diff options
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/interrupts.c | 1 | ||||
| -rw-r--r-- | kernel/kernel.c | 8 | ||||
| -rw-r--r-- | kernel/task.c | 67 | ||||
| -rw-r--r-- | kernel/usermode.c | 15 |
4 files changed, 76 insertions, 15 deletions
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<MAX_TASKS;i++) { @@ -89,6 +108,7 @@ volatile uint32_t task_switch_next(uint32_t oldesp) //TODO: notify waiting parent when child finished; volatile uint32_t task_exit(uint32_t oldesp) { + task_list[current_task].active=false; int parent_pid=task_list[current_task].parent; @@ -140,16 +160,51 @@ volatile uint32_t task_fork(uint32_t oldesp) // 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 = 0; // will be set by next task_switch_next() call. + 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; - - switch_to_user_mode(); + 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() diff --git a/kernel/usermode.c b/kernel/usermode.c index 76558d8..81dc5c1 100644 --- a/kernel/usermode.c +++ b/kernel/usermode.c @@ -26,11 +26,18 @@ void install_tss(int cpu_no){ // sys_tss.iomap = ( unsigned short ) sizeof( tss_struct ); } -// THIS IS THE FUNCTION TO BE RUN IN RING 3 // USER MODE -static void userfunc() +void userfunc() { - syscall(SYSCALL_EXECVE,BIN_INIT,NULL,NULL); - while(1); // we should never get here. + // we need enable here again (since the pushed eflags have it disabled)! + x86_sti(); + + // if we are pid 0, replace ourselves with /bin/init TODO: switch to usermode before! + if(task_get_current_pid()==0)syscall(SYSCALL_EXECVE,BIN_INIT,NULL,NULL); + + // kernel worker thread + if(task_get_current_pid()==1) + { + } } void switch_to_user_mode() |
