Commit 796eb8d2 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Ingo Molnar

efi/libstub/x86: Use const attribute for efi_is_64bit()

Reshuffle the x86 stub code a bit so that we can tag the efi_is_64bit()
function with the 'const' attribute, which permits the compiler to
optimize away any redundant calls. Since we have two different entry
points for 32 and 64 bit firmware in the startup code, this also
simplifies the C code since we'll enter it with the efi_is64 variable
already set.
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20200113172245.27925-2-ardb@kernel.org
parent a786810c
...@@ -21,16 +21,18 @@ ...@@ -21,16 +21,18 @@
#include "eboot.h" #include "eboot.h"
static efi_system_table_t *sys_table; static efi_system_table_t *sys_table;
static bool efi_is64 = IS_ENABLED(CONFIG_X86_64); extern const bool efi_is64;
__pure efi_system_table_t *efi_system_table(void) __pure efi_system_table_t *efi_system_table(void)
{ {
return sys_table; return sys_table;
} }
__pure bool efi_is_64bit(void) __attribute_const__ bool efi_is_64bit(void)
{ {
return efi_is64; if (IS_ENABLED(CONFIG_EFI_MIXED))
return efi_is64;
return IS_ENABLED(CONFIG_X64_64);
} }
static efi_status_t static efi_status_t
...@@ -710,8 +712,7 @@ static efi_status_t exit_boot(struct boot_params *boot_params, void *handle) ...@@ -710,8 +712,7 @@ static efi_status_t exit_boot(struct boot_params *boot_params, void *handle)
*/ */
struct boot_params *efi_main(efi_handle_t handle, struct boot_params *efi_main(efi_handle_t handle,
efi_system_table_t *sys_table_arg, efi_system_table_t *sys_table_arg,
struct boot_params *boot_params, struct boot_params *boot_params)
bool is64)
{ {
struct desc_ptr *gdt = NULL; struct desc_ptr *gdt = NULL;
struct setup_header *hdr = &boot_params->hdr; struct setup_header *hdr = &boot_params->hdr;
...@@ -721,9 +722,6 @@ struct boot_params *efi_main(efi_handle_t handle, ...@@ -721,9 +722,6 @@ struct boot_params *efi_main(efi_handle_t handle,
sys_table = sys_table_arg; sys_table = sys_table_arg;
if (IS_ENABLED(CONFIG_EFI_MIXED))
efi_is64 = is64;
/* Check if we were booted by the EFI firmware */ /* Check if we were booted by the EFI firmware */
if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
goto fail; goto fail;
......
...@@ -211,10 +211,9 @@ SYM_FUNC_START(startup_32) ...@@ -211,10 +211,9 @@ SYM_FUNC_START(startup_32)
movl efi32_boot_args(%ebp), %edi movl efi32_boot_args(%ebp), %edi
cmp $0, %edi cmp $0, %edi
jz 1f jz 1f
leal handover_entry(%ebp), %eax leal efi64_stub_entry(%ebp), %eax
movl %esi, %edx movl %esi, %edx
movl efi32_boot_args+4(%ebp), %esi movl efi32_boot_args+4(%ebp), %esi
movl $0x0, %ecx
1: 1:
#endif #endif
pushl %eax pushl %eax
...@@ -242,6 +241,7 @@ SYM_FUNC_START(efi32_stub_entry) ...@@ -242,6 +241,7 @@ SYM_FUNC_START(efi32_stub_entry)
movl %ecx, efi32_boot_args(%ebp) movl %ecx, efi32_boot_args(%ebp)
movl %edx, efi32_boot_args+4(%ebp) movl %edx, efi32_boot_args+4(%ebp)
sgdtl efi32_boot_gdt(%ebp) sgdtl efi32_boot_gdt(%ebp)
movb $0, efi_is64(%ebp)
/* Disable paging */ /* Disable paging */
movl %cr0, %eax movl %cr0, %eax
...@@ -452,8 +452,6 @@ SYM_CODE_END(startup_64) ...@@ -452,8 +452,6 @@ SYM_CODE_END(startup_64)
.org 0x390 .org 0x390
SYM_FUNC_START(efi64_stub_entry) SYM_FUNC_START(efi64_stub_entry)
SYM_FUNC_START_ALIAS(efi_stub_entry) SYM_FUNC_START_ALIAS(efi_stub_entry)
movq $1, %rcx
SYM_INNER_LABEL(handover_entry, SYM_L_LOCAL)
and $~0xf, %rsp /* realign the stack */ and $~0xf, %rsp /* realign the stack */
call efi_main call efi_main
movq %rax,%rsi movq %rax,%rsi
...@@ -632,6 +630,7 @@ SYM_DATA_END_LABEL(gdt, SYM_L_LOCAL, gdt_end) ...@@ -632,6 +630,7 @@ SYM_DATA_END_LABEL(gdt, SYM_L_LOCAL, gdt_end)
#ifdef CONFIG_EFI_MIXED #ifdef CONFIG_EFI_MIXED
SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0) SYM_DATA_LOCAL(efi32_boot_args, .long 0, 0)
SYM_DATA(efi_is64, .byte 1)
#endif #endif
/* /*
......
...@@ -221,7 +221,7 @@ efi_status_t efi_set_virtual_address_map(unsigned long memory_map_size, ...@@ -221,7 +221,7 @@ efi_status_t efi_set_virtual_address_map(unsigned long memory_map_size,
/* arch specific definitions used by the stub code */ /* arch specific definitions used by the stub code */
__pure bool efi_is_64bit(void); __attribute_const__ bool efi_is_64bit(void);
static inline bool efi_is_native(void) static inline bool efi_is_native(void)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment