From e134202611a50b358c147c92bfb8a7f443030b8b Mon Sep 17 00:00:00 2001 From: Kimplul Date: Mon, 8 Jul 2024 17:43:59 +0300 Subject: fix LLVM + Anything extern is right out as LLVM doesn't produce correct code for them. Maybe if I added some extra attributes but I'm skeptical. Replaced with static variables and getters/setters. + Inline ASM is apparently a bit buggy, so use an assembly stub when jumping to init. + Minimize work done in main() to minimize chance of LLVM doing something silly. Still not 100% certain that I shouldn't just write the main() as an assembly stub in arch/riscv64 to be absolutely sure everything works as intended. + Make .kernel.start section SHF_ALLOC, otherwise lld complains about pc-relative addressing Probably some other stuff as well that I'm forgetting right now. But at least with LLVM14 LTO seems to work, which is pretty cool? --- src/main.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index f3c5e17..12d8514 100644 --- a/src/main.c +++ b/src/main.c @@ -61,6 +61,15 @@ __noreturn void kernel(void *fdt, uintptr_t load_addr, struct vmem *d) /* we should be in kernelspace, so use the virtual address of our FDT. */ fdt = __va(fdt); + /** @todo some kind of lottery? */ + pm_t ram_base = __fdt_ram_base(fdt); + pm_t ram_size = __fdt_ram_size(fdt); + set_ram_base(ram_base); + set_ram_size(ram_size); + set_load_addr(load_addr); + + init_dbg(fdt); + /* start up debugging in kernel IO */ setup_io_dbg(d); @@ -102,27 +111,10 @@ __noreturn void main(unsigned long hart, void *fdt, uintptr_t load_addr) /* we have our own ways to get the current hart when we need it, but we * have to get the function signature right */ (void)hart; - - /* dbg uses direct mapping at this point, useful for early init asserts - * and so on */ - init_dbg(fdt); - - /** @todo some kind of lottery? */ - pm_t ram_base = __fdt_ram_base(fdt); - pm_t ram_size = __fdt_ram_size(fdt); - set_ram_base(ram_base); - set_ram_size(ram_size); - set_load_addr(load_addr); - init_mem(fdt); - /* we don't have any debug output just yet but still */ - /* also this is I guess more of an architecture limitation, should the - * whole of main() just be moved to arch? */ - assert(is_aligned(load_addr, order_size(MM_O1))); - - struct vmem *d = init_mapping(); - to_kernelspace(fdt, load_addr, d, ram_base); + struct vmem *d = init_mapping(load_addr); + to_kernelspace(fdt, load_addr, d, 0); unreachable(); } -- cgit v1.3