diff --git a/Kernel/Arch/aarch64/MMU.cpp b/Kernel/Arch/aarch64/MMU.cpp index 2b4a336988e..1c4a1d1f269 100644 --- a/Kernel/Arch/aarch64/MMU.cpp +++ b/Kernel/Arch/aarch64/MMU.cpp @@ -21,6 +21,8 @@ // These come from the linker script extern u8 page_tables_phys_start[]; extern u8 page_tables_phys_end[]; +extern u8 start_of_kernel_image[]; +extern u8 end_of_kernel_image[]; namespace Kernel { @@ -122,7 +124,11 @@ static void build_identity_map(PageBumpAllocator& allocator) u64 normal_memory_flags = ACCESS_FLAG | PAGE_DESCRIPTOR | INNER_SHAREABLE | NORMAL_MEMORY; u64 device_memory_flags = ACCESS_FLAG | PAGE_DESCRIPTOR | OUTER_SHAREABLE | DEVICE_MEMORY; - insert_identity_entries_for_physical_memory_range(allocator, level1_table, START_OF_NORMAL_MEMORY, END_OF_NORMAL_MEMORY, normal_memory_flags); + // Align the identity mapping of the kernel image to 2 MiB, the rest of the memory is initially not mapped. + FlatPtr start_of_range = ((FlatPtr)start_of_kernel_image & ~(FlatPtr)0x1fffff); + FlatPtr end_of_range = ((FlatPtr)end_of_kernel_image & ~(FlatPtr)0x1fffff) + 0x200000 - 1; + + insert_identity_entries_for_physical_memory_range(allocator, level1_table, start_of_range, end_of_range, normal_memory_flags); insert_identity_entries_for_physical_memory_range(allocator, level1_table, RPi::MMIO::the().peripheral_base_address(), RPi::MMIO::the().peripheral_end_address(), device_memory_flags); } diff --git a/Kernel/Arch/aarch64/linker.ld b/Kernel/Arch/aarch64/linker.ld index ea81f81bc5c..08d34693fee 100644 --- a/Kernel/Arch/aarch64/linker.ld +++ b/Kernel/Arch/aarch64/linker.ld @@ -13,6 +13,8 @@ SECTIONS { . = 0x00080000; + start_of_kernel_image = .; + .text ALIGN(4K) : AT (ADDR(.text)) { *(.text.first) @@ -62,8 +64,6 @@ SECTIONS /* FIXME: Placeholder to satisfy linker */ start_of_kernel_text = .; end_of_kernel_text = .; - start_of_kernel_image = .; - end_of_kernel_image = .; start_of_unmap_after_init = .; end_of_unmap_after_init = .; start_of_ro_after_init = .; @@ -76,6 +76,8 @@ SECTIONS . += 8M; page_tables_phys_end = .; + + end_of_kernel_image = .; } size_of_bss_divided_by_8 = (end_of_bss - start_of_bss + 7) / 8; diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp index 5710235f62a..33fb51c8067 100644 --- a/Kernel/Memory/MemoryManager.cpp +++ b/Kernel/Memory/MemoryManager.cpp @@ -72,8 +72,14 @@ bool MemoryManager::is_initialized() static UNMAP_AFTER_INIT VirtualRange kernel_virtual_range() { +#if ARCH(AARCH64) + // NOTE: We currently identity map the kernel image for aarch64, so the kernel virtual range + // is the complete memory range. + return VirtualRange { VirtualAddress((FlatPtr)0), 0x3F000000 }; +#else size_t kernel_range_start = kernel_mapping_base + 2 * MiB; // The first 2 MiB are used for mapping the pre-kernel return VirtualRange { VirtualAddress(kernel_range_start), KERNEL_PD_END - kernel_range_start }; +#endif } MemoryManager::GlobalData::GlobalData()