aboutsummaryrefslogtreecommitdiff
path: root/src/core/scheduler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/scheduler.c')
-rw-r--r--src/core/scheduler.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/core/scheduler.c b/src/core/scheduler.c
index d046298..224c20d 100644
--- a/src/core/scheduler.c
+++ b/src/core/scheduler.c
@@ -123,19 +123,25 @@ void task_create(int *page_dir, void *task, int task_size, int stack_offset){
void scheduler_start(){
if(nproc>0){
+ // Disable interrupt to not be interrupted
asm("cli");
- scheduler_on=1; // Enable scheduling
+ // Enable scheduling
+ scheduler_on=1;
+
+ // Save kernel stack state
u32 *stack;
asm("mov %%ebp, %0":"=r" (stack));
- TSS.esp0=(u32)stack+1; // Remove ebp (c call convention)
+ // Remove ebp from the (c call convention) and return address (call)
+ TSS.esp0=(u32)stack+2;
asm("mov %%ss, %0": "=m" (TSS.ss0));
- current_id=1;
+ // Get first stack
+ current_id=0;
PROC *p=&procs[current_id];
-
// Ensure interrupts are activated and NT flag is clear
p->regs.eflags|=0x200;
p->regs.eflags&=0xffffbfff;
+ // Switch to user task
asm(
"push %0 \n\t"
"jmp task_switch"