From cf5fc2312aa21d6a9cc9dea6fe3bb905a2f64086 Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Thu, 9 May 2024 11:25:22 +0000 Subject: [PATCH] include/efi: Override EFIAPI macro for x86_64 This commit overrides the EFIAPI macro definition when using FSP on x86_64 to ensure the correct calling convention is used. On i386, there is no side-effect since the C calling convention used by coreboot and FSP are the same. However, on x86_64, FSP/UEFI uses the Microsoft x64 calling convention while coreboot uses the System V AMD64 ABI. This change resolves this incompatibility by setting EFIAPI to attribute((ms_abi)) on x86_64 when using FSP. TEST=Able to build google/rex0 in 32-bit and 64-bit mode. Change-Id: Ifae910be66d550af04cce5136d186a7e9dd085b3 Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/82266 Reviewed-by: Ronak Kanabar Reviewed-by: Eric Lai Tested-by: build bot (Jenkins) --- src/include/efi/efi_datatype.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/include/efi/efi_datatype.h b/src/include/efi/efi_datatype.h index 0333a84a4e..d4152af754 100644 --- a/src/include/efi/efi_datatype.h +++ b/src/include/efi/efi_datatype.h @@ -3,6 +3,22 @@ /* Create EFI equivalent datatype in coreboot based on UEFI specification */ #ifndef __EFI_DATATYPE_H__ #define __EFI_DATATYPE_H__ + +/* + * EDK2 EFIAPI macro definition relies on compiler flags such as __GNUC__ which + * is not working well when included by coreboot. While it has no side-effect on + * i386 because the C calling convention used by coreboot and FSP are the same, + * it breaks on x86_64 because FSP/UEFI uses the Microsoft x64 calling + * convention while coreboot uses the System V AMD64 ABI. + * + * Fortunately, EDK2 header allows to override EFIAPI. + */ +#if CONFIG(PLATFORM_USES_FSP2_X86_32) +#define EFIAPI __attribute__((regparm(0))) +#else +#define EFIAPI __attribute__((__ms_abi__)) +#endif + #include #include