--- xinu/sys/resched.c 2018/04/24 17:39:03 1.1.1.1 +++ xinu/sys/resched.c 2018/04/24 17:39:31 1.1.1.2 @@ -10,7 +10,7 @@ * * Notes: Upon entry, currpid gives current process id. * Proctab[currpid].pstate gives correct NEXT state for - * current process if other than PRCURR. + * current process if other than PRREADY. *------------------------------------------------------------------------ */ int resched() @@ -21,8 +21,9 @@ int resched() /* no switch needed if current process priority higher than next*/ if ( ( (optr= &proctab[currpid])->pstate == PRCURR) && - (lastkey(rdytail)pprio)) + (lastkey(rdytail)pprio)) { return(OK); + } /* force context switch */ @@ -35,22 +36,12 @@ int resched() nptr = &proctab[ (currpid = getlast(rdytail)) ]; nptr->pstate = PRCURR; /* mark it currently running */ -#ifdef STKCHK - if ( *( (int *)nptr->pbase ) != MAGIC ) { - kprintf("Bad magic pid=%d, value=%x, at %x\n", - currpid, *( (int *)nptr->pbase ), nptr->pbase); - panic("stack corrupted"); - } - if ( ((unsigned)nptr->pregs[SPINDX]) < ((unsigned)nptr->plimit) ) { - kprintf("Bad SP pid=%d (%s), lim=%x will be %x\n", - currpid, nptr->pname, nptr->plimit, - nptr->pregs[SPINDX]); - panic("stack overflow"); - } -#endif #ifdef RTCLOCK preempt = QUANTUM; /* reset preemption counter */ #endif - ctxsw(nptr->pregs); + ctxsw(optr->pregs,nptr->pregs); + + /* The OLD process returns here when resumed. */ + return(OK); }