Skip to content

Commit c4d897e

Browse files
committed
Add barrier instructions
1 parent 14851f2 commit c4d897e

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/asm.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,53 @@ pub fn wfi() {
5858
() => {}
5959
}
6060
}
61+
62+
/// Instruction Synchronization Barrier
63+
///
64+
/// Flushes the pipeline in the processor, so that all instructions following the `ISB` are fetched
65+
/// from cache or memory, after the instruction has been completed.
66+
pub fn isb() {
67+
match () {
68+
#[cfg(target_arch = "arm")]
69+
() => unsafe {
70+
asm!("isb 0xF" : : : "memory" : "volatile");
71+
},
72+
#[cfg(not(target_arch = "arm"))]
73+
() => {}
74+
}
75+
}
76+
77+
/// Data Synchronization Barrier
78+
///
79+
/// Acts as a special kind of memory barrier. No instruction in program order after this
80+
/// instruction can execute until this instruction completes. This instruction completes only when
81+
/// both:
82+
///
83+
/// * any explicit memory access made before this instruction is complete
84+
/// * all cache and branch predictor maintenance operations before this instruction complete
85+
pub fn dsb() {
86+
match () {
87+
#[cfg(target_arch = "arm")]
88+
() => unsafe {
89+
asm!("dsb 0xF" : : : "memory" : "volatile");
90+
},
91+
#[cfg(not(target_arch = "arm"))]
92+
() => {}
93+
}
94+
}
95+
96+
/// Data Memory Barrier
97+
///
98+
/// Ensures that all explicit memory accesses that appear in program order before the `DMB`
99+
/// instruction are observed before any explicit memory accesses that appear in program order
100+
/// after the `DMB` instruction.
101+
pub fn dmb() {
102+
match () {
103+
#[cfg(target_arch = "arm")]
104+
() => unsafe {
105+
asm!("dmb 0xF" : : : "memory" : "volatile");
106+
},
107+
#[cfg(not(target_arch = "arm"))]
108+
() => {}
109+
}
110+
}

0 commit comments

Comments
 (0)