diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-04 17:23:57 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-04 17:23:57 +0100 |
| commit | 22a681a07ab09922435ad0a9f665290a30f6b85b (patch) | |
| tree | 084fd239e826c8ab03d0d5ade73eac26f05c1e3a /kernel | |
| parent | 4c25981400e9d6d7c15df70dac32b6c8819b77a5 (diff) | |
| download | fbos-22a681a07ab09922435ad0a9f665290a30f6b85b.tar.gz fbos-22a681a07ab09922435ad0a9f665290a30f6b85b.zip | |
Pass the hart ID on start_kernel instead
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>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/head.S | 17 | ||||
| -rw-r--r-- | kernel/main.c | 7 | ||||
| -rw-r--r-- | kernel/printk.c | 2 |
3 files changed, 9 insertions, 17 deletions
diff --git a/kernel/head.S b/kernel/head.S index 638e5e8..45e66a8 100644 --- a/kernel/head.S +++ b/kernel/head.S @@ -71,11 +71,6 @@ _start_kernel: amoadd.w a3, a2, (a3) bnez a3, .Lhart_wait - // Store the hart id as we will tamper with the 'a0' register later when - // performing the call to `start_kernel`. - la a3, hart_id - sw a0, 0(a3) - // Explicitely nullify the 'gp' and 'sscratch' registers, as they are a bit // special but we are not using them. For the rest of the registers, we // explicitely do not care to reset them. @@ -90,12 +85,12 @@ _start_kernel: // Point 'sp' the our global stack. See fbos/sched.h for more details. la sp, stack + STACK_SIZE - // The `start_kernel` function requires an argument to be passed, which is - // the pointer to the `fdt` blob. The bootloader puts this on the `a1` - // register, so let's move it now to `a0`. - mv a0, a1 - - // Start the kernel. + // Start the kernel. Notice that both 'a0' and 'a1' have been left + // untouched. This is no coincidence as the values as passed from the + // bootloader for both these two registers will be passed down to the kernel + // as is. As with the Linux kernel these two registers contain: + // - a0: boot hart id. + // - a1: pointer to the flattened device tree blob. tail start_kernel // We really shouldn't reach this point. If so, at least mask again all diff --git a/kernel/main.c b/kernel/main.c index 41619d6..3ed8551 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -5,11 +5,8 @@ #include <fbos/string.h> #include <fbos/dt.h> -/* - * Data related to harts and set by kernel/head.S. Defined in fbos/init.h. - */ +// Defined in fbos/init.h. atomic32_t hart_lottery __section(".sdata"); -uint32_t hart_id; // Defined in fbos/sched.h. uint64_t stack[STACK_SIZE / sizeof(uint64_t)]; @@ -30,7 +27,7 @@ struct dt_info info = { .initrd_end = 0, }; -__noreturn __kernel void start_kernel(void *dtb) +__noreturn __kernel void start_kernel(uint64_t hart_id, void *dtb) { printk("Welcome to FizzBuzz OS!\n"); diff --git a/kernel/printk.c b/kernel/printk.c index 1cc68db..b67eea7 100644 --- a/kernel/printk.c +++ b/kernel/printk.c @@ -13,7 +13,7 @@ __kernel __noreturn void die(const char *const message) ; } -__kernel void print_digit(uint32_t digit) +__kernel void print_digit(uint64_t digit) { char buffer[2]; |
