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 | |
swissChili | 14d0b84 | 2023-01-01 02:22:44 -0500 | [diff] [blame] | 15 | DECLARE_INTERRUPT(gp, "#GP"); |
| 16 | |
| 17 | static 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 | } |
swissChili | aed6ff3 | 2021-05-29 17:51:04 -0700 | [diff] [blame] | 31 | |
| 32 | void init_faults() |
| 33 | { |
| 34 | ADD_INTERRUPT(gp, 13); |
| 35 | ADD_INTERRUPT(pf, 14); |
| 36 | } |