Initialize and demo the scheduler
This commit is contained in:
parent
c907e16311
commit
f169718a4b
@ -1,12 +1,35 @@
|
|||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "arch/CPU.h"
|
#include "arch/CPU.h"
|
||||||
|
#include "arch/Serial.h"
|
||||||
#include "arch/Timer.h"
|
#include "arch/Timer.h"
|
||||||
#include "boot/Init.h"
|
#include "boot/Init.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "memory/MemoryManager.h"
|
#include "memory/MemoryManager.h"
|
||||||
|
#include "thread/Scheduler.h"
|
||||||
#include <luna/Result.h>
|
#include <luna/Result.h>
|
||||||
#include <luna/Units.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()
|
Result<void> init()
|
||||||
{
|
{
|
||||||
kinfoln("Starting Moon %s", MOON_VERSION);
|
kinfoln("Starting Moon %s", MOON_VERSION);
|
||||||
@ -17,10 +40,6 @@ Result<void> init()
|
|||||||
|
|
||||||
Timer::init();
|
Timer::init();
|
||||||
|
|
||||||
CPU::platform_finish_init();
|
|
||||||
|
|
||||||
CPU::enable_interrupts();
|
|
||||||
|
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
to_dynamic_unit(MemoryManager::total(), buffer, sizeof(buffer));
|
to_dynamic_unit(MemoryManager::total(), buffer, sizeof(buffer));
|
||||||
kinfoln("Total memory: %s", buffer);
|
kinfoln("Total memory: %s", buffer);
|
||||||
@ -31,6 +50,20 @@ Result<void> init()
|
|||||||
to_dynamic_unit(MemoryManager::reserved(), buffer, sizeof(buffer));
|
to_dynamic_unit(MemoryManager::reserved(), buffer, sizeof(buffer));
|
||||||
kinfoln("Reserved memory: %s", 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 {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,5 +73,5 @@ extern "C" [[noreturn]] void _start()
|
|||||||
Init::early_init();
|
Init::early_init();
|
||||||
auto rc = init();
|
auto rc = init();
|
||||||
if (rc.has_error()) kerrorln("Runtime error: %s", rc.error_string());
|
if (rc.has_error()) kerrorln("Runtime error: %s", rc.error_string());
|
||||||
CPU::efficient_halt();
|
CPU::idle_loop();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user