aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-08 17:43:59 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-08 18:04:03 +0300
commite134202611a50b358c147c92bfb8a7f443030b8b (patch)
treeac7c31824adcf41a63e4d2c5e141f5149cc55b1a /src/main.c
parent7e828ec1e1479ff9a8afe845539d08ca0dfada5f (diff)
downloadkmi-e134202611a50b358c147c92bfb8a7f443030b8b.tar.gz
kmi-e134202611a50b358c147c92bfb8a7f443030b8b.zip
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?
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c30
1 files changed, 11 insertions, 19 deletions
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();
}