diff --git a/arch/x86_64/irq.c b/arch/x86_64/irq.c index 28594b5..928e9da 100644 --- a/arch/x86_64/irq.c +++ b/arch/x86_64/irq.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -96,7 +97,7 @@ static void gpf_handler(struct cpu_context *regs) static void pf_handler(struct cpu_context *regs) { - printk("page fault (%016llx %016llx %016llx)", pf_faultptr(), regs->rip, regs->err_no); + panic_irq(regs, "page fault (%016llx %016llx %016llx)", pf_faultptr(), regs->rip, regs->err_no); ml_halt_cpu(); } @@ -228,6 +229,8 @@ void isr_dispatch(struct cpu_context *regs) int_hook h = isr_handlers[regs->int_no]; if (h) { h(regs); + } else { + panic_irq(regs, "unhandled exception %u", regs->int_no); } } diff --git a/include/socks/panic.h b/include/socks/panic.h index 3ff7b0a..521d11a 100644 --- a/include/socks/panic.h +++ b/include/socks/panic.h @@ -3,6 +3,10 @@ #include -extern void __noreturn panic(const char *fmt, ...); +struct cpu_context; + +#define panic(...) panic_irq(NULL, __VA_ARGS__) + +extern void __noreturn panic_irq(struct cpu_context *ctx, const char *fmt, ...); #endif diff --git a/kernel/panic.c b/kernel/panic.c index badc4b1..587bca9 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -7,7 +7,7 @@ static int has_panicked = 0; -void panic(const char *fmt, ...) +void panic_irq(struct cpu_context *ctx, const char *fmt, ...) { char buf[512]; va_list args; @@ -29,7 +29,7 @@ void panic(const char *fmt, ...) printk("cpu: %u", this_cpu()); - ml_print_cpu_state(NULL); + ml_print_cpu_state(ctx); if (READ_ONCE(has_panicked)) { ml_halt_cpu();