Skip to content

Commit 7c3f48e

Browse files
Fix issue where _stack_setup assumed you were in sys mode.
1 parent ff75c22 commit 7c3f48e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cortex-r-rt/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,15 @@ core::arch::global_asm!(
488488
// Work around https://github.com/rust-lang/rust/issues/127269
489489
.fpu vfp3-d16
490490
491-
// Pass in stack top in r0
491+
// Configure a stack for every mode. Leaves you in sys mode.
492+
//
493+
// Pass in stack top in r0.
492494
.global _stack_setup
493495
.type _stack_setup, %function
494496
_stack_setup:
497+
// Save LR from whatever mode we're currently in
498+
mov r2, lr
499+
// (we might not be in the same mode when we return).
495500
// Set stack pointer (right after) and mask interrupts for for UND mode (Mode 0x1B)
496501
msr cpsr, {und_mode}
497502
mov sp, r0
@@ -520,11 +525,12 @@ core::arch::global_asm!(
520525
// Set stack pointer (right after) and mask interrupts for for System mode (Mode 0x1F)
521526
msr cpsr, {sys_mode}
522527
mov sp, r0
523-
// Clear the Thumb Exception bit because we're in Arm mode
528+
// Clear the Thumb Exception bit because all our targets are currently
529+
// for Arm (A32) mode
524530
mrc p15, 0, r0, c1, c0, 0
525531
bic r0, #{te_bit}
526532
mcr p15, 0, r0, c1, c0, 0
527-
bx lr
533+
bx r2
528534
.size _stack_setup, . - _stack_setup
529535
530536
.type _el1_start, %function

0 commit comments

Comments
 (0)