Luna/kernel/src/main.cpp
apio 26211bd49f It (almost) works now
The only thing doing weird stuff is exec(), so that's commented out and throws ENOSYS right now.

But we have two user tasks running in parallel, isolated from each other!
2022-10-14 16:46:00 +02:00

101 lines
2.2 KiB
C++

#define MODULE "main"
#include "acpi/RSDT.h"
#include "assert.h"
#include "config.h"
#include "cpu/CPU.h"
#include "fs/VFS.h"
#include "fs/devices/DeviceFS.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/PCI.h"
#include "io/PIC.h"
#include "io/Serial.h"
#include "log/Log.h"
#include "memory/AddressSpace.h"
#include "memory/Memory.h"
#include "memory/MemoryManager.h"
#include "memory/MemoryMap.h"
#include "memory/PMM.h"
#include "memory/VMM.h"
#include "misc/PCITypes.h"
#include "misc/reboot.h"
#include "panic/Panic.h"
#include "rand/Mersenne.h"
#include "render/Framebuffer.h"
#include "render/TextRenderer.h"
#include "std/stdio.h"
#include "std/stdlib.h"
#include "std/string.h"
#include "sys/elf/ELFLoader.h"
#include "thread/PIT.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();
GDT::load();
kinfoln("Loaded GDT");
Interrupts::install();
IDT::load();
kinfoln("Loaded IDT");
PIT::initialize(1000); // 1000 times per second
kinfoln("Prepared PIT");
Scheduler::init();
kinfoln("Prepared scheduler");
Scheduler::add_kernel_task([]() {
while (1)
{
sleep(400);
Scheduler::reap_tasks();
}
});
Scheduler::load_user_task("/bin/init");
Scheduler::load_user_task("/bin/sym");
kinfoln("Prepared scheduler tasks");
ASSERT(VFS::mkdir("/", "dev") == 0);
VFS::mount("/dev", DeviceFS::get());
Init::finish_kernel_boot();
PIC::remap();
PIC::enable_master(0b11111100); // enable keyboard and PIT
PIC::enable_slave(0b11111111);
kinfoln("Prepared PIC");
Interrupts::enable(); // Task switching commences here
kinfoln("Interrupts enabled");
PCI::scan([](PCI::Device& dev) {
kinfoln("Found PCI device %x:%x, %s", dev.id().vendor, dev.id().device, pci_type_name(dev.type()));
});
Scheduler::exit(0);
}