Skip to content

Commit 37fe84a

Browse files
authored
Merge pull request #19 from japaric/panic
[RFC] default panic! to abort, drop panic-* features, add panic_fmt! macro
2 parents a2af5e2 + cfe8c2a commit 37fe84a

File tree

3 files changed

+12
-46
lines changed

3 files changed

+12
-46
lines changed

cortex-m-rt/Cargo.toml

+3-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ keywords = ["arm", "cortex-m", "runtime", "startup"]
77
license = "MIT OR Apache-2.0"
88
name = "cortex-m-rt"
99
repository = "https://github.com/japaric/cortex-m-rt"
10-
version = "0.2.4"
10+
version = "0.3.0"
1111

1212
[dependencies]
1313
r0 = "0.2.1"
@@ -16,17 +16,11 @@ r0 = "0.2.1"
1616
optional = true
1717
version = "0.2.7"
1818

19-
[dependencies.cortex-m-semihosting]
20-
optional = true
21-
version = "0.1.3"
22-
2319
[features]
2420
default = ["exceptions", "linker-script"]
2521
# service all exceptions using the default handler
2622
exceptions = ["cortex-m"]
2723
# generic linker script
2824
linker-script = []
29-
# prints panic messages to the ITM
30-
panic-over-itm = ["cortex-m"]
31-
# prints panic messages to the host stdout
32-
panic-over-semihosting = ["cortex-m-semihosting"]
25+
# provides a panic_fmt implementation that calls the abort instruction (`udf 0xfe`)
26+
abort-on-panic = []

cortex-m-rt/src/lang_items.rs

+5-30
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,12 @@
11
/// Default panic handler
2+
#[cfg(feature = "abort-on-panic")]
23
#[lang = "panic_fmt"]
3-
#[linkage = "weak"]
44
unsafe extern "C" fn panic_fmt(
5-
_args: ::core::fmt::Arguments,
6-
_file: &'static str,
7-
_line: u32,
5+
_: ::core::fmt::Arguments,
6+
_: &'static str,
7+
_: u32,
88
) -> ! {
9-
match () {
10-
#[cfg(feature = "panic-over-itm")]
11-
() => {
12-
use cortex_m::itm;
13-
use cortex_m::peripheral::ITM;
14-
15-
let port = &(*ITM.get()).stim[0];
16-
iprint!(port, "panicked at '");
17-
itm::write_fmt(port, _args);
18-
iprintln!(port, "', {}:{}", _file, _line);
19-
}
20-
#[cfg(feature = "panic-over-semihosting")]
21-
() => {
22-
hprint!("panicked at '");
23-
::cortex_m_semihosting::io::write_fmt(_args);
24-
hprintln!("', {}:{}", _file, _line);
25-
}
26-
#[cfg(not(any(feature = "panic-over-itm",
27-
feature = "panic-over-semihosting")))]
28-
() => {}
29-
}
30-
31-
#[cfg(target_arch = "arm")]
32-
asm!("bkpt" :::: "volatile");
33-
34-
loop {}
9+
::core::intrinsics::abort()
3510
}
3611

3712
/// Lang item required to make the normal `main` work in applications

cortex-m-rt/src/lib.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
//! 8000404: b084 sub sp, #16
146146
//! ```
147147
148+
#![cfg_attr(feature = "abort-on-panic", feature(core_intrinsics))]
148149
#![deny(missing_docs)]
149150
#![deny(warnings)]
150151
#![feature(asm)]
@@ -154,13 +155,9 @@
154155
#![feature(used)]
155156
#![no_std]
156157

157-
#[cfg(any(feature = "panic-over-itm", feature = "exceptions"))]
158-
#[cfg_attr(feature = "panic-over-itm", macro_use)]
158+
#[cfg(feature = "exceptions")]
159159
extern crate cortex_m;
160160
extern crate compiler_builtins;
161-
#[cfg(feature = "panic-over-semihosting")]
162-
#[macro_use]
163-
extern crate cortex_m_semihosting;
164161
extern crate r0;
165162

166163
mod lang_items;
@@ -189,8 +186,8 @@ extern "C" {
189186
/// This is the entry point of all programs
190187
#[link_section = ".reset_handler"]
191188
unsafe extern "C" fn reset_handler() -> ! {
192-
::r0::zero_bss(&mut _sbss, &mut _ebss);
193-
::r0::init_data(&mut _sdata, &mut _edata, &_sidata);
189+
r0::zero_bss(&mut _sbss, &mut _ebss);
190+
r0::init_data(&mut _sdata, &mut _edata, &_sidata);
194191

195192
// Neither `argc` or `argv` make sense in bare metal context so we just
196193
// stub them

0 commit comments

Comments
 (0)