Skip to content

Commit

Permalink
Merge pull request #19 from japaric/panic
Browse files Browse the repository at this point in the history
[RFC] default panic! to abort, drop panic-* features, add panic_fmt! macro
  • Loading branch information
japaric committed Jun 30, 2017
2 parents a2af5e2 + cfe8c2a commit 37fe84a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 46 deletions.
12 changes: 3 additions & 9 deletions cortex-m-rt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = []
35 changes: 5 additions & 30 deletions cortex-m-rt/src/lang_items.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 4 additions & 7 deletions cortex-m-rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 37fe84a

Please sign in to comment.