aboutsummaryrefslogtreecommitdiff
path: root/include
Commit message (Collapse)AuthorAgeFilesLines
* Remove stack pointer for each processMiquel Sabaté Solà2024-12-031-6/+0
| | | | | | | | Since 6132623dbf30 ("Share the same stack everywhere") the same stack is used everywhere. Hence, it's rather pointless for each task to have a pointer to a stack which is the same and that is never read. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Simplify how we fetch the load addressMiquel Sabaté Solà2024-12-031-4/+5
| | | | | | | | | | | | Similarly to 58fcecc381be ("Simplify the constant on the size of the stack"), the base and offset load addresses where taken from the Linux kernel, which has to account for way more stuff than this poor kernel. Hence, let's be more explicit about the base address and the offset where the kernel will be located, so it's actually more clear both on the linker, and on the kernel's header. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Simplify the constant on the size of the stackMiquel Sabaté Solà2024-12-031-7/+4
| | | | | | | | At the beginning I carried over things from the Linux kernel just in case I would need them in the future. As this project is very much at a stage where I'm already happy with it, let's remove unneeded complexity. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Don't repeat the task name when printing the modelMiquel Sabaté Solà2024-12-021-0/+1
| | | | | | | | | | When printing the initial model message on DEBUG it repeated the "init" message twice. Avoid that by directly using 'write' on some of the calls. Fixes: 32e880127366 ("Prepend the name of the task on debug") Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Share the same stack everywhereMiquel Sabaté Solà2024-12-021-0/+3
| | | | | | | | | | As documented in the code, we are not implementing any kind of memory protection, so in theory any process (regardless if running in user or kernel space) would be able to tamper with other processes' stack. Hence, don't even pretend that we are separating stacks and share the same global stack everywhere. This simplifies things a bit. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Prepend the name of the task on debugMiquel Sabaté Solà2024-12-022-3/+21
| | | | | | | | | On 'printk' and 'sys_write' calls, prepend the name of the task that is being executed for each message. This is an easy way to show off that we are doing the right thing with the 'tp' register, even if we don't do much with it. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Rename 'switch_to' to 'set_return_address_to'Miquel Sabaté Solà2024-11-301-4/+2
| | | | | | | | The original name came from a previous hack the did not work but somehow the old name remained. Now it was more misleading than anything else, so let's rename it to something that is closer to what it actually does. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Allow the kernel to run as a Linux imageMiquel Sabaté Solà2024-11-292-1/+25
| | | | | | | | | | | | | | | | | | In order to run on real hardware, it's actually easier to re-use workflows from existing bootloaders than loading things in memory manually. In order to achieve this two things had to be settled: 1. The image has to have a Linux header as defined in the RISC-V port. This header will be taken into consideration by bootloaders in order to know where to jump, the image offset, the endianness of the image, etc. 2. The image cannot just be an ELF executable. Rather, we must translate it into binary form via `objcopy`. With all of this at hand, I was able to make the kernel run on a Starfive VisionFive 2 board, and I have recorded an example so it's available as documentation. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Show the detected machine modelMiquel Sabaté Solà2024-11-261-0/+6
| | | | | | | | | | Originally I was planning to detect the machine model just in case we needed to do workaround for special cases. But since apparently even VisionFive2 brings its own CPU frequency base on DT, this is not even needed. Hence, fetching the model is now a cool message being shown on boot. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* dt: Fetch the CPU frequency as wellMiquel Sabaté Solà2024-11-262-6/+21
| | | | | | | | | | | If the 'timebase-frequency' property is available under the 'cpus' node from the DTB blob, it makes sense to try to fetch this value from there instead of hardcoding it. For other use-cases, where this information is not available through DT (e.g. ACPI on the VisionFive2 board), we will have to hardcode it with a default value even if it's not the proper one. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* kernel: Don't tamper the 'ra' register on switchMiquel Sabaté Solà2024-11-251-3/+4
| | | | | | | | As part of a shameful hack I was tampering with the 'ra' register as well as with the 'sepc' CSR. Since in the end we just assume 'sret' is in place at the end, let's be cleaner and leave 'ra' alone. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Accept tasks as a parameter on initrd extractionMiquel Sabaté Solà2024-11-241-1/+3
| | | | | | This allows this functionality to be properly extracted for unit tests. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Simplify the entry address computationMiquel Sabaté Solà2024-11-241-6/+18
| | | | | | | We actually don't need to preserve the initially computed base address for each binary, but we can just preserve the final entry address. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Simplify scheduling by introducing an init processMiquel Sabaté Solà2024-11-241-5/+2
| | | | | | | | | | | | | | | | Scheduling is easier if there is an init process which does nothing. This way we don't have to perform hacks in order to idle in S privilege mode while touching special registers in weird ways. For now this process is kind of costly since 'wfi' is not accepted in this context, but this can be further tuned down in the future by setting TW=1 on 'mstatus', or by handling the exception and allowing it if it comes from the proper process. All of that being said, there is still work to be done as things fail when optimitzations are on. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Enable exception handling from user modeMiquel Sabaté Solà2024-11-223-0/+16
| | | | | | | | This allows us to actually catch system calls and start to run user space programs. That being said, the whole thing is still pretty brittle, and the scheduler is not quite there yet. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Fix initrd parsing because of a path changeMiquel Sabaté Solà2024-11-221-3/+3
| | | | | | | | | | In commit 573a8c6b490a ("usr: Rename foo/bar to fizz/buzz") the path of the user-space binaries have changed. The `initrd` parsing code makes some decisions based on that naming, and so it needed to be updated as well. Fixes: 573a8c6b490a ("usr: Rename foo/bar to fizz/buzz") Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Enable the timer from the SBI interfaceMiquel Sabaté Solà2024-11-223-0/+18
| | | | | | | | A basic interrupt handler has been implemented which tracks the seconds that have been elapsing along the way. Depending on the value of these seconds, then a task has to be called. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Add basic parsing for underlying ELF executablesMiquel Sabaté Solà2024-11-223-5/+11
| | | | | | | | | | | | | The given initrd is a CPIO archive of multiple ELF executables. We are already able to parse the CPIO archive to detect where each file is located, this commit adds the mapping for each ELF executable to the corresponding task_struct. Note that this is still heavily under construction, since we cannot simply jump into the entry point of an executable as we have not yet setup the proper layout from performing context switches. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Initial parsing of the provided initrd fileMiquel Sabaté Solà2024-11-213-1/+15
| | | | | | | | | | | | We expect a CPIO archive with the 'newc' format for the initrd. Parse this archive from the given initrd address and fetch the address for each ELF executable while also pairing which task correspond to which ELF. This commit leaves to do the actual parsing of the ELF file for each task, while also leaving some string utilities to be refined. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Fetch the initrd address from the DTB blobMiquel Sabaté Solà2024-11-205-3/+38
| | | | | | | | | | The kernel entry has a pointer to the DTB blob as a parameter. From this pointer we can parse the the DTB blob to find the properties "chosen->linux,initrd-start" and "chosen->linux,initrd-start". These properties are guaranteed to have 64-bit addresses which point where the initrd is in memory, which we need to fetch the binaries to be loaded. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Check the return value from SBI ecallsMiquel Sabaté Solà2024-11-192-11/+25
| | | | Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Setup the stack for an init taskMiquel Sabaté Solà2024-11-198-8/+105
| | | | | | | | | | | | | | | | | Bootstrap an init task which holds at least the initial stack that is to be used when setting up the registers (such as `sp` and `tp`). In order to guarantee that the stack and the rest of the registers are set up correctly, this commit also provides a raw implementation of a `printk` function. Moreover, this commit also adds an argument that must be passed to `start_kernel`, which is the pointer to the embedded `fdt` blob. This argument will be used by later work so to fetch, at least, the base address for the initial ram disk. This was also used to test that the stack was working as expected. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Bootstrap the projectMiquel Sabaté Solà2024-08-243-0/+33
For now the base layout has been defined and we have a binary that is properly reached through openSBI. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>