Kernel: fix some of i368 IDT. This was really broken

This commit is contained in:
Bananymous 2023-02-02 15:52:06 +02:00
parent 117d1de038
commit c85b97abee
1 changed files with 8 additions and 17 deletions

View File

@ -74,7 +74,7 @@ namespace IDT
static IDTR s_idtr; static IDTR s_idtr;
static GateDescriptor* s_idt = nullptr; static GateDescriptor* s_idt = nullptr;
static void(**s_irq_handlers)(); static void(*s_irq_handlers[16])() { nullptr };
INTERRUPT_HANDLER____(0x00, "Division Error") INTERRUPT_HANDLER____(0x00, "Division Error")
INTERRUPT_HANDLER____(0x01, "Debug") INTERRUPT_HANDLER____(0x01, "Debug")
@ -111,22 +111,19 @@ namespace IDT
extern "C" void handle_irq() extern "C" void handle_irq()
{ {
uint8_t irq = 0; uint8_t irq;
for (uint32_t i = 0; i <= 0xFF; i++) for (uint32_t i = 0; i < 16; i++)
{ {
if (InterruptController::get().is_in_service(i)) if (InterruptController::get().is_in_service(i))
{ {
irq = i; irq = i;
break; goto found;
} }
} }
if (irq == 0) dprintln("Spurious irq");
{ return;
dprintln("Spurious irq"); found:
return;
}
if (s_irq_handlers[irq]) if (s_irq_handlers[irq])
s_irq_handlers[irq](); s_irq_handlers[irq]();
else else
@ -171,7 +168,7 @@ namespace IDT
void register_irq_handler(uint8_t irq, void(*f)()) void register_irq_handler(uint8_t irq, void(*f)())
{ {
s_irq_handlers[IRQ_VECTOR_BASE + irq] = f; s_irq_handlers[irq] = f;
register_interrupt_handler(IRQ_VECTOR_BASE + irq, handle_irq_common); register_interrupt_handler(IRQ_VECTOR_BASE + irq, handle_irq_common);
flush_idt(); flush_idt();
} }
@ -183,15 +180,9 @@ namespace IDT
s_idt = (GateDescriptor*)kmalloc_eternal(idt_size); s_idt = (GateDescriptor*)kmalloc_eternal(idt_size);
memset(s_idt, 0x00, idt_size); memset(s_idt, 0x00, idt_size);
s_irq_handlers = (void(**)())kmalloc_eternal(0x100 * sizeof(void(*)()));
memset(s_irq_handlers, 0x00, 0x100 * sizeof(void(*)()));
s_idtr.offset = s_idt; s_idtr.offset = s_idt;
s_idtr.size = idt_size - 1; s_idtr.size = idt_size - 1;
for (uint8_t i = 0x00; i <= 0xFF - IRQ_VECTOR_BASE; i++)
register_irq_handler(i, nullptr);
REGISTER_HANDLER(0x00); REGISTER_HANDLER(0x00);
REGISTER_HANDLER(0x01); REGISTER_HANDLER(0x01);
REGISTER_HANDLER(0x02); REGISTER_HANDLER(0x02);