Commit 9f0b0113c975d08c7fc5a509d67f128515486c0c

Authored by Ivan Gorinov
Committed by Bin Meng
1 parent e3ec0d03bb

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.

Signed-off-by: Ivan Gorinov <ivan.gorinov@intel.com>
Reviewed-by: Alexander Graf <agraf@suse.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

Showing 3 changed files with 17 additions and 13 deletions Side-by-side Diff

arch/x86/lib/crt0_x86_64_efi.S
... ... @@ -3,7 +3,7 @@
3 3 * crt0-efi-x86_64.S - x86_64 EFI startup code.
4 4 * Copyright (C) 1999 Hewlett-Packard Co.
5 5 * Contributed by David Mosberger <davidm@hpl.hp.com>.
6   - * Copyright (C) 2005 Intel Co.
  6 + * Copyright (C) 2005 Intel Corporation
7 7 * Contributed by Fenghua Yu <fenghua.yu@intel.com>.
8 8 *
9 9 * All rights reserved.
10 10  
11 11  
12 12  
13 13  
14 14  
15 15  
... ... @@ -14,26 +14,28 @@
14 14 .globl _start
15 15 _start:
16 16 subq $8, %rsp
  17 +
17 18 pushq %rcx
18 19 pushq %rdx
19 20  
20   -0:
21   - lea image_base(%rip), %rdi
22   - lea _DYNAMIC(%rip), %rsi
  21 + mov %rcx, %r8
  22 + mov %rdx, %r9
23 23  
24   - popq %rcx
25   - popq %rdx
26   - pushq %rcx
27   - pushq %rdx
  24 + lea image_base(%rip), %rcx
  25 + lea _DYNAMIC(%rip), %rdx
  26 +
28 27 call _relocate
29 28  
30   - popq %rdi
31   - popq %rsi
  29 + popq %rdx
  30 + popq %rcx
32 31  
  32 + testq %rax, %rax
  33 + jnz .exit
  34 +
33 35 call efi_main
  36 +.exit:
34 37 addq $8, %rsp
35 38  
36   -.exit:
37 39 ret
38 40  
39 41 /*
... ... @@ -96,7 +96,8 @@
96 96 * U-Boot. If it returns, EFI will continue. Another way to get back to EFI
97 97 * is via reset_cpu().
98 98 */
99   -efi_status_t efi_main(efi_handle_t image, struct efi_system_table *sys_table)
  99 +efi_status_t EFIAPI efi_main(efi_handle_t image,
  100 + struct efi_system_table *sys_table)
100 101 {
101 102 struct efi_priv local_priv, *priv = &local_priv;
102 103 efi_status_t ret;
... ... @@ -268,7 +268,8 @@
268 268 * This function is called by our EFI start-up code. It handles running
269 269 * U-Boot. If it returns, EFI will continue.
270 270 */
271   -efi_status_t efi_main(efi_handle_t image, struct efi_system_table *sys_table)
  271 +efi_status_t EFIAPI efi_main(efi_handle_t image,
  272 + struct efi_system_table *sys_table)
272 273 {
273 274 struct efi_priv local_priv, *priv = &local_priv;
274 275 struct efi_boot_services *boot = sys_table->boottime;