2018-09-30 14:56:07 -04:00
|
|
|
#include <stdio.h>
|
2018-09-07 00:32:45 -04:00
|
|
|
#include "isr.h"
|
|
|
|
|
#include "console.h"
|
2018-09-07 13:49:25 -04:00
|
|
|
#include "drivers/ports.h"
|
2018-09-07 00:32:45 -04:00
|
|
|
|
2018-09-21 22:15:10 -04:00
|
|
|
isr_t interrupt_handlers[256] = {};
|
2018-09-07 13:49:25 -04:00
|
|
|
|
|
|
|
|
void register_interrupt_handler(uint8_t n, isr_t handler) {
|
|
|
|
|
interrupt_handlers[n] = handler;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-25 00:37:34 -04:00
|
|
|
_unused
|
|
|
|
|
void isr_handler(registers_t regs) {
|
2018-10-07 00:34:59 -04:00
|
|
|
panic("Received interrupt: %lu (err: %Xh, CR2 %Xh) @ %P\n",
|
|
|
|
|
regs.int_no, regs.err_code, regs.cr2, (uintptr_t) regs.eip);
|
2018-09-07 13:49:25 -04:00
|
|
|
}
|
|
|
|
|
|
2018-09-25 00:37:34 -04:00
|
|
|
_unused
|
|
|
|
|
void irq_handler(registers_t regs) {
|
2018-10-01 20:51:57 -04:00
|
|
|
isr_t handler = interrupt_handlers[regs.int_no];
|
|
|
|
|
if (handler) handler(regs);
|
|
|
|
|
|
2018-09-07 13:49:25 -04:00
|
|
|
// Send an EOI (end of interrupt) signal to the PICs.
|
|
|
|
|
// If this interrupt involved the slave.
|
2018-09-07 15:21:15 -04:00
|
|
|
if (regs.int_no >= IRQ8) {
|
2018-09-07 13:49:25 -04:00
|
|
|
// Send reset signal to slave.
|
2018-09-07 15:21:15 -04:00
|
|
|
port_byte_out(I86_PIC2_REG_COMMAND, I86_PIC_OCW2_MASK_EOI);
|
2018-09-07 13:49:25 -04:00
|
|
|
}
|
|
|
|
|
// Send reset signal to master. (As well as slave, if necessary).
|
2018-09-07 15:21:15 -04:00
|
|
|
port_byte_out(I86_PIC1_REG_COMMAND, I86_PIC_OCW2_MASK_EOI);
|
2018-09-07 00:32:45 -04:00
|
|
|
}
|