summaryrefslogtreecommitdiff
path: root/src/kernel/arch/amd64/interrupts/isr.c
blob: 17dce6e727162b09e183260beb6fcbb4b4a1edfd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#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/port_io.h>
#include <kernel/arch/amd64/time.h>
#include <kernel/arch/generic.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
#include <stdbool.h>
#include <stdint.h>

bool isr_test_interrupt_called = false;

static void log_interrupt(int interrupt, uint64_t *stackframe) {
	kprintf("interrupt %x, rip = k/%08x, cs 0x%x, code 0x%x\n",
			interrupt, stackframe[0], stackframe[1], stackframe[-1]);
	if (interrupt == 0xe) {
		uint64_t addr = 0x69;
		asm("mov %%cr2, %0" : "=r"(addr));
		kprintf("addr 0x%x\n", addr);
	}
}

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);
			return;

		case IRQ_IBASE + IRQ_RTL8139:
			rtl8139_irq();
			irq_eoi(interrupt - IRQ_IBASE);
			return;

		default:
			if ((stackframe[1] & 0x3) == 0) {
				log_interrupt(interrupt, stackframe);
				cpu_halt();
			} else {
				process_kill(process_current, interrupt);
				process_switch_any();
			}
	}
}