From 86de700207fb0114ec52fafc36f84e1cbe508fd8 Mon Sep 17 00:00:00 2001 From: Ada Christine Date: Mon, 14 Feb 2022 00:33:18 +0000 Subject: entering idle loop works with timer --- kc/core/task.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'kc/core/task.c') diff --git a/kc/core/task.c b/kc/core/task.c index b825f01..b381793 100644 --- a/kc/core/task.c +++ b/kc/core/task.c @@ -42,10 +42,13 @@ static void lock_scheduler(void) static void unlock_scheduler(void) { - if (1 == schedule_lock_cnt) + if (schedule_lock_cnt >= 1) { schedule_lock_cnt--; - __asm__ volatile("sti;"); + } + if (schedule_lock_cnt == 0) + { + __asm__ volatile ("sti;"); } } @@ -86,6 +89,7 @@ static void idle_task_thread(void) noreturn void task_init(void) { + lock_scheduler(); char *kernel_rsp0 = vm_alloc(4096); // TODO: make it so this isn't demand-allocated. kernel_rsp0[1] = 0; @@ -95,12 +99,13 @@ noreturn void task_init(void) (struct kc_thread *)(first_task + 16384 - sizeof(*idle_thread)); idle_thread->state.stack = (uintptr_t)idle_thread; idle_thread->state.stack_top = (uintptr_t)kernel_rsp0; - + __asm__ volatile ( "mov %%cr3, %%rax\n\t" "mov %%rax, 0(%%rsi)\n\t" "mov %%rcx, %%rsp\n\t" + "call unlock_scheduler\n\t" "jmp idle_task_thread\n\t" : "=m"(idle_thread->state.page_map) : "S"(&idle_thread->state.page_map), -- cgit v1.3.1-1-g115d