diff options
Diffstat (limited to 'kernel/task.c')
| -rw-r--r-- | kernel/task.c | 124 |
1 files changed, 36 insertions, 88 deletions
diff --git a/kernel/task.c b/kernel/task.c index c9554b5..1780b77 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -21,57 +21,32 @@ static volatile int current_task=-2; static volatile struct task_list_struct { + int parent; bool active; uint32_t esp; // stack pointer of the task; uint32_t vmem; // number of virtual memory table to switch to -}task_list[MAX_TASKS]; +}volatile task_list[MAX_TASKS]; - -void task_create(int pid,void(*thread)()) +int add_task(uint32_t esp, uint32_t vmem) { - task_list[pid].vmem=vmem_new_space_dir(); - if(pid==0)x86_set_pdbr(0x0D08000); - if(pid==1)x86_set_pdbr(0x150E000); - - unsigned int *stack; - - - task_list[pid].esp = 0x8248000-4095; - stack = (unsigned int*)task_list[pid].esp+4095; //This makes a pointer to the stack for us - - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"new task: stack: 0x%08X thread: 0x%08X", stack, thread); - - //First, this stuff is pushed by the processor - *--stack = 0x0202; //This is EFLAGS - *--stack = 0x08; //This is CS, our code segment - *--stack = (uint32_t)thread; //This is EIP - - //Next, the stuff pushed by 'pusha' - *--stack = 0; //EDI - *--stack = 0; //ESI - *--stack = 0; //EBP - *--stack = 0; //Just an offset, no value - *--stack = 0; //EBX - *--stack = 0; //EDX - *--stack = 0; //ECX - *--stack = 0; //EAX - - //Now these are the data segments pushed by the IRQ handler - /* - *--stack = 0x10; //DS - *--stack = 0x10; //ES - *--stack = 0x10; //FS - *--stack = 0x10; //GS - */ - - task_list[pid].esp = (uint32_t)stack; //Update the stack pointer - task_list[pid].active=true; + for(int i=0;i<MAX_TASKS;i++) + { + if(task_list[i].active!=true) + { - x86_set_pdbr(0x0502000); + task_list[i].parent=current_task; + task_list[i].vmem=vmem; + task_list[i].esp=esp; + task_list[i].active=true; -}; + return i; + } + } + + panic(FOOLOS_MODULE_NAME,"out of task slots!"); +} // this gets called by our clock interrupt regularly! uint32_t task_switch_next(uint32_t oldesp) @@ -79,7 +54,8 @@ uint32_t task_switch_next(uint32_t oldesp) timer_tick(); if(current_task==-2)return oldesp; - if(current_task!=-1)task_list[current_task].esp=oldesp; + + task_list[current_task].esp=oldesp; for(int i=0;i<MAX_TASKS;i++) { @@ -87,12 +63,10 @@ uint32_t task_switch_next(uint32_t oldesp) if(task_list[pid].active) { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"switch from %d to pid: %d (0x%08X) vmem: %d ", current_task,pid,task_list[pid].esp,task_list[pid].vmem); + // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"switch from %d to pid: %d (0x%08X) vmem: %d ", current_task,pid,task_list[pid].esp,task_list[pid].vmem); current_task=pid; - if(pid==0)x86_set_pdbr(0x0D08000); - if(pid==1)x86_set_pdbr(0x150E000); - + vmem_set_dir(task_list[pid].vmem); return task_list[pid].esp; } @@ -103,55 +77,29 @@ uint32_t task_switch_next(uint32_t oldesp) } -// task testing // -volatile void test1() +uint32_t task_fork(uint32_t oldesp) +{ + return add_task(oldesp,vmem_new_space_dir()); +} + +// init task (root of all other tasks / processes) // +void task_init() { + // this is our main task on slot 0 + task_list[0].active=true; + task_list[0].vmem=0; + task_list[0].esp = 0; // will be set by next task_switch_next() call. + current_task=0; - - static char *argv[]={"/bin/foolshell",NULL}; static char *env[]={"PATH=/bin","PWD=/home/miguel","PS1=$ ",NULL}; - syscall_execve("/bin/task1",argv,env); - - - while(1) - { - syscall_write(1,">",1); - } + syscall_execve("/bin/init",argv,env); } -volatile void test2() -{ - - static char *argv[]={"/bin/foolshell",NULL}; - static char *env[]={"PATH=/bin","PWD=/home/miguel","PS1=$ ",NULL}; - syscall_execve("/bin/task2",argv,env); - - - while(1) - { - for(int i='a';i<'z';i++) - { - syscall_write(1,&i,1); - } - } - -} -volatile void test3() -{ - while(1) - { - syscall_write(1," ",1); - } - -} -void task_init() +int task_get_current_pid() { - task_create(0,test2); - task_create(1,test1); -// task_create(2,test3); - current_task=-1; + return current_task; } |
