Skip to content

Commit cfe8c2a

Browse files
committed
opt-in panic_fmt implementation
that just calls intrinsics::abort
1 parent a81bb98 commit cfe8c2a

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

cortex-m-rt/Cargo.toml

Lines changed: 3 additions & 1 deletion
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"
@@ -22,3 +22,5 @@ default = ["exceptions", "linker-script"]
2222
exceptions = ["cortex-m"]
2323
# generic linker script
2424
linker-script = []
25+
# provides a panic_fmt implementation that calls the abort instruction (`udf 0xfe`)
26+
abort-on-panic = []

cortex-m-rt/src/lang_items.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
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
) -> ! {
99
::core::intrinsics::abort()
1010
}
1111

12-
#[macro_export]
13-
macro_rules! panic_fmt {
14-
($f:expr) => {
15-
#[export_name = "rust_begin_unwind"]
16-
pub unsafe extern "C" fn _panic_fmt(
17-
args: ::core::fmt::Arguments,
18-
file: &'static str,
19-
line: u32,
20-
) -> ! {
21-
$f(args, file, line)
22-
}
23-
}
24-
}
25-
2612
/// Lang item required to make the normal `main` work in applications
2713
// This is how the `start` lang item works:
2814
// When `rustc` compiles a binary crate, it creates a `main` function that looks

cortex-m-rt/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@
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)]
151152
#![feature(compiler_builtins_lib)]
152-
#![feature(core_intrinsics)]
153153
#![feature(lang_items)]
154154
#![feature(linkage)]
155155
#![feature(used)]
@@ -186,8 +186,8 @@ extern "C" {
186186
/// This is the entry point of all programs
187187
#[link_section = ".reset_handler"]
188188
unsafe extern "C" fn reset_handler() -> ! {
189-
::r0::zero_bss(&mut _sbss, &mut _ebss);
190-
::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);
191191

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

0 commit comments

Comments
 (0)