summaryrefslogtreecommitdiff
path: root/src/kernel/arch/amd64/interrupts/isr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/arch/amd64/interrupts/isr.c')
-rw-r--r--src/kernel/arch/amd64/interrupts/isr.c63
1 files changed, 20 insertions, 43 deletions
diff --git a/src/kernel/arch/amd64/interrupts/isr.c b/src/kernel/arch/amd64/interrupts/isr.c
index 1059530..ff00f2f 100644
--- a/src/kernel/arch/amd64/interrupts/isr.c
+++ b/src/kernel/arch/amd64/interrupts/isr.c
@@ -1,21 +1,15 @@
-#include <kernel/arch/amd64/driver/ps2.h>
-#include <kernel/arch/amd64/driver/rtl8139.h>
-#include <kernel/arch/amd64/driver/serial.h>
-#include <kernel/arch/amd64/interrupts/irq.h>
-#include <kernel/arch/amd64/interrupts/isr.h>
+#include <kernel/arch/amd64/interrupts.h>
#include <kernel/arch/amd64/port_io.h>
-#include <kernel/arch/amd64/time.h>
#include <kernel/arch/generic.h>
-#include <kernel/mem/alloc.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
#include <stdbool.h>
#include <stdint.h>
-bool isr_test_interrupt_called = false;
+void (*irq_fn[16])(void) = {0};
static void log_interrupt(int interrupt, uint64_t *stackframe) {
- kprintf("interrupt %x, rip = k/%08x, cs 0x%x, code 0x%x\n",
+ kprintf("interrupt %d, rip = k/%08x, cs 0x%x, code 0x%x\n",
interrupt, stackframe[0], stackframe[1], stackframe[-1]);
if ((stackframe[1] & 0x3) == 0) {
uint64_t *stack = (void*)stackframe[3];
@@ -28,42 +22,25 @@ static void log_interrupt(int interrupt, uint64_t *stackframe) {
}
}
-void isr_stage3(int interrupt, uint64_t *stackframe) {
- if (interrupt == 0xe || interrupt == 0xd) stackframe++;
- switch (interrupt) {
- case 0x34:
- isr_test_interrupt_called = true;
- return;
-
- case IRQ_IBASE + IRQ_PIT:
- pit_irq();
- irq_eoi(IRQ_PIT);
- return;
-
- case IRQ_IBASE + IRQ_PS2KB:
- case IRQ_IBASE + IRQ_PS2MOUSE:
- ps2_irq();
- irq_eoi(interrupt - IRQ_IBASE);
- return;
-
- case IRQ_IBASE + IRQ_COM1:
- serial_irq();
- irq_eoi(IRQ_COM1);
+void isr_stage3(uint8_t interrupt, uint64_t *stackframe) {
+ uint8_t irqn = interrupt - IRQ_IBASE;
+ if (irqn < 16) {
+ if (irq_fn[irqn]) {
+ irq_fn[irqn]();
+ irq_eoi(irqn);
return;
+ }
+ }
- case IRQ_IBASE + IRQ_RTL8139:
- rtl8139_irq();
- irq_eoi(interrupt - IRQ_IBASE);
- return;
+ if (interrupt == 0xe || interrupt == 0xd) {
+ stackframe++;
+ }
- default:
- if ((stackframe[1] & 0x3) == 0) {
- // mem_debugprint();
- log_interrupt(interrupt, stackframe);
- cpu_halt();
- } else {
- proc_kill(proc_cur, interrupt);
- proc_switch_any();
- }
+ if ((stackframe[1] & 0x3) == 0) { /* in kernel */
+ log_interrupt(interrupt, stackframe);
+ cpu_halt();
+ } else { /* in user */
+ proc_kill(proc_cur, interrupt);
+ proc_switch_any();
}
}