Skip to content

Commit ecf5ddc

Browse files
committed
Set the PSPLIM when switching to the PSP on Armv8-M Mainline.
1 parent 14e748f commit ecf5ddc

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

cortex-m/src/psp.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,27 @@ impl<const N: usize> core::default::Default for Stack<N> {
8181
///
8282
#[cfg(cortex_m)]
8383
pub fn switch_to_unprivileged_psp(mut psp_stack: StackHandle, function: extern "C" fn() -> !) -> ! {
84-
unsafe { crate::asm::enter_unprivileged_psp(psp_stack.top(), function) }
84+
// set the stack limit
85+
#[cfg(armv8m_main)]
86+
unsafe {
87+
crate::register::psplim::write(psp_stack.bottom() as u32);
88+
}
89+
// do the switch
90+
unsafe {
91+
crate::asm::enter_unprivileged_psp(psp_stack.top(), function);
92+
}
8593
}
8694

8795
/// Switch to running on the Process Stack Pointer (PSP), but remain in privileged mode
8896
#[cfg(cortex_m)]
8997
pub fn switch_to_privileged_psp(mut psp_stack: StackHandle, function: extern "C" fn() -> !) -> ! {
90-
unsafe { crate::asm::enter_privileged_psp(psp_stack.top(), function) }
98+
// set the stack limit
99+
#[cfg(armv8m_main)]
100+
unsafe {
101+
crate::register::psplim::write(psp_stack.bottom() as u32);
102+
}
103+
// do the switch
104+
unsafe {
105+
crate::asm::enter_privileged_psp(psp_stack.top(), function);
106+
}
91107
}

0 commit comments

Comments
 (0)