/* Get the leaf entry for a given linear address from a page table */
UINT64 GetEntryFromPageTable(IN UINTN PageTable, IN PAGING_MODE PagingMode, IN UINT64 Address, OUT UINTN *Level)
/* Get the leaf entry for a given linear address from a page table */
UINT64 GetEntryFromPageTable(IN UINTN PageTable, IN PAGING_MODE PagingMode, IN UINT64 Address, OUT UINTN *Level)
{
  UINTN              MaxLevel;
  UINTN              MaxLeafLevel;
  UINT64             Index;
  IA32_PAGING_ENTRY  *PagingEntry;
  if ((PagingMode == Paging32bit) || (PagingMode >= PagingModeMax)) {
    return 0;
  }
  MaxLeafLevel = (UINT8)PagingMode;
  MaxLevel     = (UINT8)(PagingMode >> 8);
  Index = Address >> (MaxLevel * 9 + 3);
  ASSERT (Index == (Index & ((1<< 9) - 1)));
  PagingEntry = (IA32_PAGING_ENTRY *)(UINTN)PageTable;
  *Level      = MaxLevel;
  return GetEntryFromSubPageTable (&PagingEntry[Index], Level, MaxLeafLevel, Address - (Index << (9 * MaxLevel + 3)));
}