From 778301ab212d9bb8ffa527491cbc93955eb0cb92 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Thu, 12 Jul 2018 01:01:10 +1000 Subject: Task state information is no longer manually saved on context switch. Since the kernel now has it's own stack unique to each address space, we can now rely on hardware task switching to *also* save the task states. To accomplish this, most of the code in switch_to() has been elimated. This includes; the clearing of the busy flag in the old TSS on each switch, setting the TR register to null prior to each switch and calling save_state() (which has also been removed entirely), to copy the state information. Modified the for loop in reschedule() to account for the fact that the switch_to() function may now return (which it *always* does when returning to the task). For the same reason, switch_to() must also be careful to preserve registers such as EBX and actually make a return following the far jump. Added basic definitions for task states in sched.h. These are; running, interruptible, uninterruptible, zombie and stopped. These states will (possibly) be used in the future to implement blocking system calls. --- kernel/sched.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'kernel/sched.c') diff --git a/kernel/sched.c b/kernel/sched.c index c9f0da9..675867c 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -208,28 +208,6 @@ void sched_init(void) { switch_to(0, &tasks[0]); } -void save_state(void) { - if(ctask == NULL || cstate == NULL) - return; - - ctask->state.eax = cstate->eax; - ctask->state.ebx = cstate->ebx; - ctask->state.ecx = cstate->ecx; - ctask->state.edx = cstate->edx; - ctask->state.esi = cstate->esi; - ctask->state.edi = cstate->edi; - ctask->state.esp = cstate->esp; - ctask->state.ebp = cstate->ebp; - ctask->state.cs = cstate->cs; - ctask->state.ds = cstate->ds; - ctask->state.es = cstate->ds; - ctask->state.fs = cstate->ds; - ctask->state.gs = cstate->ds; - ctask->state.ss = cstate->ss; - ctask->state.eflags = cstate->eflags; - ctask->state.eip = cstate->eip; -} - void reschedule(void) { int i; uint32_t n; @@ -241,8 +219,9 @@ void reschedule(void) { for(i = 0; i < NRTASKS; i++) { n = (n + 1) % NRTASKS; if(tasks[n].pid) - switch_to(n, &tasks[n]); + break; } + switch_to(n, &tasks[n]); } void sched_tick(void) { -- cgit v1.3