From a5fda5546ad06b47ce197e06238e7a30ebbace86 Mon Sep 17 00:00:00 2001 From: Mintsuki Date: Mon, 16 Jun 2025 04:31:46 +0200 Subject: [PATCH] Manually attempt to allocate all conventional memory early Doing this instead of permanently raising TPL, which can cause issues in other more unpredicatable ways. --- src/csmwrap.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/csmwrap.c b/src/csmwrap.c index 2a9f49c..f23bf8c 100644 --- a/src/csmwrap.c +++ b/src/csmwrap.c @@ -98,14 +98,22 @@ EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) gBS = SystemTable->BootServices; gRT = SystemTable->RuntimeServices; + printf("%s", banner); + + for (uintptr_t i = 0; i < 0x100000; i += EFI_PAGE_SIZE) { + uintptr_t j = i; + if (gBS->AllocatePages(AllocateAddress, EfiLoaderData, 1, &j) != EFI_SUCCESS) { + if (i < 0xa0000) { + printf("warning: Early AllocatePages() failed for address %p\n", i); + } + } + } + if (gRT->GetTime(&gTimeAtBoot, NULL) != EFI_SUCCESS) { printf("Failed to query current time\n"); return -1; } - printf("%s", banner); - - gBS->RaiseTPL(TPL_NOTIFY); gBS->SetWatchdogTimer(0, 0, 0, NULL); if (unlock_bios_region()) {