From ca06f9ebb5fffe8ba08d4086d2887d3272fe4ea1 Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Sat, 2 Aug 2025 18:26:01 +0200 Subject: [PATCH] Correctly manage PAE state when enabling paging --- xtldr/modules/xtos_o/i686/memory.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/xtldr/modules/xtos_o/i686/memory.c b/xtldr/modules/xtos_o/i686/memory.c index 9134a68..3dd8e31 100644 --- a/xtldr/modules/xtos_o/i686/memory.c +++ b/xtldr/modules/xtos_o/i686/memory.c @@ -125,8 +125,21 @@ XtEnablePaging(IN PXTBL_PAGE_MAPPING PageMap) return STATUS_EFI_ABORTED; } - /* Enable Physical Address Extension (PAE) */ - ArWriteControlRegister(4, ArReadControlRegister(4) | CR4_PAE); + /* Disable paging */ + ArWriteControlRegister(0, ArReadControlRegister(0) & ~CR0_PG); + + if(PageMap->PageMapLevel == 3) + { + /* Enable Physical Address Extension (PAE) */ + XtLdrProtocol->Debug.Print(L"Enabling Physical Address Extension (PAE)\n"); + ArWriteControlRegister(4, ArReadControlRegister(4) | CR4_PAE); + } + else + { + /* Disable Physical Address Extension (PAE) */ + XtLdrProtocol->Debug.Print(L"Disabling Physical Address Extension (PAE)\n"); + ArWriteControlRegister(4, ArReadControlRegister(4) & ~CR4_PAE); + } /* Write page mappings to CR3 */ ArWriteControlRegister(3, (UINT_PTR)PageMap->PtePointer);