Fix reversed interrupt vector name
[viridis.git] / kernel / irq.c
1 /* vim: set ts=4 sw=4 sts=4 et : */
2
3 #include <kernel.h>
4 #include <apic.h>
5
6 #include <asm/regs.h>
7
8 #define NAMED_EXCEPTIONS 20
9
10 char *exception_names[NAMED_EXCEPTIONS] = {
11     "Divide by Zero",
12     "Debug",
13     "NMI",
14     "Breakpoint",
15     "Overflow",
16     "Bound",
17     "Illegal Instruction",
18     "FPU Unavailable",
19     "Double Fault",
20     "RESERVED",
21     "Invalid TSS",
22     "Segment Not Present",
23     "Stack",
24     "General Protection",
25     "Page Fault",
26     "RESERVED",
27     "FPU Error",
28     "Alignment Check",
29     "Machine Check",
30     "SIMD Error"
31 };
32
33 void dump_exception(struct regs *regs)
34 {
35     if (regs->vector == 15)
36         printk("Spurious interrupt\n");
37     else if (regs->vector < 32) {
38         if (regs->vector < NAMED_EXCEPTIONS)
39             printk("-- %s (%d) --\n", exception_names[regs->vector], regs->vector);
40         else
41             printk("-- IRQ %d --\n", regs->vector);
42
43         printk("RIP 0x%016ulx ERR 0x%ulx\n", regs->rip, regs->error_code);
44         printk("RSP 0x%016ulx RBP 0x%016ulx\n", regs->rsp, regs->rbp);
45         printk("RAX 0x%016ulx RBX 0x%016ulx\n", regs->rax, regs->rbx);
46         printk("RCX 0x%016ulx RDX 0x%016ulx\n", regs->rcx, regs->rdx);
47         printk("RDI 0x%016ulx RSI 0x%016ulx\n", regs->rdi, regs->rsi);
48         printk("R8  0x%016ulx R9  0x%016ulx\n", regs->r8, regs->r9);
49         printk("R10 0x%016ulx R11 0x%016ulx\n", regs->r10, regs->r11);
50         printk("R12 0x%016ulx R13 0x%016ulx\n", regs->r12, regs->r13);
51         printk("R14 0x%016ulx R15 0x%016ulx\n", regs->r14, regs->r15);
52         printk("CR2 0x%016ulx\n", get_cr2());
53         printk("RFLAGS 0x%016ulx\n", regs->rflags);
54
55         while (1) ;
56     } else if (regs->vector > 32)
57         printk("IRQ %d\n", regs->vector);
58
59     apic->eoi();
60 }