2022-09-07 15:02:23 +02:00
|
|
|
#define MODULE "main"
|
|
|
|
|
2022-09-05 16:13:51 +02:00
|
|
|
#include "acpi/RSDT.h"
|
2022-09-07 15:02:54 +02:00
|
|
|
#include "config.h"
|
2022-09-05 16:13:51 +02:00
|
|
|
#include "cpu/CPU.h"
|
2022-10-08 21:22:46 +02:00
|
|
|
#include "fs/VFS.h"
|
2022-10-11 19:21:16 +02:00
|
|
|
#include "fs/devices/DeviceFS.h"
|
2022-09-05 16:13:51 +02:00
|
|
|
#include "gdt/GDT.h"
|
|
|
|
#include "init/Init.h"
|
2022-09-14 17:55:24 +02:00
|
|
|
#include "init/InitRD.h"
|
2022-09-05 16:13:51 +02:00
|
|
|
#include "interrupts/IDT.h"
|
|
|
|
#include "interrupts/Install.h"
|
|
|
|
#include "interrupts/Interrupts.h"
|
2022-09-21 17:57:02 +02:00
|
|
|
#include "io/PCI.h"
|
2022-09-05 16:13:51 +02:00
|
|
|
#include "io/PIC.h"
|
2022-09-20 19:58:04 +02:00
|
|
|
#include "io/Serial.h"
|
2022-10-15 12:56:48 +02:00
|
|
|
#include "kassert.h"
|
2022-09-05 16:13:51 +02:00
|
|
|
#include "log/Log.h"
|
2022-10-13 19:19:51 +02:00
|
|
|
#include "memory/AddressSpace.h"
|
2022-09-05 17:13:12 +02:00
|
|
|
#include "memory/Memory.h"
|
2022-09-24 21:45:13 +02:00
|
|
|
#include "memory/MemoryManager.h"
|
2022-09-07 19:41:08 +02:00
|
|
|
#include "memory/MemoryMap.h"
|
2022-09-24 21:27:45 +02:00
|
|
|
#include "memory/PMM.h"
|
2022-09-23 16:41:43 +02:00
|
|
|
#include "memory/VMM.h"
|
2022-09-23 18:01:07 +02:00
|
|
|
#include "misc/PCITypes.h"
|
2022-09-21 17:56:53 +02:00
|
|
|
#include "misc/reboot.h"
|
2022-09-25 16:56:00 +02:00
|
|
|
#include "panic/Panic.h"
|
2022-09-14 18:54:40 +02:00
|
|
|
#include "rand/Mersenne.h"
|
2022-09-10 18:42:40 +02:00
|
|
|
#include "render/Framebuffer.h"
|
2022-09-11 08:23:32 +02:00
|
|
|
#include "render/TextRenderer.h"
|
2022-09-05 16:13:51 +02:00
|
|
|
#include "std/stdio.h"
|
|
|
|
#include "std/stdlib.h"
|
|
|
|
#include "std/string.h"
|
2022-10-01 12:17:16 +02:00
|
|
|
#include "sys/elf/ELFLoader.h"
|
2022-09-21 17:56:53 +02:00
|
|
|
#include "thread/PIT.h"
|
2022-09-20 19:58:04 +02:00
|
|
|
#include "thread/Scheduler.h"
|
2022-09-05 16:13:51 +02:00
|
|
|
|
2022-10-16 15:31:58 +02:00
|
|
|
#define STRINGIZE(x) #x
|
|
|
|
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
|
|
|
|
|
2022-09-05 16:13:51 +02:00
|
|
|
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();
|
|
|
|
|
2022-09-20 16:34:24 +02:00
|
|
|
kinfoln("Starting Moon %s", moon_version());
|
2022-09-07 19:41:08 +02:00
|
|
|
|
|
|
|
CPU::log_cpu_information();
|
|
|
|
|
|
|
|
Memory::walk_memory_map();
|
2022-09-05 16:13:51 +02:00
|
|
|
|
|
|
|
GDT::load();
|
|
|
|
|
|
|
|
kinfoln("Loaded GDT");
|
|
|
|
|
|
|
|
Interrupts::install();
|
|
|
|
|
|
|
|
IDT::load();
|
|
|
|
|
|
|
|
kinfoln("Loaded IDT");
|
|
|
|
|
2022-10-13 21:55:51 +02:00
|
|
|
PIT::initialize(1000); // 1000 times per second
|
|
|
|
|
|
|
|
kinfoln("Prepared PIT");
|
|
|
|
|
2022-09-20 19:58:04 +02:00
|
|
|
Scheduler::init();
|
2022-09-05 16:13:51 +02:00
|
|
|
|
2022-09-20 19:58:04 +02:00
|
|
|
kinfoln("Prepared scheduler");
|
|
|
|
|
2022-09-21 21:06:00 +02:00
|
|
|
Scheduler::add_kernel_task([]() {
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
sleep(400);
|
|
|
|
Scheduler::reap_tasks();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-10-16 15:31:58 +02:00
|
|
|
#ifdef RUN_TEST_AS_INIT
|
2022-10-16 18:48:35 +02:00
|
|
|
ASSERT(Scheduler::load_user_task(STRINGIZE_VALUE_OF(RUN_TEST_AS_INIT)) > 0);
|
2022-10-16 15:31:58 +02:00
|
|
|
#else
|
2022-10-16 18:48:35 +02:00
|
|
|
ASSERT(Scheduler::load_user_task("/bin/init") > 0);
|
2022-10-16 15:31:58 +02:00
|
|
|
#endif
|
2022-09-25 20:35:05 +02:00
|
|
|
|
2022-09-20 19:58:04 +02:00
|
|
|
kinfoln("Prepared scheduler tasks");
|
2022-09-05 16:13:51 +02:00
|
|
|
|
2022-10-16 14:45:25 +02:00
|
|
|
ASSERT(VFS::mkdir("/dev") == 0);
|
2022-10-11 19:21:16 +02:00
|
|
|
VFS::mount("/dev", DeviceFS::get());
|
|
|
|
|
2022-10-11 19:53:55 +02:00
|
|
|
Init::finish_kernel_boot();
|
|
|
|
|
2022-10-13 21:14:39 +02:00
|
|
|
PIC::remap();
|
|
|
|
PIC::enable_master(0b11111100); // enable keyboard and PIT
|
|
|
|
PIC::enable_slave(0b11111111);
|
|
|
|
|
2022-09-20 19:58:04 +02:00
|
|
|
kinfoln("Interrupts enabled");
|
|
|
|
|
2022-09-23 17:24:45 +02:00
|
|
|
PCI::scan([](PCI::Device& dev) {
|
2022-09-23 18:01:07 +02:00
|
|
|
kinfoln("Found PCI device %x:%x, %s", dev.id().vendor, dev.id().device, pci_type_name(dev.type()));
|
2022-09-21 17:57:02 +02:00
|
|
|
});
|
|
|
|
|
2022-10-08 17:56:40 +02:00
|
|
|
Scheduler::exit(0);
|
2022-09-05 16:13:51 +02:00
|
|
|
}
|