]>
Commit | Line | Data |
---|---|---|
80cabfad FB |
1 | /* |
2 | * QEMU 8259 interrupt controller emulation | |
3 | * | |
4 | * Copyright (c) 2003-2004 Fabrice Bellard | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
80cabfad FB |
24 | #include "vl.h" |
25 | ||
26 | /* debug PIC */ | |
27 | //#define DEBUG_PIC | |
28 | ||
b41a2cd1 | 29 | //#define DEBUG_IRQ_LATENCY |
4a0fb71e | 30 | //#define DEBUG_IRQ_COUNT |
b41a2cd1 | 31 | |
80cabfad FB |
32 | typedef struct PicState { |
33 | uint8_t last_irr; /* edge detection */ | |
34 | uint8_t irr; /* interrupt request register */ | |
35 | uint8_t imr; /* interrupt mask register */ | |
36 | uint8_t isr; /* interrupt service register */ | |
37 | uint8_t priority_add; /* highest irq priority */ | |
38 | uint8_t irq_base; | |
39 | uint8_t read_reg_select; | |
40 | uint8_t poll; | |
41 | uint8_t special_mask; | |
42 | uint8_t init_state; | |
43 | uint8_t auto_eoi; | |
44 | uint8_t rotate_on_auto_eoi; | |
45 | uint8_t special_fully_nested_mode; | |
46 | uint8_t init4; /* true if 4 byte init */ | |
2053152b | 47 | uint8_t single_mode; /* true if slave pic is not initialized */ |
660de336 FB |
48 | uint8_t elcr; /* PIIX edge/trigger selection*/ |
49 | uint8_t elcr_mask; | |
3de388f6 | 50 | PicState2 *pics_state; |
80cabfad FB |
51 | } PicState; |
52 | ||
3de388f6 FB |
53 | struct PicState2 { |
54 | /* 0 is master pic, 1 is slave pic */ | |
55 | /* XXX: better separation between the two pics */ | |
56 | PicState pics[2]; | |
57 | IRQRequestFunc *irq_request; | |
58 | void *irq_request_opaque; | |
d592d303 FB |
59 | /* IOAPIC callback support */ |
60 | SetIRQFunc *alt_irq_func; | |
61 | void *alt_irq_opaque; | |
3de388f6 | 62 | }; |
80cabfad | 63 | |
4a0fb71e FB |
64 | #if defined(DEBUG_PIC) || defined (DEBUG_IRQ_COUNT) |
65 | static int irq_level[16]; | |
66 | #endif | |
67 | #ifdef DEBUG_IRQ_COUNT | |
68 | static uint64_t irq_count[16]; | |
69 | #endif | |
70 | ||
80cabfad FB |
71 | /* set irq level. If an edge is detected, then the IRR is set to 1 */ |
72 | static inline void pic_set_irq1(PicState *s, int irq, int level) | |
73 | { | |
74 | int mask; | |
75 | mask = 1 << irq; | |
660de336 FB |
76 | if (s->elcr & mask) { |
77 | /* level triggered */ | |
78 | if (level) { | |
80cabfad | 79 | s->irr |= mask; |
660de336 FB |
80 | s->last_irr |= mask; |
81 | } else { | |
82 | s->irr &= ~mask; | |
83 | s->last_irr &= ~mask; | |
84 | } | |
80cabfad | 85 | } else { |
660de336 FB |
86 | /* edge triggered */ |
87 | if (level) { | |
88 | if ((s->last_irr & mask) == 0) | |
89 | s->irr |= mask; | |
90 | s->last_irr |= mask; | |
91 | } else { | |
92 | s->last_irr &= ~mask; | |
93 | } | |
80cabfad FB |
94 | } |
95 | } | |
96 | ||
97 | /* return the highest priority found in mask (highest = smallest | |
98 | number). Return 8 if no irq */ | |
99 | static inline int get_priority(PicState *s, int mask) | |
100 | { | |
101 | int priority; | |
102 | if (mask == 0) | |
103 | return 8; | |
104 | priority = 0; | |
105 | while ((mask & (1 << ((priority + s->priority_add) & 7))) == 0) | |
106 | priority++; | |
107 | return priority; | |
108 | } | |
109 | ||
110 | /* return the pic wanted interrupt. return -1 if none */ | |
111 | static int pic_get_irq(PicState *s) | |
112 | { | |
113 | int mask, cur_priority, priority; | |
114 | ||
115 | mask = s->irr & ~s->imr; | |
116 | priority = get_priority(s, mask); | |
117 | if (priority == 8) | |
118 | return -1; | |
119 | /* compute current priority. If special fully nested mode on the | |
120 | master, the IRQ coming from the slave is not taken into account | |
121 | for the priority computation. */ | |
122 | mask = s->isr; | |
3de388f6 | 123 | if (s->special_fully_nested_mode && s == &s->pics_state->pics[0]) |
80cabfad FB |
124 | mask &= ~(1 << 2); |
125 | cur_priority = get_priority(s, mask); | |
126 | if (priority < cur_priority) { | |
127 | /* higher priority found: an irq should be generated */ | |
128 | return (priority + s->priority_add) & 7; | |
129 | } else { | |
130 | return -1; | |
131 | } | |
132 | } | |
133 | ||
134 | /* raise irq to CPU if necessary. must be called every time the active | |
135 | irq may change */ | |
3de388f6 FB |
136 | /* XXX: should not export it, but it is needed for an APIC kludge */ |
137 | void pic_update_irq(PicState2 *s) | |
80cabfad FB |
138 | { |
139 | int irq2, irq; | |
140 | ||
141 | /* first look at slave pic */ | |
3de388f6 | 142 | irq2 = pic_get_irq(&s->pics[1]); |
80cabfad FB |
143 | if (irq2 >= 0) { |
144 | /* if irq request by slave pic, signal master PIC */ | |
3de388f6 FB |
145 | pic_set_irq1(&s->pics[0], 2, 1); |
146 | pic_set_irq1(&s->pics[0], 2, 0); | |
80cabfad FB |
147 | } |
148 | /* look at requested irq */ | |
3de388f6 | 149 | irq = pic_get_irq(&s->pics[0]); |
80cabfad | 150 | if (irq >= 0) { |
80cabfad FB |
151 | #if defined(DEBUG_PIC) |
152 | { | |
153 | int i; | |
154 | for(i = 0; i < 2; i++) { | |
155 | printf("pic%d: imr=%x irr=%x padd=%d\n", | |
3de388f6 FB |
156 | i, s->pics[i].imr, s->pics[i].irr, |
157 | s->pics[i].priority_add); | |
80cabfad FB |
158 | |
159 | } | |
160 | } | |
2444ca41 | 161 | printf("pic: cpu_interrupt\n"); |
80cabfad | 162 | #endif |
3de388f6 | 163 | s->irq_request(s->irq_request_opaque, 1); |
80cabfad | 164 | } |
4de9b249 TS |
165 | |
166 | /* all targets should do this rather than acking the IRQ in the cpu */ | |
167 | #if defined(TARGET_MIPS) | |
168 | else { | |
169 | s->irq_request(s->irq_request_opaque, 0); | |
170 | } | |
171 | #endif | |
80cabfad FB |
172 | } |
173 | ||
174 | #ifdef DEBUG_IRQ_LATENCY | |
175 | int64_t irq_time[16]; | |
80cabfad | 176 | #endif |
80cabfad | 177 | |
3de388f6 | 178 | void pic_set_irq_new(void *opaque, int irq, int level) |
80cabfad | 179 | { |
3de388f6 FB |
180 | PicState2 *s = opaque; |
181 | ||
4a0fb71e | 182 | #if defined(DEBUG_PIC) || defined(DEBUG_IRQ_COUNT) |
80cabfad | 183 | if (level != irq_level[irq]) { |
4a0fb71e | 184 | #if defined(DEBUG_PIC) |
80cabfad | 185 | printf("pic_set_irq: irq=%d level=%d\n", irq, level); |
4a0fb71e | 186 | #endif |
80cabfad | 187 | irq_level[irq] = level; |
4a0fb71e FB |
188 | #ifdef DEBUG_IRQ_COUNT |
189 | if (level == 1) | |
190 | irq_count[irq]++; | |
191 | #endif | |
80cabfad FB |
192 | } |
193 | #endif | |
194 | #ifdef DEBUG_IRQ_LATENCY | |
195 | if (level) { | |
2444ca41 | 196 | irq_time[irq] = qemu_get_clock(vm_clock); |
80cabfad FB |
197 | } |
198 | #endif | |
3de388f6 | 199 | pic_set_irq1(&s->pics[irq >> 3], irq & 7, level); |
d592d303 FB |
200 | /* used for IOAPIC irqs */ |
201 | if (s->alt_irq_func) | |
202 | s->alt_irq_func(s->alt_irq_opaque, irq, level); | |
3de388f6 | 203 | pic_update_irq(s); |
80cabfad FB |
204 | } |
205 | ||
3de388f6 FB |
206 | /* obsolete function */ |
207 | void pic_set_irq(int irq, int level) | |
54fa5af5 | 208 | { |
3de388f6 | 209 | pic_set_irq_new(isa_pic, irq, level); |
54fa5af5 FB |
210 | } |
211 | ||
80cabfad FB |
212 | /* acknowledge interrupt 'irq' */ |
213 | static inline void pic_intack(PicState *s, int irq) | |
214 | { | |
215 | if (s->auto_eoi) { | |
216 | if (s->rotate_on_auto_eoi) | |
217 | s->priority_add = (irq + 1) & 7; | |
218 | } else { | |
219 | s->isr |= (1 << irq); | |
220 | } | |
0ecf89aa FB |
221 | /* We don't clear a level sensitive interrupt here */ |
222 | if (!(s->elcr & (1 << irq))) | |
223 | s->irr &= ~(1 << irq); | |
80cabfad FB |
224 | } |
225 | ||
3de388f6 | 226 | int pic_read_irq(PicState2 *s) |
80cabfad FB |
227 | { |
228 | int irq, irq2, intno; | |
229 | ||
3de388f6 | 230 | irq = pic_get_irq(&s->pics[0]); |
15aeac38 | 231 | if (irq >= 0) { |
3de388f6 | 232 | pic_intack(&s->pics[0], irq); |
15aeac38 | 233 | if (irq == 2) { |
3de388f6 | 234 | irq2 = pic_get_irq(&s->pics[1]); |
15aeac38 | 235 | if (irq2 >= 0) { |
3de388f6 | 236 | pic_intack(&s->pics[1], irq2); |
15aeac38 FB |
237 | } else { |
238 | /* spurious IRQ on slave controller */ | |
239 | irq2 = 7; | |
240 | } | |
3de388f6 | 241 | intno = s->pics[1].irq_base + irq2; |
15aeac38 FB |
242 | irq = irq2 + 8; |
243 | } else { | |
3de388f6 | 244 | intno = s->pics[0].irq_base + irq; |
15aeac38 FB |
245 | } |
246 | } else { | |
247 | /* spurious IRQ on host controller */ | |
248 | irq = 7; | |
3de388f6 | 249 | intno = s->pics[0].irq_base + irq; |
15aeac38 | 250 | } |
3de388f6 | 251 | pic_update_irq(s); |
15aeac38 | 252 | |
80cabfad FB |
253 | #ifdef DEBUG_IRQ_LATENCY |
254 | printf("IRQ%d latency=%0.3fus\n", | |
255 | irq, | |
2444ca41 | 256 | (double)(qemu_get_clock(vm_clock) - irq_time[irq]) * 1000000.0 / ticks_per_sec); |
80cabfad FB |
257 | #endif |
258 | #if defined(DEBUG_PIC) | |
259 | printf("pic_interrupt: irq=%d\n", irq); | |
260 | #endif | |
80cabfad FB |
261 | return intno; |
262 | } | |
263 | ||
d7d02e3c FB |
264 | static void pic_reset(void *opaque) |
265 | { | |
266 | PicState *s = opaque; | |
d7d02e3c | 267 | |
3de388f6 FB |
268 | s->last_irr = 0; |
269 | s->irr = 0; | |
270 | s->imr = 0; | |
271 | s->isr = 0; | |
272 | s->priority_add = 0; | |
273 | s->irq_base = 0; | |
274 | s->read_reg_select = 0; | |
275 | s->poll = 0; | |
276 | s->special_mask = 0; | |
277 | s->init_state = 0; | |
278 | s->auto_eoi = 0; | |
279 | s->rotate_on_auto_eoi = 0; | |
280 | s->special_fully_nested_mode = 0; | |
281 | s->init4 = 0; | |
2053152b | 282 | s->single_mode = 0; |
4dbe19e1 | 283 | /* Note: ELCR is not reset */ |
d7d02e3c FB |
284 | } |
285 | ||
b41a2cd1 | 286 | static void pic_ioport_write(void *opaque, uint32_t addr, uint32_t val) |
80cabfad | 287 | { |
b41a2cd1 | 288 | PicState *s = opaque; |
d7d02e3c | 289 | int priority, cmd, irq; |
80cabfad FB |
290 | |
291 | #ifdef DEBUG_PIC | |
292 | printf("pic_write: addr=0x%02x val=0x%02x\n", addr, val); | |
293 | #endif | |
80cabfad FB |
294 | addr &= 1; |
295 | if (addr == 0) { | |
296 | if (val & 0x10) { | |
297 | /* init */ | |
d7d02e3c | 298 | pic_reset(s); |
b54ad049 | 299 | /* deassert a pending interrupt */ |
3de388f6 | 300 | s->pics_state->irq_request(s->pics_state->irq_request_opaque, 0); |
80cabfad FB |
301 | s->init_state = 1; |
302 | s->init4 = val & 1; | |
2053152b | 303 | s->single_mode = val & 2; |
80cabfad FB |
304 | if (val & 0x08) |
305 | hw_error("level sensitive irq not supported"); | |
306 | } else if (val & 0x08) { | |
307 | if (val & 0x04) | |
308 | s->poll = 1; | |
309 | if (val & 0x02) | |
310 | s->read_reg_select = val & 1; | |
311 | if (val & 0x40) | |
312 | s->special_mask = (val >> 5) & 1; | |
313 | } else { | |
314 | cmd = val >> 5; | |
315 | switch(cmd) { | |
316 | case 0: | |
317 | case 4: | |
318 | s->rotate_on_auto_eoi = cmd >> 2; | |
319 | break; | |
320 | case 1: /* end of interrupt */ | |
321 | case 5: | |
322 | priority = get_priority(s, s->isr); | |
323 | if (priority != 8) { | |
324 | irq = (priority + s->priority_add) & 7; | |
325 | s->isr &= ~(1 << irq); | |
326 | if (cmd == 5) | |
327 | s->priority_add = (irq + 1) & 7; | |
3de388f6 | 328 | pic_update_irq(s->pics_state); |
80cabfad FB |
329 | } |
330 | break; | |
331 | case 3: | |
332 | irq = val & 7; | |
333 | s->isr &= ~(1 << irq); | |
3de388f6 | 334 | pic_update_irq(s->pics_state); |
80cabfad FB |
335 | break; |
336 | case 6: | |
337 | s->priority_add = (val + 1) & 7; | |
3de388f6 | 338 | pic_update_irq(s->pics_state); |
80cabfad FB |
339 | break; |
340 | case 7: | |
341 | irq = val & 7; | |
342 | s->isr &= ~(1 << irq); | |
343 | s->priority_add = (irq + 1) & 7; | |
3de388f6 | 344 | pic_update_irq(s->pics_state); |
80cabfad FB |
345 | break; |
346 | default: | |
347 | /* no operation */ | |
348 | break; | |
349 | } | |
350 | } | |
351 | } else { | |
352 | switch(s->init_state) { | |
353 | case 0: | |
354 | /* normal mode */ | |
355 | s->imr = val; | |
3de388f6 | 356 | pic_update_irq(s->pics_state); |
80cabfad FB |
357 | break; |
358 | case 1: | |
359 | s->irq_base = val & 0xf8; | |
2053152b | 360 | s->init_state = s->single_mode && s->init4 ? 3 : 2; |
80cabfad FB |
361 | break; |
362 | case 2: | |
363 | if (s->init4) { | |
364 | s->init_state = 3; | |
365 | } else { | |
366 | s->init_state = 0; | |
367 | } | |
368 | break; | |
369 | case 3: | |
370 | s->special_fully_nested_mode = (val >> 4) & 1; | |
371 | s->auto_eoi = (val >> 1) & 1; | |
372 | s->init_state = 0; | |
373 | break; | |
374 | } | |
375 | } | |
376 | } | |
377 | ||
378 | static uint32_t pic_poll_read (PicState *s, uint32_t addr1) | |
379 | { | |
380 | int ret; | |
381 | ||
382 | ret = pic_get_irq(s); | |
383 | if (ret >= 0) { | |
384 | if (addr1 >> 7) { | |
3de388f6 FB |
385 | s->pics_state->pics[0].isr &= ~(1 << 2); |
386 | s->pics_state->pics[0].irr &= ~(1 << 2); | |
80cabfad FB |
387 | } |
388 | s->irr &= ~(1 << ret); | |
389 | s->isr &= ~(1 << ret); | |
390 | if (addr1 >> 7 || ret != 2) | |
3de388f6 | 391 | pic_update_irq(s->pics_state); |
80cabfad FB |
392 | } else { |
393 | ret = 0x07; | |
3de388f6 | 394 | pic_update_irq(s->pics_state); |
80cabfad FB |
395 | } |
396 | ||
397 | return ret; | |
398 | } | |
399 | ||
b41a2cd1 | 400 | static uint32_t pic_ioport_read(void *opaque, uint32_t addr1) |
80cabfad | 401 | { |
b41a2cd1 | 402 | PicState *s = opaque; |
80cabfad FB |
403 | unsigned int addr; |
404 | int ret; | |
405 | ||
406 | addr = addr1; | |
80cabfad FB |
407 | addr &= 1; |
408 | if (s->poll) { | |
409 | ret = pic_poll_read(s, addr1); | |
410 | s->poll = 0; | |
411 | } else { | |
412 | if (addr == 0) { | |
413 | if (s->read_reg_select) | |
414 | ret = s->isr; | |
415 | else | |
416 | ret = s->irr; | |
417 | } else { | |
418 | ret = s->imr; | |
419 | } | |
420 | } | |
421 | #ifdef DEBUG_PIC | |
422 | printf("pic_read: addr=0x%02x val=0x%02x\n", addr1, ret); | |
423 | #endif | |
424 | return ret; | |
425 | } | |
426 | ||
427 | /* memory mapped interrupt status */ | |
3de388f6 FB |
428 | /* XXX: may be the same than pic_read_irq() */ |
429 | uint32_t pic_intack_read(PicState2 *s) | |
80cabfad FB |
430 | { |
431 | int ret; | |
432 | ||
3de388f6 | 433 | ret = pic_poll_read(&s->pics[0], 0x00); |
80cabfad | 434 | if (ret == 2) |
3de388f6 | 435 | ret = pic_poll_read(&s->pics[1], 0x80) + 8; |
80cabfad | 436 | /* Prepare for ISR read */ |
3de388f6 | 437 | s->pics[0].read_reg_select = 1; |
80cabfad FB |
438 | |
439 | return ret; | |
440 | } | |
441 | ||
660de336 FB |
442 | static void elcr_ioport_write(void *opaque, uint32_t addr, uint32_t val) |
443 | { | |
444 | PicState *s = opaque; | |
445 | s->elcr = val & s->elcr_mask; | |
446 | } | |
447 | ||
448 | static uint32_t elcr_ioport_read(void *opaque, uint32_t addr1) | |
449 | { | |
450 | PicState *s = opaque; | |
451 | return s->elcr; | |
452 | } | |
453 | ||
b0a21b53 FB |
454 | static void pic_save(QEMUFile *f, void *opaque) |
455 | { | |
456 | PicState *s = opaque; | |
457 | ||
458 | qemu_put_8s(f, &s->last_irr); | |
459 | qemu_put_8s(f, &s->irr); | |
460 | qemu_put_8s(f, &s->imr); | |
461 | qemu_put_8s(f, &s->isr); | |
462 | qemu_put_8s(f, &s->priority_add); | |
463 | qemu_put_8s(f, &s->irq_base); | |
464 | qemu_put_8s(f, &s->read_reg_select); | |
465 | qemu_put_8s(f, &s->poll); | |
466 | qemu_put_8s(f, &s->special_mask); | |
467 | qemu_put_8s(f, &s->init_state); | |
468 | qemu_put_8s(f, &s->auto_eoi); | |
469 | qemu_put_8s(f, &s->rotate_on_auto_eoi); | |
470 | qemu_put_8s(f, &s->special_fully_nested_mode); | |
471 | qemu_put_8s(f, &s->init4); | |
2053152b | 472 | qemu_put_8s(f, &s->single_mode); |
660de336 | 473 | qemu_put_8s(f, &s->elcr); |
b0a21b53 FB |
474 | } |
475 | ||
476 | static int pic_load(QEMUFile *f, void *opaque, int version_id) | |
477 | { | |
478 | PicState *s = opaque; | |
479 | ||
480 | if (version_id != 1) | |
481 | return -EINVAL; | |
482 | ||
483 | qemu_get_8s(f, &s->last_irr); | |
484 | qemu_get_8s(f, &s->irr); | |
485 | qemu_get_8s(f, &s->imr); | |
486 | qemu_get_8s(f, &s->isr); | |
487 | qemu_get_8s(f, &s->priority_add); | |
488 | qemu_get_8s(f, &s->irq_base); | |
489 | qemu_get_8s(f, &s->read_reg_select); | |
490 | qemu_get_8s(f, &s->poll); | |
491 | qemu_get_8s(f, &s->special_mask); | |
492 | qemu_get_8s(f, &s->init_state); | |
493 | qemu_get_8s(f, &s->auto_eoi); | |
494 | qemu_get_8s(f, &s->rotate_on_auto_eoi); | |
495 | qemu_get_8s(f, &s->special_fully_nested_mode); | |
496 | qemu_get_8s(f, &s->init4); | |
2053152b | 497 | qemu_get_8s(f, &s->single_mode); |
660de336 | 498 | qemu_get_8s(f, &s->elcr); |
b0a21b53 FB |
499 | return 0; |
500 | } | |
501 | ||
502 | /* XXX: add generic master/slave system */ | |
660de336 | 503 | static void pic_init1(int io_addr, int elcr_addr, PicState *s) |
b0a21b53 FB |
504 | { |
505 | register_ioport_write(io_addr, 2, 1, pic_ioport_write, s); | |
506 | register_ioport_read(io_addr, 2, 1, pic_ioport_read, s); | |
660de336 FB |
507 | if (elcr_addr >= 0) { |
508 | register_ioport_write(elcr_addr, 1, 1, elcr_ioport_write, s); | |
509 | register_ioport_read(elcr_addr, 1, 1, elcr_ioport_read, s); | |
510 | } | |
b0a21b53 | 511 | register_savevm("i8259", io_addr, 1, pic_save, pic_load, s); |
d7d02e3c | 512 | qemu_register_reset(pic_reset, s); |
b0a21b53 FB |
513 | } |
514 | ||
ba91cd80 FB |
515 | void pic_info(void) |
516 | { | |
517 | int i; | |
518 | PicState *s; | |
3de388f6 FB |
519 | |
520 | if (!isa_pic) | |
521 | return; | |
ba91cd80 FB |
522 | |
523 | for(i=0;i<2;i++) { | |
3de388f6 | 524 | s = &isa_pic->pics[i]; |
15aeac38 | 525 | term_printf("pic%d: irr=%02x imr=%02x isr=%02x hprio=%d irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n", |
660de336 | 526 | i, s->irr, s->imr, s->isr, s->priority_add, |
15aeac38 FB |
527 | s->irq_base, s->read_reg_select, s->elcr, |
528 | s->special_fully_nested_mode); | |
ba91cd80 FB |
529 | } |
530 | } | |
531 | ||
4a0fb71e FB |
532 | void irq_info(void) |
533 | { | |
534 | #ifndef DEBUG_IRQ_COUNT | |
535 | term_printf("irq statistic code not compiled.\n"); | |
536 | #else | |
537 | int i; | |
538 | int64_t count; | |
539 | ||
540 | term_printf("IRQ statistics:\n"); | |
541 | for (i = 0; i < 16; i++) { | |
542 | count = irq_count[i]; | |
543 | if (count > 0) | |
26a76461 | 544 | term_printf("%2d: %" PRId64 "\n", i, count); |
4a0fb71e FB |
545 | } |
546 | #endif | |
547 | } | |
ba91cd80 | 548 | |
3de388f6 | 549 | PicState2 *pic_init(IRQRequestFunc *irq_request, void *irq_request_opaque) |
80cabfad | 550 | { |
3de388f6 FB |
551 | PicState2 *s; |
552 | s = qemu_mallocz(sizeof(PicState2)); | |
553 | if (!s) | |
554 | return NULL; | |
555 | pic_init1(0x20, 0x4d0, &s->pics[0]); | |
556 | pic_init1(0xa0, 0x4d1, &s->pics[1]); | |
557 | s->pics[0].elcr_mask = 0xf8; | |
558 | s->pics[1].elcr_mask = 0xde; | |
559 | s->irq_request = irq_request; | |
560 | s->irq_request_opaque = irq_request_opaque; | |
561 | s->pics[0].pics_state = s; | |
562 | s->pics[1].pics_state = s; | |
563 | return s; | |
80cabfad | 564 | } |
d592d303 FB |
565 | |
566 | void pic_set_alt_irq_func(PicState2 *s, SetIRQFunc *alt_irq_func, | |
567 | void *alt_irq_opaque) | |
568 | { | |
569 | s->alt_irq_func = alt_irq_func; | |
570 | s->alt_irq_opaque = alt_irq_opaque; | |
571 | } |