Kernel: Add constructor and destructor to MMU

This commit is contained in:
Bananymous 2023-01-30 18:54:04 +02:00
parent 3d5f1b5a86
commit 1687028ed5
2 changed files with 29 additions and 3 deletions

View File

@ -63,6 +63,32 @@ MMU::MMU()
asm volatile("movq %0, %%cr3" :: "r"(m_highest_paging_struct));
}
MMU::~MMU()
{
uint64_t* pml4 = m_highest_paging_struct;
for (uint32_t pml4e = 0; pml4e < 512; pml4e++)
{
if (!(pml4[pml4e] & PRESENT))
continue;
uint64_t* pdpt = (uint64_t*)(pml4[pml4e] & PAGE_MASK);
for (uint32_t pdpte = 0; pdpte < 512; pdpte++)
{
if (!(pdpt[pdpte] & PRESENT))
continue;
uint64_t* pd = (uint64_t*)(pdpt[pdpte] & PAGE_MASK);
for (uint32_t pde = 0; pde < 512; pde++)
{
if (!(pd[pde] & PRESENT))
continue;
kfree((void*)(pd[pde] & PAGE_MASK));
}
kfree(pd);
}
kfree(pdpt);
}
kfree(pml4);
}
void MMU::AllocatePage(uintptr_t address)
{
ASSERT((address >> 48) == 0);

View File

@ -9,15 +9,15 @@ public:
static void Intialize();
static MMU& Get();
MMU();
~MMU();
void AllocatePage(uintptr_t);
void AllocateRange(uintptr_t, ptrdiff_t);
void UnAllocatePage(uintptr_t);
void UnAllocateRange(uintptr_t, ptrdiff_t);
private:
MMU();
private:
uint64_t* m_highest_paging_struct;
};