Skip to content

Commit afcc777

Browse files
japaricgnzlbg
authored andcommitted
add CMSIS / Cortex-M instrinsics
1 parent 97742f0 commit afcc777

File tree

2 files changed

+269
-0
lines changed

2 files changed

+269
-0
lines changed

coresimd/arm/cmsis.rs

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
#![allow(non_snake_case)]
2+
3+
/// Extracted from [CMSIS 5]'s CMSIS/Core/Include/cmsis_gcc.h
4+
///
5+
/// [CMSIS 5]: https://github.com/ARM-software/CMSIS_5
6+
7+
/* Core function access */
8+
9+
/// Enable IRQ Interrupts
10+
///
11+
/// Enables IRQ interrupts by clearing the I-bit in the CPSR. Can only be
12+
/// executed in Privileged modes.
13+
#[inline(always)]
14+
pub unsafe fn __enable_irq() {
15+
asm!("cpsie i" : : : "memory" : "volatile");
16+
}
17+
18+
/// Disable IRQ Interrupts
19+
///
20+
/// Disables IRQ interrupts by setting the I-bit in the CPSR. Can only be
21+
/// executed in Privileged modes.
22+
#[inline(always)]
23+
pub unsafe fn __disable_irq() {
24+
asm!("cpsid i" : : : "memory" : "volatile");
25+
}
26+
27+
/// Get Control Register
28+
///
29+
/// Returns the content of the Control Register.
30+
#[inline(always)]
31+
pub unsafe fn __get_CONTROL() -> u32 {
32+
let result: u32;
33+
asm!("mrs $0, CONTROL" : "=r"(result) : : : "volatile");
34+
result
35+
}
36+
37+
/// Set Control Register
38+
///
39+
/// Writes the given value to the Control Register.
40+
#[inline(always)]
41+
pub unsafe fn __set_CONTROL(control: u32) {
42+
asm!("msr CONTROL, $0" : : "r"(control) : "memory" : "volatile");
43+
}
44+
45+
/// Get IPSR Register
46+
///
47+
/// Returns the content of the IPSR Register.
48+
#[inline(always)]
49+
pub unsafe fn __get_IPSR() -> u32 {
50+
let result: u32;
51+
asm!("mrs $0, IPSR" : "=r"(result) : : : "volatile");
52+
result
53+
}
54+
55+
/// Get APSR Register
56+
///
57+
/// Returns the content of the APSR Register.
58+
#[inline(always)]
59+
pub unsafe fn __get_APSR() -> u32 {
60+
let result: u32;
61+
asm!("mrs $0, APSR" : "=r"(result) : : : "volatile");
62+
result
63+
}
64+
65+
/// Get xPSR Register
66+
///
67+
/// Returns the content of the xPSR Register.
68+
#[inline(always)]
69+
pub unsafe fn __get_xPSR() -> u32 {
70+
let result: u32;
71+
asm!("mrs $0, XPSR" : "=r"(result) : : : "volatile");
72+
result
73+
}
74+
75+
/// Get Process Stack Pointer
76+
///
77+
/// Returns the current value of the Process Stack Pointer (PSP).
78+
#[inline(always)]
79+
pub unsafe fn __get_PSP() -> u32 {
80+
let result: u32;
81+
asm!("mrs $0, PSP" : "=r"(result) : : : "volatile");
82+
result
83+
}
84+
85+
/// Set Process Stack Pointer
86+
///
87+
/// Assigns the given value to the Process Stack Pointer (PSP).
88+
#[inline(always)]
89+
pub unsafe fn __set_PSP(top_of_proc_stack: u32) {
90+
asm!("msr PSP, $0" : : "r"(top_of_proc_stack) : : "volatile");
91+
}
92+
93+
/// Get Main Stack Pointer
94+
///
95+
/// Returns the current value of the Main Stack Pointer (MSP).
96+
#[inline(always)]
97+
pub unsafe fn __get_MSP() -> u32 {
98+
let result: u32;
99+
asm!("mrs $0, MSP" : "=r"(result) : : : "volatile");
100+
result
101+
}
102+
103+
/// Set Main Stack Pointer
104+
///
105+
/// Assigns the given value to the Main Stack Pointer (MSP).
106+
#[inline(always)]
107+
pub unsafe fn __set_MSP(top_of_main_stack: u32) {
108+
asm!("msr MSP, $0" : : "r"(top_of_main_stack) : : "volatile");
109+
}
110+
111+
/// Get Priority Mask
112+
///
113+
/// Returns the current state of the priority mask bit from the Priority Mask
114+
/// Register.
115+
#[inline(always)]
116+
pub unsafe fn __get_PRIMASK() -> u32 {
117+
let result: u32;
118+
asm!("mrs $0, PRIMASK" : "=r"(result) : : "memory" : "volatile");
119+
result
120+
}
121+
122+
/// Set Priority Mask
123+
///
124+
/// Assigns the given value to the Priority Mask Register.
125+
#[inline(always)]
126+
pub unsafe fn __set_PRIMASK(pri_mask: u32) {
127+
asm!("msr PRIMASK, $0" : : "r"(pri_mask) : : "volatile");
128+
}
129+
130+
#[cfg(target_feature = "v7")]
131+
mod v7 {
132+
/// Enable FIQ
133+
///
134+
/// Enables FIQ interrupts by clearing the F-bit in the CPSR. Can only be
135+
/// executed in Privileged modes.
136+
#[inline(always)]
137+
pub unsafe fn __enable_fault_irq() {
138+
asm!("cpsie f" : : : "memory" : "volatile");
139+
}
140+
141+
/// Disable FIQ
142+
///
143+
/// Disables FIQ interrupts by setting the F-bit in the CPSR. Can only be
144+
/// executed in Privileged modes.
145+
#[inline(always)]
146+
pub unsafe fn __disable_fault_irq() {
147+
asm!("cpsid f" : : : "memory" : "volatile");
148+
}
149+
150+
/// Get Base Priority
151+
///
152+
/// Returns the current value of the Base Priority register.
153+
#[inline(always)]
154+
pub unsafe fn __get_BASEPRI() -> u32 {
155+
let result: u32;
156+
asm!("mrs $0, BASEPRI" : "=r"(result) : : : "volatile");
157+
result
158+
}
159+
160+
/// Set Base Priority
161+
///
162+
/// Assigns the given value to the Base Priority register.
163+
#[inline(always)]
164+
pub unsafe fn __set_BASEPRI(base_pri: u32) {
165+
asm!("msr BASEPRI, $0" : : "r"(base_pri) : "memory" : "volatile");
166+
}
167+
168+
/// Set Base Priority with condition
169+
///
170+
/// Assigns the given value to the Base Priority register only if BASEPRI
171+
/// masking is disabled, or the new value increases the BASEPRI
172+
/// priority level.
173+
#[inline(always)]
174+
pub unsafe fn __set_BASEPRI_MAX(base_pri: u32) {
175+
asm!("msr BASEPRI_MAX, $0" : : "r"(base_pri) : "memory" : "volatile");
176+
}
177+
178+
/// Get Fault Mask
179+
///
180+
/// Returns the current value of the Fault Mask register.
181+
#[inline(always)]
182+
pub unsafe fn __get_FAULTMASK() -> u32 {
183+
let result: u32;
184+
asm!("mrs $0, FAULTMASK" : "=r"(result) : : : "volatile");
185+
result
186+
}
187+
188+
/// Set Fault Mask
189+
///
190+
/// Assigns the given value to the Fault Mask register.
191+
#[inline(always)]
192+
pub unsafe fn __set_FAULTMASK(fault_mask: u32) {
193+
asm!("msr FAULTMASK, $0" : : "r"(fault_mask) : "memory" : "volatile");
194+
}
195+
}
196+
197+
#[cfg(target_feature = "v7")]
198+
pub use self::v7::*;
199+
200+
/* Core instruction access */
201+
202+
/// No Operation
203+
///
204+
/// No Operation does nothing. This instruction can be used for code alignment
205+
/// purposes.
206+
#[inline(always)]
207+
pub unsafe fn __NOP() {
208+
asm!("nop" : : : : "volatile");
209+
}
210+
211+
/// Wait For Interrupt
212+
///
213+
/// Wait For Interrupt is a hint instruction that suspends execution until one
214+
/// of a number of events occurs.
215+
#[inline(always)]
216+
pub unsafe fn __WFI() {
217+
asm!("wfi" : : : : "volatile");
218+
}
219+
220+
/// Wait For Event
221+
///
222+
/// Wait For Event is a hint instruction that permits the processor to enter a
223+
/// low-power state until one of a number of events occurs.
224+
#[inline(always)]
225+
pub unsafe fn __WFE() {
226+
asm!("wfe" : : : : "volatile");
227+
}
228+
229+
/// Send Event
230+
///
231+
/// Send Event is a hint instruction. It causes an event to be signaled to the
232+
/// CPU.
233+
#[inline(always)]
234+
pub unsafe fn __SEV() {
235+
asm!("sev" : : : : "volatile");
236+
}
237+
238+
/// Instruction Synchronization Barrier
239+
///
240+
/// Instruction Synchronization Barrier flushes the pipeline in the processor,
241+
/// so that all instructions following the ISB are fetched from cache or
242+
/// memory, after the instruction has been completed.
243+
#[inline(always)]
244+
pub unsafe fn __ISB() {
245+
asm!("isb 0xF" : : : "memory" : "volatile");
246+
}
247+
248+
/// Data Synchronization Barrier
249+
///
250+
/// Acts as a special kind of Data Memory Barrier. It completes when all
251+
/// explicit memory accesses before this instruction complete.
252+
#[inline(always)]
253+
pub unsafe fn __DSB() {
254+
asm!("dsb 0xF" : : : "memory" : "volatile");
255+
}
256+
257+
/// Data Memory Barrier
258+
///
259+
/// Ensures the apparent order of the explicit memory operations before and
260+
/// after the instruction, without ensuring their completion.
261+
#[inline(always)]
262+
pub unsafe fn __DMB() {
263+
asm!("dmb 0xF" : : : "memory" : "volatile");
264+
}

coresimd/arm/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
//! [arm_dat]: https://developer.arm.com/technologies/neon/intrinsics
88
#![allow(non_camel_case_types)]
99

10+
#[cfg(target_feature = "mclass")]
11+
mod cmsis;
12+
#[cfg(target_feature = "mclass")]
13+
pub use self::cmsis::*;
14+
1015
mod v6;
1116
pub use self::v6::*;
1217

0 commit comments

Comments
 (0)