1 /* SPDX-License-Identifier: GPL-2.0 */
3 * EFI call stub for IA32.
5 * This stub allows us to make EFI calls in physical mode with interrupts
9 #include <linux/linkage.h>
10 #include <asm/page_types.h>
13 * efi_call_phys(void *, ...) is a function with variable parameters.
14 * All the callers of this function assure that all the parameters are 4-bytes.
18 * In gcc calling convention, EBX, ESP, EBP, ESI and EDI are all callee save.
19 * So we'd better save all of them at the beginning of this function and restore
20 * at the end no matter how many we use, because we can not assure EFI runtime
21 * service functions will comply with gcc calling convention, too.
27 * 0. The function can only be called in Linux kernel. So CS has been
28 * set to 0x0010, DS and SS have been set to 0x0018. In EFI, I found
29 * the values of these registers are the same. And, the corresponding
30 * GDT entries are identical. So I will do nothing about segment reg
31 * and GDT, but change GDT base register in prolog and epilog.
35 * 1. Now I am running with EIP = <physical address> + PAGE_OFFSET.
36 * But to make it smoothly switch from virtual mode to flat mode.
37 * The mapping of lower virtual memory has been created in prolog and
41 subl $__PAGE_OFFSET, %edx
46 * 2. Now on the top of stack is the return
47 * address in the caller of efi_call_phys(), then parameter 1,
48 * parameter 2, ..., param n. To make things easy, we save the return
49 * address of efi_call_phys in a global variable.
52 movl %edx, saved_return_addr
53 /* get the function pointer into ECX*/
55 movl %ecx, efi_rt_function_ptr
57 subl $__PAGE_OFFSET, %edx
61 * 3. Clear PG bit in %CR0.
64 andl $0x7fffffff, %edx
70 * 4. Adjust stack pointer.
72 subl $__PAGE_OFFSET, %esp
75 * 5. Call the physical function.
81 * 6. After EFI runtime service returns, control will return to
82 * following instruction. We'd better readjust stack pointer first.
84 addl $__PAGE_OFFSET, %esp
95 * 8. Now restore the virtual mode from flat mode by
96 * adding EIP with PAGE_OFFSET.
103 * 9. Balance the stack. And because EAX contain the return value,
104 * we'd better not clobber it.
106 leal efi_rt_function_ptr, %edx
111 * 10. Push the saved return address onto the stack and return.
113 leal saved_return_addr, %edx
117 ENDPROC(efi_call_phys)