diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/asm.rs | 54 | ||||
-rw-r--r-- | src/exception.rs | 41 |
2 files changed, 41 insertions, 54 deletions
@@ -3,45 +3,30 @@ /// Puts the processor in Debug state. Debuggers can pick this up as a /// "breakpoint". /// -/// Optionally, an "immediate" value (in the 0-255 range) can be passed to -/// `bkpt!`. The debugger can then read this value using the Program Counter -/// (PC). -#[cfg(target_arch = "arm")] -#[macro_export] -macro_rules! bkpt { - () => { +/// NOTE calling `bkpt` when the processor is not connected to a debugger will +/// cause an exception +#[inline(always)] +pub fn bkpt() { + #[cfg(target_arch = "arm")] + unsafe { asm!("bkpt" : : : : "volatile"); - }; - ($imm:expr) => { - asm!(concat!("bkpt #", stringify!($imm)) + } +} + +/// A no-operation. Useful to prevent delay loops from being optimized away. +pub fn nop() { + unsafe { + asm!("nop" : : : : "volatile"); - }; -} - -/// Puts the processor in Debug state. Debuggers can pick this up as a -/// "breakpoint". -/// -/// Optionally, an "immediate" value (in the 0-255 range) can be passed to -/// `bkpt!`. The debugger can then read this value using the Program Counter -/// (PC). -#[cfg(not(target_arch = "arm"))] -#[macro_export] -macro_rules! bkpt { - () => { - asm!(""); - }; - ($e:expr) => { - asm!(""); - }; + } } - /// Wait For Event pub fn wfe() { match () { @@ -73,14 +58,3 @@ pub fn wfi() { () => {} } } - -/// A no-operation. Useful to prevent delay loops from being optimized away. -pub fn nop() { - unsafe { - asm!("nop" - : - : - : - : "volatile"); - } -} diff --git a/src/exception.rs b/src/exception.rs index b944d6c..8343d99 100644 --- a/src/exception.rs +++ b/src/exception.rs @@ -72,32 +72,48 @@ pub struct Handlers { /// Pendable request for system service pub pendsv: unsafe extern "C" fn(&PendsvCtxt), /// System tick timer - pub sys_tick: unsafe extern "C" fn (&SysTickCtxt), + pub sys_tick: unsafe extern "C" fn(&SysTickCtxt), } /// Identifies the Nmi exception -pub struct NmiCtxt { _0: () } +pub struct NmiCtxt { + _0: (), +} /// Identifies the HardFault exception -pub struct HardFaultCtxt { _0: () } +pub struct HardFaultCtxt { + _0: (), +} /// Identifies the MemManage exception -pub struct MemManageCtxt { _0: () } +pub struct MemManageCtxt { + _0: (), +} /// Identifies the BusFault exception -pub struct BusFaultCtxt { _0: () } +pub struct BusFaultCtxt { + _0: (), +} /// Identifies the UsageFault exception -pub struct UsageFaultCtxt { _0: () } +pub struct UsageFaultCtxt { + _0: (), +} /// Identifies the Svcall exception -pub struct SvcallCtxt { _0: () } +pub struct SvcallCtxt { + _0: (), +} /// Identifies the Pendsv exception -pub struct PendsvCtxt { _0: () } +pub struct PendsvCtxt { + _0: (), +} /// Identifies the Systick exception -pub struct SysTickCtxt { _0: () } +pub struct SysTickCtxt { + _0: (), +} unsafe impl Token for NmiCtxt {} @@ -134,8 +150,7 @@ pub const DEFAULT_HANDLERS: Handlers = Handlers { // This needs asm!, #[naked] and unreachable() to avoid modifying the stack // pointer (MSP), that way it points to the stacked registers #[naked] -pub unsafe extern "C" fn default_handler<T>(_token: &T) -{ +pub unsafe extern "C" fn default_handler<T>(_token: &T) { // This is the actual exception handler. `_sf` is a pointer to the previous // stack frame #[cfg(target_arch = "arm")] @@ -143,9 +158,7 @@ pub unsafe extern "C" fn default_handler<T>(_token: &T) #[cfg(feature = "semihosting")] hprintln!("EXCEPTION {:?} @ PC=0x{:08x}", Exception::current(), _sr.pc); - unsafe { - bkpt!(); - } + ::asm::bkpt(); loop {} } |