|
|
|
@ -1,5 +1,10 @@
|
|
|
|
|
/* See the end of this file for copyright and license terms. */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Most of the PIC management stuff is taken directly from the OSDev wiki:
|
|
|
|
|
* <https://wiki.osdev.org/PIC>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <arch/irq.h>
|
|
|
|
|
#include <arch/port.h>
|
|
|
|
|
#include <arch/trap.h>
|
|
|
|
@ -35,34 +40,25 @@ void arch_irq_init(void)
|
|
|
|
|
x86_set_intr_gate(X86_VECT_IRQ(15), _x86_isr_irq15);
|
|
|
|
|
|
|
|
|
|
/* begin initialization sequence in cascade mode */
|
|
|
|
|
x86_outb(X86_PORT_PIC1_CMD, ICW1_INIT | ICW1_ICW4);
|
|
|
|
|
x86_io_wait();
|
|
|
|
|
x86_outb(X86_PORT_PIC2_CMD, ICW1_INIT | ICW1_ICW4);
|
|
|
|
|
x86_io_wait();
|
|
|
|
|
x86_outb_wait(X86_PORT_PIC1_CMD, ICW1_INIT | ICW1_ICW4);
|
|
|
|
|
x86_outb_wait(X86_PORT_PIC2_CMD, ICW1_INIT | ICW1_ICW4);
|
|
|
|
|
|
|
|
|
|
/* tell PIC1 its offset into the vector table */
|
|
|
|
|
x86_outb(X86_PORT_PIC1_DATA, X86_VECT_IRQ_BASE);
|
|
|
|
|
x86_io_wait();
|
|
|
|
|
x86_outb_wait(X86_PORT_PIC1_DATA, X86_VECT_IRQ_BASE);
|
|
|
|
|
/* tell PIC2 its offset into the vector table */
|
|
|
|
|
x86_outb(X86_PORT_PIC2_DATA, X86_VECT_IRQ_BASE + 8);
|
|
|
|
|
x86_io_wait();
|
|
|
|
|
x86_outb_wait(X86_PORT_PIC2_DATA, X86_VECT_IRQ_BASE + 8);
|
|
|
|
|
|
|
|
|
|
/* tell PIC1 that PIC2 is cascading into it on IRQ 2 */
|
|
|
|
|
x86_outb(X86_PORT_PIC1_DATA, 1 << 2);
|
|
|
|
|
x86_io_wait();
|
|
|
|
|
x86_outb_wait(X86_PORT_PIC1_DATA, 1 << 2);
|
|
|
|
|
/* tell PIC2 that it is the second controller in the cascade chain */
|
|
|
|
|
x86_outb(X86_PORT_PIC2_DATA, 2);
|
|
|
|
|
x86_io_wait();
|
|
|
|
|
x86_outb_wait(X86_PORT_PIC2_DATA, 2);
|
|
|
|
|
|
|
|
|
|
/* don't ask me what the fuck this does */
|
|
|
|
|
x86_outb(X86_PORT_PIC1_DATA, ICW4_8086);
|
|
|
|
|
x86_io_wait();
|
|
|
|
|
x86_outb(X86_PORT_PIC2_DATA, ICW4_8086);
|
|
|
|
|
x86_io_wait();
|
|
|
|
|
x86_outb_wait(X86_PORT_PIC1_DATA, ICW4_8086);
|
|
|
|
|
x86_outb_wait(X86_PORT_PIC2_DATA, ICW4_8086);
|
|
|
|
|
|
|
|
|
|
/* mask all IRQs */
|
|
|
|
|
x86_outb(X86_PORT_PIC1_DATA, 0xff);
|
|
|
|
|
x86_io_wait();
|
|
|
|
|
x86_outb_wait(X86_PORT_PIC1_DATA, 0xff);
|
|
|
|
|
x86_outb(X86_PORT_PIC2_DATA, 0xff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|