diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 877f26d0f2..d1eacd6f8b 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -33,10 +33,8 @@ #include #include #include -#include +#include #include -#include -#include #include #include #include @@ -50,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +59,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -86,6 +88,7 @@ static void setup_serial_debug(); static void setup_acpi(); static void setup_vmmouse(); static void setup_pci(); +static void setup_interrupts(); VirtualConsole* tty0; @@ -103,8 +106,11 @@ extern "C" [[noreturn]] void init() MemoryManager::initialize(); bool text_debug = KParams::the().has("text_debug"); + gdt_init(); + idt_init(); setup_acpi(); + setup_interrupts(); new VFS; new DebugLogDevice; @@ -115,10 +121,8 @@ extern "C" [[noreturn]] void init() __stack_chk_guard = get_good_random(); + PIT::initialize(); RTC::initialize(); - PIC::initialize(); - gdt_init(); - idt_init(); // call global constructors after gtd and itd init for (ctor_func_t* ctor = &start_ctors; ctor < &end_ctors; ctor++) @@ -291,7 +295,6 @@ void init_stage2() } } } - auto e2fs = Ext2FS::create(root_dev); if (!e2fs->initialize()) { kprintf("init_stage2: couldn't open root filesystem\n"); @@ -458,4 +461,38 @@ void setup_pci() PCI::Initializer::the().dismiss(); } +static void setup_interrupt_management() +{ + auto* madt = (ACPI_RAW::MADT*)ACPIParser::the().find_table("APIC"); + if (!madt) { + InterruptManagement::initialize(); + return; + } + AdvancedInterruptManagement::initialize(*madt); +} + +void setup_interrupts() +{ + setup_interrupt_management(); + + if (!KParams::the().has("smp")) { + InterruptManagement::the().switch_to_pic_mode(); + return; + } + auto smp = KParams::the().get("smp"); + if (smp == "off") { + InterruptManagement::the().switch_to_pic_mode(); + return; + } + if (smp == "on") { + ASSERT_NOT_REACHED(); // FIXME: The IOAPIC mode is not stable yet so we can't use it now. + InterruptManagement::the().switch_to_ioapic_mode(); + APIC::init(); + APIC::enable_bsp(); + return; + } + + kprintf("smp boot argmuent has an invalid value.\n"); + hang(); +} }