#include "u.h" #include "../port/lib.h" #include "mem.h" #include "dat.h" #include "fns.h" #include "io.h" #include "ureg.h" void delay(int ms) { int i; ms *= 7000; /* experimentally determined */ for(i=0; ictl = CTR(2)|SET16|MODE2; t->cnt2 = TIME2&0xFF; t->cnt2 = (TIME2>>8)&0xFF; t->ctl = CTR(1)|SET16|MODE2; t->cnt1 = TIME1&0xFF; t->cnt1 = (TIME1>>8)&0xFF; t->ctl = CTR(0)|SET16|MODE2; t->cnt0 = TIME0; t->cnt0 = (TIME0>>8)&0xFF; i = *CLRTIM0; USED(i); i = *CLRTIM1; USED(i); m->ticks = 0; } void clock(Ureg *ur) { int i, nrun = 0; Proc *p; if(ur->cause & INTR2){ i = *CLRTIM0; USED(i); m->ticks++; if(m->ticks&(1<<4)) LEDON(LEDpulse); else LEDOFF(LEDpulse); if(m->proc) m->proc->pc = ur->pc; if(m->machno == 0){ p = m->proc; if(p) { nrun++; p->time[p->insyscall]++; } for(i=1; iproc; if(p) { p->time[p->insyscall]++; nrun++; } } } nrun = (nrdy+nrun)*1000; m->load = (m->load*19+nrun)/20; } duartslave(); if((active.machs&(1<machno)) == 0) return; if(active.exiting && active.machs&(1<machno)){ print("someone's exiting\n"); exit(0); } checkalarms(); kproftimer(ur->pc); if(u && (ur->status&IEP) && u->p->state==Running){ if(anyready()) { if(u->p->hasspin) u->p->hasspin = 0; /* just in case */ else sched(); } /* user profiling clock */ if(ur->status & KUP) (*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1); } return; } if(ur->cause & INTR4){ extern ulong start; i = *CLRTIM1; USED(i); return; } }