aboutsummaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* Update changelog fileMiquel Sabaté Solà2024-12-051-0/+8
| | | | Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Add a note on HSMMiquel Sabaté Solà2024-12-051-0/+6
| | | | | | | The hart lottery that we do on initialization is a bit rigged. Write a note on that in the documentation of the 'hart_lottery' variable. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Pass the hart ID on start_kernel insteadMiquel Sabaté Solà2024-12-045-26/+13
| | | | | | | | | Instead of storing the hard ID as given by the bootloader into a C variable, pass it directly into the 'start_kernel' function since we don't need to tamper the value as originally laid out on the 'a0' register. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Re-use the halting loop also for the main hartMiquel Sabaté Solà2024-12-041-37/+15
| | | | | | | | | | | The halting in secondary harts should not be treated too differently as with the (unlikely) scenario that the main function quits. Hence, merge the code in both cases. Moreover, we do not really need to to initialize the values of most registers, as they will be explicitely set when needed anyways. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Move documentation to the proper placesMiquel Sabaté Solà2024-12-044-21/+30
| | | | | | | | | Code documentation was scattered between header and source files. Since the norm was already to have this documentation into header files, move some comments from source files to their header counterparts. This hopefully makes things more consistent. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Write down the requirement for the Zaamo extensionMiquel Sabaté Solà2024-12-032-1/+3
| | | | | | | | | Since 2eead36f97fa ("Run a hart lottery on SMP") the kernel is making use of the 'amoadd.w' instruction, which requires the Zaamo extension (included in the base A extension). This is notable and is worth a mention on the list of requirements. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Run a hart lottery on SMPMiquel Sabaté Solà2024-12-038-3/+89
| | | | | | | | | | | | | | | | | On systems with SMP multiple harts will try to run the kernel, and they will appear at random. But in this kernel, in order to keep things simple, we want to make sure that *only one* hart is running the show, as it greatly simplifies things on these kinds of systems. The solution is similar to what Linux does, which is to allow the first hart to initialize things, but then (and different to what Linux does), it will infinitely stall all the other harts that arrive at a random later point in time. In order to make this more apparent, I have also added a print message showing which hart is being used to run the whole thing. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* test: Remove asserts on specific entry addrsMiquel Sabaté Solà2024-12-031-7/+0
| | | | | | | | These asserts where needed when I was iterating on the initrd handling code, but they are admittedly too specific and prone to errors. Hence, get rid off them. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Remove stack pointer for each processMiquel Sabaté Solà2024-12-033-23/+16
| | | | | | | | 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-032-6/+7
| | | | | | | | | | | | 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-034-10/+7
| | | | | | | | 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-022-2/+4
| | | | | | | | | | 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-024-14/+25
| | | | | | | | | | 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>
* ci: Run tests with DEBUG=1 tooMiquel Sabaté Solà2024-12-021-0/+3
| | | | | | | | Since 32e880127366 ("Prepend the name of the task on debug") we are executing some code when DEBUG is present. Hence, the building might be different in this scenario too. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Ensure the right optimitzation level on DEBUGMiquel Sabaté Solà2024-12-021-1/+1
| | | | Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Prepend the name of the task on debugMiquel Sabaté Solà2024-12-026-20/+72
| | | | | | | | | 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>
* Document what we mean by scheduling on this kernelMiquel Sabaté Solà2024-11-302-5/+20
| | | | | | | | The notion of 'scheduling' a process on this kernel is effectively the same as starting the process anew. This is pretty bananas for any general purpose kernel, but this is not our case. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Rename 'switch_to' to 'set_return_address_to'Miquel Sabaté Solà2024-11-302-9/+6
| | | | | | | | 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>
* Simplify the qemu target by removing QEMU_BIOSMiquel Sabaté Solà2024-11-303-25/+4
| | | | | | | | | | | | | | The QEMU_BIOS parameter was meant to help on old QEMU installations which did not support the proper fw_dynamic workflow. That being said, old QEMU versions might also not implement the proper SBI specification, or it may have other unexpected issues. Hence, just remove the option and force people to have a sufficiently recent QEMU version. Finally, I have updated the SVG showing off a QEMU run. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Organize the credits betterMiquel Sabaté Solà2024-11-291-10/+12
| | | | Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Fix gdb target by not removing ELF executableMiquel Sabaté Solà2024-11-292-1/+1
| | | | | | | | GDB actually needs the ELF executable to run a session with symbols loaded in. Hence, do not remove the `fbos.elf` file after calling `objcopy`. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Allow the kernel to run as a Linux imageMiquel Sabaté Solà2024-11-297-19/+138
| | | | | | | | | | | | | | | | | | 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>
* Replace invalid explanation from contributing.mdMiquel Sabaté Solà2024-11-281-4/+5
| | | | | | | | I took this file from another project and shamefully forgot to adapt it in a proper way. Now it removes any mentions of NES development and also gives a pointer on using the style from the Linux kernel for git log. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Use mktemp when generating the archiveMiquel Sabaté Solà2024-11-271-7/+5
| | | | | | | | | | | Instead of manually making a temporary directory, do it through 'mktemp', which feels cleaner. Moreover, the base directory will now by named 'fbos' instead of the cryptic 'tmp' one. This is quite relevant when you uncompress the archive into another machine. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Move initrd.c into libMiquel Sabaté Solà2024-11-262-1/+1
| | | | | | | | Even if it's tightly coupled with the kernel (e.g. identifying specific tasks from the kernel), in the end it's a library and so it should be placed accordingly. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Move string.S to the lib directoryMiquel Sabaté Solà2024-11-262-1/+1
| | | | | | | It was weird enough to have it in the 'kernel' directory, as it's way more fitting to have it on 'lib'. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Move 'memcpy' to assemblyMiquel Sabaté Solà2024-11-262-23/+31
| | | | | | | And apparently 'memmove' is not needed anymore, so we dodged a bullet there. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Show the detected machine modelMiquel Sabaté Solà2024-11-264-0/+69
| | | | | | | | | | 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>
* test: Add a DT test for a VisionFive2 boardMiquel Sabaté Solà2024-11-262-6/+35
| | | | Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* dt: Fetch the CPU frequency as wellMiquel Sabaté Solà2024-11-266-48/+108
| | | | | | | | | | | 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>
* usr: Simplify init.SMiquel Sabaté Solà2024-11-251-4/+1
| | | | | | | | | There appears to be no reasonable way to call 'wfi' from user space and making kernel space look the other way. Moreover, it also looks like clearing TW is not working either. Hence, we will have to implement 'idle' entirely from kernel space and be reasonable about it. 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>
* Add files for contributing to the projectMiquel Sabaté Solà2024-11-254-0/+69
| | | | Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Add a make target for producing a release archiveMiquel Sabaté Solà2024-11-253-8/+46
| | | | Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Add a video example running on QEMUMiquel Sabaté Solà2024-11-252-0/+3
| | | | Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* tests: Only test initrd addresses on debugMiquel Sabaté Solà2024-11-253-6/+13
| | | | | | | | | | | | | | | | In initrd tests, and in general, we only need to check that the function did something. As in, that it set the entry addresses somewhere and did not leave them NULL. This is going to be performed from now on on CI and regular tests. And, just if you want to go the extra mile, we will run specific tests that check on memory addresses but that are not guaranteed to work. This is to be replaced in the future by having some proper debugging output. As in, having a message at kernel boot time specifying the addresses being used among other info. This needs a more complex printk utility, of course. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* test: Fix test on initrdMiquel Sabaté Solà2024-11-241-6/+9
| | | | | | | | | | | | This was broken since I first introduced the test on initrd on 40ffc517e20c ("Initial parsing of the provided initrd file") but it always was as a work in progress test. Now that the initrd parsing has separation of concerns with the global 'tasks' variable since f4986dab75fa ("Accept tasks as a parameter on initrd extraction"), we can have a proper test written for this. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Accept tasks as a parameter on initrd extractionMiquel Sabaté Solà2024-11-244-13/+21
| | | | | | This allows this functionality to be properly extracted for unit tests. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* kernel: Remove old code from initrd.cMiquel Sabaté Solà2024-11-241-36/+15
| | | | | | | And for the first time I saw this whole thing working with optimizations on :) Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Simplify the entry address computationMiquel Sabaté Solà2024-11-243-22/+25
| | | | | | | 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-246-30/+26
| | | | | | | | | | | | | | | | 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-229-11/+85
| | | | | | | | 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-223-14/+14
| | | | | | | | | | 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>
* Add a 'wfi' instruction on the main loopMiquel Sabaté Solà2024-11-221-2/+5
| | | | | | | The actual work is done somewhere else, there is no need to constantly run the main thread. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* usr: Rename foo/bar to fizz/buzzMiquel Sabaté Solà2024-11-224-10/+10
| | | | | | | | | | | | When creating the user space binaries I forgot about their proper names, which is funny on its own. Anyways, let's get them the name they were intended. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com> alksjdlkajd Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Enable the timer from the SBI interfaceMiquel Sabaté Solà2024-11-226-8/+153
| | | | | | | | 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-2210-21/+79
| | | | | | | | | | | | | 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-2111-11/+244
| | | | | | | | | | | | 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>
* ci: Make the build work for Ubuntu 24.04Miquel Sabaté Solà2024-11-201-2/+2
| | | | | | | | | The binutils used in Ubuntu 24.04 has a crash when trying to link the end binary, which is avoided when passing `-fno-PIE`. Since this is a good idea anyways for the kernel in general, let's pass this flag always and kill two birds with one stone. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
* Add a note on requirement a little-endian systemMiquel Sabaté Solà2024-11-201-0/+2
| | | | | | | | | The dt parsing algorithm assumes that a little-endian system is in place and hence most numbers on the DTB blob have to be converted from big-endian to little-endian. I am not planning on changing that any time soon, so let's add this as a requirement. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>