Skip to content

Commit

Permalink
ResetVector: remove 5-level paging
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
gaojiaqi7 authored and jyao1 committed Sep 19, 2024
1 parent 51833bd commit 0448cfd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
20 changes: 1 addition & 19 deletions td-shim/ResetVector/Ia32/Flat32ToFlat64.asm
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,11 @@ Transition32FlatTo64Flat:

mov eax, cr4
bts eax, 5 ; enable PAE

;
; esp [6:0] holds gpaw, if it is at least 52 bits, need to set
; LA57 and use 5-level paging
;
mov ecx, esp
and ecx, 0x2f
cmp ecx, 52
jl .set_cr4
bts eax, 12
.set_cr4:
mov cr4, eax

mov ecx, ADDR_OF(TopLevelPageDirectory)
;
; if we just set la57, we are ok, if using 4-level paging, adjust top-level page directory
;
bt eax, 12
jc .set_cr3
add ecx, 0x1000
.set_cr3:
add ecx, 0x1000 ; point to level-4 page table entry
mov cr3, ecx

mov eax, cr0
bts eax, 31 ; set PG
mov cr0, eax ; enable paging
Expand Down
6 changes: 6 additions & 0 deletions td-shim/src/bin/td-shim/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use td_shim_interface::td_uefi_pi::pi::hob::{
RESOURCE_SYSTEM_MEMORY,
};
use x86_64::{
registers::control::{Cr4, Cr4Flags},
structures::paging::PageTableFlags as Flags,
structures::paging::{OffsetPageTable, PageTable},
PhysAddr, VirtAddr,
Expand Down Expand Up @@ -125,6 +126,11 @@ impl<'a> Memory<'a> {
}
}

if Cr4::read().contains(Cr4Flags::L5_PAGING) {
panic!(
"5-Level paging is not supported by td-shim but it is enabled in CR4 unexpectedly"
);
}
td_paging::cr3_write(
self.get_layout_region(SliceType::PayloadPageTable)
.base_address as u64,
Expand Down

0 comments on commit 0448cfd

Please sign in to comment.