From 2ef7fd71867763b057bb644d9ed9cfc9ac0b8b4c Mon Sep 17 00:00:00 2001 From: PulkoMandy Date: Wed, 30 Dec 2020 18:59:41 +0100 Subject: [PATCH] bootloader elf: fix elf64 loading for non-x86 platforms Some code was enabled only for EFI, but is in fact correct for all platforms except BIOS. Switch the defines around to have the correct code enabled by default. Change-Id: I58b1d17a78dcf273ceee88318338b4770b500bb3 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3566 Reviewed-by: waddlesplash --- src/system/boot/loader/elf.cpp | 26 +++++++++------------- src/system/boot/platform/bios_ia32/Jamfile | 2 +- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/system/boot/loader/elf.cpp b/src/system/boot/loader/elf.cpp index 1a39c96001..b0e3e58be7 100644 --- a/src/system/boot/loader/elf.cpp +++ b/src/system/boot/loader/elf.cpp @@ -119,21 +119,14 @@ struct ELF64Class { AllocateRegion(AddrType* _address, AddrType size, uint8 protection, void **_mappedAddress) { -#ifdef _BOOT_PLATFORM_EFI - void* address = (void*)*_address; - - status_t status = platform_allocate_region(&address, size, protection, - false); - if (status != B_OK) - return status; - - *_mappedAddress = address; - platform_bootloader_address_to_kernel_address(address, _address); -#else +#if defined(_BOOT_PLATFORM_BIOS) // Assume the real 64-bit base address is KERNEL_LOAD_BASE_64_BIT and // the mappings in the loader address space are at KERNEL_LOAD_BASE. void* address = (void*)(addr_t)(*_address & 0xffffffff); +#else + void* address = (void*)*_address; +#endif status_t status = platform_allocate_region(&address, size, protection, false); @@ -141,8 +134,11 @@ struct ELF64Class { return status; *_mappedAddress = address; +#if defined(_BOOT_PLATFORM_BIOS) *_address = (AddrType)(addr_t)address + KERNEL_LOAD_BASE_64_BIT - KERNEL_LOAD_BASE; +#else + platform_bootloader_address_to_kernel_address(address, _address); #endif return B_OK; } @@ -150,15 +146,15 @@ struct ELF64Class { static inline void* Map(AddrType address) { -#ifdef _BOOT_PLATFORM_EFI +#ifdef _BOOT_PLATFORM_BIOS + return (void*)(addr_t)(address - KERNEL_LOAD_BASE_64_BIT + + KERNEL_LOAD_BASE); +#else void *result; if (platform_kernel_address_to_bootloader_address(address, &result) != B_OK) { panic("Couldn't convert address %#lx", address); } return result; -#else - return (void*)(addr_t)(address - KERNEL_LOAD_BASE_64_BIT - + KERNEL_LOAD_BASE); #endif } }; diff --git a/src/system/boot/platform/bios_ia32/Jamfile b/src/system/boot/platform/bios_ia32/Jamfile index 872ced4d4a..6c44677fb9 100644 --- a/src/system/boot/platform/bios_ia32/Jamfile +++ b/src/system/boot/platform/bios_ia32/Jamfile @@ -8,7 +8,7 @@ UsePrivateHeaders [ FDirName graphics vesa ] ; UsePrivateHeaders [ FDirName storage ] ; { - local defines = _BOOT_MODE ; + local defines = _BOOT_MODE _BOOT_PLATFORM_BIOS ; defines = [ FDefines $(defines) ] ; SubDirCcFlags $(defines) ;