Skip to content

Commit c660e60

Browse files
committed
Import the arm_cfg macro instead of qualifying on ever use.
1 parent 1bff304 commit c660e60

File tree

14 files changed

+60
-48
lines changed

14 files changed

+60
-48
lines changed

cortex-m/src/asm.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
use core::arch::asm;
77
#[cfg(cortex_m)]
88
use core::sync::atomic::{Ordering, compiler_fence};
9+
use cortex_m_macros::asm_cfg;
910

1011
/// Puts the processor in Debug state. Debuggers can pick this up as a "breakpoint".
1112
///
1213
/// **NOTE** calling `bkpt` when the processor is not connected to a debugger will cause an
1314
/// exception.
1415
#[inline(always)]
15-
#[cortex_m_macros::asm_cfg(cortex_m)]
16+
#[asm_cfg(cortex_m)]
1617
pub fn bkpt() {
1718
unsafe { asm!("bkpt", options(nomem, nostack, preserves_flags)) };
1819
}
@@ -32,7 +33,7 @@ pub fn bkpt() {
3233
/// initialization of peripherals if and only if accurate timing is not essential. In any other case
3334
/// please use a more accurate method to produce a delay.
3435
#[inline]
35-
#[cortex_m_macros::asm_cfg(cortex_m)]
36+
#[asm_cfg(cortex_m)]
3637
pub fn delay(cycles: u32) {
3738
// The loop will normally take 3 to 4 CPU cycles per iteration, but superscalar cores
3839
// (eg. Cortex-M7) can potentially do it in 2, so we use that as the lower bound, since delaying
@@ -57,7 +58,7 @@ pub fn delay(cycles: u32) {
5758

5859
/// A no-operation. Useful to prevent delay loops from being optimized away.
5960
#[inline]
60-
#[cortex_m_macros::asm_cfg(cortex_m)]
61+
#[asm_cfg(cortex_m)]
6162
pub fn nop() {
6263
// NOTE: This is a `pure` asm block, but applying that option allows the compiler to eliminate
6364
// the nop entirely (or to collapse multiple subsequent ones). Since the user probably wants N
@@ -69,28 +70,28 @@ pub fn nop() {
6970
///
7071
/// Can be used as a stable alternative to `core::intrinsics::abort`.
7172
#[inline]
72-
#[cortex_m_macros::asm_cfg(cortex_m)]
73+
#[asm_cfg(cortex_m)]
7374
pub fn udf() -> ! {
7475
unsafe { asm!("udf #0", options(noreturn, nomem, nostack, preserves_flags)) };
7576
}
7677

7778
/// Wait For Event
7879
#[inline]
79-
#[cortex_m_macros::asm_cfg(cortex_m)]
80+
#[asm_cfg(cortex_m)]
8081
pub fn wfe() {
8182
unsafe { asm!("wfe", options(nomem, nostack, preserves_flags)) };
8283
}
8384

8485
/// Wait For Interrupt
8586
#[inline]
86-
#[cortex_m_macros::asm_cfg(cortex_m)]
87+
#[asm_cfg(cortex_m)]
8788
pub fn wfi() {
8889
unsafe { asm!("wfi", options(nomem, nostack, preserves_flags)) };
8990
}
9091

9192
/// Send Event
9293
#[inline]
93-
#[cortex_m_macros::asm_cfg(cortex_m)]
94+
#[asm_cfg(cortex_m)]
9495
pub fn sev() {
9596
unsafe { asm!("sev", options(nomem, nostack, preserves_flags)) };
9697
}
@@ -100,7 +101,7 @@ pub fn sev() {
100101
/// Flushes the pipeline in the processor, so that all instructions following the `ISB` are fetched
101102
/// from cache or memory, after the instruction has been completed.
102103
#[inline]
103-
#[cortex_m_macros::asm_cfg(cortex_m)]
104+
#[asm_cfg(cortex_m)]
104105
pub fn isb() {
105106
compiler_fence(Ordering::SeqCst);
106107
unsafe { asm!("isb", options(nostack, preserves_flags)) };
@@ -115,7 +116,7 @@ pub fn isb() {
115116
/// * any explicit memory access made before this instruction is complete
116117
/// * all cache and branch predictor maintenance operations before this instruction complete
117118
#[inline]
118-
#[cortex_m_macros::asm_cfg(cortex_m)]
119+
#[asm_cfg(cortex_m)]
119120
pub fn dsb() {
120121
compiler_fence(Ordering::SeqCst);
121122
unsafe { asm!("dsb", options(nostack, preserves_flags)) };
@@ -128,7 +129,7 @@ pub fn dsb() {
128129
/// instruction are observed before any explicit memory accesses that appear in program order
129130
/// after the `DMB` instruction.
130131
#[inline]
131-
#[cortex_m_macros::asm_cfg(cortex_m)]
132+
#[asm_cfg(cortex_m)]
132133
pub fn dmb() {
133134
compiler_fence(Ordering::SeqCst);
134135
unsafe { asm!("dmb", options(nostack, preserves_flags)) };
@@ -141,7 +142,7 @@ pub fn dmb() {
141142
/// Returns a Test Target Response Payload (cf section D1.2.215 of
142143
/// Armv8-M Architecture Reference Manual).
143144
#[inline]
144-
#[cortex_m_macros::asm_cfg(armv8m)]
145+
#[asm_cfg(armv8m)]
145146
// The __tt function does not dereference the pointer received.
146147
#[allow(clippy::not_unsafe_ptr_arg_deref)]
147148
pub fn tt(addr: *mut u32) -> u32 {
@@ -163,7 +164,7 @@ pub fn tt(addr: *mut u32) -> u32 {
163164
/// Returns a Test Target Response Payload (cf section D1.2.215 of
164165
/// Armv8-M Architecture Reference Manual).
165166
#[inline]
166-
#[cortex_m_macros::asm_cfg(armv8m)]
167+
#[asm_cfg(armv8m)]
167168
// The __ttt function does not dereference the pointer received.
168169
#[allow(clippy::not_unsafe_ptr_arg_deref)]
169170
pub fn ttt(addr: *mut u32) -> u32 {
@@ -186,7 +187,7 @@ pub fn ttt(addr: *mut u32) -> u32 {
186187
/// Returns a Test Target Response Payload (cf section D1.2.215 of
187188
/// Armv8-M Architecture Reference Manual).
188189
#[inline]
189-
#[cortex_m_macros::asm_cfg(armv8m)]
190+
#[asm_cfg(armv8m)]
190191
// The __tta function does not dereference the pointer received.
191192
#[allow(clippy::not_unsafe_ptr_arg_deref)]
192193
pub fn tta(addr: *mut u32) -> u32 {
@@ -209,7 +210,7 @@ pub fn tta(addr: *mut u32) -> u32 {
209210
/// Returns a Test Target Response Payload (cf section D1.2.215 of
210211
/// Armv8-M Architecture Reference Manual).
211212
#[inline]
212-
#[cortex_m_macros::asm_cfg(armv8m)]
213+
#[asm_cfg(armv8m)]
213214
// The __ttat function does not dereference the pointer received.
214215
#[allow(clippy::not_unsafe_ptr_arg_deref)]
215216
pub fn ttat(addr: *mut u32) -> u32 {
@@ -229,7 +230,7 @@ pub fn ttat(addr: *mut u32) -> u32 {
229230
/// See section C2.4.26 of Armv8-M Architecture Reference Manual for details.
230231
/// Undefined if executed in Non-Secure state.
231232
#[inline]
232-
#[cortex_m_macros::asm_cfg(armv8m)]
233+
#[asm_cfg(armv8m)]
233234
pub unsafe fn bx_ns(addr: u32) {
234235
unsafe { asm!("BXNS {}", in(reg) addr, options(nomem, nostack, preserves_flags)) };
235236
}
@@ -238,7 +239,7 @@ pub unsafe fn bx_ns(addr: u32) {
238239
///
239240
/// This method is used by cortex-m-semihosting to provide semihosting syscalls.
240241
#[inline]
241-
#[cortex_m_macros::asm_cfg(cortex_m)]
242+
#[asm_cfg(cortex_m)]
242243
pub unsafe fn semihosting_syscall(mut nr: u32, arg: u32) -> u32 {
243244
unsafe {
244245
asm!("bkpt #0xab", inout("r0") nr, in("r1") arg, options(nomem, nostack, preserves_flags))
@@ -263,7 +264,7 @@ pub unsafe fn semihosting_syscall(mut nr: u32, arg: u32) -> u32 {
263264
/// program - stack overflows are obviously UB. If your processor supports
264265
/// it, you may wish to set the `PSPLIM` register to guard against this.
265266
#[inline(always)]
266-
#[cortex_m_macros::asm_cfg(cortex_m)]
267+
#[asm_cfg(cortex_m)]
267268
pub unsafe fn enter_unprivileged_psp(psp: *const u32, entry: extern "C" fn() -> !) -> ! {
268269
use crate::register::control::{Control, Npriv, Spsel};
269270
const CONTROL_FLAGS: u32 = {
@@ -305,7 +306,7 @@ pub unsafe fn enter_unprivileged_psp(psp: *const u32, entry: extern "C" fn() ->
305306
/// program - stack overflows are obviously UB. If your processor supports
306307
/// it, you may wish to set the `PSPLIM` register to guard against this.
307308
#[inline(always)]
308-
#[cortex_m_macros::asm_cfg(cortex_m)]
309+
#[asm_cfg(cortex_m)]
309310
pub unsafe fn enter_privileged_psp(psp: *const u32, entry: extern "C" fn() -> !) -> ! {
310311
use crate::register::control::{Control, Npriv, Spsel};
311312
const CONTROL_FLAGS: u32 = {
@@ -342,7 +343,7 @@ pub unsafe fn enter_privileged_psp(psp: *const u32, entry: extern "C" fn() -> !)
342343
/// `msp` and `rv` must point to valid stack memory and executable code,
343344
/// respectively.
344345
#[inline]
345-
#[cortex_m_macros::asm_cfg(cortex_m)]
346+
#[asm_cfg(cortex_m)]
346347
pub unsafe fn bootstrap(msp: *const u32, rv: *const u32) -> ! {
347348
// Ensure thumb mode is set.
348349
let rv = (rv as u32) | 1;
@@ -379,7 +380,7 @@ pub unsafe fn bootstrap(msp: *const u32, rv: *const u32) -> ! {
379380
/// table, with a valid stack pointer as the first word and
380381
/// a valid reset vector as the second word.
381382
#[inline]
382-
#[cortex_m_macros::asm_cfg(cortex_m)]
383+
#[asm_cfg(cortex_m)]
383384
pub unsafe fn bootload(vector_table: *const u32) -> ! {
384385
unsafe {
385386
let msp = core::ptr::read_volatile(vector_table);

cortex-m/src/interrupt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Interrupts
22
3+
pub use bare_metal::{CriticalSection, Mutex, Nr};
34
#[cfg(cortex_m)]
45
use core::arch::asm;
56
#[cfg(cortex_m)]
67
use core::sync::atomic::{Ordering, compiler_fence};
7-
8-
pub use bare_metal::{CriticalSection, Mutex, Nr};
8+
use cortex_m_macros::asm_cfg;
99

1010
/// Trait for enums of external interrupt numbers.
1111
///
@@ -39,7 +39,7 @@ unsafe impl<T: Nr + Copy> InterruptNumber for T {
3939

4040
/// Disables all interrupts
4141
#[inline]
42-
#[cortex_m_macros::asm_cfg(cortex_m)]
42+
#[asm_cfg(cortex_m)]
4343
pub fn disable() {
4444
unsafe { asm!("cpsid i", options(nomem, nostack, preserves_flags)) };
4545

@@ -53,7 +53,7 @@ pub fn disable() {
5353
///
5454
/// - Do not call this function inside an `interrupt::free` critical section
5555
#[inline]
56-
#[cortex_m_macros::asm_cfg(cortex_m)]
56+
#[asm_cfg(cortex_m)]
5757
pub unsafe fn enable() {
5858
// Ensure no preceeding memory accesses are reordered to after interrupts are enabled.
5959
compiler_fence(Ordering::SeqCst);

cortex-m/src/peripheral/scb.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::arch::asm;
55
use core::ptr;
66
#[cfg(any(armv7m, armv8m))]
77
use core::sync::atomic::{Ordering, compiler_fence};
8-
8+
use cortex_m_macros::asm_cfg;
99
use volatile_register::RW;
1010

1111
#[cfg(not(armv6m))]
@@ -308,7 +308,7 @@ impl SCB {
308308
///
309309
/// This operation first invalidates the entire I-cache.
310310
#[inline]
311-
#[cortex_m_macros::asm_cfg(cortex_m)]
311+
#[asm_cfg(cortex_m)]
312312
pub fn enable_icache(&mut self) {
313313
// Don't do anything if I-cache is already enabled
314314
if Self::icache_enabled() {
@@ -396,7 +396,7 @@ impl SCB {
396396
/// This operation first invalidates the entire D-cache, ensuring it does
397397
/// not contain stale values before being enabled.
398398
#[inline]
399-
#[cortex_m_macros::asm_cfg(cortex_m)]
399+
#[asm_cfg(cortex_m)]
400400
pub fn enable_dcache(&mut self, cpuid: &mut CPUID) {
401401
// Don't do anything if D-cache is already enabled
402402
if Self::dcache_enabled() {

cortex-m/src/register/apsr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
#[cfg(cortex_m)]
44
use core::arch::asm;
5+
use cortex_m_macros::asm_cfg;
56

67
/// Application Program Status Register
78
#[derive(Clone, Copy, Debug)]
@@ -51,7 +52,7 @@ impl Apsr {
5152
///
5253
/// **NOTE** This function is available if `cortex-m` is built with the `"inline-asm"` feature.
5354
#[inline]
54-
#[cortex_m_macros::asm_cfg(cortex_m)]
55+
#[asm_cfg(cortex_m)]
5556
pub fn read() -> Apsr {
5657
let bits;
5758
unsafe { asm!("mrs {}, APSR", out(reg) bits, options(nomem, nostack, preserves_flags)) };

cortex-m/src/register/basepri.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
33
#[cfg(any(armv7m, armv8m))]
44
use core::arch::asm;
5+
use cortex_m_macros::asm_cfg;
56

67
/// Reads the CPU register
78
#[inline]
8-
#[cortex_m_macros::asm_cfg(any(armv7m, armv8m_main))]
9+
#[asm_cfg(any(armv7m, armv8m_main))]
910
pub fn read() -> u8 {
1011
let r;
1112
unsafe { asm!("mrs {}, BASEPRI", out(reg) r, options(nomem, nostack, preserves_flags)) };
@@ -17,7 +18,7 @@ pub fn read() -> u8 {
1718
/// **IMPORTANT** If you are using a Cortex-M7 device with revision r0p1 you MUST enable the
1819
/// `cm7-r0p1` Cargo feature or this function WILL misbehave.
1920
#[inline]
20-
#[cortex_m_macros::asm_cfg(any(armv7m, armv8m_main))]
21+
#[asm_cfg(any(armv7m, armv8m_main))]
2122
pub unsafe fn write(basepri: u8) {
2223
#[cfg(not(feature = "cm7-r0p1"))]
2324
{

cortex-m/src/register/basepri_max.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
#[cfg(any(armv7m, armv8m))]
44
use core::arch::asm;
5+
use cortex_m_macros::asm_cfg;
56

67
/// Writes to BASEPRI *if*
78
///
@@ -11,7 +12,7 @@ use core::arch::asm;
1112
/// **IMPORTANT** If you are using a Cortex-M7 device with revision r0p1 you MUST enable the
1213
/// `cm7-r0p1` Cargo feature or this function WILL misbehave.
1314
#[inline]
14-
#[cortex_m_macros::asm_cfg(any(armv7m, armv8m_main))]
15+
#[asm_cfg(any(armv7m, armv8m_main))]
1516
pub fn write(basepri: u8) {
1617
#[cfg(not(feature = "cm7-r0p1"))]
1718
{

cortex-m/src/register/control.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use core::arch::asm;
55
#[cfg(cortex_m)]
66
use core::sync::atomic::{Ordering, compiler_fence};
7+
use cortex_m_macros::asm_cfg;
78

89
/// Control register
910
#[derive(Clone, Copy, Debug)]
@@ -178,7 +179,7 @@ impl Fpca {
178179

179180
/// Reads the CPU register
180181
#[inline]
181-
#[cortex_m_macros::asm_cfg(cortex_m)]
182+
#[asm_cfg(cortex_m)]
182183
pub fn read() -> Control {
183184
let bits;
184185
unsafe { asm!("mrs {}, CONTROL", out(reg) bits, options(nomem, nostack, preserves_flags)) };
@@ -187,7 +188,7 @@ pub fn read() -> Control {
187188

188189
/// Writes to the CPU register.
189190
#[inline]
190-
#[cortex_m_macros::asm_cfg(cortex_m)]
191+
#[asm_cfg(cortex_m)]
191192
pub unsafe fn write(control: Control) {
192193
let control = control.bits();
193194

cortex-m/src/register/faultmask.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
#[cfg(cortex_m)]
44
use core::arch::asm;
5+
use cortex_m_macros::asm_cfg;
56

67
/// All exceptions are ...
78
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -28,7 +29,7 @@ impl Faultmask {
2829

2930
/// Reads the CPU register
3031
#[inline]
31-
#[cortex_m_macros::asm_cfg(any(armv7m, armv8m_main))]
32+
#[asm_cfg(any(armv7m, armv8m_main))]
3233
pub fn read() -> Faultmask {
3334
let r: u32;
3435
unsafe { asm!("mrs {}, FAULTMASK", out(reg) r, options(nomem, nostack, preserves_flags)) };

cortex-m/src/register/lr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
33
#[cfg(cortex_m)]
44
use core::arch::asm;
5+
use cortex_m_macros::asm_cfg;
56

67
/// Reads the CPU register
78
///
89
/// **NOTE** This function is available if `cortex-m` is built with the `"inline-asm"` feature.
910
#[inline]
10-
#[cortex_m_macros::asm_cfg(cortex_m)]
11+
#[asm_cfg(cortex_m)]
1112
pub fn read() -> u32 {
1213
let r;
1314
unsafe { asm!("mov {}, lr", out(reg) r, options(nomem, nostack, preserves_flags)) };
@@ -22,7 +23,7 @@ pub fn read() -> u32 {
2223
/// This function can't be used soundly.
2324
#[inline]
2425
#[deprecated = "This function can't be used soundly."]
25-
#[cortex_m_macros::asm_cfg(cortex_m)]
26+
#[asm_cfg(cortex_m)]
2627
pub unsafe fn write(bits: u32) {
2728
unsafe { asm!("mov lr, {}", in(reg) bits, options(nomem, nostack, preserves_flags)) };
2829
}

0 commit comments

Comments
 (0)