aboutsummaryrefslogtreecommitdiff
path: root/src/pmem.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/pmem.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/pmem.c')
-rw-r--r--src/pmem.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/pmem.c b/src/pmem.c
index bed10a4..47bb319 100644
--- a/src/pmem.c
+++ b/src/pmem.c
@@ -612,6 +612,11 @@ retry:
return 0;
}
+/** Actual kernel size in bytes. Populated by `_start`, as I don't think we
+ * have enough control from C to get both LLVM and GCC to output correct code
+ * if this was just a virtual symbol defined in a linker file. */
+size_t kernel_size = 0;
+
void init_pmem(void *fdt, uintptr_t load_addr)
{
/** @todo should I keep the info outputs? I suppose it's nice to see
@@ -650,13 +655,11 @@ void init_pmem(void *fdt, uintptr_t load_addr)
size_t probe_size = probe_pmap(0, ram_size, 0);
info("pmem map probe size returned %lu\n", probe_size);
- /* linker magicry */
- extern char *__kernel_size;
/* avoidance regions, note that stack and so on is included in the
* kernel. Addresses can be outside RAM, in which case they are just
* ignored. */
struct avoid_region avoid[64] = {
- {(pm_t)__va(load_addr), (pm_t)&__kernel_size},
+ {(pm_t)__va(load_addr), kernel_size},
{(pm_t)__va(initrd_base), initrd_size},
{(pm_t)__va(fdt_base), fdt_size}
};