1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#[derive(Clone, Copy, Debug)]
pub struct Apsr {
bits: u32,
}
impl Apsr {
pub fn bits(&self) -> u32 {
self.bits
}
pub fn q(&self) -> bool {
self.bits & (1 << 27) == (1 << 27)
}
pub fn v(&self) -> bool {
self.bits & (1 << 28) == (1 << 28)
}
pub fn c(&self) -> bool {
self.bits & (1 << 29) == (1 << 29)
}
pub fn z(&self) -> bool {
self.bits & (1 << 30) == (1 << 30)
}
pub fn n(&self) -> bool {
self.bits & (1 << 31) == (1 << 31)
}
}
#[inline]
pub fn read() -> Apsr {
match () {
#[cfg(cortex_m)]
() => {
let r: u32;
unsafe {
asm!("mrs $0, APSR" : "=r"(r) ::: "volatile");
}
Apsr { bits: r }
}
#[cfg(not(cortex_m))]
() => unimplemented!(),
}
}