Add code (currently disabled) to mask run away irqs.
[seabios.git] / src / pic.c
1 // Helpers for working with i8259 interrupt controller.
2 //
3 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002  MandrakeSoft S.A.
5 //
6 // This file may be distributed under the terms of the GNU GPLv3 license.
7
8 #include "pic.h"
9
10 void
11 pic_setup()
12 {
13     dprintf(3, "init pic\n");
14     // Send ICW1 (select OCW1 + will send ICW4)
15     outb(0x11, PORT_PIC1_CMD);
16     outb(0x11, PORT_PIC2_CMD);
17     // Send ICW2 (base irqs: 0x08-0x0f for irq0-7, 0x70-0x78 for irq8-15)
18     outb(0x08, PORT_PIC1_DATA);
19     outb(0x70, PORT_PIC2_DATA);
20     // Send ICW3 (cascaded pic ids)
21     outb(0x04, PORT_PIC1_DATA);
22     outb(0x02, PORT_PIC2_DATA);
23     // Send ICW4 (enable 8086 mode)
24     outb(0x01, PORT_PIC1_DATA);
25     outb(0x01, PORT_PIC2_DATA);
26     // Mask all irqs (except cascaded PIC2 irq)
27     outb(~PIC1_IRQ2, PORT_PIC1_DATA);
28     outb(~0, PORT_PIC2_DATA);
29 }
30
31 // Handler for otherwise unused hardware irqs.
32 void VISIBLE16
33 handle_hwirq(struct bregs *regs)
34 {
35     debug_isr(DEBUG_ISR_hwirq);
36
37     u8 isr1 = get_pic1_isr();
38     if (! isr1) {
39         dprintf(1, "Got hwirq with no ISR\n");
40         return;
41     }
42
43     u8 isr2 = get_pic2_isr();
44     u16 isr = isr2<<8 | isr1;
45     dprintf(1, "Masking noisy irq %x\n", isr);
46     if (isr2) {
47         mask_pic2(isr2);
48         eoi_pic2();
49     } else {
50         if (! (isr1 & 0x2)) // don't ever mask the cascaded irq
51             mask_pic1(isr1);
52         eoi_pic1();
53     }
54 }