From: "Zhiguang Liu" <zhiguang.liu@intel.com>
To: devel@edk2.groups.io
Cc: Zhiguang Liu <zhiguang.liu@intel.com>,
Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>,
Rahul Kumar <rahul1.kumar@intel.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Debkumar De <debkumar.de@intel.com>,
Catharine West <catharine.west@intel.com>
Subject: [PATCH v4 2/5] UefiCpuPkg/ResetVector: Simplify page table creation in ResetVector
Date: Thu, 4 May 2023 09:55:14 +0800 [thread overview]
Message-ID: <20230504015517.2487-3-zhiguang.liu@intel.com> (raw)
In-Reply-To: <20230504015517.2487-1-zhiguang.liu@intel.com>
Currently, page table creation has many hard-code values about the
offset to the start of page table. To simplify it, add Labels such
as Pml4, Pdp and Pd, so that we can remove many hard-code values
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Debkumar De <debkumar.de@intel.com>
Cc: Catharine West <catharine.west@intel.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
.../ResetVector/Vtf0/Ia32/PageTables64.asm | 4 +--
.../ResetVector/Vtf0/X64/PageTables1G.asm | 18 ++++------
.../ResetVector/Vtf0/X64/PageTables2M.asm | 34 ++++++++-----------
3 files changed, 24 insertions(+), 32 deletions(-)
diff --git a/UefiCpuPkg/ResetVector/Vtf0/Ia32/PageTables64.asm b/UefiCpuPkg/ResetVector/Vtf0/Ia32/PageTables64.asm
index 87a4125d4b..f188da20ba 100644
--- a/UefiCpuPkg/ResetVector/Vtf0/Ia32/PageTables64.asm
+++ b/UefiCpuPkg/ResetVector/Vtf0/Ia32/PageTables64.asm
@@ -2,7 +2,7 @@
; @file
; Sets the CR3 register for 64-bit paging
;
-; Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.<BR>
+; Copyright (c) 2008 - 2023, Intel Corporation. All rights reserved.<BR>
; SPDX-License-Identifier: BSD-2-Clause-Patent
;
;------------------------------------------------------------------------------
@@ -17,7 +17,7 @@ SetCr3ForPageTables64:
;
; These pages are built into the ROM image in X64/PageTables.asm
;
- mov eax, ADDR_OF(TopLevelPageDirectory)
+ mov eax, ADDR_OF(Pml4)
mov cr3, eax
OneTimeCallRet SetCr3ForPageTables64
diff --git a/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables1G.asm b/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables1G.asm
index 94247c917d..2ab2d37507 100644
--- a/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables1G.asm
+++ b/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables1G.asm
@@ -29,35 +29,31 @@ BITS 64
PAGE_PRESENT + \
PAGE_SIZE)
-%define PGTBLS_OFFSET(x) ((x) - TopLevelPageDirectory)
-%define PGTBLS_ADDR(x) (ADDR_OF(TopLevelPageDirectory) + (x))
-
;
; Page table non-leaf entry
;
-%define PAGE_NLE(offset) (ADDR_OF(TopLevelPageDirectory) + (offset) + \
+%define PAGE_NLE(address) (ADDR_OF(address) + \
PAGE_NLE_ATTR)
%define PDPTE_1GB(x) ((x << 30) + PAGE_BLE_ATTR)
ALIGN 16
-TopLevelPageDirectory:
-
+Pml4:
;
- ; Top level Page Directory Pointers (1 * 512GB entry)
+ ; PML4 (1 * 512GB entry)
;
- DQ PAGE_NLE(0x1000)
+ DQ PAGE_NLE(Pdp)
+ TIMES 0x1000 - ($ - Pml4) DB 0
- TIMES 0x1000-PGTBLS_OFFSET($) DB 0
+Pdp:
;
- ; Next level Page Directory Pointers (512 * 1GB entries => 512GB)
+ ; Page-directory pointer table (512 * 1GB entries => 512GB)
;
%assign i 0
%rep 512
DQ PDPTE_1GB(i)
%assign i i+1
%endrep
- TIMES 0x2000-PGTBLS_OFFSET($) DB 0
EndOfPageTables:
diff --git a/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables2M.asm b/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables2M.asm
index f8fada0a2c..f5adf16630 100644
--- a/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables2M.asm
+++ b/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables2M.asm
@@ -28,36 +28,32 @@ BITS 64
PAGE_READ_WRITE + \
PAGE_PRESENT)
-%define PGTBLS_OFFSET(x) ((x) - TopLevelPageDirectory)
-%define PGTBLS_ADDR(x) (ADDR_OF(TopLevelPageDirectory) + (x))
-
-%define PAGE_NLE(offset) (ADDR_OF(TopLevelPageDirectory) + (offset) + \
+%define PAGE_NLE(address) (ADDR_OF(address) + \
PAGE_NLE_ATTR)
%define PDE_2MB(x) ((x << 21) + PAGE_BLE_ATTR)
-TopLevelPageDirectory:
-
+Pml4:
;
- ; Top level Page Directory Pointers (1 * 512GB entry)
+ ; PML4 (1 * 512GB entry)
;
- DQ PAGE_NLE(0x1000)
-
+ DQ PAGE_NLE(Pdp)
+ TIMES 0x1000 - ($ - Pml4) DB 0
+Pdp:
;
- ; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
+ ; Page-directory pointer table (4 * 1GB entries => 4GB)
;
- TIMES 0x1000-PGTBLS_OFFSET($) DB 0
-
- DQ PAGE_NLE(0x2000)
- DQ PAGE_NLE(0x3000)
- DQ PAGE_NLE(0x4000)
- DQ PAGE_NLE(0x5000)
+ DQ PAGE_NLE(Pd)
+ DQ PAGE_NLE(Pd + 0x1000)
+ DQ PAGE_NLE(Pd + 0x2000)
+ DQ PAGE_NLE(Pd + 0x3000)
+ TIMES 0x1000 - ($ - Pdp) DB 0
+Pd:
;
- ; Page Table Entries (2048 * 2MB entries => 4GB)
+ ; Page-Directory (2048 * 2MB entries => 4GB)
+ ; Four pages below, each is pointed by one entry in Pdp.
;
- TIMES 0x2000-PGTBLS_OFFSET($) DB 0
-
%assign i 0
%rep 0x800
DQ PDE_2MB(i)
--
2.31.1.windows.1
next prev parent reply other threads:[~2023-05-04 1:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-04 1:55 [PATCH v4 0/5] UefiCpuPkg/ResetVector: Refine page table creation, and support 5 Level paging Zhiguang Liu
2023-05-04 1:55 ` [PATCH v4 1/5] UefiCpuPkg/ResetVector: Rename macros about page table Zhiguang Liu
2023-05-04 1:55 ` Zhiguang Liu [this message]
2023-05-04 1:55 ` [PATCH v4 3/5] UefiCpuPkg/ResetVector: Combine PageTables1G.asm and PageTables2M.asm Zhiguang Liu
2023-05-04 1:55 ` [PATCH v4 4/5] UefiCpuPkg/ResetVector: Modify Page Table in ResetVector Zhiguang Liu
2023-05-04 2:01 ` Zhiguang Liu
2023-05-04 1:55 ` [PATCH v4 5/5] UefiCpuPkg/ResetVector: Support 5 level page table " Zhiguang Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230504015517.2487-3-zhiguang.liu@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox