#define MODULE "main" #include "acpi/RSDT.h" #include "assert.h" #include "config.h" #include "cpu/CPU.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/Log.h" #include "memory/KernelMemoryManager.h" #include "memory/Memory.h" #include "memory/MemoryMap.h" #include "memory/RangeAllocator.h" #include "panic/hang.h" #include "power/reboot.h" #include "rand/Mersenne.h" #include "render/Framebuffer.h" #include "render/TextRenderer.h" #include "scheduling/PIT.h" #include "std/stdio.h" #include "std/stdlib.h" #include "std/string.h" #include "thread/Scheduler.h" extern "C" void _start() { Init::check_magic(); Init::disable_smp(); // Put all other cores except the bootstrap one in an infinite loop Init::early_init(); kinfoln("Starting Moon %s", moon_version()); CPU::log_cpu_information(); Memory::walk_memory_map(); kdbgln("System memory: %ld KB", Memory::get_system() / 1024); kdbgln(" Free memory : %ld KB", kernelPMM.get_free() / 1024); kdbgln(" Used memory : %ld KB", kernelPMM.get_used() / 1024); kdbgln(" Reserved memory : %ld KB", kernelPMM.get_reserved() / 1024); GDT::load(); kinfoln("Loaded GDT"); Interrupts::install(); IDT::load(); kinfoln("Loaded IDT"); PIC::remap(); PIC::enable_master(0b11111100); // enable keyboard and PIT PIC::enable_slave(0b11111111); kinfoln("Prepared PIC"); PIT::initialize(200); // 200 times per second kinfoln("Prepared PIT"); Scheduler::init(); kinfoln("Prepared scheduler"); Scheduler::add_kernel_task([]() { while (1) { sleep(1000); for (int i = 0; i < 5; i++) { Serial::println("woo!"); } } }); Scheduler::add_kernel_task([]() { sleep(500); while (1) { sleep(2000); for (int i = 0; i < 6; i++) { Serial::println("boo!"); } } }); Scheduler::add_kernel_task([]() { sleep(20000); kinfoln("Here i am, the hard-to-get thread!"); while (1) Scheduler::yield(); }); kinfoln("Prepared scheduler tasks"); ACPI::SDTHeader* rootSDT = ACPI::GetRSDTOrXSDT(); bool isXSDT = ACPI::IsXSDT(); if (!ACPI::ValidateRSDTOrXSDT(rootSDT)) kerrorln("Invalid %s", isXSDT ? "XSDT" : "RSDT"); framebuffer0.clear(Color::Cyan); Interrupts::enable(); kinfoln("Interrupts enabled"); sleep(20000); reboot(); }