1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2014 Intel Corporation; author Matt Fleming
5 * Support for invoking 32-bit EFI runtime services from a 64-bit
8 * The below thunking functions are only used after ExitBootServices()
9 * has been called. This simplifies things considerably as compared with
10 * the early EFI thunking because we can leave all the kernel state
11 * intact (GDT, IDT, etc) and simply invoke the the 32-bit EFI runtime
12 * services from __KERNEL32_CS. This means we can continue to service
13 * interrupts across an EFI mixed mode call.
15 * We do however, need to handle the fact that we're running in a full
16 * 64-bit virtual address space. Things like the stack and instruction
17 * addresses need to be accessible by the 32-bit firmware, so we rely on
18 * using the identity mappings in the EFI page table to access the stack
19 * and kernel text (see efi_setup_page_tables()).
22 #include <linux/linkage.h>
23 #include <asm/page_types.h>
24 #include <asm/segment.h>
33 * Switch to 1:1 mapped 32-bit stack pointer.
35 movq %rsp, efi_saved_sp(%rip)
36 movq efi_scratch(%rip), %rsp
39 * Calculate the physical address of the kernel text.
41 movq $__START_KERNEL_map, %rax
42 subq phys_base(%rip), %rax
45 * Push some physical addresses onto the stack. This is easier
46 * to do now in a code64 section while the assembler can address
47 * 64-bit values. Note that all the addresses on the stack are
51 leaq efi_exit32(%rip), %rbx
55 leaq __efi64_thunk(%rip), %rbx
59 movq efi_saved_sp(%rip), %rsp
66 * We run this function from the 1:1 mapping.
68 * This function must be invoked with a 1:1 mapped stack.
88 movq %rbx, func_rt_ptr(%rip)
90 /* Switch to 32-bit descriptor */
92 leaq efi_enter32(%rip), %rax
106 * Convert 32-bit status code into 64-bit.
111 andl $0x0fffffff, %ecx
112 andl $0xf0000000, %eax
117 ENDPROC(__efi64_thunk)
120 movq func_rt_ptr(%rip), %rax
128 * EFI service pointer must be in %edi.
130 * The stack should represent the 32-bit calling convention.
133 movl $__KERNEL_DS, %eax
140 /* We must preserve return value */
153 efi_saved_sp: .quad 0