Fix hardware interrupts

This commit is contained in:
Alex Kotov 2022-12-08 07:00:31 +04:00
parent d625623625
commit 9e55308d5f
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 19 additions and 25 deletions

View File

@ -1,43 +1,37 @@
#include "main.h" #include "main.h"
#include <drivers/console.h> #include <stddef.h>
#include <drivers/intel_8259_pic.h> #include <drivers/intel_8259_pic.h>
static hwint_handler_t handlers[INT_HWINT_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static hwint_handler_t handlers[INT_HWINT_COUNT] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
};
void hwint_handler(struct IsrRegisters regs) void hwint_handler(struct IsrRegisters regs)
{ {
if (regs.int_no >= INT_HWINT_COUNT) return; if (regs.int_no < INT_HWINT_FIRST || regs.int_no > INT_HWINT_LAST) return;
const unsigned int hwint_no = regs.int_no - INT_HWINT_FIRST;
const unsigned char hwint_no = regs.int_no - INT_HWINT_FIRST;
const hwint_handler_t handler = handlers[hwint_no]; const hwint_handler_t handler = handlers[hwint_no];
if (handler) handler();
if (!handler) {
drivers_console_printf("[WARN] hwint: Unhandled hardware interrupt: %u\n", hwint_no);
return;
}
handler();
drivers_intel_8259_pic_eoi(regs.int_no); drivers_intel_8259_pic_eoi(regs.int_no);
} }
void hwint_register_handler(unsigned int int_no, hwint_handler_t handler) void hwint_register_handler(unsigned int hwint_no, hwint_handler_t handler)
{ {
if (int_no >= INT_HWINT_COUNT) { if (hwint_no >= INT_HWINT_COUNT) return;
return;
}
handlers[int_no] = handler; handlers[hwint_no] = handler;
drivers_intel_8259_pic_enable(int_no); drivers_intel_8259_pic_enable(hwint_no);
} }
void hwint_unregister_handler(unsigned int int_no) void hwint_unregister_handler(unsigned int hwint_no)
{ {
if (int_no >= INT_HWINT_COUNT) { if (hwint_no >= INT_HWINT_COUNT) return;
return;
}
drivers_intel_8259_pic_disable(int_no); drivers_intel_8259_pic_disable(hwint_no);
handlers[int_no] = 0; handlers[hwint_no] = NULL;
} }

View File

@ -73,8 +73,8 @@ void interrupt_0x80();
typedef void(*hwint_handler_t)(); typedef void(*hwint_handler_t)();
void hwint_register_handler(unsigned int int_no, hwint_handler_t handler); void hwint_register_handler(unsigned int hwint_no, hwint_handler_t handler);
void hwint_unregister_handler(unsigned int int_no); void hwint_unregister_handler(unsigned int hwint_no);