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? --- arch/riscv64/kernel/arch.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'arch/riscv64/kernel/arch.h') diff --git a/arch/riscv64/kernel/arch.h b/arch/riscv64/kernel/arch.h index d38dad0..789b416 100644 --- a/arch/riscv64/kernel/arch.h +++ b/arch/riscv64/kernel/arch.h @@ -12,9 +12,6 @@ #include -/** Actual map of cpu id to hart id. */ -extern id_t __cpuid_to_hartid[MAX_CPUS]; - /** * Map cpu id to hart id. * Defined as a macro to allow for stuff like @@ -23,15 +20,24 @@ extern id_t __cpuid_to_hartid[MAX_CPUS]; * @endcode * * @param x Hart ID. + * @return Corresponding CPU ID. + */ +id_t cpuid_to_hartid(id_t x); + +/** + * Create mapping between \p cpuid and \p hartid. + * + * @param cpuid CPU ID to map to \p hartid. + * @param hartid Hart ID to map to \p CPU ID. */ -#define cpuid_to_hartid(x) __cpuid_to_hartid[x] +void set_hartid(id_t cpuid, id_t hartid); /** * Find the cpu id that corresponds to hart id. * * @param hart Hart to find corresponding cpu id for. * @return Corresponding cpu id. 0 if not found, though this should maybe be a - * panic situation. + * panic situation. Currently just sets the core to sleep. */ id_t hartid_to_cpuid(id_t hart); -- cgit v1.3