Bind interrupts
This commit is contained in:
parent
30b9fe2c93
commit
b1fb74db0c
@ -12,6 +12,11 @@ int divide(int a, int b)
|
||||
return a/b;
|
||||
}
|
||||
|
||||
registers *divbyzero(registers *r) {
|
||||
PANIC("DIVIDE BY ZERO!");
|
||||
return r;
|
||||
}
|
||||
|
||||
void kmain(uint64_t multiboot_magic, void *multiboot_data)
|
||||
{
|
||||
vga_init();
|
||||
@ -35,6 +40,8 @@ void kmain(uint64_t multiboot_magic, void *multiboot_data)
|
||||
|
||||
interrupt_init();
|
||||
|
||||
bind_interrupt(0, divbyzero);
|
||||
|
||||
debug("Hello, world!");
|
||||
|
||||
// Force a divide by zero error
|
||||
|
@ -26,6 +26,7 @@ struct {
|
||||
}__attribute__((packed)) idtr;
|
||||
|
||||
extern uintptr_t isr_table[];
|
||||
int_handler_t int_handlers[NUM_INTERRUPTS];
|
||||
|
||||
void interrupt_init()
|
||||
{
|
||||
@ -45,8 +46,16 @@ void interrupt_init()
|
||||
load_idt(&idtr); // cpu/registers.S
|
||||
}
|
||||
|
||||
int_handler_t bind_interrupt(uint32_t num, int_handler_t fn) {
|
||||
int_handler_t old = int_handlers[num];
|
||||
int_handlers[num] = fn;
|
||||
return old;
|
||||
}
|
||||
|
||||
registers *int_handler(registers *r)
|
||||
{
|
||||
if(int_handlers[r->int_no])
|
||||
return int_handlers[r->int_no](r);
|
||||
debug_error("Unhandled interrupt occurred\n");
|
||||
debug_error("Interrupt number: %d, Error code: %d\n", r->int_no, r->err_code);
|
||||
PANIC("Unhandled interrupt");
|
||||
|
@ -28,5 +28,9 @@ typedef struct {
|
||||
uint64_t ss;
|
||||
} registers;
|
||||
|
||||
typedef registers *(*int_handler_t)(registers *);
|
||||
|
||||
// cpu/interrupts.c
|
||||
void interrupt_init();
|
||||
void isr_return(registers *);
|
||||
int_handler_t bind_interrupt(uint32_t num, int_handler_t fn);
|
Loading…
x
Reference in New Issue
Block a user