1 #include "u.h" 2 #include "../port/lib.h" 3 #include "mem.h" 4 #include "dat.h" 5 #include "fns.h" 6 #include "io.h" 7 #include "ureg.h" 8 9 static ulong clkreload; 10 11 void delayloopinit(void)12delayloopinit(void) 13 { 14 ulong v; 15 uvlong x; 16 17 m->loopconst = 5000; 18 v = getdec(); 19 delay(1000); 20 v -= getdec(); 21 22 x = m->loopconst; 23 x *= m->dechz; 24 x /= v; 25 m->loopconst = x; 26 } 27 28 void clockinit(void)29clockinit(void) 30 { 31 /* XXX this should not be hard coded! */ 32 m->cpuhz = 300000000; 33 m->bushz = 66666666; 34 35 m->dechz = m->bushz/4; /* true for all 604e */ 36 m->tbhz = m->dechz; /* conjecture; manual doesn't say */ 37 38 delayloopinit(); 39 40 clkreload = m->dechz/HZ-1; 41 putdec(clkreload); 42 } 43 44 void clockintr(Ureg * ureg)45clockintr(Ureg *ureg) 46 { 47 long v; 48 49 v = -getdec(); 50 if(v > clkreload/2){ 51 if(v > clkreload) 52 m->ticks += v/clkreload; 53 v = 0; 54 } 55 putdec(clkreload-v); 56 57 timerintr(ureg, 0); 58 } 59 60 void timerset(Tval)61timerset(Tval) 62 { 63 } 64 65 void delay(int l)66delay(int l) 67 { 68 ulong i, j; 69 70 j = m->loopconst; 71 while(l-- > 0) 72 for(i=0; i < j; i++) 73 ; 74 } 75 76 void microdelay(int l)77microdelay(int l) 78 { 79 ulong i; 80 81 l *= m->loopconst; 82 l += 500; 83 l /= 1000; 84 if(l <= 0) 85 l = 1; 86 for(i = 0; i < l; i++) 87 ; 88 } 89 90 uvlong fastticks(uvlong * hz)91fastticks(uvlong *hz) 92 { 93 if(hz) 94 *hz = HZ; 95 return m->ticks; 96 } 97 98 ulong s(void)99µs(void) 100 { 101 return fastticks2us(m->ticks); 102 } 103 104 /* 105 * performance measurement ticks. must be low overhead. 106 * doesn't have to count over a second. 107 */ 108 ulong perfticks(void)109perfticks(void) 110 { 111 return m->ticks; 112 } 113