Skip to contentSkip to conversation

x86: use EFI calling convention for efi_main on x86_64

PATCH Superseded Ivan Gorinov 3 participants 5 messages Jun 14, 2018 – Jun 15, 2018 x86

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 x86: use EFI calling convention for efi_main on x86_64

UEFI specifies the calling convention used in Microsoft compilers; first arguments of a function are passed in (%rcx, %rdx, %r8, %r9).

All other compilers use System V ABI by default, passing first integer arguments of a function in (%rdi, %rsi, %rdx, %rcx, %r8, %r9).

These ABI also specify different sets of registers that must be preserved across function calls (callee-saved).

GCC allows using the Microsoft calling convention by adding the ms_abi attribute to a function declaration.

Current EFI implementation in U-Boot specifies EFIAPI for efi_main() in the test apps but uses default calling convention in lib/efi.

Save efi_main() arguments in the startup code on x86_64; use EFI calling convention for _relocate() on x86_64; consistently use EFI calling convention for efi_main() everywhere.

v5:
Keeping unused _relocate() arguments, to be submitted as another patch.

v4:
Keeping .exit label in x86_64 startup code;
Also removed the unused _relocate() arguments for arm, x86, riscv.

v3:
Updated patch description.

v2:
Added EFIABI to _relocate() declaration.

Ivan Gorinov (1):
x86: use EFI calling convention for efi_main on x86_64

 arch/x86/lib/crt0_x86_64_efi.S | 24 +++++++++++++-----------
 lib/efi/efi_app.c              |  3 ++-
 lib/efi/efi_stub.c             |  3 ++-
 3 files changed, 17 insertions(+), 13 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v5 1/1 x86: use EFI calling convention for efi_main on x86_64

UEFI specifies the calling convention used in Microsoft compilers; first arguments of a function are passed in (%rcx, %rdx, %r8, %r9).

All other compilers use System V ABI by default, passing first integer arguments of a function in (%rdi, %rsi, %rdx, %rcx, %r8, %r9).

These ABI also specify different sets of registers that must be preserved across function calls (callee-saved).

GCC allows using the Microsoft calling convention by adding the ms_abi attribute to a function declaration.

Current EFI implementation in U-Boot specifies EFIAPI for efi_main() in the test apps but uses default calling convention in lib/efi.

Save efi_main() arguments in the startup code on x86_64; use EFI calling convention for _relocate() on x86_64; consistently use EFI calling convention for efi_main() everywhere.

---
 arch/x86/lib/crt0_x86_64_efi.S | 24 +++++++++++++-----------
 lib/efi/efi_app.c              |  3 ++-
 lib/efi/efi_stub.c             |  3 ++-
 3 files changed, 17 insertions(+), 13 deletions(-)
arch/x86/lib/crt0_x86_64_efi.S +13 -11
index 989799f..8a25ceb 100644
@@ -3,7 +3,7 @@
  * crt0-efi-x86_64.S - x86_64 EFI startup code.
  * Copyright (C) 1999 Hewlett-Packard Co.
  * Contributed by David Mosberger <[email protected]>.
- * Copyright (C) 2005 Intel Co.
+ * Copyright (C) 2005 Intel Corporation
  * Contributed by Fenghua Yu <[email protected]>.
  *
  * All rights reserved.
@@ -14,26 +14,28 @@
 	.globl _start
 _start:
 	subq $8, %rsp
+
 	pushq %rcx
 	pushq %rdx
 
-0:
-	lea image_base(%rip), %rdi
-	lea _DYNAMIC(%rip), %rsi
+	mov %rcx, %r8
+	mov %rdx, %r9
+
+	lea image_base(%rip), %rcx
+	lea _DYNAMIC(%rip), %rdx
 
-	popq %rcx
-	popq %rdx
-	pushq %rcx
-	pushq %rdx
 	call _relocate
 
-	popq %rdi
-	popq %rsi
+	popq %rdx
+	popq %rcx
+
+	testq %rax, %rax
+	jnz .exit
 
 	call efi_main
+.exit:
 	addq $8, %rsp
 
-.exit:
 	ret
 
 	/*
lib/efi/efi_app.c +2 -1
index c828093..3eb8eeb 100644
@@ -96,7 +96,8 @@ static void free_memory(struct efi_priv *priv)
  * U-Boot. If it returns, EFI will continue. Another way to get back to EFI
  * is via reset_cpu().
  */
