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.
This commit is contained in:
Timon Kruiper 2022-09-21 16:16:39 +02:00 committed by Andreas Kling
parent cdf59c86ac
commit a62732ee2f
Notes: sideshowbarker 2024-07-17 18:49:10 +09:00
3 changed files with 17 additions and 3 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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()