Skip to content

Commit 763daec

Browse files
committed
Add a CPSR write function.
Comes with big scary warning sign though.
1 parent ddf15c5 commit 763daec

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cortex-r/src/register/cpsr.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,26 @@ impl Cpsr {
8181
}
8282
Self::new_with_raw_value(r)
8383
}
84+
85+
/// Writes the *Current Program Status Register*
86+
///
87+
/// # Safety
88+
///
89+
/// Changing the Program Status Register can affect whether interrupts are
90+
/// enabled, whether we are executing Arm or Thumb instructions, or which
91+
/// processor mode are in. You must be absolutely certain that the new CPSR
92+
/// value is valid and appropriate for continued Rust code execution.
93+
///
94+
/// You almost certainly want to follow this with an [ISB](crate::asm::isb)
95+
/// instruction.
96+
#[inline]
97+
pub unsafe fn write(_value: Self) {
98+
// Safety: We're in an unsafe function
99+
#[cfg(target_arch = "arm")]
100+
unsafe {
101+
core::arch::asm!("msr CPSR, {}", in(reg) _value.raw_value());
102+
}
103+
}
84104
}
85105

86106
impl core::fmt::Debug for Cpsr {

0 commit comments

Comments
 (0)