-
Notifications
You must be signed in to change notification settings - Fork 0
/
lapic.c
63 lines (55 loc) · 798 Bytes
/
lapic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <lapic.h>
#include <tick.h>
#define BASE 0xfee00000
#define R(o) (*(volatile u32 *)(BASE + (o)))
enum {
Siv = 0x00f0,
Timer = 0x0320,
TIC = 0x0380,
TCC = 0x0390,
TDC = 0x03e0
};
enum {
Otimermode = 0x11,
Periodic = 1,
Omask = 0x10,
Masked = 1,
NotMasked = 0,
Ovector = 0x00,
DivX1 = 0xB
};
enum {
Msv = 0x000000ff,
Oenable = 0x08
};
void
lapicinit(u8 spurvec)
{
R(Siv) = (R(Siv) & ~Msv) | spurvec;
}
void
timerinit(u8 vec)
{
u32 t;
t = 0;
t |= Periodic << Otimermode;
t |= Masked << Omask;
t |= vec << Ovector;
R(TDC) = DivX1;
R(Timer) = t;
}
void
timerstart(int hz, int rhz)
{
u32 x, t;
u32 p, d;
R(TIC) = 0xffffffff;
t = ticks + rhz;
do {
x = ticks;
} while (x < t);
p = R(TCC);
d = 0xffffffff - p;
R(TIC) = d / hz;
R(Timer) &= ~(1 << Omask);
}