diff --git a/kernel/src/arch/MMU.h b/kernel/src/arch/MMU.h index addd5863..8a46e6fa 100644 --- a/kernel/src/arch/MMU.h +++ b/kernel/src/arch/MMU.h @@ -27,6 +27,8 @@ namespace MMU Yes = 1 }; + u64 translate_physical_address(u64 phys); + Result map(u64 virt, u64 phys, int flags, UseHugePages use_huge_pages); Result unmap(u64 virt); Result get_physical(u64 virt); diff --git a/kernel/src/arch/x86_64/MMU.cpp b/kernel/src/arch/x86_64/MMU.cpp index 7d037bef..760508c4 100644 --- a/kernel/src/arch/x86_64/MMU.cpp +++ b/kernel/src/arch/x86_64/MMU.cpp @@ -47,6 +47,11 @@ namespace MMU return (T)(g_physical_mapping_base + (u64)phys); } + u64 translate_physical_address(u64 phys) + { + return g_physical_mapping_base + phys; + } + void switch_page_directory(PageDirectory* dir) { asm volatile("mov %0, %%cr3" : : "r"(dir)); diff --git a/kernel/src/memory/MemoryManager.cpp b/kernel/src/memory/MemoryManager.cpp index bfa4e497..3160f808 100644 --- a/kernel/src/memory/MemoryManager.cpp +++ b/kernel/src/memory/MemoryManager.cpp @@ -103,20 +103,10 @@ namespace MemoryManager KernelVM::init(); MMU::setup_initial_page_directory(); - // NOTE: We force these operations to succeed, because if we can't map the frame bitmap to virtual memory - // there's no point in continuing. - auto bitmap_pages = g_frame_bitmap.lock()->size_in_bytes() / ARCH_PAGE_SIZE; - - auto virtual_bitmap_base = - KernelVM::alloc_several_pages(bitmap_pages) - .expect_value("Unable to allocate virtual memory for the physical frame bitmap, cannot continue"); - - u64 phys = (u64)g_frame_bitmap.lock()->location(); - map_frames_at(virtual_bitmap_base, phys, bitmap_pages, MMU::ReadWrite | MMU::NoExecute) - .expect_value("Unable to map the physical frame bitmap to virtual memory, cannot continue"); - auto frame_bitmap = g_frame_bitmap.lock(); + u64 phys = (u64)frame_bitmap->location(); + auto virtual_bitmap_base = MMU::translate_physical_address(phys); frame_bitmap->initialize((void*)virtual_bitmap_base, frame_bitmap->size_in_bytes()); }