]> git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/arch/x86/irq/interrupt.c
Rework interrupt handling
[nameless-os.git] / kernel / arch / x86 / irq / interrupt.c
1 #include <irq/idt.h>
2 #include <irq/interrupt.h>
3 #include <tty.h>
4 #include <stddef.h>
5 #include <irq/i8259a.h>
6
7 /* This table will hold pointers to our interrupt handlers. */
8 static int (*int_handler_table[256])(void);
9
10 void int_handler(int interrupt)
11 {
12 if (int_handler_table[interrupt] == NULL) {
13 kprint("WARNING: Unhandled interrupt ", 0);
14 kprintb(interrupt);
15 kprint(" occurred!\n", 0);
16 } else {
17 int ret = (*int_handler_table[interrupt])();
18 if (ret) {
19 kprint("WARNING: Error while handling interrupt ", 0);
20 kprintb(interrupt);
21 kprint("!\n", 0);
22 }
23 }
24 if (interrupt >= 0x20) {
25 pic_send_eoi(interrupt - 0x20);
26 }
27 }
28
29 int register_interrupt(int irq, int (*handler)(void))
30 {
31 int_handler_table[irq] = handler;
32 if (irq >= 32 && irq < 48) {
33 pic_unmask(irq-32);
34 }
35 return 0;
36 }