Skip to content

Commit b4186cf

Browse files
bors[bot]japaric
andcommitted
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 <[email protected]>
2 parents 7865725 + 335856a commit b4186cf

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

cortex-m-rt/link.x.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ PROVIDE(DebugMonitor = DefaultHandler);
4545
PROVIDE(PendSV = DefaultHandler);
4646
PROVIDE(SysTick = DefaultHandler);
4747

48+
PROVIDE(DefaultHandler = DefaultDefaultHandler);
49+
PROVIDE(UserHardFault = DefaultUserHardFault);
50+
4851
/* # Interrupt vectors */
4952
EXTERN(__INTERRUPTS); /* `static` variable similar to `__EXCEPTIONS` */
5053

cortex-m-rt/src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@
390390

391391
extern crate r0;
392392

393-
use core::fmt;
393+
use core::{fmt, ptr};
394394

395395
/// Registers stacked (pushed into the stack) during an exception
396396
#[derive(Clone, Copy)]
@@ -511,6 +511,26 @@ pub unsafe extern "C" fn Reset() -> ! {
511511
}
512512
}
513513

514+
#[doc(hidden)]
515+
#[no_mangle]
516+
pub unsafe extern "C" fn DefaultDefaultHandler() {
517+
loop {
518+
// add some side effect to prevent this from turning into a UDF instruction
519+
// see rust-lang/rust#28728
520+
ptr::read_volatile(&0u8);
521+
}
522+
}
523+
524+
#[doc(hidden)]
525+
#[no_mangle]
526+
pub unsafe extern "C" fn DefaultUserHardFault() {
527+
loop {
528+
// add some side effect to prevent this from turning into a UDF instruction
529+
// see rust-lang/rust#28728
530+
ptr::read_volatile(&0u8);
531+
}
532+
}
533+
514534
/// Macro to define the entry point of the program
515535
///
516536
/// **NOTE** This macro must be invoked once and must be invoked from an accessible module, ideally

0 commit comments

Comments
 (0)