arch/x86: Prepare EFI support

As for Multiboot, let prep_c be aware of EFI boot.
In the futur, EFI will pass an argument to it.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2020-09-15 12:58:51 +02:00 committed by Anas Nashif
parent f19f9db8df
commit 27df16ea8e
7 changed files with 63 additions and 4 deletions

View File

@ -479,6 +479,14 @@ config X86_KPTI
user thread interrupts and system calls, and significant footprint
increase for additional page tables and trampoline stacks.
config X86_EFI
bool "EFI"
default y
depends on BUILD_OUTPUT_EFI
help
Enable EFI support. This means you build your image with zefi
support. See arch/x86/zefi/README.txt for more information.
source "arch/x86/core/Kconfig.ia32"
source "arch/x86/core/Kconfig.intel64"

View File

@ -14,6 +14,7 @@ zephyr_library_sources_ifdef(CONFIG_X86_MEMMAP memmap.c)
zephyr_library_sources_ifdef(CONFIG_PCIE pcie.c)
zephyr_library_sources_ifdef(CONFIG_REBOOT_RST_CNT reboot_rst_cnt.c)
zephyr_library_sources_ifdef(CONFIG_MULTIBOOT_INFO multiboot.c)
zephyr_library_sources_ifdef(CONFIG_X86_EFI efi.c)
zephyr_library_sources_ifdef(CONFIG_ACPI acpi.c)
zephyr_library_sources_ifdef(CONFIG_X86_MMU x86_mmu.c)
zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.c)

10
arch/x86/core/efi.c Normal file
View File

@ -0,0 +1,10 @@
/*
* Copyright (c) 2020 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
void efi_init(void)
{
/* Do Nothing atm */
}

View File

@ -5,6 +5,7 @@
#include <toolchain.h>
#include <arch/x86/multiboot.h>
#include <arch/x86/efi.h>
#include <sys/util.h>
#include <arch/x86/msr.h>
#include <kernel_arch_data.h>
@ -289,8 +290,14 @@ __start64:
outb %al, $0x21
outb %al, $0xA1
/* Far call into the Zephyr code segment */
movq $x86_cpuboot, %rbp
movq $x86_cpu_boot_arg, %rbp
/* Inserting boot type */
movq $EFI_BOOT_TYPE, __x86_boot_arg_t_boot_type_OFFSET(%rbp)
/* and EFI boot arg (if any) */
movq %rbx, __x86_boot_arg_t_arg_OFFSET(%rbp)
movq $x86_cpuboot, %rbp /* BSP is always logical CPU id 0 */
mov jmpdesc, %rax
jmp *%rax
jmpdesc:

View File

@ -8,6 +8,7 @@
#include <kernel_internal.h>
#include <arch/x86/acpi.h>
#include <arch/x86/multiboot.h>
#include <arch/x86/efi.h>
#include <x86_mmu.h>
extern FUNC_NORETURN void z_cstart(void);
@ -43,10 +44,12 @@ FUNC_NORETURN void z_x86_prep_c(void *arg)
x86_64_irq_init();
#endif
if (IS_ENABLED(CONFIG_MULTIBOOT_INFO) &&
cpu_arg->boot_type == MULTIBOOT_BOOT_TYPE) {
z_multiboot_init((struct multiboot_info *)cpu_arg->arg);
} else if (IS_ENABLED(CONFIG_X86_EFI) &&
cpu_arg->boot_type == EFI_BOOT_TYPE) {
efi_init();
} else {
ARG_UNUSED(cpu_arg);
}

View File

@ -123,7 +123,8 @@ uintptr_t __abi efi_entry(void *img_handle, struct efi_system_table *sys_tab)
for (volatile int i = 0; i < 50000000; i++) {
}
__asm__ volatile("cli; jmp *%0" :: "r"(code));
__asm__ volatile("cli; movq %0, %%rbx; jmp *%1"
:: "r"(NULL), "r"(code) : "rbx");
return 0;
}

29
include/arch/x86/efi.h Normal file
View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2020 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_ARCH_X86_INCLUDE_EFI_H_
#define ZEPHYR_ARCH_X86_INCLUDE_EFI_H_
/* Boot type value (see prep_c.c) */
#define EFI_BOOT_TYPE 2
#ifndef _ASMLANGUAGE
#if defined(CONFIG_X86_EFI)
/** @brief Initialize usage of EFI gathered information
*/
void efi_init(void);
#else /* CONFIG_X86_EFI */
#define efi_init(...)
#endif /* CONFIG_X86_EFI */
#endif /* _ASMLANGUAGE */
#endif /* ZEPHYR_ARCH_X86_INCLUDE_EFI_H_ */