From 8e3411139b27a3421e9ac75c13f14f99f6dd3137 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 2 Sep 2018 00:08:42 +0200 Subject: syscalls --- kernel/scheduler.c | 196 +++++++++++++++++++++++++++++------------------------ 1 file changed, 107 insertions(+), 89 deletions(-) (limited to 'kernel/scheduler.c') diff --git a/kernel/scheduler.c b/kernel/scheduler.c index b367825..ee1cea2 100644 --- a/kernel/scheduler.c +++ b/kernel/scheduler.c @@ -1,7 +1,3 @@ -// http://hosted.cjmovie.net/TutMultitask.htm -// -// - #include "kernel.h" #include "mem.h" #include "asm/x86.h" @@ -11,53 +7,70 @@ #include "fs/fs.h" #include "fs/ext2.h" -static volatile int volatile current_task=-1; +#define NO_TASK 0xffffffff + +static volatile uint32_t current_task=NO_TASK; static volatile struct task_list_struct { - volatile int parent; - volatile bool active; - volatile uint32_t esp; // stack pointer of the task; - volatile pdirectory *vmem; // number of virtual memory table to switch to - volatile bool waiting; - volatile bool skipwait; - volatile uint32_t brk; - volatile uint32_t esp0; - - volatile bool syscall; // waiting for syscall to be processed. + volatile bool active; // is this slot used (Y/N) + volatile uint32_t pid; // process id (TODO) + + volatile uint32_t parent; // parent process id + volatile uint32_t esp; // stack pointer of the task + volatile uint32_t esp0; // tss.esp0 + volatile pdirectory *vmem; // number of virtual memory table + + volatile uint32_t brk; // memory brk pos + + volatile bool wait; // waiting for syscall to be processed. volatile uint32_t eax; volatile uint32_t ebx; volatile uint32_t ecx; volatile uint32_t edx; - }volatile task_list[MAX_TASKS]; -volatile int add_task(uint32_t esp, uint32_t vmem) +volatile int task_reset(uint32_t pid, uint32_t entry, uint32_t stack) +{ + uint32_t *stk=task_list[pid].esp; + stk[14]=entry; + stk[17]=stack; +} + +volatile int add_task(uint32_t parent) { for(int i=0;i [%d] (free blocks remaining: %d )", current_task, pid,mem_get_free_blocks_count()); - return pid; + return ret; } // init task (root of all other tasks / processes) // @@ -220,27 +237,28 @@ volatile void scheduler_init(pdirectory *dir) // this is our main user task on slot 0 task_list[0].parent=0; task_list[0].active=true; - task_list[0].waiting=false; + task_list[0].wait=false; task_list[0].vmem=dir; - task_list[0].esp = kballoc(4)+4*4096; + task_list[0].esp = kballoc(4)+3*4096; task_list[0].esp0 = kballoc(4)+4*4096; - task_list[1].parent=0; - task_list[1].active=true; - task_list[1].waiting=false; - task_list[1].vmem=dir; - task_list[1].esp = kballoc(4)+4*4096; - task_list[1].esp0 = 0; // not needed by kernel space tasks +// task_list[1].parent=0; +// task_list[1].active=true; +// task_list[1].waiting=false; +// task_list[1].syscall=false; +// task_list[1].vmem=dir; +// task_list[1].esp = kballoc(4)+3*4096; +// task_list[1].esp0 = 0; // not needed by kernel space tasks task_list[2].parent=0; task_list[2].active=true; - task_list[2].waiting=false; + task_list[2].wait=false; task_list[2].vmem=dir; - task_list[2].esp = kballoc(4)+4*4096; + task_list[2].esp = kballoc(4)+3*4096; task_list[2].esp0 = 0; // not needed by kernel space tasks task_pusha(task_list[2].esp); - task_pusha(task_list[1].esp); +// task_pusha(task_list[1].esp); task_pusha(task_list[0].esp); // finally enable interrrupts so the scheduler is called (by timer) -- cgit v1.2.3