2 * EFI call stub for IA32.
4 * This stub allows us to make EFI calls in physical mode with interrupts
8 #include <linux/config.h>
9 #include <linux/linkage.h>
11 #include <asm/pgtable.h>
14 * efi_call_phys(void *, ...) is a function with variable parameters.
15 * All the callers of this function assure that all the parameters are 4-bytes.
19 * In gcc calling convention, EBX, ESP, EBP, ESI and EDI are all callee save.
20 * So we'd better save all of them at the beginning of this function and restore
21 * at the end no matter how many we use, because we can not assure EFI runtime
22 * service functions will comply with gcc calling convention, too.
28 * 0. The function can only be called in Linux kernel. So CS has been
29 * set to 0x0010, DS and SS have been set to 0x0018. In EFI, I found
30 * the values of these registers are the same. And, the corresponding
31 * GDT entries are identical. So I will do nothing about segment reg
32 * and GDT, but change GDT base register in prelog and epilog.
36 * 1. Now I am running with EIP = <physical address> + PAGE_OFFSET.
37 * But to make it smoothly switch from virtual mode to flat mode.
38 * The mapping of lower virtual memory has been created in prelog and
42 subl $__PAGE_OFFSET, %edx
47 * 2. Now on the top of stack is the return
48 * address in the caller of efi_call_phys(), then parameter 1,
49 * parameter 2, ..., param n. To make things easy, we save the return
50 * address of efi_call_phys in a global variable.
53 movl %edx, saved_return_addr
54 /* get the function pointer into ECX*/
56 movl %ecx, efi_rt_function_ptr
58 subl $__PAGE_OFFSET, %edx
62 * 3. Clear PG bit in %CR0.
65 andl $0x7fffffff, %edx
71 * 4. Adjust stack pointer.
73 subl $__PAGE_OFFSET, %esp
76 * 5. Call the physical function.
82 * 6. After EFI runtime service returns, control will return to
83 * following instruction. We'd better readjust stack pointer first.
85 addl $__PAGE_OFFSET, %esp
96 * 8. Now restore the virtual mode from flat mode by
97 * adding EIP with PAGE_OFFSET.
104 * 9. Balance the stack. And because EAX contain the return value,
105 * we'd better not clobber it.
107 leal efi_rt_function_ptr, %edx
112 * 10. Push the saved return address onto the stack and return.
114 leal saved_return_addr, %edx