Initialize and demo the scheduler

This commit is contained in:
apio 2022-12-07 15:04:11 +01:00 committed by Gitea
parent c907e16311
commit f169718a4b

View File

@ -1,12 +1,35 @@
#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);
@ -17,10 +40,6 @@ Result<void> init()
Timer::init();
CPU::platform_finish_init();
CPU::enable_interrupts();
char buffer[64];
to_dynamic_unit(MemoryManager::total(), buffer, sizeof(buffer));
kinfoln("Total memory: %s", buffer);
@ -31,6 +50,20 @@ Result<void> init()
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 {};
}
@ -40,5 +73,5 @@ extern "C" [[noreturn]] void _start()
Init::early_init();
auto rc = init();
if (rc.has_error()) kerrorln("Runtime error: %s", rc.error_string());
CPU::efficient_halt();
CPU::idle_loop();
}