Skip to main content

cortex_m/register/
psp.rs

1//! Process Stack Pointer
2
3#[cfg(cortex_m)]
4use core::arch::asm;
5use cortex_m_macros::asm_cfg;
6
7/// Reads the CPU register
8#[inline]
9#[asm_cfg(cortex_m)]
10pub fn read() -> u32 {
11    let r;
12    unsafe { asm!("mrs {}, PSP", out(reg) r, options(nomem, nostack, preserves_flags)) };
13    r
14}
15
16/// Writes `bits` to the CPU register
17#[inline]
18#[asm_cfg(cortex_m)]
19pub unsafe fn write(bits: u32) {
20    // See comment on __msp_w. Unlike MSP, there are legitimate use-cases for modifying PSP
21    // if MSP is currently being used as the stack pointer.
22    unsafe { asm!("msr PSP, {}", in(reg) bits, options(nomem, nostack, preserves_flags)) };
23}