2 * Copyright (C) 2014 Intel Corporation; author Matt Fleming
4 * Support for invoking 32-bit EFI runtime services from a 64-bit
7 * The below thunking functions are only used after ExitBootServices()
8 * has been called. This simplifies things considerably as compared with
9 * the early EFI thunking because we can leave all the kernel state
10 * intact (GDT, IDT, etc) and simply invoke the the 32-bit EFI runtime
11 * services from __KERNEL32_CS. This means we can continue to service
12 * interrupts across an EFI mixed mode call.
14 * We do however, need to handle the fact that we're running in a full
15 * 64-bit virtual address space. Things like the stack and instruction
16 * addresses need to be accessible by the 32-bit firmware, so we rely on
17 * using the identity mappings in the EFI page table to access the stack
18 * and kernel text (see efi_setup_page_tables()).
21 #include <linux/linkage.h>
22 #include <asm/page_types.h>
23 #include <asm/segment.h>
32 * Switch to 1:1 mapped 32-bit stack pointer.
34 movq %rsp, efi_saved_sp(%rip)
35 movq efi_scratch+25(%rip), %rsp
38 * Calculate the physical address of the kernel text.
40 movq $__START_KERNEL_map, %rax
41 subq phys_base(%rip), %rax
44 * Push some physical addresses onto the stack. This is easier
45 * to do now in a code64 section while the assembler can address
46 * 64-bit values. Note that all the addresses on the stack are
50 leaq efi_exit32(%rip), %rbx
54 leaq __efi64_thunk(%rip), %rbx
58 movq efi_saved_sp(%rip), %rsp
65 * We run this function from the 1:1 mapping.
67 * This function must be invoked with a 1:1 mapped stack.
87 movq %rbx, func_rt_ptr(%rip)
89 /* Switch to 32-bit descriptor */
91 leaq efi_enter32(%rip), %rax
105 * Convert 32-bit status code into 64-bit.
110 andl $0x0fffffff, %ecx
111 andl $0xf0000000, %eax
116 ENDPROC(__efi64_thunk)
119 movq func_rt_ptr(%rip), %rax
127 * EFI service pointer must be in %edi.
129 * The stack should represent the 32-bit calling convention.
132 movl $__KERNEL_DS, %eax
139 /* We must preserve return value */
152 efi_saved_sp: .quad 0