2022-09-07 15:02:23 +02:00
|
|
|
#define MODULE "main"
|
|
|
|
|
2022-09-07 15:02:54 +02:00
|
|
|
#include "config.h"
|
2022-09-05 16:13:51 +02:00
|
|
|
#include "cpu/CPU.h"
|
2022-11-12 18:13:41 +01:00
|
|
|
#include "fs/TmpFS.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"
|
|
|
|
#include "interrupts/IDT.h"
|
|
|
|
#include "interrupts/Install.h"
|
|
|
|
#include "interrupts/Interrupts.h"
|
|
|
|
#include "io/PIC.h"
|
|
|
|
#include "log/Log.h"
|
2022-09-05 17:13:12 +02:00
|
|
|
#include "memory/Memory.h"
|
2022-09-07 19:41:08 +02:00
|
|
|
#include "memory/MemoryMap.h"
|
2022-10-17 19:12:47 +02:00
|
|
|
#include "misc/hang.h"
|
2022-11-09 15:28:35 +01:00
|
|
|
#include "std/ensure.h"
|
2022-09-05 16:13:51 +02:00
|
|
|
#include "std/stdlib.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::disable_smp(); // Put all other cores except the bootstrap one in an infinite loop
|
2022-10-29 20:10:49 +02:00
|
|
|
Init::check_magic();
|
2022-09-05 16:13:51 +02:00
|
|
|
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();
|
|
|
|
|
|
|
|
Interrupts::install();
|
|
|
|
|
|
|
|
IDT::load();
|
|
|
|
|
2022-10-13 21:55:51 +02:00
|
|
|
PIT::initialize(1000); // 1000 times per second
|
|
|
|
|
2022-09-20 19:58:04 +02:00
|
|
|
Scheduler::init();
|
2022-09-05 16:13:51 +02:00
|
|
|
|
2022-10-17 19:12:47 +02:00
|
|
|
#ifdef RUN_TEST_AS_INIT
|
2022-11-02 19:38:15 +01:00
|
|
|
ensure(Scheduler::load_user_task(STRINGIZE_VALUE_OF(RUN_TEST_AS_INIT)) > 0);
|
2022-10-17 19:12:47 +02:00
|
|
|
#else
|
2022-11-02 19:38:15 +01:00
|
|
|
ensure(Scheduler::load_user_task("/bin/init") > 0);
|
2022-10-17 19:12:47 +02:00
|
|
|
#endif
|
|
|
|
|
2022-10-22 14:43:41 +02:00
|
|
|
Scheduler::add_kernel_task("[reaper]", []() {
|
2022-09-21 21:06:00 +02:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
sleep(400);
|
|
|
|
Scheduler::reap_tasks();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-11-02 19:38:15 +01:00
|
|
|
ensure(VFS::mkdir("/dev") == 0);
|
2022-11-12 18:13:41 +01:00
|
|
|
ensure(VFS::mkdir("/tmp") == 0);
|
2022-10-11 19:21:16 +02:00
|
|
|
VFS::mount("/dev", DeviceFS::get());
|
2022-11-12 18:13:41 +01:00
|
|
|
VFS::mount("/tmp", TmpFS::get());
|
2022-10-11 19:21:16 +02:00
|
|
|
|
2022-10-11 19:53:55 +02:00
|
|
|
Init::finish_kernel_boot();
|
|
|
|
|
2022-10-13 21:14:39 +02:00
|
|
|
PIC::remap();
|
2022-10-17 19:12:47 +02:00
|
|
|
PIC::enable_master(0b11111100);
|
2022-10-13 21:14:39 +02:00
|
|
|
PIC::enable_slave(0b11111111);
|
|
|
|
|
2022-10-17 19:12:47 +02:00
|
|
|
Interrupts::enable();
|
2022-09-21 17:57:02 +02:00
|
|
|
|
2022-11-09 15:58:00 +01:00
|
|
|
while (1)
|
|
|
|
halt(); // As soon as the first timer interrupt arrives, this idle loop is gone, since the main function is not
|
|
|
|
// registered as a task and thus the scheduler will never schedule this again. We still have to do
|
|
|
|
// something while waiting for a timer interrupt to arrive, though. In fact, in most cases, calling
|
|
|
|
// halt() once would be enough, since that function halts the CPU until the next interrupt (most likely
|
|
|
|
// the timer one) arrives. But we have to guarantee this function never returns.
|
2022-09-05 16:13:51 +02:00
|
|
|
}
|