]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/ppc/clock.c
devmnt: make sure auth chan is on said conection in mntattach()
[plan9front.git] / sys / src / 9 / ppc / clock.c
1 #include        "u.h"
2 #include        "../port/lib.h"
3 #include        "mem.h"
4 #include        "dat.h"
5 #include        "io.h"
6 #include        "fns.h"
7 #include        "ureg.h"
8
9 static  ulong   clkreload;
10
11 void
12 delayloopinit(void)
13 {
14         ulong v;
15         uvlong x;
16
17         /* initial value for loopconst set in machinit */
18         m->loopconst = 1000;
19         v = getdec();
20         delay(1000);
21         v -= getdec();
22
23         x = m->loopconst;
24         x *= m->dechz;
25         x /= v;
26         m->loopconst = x;
27 }
28
29 void
30 clockinit(void)
31 {
32         m->dechz = m->bushz/4;  /* true for all 604e */
33         m->tbhz = m->dechz;     /* conjecture; manual doesn't say */
34
35         delayloopinit();
36
37         clkreload = m->dechz/HZ-1;
38         putdec(clkreload);
39 }
40
41 void
42 clockintr(Ureg *)
43 {
44         long v;
45
46         v = -getdec();
47         if(v > (clkreload >> 1)){
48                 if(v > clkreload)
49                         m->ticks += v/clkreload;
50                 v = 0;
51         }
52         putdec(clkreload-v);
53 }
54
55 void
56 delay(int l)
57 {
58         ulong i, j;
59
60         j = 0;
61         if(m)
62                 j = m->loopconst;
63         if(j == 0)
64                 j = 1096;
65         while(l-- > 0)
66                 for(i=0; i < j; i++)
67                         ;
68 }
69
70 void
71 microdelay(int l)
72 {
73         ulong i;
74
75         l *= m->loopconst;
76         l += 500;
77         l /= 1000;
78         if(l <= 0)
79                 l = 1;
80         for(i = 0; i < l; i++)
81                 ;
82 }
83
84 ulong
85 perfticks(void)
86 {
87         return (ulong)fastticks(nil);
88 }