diff options
| author | Ian Moffett <ian@osmora.org> | 2025-11-19 01:02:33 -0500 |
|---|---|---|
| committer | Ian Moffett <ian@osmora.org> | 2025-11-19 01:02:33 -0500 |
| commit | 860ac5d5d1c047bd388aed8ac9c0570a118a5034 (patch) | |
| tree | bdcec6605bfb4f0e4f3db2cb8cfae57fb4749939 /sys | |
| parent | 298e9130c6c57706453e401975b36461e970460b (diff) | |
kern/amd64+mu: panic: Dump registers on panicdev
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/arch/amd64/os/os_panic.c | 85 | ||||
| -rw-r--r-- | sys/inc/mu/panic.h | 6 | ||||
| -rw-r--r-- | sys/kern/kern_panic.c | 7 |
3 files changed, 95 insertions, 3 deletions
diff --git a/sys/arch/amd64/os/os_panic.c b/sys/arch/amd64/os/os_panic.c index ecad944..2215ec6 100644 --- a/sys/arch/amd64/os/os_panic.c +++ b/sys/arch/amd64/os/os_panic.c @@ -28,8 +28,93 @@ */ #include <sys/types.h> +#include <sys/cdefs.h> +#include <os/trace.h> #include <mu/panic.h> +/* + * XXX: We could implement panic() as an assembly stub + * that takes a register snapshot and passes it to + * an MI routine which calls into the MD side using + * it as an argument, that could be better... + */ +void +mu_panic_dump(void) +{ + static uint64_t cr4, cr3, cr2, cr0; + static uint64_t rax, rbx, rcx, rdx; + static uint64_t r[16], rbp, rsp; + + __asmv( + "mov %%cr4, %0\n\t" + "mov %%cr3, %1\n\t" + "mov %%cr2, %2\n\t" + "mov %%cr0, %3" + : "=r" (cr4), + "=r" (cr3), + "=r" (cr2), + "=r" (cr0) + : + : "memory" + ); + + __asmv( + "mov %%r8, %0\n\t" + "mov %%r9, %1\n\t" + "mov %%r10, %2\n\t" + "mov %%r11, %3\n\t" + "mov %%r12, %4\n\t" + "mov %%r13, %5\n\t" + "mov %%r14, %6\n\t" + "mov %%r15, %7\n\t" + "mov %%rax, %8\n\t" + "mov %%rbx, %8\n\t" + "mov %%rcx, %9\n\t" + "mov %%rdx, %10\n\t" + "mov %%rbp, %11\n\t" + "mov %%rsp, %12" + : "=r" (r[0]), + "=r" (r[1]), + "=r" (r[2]), + "=r" (r[3]), + "=r" (r[4]), + "=r" (r[5]), + "=r" (r[6]), + "=r" (r[7]), + "=r" (rax), + "=r" (rbx), + "=r" (rcx), + "=r" (rdx), + "=r" (rbp), + "=r" (rsp) + : + : "memory" + ); + + trace( + "CR0=%p CR2=%p\nCR3=%p CR4=%p\n", + cr0, cr2, cr3, cr4 + ); + + trace( + "---------------------------------------------\n" + "RAX=%p RBX=%p\nRCX=%p RDX=%p\n" + "RBP=%p RSP=%p\n", + rax, rbx, rcx, rdx, + rbp, rsp + ); + + trace( + "---------------------------------------------\n" + "R15=%p R14=%p\nR13=%p R12=%p\nR11=%p R10=%p\n" + "R9=%p R8=%p", + r[7], r[6], r[5], + r[4], r[3], r[2], + r[1], r[0] + ); + +} + void mu_panic_hcf(void) { diff --git a/sys/inc/mu/panic.h b/sys/inc/mu/panic.h index 310e657..c96e844 100644 --- a/sys/inc/mu/panic.h +++ b/sys/inc/mu/panic.h @@ -33,6 +33,12 @@ #include <sys/types.h> /* + * Used internally by the panic function to dump + * internal machine state. + */ +void mu_panic_dump(void); + +/* * Used internally by the panic function and implemented * per architecture to bring the system to a halt. */ diff --git a/sys/kern/kern_panic.c b/sys/kern/kern_panic.c index af30e7b..64660e8 100644 --- a/sys/kern/kern_panic.c +++ b/sys/kern/kern_panic.c @@ -28,9 +28,9 @@ */ #include <kern/panic.h> -#include <kern/serial.h> #include <mu/panic.h> #include <mu/spinlock.h> +#include <os/trace.h> #include <lib/string.h> #include <lib/stdarg.h> #include <lib/stdbool.h> @@ -48,9 +48,10 @@ panic(const char *fmt, ...) va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); - serial_write("panic: ", 7); - serial_write(buf, strlen(buf)); + trace("panic: "); + trace(buf); + mu_panic_dump(); mu_panic_hcf(); __builtin_unreachable(); } |
