// http://hosted.cjmovie.net/TutMultitask.htm // // #define FOOLOS_MODULE_NAME "task" #include "kernel.h" #include "lib/logger/log.h" // logger facilities #include "mem.h" #include "timer.h" #include "asm/x86.h" #include "vmem.h" #include "syscalls.h" #include "fs/fs.h" #include "fs/ext2.h" #define MAX_TASKS 10 static volatile int volatile current_task=-1; 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 task_list[MAX_TASKS]; volatile int add_task(uint32_t esp, uint32_t vmem) { for(int i=0;i [%d] (free blocks remaining: %d )", current_task, pid,mem_get_free_blocks_count()); return pid; } // init task (root of all other tasks / processes) // volatile void task_init(pdirectory *dir) { current_task=0; // this is our main task on slot 0 task_list[0].parent=0; task_list[0].active=true; task_list[0].waiting=false; task_list[0].vmem=dir; task_list[0].esp = kballoc(4); // 0; // will be set by next task_switch_next() call. 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); // fresh 16kb stack from here. log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"fresh esp on: 0x%08X",1,task_list[1].esp); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"fresh esp on: 0x%08X",0,task_list[0].esp); task_pusha(task_list[1].esp); // pusha but to alternative location task_pusha(task_list[0].esp); // pusha but to alternative location /* current_task=0; unsigned esp, ebp, eax, ebx, ecx, edx; asm( "movl %%esp, %0;" "movl %%ebp, %1;" "movl %%eax, %2;" "movl %%ebx, %3;" "movl %%ecx, %4;" "movl %%edx, %5;" :"=r"(esp), "=r"(ebp), "=r"(eax), "=r"(ebx), "=r"(ecx), "=r"(edx) ); // TODO: prepare stack so popa get's what it wants! int i=task_fork(esp); */ // finally enable interrrupts so the scheduler is called (by timer) x86_sti(); // loop until scheduler kicks in and reschedules us... while(1); } volatile int task_get_current_pid() { return current_task; } volatile uint32_t task_get_brk() { return task_list[current_task].brk; } volatile void task_set_brk(uint32_t brk) { task_list[current_task].brk=brk; }