Add a basic scheduler with threads #18

Merged
apio merged 19 commits from threads into restart 2022-12-07 16:11:59 +00:00
2 changed files with 13 additions and 3 deletions
Showing only changes of commit 7db1a8253b - Show all commits

View File

@ -13,6 +13,8 @@ namespace CPU
[[noreturn]] void efficient_halt();
void idle_loop();
void switch_kernel_stack(u64 top);
void enable_interrupts();

View File

@ -1,14 +1,14 @@
#include "arch/CPU.h"
#include "arch/x86_64/CPU.h"
#include "Log.h"
#include "arch/Timer.h"
#include "arch/x86_64/CPU.h"
#include "arch/x86_64/IO.h"
#include <cpuid.h>
#include <luna/Check.h>
#include <luna/Result.h>
#include <luna/String.h>
#include <luna/SystemError.h>
#include <luna/Types.h>
#include <luna/Check.h>
#include <luna/Result.h>
extern "C" void enable_sse();
extern "C" void enable_write_protect();
@ -430,6 +430,14 @@ namespace CPU
goto loop; // Safeguard: if we ever wake up, start our low-power rest again
}
void idle_loop()
{
asm volatile("sti");
loop:
asm volatile("hlt");
goto loop;
}
void switch_kernel_stack(u64 top)
{
task_state_segment.rsp[0] = top;