Implement unified PTE accessors and management helpers
This commit is contained in:
@@ -23,9 +23,25 @@ XTAPI
|
||||
VOID
|
||||
MM::PageMap::ClearPte(PHARDWARE_PTE PtePointer)
|
||||
{
|
||||
/* Clear PTE */
|
||||
PtePointer->Long = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value representing an empty PTE list.
|
||||
*
|
||||
* @return This routine returns the value representing an empty PTE list.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
ULONG
|
||||
MM::PageMap::GetEmptyPteList(VOID)
|
||||
{
|
||||
/* Return empty PTE list mask */
|
||||
return PageMapInfo.EmptyPteList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the address of the PDE (Page Directory Entry), that maps given address.
|
||||
*
|
||||
@@ -47,6 +63,42 @@ MM::PageMap::GetPdeAddress(PVOID Address)
|
||||
return (PMMPDE)(PageMapInfo.PdeBase + Offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of the PDE (Page Directory Entry), that maps given address.
|
||||
*
|
||||
* @param Address
|
||||
* Specifies the virtual address for which to retrieve the corresponding PDE.
|
||||
*
|
||||
* @return This routine returns the index of the PDE.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
ULONG
|
||||
MM::PageMap::GetPdeIndex(PVOID Address)
|
||||
{
|
||||
/* Return PDE index */
|
||||
return ((((ULONG_PTR)(Address)) >> PageMapInfo.PdiShift) & (PageMapInfo.Xpa ? 0x1FF : 0x3FF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the virtual address that is mapped by a given Page Directory Entry.
|
||||
*
|
||||
* @param PdePointer
|
||||
* Specifies the address of the PDE.
|
||||
*
|
||||
* @return This routine returns the virtual address mapped by the PDE.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
PVOID
|
||||
MM::PageMap::GetPdeVirtualAddress(PMMPDE PdePointer)
|
||||
{
|
||||
/* Return PDE virtual address */
|
||||
return ((PVOID)((ULONG)(PdePointer) << 20));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the address of the PPE (Page Directory Pointer Table Entry), that maps given address.
|
||||
*
|
||||
@@ -65,6 +117,42 @@ MM::PageMap::GetPpeAddress(PVOID Address)
|
||||
return (PMMPPE)0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of the PPE (Page Directory Pointer Table Entry), that maps given address.
|
||||
*
|
||||
* @param Address
|
||||
* Specifies the virtual address for which to retrieve the corresponding PPE.
|
||||
*
|
||||
* @return This routine returns the index of the PPE.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
ULONG
|
||||
MM::PageMap::GetPpeIndex(PVOID Address)
|
||||
{
|
||||
/* Return PPE index */
|
||||
return ((((ULONG_PTR)(Address)) >> MM_PPI_SHIFT) & 0x3) * PageMapInfo.Xpa;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the virtual address that is mapped by a given Page Directory Pointer Table Entry.
|
||||
*
|
||||
* @param PpePointer
|
||||
* Specifies the virtual address of the PPE.
|
||||
*
|
||||
* @return This routine returns the virtual address mapped by the PPE.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
PVOID
|
||||
MM::PageMap::GetPpeVirtualAddress(PMMPPE PpePointer)
|
||||
{
|
||||
/* Return PPE virtual address */
|
||||
return (PVOID)((ULONG)(PpePointer) << 30);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the address of the PTE (Page Table Entry), that maps given address.
|
||||
*
|
||||
@@ -86,6 +174,133 @@ MM::PageMap::GetPteAddress(PVOID Address)
|
||||
return (PMMPTE)(PageMapInfo.PteBase + Offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of the PTE (Page Table Entry), that maps given address.
|
||||
*
|
||||
* @param Address
|
||||
* Specifies the virtual address for which to retrieve the corresponding PTE.
|
||||
*
|
||||
* @return This routine returns the index of the PTE.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
ULONG
|
||||
MM::PageMap::GetPteIndex(PVOID Address)
|
||||
{
|
||||
/* Return PTE index */
|
||||
return ((((ULONG_PTR)(Address)) >> MM_PTI_SHIFT) & (PageMapInfo.Xpa ? 0x1FF : 0x3FF));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the virtual address that is mapped by a given Page Table Entry.
|
||||
*
|
||||
* @param PtePointer
|
||||
* Specifies the virtual address of the PTE.
|
||||
*
|
||||
* @return This routine returns the virtual address mapped by the PTE.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
PVOID
|
||||
MM::PageMap::GetPteVirtualAddress(PMMPTE PtePointer)
|
||||
{
|
||||
/* Return PTE virtual address */
|
||||
return ((PVOID)((ULONG)(PtePointer) << 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances a PTE pointer by a given number of entries, considering the actual PTE size for PML2.
|
||||
*
|
||||
* @param Pte
|
||||
* The PTE pointer to advance.
|
||||
*
|
||||
* @param Count
|
||||
* The number of PTE entries to advance by.
|
||||
*
|
||||
* @return This routine returns the advanced PTE pointer.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
PMMPTE
|
||||
MM::PageMapBasic::AdvancePte(PMMPTE Pte,
|
||||
ULONG Count)
|
||||
{
|
||||
/* Return advanced PTE pointer */
|
||||
return (PMMPTE)((ULONG_PTR)Pte + (Count * sizeof(MMPML2_PTE)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next entry in a PTE list.
|
||||
*
|
||||
* @param Pte
|
||||
* The PTE pointer to get the next entry from.
|
||||
*
|
||||
* @return This routine returns the next entry in the PTE list.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
ULONG_PTR
|
||||
MM::PageMapBasic::GetNextEntry(PMMPTE Pte)
|
||||
{
|
||||
/* Return next entry in PTE list */
|
||||
return Pte->Pml2.List.NextEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances a PTE pointer, considering the actual PTE size for PML2.
|
||||
*
|
||||
* @param Pte
|
||||
* The PTE pointer to advance.
|
||||
*
|
||||
* @return The advanced PTE pointer.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
PMMPTE
|
||||
MM::PageMapBasic::GetNextPte(PMMPTE Pte)
|
||||
{
|
||||
/* Return advanced PTE pointer */
|
||||
return AdvancePte(Pte, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a PTE list contains only one entry.
|
||||
*
|
||||
* @param Pte
|
||||
* The PTE pointer to check.
|
||||
*
|
||||
* @return This routine returns TRUE if the PTE list has only one entry, FALSE otherwise.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
BOOLEAN
|
||||
MM::PageMapBasic::GetOneEntry(PMMPTE Pte)
|
||||
{
|
||||
/* Return one entry status */
|
||||
return Pte->Pml2.List.OneEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of a PTE for basic paging (PML2).
|
||||
*
|
||||
* @return This routine returns the size of a PTE.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
ULONG
|
||||
MM::PageMapBasic::GetPteSize(VOID)
|
||||
{
|
||||
/* Return the size of MMPTE */
|
||||
return sizeof(MMPML2_PTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes page map information for basic paging (PML2).
|
||||
*
|
||||
@@ -100,6 +315,9 @@ MM::PageMapBasic::InitializePageMapInfo(VOID)
|
||||
/* Set PML2 page map information */
|
||||
PageMapInfo.Xpa = FALSE;
|
||||
|
||||
/* Set PML2 empty PTE list mask */
|
||||
PageMapInfo.EmptyPteList = (ULONG)0xFFFFF;
|
||||
|
||||
/* Set PML2 base addresses */
|
||||
PageMapInfo.PteBase = MM_PTE_BASE;
|
||||
PageMapInfo.PdeBase = MM_PDE_LEGACY_BASE;
|
||||
@@ -123,9 +341,54 @@ XTAPI
|
||||
BOOLEAN
|
||||
MM::PageMapBasic::PteValid(PHARDWARE_PTE PtePointer)
|
||||
{
|
||||
/* Check if PTE is valid */
|
||||
return (BOOLEAN)PtePointer->Pml2.Valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the next entry in a PTE list.
|
||||
*
|
||||
* @param Pte
|
||||
* The PTE pointer to modify.
|
||||
*
|
||||
* @param Value
|
||||
* The value to set as the next entry.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
MM::PageMapBasic::SetNextEntry(PMMPTE Pte,
|
||||
ULONG_PTR Value)
|
||||
{
|
||||
/* Set next entry in PTE list */
|
||||
Pte->Pml2.List.NextEntry = Value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the flag indicating whether a PTE list contains only one entry.
|
||||
*
|
||||
* @param Pte
|
||||
* The PTE pointer to modify.
|
||||
*
|
||||
* @param Value
|
||||
* The value to set. TRUE if the list has only one entry, FALSE otherwise.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
MM::PageMapBasic::SetOneEntry(PMMPTE Pte,
|
||||
BOOLEAN Value)
|
||||
{
|
||||
/* Set one entry status */
|
||||
Pte->Pml2.List.OneEntry = Value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a PML2 page table entry (PTE) with the specified physical page and access flags.
|
||||
*
|
||||
@@ -148,6 +411,7 @@ MM::PageMapBasic::SetPte(PHARDWARE_PTE PtePointer,
|
||||
PFN_NUMBER PageFrameNumber,
|
||||
BOOLEAN Writable)
|
||||
{
|
||||
/* Set PTE */
|
||||
PtePointer->Pml2.PageFrameNumber = PageFrameNumber;
|
||||
PtePointer->Pml2.Valid = 1;
|
||||
PtePointer->Pml2.Writable = Writable;
|
||||
@@ -175,10 +439,102 @@ MM::PageMapBasic::SetPteCaching(PHARDWARE_PTE PtePointer,
|
||||
BOOLEAN CacheDisable,
|
||||
BOOLEAN WriteThrough)
|
||||
{
|
||||
/* Set caching attributes */
|
||||
PtePointer->Pml2.CacheDisable = CacheDisable;
|
||||
PtePointer->Pml2.WriteThrough = WriteThrough;
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances a PTE pointer by a given number of entries, considering the actual PTE size for PML3.
|
||||
*
|
||||
* @param Pte
|
||||
* The PTE pointer to advance.
|
||||
*
|
||||
* @param Count
|
||||
* The number of PTE entries to advance by.
|
||||
*
|
||||
* @return The advanced PTE pointer.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
PMMPTE
|
||||
MM::PageMapXpa::AdvancePte(PMMPTE Pte,
|
||||
ULONG Count)
|
||||
{
|
||||
/* Return advanced PTE pointer */
|
||||
return (PMMPTE)((ULONG_PTR)Pte + (Count * sizeof(MMPML3_PTE)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next entry in a PTE list.
|
||||
*
|
||||
* @param Pte
|
||||
* The PTE pointer to get the next entry from.
|
||||
*
|
||||
* @return This routine returns the next entry in the PTE list.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
ULONG_PTR
|
||||
MM::PageMapXpa::GetNextEntry(PMMPTE Pte)
|
||||
{
|
||||
/* Return next entry in PTE list */
|
||||
return Pte->Pml3.List.NextEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Advances a PTE pointer, considering the actual PTE size for PML3.
|
||||
*
|
||||
* @param Pte
|
||||
* The PTE pointer to advance.
|
||||
*
|
||||
* @return The advanced PTE pointer.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
PMMPTE
|
||||
MM::PageMapXpa::GetNextPte(PMMPTE Pte)
|
||||
{
|
||||
/* Return advanced PTE pointer */
|
||||
return AdvancePte(Pte, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a PTE list contains only one entry.
|
||||
*
|
||||
* @param Pte
|
||||
* The PTE pointer to check.
|
||||
*
|
||||
* @return This routine returns TRUE if the PTE list has only one entry, FALSE otherwise.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
BOOLEAN
|
||||
MM::PageMapXpa::GetOneEntry(PMMPTE Pte)
|
||||
{
|
||||
/* Return one entry status */
|
||||
return Pte->Pml3.List.OneEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of a PTE for XPA paging (PML3).
|
||||
*
|
||||
* @return This routine returns the size of a PTE.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
ULONG
|
||||
MM::PageMapXpa::GetPteSize(VOID)
|
||||
{
|
||||
/* Return the size of MMPTE */
|
||||
return sizeof(MMPML3_PTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes page map information for basic paging (PML3).
|
||||
*
|
||||
@@ -190,14 +546,17 @@ XTAPI
|
||||
VOID
|
||||
MM::PageMapXpa::InitializePageMapInfo(VOID)
|
||||
{
|
||||
/* Set PML2 page map information */
|
||||
/* Set PML3 page map information */
|
||||
PageMapInfo.Xpa = TRUE;
|
||||
|
||||
/* Set PML2 base addresses */
|
||||
/* Set PML3 empty PTE list mask */
|
||||
PageMapInfo.EmptyPteList = (ULONG)0xFFFFFFFF;
|
||||
|
||||
/* Set PML3 base addresses */
|
||||
PageMapInfo.PteBase = MM_PTE_BASE;
|
||||
PageMapInfo.PdeBase = MM_PDE_BASE;
|
||||
|
||||
/* Set PML2 shift values */
|
||||
/* Set PML3 shift values */
|
||||
PageMapInfo.PdiShift = MM_PDI_SHIFT;
|
||||
PageMapInfo.PteShift = MM_PTE_SHIFT;
|
||||
}
|
||||
@@ -219,6 +578,50 @@ MM::PageMapXpa::PteValid(PHARDWARE_PTE PtePointer)
|
||||
return (BOOLEAN)PtePointer->Pml3.Valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the next entry in a PTE list.
|
||||
*
|
||||
* @param Pte
|
||||
* The PTE pointer to modify.
|
||||
*
|
||||
* @param Value
|
||||
* The value to set as the next entry.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
MM::PageMapXpa::SetNextEntry(PMMPTE Pte,
|
||||
ULONG_PTR Value)
|
||||
{
|
||||
/* Set next entry in PTE list */
|
||||
Pte->Pml3.List.NextEntry = Value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the flag indicating whether a PTE list contains only one entry.
|
||||
*
|
||||
* @param Pte
|
||||
* The PTE pointer to modify.
|
||||
*
|
||||
* @param Value
|
||||
* The value to set. TRUE if the list has only one entry, FALSE otherwise.
|
||||
*
|
||||
* @return This routine does not return any value.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTAPI
|
||||
VOID
|
||||
MM::PageMapXpa::SetOneEntry(PMMPTE Pte,
|
||||
BOOLEAN Value)
|
||||
{
|
||||
/* Set one entry status */
|
||||
Pte->Pml3.List.OneEntry = Value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a PML3 page table entry (PTE) with the specified physical page and access flags.
|
||||
*
|
||||
@@ -241,6 +644,7 @@ MM::PageMapXpa::SetPte(PHARDWARE_PTE PtePointer,
|
||||
PFN_NUMBER PageFrameNumber,
|
||||
BOOLEAN Writable)
|
||||
{
|
||||
/* Set PTE */
|
||||
PtePointer->Pml3.PageFrameNumber = PageFrameNumber;
|
||||
PtePointer->Pml3.Valid = 1;
|
||||
PtePointer->Pml3.Writable = Writable;
|
||||
@@ -268,6 +672,7 @@ MM::PageMapXpa::SetPteCaching(PHARDWARE_PTE PtePointer,
|
||||
BOOLEAN CacheDisable,
|
||||
BOOLEAN WriteThrough)
|
||||
{
|
||||
/* Set caching attributes */
|
||||
PtePointer->Pml3.CacheDisable = CacheDisable;
|
||||
PtePointer->Pml3.WriteThrough = WriteThrough;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user