Skip to content

Commit 473de97

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 0d2a810 commit 473de97

21 files changed

Lines changed: 224 additions & 250 deletions

cortex-m/asm/lib.rs

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

cortex-m/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn main() {
4747
} else if target.starts_with("thumbv7em-") {
4848
println!("cargo:rustc-cfg=cortex_m");
4949
println!("cargo:rustc-cfg=armv7m");
50-
println!("cargo:rustc-cfg=armv7em"); // (not currently used)
50+
println!("cargo:rustc-cfg=armv7em");
5151
} else if target.starts_with("thumbv8m.base") {
5252
println!("cargo:rustc-cfg=cortex_m");
5353
println!("cargo:rustc-cfg=armv8m");

cortex-m/src/asm.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
33
// When inline assembly is enabled, pull in the assembly routines here. `call_asm!` will invoke
44
// these routines.
5-
#[cfg(feature = "inline-asm")]
6-
#[path = "../asm/inline.rs"]
7-
pub(crate) mod inline;
5+
6+
#![allow(missing_docs)]
7+
8+
#[cfg_attr(any(armv6m, armv7m, armv7em, armv8m), path = "asm/inner.rs")]
9+
#[cfg_attr(native, path = "asm/inner_mock.rs")]
10+
pub mod inner;
811

912
/// Puts the processor in Debug state. Debuggers can pick this up as a "breakpoint".
1013
///
1114
/// **NOTE** calling `bkpt` when the processor is not connected to a debugger will cause an
1215
/// exception.
1316
#[inline(always)]
1417
pub fn bkpt() {
15-
call_asm!(__bkpt());
18+
unsafe { inner::__bkpt() };
1619
}
1720

1821
/// Blocks the program for *at least* `cycles` CPU cycles.
@@ -31,39 +34,39 @@ pub fn bkpt() {
3134
/// please use a more accurate method to produce a delay.
3235
#[inline]
3336
pub fn delay(cycles: u32) {
34-
call_asm!(__delay(cycles: u32));
37+
unsafe { inner::__delay(cycles) };
3538
}
3639

3740
/// A no-operation. Useful to prevent delay loops from being optimized away.
3841
#[inline]
3942
pub fn nop() {
40-
call_asm!(__nop());
43+
unsafe { inner::__nop() };
4144
}
4245

4346
/// Generate an Undefined Instruction exception.
4447
///
4548
/// Can be used as a stable alternative to `core::intrinsics::abort`.
4649
#[inline]
4750
pub fn udf() -> ! {
48-
call_asm!(__udf() -> !)
51+
unsafe { inner::__udf() }
4952
}
5053

5154
/// Wait For Event
5255
#[inline]
5356
pub fn wfe() {
54-
call_asm!(__wfe())
57+
unsafe { inner::__wfe() }
5558
}
5659

5760
/// Wait For Interrupt
5861
#[inline]
5962
pub fn wfi() {
60-
call_asm!(__wfi())
63+
unsafe { inner::__wfi() }
6164
}
6265

6366
/// Send Event
6467
#[inline]
6568
pub fn sev() {
66-
call_asm!(__sev())
69+
unsafe { inner::__sev() }
6770
}
6871

6972
/// Instruction Synchronization Barrier
@@ -72,7 +75,7 @@ pub fn sev() {
7275
/// from cache or memory, after the instruction has been completed.
7376
#[inline]
7477
pub fn isb() {
75-
call_asm!(__isb())
78+
unsafe { inner::__isb() }
7679
}
7780

7881
/// Data Synchronization Barrier
@@ -84,7 +87,7 @@ pub fn isb() {
8487
/// * all cache and branch predictor maintenance operations before this instruction complete
8588
#[inline]
8689
pub fn dsb() {
87-
call_asm!(__dsb())
90+
unsafe { inner::__dsb() }
8891
}
8992

9093
/// Data Memory Barrier
@@ -94,7 +97,7 @@ pub fn dsb() {
9497
/// after the `DMB` instruction.
9598
#[inline]
9699
pub fn dmb() {
97-
call_asm!(__dmb())
100+
unsafe { inner::__dmb() }
98101
}
99102

100103
/// Test Target
@@ -108,7 +111,7 @@ pub fn dmb() {
108111
#[allow(clippy::not_unsafe_ptr_arg_deref)]
109112
pub fn tt(addr: *mut u32) -> u32 {
110113
let addr = addr as u32;
111-
call_asm!(__tt(addr: u32) -> u32)
114+
unsafe { crate::asm::inner::__tt(addr) }
112115
}
113116

114117
/// Test Target Unprivileged
@@ -123,7 +126,7 @@ pub fn tt(addr: *mut u32) -> u32 {
123126
#[allow(clippy::not_unsafe_ptr_arg_deref)]
124127
pub fn ttt(addr: *mut u32) -> u32 {
125128
let addr = addr as u32;
126-
call_asm!(__ttt(addr: u32) -> u32)
129+
unsafe { crate::asm::inner::__ttt(addr) }
127130
}
128131

129132
/// Test Target Alternate Domain
@@ -139,7 +142,7 @@ pub fn ttt(addr: *mut u32) -> u32 {
139142
#[allow(clippy::not_unsafe_ptr_arg_deref)]
140143
pub fn tta(addr: *mut u32) -> u32 {
141144
let addr = addr as u32;
142-
call_asm!(__tta(addr: u32) -> u32)
145+
unsafe { crate::asm::inner::__tta(addr) }
143146
}
144147

145148
/// Test Target Alternate Domain Unprivileged
@@ -155,7 +158,7 @@ pub fn tta(addr: *mut u32) -> u32 {
155158
#[allow(clippy::not_unsafe_ptr_arg_deref)]
156159
pub fn ttat(addr: *mut u32) -> u32 {
157160
let addr = addr as u32;
158-
call_asm!(__ttat(addr: u32) -> u32)
161+
unsafe { crate::asm::inner::__ttat(addr) }
159162
}
160163

161164
/// Branch and Exchange Non-secure
@@ -165,15 +168,15 @@ pub fn ttat(addr: *mut u32) -> u32 {
165168
#[inline]
166169
#[cfg(armv8m)]
167170
pub unsafe fn bx_ns(addr: u32) {
168-
call_asm!(__bxns(addr: u32));
171+
unsafe { crate::asm::inner::__bxns(addr) };
169172
}
170173

171174
/// Semihosting syscall.
172175
///
173176
/// This method is used by cortex-m-semihosting to provide semihosting syscalls.
174177
#[inline]
175178
pub unsafe fn semihosting_syscall(nr: u32, arg: u32) -> u32 {
176-
call_asm!(__sh_syscall(nr: u32, arg: u32) -> u32)
179+
unsafe { inner::__sh_syscall(nr, arg) }
177180
}
178181

179182
/// Switch to unprivileged mode using the Process Stack
@@ -276,7 +279,7 @@ pub unsafe fn bootstrap(msp: *const u32, rv: *const u32) -> ! {
276279
// Ensure thumb mode is set.
277280
let rv = (rv as u32) | 1;
278281
let msp = msp as u32;
279-
call_asm!(__bootstrap(msp: u32, rv: u32) -> !);
282+
unsafe { inner::__bootstrap(msp, rv) }
280283
}
281284

282285
/// Bootload.

0 commit comments

Comments
 (0)