-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathisr.c
More file actions
65 lines (55 loc) · 1.39 KB
/
isr.c
File metadata and controls
65 lines (55 loc) · 1.39 KB
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
/**
* This file contains the minimal C code for dispatching
* interrupts to handlers.
*/
#include "isr.h"
#include "idt.h"
#include "kernio.h"
#include "pic.h"
#include "port.h"
#include "stdint.h"
extern void halt();
isr_handler_t interrupt_handlers[256];
void register_interrupt_handler(uint8_t interrupt, isr_handler_t handler)
{
interrupt_handlers[interrupt] = handler;
}
void isr_handler(registers_t regs)
{
if(regs.int_no == GENERAL_PROTECTION_FAULT)
{
printf("General Protection Fault. Code: %d", regs.err_code);
PANIC("General Protection Fault!");
}
if(interrupt_handlers[regs.int_no])
{
//printf("Handling %d!\n", regs.int_no);
interrupt_handlers[regs.int_no](regs);
//printf("Returning!\n");
}
// else {
// printf("Got ISR.\n");
// PANIC("Unhandled ISR.\n");
// }
}
void irq_handler(registers_t regs)
{
//If int_no >= 40, we must reset the slave as well as the master
if(regs.int_no >= 40)
{
//reset slave
outb(SLAVE_COMMAND, PIC_RESET);
}
outb(MASTER_COMMAND, PIC_RESET);
if(interrupt_handlers[regs.int_no])
{
interrupt_handlers[regs.int_no](regs);
}
// else {
// if(regs.int_no == 33) return;
// printf("Got IRQ.\n");
// char buff[1024];
// sprintf(buff, "Unhandled IRQ %d\n", regs.int_no);
// PANIC(buff);
// }
}