summaryrefslogtreecommitdiff
path: root/kernel/task.c
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-08-21 17:54:28 +0200
committerMiguel <m.i@gmx.at>2018-08-21 17:54:28 +0200
commit6c926175afbf1f9ec2715fb007acc28588b36c4a (patch)
treee35451d0c8e5c3f3b6033b919f405a40fd6128fc /kernel/task.c
parent8a5fbdabb24250a76feed770bce64d7e3e4f61de (diff)
cleaning up multitasking
Diffstat (limited to 'kernel/task.c')
-rw-r--r--kernel/task.c67
1 files changed, 61 insertions, 6 deletions
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()