summaryrefslogtreecommitdiff
path: root/kernel/scheduler.c
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-02 01:44:40 +0200
committerMiguel <m.i@gmx.at>2018-09-02 01:44:40 +0200
commitc459fab7662eaf45df9994c828065b9fc8d4a8ac (patch)
treedf1504de1c254a18b44bad24d530531790ad8aef /kernel/scheduler.c
parent8e3411139b27a3421e9ac75c13f14f99f6dd3137 (diff)
syscalls fine
Diffstat (limited to 'kernel/scheduler.c')
-rw-r--r--kernel/scheduler.c89
1 files changed, 44 insertions, 45 deletions
diff --git a/kernel/scheduler.c b/kernel/scheduler.c
index ee1cea2..a16dd02 100644
--- a/kernel/scheduler.c
+++ b/kernel/scheduler.c
@@ -92,6 +92,7 @@ void task_syscall_worker()
{
//klog("checking if any pending syscalls.");
+ bool nowork=true;
for(int i=0;i<MAX_TASKS;i++)
{
if(task_list[i].wait)
@@ -99,6 +100,24 @@ void task_syscall_worker()
// klog("task %d waiting on syscall %d. processing...",i,task_list[i].eax);
task_list[2].vmem=task_list[i].vmem; // switch syscall worker to pagedir of calling userprog
x86_set_page_directory(task_list[2].vmem);
+
+ if(task_list[i].eax==SYSCALL_WAIT)
+ {
+ continue;
+ }
+
+ if(task_list[i].eax==SYSCALL_READ)
+ {
+ uint32_t ok= chk_syscall_read(
+ task_list[i].edx,
+ task_list[i].ecx,
+ task_list[i].ebx
+ );
+ if(!ok)continue;
+ }
+
+ nowork=false;
+
uint32_t ret= syscall_generic(task_list[i].eax,
task_list[i].edx,
task_list[i].ecx,
@@ -113,8 +132,9 @@ void task_syscall_worker()
}
}
- task_list[2].wait=true;
- __asm__("int $0x81"); // wake scheduler!
+ //task_list[2].wait=true;
+ if (nowork)__asm__("hlt");
+ else __asm__("int $0x81"); // wake scheduler!
}
}
@@ -128,7 +148,7 @@ void task_syscall_worker()
//
// we need to return a NEW stack pointer where popa will get the registers the new task requires
//
-volatile uint32_t my_scheduler(uint32_t oldesp)
+volatile uint32_t my_scheduler(uint32_t oldesp,uint32_t force_pid)
{
//
static bool first=true;
@@ -136,6 +156,15 @@ volatile uint32_t my_scheduler(uint32_t oldesp)
if(!first) task_list[current_task].esp=oldesp;
first=false;
//
+ if(force_pid>-1)
+ {
+ int pid=force_pid;
+ current_task=pid;
+ install_tss(task_list[pid].esp0);
+
+ x86_set_page_directory(task_list[pid].vmem);
+ return task_list[pid].esp;
+ }
for(int i=0;i<MAX_TASKS;i++)
{
@@ -170,51 +199,21 @@ volatile uint32_t task_syscall(uint32_t eax,uint32_t ebx, uint32_t ecx, uint32_t
//TODO: free vmem too!
//TODO: notify waiting parent when child finished;
-volatile uint32_t task_exit(uint32_t oldesp)
+volatile uint32_t task_exit(uint32_t pid)
{
- /*
-
- task_list[current_task].active=false;
- int parent_pid=task_list[current_task].parent;
-
- klog("[%d] exit ", current_task);
-
- if(task_list[parent_pid].active)
- {
- if(task_list[parent_pid].waiting)
- {
-
- klog("[%d] wake up", parent_pid);
- task_list[parent_pid].waiting=false;
- }
- else
- {
-// klog("[%d] skipwait", parent_pid);
-// task_list[parent_pid].skipwait=true;
- }
-
- }
-
- vmem_free_dir(task_list[current_task].vmem);
-
- return my_scheduler(oldesp);
- */
-
+ task_list[pid].active=false;
+ int parent_pid=task_list[pid].parent;
+ if(task_list[parent_pid].wait&&task_list[parent_pid].eax==SYSCALL_WAIT)
+ task_list[parent_pid].wait=false;
+ klog("[%d] exit", pid);
+ vmem_free_dir(task_list[pid].vmem);
}
-volatile uint32_t task_wait(uint32_t oldesp)
-{ /*
- klog("[%d] wait", current_task);
- if(task_list[current_task].skipwait)
- {
- task_list[current_task].skipwait=false;
- }
- else
- {
- task_list[current_task].waiting=true;
- }
- return my_scheduler(oldesp);
- */
+volatile uint32_t task_wait(uint32_t pid)
+{
+ klog("[%d] wait", pid);
+ task_list[pid].wait=true;
+ task_list[pid].eax=SYSCALL_WAIT;
}
volatile uint32_t task_fork(uint32_t pid)