diff options
| author | Ada Christine <adachristine18@gmail.com> | 2022-01-17 14:03:39 +0000 |
|---|---|---|
| committer | Ada Christine <adachristine18@gmail.com> | 2022-01-17 14:03:39 +0000 |
| commit | 4130fbcdcfd2baa6d1f9b065ce34afa2a339f670 (patch) | |
| tree | 5b44d1ca1c17bbb57dfb577a54e567086fa9690f /kc | |
| parent | 8c56039ca130dfef1f0bf204cc702eeb10801379 (diff) | |
entering the idle task appears to work
Diffstat (limited to 'kc')
| -rw-r--r-- | kc/core/Makefile | 2 | ||||
| -rw-r--r-- | kc/core/exceptions.S | 3 | ||||
| -rw-r--r-- | kc/core/kc_main.c | 5 | ||||
| -rw-r--r-- | kc/core/memory.c | 2 | ||||
| -rw-r--r-- | kc/core/task.c | 38 | ||||
| -rw-r--r-- | kc/core/task.h | 2 |
6 files changed, 48 insertions, 4 deletions
diff --git a/kc/core/Makefile b/kc/core/Makefile index 2b8ab8d..7458ba5 100644 --- a/kc/core/Makefile +++ b/kc/core/Makefile @@ -12,7 +12,7 @@ CFLAGS += -Wno-unused-const-variable -Wno-unused-function -fvisibility=hidden -g SOBJS := GOBJS := entry_x86_64.o reloc_x86_64.o kprint.o serial.o port.o \ kc_main.o main.o memory.o memset.o memcpy.o memmove.o memcmp.o cpu.o \ - vm_tree.o exceptions.o panic.o msr.o + vm_tree.o exceptions.o panic.o msr.o task.o cpu_task.o IOBJS := # __attribute__((interrupt)) requires -mgeneral-regs-only diff --git a/kc/core/exceptions.S b/kc/core/exceptions.S index 46b9947..0a5b760 100644 --- a/kc/core/exceptions.S +++ b/kc/core/exceptions.S @@ -26,6 +26,7 @@ .macro ISR_RESTORE_REGISTERS // restore all the registers + pop %r15 pop %r14 pop %r13 pop %r12 @@ -57,7 +58,7 @@ page_fault_isr: ISR_STORE_REGISTERS /* collect parameters for page fault handler */ - mov 48(%rsp), %rdi /* error code is first parameter */ + mov 120(%rsp), %rdi /* error code is first parameter */ mov %cr2, %rsi /* PFLA is next parameter */ /* stack has to be aligned */ ISR_CALL page_fault_handler diff --git a/kc/core/kc_main.c b/kc/core/kc_main.c index 1eb07da..68fcb0a 100644 --- a/kc/core/kc_main.c +++ b/kc/core/kc_main.c @@ -3,6 +3,7 @@ #include "kprint.h" #include "memory.h" #include "panic.h" +#include "task.h" #include <kernel/entry.h> @@ -19,6 +20,8 @@ unsigned long kc_main(struct kc_boot_data *data) serial_init(); kputs("<hacker voice> i'm in 3333\r\n"); memory_init(data); - halt(); + task_init(); + + return 0; } diff --git a/kc/core/memory.c b/kc/core/memory.c index 9956bfd..ba0ca57 100644 --- a/kc/core/memory.c +++ b/kc/core/memory.c @@ -537,12 +537,12 @@ static uint64_t *get_kernel_pm2e(void *vaddr) return &kernel_pm2[kpm2_index(vaddr)]; } - int anonymous_page_handler(uint32_t code, void *address) { kputs("anonymous space fault\n"); if (code & PAGE_PR) { + kputs("can't fault a present page\n"); // there's no reason a protection violation should happen // in anonymous space panic(UNHANDLED_FAULT); 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); } diff --git a/kc/core/task.h b/kc/core/task.h index 86e262f..e9ddaaf 100644 --- a/kc/core/task.h +++ b/kc/core/task.h @@ -31,3 +31,5 @@ extern void cpu_set_thread( struct kc_thread_state *next, uint64_t *cpu_tss_rsp0); +void task_init(void); + |
