diff options
author | 2017-06-30 13:12:19 -0500 | |
---|---|---|
committer | 2017-06-30 13:12:19 -0500 | |
commit | 37fe84a083a7906f163b4d47524431be9baae2e0 (patch) | |
tree | b24101c4c8a53debd46f72ed5d08cd8c2e48eee5 | |
parent | a2af5e27d0aeb3c507a1193b74dae24da2c17bda (diff) | |
parent | cfe8c2aad28327b3698dc02abe70b10ddc25b05c (diff) | |
download | cortex-m-37fe84a083a7906f163b4d47524431be9baae2e0.tar.gz cortex-m-37fe84a083a7906f163b4d47524431be9baae2e0.tar.zst cortex-m-37fe84a083a7906f163b4d47524431be9baae2e0.zip |
Merge pull request #19 from japaric/panic
[RFC] default panic! to abort, drop panic-* features, add panic_fmt! macro
-rw-r--r-- | cortex-m-rt/Cargo.toml | 12 | ||||
-rw-r--r-- | cortex-m-rt/src/lang_items.rs | 35 | ||||
-rw-r--r-- | cortex-m-rt/src/lib.rs | 11 |
3 files changed, 12 insertions, 46 deletions
diff --git a/cortex-m-rt/Cargo.toml b/cortex-m-rt/Cargo.toml index 0b24d79..fc1c181 100644 --- a/cortex-m-rt/Cargo.toml +++ b/cortex-m-rt/Cargo.toml @@ -7,7 +7,7 @@ keywords = ["arm", "cortex-m", "runtime", "startup"] license = "MIT OR Apache-2.0" name = "cortex-m-rt" repository = "https://github.com/japaric/cortex-m-rt" -version = "0.2.4" +version = "0.3.0" [dependencies] r0 = "0.2.1" @@ -16,17 +16,11 @@ r0 = "0.2.1" optional = true version = "0.2.7" -[dependencies.cortex-m-semihosting] -optional = true -version = "0.1.3" - [features] default = ["exceptions", "linker-script"] # service all exceptions using the default handler exceptions = ["cortex-m"] # generic linker script linker-script = [] -# prints panic messages to the ITM -panic-over-itm = ["cortex-m"] -# prints panic messages to the host stdout -panic-over-semihosting = ["cortex-m-semihosting"] +# provides a panic_fmt implementation that calls the abort instruction (`udf 0xfe`) +abort-on-panic = []
\ No newline at end of file diff --git a/cortex-m-rt/src/lang_items.rs b/cortex-m-rt/src/lang_items.rs index 7b3fa9d..236b2bd 100644 --- a/cortex-m-rt/src/lang_items.rs +++ b/cortex-m-rt/src/lang_items.rs @@ -1,37 +1,12 @@ /// Default panic handler +#[cfg(feature = "abort-on-panic")] #[lang = "panic_fmt"] -#[linkage = "weak"] unsafe extern "C" fn panic_fmt( - _args: ::core::fmt::Arguments, - _file: &'static str, - _line: u32, + _: ::core::fmt::Arguments, + _: &'static str, + _: u32, ) -> ! { - match () { - #[cfg(feature = "panic-over-itm")] - () => { - use cortex_m::itm; - use cortex_m::peripheral::ITM; - - let port = &(*ITM.get()).stim[0]; - iprint!(port, "panicked at '"); - itm::write_fmt(port, _args); - iprintln!(port, "', {}:{}", _file, _line); - } - #[cfg(feature = "panic-over-semihosting")] - () => { - hprint!("panicked at '"); - ::cortex_m_semihosting::io::write_fmt(_args); - hprintln!("', {}:{}", _file, _line); - } - #[cfg(not(any(feature = "panic-over-itm", - feature = "panic-over-semihosting")))] - () => {} - } - - #[cfg(target_arch = "arm")] - asm!("bkpt" :::: "volatile"); - - loop {} + ::core::intrinsics::abort() } /// Lang item required to make the normal `main` work in applications diff --git a/cortex-m-rt/src/lib.rs b/cortex-m-rt/src/lib.rs index fa87e6f..4e10b59 100644 --- a/cortex-m-rt/src/lib.rs +++ b/cortex-m-rt/src/lib.rs @@ -145,6 +145,7 @@ //! 8000404: b084 sub sp, #16 //! ``` +#![cfg_attr(feature = "abort-on-panic", feature(core_intrinsics))] #![deny(missing_docs)] #![deny(warnings)] #![feature(asm)] @@ -154,13 +155,9 @@ #![feature(used)] #![no_std] -#[cfg(any(feature = "panic-over-itm", feature = "exceptions"))] -#[cfg_attr(feature = "panic-over-itm", macro_use)] +#[cfg(feature = "exceptions")] extern crate cortex_m; extern crate compiler_builtins; -#[cfg(feature = "panic-over-semihosting")] -#[macro_use] -extern crate cortex_m_semihosting; extern crate r0; mod lang_items; @@ -189,8 +186,8 @@ extern "C" { /// This is the entry point of all programs #[link_section = ".reset_handler"] unsafe extern "C" fn reset_handler() -> ! { - ::r0::zero_bss(&mut _sbss, &mut _ebss); - ::r0::init_data(&mut _sdata, &mut _edata, &_sidata); + r0::zero_bss(&mut _sbss, &mut _ebss); + r0::init_data(&mut _sdata, &mut _edata, &_sidata); // Neither `argc` or `argv` make sense in bare metal context so we just // stub them |