From b9f41799b42bc017c34ea2f49aabf4592f951c5a Mon Sep 17 00:00:00 2001 From: mintsuki Date: Thu, 22 Sep 2022 18:10:08 +0200 Subject: [PATCH] linux/efi: Perform efi_memmap_size=0 workaround for 32 on 64 as well --- common/protos/linux.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/common/protos/linux.c b/common/protos/linux.c index 1afcf38f..58ae4a0b 100644 --- a/common/protos/linux.c +++ b/common/protos/linux.c @@ -30,6 +30,8 @@ noreturn void linux_spinup(void *entry, void *boot_params); #define E820_MAX_ENTRIES_ZEROPAGE 128 #define EDDMAXNR 6 +#define XLF_KERNEL_64 (1 << 0) + struct setup_header { uint8_t setup_sects; uint16_t root_flags; @@ -591,13 +593,18 @@ set_textmode:; boot_params->efi_info.efi_memmap = (uint32_t)(uint64_t)(uintptr_t)efi_mmap; boot_params->efi_info.efi_memmap_hi = (uint32_t)((uint64_t)(uintptr_t)efi_mmap >> 32); #if defined (__x86_64__) - boot_params->efi_info.efi_memmap_size = efi_mmap_size; + if ((setup_header->xloadflags & XLF_KERNEL_64) == 0) { #elif defined (__i386__) - // A memmap size of 0 will cause Linux to force bail out of trying to use - // 32-bit EFI runtime services without ignoring other EFI info. - // XXX: Figure out why 64-bit Linux hangs if trying to use 32-bit boot services. - boot_params->efi_info.efi_memmap_size = 0; + if ((setup_header->xloadflags & XLF_KERNEL_64) != 0) { #endif + // A memmap size of 0 will cause Linux to force bail out of trying to use + // mismatched bitness EFI runtime services without ignoring other EFI info. + // XXX: Figure out why 64-bit Linux hangs if trying to use 32-bit boot services, + // and vice versa. + boot_params->efi_info.efi_memmap_size = 0; + } else { + boot_params->efi_info.efi_memmap_size = efi_mmap_size; + } boot_params->efi_info.efi_memdesc_size = efi_desc_size; boot_params->efi_info.efi_memdesc_version = efi_desc_ver; #endif