Orion
Barry Importing existing Orion kernel d41a53c (2 years, 4 months ago)diff --git a/proc/pic.c b/proc/pic.c new file mode 100644 index 0000000..e478921 --- /dev/null +++ b/proc/pic.c @@ -0,0 +1,40 @@ +/* + * This file deals with the Programmable Interrupt Controller. It is usually + * disable and replaced by the APIC. + */ + +#include "../io.h" + +/* Initialise the PIC to a specified frequency */ +static void +init_pit(void) +{ + uint32_t divisor = 1193182 / 1000; + outb(0x43, 0x36); + outb(0x40, divisor & 0xFF); + outb(0x40, (divisor >> 8) & 0xFF); +} + +/* Initialise the PIC */ +void +init_pic(void) +{ + /* + * By default interrupts and exceptions both start at IRQ#0. To avoid + * collision we can map interrupts to start at IRQ#32. Since lower + * numbered IRQ lines are higher priority, exceptions have priority. + */ + outb(0x20, 0x11); io_wait(); + outb(0xA0, 0x11); io_wait(); + outb(0x21, 0x20); io_wait(); + outb(0xA1, 0x28); io_wait(); + outb(0x21, 0x04); io_wait(); + outb(0xA1, 0x02); io_wait(); + outb(0x21, 0x01); io_wait(); + outb(0xA1, 0x01); io_wait(); + outb(0x21, 0x00); io_wait(); + outb(0xA1, 0x00); io_wait(); + + init_pit(); +} +