mirror of https://github.com/tailix/kernel.git
Fix hardware interrupts
This commit is contained in:
parent
d625623625
commit
9e55308d5f
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue