Skip to content

Commit 0448cfd

Browse files
gaojiaqi7jyao1
authored andcommitted
ResetVector: remove 5-level paging
5-level paging is not necessary in td-shim, remove the related code and page table entry in reset vector. td-shim checks the CR4.LA57 before setting the new page table, it will panic if the bit is set. Signed-off-by: Jiaqi Gao <[email protected]>
1 parent 51833bd commit 0448cfd

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

td-shim/ResetVector/Ia32/Flat32ToFlat64.asm

+1-19
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,11 @@ Transition32FlatTo64Flat:
1616

1717
mov eax, cr4
1818
bts eax, 5 ; enable PAE
19-
20-
;
21-
; esp [6:0] holds gpaw, if it is at least 52 bits, need to set
22-
; LA57 and use 5-level paging
23-
;
24-
mov ecx, esp
25-
and ecx, 0x2f
26-
cmp ecx, 52
27-
jl .set_cr4
28-
bts eax, 12
29-
.set_cr4:
3019
mov cr4, eax
3120

3221
mov ecx, ADDR_OF(TopLevelPageDirectory)
33-
;
34-
; if we just set la57, we are ok, if using 4-level paging, adjust top-level page directory
35-
;
36-
bt eax, 12
37-
jc .set_cr3
38-
add ecx, 0x1000
39-
.set_cr3:
22+
add ecx, 0x1000 ; point to level-4 page table entry
4023
mov cr3, ecx
41-
4224
mov eax, cr0
4325
bts eax, 31 ; set PG
4426
mov cr0, eax ; enable paging

td-shim/src/bin/td-shim/memory.rs

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use td_shim_interface::td_uefi_pi::pi::hob::{
1414
RESOURCE_SYSTEM_MEMORY,
1515
};
1616
use x86_64::{
17+
registers::control::{Cr4, Cr4Flags},
1718
structures::paging::PageTableFlags as Flags,
1819
structures::paging::{OffsetPageTable, PageTable},
1920
PhysAddr, VirtAddr,
@@ -125,6 +126,11 @@ impl<'a> Memory<'a> {
125126
}
126127
}
127128

129+
if Cr4::read().contains(Cr4Flags::L5_PAGING) {
130+
panic!(
131+
"5-Level paging is not supported by td-shim but it is enabled in CR4 unexpectedly"
132+
);
133+
}
128134
td_paging::cr3_write(
129135
self.get_layout_region(SliceType::PayloadPageTable)
130136
.base_address as u64,

0 commit comments

Comments
 (0)