From c561b0b310cb5e09cb69549dd27812b0bb06563f Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 7 Dec 2022 15:04:02 +0100 Subject: [PATCH] x86_64: Invoke the scheduler every millisecond --- kernel/src/arch/x86_64/CPU.asm | 7 +------ kernel/src/arch/x86_64/CPU.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/kernel/src/arch/x86_64/CPU.asm b/kernel/src/arch/x86_64/CPU.asm index 59f4d68a..f3e2d2fc 100644 --- a/kernel/src/arch/x86_64/CPU.asm +++ b/kernel/src/arch/x86_64/CPU.asm @@ -48,12 +48,7 @@ load_tr: ltr ax ret -global switch_task -switch_task: - cli -.loop: - hlt - jmp .loop +extern switch_task global kernel_yield kernel_yield: diff --git a/kernel/src/arch/x86_64/CPU.cpp b/kernel/src/arch/x86_64/CPU.cpp index 40e86dc6..6a9f8600 100644 --- a/kernel/src/arch/x86_64/CPU.cpp +++ b/kernel/src/arch/x86_64/CPU.cpp @@ -3,6 +3,7 @@ #include "arch/Timer.h" #include "arch/x86_64/CPU.h" #include "arch/x86_64/IO.h" +#include "thread/Scheduler.h" #include #include #include @@ -336,6 +337,7 @@ extern "C" void arch_interrupt_entry(Registers* regs) else if (regs->isr == 32) { Timer::tick(); + if (should_invoke_scheduler()) Scheduler::invoke(regs); pic_eoi(regs); } else @@ -442,4 +444,10 @@ namespace CPU { task_state_segment.rsp[0] = top; } +} + +// called by kernel_yield +extern "C" void switch_task(Registers* regs) +{ + Scheduler::switch_task(regs); } \ No newline at end of file