aboutsummaryrefslogtreecommitdiff
path: root/cortex-m-rt
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2018-08-07 18:57:41 -0500
committerGravatar Jorge Aparicio <jorge@japaric.io> 2018-08-07 18:59:51 -0500
commit335856a05a9cd4d78b3dd4e2348fdd5702edb9ba (patch)
tree769033ab47421b56ed6710cff6c5be095b654404 /cortex-m-rt
parent7865725aacf3c9718902361b9d9919b7bebce7be (diff)
downloadcortex-m-335856a05a9cd4d78b3dd4e2348fdd5702edb9ba.tar.gz
cortex-m-335856a05a9cd4d78b3dd4e2348fdd5702edb9ba.tar.zst
cortex-m-335856a05a9cd4d78b3dd4e2348fdd5702edb9ba.zip
[WIP] provide defaults for DefaultHandler and HardFault
`exception!(HardFault, ..)` and `exception!(*, ..)` can now be omitted from programs to pick up the default behavior of an infinite loop. Existing programs that define these exception handlers will continue to work w/o any functional change. closes #72
Diffstat (limited to 'cortex-m-rt')
-rw-r--r--cortex-m-rt/link.x.in3
-rw-r--r--cortex-m-rt/src/lib.rs22
2 files changed, 24 insertions, 1 deletions
diff --git a/cortex-m-rt/link.x.in b/cortex-m-rt/link.x.in
index 5df965a..5fa7dbf 100644
--- a/cortex-m-rt/link.x.in
+++ b/cortex-m-rt/link.x.in
@@ -45,6 +45,9 @@ PROVIDE(DebugMonitor = DefaultHandler);
PROVIDE(PendSV = DefaultHandler);
PROVIDE(SysTick = DefaultHandler);
+PROVIDE(DefaultHandler = DefaultDefaultHandler);
+PROVIDE(UserHardFault = DefaultUserHardFault);
+
/* # Interrupt vectors */
EXTERN(__INTERRUPTS); /* `static` variable similar to `__EXCEPTIONS` */
diff --git a/cortex-m-rt/src/lib.rs b/cortex-m-rt/src/lib.rs
index e55171a..60c8034 100644
--- a/cortex-m-rt/src/lib.rs
+++ b/cortex-m-rt/src/lib.rs
@@ -390,7 +390,7 @@
extern crate r0;
-use core::fmt;
+use core::{fmt, ptr};
/// Registers stacked (pushed into the stack) during an exception
#[derive(Clone, Copy)]
@@ -511,6 +511,26 @@ pub unsafe extern "C" fn Reset() -> ! {
}
}
+#[doc(hidden)]
+#[no_mangle]
+pub unsafe extern "C" fn DefaultDefaultHandler() {
+ loop {
+ // add some side effect to prevent this from turning into a UDF instruction
+ // see rust-lang/rust#28728
+ ptr::read_volatile(&0u8);
+ }
+}
+
+#[doc(hidden)]
+#[no_mangle]
+pub unsafe extern "C" fn DefaultUserHardFault() {
+ loop {
+ // add some side effect to prevent this from turning into a UDF instruction
+ // see rust-lang/rust#28728
+ ptr::read_volatile(&0u8);
+ }
+}
+
/// Macro to define the entry point of the program
///
/// **NOTE** This macro must be invoked once and must be invoked from an accessible module, ideally