Add Virtual::GetPhysical()

This commit is contained in:
Alex 2023-03-31 17:30:33 +03:00
parent 43af65b21e
commit eae6006d25
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 42 additions and 0 deletions

View File

@ -40,6 +40,41 @@ namespace Memory
return false;
}
void *Virtual::GetPhysical(void *VirtualAddress)
{
// 0x1000 aligned
uintptr_t Address = (uintptr_t)VirtualAddress;
Address &= 0xFFFFFFFFFFFFF000;
PageMapIndexer Index = PageMapIndexer(Address);
PageMapLevel4 PML4 = this->Table->Entries[Index.PMLIndex];
PageDirectoryPointerTableEntryPtr *PDPTE = nullptr;
PageDirectoryEntryPtr *PDE = nullptr;
PageTableEntryPtr *PTE = nullptr;
if (PML4.Present)
{
PDPTE = (PageDirectoryPointerTableEntryPtr *)((uintptr_t)PML4.GetAddress() << 12);
if (PDPTE)
if (PDPTE->Entries[Index.PDPTEIndex].Present)
{
PDE = (PageDirectoryEntryPtr *)((uintptr_t)PDPTE->Entries[Index.PDPTEIndex].GetAddress() << 12);
if (PDE)
if (PDE->Entries[Index.PDEIndex].Present)
{
PTE = (PageTableEntryPtr *)((uintptr_t)PDE->Entries[Index.PDEIndex].GetAddress() << 12);
if (PTE)
if (PTE->Entries[Index.PTEIndex].Present)
{
return (void *)((uintptr_t)PTE->Entries[Index.PTEIndex].GetAddress() << 12);
}
}
}
}
return nullptr;
}
void Virtual::Map(void *VirtualAddress, void *PhysicalAddress, uint64_t Flags)
{
SmartLock(this->MemoryLock);

View File

@ -539,6 +539,13 @@ namespace Memory
*/
bool Check(void *VirtualAddress, PTFlag Flag = PTFlag::P);
/**
* @brief Get physical address of the page.
* @param VirtualAddress Virtual address of the page.
* @return Physical address of the page.
*/
void *GetPhysical(void *VirtualAddress);
/**
* @brief Map page.
*