From c586035caacbc55302821140bb43d3e5e937d24f Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 14 Mar 2017 09:02:28 +0000 Subject: [PATCH] runtime: add an option to reboot after a panic. --- artiq/firmware/libboard/{hotswap.rs => boot.rs} | 12 +++++++++++- artiq/firmware/libboard/lib.rs | 2 +- artiq/firmware/libboard/uart_console.rs | 7 ------- artiq/firmware/runtime/lib.rs | 15 ++++++++++++++- artiq/firmware/runtime/session.rs | 2 +- 5 files changed, 27 insertions(+), 11 deletions(-) rename artiq/firmware/libboard/{hotswap.rs => boot.rs} (76%) diff --git a/artiq/firmware/libboard/hotswap.rs b/artiq/firmware/libboard/boot.rs similarity index 76% rename from artiq/firmware/libboard/hotswap.rs rename to artiq/firmware/libboard/boot.rs index 5fb2fd749..bd54177a0 100644 --- a/artiq/firmware/libboard/hotswap.rs +++ b/artiq/firmware/libboard/boot.rs @@ -1,6 +1,16 @@ use irq; -pub unsafe fn run(new_code: &[u8]) -> ! { +pub unsafe fn reboot() -> ! { + irq::set_ie(false); + #[cfg(target_arch="or1k")] + asm!(r#" + l.j _ftext + l.nop + "# : : : : "volatile"); + loop {} +} + +pub unsafe fn hotswap(new_code: &[u8]) -> ! { irq::set_ie(false); #[cfg(target_arch="or1k")] asm!(r#" diff --git a/artiq/firmware/libboard/lib.rs b/artiq/firmware/libboard/lib.rs index 499e4b0e1..3c1f3cac8 100644 --- a/artiq/firmware/libboard/lib.rs +++ b/artiq/firmware/libboard/lib.rs @@ -35,7 +35,7 @@ mod ad9154_reg; #[cfg(has_ad9154)] pub mod ad9154; -pub mod hotswap; +pub mod boot; #[cfg(feature = "uart_console")] pub use uart_console::Console; diff --git a/artiq/firmware/libboard/uart_console.rs b/artiq/firmware/libboard/uart_console.rs index dcd79ff33..5a1c82f7c 100644 --- a/artiq/firmware/libboard/uart_console.rs +++ b/artiq/firmware/libboard/uart_console.rs @@ -28,10 +28,3 @@ macro_rules! println { ($fmt:expr) => (print!(concat!($fmt, "\n"))); ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); } - -#[no_mangle] -#[lang = "panic_fmt"] -pub extern fn panic_fmt(args: fmt::Arguments, file: &'static str, line: u32) -> ! { - println!("panic at {}:{}: {}", file, line, args); - loop {} -} diff --git a/artiq/firmware/runtime/lib.rs b/artiq/firmware/runtime/lib.rs index 61e52920e..f92b3c666 100644 --- a/artiq/firmware/runtime/lib.rs +++ b/artiq/firmware/runtime/lib.rs @@ -1,5 +1,5 @@ #![no_std] -#![feature(compiler_builtins_lib, repr_simd, const_fn)] +#![feature(compiler_builtins_lib, repr_simd, lang_items, const_fn)] extern crate compiler_builtins; extern crate cslice; @@ -169,6 +169,19 @@ pub extern fn abort() { panic!("aborted") } +#[no_mangle] +#[lang = "panic_fmt"] +pub extern fn panic_fmt(args: core::fmt::Arguments, file: &'static str, line: u32) -> ! { + println!("panic at {}:{}: {}", file, line, args); + + if config::read_str("panic_reboot", |r| r == Ok("1")) { + println!("rebooting..."); + unsafe { board::boot::reboot() } + } else { + loop {} + } +} + // Allow linking with crates that are built as -Cpanic=unwind even if we use -Cpanic=abort. // This is never called. #[allow(non_snake_case)] diff --git a/artiq/firmware/runtime/session.rs b/artiq/firmware/runtime/session.rs index 00cfb7eb7..2e33275f6 100644 --- a/artiq/firmware/runtime/session.rs +++ b/artiq/firmware/runtime/session.rs @@ -274,7 +274,7 @@ fn process_host_message(io: &Io, host_write(stream, host::Reply::HotswapImminent)?; stream.close()?; warn!("hotswapping firmware"); - unsafe { board::hotswap::run(&binary) } + unsafe { board::boot::hotswap(&binary) } } // artiq_run/artiq_master