-
Notifications
You must be signed in to change notification settings - Fork 0
/
pic.c
37 lines (31 loc) · 1.41 KB
/
pic.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "io.h"
#include "pic.h"
/** pic_acknowledge:
* Acknowledges an interrupt from either PIC 1 or PIC 2.
*
* @param num The number of the interrupt
*/
void pic_acknowledge(unsigned int interrupt){
if (interrupt < PIC_1_OFFSET || interrupt > PIC_2_END) {
return;
}
if (interrupt < PIC_2_OFFSET) {
outb(PIC_1_COMMAND_PORT, PIC_ACKNOWLEDGE);
} else {
outb(PIC_2_COMMAND_PORT, PIC_ACKNOWLEDGE);
}
}
void pic_remap(int offset1, int offset2){
outb(PIC_1_COMMAND, PIC_ICW1_INIT + PIC_ICW1_ICW4); // starts the initialization sequence (in cascade mode)
outb(PIC_2_COMMAND, PIC_ICW1_INIT + PIC_ICW1_ICW4);
outb(PIC_1_DATA, offset1); // ICW2: Master PIC vector offset
outb(PIC_2_DATA, offset2); // ICW2: Slave PIC vector offset
outb(PIC_1_DATA, 4); // ICW3: tell Master PIC that there is a slave PIC at IRQ2 (0000 0100)
outb(PIC_2_DATA, 2); // ICW3: tell Slave PIC its cascade identity (0000 0010)
outb(PIC_1_DATA, PIC_ICW4_8086);
outb(PIC_2_DATA, PIC_ICW4_8086);
// Setup Interrupt Mask Register (IMR)
outb(PIC_1_DATA, 0xFD); // 1111 1101 - Enable IRQ 1 only (keyboard).
outb(PIC_2_DATA, 0xFF);
asm("sti"); // Enable interrupts.
}