2 Function to create page talbe.
3 Only create page table for x64, and leave the CreatePageTable empty for Ia32.
4 Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
7 #include <Library/CpuPageTableLib.h>
8 #include <Library/MemoryAllocationLib.h>
10 #include <Library/BaseMemoryLib.h>
11 #include <Library/DebugLib.h>
12 #include <Library/BaseLib.h>
15 Create 1:1 mapping page table in reserved memory to map the specified address range.
16 @param[in] LinearAddress The start of the linear address range.
17 @param[in] Length The length of the linear address range.
18 @return The page table to be created.
27 VOID
*PageTableBuffer
;
28 UINTN PageTableBufferSize
;
30 PAGING_MODE PagingMode
;
33 IA32_MAP_ATTRIBUTE MapAttribute
;
34 IA32_MAP_ATTRIBUTE MapMask
;
36 MapAttribute
.Uint64
= Address
;
37 MapAttribute
.Bits
.Present
= 1;
38 MapAttribute
.Bits
.ReadWrite
= 1;
40 MapMask
.Bits
.PageTableBaseAddress
= 1;
41 MapMask
.Bits
.Present
= 1;
42 MapMask
.Bits
.ReadWrite
= 1;
45 PageTableBufferSize
= 0;
47 Cr4
.UintN
= AsmReadCr4 ();
49 if (Cr4
.Bits
.LA57
== 1) {
50 PagingMode
= Paging5Level
;
52 PagingMode
= Paging4Level
;
55 Status
= PageTableMap (
65 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
66 DEBUG ((DEBUG_INFO
, "AP Page Table Buffer Size = %x\n", PageTableBufferSize
));
68 PageTableBuffer
= AllocateReservedPages (EFI_SIZE_TO_PAGES (PageTableBufferSize
));
69 ASSERT (PageTableBuffer
!= NULL
);
70 Status
= PageTableMap (
80 ASSERT_EFI_ERROR (Status
);