diff options
author | 2018-04-24 20:50:56 +0200 | |
---|---|---|
committer | 2018-04-24 20:50:56 +0200 | |
commit | 857eb6579852b1578bcf9e8743ff9ba4a9276e5b (patch) | |
tree | 49a8b52a0c30455d6740b0fbd432881ab9bff544 /cortex-m-rt | |
parent | 9976eb18cfe753dd388504c7ef54fb0de6a56a02 (diff) | |
download | cortex-m-857eb6579852b1578bcf9e8743ff9ba4a9276e5b.tar.gz cortex-m-857eb6579852b1578bcf9e8743ff9ba4a9276e5b.tar.zst cortex-m-857eb6579852b1578bcf9e8743ff9ba4a9276e5b.zip |
expose exception number to DefaultHandler
Diffstat (limited to 'cortex-m-rt')
-rw-r--r-- | cortex-m-rt/src/lib.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/cortex-m-rt/src/lib.rs b/cortex-m-rt/src/lib.rs index fe2156f..d4486e1 100644 --- a/cortex-m-rt/src/lib.rs +++ b/cortex-m-rt/src/lib.rs @@ -156,30 +156,36 @@ pub static __EXCEPTIONS: [Option<unsafe extern "C" fn()>; 14] = [ /// All exceptions are serviced by the `DefaultHandler` exception handler unless overridden using /// this macro. `ExceptionName` can be one of are: /// -/// - `DefaultHandler` (\*) -/// - `NMI` -/// - `HardFault` -/// - `MemManage` -/// - `BusFault` -/// - `UsageFault` -/// - `SVC` -/// - `DebugMon` (not available on ARMv6-M) -/// - `PendSV` -/// - `SysTick` +/// - `DefaultHandler` (a) -- `fn(u8) -> !` -- the argument is the exception number (VECTACTIVE) +/// - `NMI` -- `fn()` +/// - `HardFault` -- `fn() -> !` +/// - `MemManage` -- `fn()` +/// - `BusFault` -- `fn()` +/// - `UsageFault` -- `fn()` +/// - `SVC` -- `fn()` +/// - `DebugMon` (b) -- `fn()` +/// - `PendSV` -- `fn()` +/// - `SysTick` -- `fn()` /// -/// (\*) Note that `DefaultHandler` is left undefined and *must* be defined by the user somewhere +/// (a) Note that `DefaultHandler` is left undefined and *must* be defined by the user somewhere /// using this macro. +/// +/// (b) Not available on ARMv6-M +// XXX should we prevent the fault handlers from returning? #[macro_export] macro_rules! exception { (DefaultHandler, $path:path) => { #[allow(non_snake_case)] #[export_name = "DefaultHandler"] pub unsafe extern "C" fn __impl_DefaultHandler() { - // XXX should we really prevent this handler from returning? // validate the signature of the user provided handler - let f: fn() -> ! = $path; + let f: fn(u8) -> ! = $path; - f() + const SCB_ICSR: *const u32 = 0xE000_ED04 as *const u32; + + // NOTE not volatile so the compiler can opt the load operation away if the value is + // unused + f(core::ptr::read(SCB_ICSR) as u8) } }; @@ -187,7 +193,6 @@ macro_rules! exception { #[allow(non_snake_case)] #[export_name = "HardFault"] pub unsafe extern "C" fn __impl_HardFault() { - // XXX should we really prevent this handler from returning? // validate the signature of the user provided handler let f: fn() -> ! = $path; |