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 <drivers/console.h>
#include <stddef.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)
{
if (regs.int_no >= INT_HWINT_COUNT) return;
const unsigned char hwint_no = regs.int_no - INT_HWINT_FIRST;
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 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);
}
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) {
return;
}
if (hwint_no >= INT_HWINT_COUNT) return;
handlers[int_no] = handler;
drivers_intel_8259_pic_enable(int_no);
handlers[hwint_no] = handler;
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) {
return;
}
if (hwint_no >= INT_HWINT_COUNT) return;
drivers_intel_8259_pic_disable(int_no);
handlers[int_no] = 0;
drivers_intel_8259_pic_disable(hwint_no);
handlers[hwint_no] = NULL;
}

View File

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