Skip to contentSkip to conversation

x86: use EFI calling convention for efi_main on x86_64

PATCH Superseded Ivan Gorinov 2 participants 2 messages May 25, 2018 – May 26, 2018 x86

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

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

Save the arguments passed in %rcx and %rdx for efi_main() on x86_64; consistently use EFI calling convention for efi_main().

---
 arch/x86/lib/crt0_x86_64_efi.S | 8 ++++----
 lib/efi/efi_app.c              | 3 ++-
 lib/efi/efi_stub.c             | 3 ++-
 3 files changed, 8 insertions(+), 6 deletions(-)
arch/x86/lib/crt0_x86_64_efi.S +4 -4
index 989799f..2d53d1b 100644
@@ -16,19 +16,19 @@ _start:
 	subq $8, %rsp
 	pushq %rcx
 	pushq %rdx
+	pushq %rsi
+	pushq %rdi
 
 0:
 	lea image_base(%rip), %rdi
 	lea _DYNAMIC(%rip), %rsi
 
-	popq %rcx
-	popq %rdx
-	pushq %rcx
-	pushq %rdx
 	call _relocate
 
 	popq %rdi
 	popq %rsi
+	popq %rdx
+	popq %rcx
 
 	call efi_main
 	addq $8, %rsp
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
#1 lore raw

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

Quoted 4 lines · Ivan Gorinov

Save the arguments passed in %rcx and %rdx for efi_main() on x86_64; consistently use EFI calling convention for efi_main().

One big difference between the ms_abi and the sysv_abi calling convention is the set of volatile registers. So shouldn't _relocate() also be declared as EFIAPI to ensure that we do not mess up the callers registers?

Best regards

Heinrich

Quoted 63 lines
---
 arch/x86/lib/crt0_x86_64_efi.S | 8 ++++----
 lib/efi/efi_app.c              | 3 ++-
 lib/efi/efi_stub.c             | 3 ++-
 3 files changed, 8 insertions(+), 6 deletions(-)
arch/x86/lib/crt0_x86_64_efi.S +4 -4
index 989799f..2d53d1b 100644
@@ -16,19 +16,19 @@ _start:
 	subq $8, %rsp
 	pushq %rcx
 	pushq %rdx
+	pushq %rsi
+	pushq %rdi
 
 0:
 	lea image_base(%rip), %rdi
 	lea _DYNAMIC(%rip), %rsi
 
-	popq %rcx
-	popq %rdx
-	pushq %rcx
-	pushq %rdx
 	call _relocate
 
 	popq %rdi
 	popq %rsi
+	popq %rdx
+	popq %rcx
 
 	call efi_main
 	addq $8, %rsp
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;