Skip to content

Commit

Permalink
arch: arm: cortex_a_r: Fix usage of stmdb while entering an exception
Browse files Browse the repository at this point in the history
This commit fixes the unpredictable behavior, caused by using the
^ form of stmdb instruction, while entering an exception in SMP mode
on Cortex-A/R.

Change:
Use "push" instead of "stmdb" to store user mode registers on
stack while entering an exception in SYStem mode.

Reason for change:
As reported in discussion/#75339, processor is already in SYS mode
after entering `z_arm_cortex_ar_enter_exc()` in an exception and
using stmdb is UNPREDICTABLE in system mode. Also, the user mode
register can be accessed directly without the ^ form of the
instruction. The solution suggested to fix this is to use
`stmdb sp!, {r0-r3, r12, lr}` which can save the user registers,
update the SP and avoid an extra instruction.
We use "push {}" instruction instead since it is the preferred
mnemonic over `stmdb`.

Signed-off-by: Sudan Landge <[email protected]>
  • Loading branch information
wearyzen authored and nashif committed Aug 15, 2024
1 parent 2f64e7c commit 6d8deac
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions arch/arm/core/cortex_a_r/macro_priv.inc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
*/
srsdb sp!, #MODE_SYS
cps #MODE_SYS
stmdb sp, {r0-r3, r12, lr}^
sub sp, #24
push {r0-r3, r12, lr}

/* TODO: EXTRA_EXCEPTION_INFO */
mov r0, sp
Expand Down

0 comments on commit 6d8deac

Please sign in to comment.