kernel: add panic() function that accepts a cpu_context

This commit is contained in:
2023-05-03 19:22:12 +01:00
parent 390fe86657
commit a52571eb19
3 changed files with 11 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
#include <arch/acpi.h> #include <arch/acpi.h>
#include <socks/printk.h> #include <socks/printk.h>
#include <socks/sched.h> #include <socks/sched.h>
#include <socks/panic.h>
#include <socks/libc/string.h> #include <socks/libc/string.h>
#include <socks/machine/irq.h> #include <socks/machine/irq.h>
#include <socks/machine/cpu.h> #include <socks/machine/cpu.h>
@@ -96,7 +97,7 @@ static void gpf_handler(struct cpu_context *regs)
static void pf_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(); ml_halt_cpu();
} }
@@ -228,6 +229,8 @@ void isr_dispatch(struct cpu_context *regs)
int_hook h = isr_handlers[regs->int_no]; int_hook h = isr_handlers[regs->int_no];
if (h) { if (h) {
h(regs); h(regs);
} else {
panic_irq(regs, "unhandled exception %u", regs->int_no);
} }
} }

View File

@@ -3,6 +3,10 @@
#include <socks/compiler.h> #include <socks/compiler.h>
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 #endif

View File

@@ -7,7 +7,7 @@
static int has_panicked = 0; static int has_panicked = 0;
void panic(const char *fmt, ...) void panic_irq(struct cpu_context *ctx, const char *fmt, ...)
{ {
char buf[512]; char buf[512];
va_list args; va_list args;
@@ -29,7 +29,7 @@ void panic(const char *fmt, ...)
printk("cpu: %u", this_cpu()); printk("cpu: %u", this_cpu());
ml_print_cpu_state(NULL); ml_print_cpu_state(ctx);
if (READ_ONCE(has_panicked)) { if (READ_ONCE(has_panicked)) {
ml_halt_cpu(); ml_halt_cpu();