-efi_status_t efi_main(efi_handle_t image, struct efi_system_table *sys_table)
+efi_status_t EFIAPI efi_main(efi_handle_t image,
+			     struct efi_system_table *sys_table)
 {
 	struct efi_priv local_priv, *priv = &local_priv;
 	efi_status_t ret;
lib/efi/efi_stub.c +2 -1
index 3138739..399d16b 100644
@@ -268,7 +268,8 @@ static void add_entry_addr(struct efi_priv *priv, enum efi_entry_t type,
  * This function is called by our EFI start-up code. It handles running
  * U-Boot. If it returns, EFI will continue.
  */
-efi_status_t efi_main(efi_handle_t image, struct efi_system_table *sys_table)
+efi_status_t EFIAPI efi_main(efi_handle_t image,
+			     struct efi_system_table *sys_table)
 {
 	struct efi_priv local_priv, *priv = &local_priv;
 	struct efi_boot_services *boot = sys_table->boottime;
Signature · 1 line
2.7.4
#2 lore raw

PATCH v5 1/1 x86: use EFI calling convention for efi_main on x86_64

Quoted 12 lines · Ivan Gorinov

UEFI specifies the calling convention used in Microsoft compilers; first arguments of a function are passed in (%rcx, %rdx, %r8, %r9).

All other compilers use System V ABI by default, passing first integer arguments of a function in (%rdi, %rsi, %rdx, %rcx, %r8, %r9).

These ABI also specify different sets of registers that must be preserved across function calls (callee-saved).

GCC allows using the Microsoft calling convention by adding the ms_abi attribute to a function declaration.

Quoted 8 lines

Current EFI implementation in U-Boot specifies EFIAPI for efi_main() in the test apps but uses default calling convention in lib/efi.

Save efi_main() arguments in the startup code on x86_64; use EFI calling convention for _relocate() on x86_64; consistently use EFI calling convention for efi_main() everywhere.

This patch should go via Bin's tree.

Alex

#3 lore raw

PATCH v5 1/1 x86: use EFI calling convention for efi_main on x86_64

In reply to Ivan Gorinov
Quoted 19 lines · Ivan Gorinov

UEFI specifies the calling convention used in Microsoft compilers; first arguments of a function are passed in (%rcx, %rdx, %r8, %r9).

All other compilers use System V ABI by default, passing first integer arguments of a function in (%rdi, %rsi, %rdx, %rcx, %r8, %r9).

These ABI also specify different sets of registers that must be preserved across function calls (callee-saved).

GCC allows using the Microsoft calling convention by adding the ms_abi attribute to a function declaration.

Current EFI implementation in U-Boot specifies EFIAPI for efi_main() in the test apps but uses default calling convention in lib/efi.

Save efi_main() arguments in the startup code on x86_64; use EFI calling convention for _relocate() on x86_64; consistently use EFI calling convention for efi_main() everywhere.

Quoted 7 lines
---
 arch/x86/lib/crt0_x86_64_efi.S | 24 +++++++++++++-----------
 lib/efi/efi_app.c              |  3 ++-
 lib/efi/efi_stub.c             |  3 ++-
 3 files changed, 17 insertions(+), 13 deletions(-)
#4 lore raw

PATCH v5 1/1 x86: use EFI calling convention for efi_main on x86_64

Quoted 28 lines · Bin Meng
Quoted 19 lines · Ivan Gorinov

UEFI specifies the calling convention used in Microsoft compilers; first arguments of a function are passed in (%rcx, %rdx, %r8, %r9).

All other compilers use System V ABI by default, passing first integer arguments of a function in (%rdi, %rsi, %rdx, %rcx, %r8, %r9).

These ABI also specify different sets of registers that must be preserved across function calls (callee-saved).

GCC allows using the Microsoft calling convention by adding the ms_abi attribute to a function declaration.

Current EFI implementation in U-Boot specifies EFIAPI for efi_main() in the test apps but uses default calling convention in lib/efi.

Save efi_main() arguments in the startup code on x86_64; use EFI calling convention for _relocate() on x86_64; consistently use EFI calling convention for efi_main() everywhere.

Quoted 7 lines
---
 arch/x86/lib/crt0_x86_64_efi.S | 24 +++++++++++++-----------
 lib/efi/efi_app.c              |  3 ++-
 lib/efi/efi_stub.c             |  3 ++-
 3 files changed, 17 insertions(+), 13 deletions(-)
Quoted 2 lines

applied to u-boot-x86, thanks!