Skip to content

Commit 8cd7762

Browse files
committed
Move asm code into normal code.
Inline asm has been supported in stable rust for some time, so I removed the separate asm build infra and added that code to the normal crate code. I also crated a mock of the asm functions that were needed to run clippy with a non-arm target (like x86_64).
1 parent 2d2847f commit 8cd7762

21 files changed

Lines changed: 261 additions & 256 deletions

cortex-m/asm/lib.rs

Lines changed: 0 additions & 140 deletions
This file was deleted.

cortex-m/src/asm.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//! Miscellaneous assembly instructions
22
3-
// When inline assembly is enabled, pull in the assembly routines here. `call_asm!` will invoke
4-
// these routines.
5-
#[cfg(feature = "inline-asm")]
6-
#[path = "../asm/inline.rs"]
7-
pub(crate) mod inline;
3+
#![allow(missing_docs)]
4+
5+
#[cfg_attr(cortex_m, path = "asm/inner.rs")]
6+
#[cfg_attr(not(cortex_m), path = "asm/inner_mock.rs")]
7+
pub mod inner;
88

99
/// Puts the processor in Debug state. Debuggers can pick this up as a "breakpoint".
1010
///
1111
/// **NOTE** calling `bkpt` when the processor is not connected to a debugger will cause an
1212
/// exception.
1313
#[inline(always)]
1414
pub fn bkpt() {
15-
call_asm!(__bkpt());
15+
unsafe { inner::__bkpt() };
1616
}
1717

1818
/// Blocks the program for *at least* `cycles` CPU cycles.
@@ -31,39 +31,39 @@ pub fn bkpt() {
3131
/// please use a more accurate method to produce a delay.
3232
#[inline]
3333
pub fn delay(cycles: u32) {
34-
call_asm!(__delay(cycles: u32));
34+
unsafe { inner::__delay(cycles) };
3535
}
3636

3737
/// A no-operation. Useful to prevent delay loops from being optimized away.
3838
#[inline]
3939
pub fn nop() {
40-
call_asm!(__nop());
40+
unsafe { inner::__nop() };
4141
}
4242

4343
/// Generate an Undefined Instruction exception.
4444
///
4545
/// Can be used as a stable alternative to `core::intrinsics::abort`.
4646
#[inline]
4747
pub fn udf() -> ! {
48-
call_asm!(__udf() -> !)
48+
unsafe { inner::__udf() }
4949
}
5050

5151
/// Wait For Event
5252
#[inline]
5353
pub fn wfe() {
54-
call_asm!(__wfe())
54+
unsafe { inner::__wfe() }
5555
}
5656

5757
/// Wait For Interrupt
5858
#[inline]
5959
pub fn wfi() {
60-
call_asm!(__wfi())
60+
unsafe { inner::__wfi() }
6161
}
6262

6363
/// Send Event
6464
#[inline]
6565
pub fn sev() {
66-
call_asm!(__sev())
66+
unsafe { inner::__sev() }
6767
}
6868

6969
/// Instruction Synchronization Barrier
@@ -72,7 +72,7 @@ pub fn sev() {
7272
/// from cache or memory, after the instruction has been completed.
7373
#[inline]
7474
pub fn isb() {
75-
call_asm!(__isb())
75+
unsafe { inner::__isb() }
7676
}
7777

7878
/// Data Synchronization Barrier
@@ -84,7 +84,7 @@ pub fn isb() {
8484
/// * all cache and branch predictor maintenance operations before this instruction complete
8585
#[inline]
8686
pub fn dsb() {
87-
call_asm!(__dsb())
87+
unsafe { inner::__dsb() }
8888
}
8989

9090
/// Data Memory Barrier
@@ -94,7 +94,7 @@ pub fn dsb() {
9494
/// after the `DMB` instruction.
9595
#[inline]
9696
pub fn dmb() {
97-
call_asm!(__dmb())
97+
unsafe { inner::__dmb() }
9898
}
9999

100100
/// Test Target
@@ -108,7 +108,7 @@ pub fn dmb() {
108108
#[allow(clippy::not_unsafe_ptr_arg_deref)]
109109
pub fn tt(addr: *mut u32) -> u32 {
110110
let addr = addr as u32;
111-
call_asm!(__tt(addr: u32) -> u32)
111+
unsafe { crate::asm::inner::__tt(addr) }
112112
}
113113

114114
/// Test Target Unprivileged
@@ -123,7 +123,7 @@ pub fn tt(addr: *mut u32) -> u32 {
123123
#[allow(clippy::not_unsafe_ptr_arg_deref)]
124124
pub fn ttt(addr: *mut u32) -> u32 {
125125
let addr = addr as u32;
126-
call_asm!(__ttt(addr: u32) -> u32)
126+
unsafe { crate::asm::inner::__ttt(addr) }
127127
}
128128

129129
/// Test Target Alternate Domain
@@ -139,7 +139,7 @@ pub fn ttt(addr: *mut u32) -> u32 {
139139
#[allow(clippy::not_unsafe_ptr_arg_deref)]
140140
pub fn tta(addr: *mut u32) -> u32 {
141141
let addr = addr as u32;
142-
call_asm!(__tta(addr: u32) -> u32)
142+
unsafe { crate::asm::inner::__tta(addr) }
143143
}
144144

145145
/// Test Target Alternate Domain Unprivileged
@@ -155,7 +155,7 @@ pub fn tta(addr: *mut u32) -> u32 {
155155
#[allow(clippy::not_unsafe_ptr_arg_deref)]
156156
pub fn ttat(addr: *mut u32) -> u32 {
157157
let addr = addr as u32;
158-
call_asm!(__ttat(addr: u32) -> u32)
158+
unsafe { crate::asm::inner::__ttat(addr) }
159159
}
160160

161161
/// Branch and Exchange Non-secure
@@ -165,15 +165,15 @@ pub fn ttat(addr: *mut u32) -> u32 {
165165
#[inline]
166166
#[cfg(armv8m)]
167167
pub unsafe fn bx_ns(addr: u32) {
168-
call_asm!(__bxns(addr: u32));
168+
unsafe { crate::asm::inner::__bxns(addr) };
169169
}
170170

171171
/// Semihosting syscall.
172172
///
173173
/// This method is used by cortex-m-semihosting to provide semihosting syscalls.
174174
#[inline]
175175
pub unsafe fn semihosting_syscall(nr: u32, arg: u32) -> u32 {
176-
call_asm!(__sh_syscall(nr: u32, arg: u32) -> u32)
176+
unsafe { inner::__sh_syscall(nr, arg) }
177177
}
178178

179179
/// Switch to unprivileged mode using the Process Stack
@@ -276,7 +276,7 @@ pub unsafe fn bootstrap(msp: *const u32, rv: *const u32) -> ! {
276276
// Ensure thumb mode is set.
277277
let rv = (rv as u32) | 1;
278278
let msp = msp as u32;
279-
call_asm!(__bootstrap(msp: u32, rv: u32) -> !);
279+
unsafe { inner::__bootstrap(msp, rv) }
280280
}
281281

282282
/// Bootload.

0 commit comments

Comments
 (0)