From 5cb37038a3d7e5407863e28599d716d6e7ff92ab Mon Sep 17 00:00:00 2001 From: Timon Kruiper Date: Mon, 30 Jan 2023 10:51:40 +0100 Subject: [PATCH] Kernel/aarch64: Set kernel_load_base and correctly calculate symbol addr Setting the kernel_load_base variable caused backtracking to regress, so to have proper backtracing the calculation of the symbol address in KSyms.cpp needs to keep into account that the aarch64 kernel is linked at a high virtual memory address. --- Kernel/Arch/aarch64/MMU.cpp | 1 + Kernel/KSyms.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/Kernel/Arch/aarch64/MMU.cpp b/Kernel/Arch/aarch64/MMU.cpp index cb21eda2fd..c28c1e6f2c 100644 --- a/Kernel/Arch/aarch64/MMU.cpp +++ b/Kernel/Arch/aarch64/MMU.cpp @@ -269,6 +269,7 @@ void init_page_tables() { *adjust_by_mapping_base(&physical_to_virtual_offset) = KERNEL_MAPPING_BASE; *adjust_by_mapping_base(&kernel_mapping_base) = KERNEL_MAPPING_BASE; + *adjust_by_mapping_base(&kernel_load_base) = KERNEL_MAPPING_BASE; PageBumpAllocator allocator(adjust_by_mapping_base((u64*)page_tables_phys_start), adjust_by_mapping_base((u64*)page_tables_phys_end)); auto root_table = allocator.take_page(); diff --git a/Kernel/KSyms.cpp b/Kernel/KSyms.cpp index 4e66a6781b..75be3dbdbd 100644 --- a/Kernel/KSyms.cpp +++ b/Kernel/KSyms.cpp @@ -84,7 +84,17 @@ UNMAP_AFTER_INIT static void load_kernel_symbols_from_data(Bytes buffer) } } auto& ksym = s_symbols[current_symbol_index]; + + // FIXME: Remove this ifdef once the aarch64 kernel is loaded by the Prekernel. + // Currently, the aarch64 kernel is linked at a high virtual memory address, instead + // of zero, so the address of a symbol does not need to be offset by the kernel_load_base. +#if ARCH(X86_64) ksym.address = kernel_load_base + address; +#elif ARCH(AARCH64) + ksym.address = address; +#else +# error "Unknown architecture" +#endif ksym.name = start_of_name; *bufptr = '\0';