1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2014, 2015 Intel Corporation; author Matt Fleming
5 * Early support for invoking 32-bit EFI services from a 64-bit kernel.
7 * Because this thunking occurs before ExitBootServices() we have to
8 * restore the firmware's 32-bit GDT before we make EFI serivce calls,
9 * since the firmware's 32-bit IDT is still currently installed and it
10 * needs to be able to service interrupts.
12 * On the plus side, we don't have to worry about mangling 64-bit
13 * addresses into 32-bits because we're executing with an identity
14 * mapped pagetable and haven't transitioned to 64-bit virtual addresses
18 #include <linux/linkage.h>
20 #include <asm/page_types.h>
21 #include <asm/processor-flags.h>
22 #include <asm/segment.h>
26 SYM_FUNC_START(__efi64_thunk)
40 * Convert x86-64 ABI params to i386 ABI
53 * Switch to gdt with 32-bit segments. This is the firmware GDT
54 * that was installed when the kernel started executing. This
55 * pointer was saved at the EFI stub entry point in head_64.S.
57 * Pass the saved DS selector to the 32-bit code, and use far return to
58 * restore the saved CS selector.
60 leaq efi32_boot_gdt(%rip), %rax
63 movzwl efi32_boot_ds(%rip), %edx
64 movzwq efi32_boot_cs(%rip), %rax
66 leaq efi_enter32(%rip), %rax
79 /* Clear out 32-bit selector from FS and GS */
85 * Convert 32-bit status code into 64-bit.
93 SYM_FUNC_END(__efi64_thunk)
97 * EFI service pointer must be in %edi.
99 * The stack should represent the 32-bit calling convention.
101 SYM_FUNC_START_LOCAL(efi_enter32)
102 /* Load firmware selector into data and stack segment registers */
109 /* Reload pgtables */
115 btrl $X86_CR0_PG_BIT, %eax
118 /* Disable long mode via EFER */
121 btrl $_EFER_LME, %eax
126 /* We must preserve return value */
130 * Some firmware will return with interrupts enabled. Be sure to
131 * disable them before we switch GDTs.
138 btsl $(X86_CR4_PAE_BIT), %eax
146 btsl $_EFER_LME, %eax
157 btsl $X86_CR0_PG_BIT, %eax
160 SYM_FUNC_END(efi_enter32)
164 SYM_DATA_START(efi32_boot_gdt)
167 SYM_DATA_END(efi32_boot_gdt)
169 SYM_DATA_START(efi32_boot_cs)
171 SYM_DATA_END(efi32_boot_cs)
173 SYM_DATA_START(efi32_boot_ds)
175 SYM_DATA_END(efi32_boot_ds)