mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:48:11 +00:00
Kernel/aarch64: Add function to MMU.cpp to unmap identity mapping
This function will be used once the kernel runs in high virtual memory to unmap the identity mapping as userspace will later on use this memory range instead.
This commit is contained in:
parent
150c52e420
commit
a581cae4d4
2 changed files with 22 additions and 0 deletions
|
@ -13,6 +13,7 @@ namespace Kernel {
|
|||
|
||||
void initialize_exceptions();
|
||||
void init_page_tables();
|
||||
void unmap_identity_map();
|
||||
void panic_without_mmu(StringView);
|
||||
void dbgln_without_mmu(StringView);
|
||||
|
||||
|
|
|
@ -244,4 +244,25 @@ void init_page_tables()
|
|||
activate_mmu();
|
||||
}
|
||||
|
||||
void unmap_identity_map()
|
||||
{
|
||||
auto start_of_physical_memory = FlatPtr(START_OF_NORMAL_MEMORY);
|
||||
|
||||
u64 level0_idx = (start_of_physical_memory >> 39) & 0x1FF;
|
||||
u64 level1_idx = (start_of_physical_memory >> 30) & 0x1FF;
|
||||
|
||||
u64* level1_table = (u64*)page_tables_phys_start;
|
||||
|
||||
auto level2_table = FlatPtr(descriptor_to_pointer(level1_table[level0_idx]));
|
||||
if (!level2_table)
|
||||
panic_without_mmu("Could not find table!"sv);
|
||||
|
||||
// NOTE: The function descriptor_to_pointer returns a physical address, but we want to unmap that range
|
||||
// so, the pointer must be converted to a virtual address by adding KERNEL_MAPPING_BASE.
|
||||
level2_table += KERNEL_MAPPING_BASE;
|
||||
|
||||
// Unmap the complete identity map
|
||||
((u64*)level2_table)[level1_idx] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue