#define MODULE "main" #include "acpi/RSDT.h" #include "assert.h" #include "bootboot.h" #include "config.h" #include "cpu/CPU.h" #include "debug.h" #include "gdt/GDT.h" #include "init/Init.h" #include "init/InitRD.h" #include "interrupts/IDT.h" #include "interrupts/Install.h" #include "interrupts/Interrupts.h" #include "io/PIC.h" #include "io/Serial.h" #include "log/Address.h" #include "log/Log.h" #include "memory/KernelHeap.h" #include "memory/KernelMemoryManager.h" #include "memory/Memory.h" #include "memory/RangeAllocator.h" #include "panic/hang.h" #include "power/shutdown.h" #include "render/BBRenderer.h" #include "render/Draw.h" #include "render/TextRenderer.h" #include "scheduling/PIT.h" #include "std/stdio.h" #include "std/stdlib.h" #include "std/string.h" extern BOOTBOOT bootboot; extern "C" void _start() { Init::check_magic(); Init::disable_smp(); // Put all other cores except the bootstrap one in an infinite loop Debug::DebugStatus::the()->Init(); Debug::DebugStatus::the()->StartBootStage(Color::White); Init::early_init(); Debug::DebugStatus::the()->PassBootStage(Color::White); kinfoln("Starting Moon %d.%d-%s", MOON_MAJOR, MOON_MINOR, MOON_SUFFIX); Debug::DebugStatus::the()->StartBootStage(Color::Gray); GDT::load(); Debug::DebugStatus::the()->PassBootStage(Color::Gray); kinfoln("Loaded GDT"); Debug::DebugStatus::the()->StartBootStage(Color::Cyan); Interrupts::install(); Debug::DebugStatus::the()->PassBootStage(Color::Cyan); Debug::DebugStatus::the()->StartBootStage(Color::Blue); IDT::load(); Debug::DebugStatus::the()->PassBootStage(Color::Blue); kinfoln("Loaded IDT"); Debug::DebugStatus::the()->StartBootStage(Color::Green); PIC::remap(); PIC::enable_master(0b11111100); // enable keyboard and PIT PIC::enable_slave(0b11111111); Debug::DebugStatus::the()->PassBootStage(Color::Green); kinfoln("Prepared PIC"); Debug::DebugStatus::the()->StartBootStage(Color::Magenta); PIT::initialize(100); // 100 times per second Debug::DebugStatus::the()->PassBootStage(Color::Magenta); kinfoln("Prepared PIT"); Debug::DebugStatus::the()->StartBootStage(Color::Yellow); Interrupts::enable(); Debug::DebugStatus::the()->PassBootStage(Color::Yellow); kinfoln("Interrupts enabled"); Debug::DebugStatus::the()->StartBootStage(Color{0x33, 0x33, 0x00, 0xFF}); ACPI::SDTHeader* rootSDT = (ACPI::SDTHeader*)KernelMemoryManager::get_unaligned_mapping(ACPI::GetRSDTOrXSDT()); bool isXSDT = false; if (strncmp(rootSDT->Signature, "XSDT", 4) != 0) { if (strncmp(rootSDT->Signature, "RSDT", 4) != 0) { kerrorln("Invalid RootSDT signature"); Debug::DebugStatus::the()->FailBootStage(); while (1) halt(); } } else isXSDT = true; if (ACPI::ValidateSDTHeader(rootSDT)) { kinfoln("%s: 0x%lx", isXSDT ? "XSDT is valid" : "RSDT is valid", (uint64_t)rootSDT); Debug::DebugStatus::the()->PassBootStage(Color{0x33, 0x33, 0x00, 0xFF}); } else { kinfoln(isXSDT ? "Invalid XSDT :(" : "Invalid RSDT :("); Debug::DebugStatus::the()->FailBootStage(); while (1) halt(); } Debug::DebugStatus::the()->StartBootStage(Color{0x00, 0x66, 0xCC, 0xFF}); ACPI::SDTHeader* fadt = (ACPI::SDTHeader*)ACPI::FindTable(rootSDT, "FACP"); if (!fadt) { kerrorln("FADT not found"); Debug::DebugStatus::the()->FailBootStage(); while (1) halt(); } if (strncmp(fadt->Signature, "FACP", 4) != 0) { kerrorln("Invalid FADT signature"); Debug::DebugStatus::the()->FailBootStage(); while (1) halt(); } else { if (ACPI::ValidateSDTHeader(fadt)) { kinfoln("FADT is valid"); Debug::DebugStatus::the()->PassBootStage(Color{0x00, 0x66, 0xCC, 0xFF}); } else { kinfoln("Invalid FADT :("); Debug::DebugStatus::the()->FailBootStage(); while (1) halt(); } } ACPI::SDTHeader* madt = (ACPI::SDTHeader*)ACPI::FindTable(rootSDT, "APIC"); if (!madt) { kerrorln("MADT not found"); while (1) halt(); } KernelMemoryManager::release_unaligned_mapping(rootSDT); sleep(2500); shutdown(); while (1) halt(); loop: goto loop; }