artiq-zynq/src/runtime/src/panic.rs

39 lines
1.0 KiB
Rust

use unwind::backtrace;
use libboard_zynq::{slcr, print, println};
static mut PANICKED: bool = false;
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
print!("panic at ");
if let Some(location) = info.location() {
print!("{}:{}:{}", location.file(), location.line(), location.column());
} else {
print!("unknown location");
}
if let Some(message) = info.message() {
println!(": {}", message);
} else {
println!("");
}
if unsafe { PANICKED } {
print!("Panic in panic!");
} else {
unsafe {
PANICKED = true;
}
// read backtrace can trigger panic.
println!("Backtrace:");
let _ = backtrace(|ip| {
// Backtrace gives us the return address, i.e. the address after the delay slot,
// but we're interested in the call instruction.
println!("{:#08x}", ip - 2 * 4);
});
}
slcr::RegisterBlock::unlocked(|slcr| slcr.soft_reset());
loop {}
}