From 9012ccc49e7a44e4d0922c7d5b2f3648635eb5cc Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 1 Oct 2022 12:16:30 +0200 Subject: [PATCH] Remove _userspace and move the idle task to assembly --- kernel/src/main.asm | 47 +++++++-------------------------- kernel/src/thread/Scheduler.cpp | 10 +++---- 2 files changed, 13 insertions(+), 44 deletions(-) diff --git a/kernel/src/main.asm b/kernel/src/main.asm index c67ee078..7c5c15f8 100644 --- a/kernel/src/main.asm +++ b/kernel/src/main.asm @@ -4,41 +4,14 @@ extern _start _main: xor rbp, rbp call _start + cli +.hang: + hlt + jmp .hang -global _userspace -_userspace: - mov rdi, 4000 ; 4000 ms / 4 seconds - mov rax, 2 ; sys_sleep - int 42h - cmp rax, 0 - jne .fail ; syscall failed - mov rdi, .message - mov rsi, 33 - mov rax, 3 ; sys_write - int 42h - cmp rax, 33 - jne .fail ; syscall did not write enough bytes -.draw: - mov rax, 5 ; sys_rand - int 42h - mov r9, rax ; color - mov rdi, 20 ; x - mov rsi, 20 ; y - mov r10, 40 ; width - mov r8, 30 ; height - mov rax, 4 ; sys_paint - int 42h - cmp rax, 0 - jne .fail - mov rdi, 100 - mov rax, 2 ; sys_sleep - int 42h - cmp rax, 0 - jne .fail - jmp .draw -.fail: - mov rax, 0 ; sys_exit - int 42h - jmp $ ; sys_exit failed, nothing more we can do -.message: - db "userspace preparing for painting", 0xA \ No newline at end of file +global idle_task_function +idle_task_function: + sti +.idle: + hlt + jmp .idle \ No newline at end of file diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index 46413039..2c5801dc 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -25,10 +25,7 @@ static Task* sched_current_task; static Task* base_task; static Task* end_task; -static void idle_task_function() -{ - while (1) asm volatile("hlt"); -} +extern "C" void idle_task_function(); static uint64_t frequency; @@ -36,12 +33,11 @@ void Scheduler::init() { memset(&idle_task, 0, sizeof(Task)); idle_task.id = free_tid++; - idle_task.regs.rip = (uint64_t)&idle_task_function; + idle_task.regs.rip = (uint64_t)idle_task_function; idle_task.regs.rsp = (uint64_t)MemoryManager::get_page(); idle_task.regs.cs = 0x08; idle_task.regs.ss = 0x10; - asm volatile("pushfq; movq (%%rsp), %%rax; movq %%rax, %0; popfq;" : "=m"(idle_task.regs.rflags)::"%rax"); - idle_task.regs.rflags |= 0x200; + idle_task.regs.rflags = (1 << 21) | (1 << 9); idle_task.task_sleep = 1000; idle_task.state = idle_task.Idle;