2022-06-23 21:31:53 +00:00
|
|
|
#include "main.h"
|
2017-11-03 02:51:24 +00:00
|
|
|
|
2022-06-23 10:51:42 +00:00
|
|
|
#include <kernaux/drivers/console.h>
|
2022-06-23 19:53:28 +00:00
|
|
|
#include <kernaux/drivers/intel_8259_pic.h>
|
2020-12-06 03:04:34 +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)
|
|
|
|
{
|
2022-06-23 19:53:28 +00:00
|
|
|
if (regs.int_no >= INT_HWINT_COUNT) return;
|
2017-11-03 03:14:46 +00:00
|
|
|
|
|
|
|
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) {
|
2022-06-23 10:51:42 +00:00
|
|
|
kernaux_drivers_console_printf("[WARN] hwint: Unhandled hardware interrupt: %u\n", hwint_no);
|
2017-11-03 05:10:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
handler();
|
2022-06-23 19:53:28 +00:00
|
|
|
kernaux_drivers_intel_8259_pic_eoi(regs.int_no);
|
2017-11-03 05:10:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void hwint_register_handler(unsigned int int_no, hwint_handler_t handler)
|
|
|
|
{
|
|
|
|
if (int_no >= INT_HWINT_COUNT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
handlers[int_no] = handler;
|
2022-06-23 19:53:28 +00:00
|
|
|
kernaux_drivers_intel_8259_pic_enable(int_no);
|
2017-11-03 02:51:24 +00:00
|
|
|
}
|
2017-11-06 12:06:28 +00:00
|
|
|
|
|
|
|
void hwint_unregister_handler(unsigned int int_no)
|
|
|
|
{
|
|
|
|
if (int_no >= INT_HWINT_COUNT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-23 19:53:28 +00:00
|
|
|
kernaux_drivers_intel_8259_pic_disable(int_no);
|
2017-11-06 12:06:28 +00:00
|
|
|
handlers[int_no] = 0;
|
|
|
|
}
|