]> wirehaze git hosting - BOS.git/blob - kernel/krl_incs/timer.inc

wirehaze git hosting

initial commit
[BOS.git] / kernel / krl_incs / timer.inc
1 ;----------------------------------------------------------;
2 ; BOS kernel Christoffer Bubach, 2005. ;
3 ;----------------------------------------------------------;
4 ; ;
5 ; Function to set up the timer IRQ. ;
6 ; ;
7 ;----------------------------------------------------------;
8
9 ;-----------------;
10 ; variables ;
11 ;-----------------;
12 timer_wait dd 0 ; time to wait
13 timer_counter dd 0, 0 ; time since BOS started
14 call_list dd 0, 0, 0, 0, 0 ; functions to call
15
16
17 ;---------------------------;
18 ; Timer IRQ(0) ;
19 ;---------------------------;
20 timer:
21 add dword [timer_counter], 1 ; it's just a 64-bit
22 adc dword [timer_counter+4], 0 ; counter since boot.
23
24 cmp [timer_wait], 0 ; "delay" countdown.
25 je .test1
26 dec [timer_wait]
27
28 .test1: ; checks for calls to
29 cmp [call_list], dword 0 ; do before we quit.
30 je .test2
31 call dword [call_list]
32 .test2:
33 cmp [call_list+4], dword 0
34 je .test3
35 call dword [call_list+4]
36 .test3:
37 cmp [call_list+8], dword 0
38 je .test4
39 call dword [call_list+8]
40 .test4:
41 cmp [call_list+12], dword 0
42 je .test5
43 call dword [call_list+12]
44 .test5:
45 cmp [call_list+16], dword 0
46 je .end
47 call dword [call_list+16]
48
49 .end:
50 mov al, 0x20
51 out 0x20, al
52 ret
53
54
55
56 ;------------------------------------------------;
57 ; add function for the timer to call ;
58 ; in: ebx = function address ;
59 ; out: eax = 0 if OK ;
60 ;------------------------------------------------;
61 add_timercall:
62 cmp [call_list], 0
63 jne .test2
64 mov [call_list], ebx
65 jmp .end
66 .error:
67 mov eax, 1
68 ret
69 .test2:
70 cmp [call_list+4], 0 ; since i am so lazy
71 jne .test3 ; and a loop can be
72 mov [call_list+4], ebx ; rather complicated
73 jmp .end ; for this stuff, i
74 .test3: ; check for each one..
75 cmp [call_list+8], 0 ; after all, it's only 5.
76 jne .test4
77 mov [call_list+8], ebx
78 jmp .end
79 .test4:
80 cmp [call_list+12], 0
81 jne .test5
82 mov [call_list+12], ebx
83 jmp .end
84 .test5:
85 cmp [call_list+16], 0
86 jne .error
87 mov [call_list+16], ebx
88 .end:
89 xor eax, eax
90 ret
91
92
93
94 ;-------------------------------------------------;
95 ; remove function from the call list ;
96 ; in: ebx = function address ;
97 ; out: eax = 0 if OK ;
98 ;-------------------------------------------------;
99 remove_timercall:
100 cmp [call_list], ebx
101 jne .test2
102 mov [call_list], dword 0
103 jmp .end
104 .error:
105 mov eax, 1
106 ret
107 .test2:
108 cmp [call_list+4], ebx
109 jne .test3
110 mov [call_list+4], dword 0
111 jmp .end
112 .test3:
113 cmp [call_list+8], ebx
114 jne .test4
115 mov [call_list+8], dword 0
116 jmp .end
117 .test4:
118 cmp [call_list+12], ebx
119 jne .test5
120 mov [call_list+12], dword 0
121 jmp .end
122 .test5:
123 cmp [call_list+16], ebx
124 jne .error
125 mov [call_list+16], dword 0
126 .end:
127 xor eax, eax
128 ret
129
130
131
132 ;--------------------------------------------;
133 ; delay function ;
134 ; in: ecx = 100/second to wait ;
135 ; out: nothing ;
136 ;--------------------------------------------;
137 delay:
138 mov [timer_wait], ecx ; mov value to "timer"
139 .loop:
140 cmp [timer_wait], 0
141 jne .loop
142 ret
143
144
145
146 ;--------------------------------------------;
147 ; "active" delay ;
148 ; ;
149 ; gives the caller a pointer to the counter ;
150 ; so that it can check for timeouts etc, ;
151 ; itself. ;
152 ; in: ecx = 100/second to wait ;
153 ; out: ecx = pointer to counter ;
154 ;--------------------------------------------;
155 active_delay:
156 mov [timer_wait], ecx ; mov value to "timer"
157 mov ecx, timer_wait ; let caller check value
158 ret
159
160
161
162 ;------------------------------;
163 ; set PIT to 100Hz ;
164 ;------------------------------;
165 set_pit_freq:
166 push eax
167 mov al, 0x34 ; set to 100Hz, 0x34 = 00110100b
168 out 0x43, al
169 mov al, 0x9B ; lsb 1193180 / 1193
170 out 0x40, al
171 mov al, 0x2E ; msb
172 out 0x40, al
173 pop eax
174 ret