From 6f2e70067b9fd62818117eb2969169d549179ee0 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 20 Feb 2024 00:31:44 -0500 Subject: kernel/amd64: trap: Dump regs upon exception Signed-off-by: Ian Moffett --- sys/arch/amd64/amd64/trap.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'sys/arch/amd64') diff --git a/sys/arch/amd64/amd64/trap.c b/sys/arch/amd64/amd64/trap.c index 85d1058..703b6cf 100644 --- a/sys/arch/amd64/amd64/trap.c +++ b/sys/arch/amd64/amd64/trap.c @@ -63,6 +63,28 @@ trap_print(struct trapframe *tf) kprintf(" in %s mode **\n", mode); } +static void +regdump(struct trapframe *tf) +{ + uintptr_t cr3, cr2; + + __ASMV("mov %%cr2, %0\n" + "mov %%cr3, %1\n" + : "=r" (cr2), "=r" (cr3) + : + : "memory" + ); + + kprintf("RAX=%p RCX=%p RDX=%p\n" + "RBX=%p RSI=%p RDI=%p\n" + "RFL=%p CR2=%p CR3=%p\n" + "RBP=%p RSP=%p RIP=%p\n", + tf->rax, tf->rcx, tf->rdx, + tf->rbx, tf->rsi, tf->rdi, + tf->rflags, cr2, cr3, + tf->rbp, tf->rsp, tf->rip); +} + /* * Handles traps. */ @@ -80,5 +102,6 @@ trap_handler(struct trapframe *tf) panic("Caught NMI; bailing out\n"); } - panic("Caught pre-sched exception @0x%x\n", tf->rip); + regdump(tf); + panic("Caught pre-sched exception\n"); } -- cgit v1.2.3