From 6d3164a9128d6896777f8e60a250229483b9b2df Mon Sep 17 00:00:00 2001 From: occheung Date: Fri, 8 Oct 2021 14:41:01 +0800 Subject: [PATCH] riscv: print mtval on panic --- artiq/firmware/bootloader/main.rs | 5 +++-- artiq/firmware/ksupport/lib.rs | 3 ++- artiq/firmware/runtime/main.rs | 5 +++-- artiq/firmware/satman/main.rs | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/artiq/firmware/bootloader/main.rs b/artiq/firmware/bootloader/main.rs index 1ef7426a1..9a41bdb4b 100644 --- a/artiq/firmware/bootloader/main.rs +++ b/artiq/firmware/bootloader/main.rs @@ -17,7 +17,7 @@ use board_misoc::slave_fpga; #[cfg(has_ethmac)] use board_misoc::{clock, ethmac, net_settings}; use board_misoc::uart_console::Console; -use riscv::register::{mcause, mepc}; +use riscv::register::{mcause, mepc, mtval}; fn check_integrity() -> bool { extern { @@ -522,7 +522,8 @@ pub extern fn main() -> i32 { pub extern fn exception(_regs: *const u32) { let pc = mepc::read(); let cause = mcause::read().cause(); - panic!("{:?} at PC {:#08x}", cause, u32::try_from(pc).unwrap()) + let mtval = mtval::read(); + panic!("{:?} at PC {:#08x}, trap value {:#08x}", cause, u32::try_from(pc).unwrap(), mtval); } #[no_mangle] diff --git a/artiq/firmware/ksupport/lib.rs b/artiq/firmware/ksupport/lib.rs index f4a0ec2c7..d915d7e81 100644 --- a/artiq/firmware/ksupport/lib.rs +++ b/artiq/firmware/ksupport/lib.rs @@ -532,7 +532,8 @@ pub unsafe fn main() { pub extern fn exception(_regs: *const u32) { let pc = mepc::read(); let cause = mcause::read().cause(); - panic!("{:?} at PC {:#08x}", cause, u32::try_from(pc).unwrap()) + let mtval = mtval::read(); + panic!("{:?} at PC {:#08x}, trap value {:#08x}", cause, u32::try_from(pc).unwrap(), mtval); } #[no_mangle] diff --git a/artiq/firmware/runtime/main.rs b/artiq/firmware/runtime/main.rs index 04af01be0..45fb76f91 100644 --- a/artiq/firmware/runtime/main.rs +++ b/artiq/firmware/runtime/main.rs @@ -40,7 +40,7 @@ use proto_artiq::{mgmt_proto, moninj_proto, rpc_proto, session_proto, kernel_pro #[cfg(has_rtio_analyzer)] use proto_artiq::analyzer_proto; -use riscv::register::{mcause, mepc}; +use riscv::register::{mcause, mepc, mtval}; mod rtio_clocking; mod rtio_mgt; @@ -319,7 +319,8 @@ pub extern fn exception(regs: *const TrapFrame) { } hexdump(u32::try_from(pc).unwrap()); - panic!("exception {:?} at PC 0x{:x}", e, u32::try_from(pc).unwrap()) + let mtval = mtval::read(); + panic!("exception {:?} at PC 0x{:x}, trap value 0x{:x}", e, u32::try_from(pc).unwrap(), mtval) } } } diff --git a/artiq/firmware/satman/main.rs b/artiq/firmware/satman/main.rs index ef639b7f1..e0ec83612 100644 --- a/artiq/firmware/satman/main.rs +++ b/artiq/firmware/satman/main.rs @@ -18,7 +18,7 @@ use board_artiq::{spi, drtioaux}; use board_artiq::drtio_routing; #[cfg(has_hmc830_7043)] use board_artiq::hmc830_7043; -use riscv::register::{mcause, mepc}; +use riscv::register::{mcause, mepc, mtval}; mod repeater; #[cfg(has_jdcg)] @@ -670,7 +670,8 @@ pub extern fn exception(_regs: *const u32) { } hexdump(u32::try_from(pc).unwrap()); - panic!("exception {:?} at PC 0x{:x}", cause, u32::try_from(pc).unwrap()) + let mtval = mtval::read(); + panic!("exception {:?} at PC 0x{:x}, trap value 0x{:x}", cause, u32::try_from(pc).unwrap(), mtval) } #[no_mangle]