-
Notifications
You must be signed in to change notification settings - Fork 0
/
irq.c
66 lines (55 loc) · 1.61 KB
/
irq.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <irq.h>
#include <idt.h>
#include <kernlib.h>
#include <timer.h>
isr_t interrupt_handlers[256];
void irq_handler(registers_t regs)
{
if (regs.int_no >= 40)
{
// Send reset signal to slave.
outb(PIC2_COMMAND, PIC_EOI);
}
// Send reset signal to master. (As well as slave, if necessary).
outb(PIC1_COMMAND, PIC_EOI);
if (interrupt_handlers[regs.int_no] != 0)
{
isr_t handler = interrupt_handlers[regs.int_no];
handler(regs);
} else {
printf("IRQ %u received\n", regs.int_no-32);
}
}
void irq_install(void) {
outb(PIC1_COMMAND, 0x11);
outb(PIC2_COMMAND, 0x11);
outb(0x21, 0x20);
outb(0xA1, 0x28);
outb(0x21, 0x04);
outb(0xA1, 0x02);
outb(0x21, 0x01);
outb(0xA1, 0x01);
outb(0x21, 0x0);
outb(0xA1, 0x0);
idt_set_gate(32, (u32_t)irq0, 0x08, 0x8E);
idt_set_gate(33, (u32_t)irq1, 0x08, 0x8E);
idt_set_gate(34, (u32_t)irq2, 0x08, 0x8E);
idt_set_gate(35, (u32_t)irq3, 0x08, 0x8E);
idt_set_gate(36, (u32_t)irq4, 0x08, 0x8E);
idt_set_gate(37, (u32_t)irq5, 0x08, 0x8E);
idt_set_gate(38, (u32_t)irq6, 0x08, 0x8E);
idt_set_gate(39, (u32_t)irq7, 0x08, 0x8E);
idt_set_gate(40, (u32_t)irq8, 0x08, 0x8E);
idt_set_gate(41, (u32_t)irq9, 0x08, 0x8E);
idt_set_gate(42, (u32_t)irq10, 0x08, 0x8E);
idt_set_gate(43, (u32_t)irq11, 0x08, 0x8E);
idt_set_gate(44, (u32_t)irq12, 0x08, 0x8E);
idt_set_gate(45, (u32_t)irq13, 0x08, 0x8E);
idt_set_gate(46, (u32_t)irq14, 0x08, 0x8E);
idt_set_gate(47, (u32_t)irq15, 0x08, 0x8E);
}
void register_irq_handler(u8_t irq_nr, isr_t handler)
{
interrupt_handlers[irq_nr + IRQ_OFFSET] = handler;
}
// register_irq_handler(0, timer_handler);