77 lines
2.0 KiB
C++
77 lines
2.0 KiB
C++
#include "Log.h"
|
|
#include "arch/CPU.h"
|
|
#include "arch/Serial.h"
|
|
#include "arch/Timer.h"
|
|
#include "boot/Init.h"
|
|
#include "config.h"
|
|
#include "memory/MemoryManager.h"
|
|
#include "thread/Scheduler.h"
|
|
#include <luna/Result.h>
|
|
#include <luna/Units.h>
|
|
|
|
void print_in_loop()
|
|
{
|
|
while (true)
|
|
{
|
|
CPU::disable_interrupts();
|
|
Serial::printf("%lu", Scheduler::current()->id);
|
|
CPU::enable_interrupts();
|
|
}
|
|
}
|
|
|
|
void print_one_and_then_yield()
|
|
{
|
|
while (true)
|
|
{
|
|
CPU::disable_interrupts();
|
|
Serial::printf("%lu", Scheduler::current()->id);
|
|
kernel_yield();
|
|
CPU::enable_interrupts();
|
|
}
|
|
}
|
|
|
|
Result<void> init()
|
|
{
|
|
kinfoln("Starting Moon %s", MOON_VERSION);
|
|
|
|
kinfoln("Current platform: %s", CPU::platform_string());
|
|
|
|
kinfoln("Current processor: %s", CPU::identify().value_or("(unknown)"));
|
|
|
|
Timer::init();
|
|
|
|
char buffer[64];
|
|
to_dynamic_unit(MemoryManager::total(), buffer, sizeof(buffer));
|
|
kinfoln("Total memory: %s", buffer);
|
|
to_dynamic_unit(MemoryManager::free(), buffer, sizeof(buffer));
|
|
kinfoln("Free memory: %s", buffer);
|
|
to_dynamic_unit(MemoryManager::used(), buffer, sizeof(buffer));
|
|
kinfoln("Used memory: %s", buffer);
|
|
to_dynamic_unit(MemoryManager::reserved(), buffer, sizeof(buffer));
|
|
kinfoln("Reserved memory: %s", buffer);
|
|
|
|
Scheduler::init();
|
|
|
|
TRY(Scheduler::new_kernel_thread(print_in_loop));
|
|
TRY(Scheduler::new_kernel_thread(print_in_loop));
|
|
TRY(Scheduler::new_kernel_thread(print_in_loop));
|
|
TRY(Scheduler::new_kernel_thread(print_in_loop));
|
|
TRY(Scheduler::new_kernel_thread(print_in_loop));
|
|
TRY(Scheduler::new_kernel_thread(print_in_loop));
|
|
TRY(Scheduler::new_kernel_thread(print_one_and_then_yield));
|
|
|
|
CPU::platform_finish_init();
|
|
|
|
CPU::enable_interrupts();
|
|
|
|
return {};
|
|
}
|
|
|
|
extern "C" [[noreturn]] void _start()
|
|
{
|
|
Init::check_magic();
|
|
Init::early_init();
|
|
auto rc = init();
|
|
if (rc.has_error()) kerrorln("Runtime error: %s", rc.error_string());
|
|
CPU::idle_loop();
|
|
} |