From a23c557e5e3cefa64a2406878cf62c566260d9c4 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 16 Jul 2020 16:24:27 +0800 Subject: [PATCH 1/2] runtime/panic: prevent nested panic and added core ID in panic msg. --- src/runtime/src/panic.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/runtime/src/panic.rs b/src/runtime/src/panic.rs index ab9b8d2..a972be1 100644 --- a/src/runtime/src/panic.rs +++ b/src/runtime/src/panic.rs @@ -1,8 +1,21 @@ use libboard_zynq::{print, println}; +use libregister::RegisterR; +use libcortex_a9::regs::MPIDR; use unwind::backtrace; +static mut PANICKED: [bool; 2] = [false; 2]; + #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { + let id = MPIDR.read().cpu_id() as usize; + print!("Core {} ", id); + unsafe { + if PANICKED[id] { + println!("nested panic!"); + loop {} + } + PANICKED[id] = true; + } print!("panic at "); if let Some(location) = info.location() { print!("{}:{}:{}", location.file(), location.line(), location.column()); -- 2.44.1 From 9e7404b9ab8d45b227012630df2a283523d145b6 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 16 Jul 2020 16:25:26 +0800 Subject: [PATCH 2/2] kernel: added error message after uncaught exception --- src/runtime/src/kernel/core1.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/runtime/src/kernel/core1.rs b/src/runtime/src/kernel/core1.rs index e1b7884..41f18f0 100644 --- a/src/runtime/src/kernel/core1.rs +++ b/src/runtime/src/kernel/core1.rs @@ -189,5 +189,7 @@ pub fn terminate(exception: &'static eh_artiq::Exception<'static>, backtrace: &' let core1_tx: &mut sync_channel::Sender = unsafe { mem::transmute(KERNEL_CHANNEL_1TO0) }; core1_tx.send(Message::KernelException(exception, &backtrace[..cursor])); + // TODO: remove after implementing graceful kernel termination. + error!("Core1 uncaught exception"); loop {} } -- 2.44.1