summaryrefslogtreecommitdiff
path: root/kc/core/task.c
diff options
context:
space:
mode:
authorAda Christine <adachristine18@gmail.com>2022-01-17 14:03:39 +0000
committerAda Christine <adachristine18@gmail.com>2022-01-17 14:03:39 +0000
commit4130fbcdcfd2baa6d1f9b065ce34afa2a339f670 (patch)
tree5b44d1ca1c17bbb57dfb577a54e567086fa9690f /kc/core/task.c
parent8c56039ca130dfef1f0bf204cc702eeb10801379 (diff)
entering the idle task appears to work
Diffstat (limited to 'kc/core/task.c')
-rw-r--r--kc/core/task.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/kc/core/task.c b/kc/core/task.c
index 8f78516..b825f01 100644
--- a/kc/core/task.c
+++ b/kc/core/task.c
@@ -2,6 +2,7 @@
#include "memory.h"
#include "panic.h"
#include "cpu.h"
+#include "kprint.h"
struct kc_thread *current_task = NULL;
struct kc_thread *first_ready_task = NULL;
@@ -72,5 +73,42 @@ static void set_thread_status(enum kc_thread_status status)
static void idle_task_thread(void)
{
+ kputs("in idle thread\n");
+ while (1)
+ {
+ __asm__ volatile ("hlt;");
+ }
+ kputs("scheduling\n");
+ lock_scheduler();
+ task_schedule();
+ unlock_scheduler();
+}
+
+noreturn void task_init(void)
+{
+ char *kernel_rsp0 = vm_alloc(4096);
+ // TODO: make it so this isn't demand-allocated.
+ kernel_rsp0[1] = 0;
+ *get_tss_rsp0() = (uintptr_t)kernel_rsp0;
+ char *first_task = vm_alloc(16384);
+ struct kc_thread *idle_thread =
+ (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"
+ "jmp idle_task_thread\n\t"
+ : "=m"(idle_thread->state.page_map)
+ : "S"(&idle_thread->state.page_map),
+ "c"(idle_thread)
+ : "rax"
+ );
+
+ // shouldn't ever get here
+ panic(GENERAL_PANIC);
}