aboutsummaryrefslogtreecommitdiff
path: root/src/exception.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <japaricious@gmail.com> 2017-03-04 20:46:19 -0500
committerGravatar Jorge Aparicio <japaricious@gmail.com> 2017-03-04 20:46:19 -0500
commit251d1aa11244d5356659ccf969e29b0e7da82c7a (patch)
treec586f652b45b6981c3aa15ea870643763d7dbc35 /src/exception.rs
parentb4f105cde28d89f3c8e42e4fe341390a7dc2dccf (diff)
downloadcortex-m-251d1aa11244d5356659ccf969e29b0e7da82c7a.tar.gz
cortex-m-251d1aa11244d5356659ccf969e29b0e7da82c7a.tar.zst
cortex-m-251d1aa11244d5356659ccf969e29b0e7da82c7a.zip
review safety of the existing API, make the register API type safe
Diffstat (limited to 'src/exception.rs')
-rw-r--r--src/exception.rs28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/exception.rs b/src/exception.rs
index fad3ea9..cd38366 100644
--- a/src/exception.rs
+++ b/src/exception.rs
@@ -1,6 +1,8 @@
//! Exceptions
-use {Handler, Reserved, StackFrame};
+use {Handler, Reserved};
+#[cfg(target_arch = "arm")]
+use StackFrame;
/// Kind of exception
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -98,6 +100,7 @@ pub const DEFAULT_HANDLERS: Handlers = Handlers {
pub unsafe extern "C" fn default_handler() {
// This is the actual exception handler. `_sf` is a pointer to the previous
// stack frame
+ #[cfg(target_arch = "arm")]
extern "C" fn handler(_sf: &StackFrame) -> ! {
#[cfg(feature = "semihosting")]
hprintln!("EXCEPTION {:?} @ PC=0x{:08x}", Exception::current(), _sf.pc);
@@ -109,12 +112,21 @@ pub unsafe extern "C" fn default_handler() {
loop {}
}
- // "trampoline" to get to the real exception handler.
- asm!("mrs r0, MSP
- ldr r1, [r0, #20]
- b $0"
- :
- : "i"(handler as extern "C" fn(&StackFrame) -> !) :: "volatile");
+ match () {
+ #[cfg(target_arch = "arm")]
+ () => {
+ // "trampoline" to get to the real exception handler.
+ asm!("mrs r0, MSP
+ ldr r1, [r0, #20]
+ b $0"
+ :
+ : "i"(handler as extern "C" fn(&StackFrame) -> !)
+ :
+ : "volatile");
- ::core::intrinsics::unreachable()
+ ::core::intrinsics::unreachable()
+ }
+ #[cfg(not(target_arch = "arm"))]
+ () => {}
+ }
}