swissChili | aed6ff3 | 2021-05-29 17:51:04 -0700 | [diff] [blame] | 1 | #include "pic.h" |
| 2 | #include <log.h> |
| 3 | |
| 4 | #define DECLARE_INTERRUPT(sym, name) \ |
| 5 | static void sym##_h(struct registers *regs) \ |
| 6 | { \ |
swissChili | 9bd74de | 2021-06-15 20:30:48 -0700 | [diff] [blame] | 7 | kprintf(ERROR "Fault " name ": eip = 0x%x, err = 0x%x\n", regs->eip, \ |
swissChili | aed6ff3 | 2021-05-29 17:51:04 -0700 | [diff] [blame] | 8 | 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 | |
| 15 | DECLARE_INTERRUPT(gp, "#GP") |
| 16 | DECLARE_INTERRUPT(pf, "#PF") |
| 17 | |
| 18 | void init_faults() |
| 19 | { |
| 20 | ADD_INTERRUPT(gp, 13); |
| 21 | ADD_INTERRUPT(pf, 14); |
| 22 | } |