MemoryManager: Reuse the existing mapping of physical memory that MMU has

This commit is contained in:
apio 2023-02-27 12:51:29 +01:00
parent ff01f49b41
commit 9af6a3f30f
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 9 additions and 12 deletions

View File

@ -27,6 +27,8 @@ namespace MMU
Yes = 1
};
u64 translate_physical_address(u64 phys);
Result<void> map(u64 virt, u64 phys, int flags, UseHugePages use_huge_pages);
Result<u64> unmap(u64 virt);
Result<u64> get_physical(u64 virt);

View File

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

View File

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