From 5663c3daac784a3078be168b6ce0dedb254a6e26 Mon Sep 17 00:00:00 2001 From: tone121 Date: Mon, 19 Feb 2018 20:17:49 -0700 Subject: [PATCH] more scheduler crap preemptive scheduling is hard, so i went back to cooperative scheduling. --- include/sched/sched.h | 5 +--- src/boot/init.c | 8 +++--- src/sched/sched.c | 57 ++++++------------------------------------- src/sched/switch.asm | 10 ++------ 4 files changed, 14 insertions(+), 66 deletions(-) diff --git a/include/sched/sched.h b/include/sched/sched.h index 469f7b9..d53060d 100644 --- a/include/sched/sched.h +++ b/include/sched/sched.h @@ -1,9 +1,6 @@ #ifndef SCHED_H #define SCHED_H -#include -#include -#include #include #include @@ -11,6 +8,6 @@ void sched_init(process_t *proc); void sched_add(process_t *proc); void sched_remove(process_t *proc); unsigned long sched_pid_alloc(void); -unsigned long sched_step(void); +void sched_step(void); #endif diff --git a/src/boot/init.c b/src/boot/init.c index f49133f..31c5449 100644 --- a/src/boot/init.c +++ b/src/boot/init.c @@ -35,9 +35,8 @@ void init_arch(struct multiboot_info *mb) void idle(void) { - for (;;) { - asm ("nop"); - } + tty_printf("a"); + asm ("nop"); } void init(struct multiboot_info *mb) @@ -48,7 +47,8 @@ void init(struct multiboot_info *mb) sched_init(process_init(idle, "idle")); - idle(); + for (;;) + sched_step(); return; } diff --git a/src/sched/sched.c b/src/sched/sched.c index 88277d7..38d0744 100644 --- a/src/sched/sched.c +++ b/src/sched/sched.c @@ -5,45 +5,6 @@ extern void sched_jump(unsigned long eip); static process_t *curr = NULL; static unsigned long pid = 0; -void sched_int(void) -{ - asm ("cli"); - - asm ("out %%al, %%dx" : : "d"(0x20), "a"(0x20)); - - // save registers - asm ("mov %%ebx, %0" : "=r"(curr->regs.ebx)); - asm ("mov %%ecx, %0" : "=r"(curr->regs.ecx)); - asm ("mov %%edx, %0" : "=r"(curr->regs.edx)); - - asm ("mov %%esi, %0" : "=r"(curr->regs.esi)); - asm ("mov %%edi, %0" : "=r"(curr->regs.edi)); - - asm ("mov %%esp, %0" : "=r"(curr->regs.esp)); - asm ("mov %%ebp, %0" : "=r"(curr->regs.ebp)); - - asm ("mov 12(%%esp), %0" : "=r"(curr->regs.eip)); - - if (sched_step() == 1) { - - // restore registers - - asm ("mov %0, %%ebx" : "=r"(curr->regs.ebx)); - asm ("mov %0, %%ecx" : "=r"(curr->regs.ecx)); - asm ("mov %0, %%edx" : "=r"(curr->regs.edx)); - - asm ("mov %0, %%esi" : "=r"(curr->regs.esi)); - asm ("mov %0, %%edi" : "=r"(curr->regs.edi)); - - // asm ("mov %0, %%esp" : "=r"(curr->regs.esp)); - // asm ("mov %0, %%ebp" : "=r"(curr->regs.ebp)); - - sched_jump(curr->regs.eip); - } - - asm ("sti; leave; iret"); -} - void sched_init(process_t *proc) { if (proc) { @@ -51,10 +12,6 @@ void sched_init(process_t *proc) curr->prev = curr; curr->next = curr; - - idt_set_entry(32, (unsigned long)sched_int); - pit_set_phase(PIT_HZ / 1000); - pic_enable_irq(0); } } @@ -81,14 +38,16 @@ unsigned long sched_pid_alloc(void) return pid++; } -unsigned long sched_step(void) +void sched_step(void) { - unsigned long schedule = 0; - if (curr && curr->next) { switch (curr->state) { + case PROCESS_RUNNING: + PANIC("trying to schedule a running process!"); case PROCESS_RUNABLE: - schedule = 1; + curr->state = PROCESS_RUNNING; + sched_jump(curr->regs.eip); + curr->state = PROCESS_RUNABLE; break; case PROCESS_SLEEPING: // do nothing and let it sleep @@ -96,7 +55,7 @@ unsigned long sched_step(void) case PROCESS_ZOMBIE: curr = curr->next; sched_remove(curr->prev); - return 0; + return; default: PANIC("cannot handle unknown process state!"); } @@ -104,6 +63,4 @@ unsigned long sched_step(void) } else { PANIC("no more processes to schedule!"); } - - return schedule; } diff --git a/src/sched/switch.asm b/src/sched/switch.asm index 9c0ce99..08f8be1 100644 --- a/src/sched/switch.asm +++ b/src/sched/switch.asm @@ -2,12 +2,6 @@ ; void sched_jump(unsigned long eip); global sched_jump sched_jump: - pop eax - - pushfd - or dword [esp], 0x200 - push 0x8 - push eax - - iret + mov eax, [esp + 4] + jmp eax \ No newline at end of file