From 6c926175afbf1f9ec2715fb007acc28588b36c4a Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 21 Aug 2018 17:54:28 +0200 Subject: cleaning up multitasking --- kernel/interrupts.c | 1 + kernel/kernel.c | 8 +++---- kernel/task.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++----- kernel/usermode.c | 15 ++++++++---- 4 files changed, 76 insertions(+), 15 deletions(-) (limited to 'kernel') diff --git a/kernel/interrupts.c b/kernel/interrupts.c index 96446f3..9b08475 100644 --- a/kernel/interrupts.c +++ b/kernel/interrupts.c @@ -51,6 +51,7 @@ void exception_handle() void int_default() { log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"default handler"); + panic(FOOLOS_MODULE_NAME,"unhandled interrupt (is this a panic or should just iognore?)"); } void show_error(uint32_t err) diff --git a/kernel/kernel.c b/kernel/kernel.c index ea14869..e1076a9 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -35,6 +35,7 @@ void kernel_main(uint32_t eax,uint32_t ebx) // KEYBOARD DRIVER keyboard_init(0); //sstdin + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Keyboard Initialized"); // MOUSE DRIVER mouse_init(); @@ -80,13 +81,10 @@ void kernel_main(uint32_t eax,uint32_t ebx) uint32_t sstdout = syscall_open("term",0,0); // stdout 1 uint32_t sstderr = syscall_open("stderr",0,0); // stderr 2 - // START INTERRUPTS (code segment: 0x08) + // INSTALL INTERRUPTS (code segment: 0x08) int_init(0x08); - // INIT MULTITASKING (and switch to our pseudo-usermode) + // INIT MULTITASKING (and start scheduler) task_init(dir); - // we should never reach this - panic(FOOLOS_MODULE_NAME,"reached end of kernel.c !!"); - } diff --git a/kernel/task.c b/kernel/task.c index c281821..395c196 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -45,7 +45,6 @@ volatile int add_task(uint32_t esp, uint32_t vmem) task_list[i].waiting=false; task_list[i].skipwait=false; task_list[i].brk=task_list[current_task].brk; - return i; } } @@ -53,9 +52,29 @@ volatile int add_task(uint32_t esp, uint32_t vmem) panic(FOOLOS_MODULE_NAME,"out of task slots!"); } +// +// REMEMBER WE ARE INSIDE AN INTERRUPT HERE - DON'T WASTE TIME! +// +// oldesp - is the adress of the stack pointer when pit_interrupt_handler was entered. +// registers have been pushed with pusha to this old stack. +// +// stack pointer was moved to the 16kb stack we have from multiboot.s +// +// we need to return a NEW stack pointer where popa will get the registers the new task requires +// +static int first=1; volatile uint32_t my_scheduler(uint32_t oldesp) { - task_list[current_task].esp=oldesp; + + // allows skipping scheduling from gdb + volatile int skippy=0; + if(skippy)return oldesp; + + if(!first) + { + task_list[current_task].esp=oldesp; + } + first=0; for(int i=0;i