|
1 | 1 | // Reference: Section 7.4 "Hints" of ACLE |
2 | 2 |
|
| 3 | +// CP15 instruction |
| 4 | +#[cfg(not(any( |
| 5 | + // v8 |
| 6 | + target_arch = "aarch64", |
| 7 | + // v7 |
| 8 | + target_feature = "v7", |
| 9 | + // v6-M |
| 10 | + target_feature = "mclass" |
| 11 | +)))] |
| 12 | +mod cp15; |
| 13 | + |
| 14 | +#[cfg(not(any( |
| 15 | + target_arch = "aarch64", |
| 16 | + target_feature = "v7", |
| 17 | + target_feature = "mclass" |
| 18 | +)))] |
| 19 | +pub use self::cp15::*; |
| 20 | + |
| 21 | +// Dedicated instructions |
3 | 22 | macro_rules! dmb_dsb { |
4 | 23 | ($A:ident) => { |
5 | 24 | impl super::super::sealed::Dmb for $A { |
6 | 25 | #[inline(always)] |
7 | 26 | unsafe fn __dmb(&self) { |
8 | | - asm!(concat!("DMB ", stringify!($A)) : : : "memory" : "volatile") |
| 27 | + super::dmb(super::arg::$A) |
9 | 28 | } |
10 | 29 | } |
11 | 30 |
|
12 | 31 | impl super::super::sealed::Dsb for $A { |
13 | 32 | #[inline(always)] |
14 | 33 | unsafe fn __dsb(&self) { |
15 | | - asm!(concat!("DSB ", stringify!($A)) : : : "memory" : "volatile") |
| 34 | + super::dsb(super::arg::$A) |
16 | 35 | } |
17 | 36 | } |
18 | 37 | }; |
19 | 38 | } |
20 | 39 |
|
| 40 | +#[cfg(any( |
| 41 | + target_arch = "aarch64", |
| 42 | + target_feature = "v7", |
| 43 | + target_feature = "mclass" |
| 44 | +))] |
21 | 45 | mod common; |
22 | 46 |
|
| 47 | +#[cfg(any( |
| 48 | + target_arch = "aarch64", |
| 49 | + target_feature = "v7", |
| 50 | + target_feature = "mclass" |
| 51 | +))] |
23 | 52 | pub use self::common::*; |
24 | 53 |
|
25 | | -#[cfg(not(target_feature = "mclass"))] |
| 54 | +#[cfg(any( |
| 55 | + target_arch = "aarch64", |
| 56 | + target_feature = "v7", |
| 57 | +))] |
26 | 58 | mod not_mclass; |
27 | 59 |
|
28 | | -#[cfg(not(target_feature = "mclass"))] |
| 60 | +#[cfg(any( |
| 61 | + target_arch = "aarch64", |
| 62 | + target_feature = "v7", |
| 63 | +))] |
29 | 64 | pub use self::not_mclass::*; |
30 | 65 |
|
31 | 66 | #[cfg(target_arch = "aarch64")] |
@@ -87,3 +122,34 @@ where |
87 | 122 | { |
88 | 123 | arg.__isb() |
89 | 124 | } |
| 125 | + |
| 126 | +extern "C" { |
| 127 | + #[cfg_attr(target_arch = "aarch64", link_name = "llvm.aarch64.dmb")] |
| 128 | + #[cfg_attr(target_arch = "arm", link_name = "llvm.arm.dmb")] |
| 129 | + fn dmb(_: i32); |
| 130 | + |
| 131 | + #[cfg_attr(target_arch = "aarch64", link_name = "llvm.aarch64.dsb")] |
| 132 | + #[cfg_attr(target_arch = "arm", link_name = "llvm.arm.dsb")] |
| 133 | + fn dsb(_: i32); |
| 134 | + |
| 135 | + #[cfg_attr(target_arch = "aarch64", link_name = "llvm.aarch64.isb")] |
| 136 | + #[cfg_attr(target_arch = "arm", link_name = "llvm.arm.isb")] |
| 137 | + fn isb(_: i32); |
| 138 | +} |
| 139 | + |
| 140 | +// we put these in a module to prevent weirdness with glob re-exports |
| 141 | +mod arg { |
| 142 | + // See Section 7.3 Memory barriers of ACLE |
| 143 | + pub const SY: i32 = 15; |
| 144 | + pub const ST: i32 = 14; |
| 145 | + pub const LD: i32 = 13; |
| 146 | + pub const ISH: i32 = 11; |
| 147 | + pub const ISHST: i32 = 10; |
| 148 | + pub const ISHLD: i32 = 9; |
| 149 | + pub const NSH: i32 = 7; |
| 150 | + pub const NSHST: i32 = 6; |
| 151 | + pub const NSHLD: i32 = 5; |
| 152 | + pub const OSH: i32 = 3; |
| 153 | + pub const OSHST: i32 = 2; |
| 154 | + pub const OSHLD: i32 = 1; |
| 155 | +} |
0 commit comments