00001
00002
00003 #include "types.h"
00004 #include "x86.h"
00005 #include "traps.h"
00006
00007
00008 #define IO_PIC1 0x20 // Master (IRQs 0-7)
00009 #define IO_PIC2 0xA0 // Slave (IRQs 8-15)
00010
00011 #define IRQ_SLAVE 2 // IRQ at which slave connects to master
00012
00013
00014
00015 static ushort irqmask = 0xFFFF & ~(1<<IRQ_SLAVE);
00016
00017 static void
00018 picsetmask(ushort mask)
00019 {
00020 irqmask = mask;
00021 outb(IO_PIC1+1, mask);
00022 outb(IO_PIC2+1, mask >> 8);
00023 }
00024
00025 void
00026 picenable(int irq)
00027 {
00028 picsetmask(irqmask & ~(1<<irq));
00029 }
00030
00031
00032 void
00033 picinit(void)
00034 {
00035
00036 outb(IO_PIC1+1, 0xFF);
00037 outb(IO_PIC2+1, 0xFF);
00038
00039
00040
00041
00042
00043
00044
00045 outb(IO_PIC1, 0x11);
00046
00047
00048 outb(IO_PIC1+1, T_IRQ0);
00049
00050
00051
00052 outb(IO_PIC1+1, 1<<IRQ_SLAVE);
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 outb(IO_PIC1+1, 0x3);
00063
00064
00065 outb(IO_PIC2, 0x11);
00066 outb(IO_PIC2+1, T_IRQ0 + 8);
00067 outb(IO_PIC2+1, IRQ_SLAVE);
00068
00069
00070 outb(IO_PIC2+1, 0x3);
00071
00072
00073
00074
00075
00076 outb(IO_PIC1, 0x68);
00077 outb(IO_PIC1, 0x0a);
00078
00079 outb(IO_PIC2, 0x68);
00080 outb(IO_PIC2, 0x0a);
00081
00082 if(irqmask != 0xFFFF)
00083 picsetmask(irqmask);
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113