From a8ed090450c5a414b1d8fec4372e23006e4828ae Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Mon, 8 Nov 2021 12:56:33 +0800 Subject: [PATCH] smp: move the ticking from C to Assembly --- smp/kthread_switch.c | 8 -------- smp/kthread_switch_asm.S | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/smp/kthread_switch.c b/smp/kthread_switch.c index b615b2d..0abb604 100644 --- a/smp/kthread_switch.c +++ b/smp/kthread_switch.c @@ -27,14 +27,6 @@ static void printTree(tree_Node *root, int level, __tree_ConnectType type) { SYSV_ABI uintptr_t __smp_Switch() { // the calling function smp_IntSwitch already CLI-ed for us - // TODO ticker and switch should be 2 functions! - if (!__smp_PauseTicker) { - __smp_Now++; - if (__smp_Now % 8) - return 0; - } else - __smp_PauseTicker = false; - //io_Printf("__smp_Switch: Tick: %d, switching\n", __smp_Now); __smp_Thread *t = __smp_Current[0]; diff --git a/smp/kthread_switch_asm.S b/smp/kthread_switch_asm.S index 8332c9a..e4b7820 100644 --- a/smp/kthread_switch_asm.S +++ b/smp/kthread_switch_asm.S @@ -1,6 +1,8 @@ format elf64 extrn __smp_Switch +extrn __smp_PauseTicker +extrn __smp_Now public __smp_IntSwitch_LastState public __smp_IntSwitch public __smp_Switch_Idle @@ -33,6 +35,29 @@ __smp_IntSwitch: cli mov [__smp_IntSwitch_LastState], rax + + ; if (!__smp_PauseTicker) { + ; __smp_Now++; + ; if (__smp_Now % 8) + ; return 0; + ; } else + ; __smp_PauseTicker = false; + mov al, [__smp_PauseTicker] + test al, al + jnz .noticker + + mov rax, [__smp_Now] + inc rax + mov [__smp_Now], rax + test rax, 0x7 + jz .realcall + mov rax, [__smp_IntSwitch_LastState] + iret + +.noticker: + mov byte [__smp_PauseTicker], 0 + +.realcall: mov [__smp_IntSwitch_LastState+8], rbx mov [__smp_IntSwitch_LastState+16], rcx mov [__smp_IntSwitch_LastState+24], rdx