Skip to content

Commit 875ee38

Browse files
committed
map asm! ops to unimplemented! on non ARM targets
1 parent 9a80bae commit 875ee38

File tree

12 files changed

+183
-191
lines changed

12 files changed

+183
-191
lines changed

src/asm.rs

+26-47
Original file line numberDiff line numberDiff line change
@@ -7,74 +7,57 @@
77
/// cause an exception
88
#[inline(always)]
99
pub fn bkpt() {
10-
#[cfg(target_arch = "arm")]
11-
unsafe {
12-
asm!("bkpt"
13-
:
14-
:
15-
:
16-
: "volatile");
10+
match () {
11+
#[cfg(target_arch = "arm")]
12+
() => unsafe { asm!("bkpt" :::: "volatile") },
13+
#[cfg(not(target_arch = "arm"))]
14+
() => unimplemented!(),
1715
}
1816
}
1917

2018
/// A no-operation. Useful to prevent delay loops from being optimized away.
21-
#[inline(always)]
19+
#[inline]
2220
pub fn nop() {
23-
unsafe {
24-
asm!("nop"
25-
:
26-
:
27-
:
28-
: "volatile");
21+
match () {
22+
#[cfg(target_arch = "arm")]
23+
() => unsafe { asm!("nop" :::: "volatile") },
24+
#[cfg(not(target_arch = "arm"))]
25+
() => unimplemented!(),
2926
}
3027
}
3128
/// Wait For Event
32-
#[inline(always)]
29+
#[inline]
3330
pub fn wfe() {
3431
match () {
3532
#[cfg(target_arch = "arm")]
36-
() => unsafe {
37-
asm!("wfe"
38-
:
39-
:
40-
:
41-
: "volatile")
42-
},
33+
() => unsafe { asm!("wfe" :::: "volatile") },
4334
#[cfg(not(target_arch = "arm"))]
44-
() => {}
35+
() => unimplemented!(),
4536
}
4637
}
4738

4839
/// Wait For Interrupt
49-
#[inline(always)]
40+
#[inline]
5041
pub fn wfi() {
5142
match () {
5243
#[cfg(target_arch = "arm")]
53-
() => unsafe{
54-
asm!("wfi"
55-
:
56-
:
57-
:
58-
: "volatile")
59-
},
44+
() => unsafe { asm!("wfi" :::: "volatile") },
6045
#[cfg(not(target_arch = "arm"))]
61-
() => {}
46+
() => unimplemented!(),
6247
}
6348
}
6449

6550
/// Instruction Synchronization Barrier
6651
///
6752
/// Flushes the pipeline in the processor, so that all instructions following the `ISB` are fetched
6853
/// from cache or memory, after the instruction has been completed.
69-
#[inline(always)]
54+
#[inline]
7055
pub fn isb() {
7156
match () {
7257
#[cfg(target_arch = "arm")]
73-
() => unsafe {
74-
asm!("isb 0xF" : : : "memory" : "volatile");
75-
},
58+
() => unsafe { asm!("isb 0xF" : : : "memory" : "volatile") },
7659
#[cfg(not(target_arch = "arm"))]
77-
() => {}
60+
() => unimplemented!(),
7861
}
7962
}
8063

@@ -86,15 +69,13 @@ pub fn isb() {
8669
///
8770
/// * any explicit memory access made before this instruction is complete
8871
/// * all cache and branch predictor maintenance operations before this instruction complete
89-
#[inline(always)]
72+
#[inline]
9073
pub fn dsb() {
9174
match () {
9275
#[cfg(target_arch = "arm")]
93-
() => unsafe {
94-
asm!("dsb 0xF" : : : "memory" : "volatile");
95-
},
76+
() => unsafe { asm!("dsb 0xF" : : : "memory" : "volatile") },
9677
#[cfg(not(target_arch = "arm"))]
97-
() => {}
78+
() => unimplemented!(),
9879
}
9980
}
10081

@@ -103,14 +84,12 @@ pub fn dsb() {
10384
/// Ensures that all explicit memory accesses that appear in program order before the `DMB`
10485
/// instruction are observed before any explicit memory accesses that appear in program order
10586
/// after the `DMB` instruction.
106-
#[inline(always)]
87+
#[inline]
10788
pub fn dmb() {
10889
match () {
10990
#[cfg(target_arch = "arm")]
110-
() => unsafe {
111-
asm!("dmb 0xF" : : : "memory" : "volatile");
112-
},
91+
() => unsafe { asm!("dmb 0xF" : : : "memory" : "volatile") },
11392
#[cfg(not(target_arch = "arm"))]
114-
() => {}
93+
() => unimplemented!(),
11594
}
11695
}

src/interrupt.rs

+6-16
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
pub use bare_metal::{CriticalSection, Mutex, Nr};
44

55
/// Disables all interrupts
6-
#[inline(always)]
6+
#[inline]
77
pub fn disable() {
88
match () {
99
#[cfg(target_arch = "arm")]
1010
() => unsafe {
11-
asm!("cpsid i"
12-
:
13-
:
14-
: "memory"
15-
: "volatile");
11+
asm!("cpsid i" ::: "memory" : "volatile");
1612
},
1713
#[cfg(not(target_arch = "arm"))]
18-
() => {}
14+
() => unimplemented!(),
1915
}
2016
}
2117

@@ -24,19 +20,13 @@ pub fn disable() {
2420
/// # Safety
2521
///
2622
/// - Do not call this function inside an `interrupt::free` critical section
27-
#[inline(always)]
23+
#[inline]
2824
pub unsafe fn enable() {
2925
match () {
3026
#[cfg(target_arch = "arm")]
31-
() => {
32-
asm!("cpsie i"
33-
:
34-
:
35-
: "memory"
36-
: "volatile");
37-
}
27+
() => asm!("cpsie i" ::: "memory" : "volatile"),
3828
#[cfg(not(target_arch = "arm"))]
39-
() => {}
29+
() => unimplemented!(),
4030
}
4131
}
4232

src/register/apsr.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ impl Apsr {
3939
}
4040

4141
/// Reads the CPU register
42-
#[inline(always)]
42+
#[inline]
4343
pub fn read() -> Apsr {
44-
let r: u32;
45-
unsafe {
46-
asm!("mrs $0, APSR"
47-
: "=r"(r)
48-
:
49-
:
50-
: "volatile");
44+
match () {
45+
#[cfg(target_arch = "arm")]
46+
() => {
47+
let r: u32;
48+
unsafe {
49+
asm!("mrs $0, APSR" : "=r"(r) ::: "volatile");
50+
}
51+
Apsr { bits: r }
52+
}
53+
#[cfg(not(target_arch = "arm"))]
54+
() => unimplemented!(),
5155
}
52-
Apsr { bits: r }
5356
}

src/register/basepri.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
//! Base Priority Mask Register
22
33
/// Reads the CPU register
4-
#[inline(always)]
4+
#[inline]
55
pub fn read() -> u8 {
6-
let r: u32;
7-
unsafe {
8-
asm!("mrs $0, BASEPRI"
9-
: "=r"(r)
10-
:
11-
:
12-
: "volatile");
6+
match () {
7+
#[cfg(target_arch = "arm")]
8+
() => {
9+
let r: u32;
10+
unsafe {
11+
asm!("mrs $0, BASEPRI" : "=r"(r) ::: "volatile");
12+
}
13+
r as u8
14+
}
15+
#[cfg(not(target_arch = "arm"))]
16+
() => unimplemented!(),
1317
}
14-
r as u8
1518
}
1619

1720
/// Writes to the CPU register
18-
#[inline(always)]
19-
pub unsafe fn write(basepri: u8) {
20-
asm!("msr BASEPRI, $0"
21-
:
22-
: "r"(basepri)
23-
: "memory"
24-
: "volatile");
21+
#[inline]
22+
pub unsafe fn write(_basepri: u8) {
23+
match () {
24+
#[cfg(target_arch = "arm")]
25+
() => asm!("msr BASEPRI, $0" :: "r"(_basepri) : "memory" : "volatile"),
26+
#[cfg(not(target_arch = "arm"))]
27+
() => unimplemented!(),
28+
}
2529
}

src/register/basepri_max.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
///
55
/// - `basepri != 0` AND `basepri::read() == 0`, OR
66
/// - `basepri != 0` AND `basepri < basepri::read()`
7-
#[inline(always)]
8-
pub fn write(basepri: u8) {
9-
unsafe {
10-
asm!("msr BASEPRI_MAX, $0"
11-
:
12-
: "r"(basepri)
13-
: "memory"
14-
: "volatile");
7+
#[inline]
8+
pub fn write(_basepri: u8) {
9+
match () {
10+
#[cfg(target_arch = "arm")]
11+
() => unsafe {
12+
asm!("msr BASEPRI_MAX, $0" :: "r"(_basepri) : "memory" : "volatile");
13+
},
14+
#[cfg(not(target_arch = "arm"))]
15+
() => unimplemented!(),
1516
}
1617
}

src/register/control.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,16 @@ impl Fpca {
104104
}
105105

106106
/// Reads the CPU register
107-
#[inline(always)]
107+
#[inline]
108108
pub fn read() -> Control {
109-
let r: u32;
110-
unsafe {
111-
asm!("mrs $0, CONTROL"
112-
: "=r"(r)
113-
:
114-
:
115-
: "volatile");
109+
match () {
110+
#[cfg(target_arch = "arm")]
111+
() => {
112+
let r: u32;
113+
unsafe { asm!("mrs $0, CONTROL" : "=r"(r) ::: "volatile") }
114+
Control { bits: r }
115+
}
116+
#[cfg(not(target_arch = "arm"))]
117+
() => unimplemented!(),
116118
}
117-
Control { bits: r }
118119
}

src/register/faultmask.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@ impl Faultmask {
2222
}
2323

2424
/// Reads the CPU register
25-
#[inline(always)]
25+
#[inline]
2626
pub fn read() -> Faultmask {
27-
let r: u32;
28-
unsafe {
29-
asm!("mrs $0, FAULTMASK"
30-
: "=r"(r)
31-
:
32-
:
33-
: "volatile");
34-
}
35-
if r & (1 << 0) == (1 << 0) {
36-
Faultmask::Inactive
37-
} else {
38-
Faultmask::Active
27+
match () {
28+
#[cfg(target_arch = "arm")]
29+
() => {
30+
let r: u32;
31+
unsafe { asm!("mrs $0, FAULTMASK" : "=r"(r) ::: "volatile") }
32+
if r & (1 << 0) == (1 << 0) {
33+
Faultmask::Inactive
34+
} else {
35+
Faultmask::Active
36+
}
37+
}
38+
#[cfg(not(target_arch = "arm"))]
39+
() => unimplemented!(),
3940
}
4041
}

src/register/lr.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
//! Link register
22
33
/// Reads the CPU register
4-
#[inline(always)]
4+
#[inline]
55
pub fn read() -> u32 {
6-
let r: u32;
7-
unsafe {
8-
asm!("mov $0,R14"
9-
: "=r"(r)
10-
:
11-
:
12-
: "volatile");
6+
match () {
7+
#[cfg(target_arch = "arm")]
8+
() => {
9+
let r: u32;
10+
unsafe { asm!("mov $0,R14" : "=r"(r) ::: "volatile") }
11+
r
12+
}
13+
#[cfg(not(target_arch = "arm"))]
14+
() => unimplemented!(),
1315
}
14-
r
1516
}
1617

1718
/// Writes `bits` to the CPU register
18-
#[inline(always)]
19+
#[cfg_attr(not(target_arch = "arm"), allow(unused_variables))]
20+
#[inline]
1921
pub unsafe fn write(bits: u32) {
20-
asm!("mov R14,$0"
21-
:
22-
: "r"(bits)
23-
:
24-
: "volatile");
22+
match () {
23+
#[cfg(target_arch = "arm")]
24+
() => asm!("mov R14,$0" :: "r"(bits) :: "volatile"),
25+
#[cfg(not(target_arch = "arm"))]
26+
() => unimplemented!(),
27+
}
2528
}

0 commit comments

Comments
 (0)