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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include <kernel/pic.h>
void pic_eoi(unsigned char irq) {
if (irq >= 8)
outb(PIC2_COMMAND, 0x20);
outb(PIC1_COMMAND, 0x20);
}
void pic_remap(void) {
unsigned char a1 = inb(PIC1_DATA);
unsigned char a2 = inb(PIC2_DATA);
outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4);
outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4);
outb(PIC1_DATA, PIC1);
outb(PIC2_DATA, PIC2);
outb(PIC1_DATA, 4);
outb(PIC2_DATA, 2);
outb(PIC1_DATA, ICW4_8086);
outb(PIC2_DATA, ICW4_8086);
outb(PIC1_DATA, a1);
outb(PIC2_DATA, a2);
}
void irq_set_mask(uint8_t irq) {
uint16_t port;
uint8_t data;
if (irq < 8) {
port = PIC1_DATA;
} else {
port = PIC2_DATA;
irq -= 8;
}
data = inb(port) | (1 << irq);
outb(port, data);
}
void irq_clear_mask(unsigned char irq) {
uint16_t port;
uint8_t data;
if (irq < 8) {
port = PIC1_DATA;
} else {
port = PIC2_DATA;
irq -= 8;
}
data = inb(port) & ~(1 << irq);
outb(port, data);
}
|