aboutsummaryrefslogtreecommitdiff
path: root/cortex-m-rt/src
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2018-04-26 05:26:35 +0200
committerGravatar Jorge Aparicio <jorge@japaric.io> 2018-04-26 05:26:35 +0200
commit6dd420ff082b4a9d9151e27d1edf724e416d712b (patch)
tree4045406376190559b504a3eabd81d97860e621a2 /cortex-m-rt/src
parentc4b580b957853aaa7b0680ce12da81049e30d978 (diff)
downloadcortex-m-6dd420ff082b4a9d9151e27d1edf724e416d712b.tar.gz
cortex-m-6dd420ff082b4a9d9151e27d1edf724e416d712b.tar.zst
cortex-m-6dd420ff082b4a9d9151e27d1edf724e416d712b.zip
re-implement interrupt / exception state
Diffstat (limited to 'cortex-m-rt/src')
-rw-r--r--cortex-m-rt/src/lib.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/cortex-m-rt/src/lib.rs b/cortex-m-rt/src/lib.rs
index 128d7b4..23cb1d4 100644
--- a/cortex-m-rt/src/lib.rs
+++ b/cortex-m-rt/src/lib.rs
@@ -211,6 +211,7 @@ pub static __EXCEPTIONS: [Option<unsafe extern "C" fn()>; 14] = [
#[macro_export]
macro_rules! exception {
(DefaultHandler, $path:path) => {
+ #[allow(unsafe_code)]
#[allow(non_snake_case)]
#[export_name = "DefaultHandler"]
pub unsafe extern "C" fn __impl_DefaultHandler() {
@@ -226,6 +227,7 @@ macro_rules! exception {
};
(HardFault, $path:path) => {
+ #[allow(unsafe_code)]
#[allow(non_snake_case)]
#[export_name = "UserHardFault"]
pub unsafe extern "C" fn __impl_UserHardFault(ef: &$crate::ExceptionFrame) {
@@ -238,7 +240,24 @@ macro_rules! exception {
// NOTE Unfortunately, this will end up leaking `$exception` into the function call namespace.
// But the damage is somewhat reduced by having `$exception` not being a `snake_case` function.
+ ($ExceptionName:ident, $path:path, state: $State:ty = $init:expr) => {
+ #[allow(unsafe_code)]
+ #[no_mangle]
+ pub unsafe extern "C" fn $ExceptionName() {
+ static mut STATE: $State = $init;
+
+ // check that this exception exists
+ let _ = $crate::Exception::$ExceptionName;
+
+ // validate the signature of the user provided handler
+ let f: fn(&mut $State) = $path;
+
+ f(&mut STATE)
+ }
+ };
+
($ExceptionName:ident, $path:path) => {
+ #[allow(unsafe_code)]
#[no_mangle]
pub unsafe extern "C" fn $ExceptionName() {
// check that this exception exists