From 9eeb9c863209492b02ff1d61c263dd2b2632a6a3 Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Thu, 11 Nov 2021 01:49:27 +0800 Subject: [PATCH] smp: move thread_Yield to Assembly --- smp/kthread.c | 5 ----- smp/kthread_switch_asm.S | 13 +++++++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/smp/kthread.c b/smp/kthread.c index d57e24e..4fbe075 100644 --- a/smp/kthread.c +++ b/smp/kthread.c @@ -85,11 +85,6 @@ int smp_thread_Nice(smp_thread_ID id, int newnice) { return oldnice; } -void smp_thread_Yield() { - __smp_PauseTicker = true; - asm volatile("int $0x28"); // TODO This is just quick and dirty to get into the scheduler -} - void smp_thread_Sleep(int ticks) { INTERRUPT_DISABLE; __smp_Current[0]->lastTick = __smp_Now + ticks; diff --git a/smp/kthread_switch_asm.S b/smp/kthread_switch_asm.S index e4b7820..09c6a2a 100644 --- a/smp/kthread_switch_asm.S +++ b/smp/kthread_switch_asm.S @@ -6,6 +6,7 @@ extrn __smp_Now public __smp_IntSwitch_LastState public __smp_IntSwitch public __smp_Switch_Idle +public smp_thread_Yield section '.bss' writable @@ -27,6 +28,18 @@ __smp_IntSwitch_LastState: section '.text' executable +; sysvx64abi smp_thread_Yield() +; +; Sets __smp_PauseTicker. +; Pushes SS, RSP, RFLAGS, CS, RIP into the stack as Qwords, +; like what the CPU does on execption, +; and jumps to __smp_IntSwitch. +smp_thread_Yield: + mov byte [__smp_PauseTicker], 1 + int 0x28 + ret + + ; interrupt_handler smp_IntSwitch() ; ; Called from a timer interrupt.