2022-09-07 13:02:23 +00:00
|
|
|
#define MODULE "main"
|
|
|
|
|
2022-09-07 13:02:54 +00:00
|
|
|
#include "config.h"
|
2022-09-05 14:13:51 +00:00
|
|
|
#include "cpu/CPU.h"
|
2022-10-11 17:21:16 +00:00
|
|
|
#include "fs/devices/DeviceFS.h"
|
2022-09-05 14:13:51 +00:00
|
|
|
#include "gdt/GDT.h"
|
|
|
|
#include "init/Init.h"
|
|
|
|
#include "interrupts/IDT.h"
|
|
|
|
#include "interrupts/Install.h"
|
|
|
|
#include "interrupts/Interrupts.h"
|
|
|
|
#include "io/PIC.h"
|
|
|
|
#include "log/Log.h"
|
2022-09-05 15:13:12 +00:00
|
|
|
#include "memory/Memory.h"
|
2022-09-07 17:41:08 +00:00
|
|
|
#include "memory/MemoryMap.h"
|
2022-10-17 17:12:47 +00:00
|
|
|
#include "misc/hang.h"
|
2022-10-19 15:41:23 +00:00
|
|
|
#include "std/assert.h"
|
2022-09-05 14:13:51 +00:00
|
|
|
#include "std/stdlib.h"
|
2022-09-21 15:56:53 +00:00
|
|
|
#include "thread/PIT.h"
|
2022-09-20 17:58:04 +00:00
|
|
|
#include "thread/Scheduler.h"
|
2022-09-05 14:13:51 +00:00
|
|
|
|
2022-10-16 13:31:58 +00:00
|
|
|
#define STRINGIZE(x) #x
|
|
|
|
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
|
|
|
|
|
2022-09-05 14:13:51 +00:00
|
|
|
extern "C" void _start()
|
|
|
|
{
|
|
|
|
Init::disable_smp(); // Put all other cores except the bootstrap one in an infinite loop
|
2022-10-29 18:10:49 +00:00
|
|
|
Init::check_magic();
|
2022-09-05 14:13:51 +00:00
|
|
|
Init::early_init();
|
|
|
|
|
2022-09-20 14:34:24 +00:00
|
|
|
kinfoln("Starting Moon %s", moon_version());
|
2022-09-07 17:41:08 +00:00
|
|
|
|
|
|
|
CPU::log_cpu_information();
|
|
|
|
|
|
|
|
Memory::walk_memory_map();
|
2022-09-05 14:13:51 +00:00
|
|
|
|
|
|
|
GDT::load();
|
|
|
|
|
|
|
|
kinfoln("Loaded GDT");
|
|
|
|
|
|
|
|
Interrupts::install();
|
|
|
|
|
|
|
|
IDT::load();
|
|
|
|
|
|
|
|
kinfoln("Loaded IDT");
|
|
|
|
|
2022-10-13 19:55:51 +00:00
|
|
|
PIT::initialize(1000); // 1000 times per second
|
|
|
|
|
|
|
|
kinfoln("Prepared PIT");
|
|
|
|
|
2022-09-20 17:58:04 +00:00
|
|
|
Scheduler::init();
|
2022-09-05 14:13:51 +00:00
|
|
|
|
2022-09-20 17:58:04 +00:00
|
|
|
kinfoln("Prepared scheduler");
|
|
|
|
|
2022-10-17 17:12:47 +00:00
|
|
|
#ifdef RUN_TEST_AS_INIT
|
|
|
|
ASSERT(Scheduler::load_user_task(STRINGIZE_VALUE_OF(RUN_TEST_AS_INIT)) > 0);
|
|
|
|
#else
|
|
|
|
ASSERT(Scheduler::load_user_task("/bin/init") > 0);
|
|
|
|
#endif
|
|
|
|
|
2022-10-22 12:43:41 +00:00
|
|
|
Scheduler::add_kernel_task("[reaper]", []() {
|
2022-09-21 19:06:00 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
sleep(400);
|
|
|
|
Scheduler::reap_tasks();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-09-20 17:58:04 +00:00
|
|
|
kinfoln("Prepared scheduler tasks");
|
2022-09-05 14:13:51 +00:00
|
|
|
|
2022-10-16 12:45:25 +00:00
|
|
|
ASSERT(VFS::mkdir("/dev") == 0);
|
2022-10-11 17:21:16 +00:00
|
|
|
VFS::mount("/dev", DeviceFS::get());
|
|
|
|
|
2022-10-11 17:53:55 +00:00
|
|
|
Init::finish_kernel_boot();
|
|
|
|
|
2022-10-13 19:14:39 +00:00
|
|
|
PIC::remap();
|
2022-10-17 17:12:47 +00:00
|
|
|
PIC::enable_master(0b11111100);
|
2022-10-13 19:14:39 +00:00
|
|
|
PIC::enable_slave(0b11111111);
|
|
|
|
|
2022-10-17 17:12:47 +00:00
|
|
|
Interrupts::enable();
|
2022-09-21 15:57:02 +00:00
|
|
|
|
2022-10-17 17:12:47 +00:00
|
|
|
while (1) halt();
|
2022-09-05 14:13:51 +00:00
|
|
|
}
|