From dd98de880a2d16cee19bb69fcc264e02dd84e125 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Wed, 10 Feb 2021 14:18:45 -0800 Subject: [PATCH] x86: move calling z_loapic_enable into z_x86_prep_c This moves calling z_loapic_enable() from crt0.S into z_x86_prep_c(). This is done so we can move BSS clearing and data section copying inside z_x86_prep_c() as these are needed before calling z_loapic_enable(). Signed-off-by: Daniel Leung --- arch/x86/core/ia32/crt0.S | 7 ------- arch/x86/core/intel64/cpu.c | 13 ++++++++++++- arch/x86/core/prep_c.c | 4 ++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/arch/x86/core/ia32/crt0.S b/arch/x86/core/ia32/crt0.S index 58ac45b447c..e886eebb3d8 100644 --- a/arch/x86/core/ia32/crt0.S +++ b/arch/x86/core/ia32/crt0.S @@ -224,13 +224,6 @@ __csSet: movl %eax, %cr0 #endif /* CONFIG_X86_MMU */ -#ifdef CONFIG_LOAPIC - /* For BSP, cpu_number is 0 */ - xorl %eax, %eax - pushl %eax - call z_loapic_enable -#endif - pushl %ebx /* pointer to multiboot info, or NULL */ call z_x86_prep_c /* enter kernel; never returns */ diff --git a/arch/x86/core/intel64/cpu.c b/arch/x86/core/intel64/cpu.c index 6df0735e52c..57c588e04e7 100644 --- a/arch/x86/core/intel64/cpu.c +++ b/arch/x86/core/intel64/cpu.c @@ -163,8 +163,19 @@ FUNC_NORETURN void z_x86_cpu_init(struct x86_cpuboot *cpuboot) { x86_sse_init(NULL); +#if CONFIG_MP_NUM_CPUS > 1 /* The internal cpu_number is the index to x86_cpuboot[] */ - z_loapic_enable((unsigned char)(cpuboot - x86_cpuboot)); + unsigned char cpu_num = (unsigned char)(cpuboot - x86_cpuboot); + + if (cpu_num > 0) { + /* + * For CPU #0, z_loapic_enable(0) will be done + * inside z_x86_prep_c() so there is no need to do it + * here. + */ + z_loapic_enable(cpu_num); + } +#endif #ifdef CONFIG_USERSPACE /* Set landing site for 'syscall' instruction */ diff --git a/arch/x86/core/prep_c.c b/arch/x86/core/prep_c.c index a45e2a0fd94..62b1420f499 100644 --- a/arch/x86/core/prep_c.c +++ b/arch/x86/core/prep_c.c @@ -22,6 +22,10 @@ FUNC_NORETURN void z_x86_prep_c(void *arg) _kernel.cpus[0].nested = 0; +#if defined(CONFIG_LOAPIC) + z_loapic_enable(0); +#endif + #ifdef CONFIG_X86_VERY_EARLY_CONSOLE z_x86_early_serial_init(); #endif