1 // Helpers for working with i8259 interrupt controller.
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002 MandrakeSoft S.A.
6 // This file may be distributed under the terms of the GNU GPLv3 license.
8 #include "ioport.h" // PORT_PIC*
9 #include "util.h" // dprintf
12 #define PIC1_IRQ0 (1<<0)
13 #define PIC1_IRQ1 (1<<1)
14 #define PIC1_IRQ2 (1<<2)
15 #define PIC1_IRQ5 (1<<5)
16 #define PIC1_IRQ6 (1<<6)
18 #define PIC2_IRQ8 (1<<0)
19 #define PIC2_IRQ12 (1<<4)
20 #define PIC2_IRQ13 (1<<5)
21 #define PIC2_IRQ14 (1<<6)
26 // Send eoi (select OCW2 + eoi)
27 outb(0x20, PORT_PIC1_CMD);
33 // Send eoi (select OCW2 + eoi)
34 outb(0x20, PORT_PIC2_CMD);
41 outb(inb(PORT_PIC1_DATA) & ~irq, PORT_PIC1_DATA);
47 outb(inb(PORT_PIC2_DATA) & ~irq, PORT_PIC2_DATA);
53 // 0x0b == select OCW1 + read ISR
54 outb(0x0b, PORT_PIC1_CMD);
55 return inb(PORT_PIC1_CMD);
61 dprintf(3, "init pic\n");
62 // Send ICW1 (select OCW1 + will send ICW4)
63 outb(0x11, PORT_PIC1_CMD);
64 outb(0x11, PORT_PIC2_CMD);
65 // Send ICW2 (base irqs: 0x08-0x0f for irq0-7, 0x70-0x78 for irq8-15)
66 outb(0x08, PORT_PIC1_DATA);
67 outb(0x70, PORT_PIC2_DATA);
68 // Send ICW3 (cascaded pic ids)
69 outb(0x04, PORT_PIC1_DATA);
70 outb(0x02, PORT_PIC2_DATA);
71 // Send ICW4 (enable 8086 mode)
72 outb(0x01, PORT_PIC1_DATA);
73 outb(0x01, PORT_PIC2_DATA);
74 // Mask all irqs (except cascaded PIC2 irq)
75 outb(~PIC1_IRQ2, PORT_PIC1_DATA);
76 outb(~0, PORT_PIC2_DATA);