From ccf6421ebfd30808a24b1a08aa6dbf963de1f24d Mon Sep 17 00:00:00 2001 From: sigsegv7 Date: Wed, 4 Oct 2023 19:21:14 -0400 Subject: kernel/amd64: Initialize IDT and GDT first This commit moves the interrupts_init() and gdt_load() calls to the top so interrupts are set up first in case something goes wrong so we can get information from exception handlers. Signed-off-by: sigsegv7 --- sys/arch/amd64/lapic.c | 4 ++++ sys/arch/amd64/machdep.c | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sys/arch/amd64/lapic.c b/sys/arch/amd64/lapic.c index 792cfa3..53a4fd5 100644 --- a/sys/arch/amd64/lapic.c +++ b/sys/arch/amd64/lapic.c @@ -251,10 +251,14 @@ lapic_init(void) /* Get the current processor, and calibrate LAPIC timer */ cur_cpu = this_cpu(); + CPU_INFO_LOCK(cur_cpu); + lapic_timer_init(&tmr_freq); cur_cpu->lapic_tmr_freq = tmr_freq; /* Set the Local APIC ID */ cur_cpu->lapic_id = lapic_get_id(); + BSP_KINFO("BSP Local APIC ID: %d\n", cur_cpu->lapic_id); + } diff --git a/sys/arch/amd64/machdep.c b/sys/arch/amd64/machdep.c index 9fd7a12..edff4f2 100644 --- a/sys/arch/amd64/machdep.c +++ b/sys/arch/amd64/machdep.c @@ -68,14 +68,15 @@ processor_init(void) /* Indicates what doesn't need to be init anymore */ static uint8_t init_flags = 0; + interrupts_init(); + gdt_load(&g_gdtr); + if (!__TEST(init_flags, INIT_FLAG_IOAPIC)) { init_flags |= INIT_FLAG_IOAPIC; ioapic_init(); } lapic_init(); /* Per core */ - gdt_load(&g_gdtr); - interrupts_init(); /* Enable spectre mitigation if enabled */ if (try_spectre_mitigate != NULL) -- cgit v1.2.3