blob: 761558ca669748e55286e3ed8dbf40282e593701 [file] [log] [blame]
swissChiliaed6ff32021-05-29 17:51:04 -07001#include "pic.h"
2#include <log.h>
3
4#define DECLARE_INTERRUPT(sym, name) \
5 static void sym##_h(struct registers *regs) \
6 { \
swissChili9bd74de2021-06-15 20:30:48 -07007 kprintf(ERROR "Fault " name ": eip = 0x%x, err = 0x%x\n", regs->eip, \
swissChiliaed6ff32021-05-29 17:51:04 -07008 regs->error_code); \
9 asm volatile("cli"); \
10 kpanic(name); \
11 }
12
13#define ADD_INTERRUPT(sym, num) add_interrupt_handler(num, sym##_h)
14
swissChili14d0b842023-01-01 02:22:44 -050015DECLARE_INTERRUPT(gp, "#GP");
16
17static void pf_h(struct registers *regs)
18{
19 uint err = regs->error_code;
20
21 kprintf(ERROR "Fault #PF: eip=0x%x, err=0x%x\n", regs->eip, err);
22 kprintf("\tDue to: %c%c%c%c\n",
23 err & 1 ? 'P' : ' ',
24 err & (1<<1) ? 'W' : ' ',
25 err & (1<<2) ? 'U' : ' ',
26 err & (1<<4) ? 'I' : ' ');
27
28 asm("cli");
29 kpanic("#PF");
30}
swissChiliaed6ff32021-05-29 17:51:04 -070031
32void init_faults()
33{
34 ADD_INTERRUPT(gp, 13);
35 ADD_INTERRUPT(pf, 14);
36}