MemoryManager: Reuse the existing mapping of physical memory that MMU has
This commit is contained in:
parent
ff01f49b41
commit
9af6a3f30f
@ -27,6 +27,8 @@ namespace MMU
|
|||||||
Yes = 1
|
Yes = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
u64 translate_physical_address(u64 phys);
|
||||||
|
|
||||||
Result<void> map(u64 virt, u64 phys, int flags, UseHugePages use_huge_pages);
|
Result<void> map(u64 virt, u64 phys, int flags, UseHugePages use_huge_pages);
|
||||||
Result<u64> unmap(u64 virt);
|
Result<u64> unmap(u64 virt);
|
||||||
Result<u64> get_physical(u64 virt);
|
Result<u64> get_physical(u64 virt);
|
||||||
|
@ -47,6 +47,11 @@ namespace MMU
|
|||||||
return (T)(g_physical_mapping_base + (u64)phys);
|
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)
|
void switch_page_directory(PageDirectory* dir)
|
||||||
{
|
{
|
||||||
asm volatile("mov %0, %%cr3" : : "r"(dir));
|
asm volatile("mov %0, %%cr3" : : "r"(dir));
|
||||||
|
@ -103,20 +103,10 @@ namespace MemoryManager
|
|||||||
KernelVM::init();
|
KernelVM::init();
|
||||||
MMU::setup_initial_page_directory();
|
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();
|
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());
|
frame_bitmap->initialize((void*)virtual_bitmap_base, frame_bitmap->size_in_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user