diff --git a/k/pic.c b/k/pic.c new file mode 100644 index 0000000..5c65180 --- /dev/null +++ b/k/pic.c @@ -0,0 +1,24 @@ +#include "pic.h" +#include "io.h" + +void remap_pic(void) +{ + // ICW1 + outb(MASTER_PORT_A, ICW1_INIT | ICW1_ICW4); + outb(SLAVE_PORT_A, ICW1_INIT | ICW1_ICW4); + + // ICW2 + outb(MASTER_PORT_B, ICW2_M_OFFSET); + outb(SLAVE_PORT_B, ICW2_S_OFFSET); + + // ICW3 + outb(MASTER_PORT_B, PIC_PIN_2); + outb(SLAVE_PORT_B, 2); + + // ICW4 + outb(MASTER_PORT_B, ICW4_INIT); + outb(SLAVE_PORT_B, ICW4_INIT); + + // OCW1 + outb(MASTER_PORT_B, PIC_PIN_0); // masking PIT for now +} diff --git a/k/pic.h b/k/pic.h new file mode 100644 index 0000000..ae5ec5d --- /dev/null +++ b/k/pic.h @@ -0,0 +1,41 @@ +#ifndef PIC_H +#define PIC_H + +#define MASTER_PORT_A 0x20 +#define MASTER_PORT_B 0x21 +#define SLAVE_PORT_A 0xa0 +#define SLAVE_PORT_B 0xa1 + +// ICW1 +#define ICW1_ICW4 0x1 +#define ICW1_SINGLE 0x2 +#define ICW_LT 0x8 +#define ICW1_INIT 0x10 + +// ICW2 +#define ICW2_M_OFFSET 0x20 +#define ICW2_S_OFFSET 0x28 + +// ICW3 / OCW1 +#define PIC_PIN_0 0x1 +#define PIC_PIN_1 0x2 +#define PIC_PIN_2 0x4 +#define PIC_PIN_3 0x8 +#define PIC_PIN_4 0x10 +#define PIC_PIN_5 0x20 +#define PIC_PIN_6 0x40 +#define PIC_PIN_7 0x80 + +// ICW4 +#define ICW4_INIT 0x1 +#define ICW4_AUTO_EOI 0x2 +#define ICW4_NESTED 0x10 + +// OCW2 +#define OCW2_EOI 0x20 +#define OCW2_SPEC 0x40 +#define OCW2_ROT 0x80 + +void remap_pic(void); + +#endif /* !PIC_H */