2019-08-05 16:17:48 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2019-10-25 00:08:21 +09:00
|
|
|
#include <kernel.h>
|
|
|
|
#include <kernel_internal.h>
|
2019-09-06 15:03:38 -04:00
|
|
|
#include <arch/x86/acpi.h>
|
2019-09-09 14:05:41 -04:00
|
|
|
#include <arch/x86/multiboot.h>
|
2020-09-15 12:58:51 +02:00
|
|
|
#include <arch/x86/efi.h>
|
2020-07-04 16:23:32 -07:00
|
|
|
#include <x86_mmu.h>
|
2019-08-05 16:17:48 -07:00
|
|
|
|
2019-09-28 14:25:13 -04:00
|
|
|
extern FUNC_NORETURN void z_cstart(void);
|
2020-06-16 12:49:54 -07:00
|
|
|
extern void x86_64_irq_init(void);
|
2019-09-28 14:25:13 -04:00
|
|
|
|
2020-09-18 09:05:50 +02:00
|
|
|
#if !defined(CONFIG_X86_64)
|
|
|
|
x86_boot_arg_t x86_cpu_boot_arg;
|
|
|
|
#endif
|
|
|
|
|
2020-01-10 12:51:38 -08:00
|
|
|
/* Early global initialization functions, C domain. This runs only on the first
|
|
|
|
* CPU for SMP systems.
|
|
|
|
*/
|
2021-02-25 16:42:53 -08:00
|
|
|
__boot_func
|
2020-01-10 12:51:38 -08:00
|
|
|
FUNC_NORETURN void z_x86_prep_c(void *arg)
|
2019-08-05 16:17:48 -07:00
|
|
|
{
|
2020-09-18 09:05:50 +02:00
|
|
|
x86_boot_arg_t *cpu_arg = arg;
|
2019-09-28 21:26:00 -04:00
|
|
|
|
2019-09-28 14:25:13 -04:00
|
|
|
_kernel.cpus[0].nested = 0;
|
2019-08-05 16:17:48 -07:00
|
|
|
|
2021-05-03 13:07:31 -07:00
|
|
|
#ifdef CONFIG_MMU
|
|
|
|
z_x86_mmu_init();
|
|
|
|
#endif
|
|
|
|
|
2021-02-10 14:18:45 -08:00
|
|
|
#if defined(CONFIG_LOAPIC)
|
|
|
|
z_loapic_enable(0);
|
|
|
|
#endif
|
|
|
|
|
2020-06-16 12:49:54 -07:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
x86_64_irq_init();
|
|
|
|
#endif
|
|
|
|
|
2020-09-18 09:05:50 +02:00
|
|
|
if (IS_ENABLED(CONFIG_MULTIBOOT_INFO) &&
|
|
|
|
cpu_arg->boot_type == MULTIBOOT_BOOT_TYPE) {
|
|
|
|
z_multiboot_init((struct multiboot_info *)cpu_arg->arg);
|
2020-09-15 12:58:51 +02:00
|
|
|
} else if (IS_ENABLED(CONFIG_X86_EFI) &&
|
|
|
|
cpu_arg->boot_type == EFI_BOOT_TYPE) {
|
2021-02-25 13:16:53 +01:00
|
|
|
efi_init((struct efi_boot_arg *)cpu_arg->arg);
|
2020-09-18 09:05:50 +02:00
|
|
|
} else {
|
|
|
|
ARG_UNUSED(cpu_arg);
|
|
|
|
}
|
2019-09-09 14:05:41 -04:00
|
|
|
|
2022-03-16 10:14:44 +01:00
|
|
|
#ifdef CONFIG_X86_VERY_EARLY_CONSOLE
|
|
|
|
z_x86_early_serial_init();
|
|
|
|
#endif
|
|
|
|
|
2019-08-05 16:17:48 -07:00
|
|
|
#if CONFIG_X86_STACK_PROTECTION
|
2020-04-24 16:24:46 -07:00
|
|
|
for (int i = 0; i < CONFIG_MP_NUM_CPUS; i++) {
|
|
|
|
z_x86_set_stack_guard(z_interrupt_stacks[i]);
|
|
|
|
}
|
2019-08-05 16:17:48 -07:00
|
|
|
#endif
|
|
|
|
|
2019-09-30 13:28:36 -04:00
|
|
|
#if defined(CONFIG_SMP)
|
|
|
|
z_x86_ipi_setup();
|
|
|
|
#endif
|
|
|
|
|
2019-08-05 16:17:48 -07:00
|
|
|
z_cstart();
|
|
|
|
}
|