git: fd3fcf71cced - stable/13 - riscv: Tidy panic messages for exceptions

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Tue, 24 Oct 2023 19:00:30 UTC
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=fd3fcf71ccedfd0b2614f6d93632f8dd35648a77

commit fd3fcf71ccedfd0b2614f6d93632f8dd35648a77
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2023-10-11 21:21:12 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-10-24 18:37:53 +0000

    riscv: Tidy panic messages for exceptions
    
    - Remove trailing newlines
    
    - Be consistent about the format used to print pointer values
    
    - Print the trap value for access faults (it is the faulting address
      if non-zero) and illegal instructions (it is the first N bytes of
      the decoded instruction if non-zero)
    
    Reviewed by:    markj
    Sponsored by:   DARPA
    Differential Revision:  https://reviews.freebsd.org/D41786
    
    (cherry picked from commit ff79f35bdae5742f4e56e1dc18fffc5d9ea98876)
---
 sys/riscv/riscv/trap.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/sys/riscv/riscv/trap.c b/sys/riscv/riscv/trap.c
index ecf6b043d606..8c1cd51d4dfa 100644
--- a/sys/riscv/riscv/trap.c
+++ b/sys/riscv/riscv/trap.c
@@ -263,7 +263,7 @@ fatal:
 			return;
 	}
 #endif
-	panic("Fatal page fault at %#lx: %#016lx", frame->tf_sepc, stval);
+	panic("Fatal page fault at %#lx: %#lx", frame->tf_sepc, stval);
 }
 
 void
@@ -290,7 +290,7 @@ do_trap_supervisor(struct trapframe *frame)
 		return;
 #endif
 
-	CTR4(KTR_TRAP, "%s: exception=%lu, sepc=%lx, stval=%lx", __func__,
+	CTR4(KTR_TRAP, "%s: exception=%lu, sepc=%#lx, stval=%#lx", __func__,
 	    exception, frame->tf_sepc, frame->tf_stval);
 
 	switch (exception) {
@@ -298,13 +298,14 @@ do_trap_supervisor(struct trapframe *frame)
 	case SCAUSE_STORE_ACCESS_FAULT:
 	case SCAUSE_INST_ACCESS_FAULT:
 		dump_regs(frame);
-		panic("Memory access exception at 0x%016lx\n", frame->tf_sepc);
+		panic("Memory access exception at %#lx: %#lx",
+		    frame->tf_sepc, frame->tf_stval);
 		break;
 	case SCAUSE_LOAD_MISALIGNED:
 	case SCAUSE_STORE_MISALIGNED:
 	case SCAUSE_INST_MISALIGNED:
 		dump_regs(frame);
-		panic("Misaligned address exception at %#016lx: %#016lx\n",
+		panic("Misaligned address exception at %#lx: %#lx",
 		    frame->tf_sepc, frame->tf_stval);
 		break;
 	case SCAUSE_STORE_PAGE_FAULT:
@@ -322,16 +323,18 @@ do_trap_supervisor(struct trapframe *frame)
 		kdb_trap(exception, 0, frame);
 #else
 		dump_regs(frame);
-		panic("No debugger in kernel.\n");
+		panic("No debugger in kernel.");
 #endif
 		break;
 	case SCAUSE_ILLEGAL_INSTRUCTION:
 		dump_regs(frame);
-		panic("Illegal instruction at 0x%016lx\n", frame->tf_sepc);
+		panic("Illegal instruction 0x%0*lx at %#lx",
+		    (frame->tf_stval & 0x3) != 0x3 ? 4 : 8,
+		    frame->tf_stval, frame->tf_sepc);
 		break;
 	default:
 		dump_regs(frame);
-		panic("Unknown kernel exception %lx trap value %lx\n",
+		panic("Unknown kernel exception %#lx trap value %#lx",
 		    exception, frame->tf_stval);
 	}
 }
@@ -364,7 +367,7 @@ do_trap_user(struct trapframe *frame)
 	}
 	intr_enable();
 
-	CTR4(KTR_TRAP, "%s: exception=%lu, sepc=%lx, stval=%lx", __func__,
+	CTR4(KTR_TRAP, "%s: exception=%lu, sepc=%#lx, stval=%#lx", __func__,
 	    exception, frame->tf_sepc, frame->tf_stval);
 
 	switch (exception) {
@@ -416,7 +419,7 @@ do_trap_user(struct trapframe *frame)
 		break;
 	default:
 		dump_regs(frame);
-		panic("Unknown userland exception %lx, trap value %lx\n",
+		panic("Unknown userland exception %#lx, trap value %#lx",
 		    exception, frame->tf_stval);
 	}
 }