Kernel/aarch64: Set up pointer to kernel page directory
The MemoryManager uses this pointer to adds its newly created page tables to the kernel page directory.
This commit is contained in:
parent
96f73c9289
commit
c2e410195a
Notes:
sideshowbarker
2024-07-17 06:30:02 +09:00
Author: https://github.com/FireFox317 Commit: https://github.com/SerenityOS/serenity/commit/c2e410195a Pull-request: https://github.com/SerenityOS/serenity/pull/15309 Reviewed-by: https://github.com/bgianfo Reviewed-by: https://github.com/bugreport0 Reviewed-by: https://github.com/nico ✅
2 changed files with 26 additions and 3 deletions
|
@ -188,6 +188,30 @@ static void activate_mmu()
|
|||
Aarch64::Asm::flush();
|
||||
}
|
||||
|
||||
static u64* get_page_directory(u64* root_table, VirtualAddress virtual_addr)
|
||||
{
|
||||
u64 level0_idx = (virtual_addr.get() >> 39) & 0x1FF;
|
||||
u64 level1_idx = (virtual_addr.get() >> 30) & 0x1FF;
|
||||
|
||||
u64* level1_table = root_table;
|
||||
|
||||
if (level1_table[level0_idx] == 0)
|
||||
return nullptr;
|
||||
|
||||
u64* level2_table = descriptor_to_pointer(level1_table[level0_idx]);
|
||||
|
||||
if (level2_table[level1_idx] == 0)
|
||||
return nullptr;
|
||||
|
||||
return descriptor_to_pointer(level2_table[level1_idx]);
|
||||
}
|
||||
|
||||
static void setup_kernel_page_directory(u64* root_table)
|
||||
{
|
||||
boot_pd_kernel = PhysicalAddress((PhysicalPtr)get_page_directory(root_table, VirtualAddress { kernel_mapping_base }));
|
||||
VERIFY(!boot_pd_kernel.is_null());
|
||||
}
|
||||
|
||||
void init_page_tables()
|
||||
{
|
||||
// We currently identity map the physical memory, so the offset is 0.
|
||||
|
@ -198,6 +222,7 @@ void init_page_tables()
|
|||
auto root_table = allocator.take_page();
|
||||
build_identity_map(allocator, root_table);
|
||||
setup_quickmap_page_table(allocator, root_table);
|
||||
setup_kernel_page_directory(root_table);
|
||||
|
||||
switch_to_page_table(page_tables_phys_start);
|
||||
activate_mmu();
|
||||
|
|
|
@ -494,10 +494,8 @@ UNMAP_AFTER_INIT void MemoryManager::initialize_physical_pages()
|
|||
auto* pd = reinterpret_cast<PageDirectoryEntry*>(quickmap_page(boot_pd_kernel));
|
||||
PageDirectoryEntry& pde = pd[page_directory_index];
|
||||
|
||||
// FIXME: port quickmap_page to aarch64
|
||||
#if !ARCH(AARCH64)
|
||||
VERIFY(!pde.is_present()); // Nothing should be using this PD yet
|
||||
#endif
|
||||
|
||||
// We can't use ensure_pte quite yet!
|
||||
pde.set_page_table_base(pt_paddr.get());
|
||||
pde.set_user_allowed(false);
|
||||
|
|
Loading…
Add table
Reference in a new issue