1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2025-02-17 15:45:37 -05:00
kernel/hwint.c

48 lines
965 B
C
Raw Normal View History

2017-11-03 05:10:07 +00:00
#include "hwint.h"
2017-11-05 12:44:57 +00:00
#include "interrupt.h"
2017-11-03 03:14:46 +00:00
#include "config.h"
#include "asm.h"
2017-11-03 02:51:24 +00:00
#include "logger.h"
2017-11-06 10:57:55 +00:00
#include "pic.h"
2017-11-03 02:51:24 +00:00
2017-11-03 05:10:07 +00:00
static hwint_handler_t handlers[INT_HWINT_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2017-11-03 02:51:24 +00:00
void hwint_handler(struct IsrRegisters regs)
{
if (!pic_end_of_interrupt(regs.int_no)) {
2017-11-03 03:14:46 +00:00
return;
}
const unsigned char hwint_no = regs.int_no - INT_HWINT_FIRST;
2017-11-03 05:10:07 +00:00
const hwint_handler_t handler = handlers[hwint_no];
if (!handler) {
2017-11-06 12:19:11 +00:00
logger_warn_from("hwint", "Unhandled hardware interrupt: %u", hwint_no);
2017-11-03 05:10:07 +00:00
return;
}
handler();
}
void hwint_register_handler(unsigned int int_no, hwint_handler_t handler)
{
if (int_no >= INT_HWINT_COUNT) {
return;
}
handlers[int_no] = handler;
pic_enable(int_no);
2017-11-03 02:51:24 +00:00
}
void hwint_unregister_handler(unsigned int int_no)
{
if (int_no >= INT_HWINT_COUNT) {
return;
}
pic_disable(int_no);
handlers[int_no] = 0;
}