10#include "../CpuPageTable.h"
12#define IA32_PAE_RESERVED_MASK 0x7FF0000000000000ull
37 ASSERT (MemorySpace <= 52);
38 mValidMaskNoLeaf[0].Uint64 = 0;
39 mValidMaskLeaf[0].Uint64 = 0;
40 mValidMaskLeafFlag[0].Uint64 = 0;
45 for (Index = 1; Index < 6; Index++) {
46 mValidMaskNoLeaf[Index].Uint64 = MAX_UINT64;
47 mValidMaskLeaf[Index].Uint64 = MAX_UINT64;
52 if (MemorySpace - 1 < 51) {
53 mValidMaskNoLeaf[Index].Uint64 =
BitFieldWrite64 (mValidMaskNoLeaf[Index].Uint64, MemorySpace - 1, 51, 0);
54 mValidMaskLeaf[Index].Uint64 =
BitFieldWrite64 (mValidMaskLeaf[Index].Uint64, MemorySpace - 1, 51, 0);
61 mValidMaskNoLeaf[1].Uint64 = 0;
62 mValidMaskNoLeaf[2].Pnle.Bits.MustBeZero = 0;
63 mValidMaskNoLeaf[3].Pnle.Bits.MustBeZero = 0;
64 mValidMaskNoLeaf[4].Pml4.Bits.MustBeZero = 0;
65 mValidMaskNoLeaf[5].Pml4.Bits.MustBeZero = 0;
71 mValidMaskLeaf[2].Uint64 =
BitFieldWrite64 (mValidMaskLeaf[2].Uint64, 13, 20, 0);
72 mValidMaskLeaf[3].Uint64 =
BitFieldWrite64 (mValidMaskLeaf[2].Uint64, 13, 29, 0);
73 mValidMaskLeaf[4].Uint64 = 0;
74 mValidMaskLeaf[5].Uint64 = 0;
80 mValidMaskLeafFlag[1].Pce.Present = 1;
84 mValidMaskLeafFlag[2].Pde2M.Bits.MustBeOne = 1;
85 mValidMaskLeafFlag[2].Pde2M.Bits.Present = 1;
86 mValidMaskLeafFlag[3].Pde2M.Bits.MustBeOne = 1;
87 mValidMaskLeafFlag[3].Pde2M.Bits.Present = 1;
88 mValidMaskLeafFlag[4].Uint64 = MAX_UINT64;
89 mValidMaskLeafFlag[5].Uint64 = MAX_UINT64;
109 IN PAGING_MODE PagingMode
116 if (PagingMode == PagingPae) {
120 if (PagingEntry->Pce.Present == 0) {
121 return UNIT_TEST_PASSED;
124 if ((PagingEntry->Uint64 & mValidMaskLeafFlag[Level].Uint64) == mValidMaskLeafFlag[Level].Uint64) {
128 if (Level > MaxLeafLevel) {
129 DEBUG ((DEBUG_ERROR,
"ERROR: Level %d entry 0x%lx is a leaf entry, but max leaf level is %d \n", Level, PagingEntry->Uint64, MaxLeafLevel));
133 if ((PagingEntry->Uint64 & mValidMaskLeaf[Level].Uint64) != PagingEntry->Uint64) {
134 DEBUG ((DEBUG_ERROR,
"ERROR: Level %d Leaf entry is 0x%lx, which reserved bit is set \n", Level, PagingEntry->Uint64));
135 UT_ASSERT_EQUAL ((PagingEntry->Uint64 & mValidMaskLeaf[Level].Uint64), PagingEntry->Uint64);
138 return UNIT_TEST_PASSED;
145 if ((PagingEntry->Uint64 & mValidMaskNoLeaf[Level].Uint64) != PagingEntry->Uint64) {
146 DEBUG ((DEBUG_ERROR,
"ERROR: Level %d no Leaf entry is 0x%lx, which reserved bit is set \n", Level, PagingEntry->Uint64));
147 UT_ASSERT_EQUAL ((PagingEntry->Uint64 & mValidMaskNoLeaf[Level].Uint64), PagingEntry->Uint64);
151 for (Index = 0; Index < 512; Index++) {
152 Status =
IsPageTableEntryValid (&ChildPageEntry[Index], Level-1, MaxLeafLevel, Address + (Index<<(9*(Level-1) + 3)), PagingMode);
153 if (Status != UNIT_TEST_PASSED) {
158 return UNIT_TEST_PASSED;
172 IN PAGING_MODE PagingMode
181 if (PageTable == 0) {
182 return UNIT_TEST_PASSED;
185 if ((PagingMode == Paging32bit) || (PagingMode >= PagingModeMax)) {
189 return UNIT_TEST_ERROR_TEST_FAILED;
192 MaxLeafLevel = (UINT8)PagingMode;
193 MaxLevel = (UINT8)(PagingMode >> 8);
196 for (Index = 0; Index < ((PagingMode == PagingPae) ? 4 : 512); Index++) {
197 if (PagingMode == PagingPae) {
203 Status =
IsPageTableEntryValid (&PagingEntry[Index], MaxLevel, MaxLeafLevel, Index << (9 * MaxLevel + 3), PagingMode);
204 if (Status != UNIT_TEST_PASSED) {
234 if (PagingEntry->Pce.Present == 0) {
238 if ((PagingEntry->Uint64 & mValidMaskLeafFlag[*Level].Uint64) == mValidMaskLeafFlag[*Level].Uint64) {
242 return PagingEntry->Uint64;
250 Index = Address >> (*Level * 9 + 3);
251 ASSERT (Index == (Index & ((1<< 9) - 1)));
253 return GetEntryFromSubPageTable (&ChildPageEntry[Index], Level, MaxLeafLevel, Address - (Index << (9 * *Level + 3)));
269 IN PAGING_MODE PagingMode,
279 if ((PagingMode == Paging32bit) || (PagingMode >= PagingModeMax)) {
287 MaxLeafLevel = (UINT8)PagingMode;
288 MaxLevel = (UINT8)(PagingMode >> 8);
290 Index = Address >> (MaxLevel * 9 + 3);
291 ASSERT (Index == (Index & ((1<< 9) - 1)));
295 return GetEntryFromSubPageTable (&PagingEntry[Index], Level, MaxLeafLevel, Address - (Index << (9 * MaxLevel + 3)));
316 case Paging4Level1GB:
318 case Paging5Level1GB:
319 return 1ull <<
MIN (12 + (Mode >> 8) * 9, 52);
UINT64 EFIAPI BitFieldWrite64(IN UINT64 Operand, IN UINTN StartBit, IN UINTN EndBit, IN UINT64 Value)
#define DEBUG(Expression)
UINT64 GetEntryFromPageTable(IN UINTN PageTable, IN PAGING_MODE PagingMode, IN UINT64 Address, OUT UINTN *Level)
UNIT_TEST_STATUS IsPageTableValid(IN UINTN PageTable, IN PAGING_MODE PagingMode)
UINT64 GetEntryFromSubPageTable(IN IA32_PAGING_ENTRY *PagingEntry, IN OUT UINTN *Level, IN UINTN MaxLeafLevel, IN UINT64 Address)
VOID InitGlobalData(UINTN MemorySpace)
UNIT_TEST_STATUS IsPageTableEntryValid(IN IA32_PAGING_ENTRY *PagingEntry, IN UINTN Level, IN UINTN MaxLeafLevel, IN UINT64 Address, IN PAGING_MODE PagingMode)
UINT64 GetMaxAddress(IN PAGING_MODE Mode)
#define UT_ASSERT_NOT_EQUAL(ValueA, ValueB)
#define UT_ASSERT_TRUE(Expression)
#define UT_ASSERT_EQUAL(ValueA, ValueB)