diff options
author | 2018-08-08 07:02:29 +0000 | |
---|---|---|
committer | 2018-08-08 07:02:29 +0000 | |
commit | b4186cfe5fc9a8e51d73549cddbf0f49db3a49ba (patch) | |
tree | 769033ab47421b56ed6710cff6c5be095b654404 | |
parent | 7865725aacf3c9718902361b9d9919b7bebce7be (diff) | |
parent | 335856a05a9cd4d78b3dd4e2348fdd5702edb9ba (diff) | |
download | cortex-m-b4186cfe5fc9a8e51d73549cddbf0f49db3a49ba.tar.gz cortex-m-b4186cfe5fc9a8e51d73549cddbf0f49db3a49ba.tar.zst cortex-m-b4186cfe5fc9a8e51d73549cddbf0f49db3a49ba.zip |
Merge #85
85: [WIP] provide defaults for DefaultHandler and HardFault r=korken89 a=japaric
`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
--
Annoyances:
- The handlers can't be *just* an infinite loop because of rust-lang/rust#28728.
If we define the handlers as just `loop {}` they will become an abort (UDF)
instruction. And that would turn HardFault into infinite recursion. For that
reason I have made them into an infinite loop that does some side effect
- If you stick to the defaults then the symbol name of the default handler
changes from `DefaultHandler` (override) to `DefaultDefaultHandler` (default).
We can make these two names more similar but I think we can not prevent the
rename. Something similar happens with UserHardFault (which becomes
DefaultUserHardFault when not overridden).
cc @rust-embedded/cortex-m
Co-authored-by: Jorge Aparicio <jorge@japaric.io>
-rw-r--r-- | cortex-m-rt/link.x.in | 3 | ||||
-rw-r--r-- | cortex-m-rt/src/lib.rs | 22 |
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 |