diff options
author | Timon Kruiper <timonkruiper@gmail.com> | 2022-09-21 16:16:39 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-10-01 14:09:01 +0200 |
commit | a62732ee2f029ca388b358e3cc013df9f1951d9d (patch) | |
tree | cc58112e736798d9fb122cb6278e2c767cd63f49 | |
parent | cdf59c86ac0fa2b38af3ec0217913cab19153ab3 (diff) | |
download | serenity-a62732ee2f029ca388b358e3cc013df9f1951d9d.zip |
Kernel/aarch64: Only identity map kernel image, instead of all of RAM
For the initial page tables we only need to identity map the kernel
image, the rest of the memory will be managed by the MemoryManager. The
linker script is updated to get the kernel image start and end
addresses.
-rw-r--r-- | Kernel/Arch/aarch64/MMU.cpp | 8 | ||||
-rw-r--r-- | Kernel/Arch/aarch64/linker.ld | 6 | ||||
-rw-r--r-- | Kernel/Memory/MemoryManager.cpp | 6 |
3 files changed, 17 insertions, 3 deletions
diff --git a/Kernel/Arch/aarch64/MMU.cpp b/Kernel/Arch/aarch64/MMU.cpp index 2b4a336988..1c4a1d1f26 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 ea81f81bc5..08d34693fe 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 5710235f62..33fb51c806 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() |