2 Internal header for CpuPageTableLib.
4 Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef CPU_PAGE_TABLE_H_
10 #define CPU_PAGE_TABLE_H_
13 #include <Library/BaseLib.h>
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/DebugLib.h>
16 #include <Library/CpuPageTableLib.h>
18 #define IA32_PE_BASE_ADDRESS_MASK_40 0xFFFFFFFFFF000ull
19 #define IA32_PE_BASE_ADDRESS_MASK_39 0xFFFFFFFFFE000ull
21 #define REGION_LENGTH(l) LShiftU64 (1, (l) * 9 + 3)
24 UINT64 Present
: 1; // 0 = Not present in memory, 1 = Present in memory
25 UINT64 ReadWrite
: 1; // 0 = Read-Only, 1= Read/Write
26 UINT64 UserSupervisor
: 1; // 0 = Supervisor, 1=User
28 UINT64 Nx
: 1; // No Execute bit
29 } IA32_PAGE_COMMON_ENTRY
;
32 /// Format of a non-leaf entry that references a page table entry
36 UINT64 Present
: 1; // 0 = Not present in memory, 1 = Present in memory
37 UINT64 ReadWrite
: 1; // 0 = Read-Only, 1= Read/Write
38 UINT64 UserSupervisor
: 1; // 0 = Supervisor, 1=User
39 UINT64 WriteThrough
: 1; // 0 = Write-Back caching, 1=Write-Through caching
40 UINT64 CacheDisabled
: 1; // 0 = Cached, 1=Non-Cached
41 UINT64 Accessed
: 1; // 0 = Not accessed, 1 = Accessed (set by CPU)
42 UINT64 Available0
: 1; // Ignored
43 UINT64 MustBeZero
: 1; // Must Be Zero
45 UINT64 Available2
: 4; // Ignored
47 UINT64 PageTableBaseAddress
: 40; // Page Table Base Address
48 UINT64 Available3
: 11; // Ignored
49 UINT64 Nx
: 1; // No Execute bit
52 } IA32_PAGE_NON_LEAF_ENTRY
;
54 #define IA32_PNLE_PAGE_TABLE_BASE_ADDRESS(pa) ((pa)->Uint64 & IA32_PE_BASE_ADDRESS_MASK_40)
57 /// Format of a PML5 Entry (PML5E) that References a PML4 Table
59 typedef IA32_PAGE_NON_LEAF_ENTRY IA32_PML5E
;
62 /// Format of a PML4 Entry (PML4E) that References a Page-Directory-Pointer Table
64 typedef IA32_PAGE_NON_LEAF_ENTRY IA32_PML4E
;
67 /// Format of a Page-Directory-Pointer-Table Entry (PDPTE) that References a Page Directory
69 typedef IA32_PAGE_NON_LEAF_ENTRY IA32_PDPTE
;
72 /// Format of a Page-Directory Entry that References a Page Table
74 typedef IA32_PAGE_NON_LEAF_ENTRY IA32_PDE
;
77 /// Format of a leaf entry that Maps a 1-Gbyte or 2-MByte Page
81 UINT64 Present
: 1; // 0 = Not present in memory, 1 = Present in memory
82 UINT64 ReadWrite
: 1; // 0 = Read-Only, 1= Read/Write
83 UINT64 UserSupervisor
: 1; // 0 = Supervisor, 1=User
84 UINT64 WriteThrough
: 1; // 0 = Write-Back caching, 1=Write-Through caching
85 UINT64 CacheDisabled
: 1; // 0 = Cached, 1=Non-Cached
86 UINT64 Accessed
: 1; // 0 = Not accessed, 1 = Accessed (set by CPU)
87 UINT64 Dirty
: 1; // 0 = Not dirty, 1 = Dirty (set by CPU)
88 UINT64 MustBeOne
: 1; // Page Size. Must Be One
90 UINT64 Global
: 1; // 0 = Not global, 1 = Global (if CR4.PGE = 1)
91 UINT64 Available1
: 3; // Ignored
92 UINT64 Pat
: 1; // PAT
94 UINT64 PageTableBaseAddress
: 39; // Page Table Base Address
95 UINT64 Available3
: 7; // Ignored
96 UINT64 ProtectionKey
: 4; // Protection key
97 UINT64 Nx
: 1; // No Execute bit
100 } IA32_PAGE_LEAF_ENTRY_BIG_PAGESIZE
;
101 #define IA32_PLEB_PAGE_TABLE_BASE_ADDRESS(pa) ((pa)->Uint64 & IA32_PE_BASE_ADDRESS_MASK_39)
104 /// Format of a Page-Directory Entry that Maps a 2-MByte Page
106 typedef IA32_PAGE_LEAF_ENTRY_BIG_PAGESIZE IA32_PDE_2M
;
109 /// Format of a Page-Directory-Pointer-Table Entry (PDPTE) that Maps a 1-GByte Page
111 typedef IA32_PAGE_LEAF_ENTRY_BIG_PAGESIZE IA32_PDPTE_1G
;
114 /// Format of a Page-Table Entry that Maps a 4-KByte Page
118 UINT64 Present
: 1; // 0 = Not present in memory, 1 = Present in memory
119 UINT64 ReadWrite
: 1; // 0 = Read-Only, 1= Read/Write
120 UINT64 UserSupervisor
: 1; // 0 = Supervisor, 1=User
121 UINT64 WriteThrough
: 1; // 0 = Write-Back caching, 1=Write-Through caching
122 UINT64 CacheDisabled
: 1; // 0 = Cached, 1=Non-Cached
123 UINT64 Accessed
: 1; // 0 = Not accessed, 1 = Accessed (set by CPU)
124 UINT64 Dirty
: 1; // 0 = Not dirty, 1 = Dirty (set by CPU)
125 UINT64 Pat
: 1; // PAT
127 UINT64 Global
: 1; // 0 = Not global, 1 = Global (if CR4.PGE = 1)
128 UINT64 Available1
: 3; // Ignored
130 UINT64 PageTableBaseAddress
: 40; // Page Table Base Address
131 UINT64 Available3
: 7; // Ignored
132 UINT64 ProtectionKey
: 4; // Protection key
133 UINT64 Nx
: 1; // No Execute bit
137 #define IA32_PTE4K_PAGE_TABLE_BASE_ADDRESS(pa) ((pa)->Uint64 & IA32_PE_BASE_ADDRESS_MASK_40)
140 /// Format of a Page-Directory-Pointer-Table Entry (PDPTE) that References a Page Directory (32bit PAE specific)
144 UINT64 Present
: 1; // 0 = Not present in memory, 1 = Present in memory
145 UINT64 MustBeZero
: 2; // Must Be Zero
146 UINT64 WriteThrough
: 1; // 0 = Write-Back caching, 1=Write-Through caching
147 UINT64 CacheDisabled
: 1; // 0 = Cached, 1=Non-Cached
148 UINT64 MustBeZero2
: 4; // Must Be Zero
150 UINT64 Available
: 3; // Ignored
152 UINT64 PageTableBaseAddress
: 40; // Page Table Base Address
153 UINT64 MustBeZero3
: 12; // Must Be Zero
159 IA32_PAGE_NON_LEAF_ENTRY Pnle
; // To access Pml5, Pml4, Pdpte and Pde.
165 IA32_PAGE_LEAF_ENTRY_BIG_PAGESIZE PleB
; // to access Pdpte1G and Pde2M.
166 IA32_PDPTE_1G Pdpte1G
;
171 IA32_PDPTE_PAE PdptePae
;
172 IA32_PAGE_COMMON_ENTRY Pce
; // To access all common bits in above entries.
179 Return TRUE when the page table entry is a leaf entry that points to the physical address memory.
180 Return FALSE when the page table entry is a non-leaf entry that points to the page table entries.
182 @param[in] PagingEntry Pointer to the page table entry.
183 @param[in] Level Page level where the page table entry resides in.
185 @retval TRUE It's a leaf entry.
186 @retval FALSE It's a non-leaf entry.
190 IN IA32_PAGING_ENTRY
*PagingEntry
,
195 Return the attribute of a 2M/1G page table entry.
197 @param[in] PleB Pointer to a 2M/1G page table entry.
198 @param[in] ParentMapAttribute Pointer to the parent attribute.
200 @return Attribute of the 2M/1G page table entry.
203 PageTableLibGetPleBMapAttribute (
204 IN IA32_PAGE_LEAF_ENTRY_BIG_PAGESIZE
*PleB
,
205 IN IA32_MAP_ATTRIBUTE
*ParentMapAttribute
209 Return the attribute of a non-leaf page table entry.
211 @param[in] Pnle Pointer to a non-leaf page table entry.
212 @param[in] ParentMapAttribute Pointer to the parent attribute.
214 @return Attribute of the non-leaf page table entry.
217 PageTableLibGetPnleMapAttribute (
218 IN IA32_PAGE_NON_LEAF_ENTRY
*Pnle
,
219 IN IA32_MAP_ATTRIBUTE
*ParentMapAttribute