Rev 2212 | Rev 2219 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2212 | Rev 2217 | ||
---|---|---|---|
Line 40... | Line 40... | ||
40 | IOAPIC_ID equ 0x0 |
40 | IOAPIC_ID equ 0x0 |
41 | IOAPIC_VER equ 0x1 |
41 | IOAPIC_VER equ 0x1 |
42 | IOAPIC_ARB equ 0x2 |
42 | IOAPIC_ARB equ 0x2 |
43 | IOAPIC_REDTBL equ 0x10 |
43 | IOAPIC_REDTBL equ 0x10 |
Line -... | Line 44... | ||
- | 44 | ||
44 | 45 | align 4 |
|
45 | APIC_init: |
46 | APIC_init: |
Line 46... | Line 47... | ||
46 | mov dword[APIC], 0 |
47 | mov dword[APIC], 0 |
47 | 48 | ||
Line 60... | Line 61... | ||
60 | shr eax, 16 |
61 | shr eax, 16 |
61 | inc al |
62 | inc al |
62 | movzx eax, al |
63 | movzx eax, al |
63 | cmp al, IRQ_RESERVED |
64 | cmp al, IRQ_RESERVED |
64 | jbe @f |
65 | jbe @f |
- | 66 | ||
65 | mov al, IRQ_RESERVED |
67 | mov al, IRQ_RESERVED |
66 | @@: |
68 | @@: |
67 | mov [IRQ_COUNT], eax |
69 | mov [IRQ_COUNT], eax |
Line 68... | Line 70... | ||
68 | 70 | ||
69 | ; Reroute IOAPIC & mask all interrupts |
71 | ; Reroute IOAPIC & mask all interrupts |
70 | xor ecx, ecx |
72 | xor ecx, ecx |
- | 73 | mov eax, IOAPIC_REDTBL |
|
71 | mov eax, IOAPIC_REDTBL |
74 | @@: |
72 | @@: mov ebx, eax |
75 | mov ebx, eax |
73 | call IOAPIC_read |
76 | call IOAPIC_read |
74 | mov ah, 0x09 ; Delivery Mode: Lowest Priority, Destination Mode: Logical |
77 | mov ah, 0x09 ; Delivery Mode: Lowest Priority, Destination Mode: Logical |
75 | mov al, cl |
78 | mov al, cl |
76 | add al, 0x20 ; vector |
79 | add al, 0x20 ; vector |
77 | or eax, 0x10000 ; Mask Interrupt |
80 | or eax, 0x10000 ; Mask Interrupt |
78 | cmp ecx, 16 |
81 | cmp ecx, 16 |
- | 82 | jb .set |
|
79 | jb .set |
83 | |
80 | or eax, 0xa000 ;<<< level-triggered active-low for IRQ16+ |
84 | or eax, 0xa000 ;<<< level-triggered active-low for IRQ16+ |
81 | .set: |
85 | .set: |
82 | xchg eax, ebx |
86 | xchg eax, ebx |
83 | call IOAPIC_write |
87 | call IOAPIC_write |
Line 101... | Line 105... | ||
101 | mov al, 1 |
105 | mov al, 1 |
102 | out 0x23, al |
106 | out 0x23, al |
Line 103... | Line 107... | ||
103 | 107 | ||
Line -... | Line 108... | ||
- | 108 | ; mov dword[irq_type_to_set], IRQ_TYPE_APIC |
|
- | 109 | ||
104 | ; mov dword[irq_type_to_set], IRQ_TYPE_APIC |
110 | .no_apic: |
Line 105... | Line 111... | ||
105 | 111 | ||
106 | ;init handlers table |
112 | ;init handlers table |
107 | 113 | ||
Line 114... | Line 120... | ||
114 | loop @B |
120 | loop @B |
Line 115... | Line 121... | ||
115 | 121 | ||
116 | mov ecx, 47 |
122 | mov ecx, 47 |
117 | mov eax, irqh_pool+IRQH.sizeof |
123 | mov eax, irqh_pool+IRQH.sizeof |
118 | mov [next_irqh], irqh_pool |
- | |
119 | 124 | mov [next_irqh], irqh_pool |
|
120 | @@: |
125 | @@: |
121 | mov [eax-IRQH.sizeof], eax |
126 | mov [eax-IRQH.sizeof], eax |
122 | add eax, IRQH.sizeof |
127 | add eax, IRQH.sizeof |
Line 123... | Line 128... | ||
123 | loop @B |
128 | loop @B |
Line 124... | Line -... | ||
124 | - | ||
125 | mov [eax-IRQH.sizeof], dword 0 |
129 | |
Line 126... | Line 130... | ||
126 | 130 | mov [eax-IRQH.sizeof], dword 0 |
|
127 | .no_apic: |
131 | |
128 | ret |
132 | ret |
Line 144... | Line 148... | ||
144 | ; Program Destination Format Register for Flat mode. |
148 | ; Program Destination Format Register for Flat mode. |
145 | mov eax, [esi + APIC_DFR] |
149 | mov eax, [esi + APIC_DFR] |
146 | or eax, 0xf0000000 |
150 | or eax, 0xf0000000 |
147 | mov [esi + APIC_DFR], eax |
151 | mov [esi + APIC_DFR], eax |
Line 148... | Line -... | ||
148 | - | ||
149 | 152 | ||
150 | ; Program Logical Destination Register. |
153 | ; Program Logical Destination Register. |
151 | mov eax, [esi + APIC_LDR] |
154 | mov eax, [esi + APIC_LDR] |
152 | ;and eax, 0xff000000 |
155 | ;and eax, 0xff000000 |
153 | and eax, 0x00ffffff |
156 | and eax, 0x00ffffff |
Line 159... | Line 162... | ||
159 | and eax, 0xffffff00 |
162 | and eax, 0xffffff00 |
160 | mov [esi + APIC_TPR], eax |
163 | mov [esi + APIC_TPR], eax |
Line 161... | Line 164... | ||
161 | 164 | ||
162 | ; Flush the queue |
165 | ; Flush the queue |
- | 166 | mov edx, 0 |
|
163 | mov edx, 0 |
167 | .nxt2: |
164 | .nxt2: mov ecx, 32 |
168 | mov ecx, 32 |
- | 169 | mov eax, [esi + APIC_ISR + edx] |
|
165 | mov eax, [esi + APIC_ISR + edx] |
170 | .nxt: |
166 | .nxt: shr eax, 1 |
171 | shr eax, 1 |
167 | jnc @f |
172 | jnc @f |
- | 173 | mov dword [esi + APIC_EOI], 0 ; EOI |
|
168 | mov dword [esi + APIC_EOI], 0 ; EOI |
174 | @@: |
- | 175 | loop .nxt |
|
169 | @@: loop .nxt |
176 | |
170 | add edx, 0x10 |
177 | add edx, 0x10 |
171 | cmp edx, 0x170 |
178 | cmp edx, 0x170 |
Line 172... | Line 179... | ||
172 | jbe .nxt2 |
179 | jbe .nxt2 |
Line 204... | Line 211... | ||
204 | shr eax, 6 ; eax /= 64; APIC ticks per 0.01 sec |
211 | shr eax, 6 ; eax /= 64; APIC ticks per 0.01 sec |
Line 205... | Line 212... | ||
205 | 212 | ||
206 | ; Start (every 0.01 sec) |
213 | ; Start (every 0.01 sec) |
207 | mov dword[esi + APIC_LVT_timer], 0x30020 ; periodic int 0x20 |
214 | mov dword[esi + APIC_LVT_timer], 0x30020 ; periodic int 0x20 |
208 | mov dword[esi + APIC_timer_init], eax |
- | |
209 | 215 | mov dword[esi + APIC_timer_init], eax |
|
- | 216 | ret |
|
210 | ret |
217 | |
211 | ;=========================================================== |
218 | ;=========================================================== |
212 | ; IOAPIC implementation |
219 | ; IOAPIC implementation |
213 | align 4 |
220 | align 4 |
214 | IOAPIC_read: |
221 | IOAPIC_read: |
Line 218... | Line 225... | ||
218 | mov esi, [IOAPIC_base] |
225 | mov esi, [IOAPIC_base] |
219 | mov [esi], eax |
226 | mov [esi], eax |
220 | mov eax, [esi + 0x10] |
227 | mov eax, [esi + 0x10] |
221 | pop esi |
228 | pop esi |
222 | ret |
229 | ret |
- | 230 | ||
223 | align 4 |
231 | align 4 |
224 | IOAPIC_write: |
232 | IOAPIC_write: |
225 | ; in : EAX - IOAPIC register |
233 | ; in : EAX - IOAPIC register |
226 | ; EBX - value |
234 | ; EBX - value |
227 | ; out: none |
235 | ; out: none |
Line 236... | Line 244... | ||
236 | ; IRQ0 to vector 0x20, IRQ1 to vector 0x21.... |
244 | ; IRQ0 to vector 0x20, IRQ1 to vector 0x21.... |
237 | PIC_init: |
245 | PIC_init: |
238 | cli |
246 | cli |
239 | mov al,0x11 ; icw4, edge triggered |
247 | mov al,0x11 ; icw4, edge triggered |
240 | out 0x20,al |
248 | out 0x20,al |
241 | call pic_delay |
- | |
242 | out 0xA0,al |
249 | out 0xA0,al |
243 | call pic_delay |
- | |
Line 244... | Line 250... | ||
244 | 250 | ||
245 | mov al,0x20 ; generate 0x20 + |
251 | mov al,0x20 ; generate 0x20 + |
246 | out 0x21,al |
- | |
247 | call pic_delay |
252 | out 0x21,al |
248 | mov al,0x28 ; generate 0x28 + |
253 | mov al,0x28 ; generate 0x28 + |
249 | out 0xA1,al |
- | |
Line 250... | Line 254... | ||
250 | call pic_delay |
254 | out 0xA1,al |
251 | 255 | ||
252 | mov al,0x04 ; slave at irq2 |
- | |
253 | out 0x21,al |
256 | mov al,0x04 ; slave at irq2 |
254 | call pic_delay |
257 | out 0x21,al |
255 | mov al,0x02 ; at irq9 |
- | |
Line 256... | Line 258... | ||
256 | out 0xA1,al |
258 | mov al,0x02 ; at irq9 |
257 | call pic_delay |
259 | out 0xA1,al |
258 | - | ||
259 | mov al,0x01 ; 8086 mode |
260 | |
260 | out 0x21,al |
- | |
Line 261... | Line 261... | ||
261 | call pic_delay |
261 | mov al,0x01 ; 8086 mode |
262 | out 0xA1,al |
- | |
263 | call pic_delay |
262 | out 0x21,al |
264 | 263 | out 0xA1,al |
|
Line 265... | Line 264... | ||
265 | call IRQ_mask_all |
264 | |
266 | cli |
- | |
267 | ; mov dword[irq_type_to_set], IRQ_TYPE_PIC |
- | |
268 | ret |
- | |
269 | - | ||
270 | ; ----------------------------------------- |
- | |
271 | pic_delay: |
265 | call IRQ_mask_all |
272 | jmp pdl1 |
266 | ; mov dword[irq_type_to_set], IRQ_TYPE_PIC |
273 | pdl1: ret |
267 | ret |
274 | 268 | ||
275 | ; ----------------------------------------- |
269 | ; ----------------------------------------- |
Line 317... | Line 311... | ||
317 | jnz .APIC |
311 | jnz .APIC |
318 | mov al, 0xFF |
312 | mov al, 0xFF |
319 | out 0x21, al |
313 | out 0x21, al |
320 | out 0xA1, al |
314 | out 0xA1, al |
321 | mov ecx,0x1000 |
315 | mov ecx,0x1000 |
322 | cld |
- | |
323 | @@: call pic_delay |
- | |
324 | loop @b |
- | |
325 | ret |
316 | ret |
326 | .APIC: |
317 | .APIC: |
327 | mov ecx, [IRQ_COUNT] |
318 | mov ecx, [IRQ_COUNT] |
328 | mov eax, 0x10 |
319 | mov eax, 0x10 |
- | 320 | @@: |
|
329 | @@: mov ebx, eax |
321 | mov ebx, eax |
330 | call IOAPIC_read |
322 | call IOAPIC_read |
331 | or eax, 0x10000 ; bit 16 |
323 | or eax, 0x10000 ; bit 16 |
332 | xchg eax, ebx |
324 | xchg eax, ebx |
333 | call IOAPIC_write |
325 | call IOAPIC_write |
334 | inc eax |
326 | inc eax |
335 | inc eax |
327 | inc eax |
336 | loop @b |
328 | loop @b |
337 | ret |
329 | ret |
- | 330 | ||
338 | ; ----------------------------------------- |
331 | ; ----------------------------------------- |
339 | ; End Of Interrupt |
332 | ; End Of Interrupt |
340 | ; cl - IRQ number |
333 | ; cl - IRQ number |
341 | align 16 |
334 | align 16 |
342 | irq_eoi: ; __fastcall |
335 | irq_eoi: ; __fastcall |
343 | test dword[APIC], 0xffffffff |
336 | test dword[APIC], 0xffffffff |
344 | jnz .APIC |
337 | jnz .APIC |
- | 338 | ||
345 | cmp cl, 8 |
339 | cmp cl, 8 |
346 | mov al, 0x20 |
340 | mov al, 0x20 |
347 | jb @f |
341 | jb @f |
348 | out 0xa0, al |
342 | out 0xa0, al |
349 | @@: |
343 | @@: |
Line 360... | Line 354... | ||
360 | align 4 |
354 | align 4 |
361 | proc enable_irq stdcall, irq_line:dword |
355 | proc enable_irq stdcall, irq_line:dword |
362 | mov ebx, [irq_line] |
356 | mov ebx, [irq_line] |
363 | test dword[APIC], 0xffffffff |
357 | test dword[APIC], 0xffffffff |
364 | jnz .APIC |
358 | jnz .APIC |
- | 359 | ||
365 | mov edx, 0x21 |
360 | mov edx, 0x21 |
366 | cmp ebx, 8 |
361 | cmp ebx, 8 |
367 | jb @F |
362 | jb @F |
- | 363 | ||
368 | mov edx, 0xA1 |
364 | mov edx, 0xA1 |
369 | sub ebx,8 |
365 | sub ebx,8 |
370 | @@: |
366 | @@: |
371 | in al,dx |
367 | in al,dx |
372 | btr eax, ebx |
368 | btr eax, ebx |