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