Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 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 | // |
Kevin O'Connor | b1b7c2a | 2009-01-15 20:52:58 -0500 | [diff] [blame] | 6 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 7 | |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 8 | #include "pic.h" // get_pic1_isr |
| 9 | #include "util.h" // dprintf |
| 10 | #include "config.h" // CONFIG_* |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 11 | |
| 12 | void |
| 13 | pic_setup() |
| 14 | { |
| 15 | dprintf(3, "init pic\n"); |
| 16 | // Send ICW1 (select OCW1 + will send ICW4) |
| 17 | outb(0x11, PORT_PIC1_CMD); |
| 18 | outb(0x11, PORT_PIC2_CMD); |
Kevin O'Connor | 65e6342 | 2008-07-19 14:12:32 -0400 | [diff] [blame] | 19 | // Send ICW2 (base irqs: 0x08-0x0f for irq0-7, 0x70-0x77 for irq8-15) |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 20 | outb(0x08, PORT_PIC1_DATA); |
| 21 | outb(0x70, PORT_PIC2_DATA); |
| 22 | // Send ICW3 (cascaded pic ids) |
| 23 | outb(0x04, PORT_PIC1_DATA); |
| 24 | outb(0x02, PORT_PIC2_DATA); |
| 25 | // Send ICW4 (enable 8086 mode) |
| 26 | outb(0x01, PORT_PIC1_DATA); |
| 27 | outb(0x01, PORT_PIC2_DATA); |
| 28 | // Mask all irqs (except cascaded PIC2 irq) |
| 29 | outb(~PIC1_IRQ2, PORT_PIC1_DATA); |
| 30 | outb(~0, PORT_PIC2_DATA); |
| 31 | } |
| 32 | |
| 33 | // Handler for otherwise unused hardware irqs. |
| 34 | void VISIBLE16 |
Kevin O'Connor | ffdc9ee | 2008-12-20 13:10:00 -0500 | [diff] [blame] | 35 | handle_hwpic1(struct bregs *regs) |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 36 | { |
Kevin O'Connor | eac894d | 2009-02-05 21:23:39 -0500 | [diff] [blame] | 37 | dprintf(DEBUG_ISR_hwpic1, "handle_hwpic1 irq=%x\n", get_pic1_isr()); |
Kevin O'Connor | ffdc9ee | 2008-12-20 13:10:00 -0500 | [diff] [blame] | 38 | eoi_pic1(); |
| 39 | } |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 40 | |
Kevin O'Connor | ffdc9ee | 2008-12-20 13:10:00 -0500 | [diff] [blame] | 41 | void VISIBLE16 |
| 42 | handle_hwpic2(struct bregs *regs) |
| 43 | { |
Kevin O'Connor | eac894d | 2009-02-05 21:23:39 -0500 | [diff] [blame] | 44 | dprintf(DEBUG_ISR_hwpic2, "handle_hwpic2 irq=%x\n", get_pic2_isr()); |
Kevin O'Connor | ffdc9ee | 2008-12-20 13:10:00 -0500 | [diff] [blame] | 45 | eoi_pic2(); |
Kevin O'Connor | c541e1b | 2008-06-21 12:24:14 -0400 | [diff] [blame] | 46 | } |