AArch32 exception exit routine behaves incorrectly on fatal exceptions #31511
Labels
area: ARM
ARM (32-bit) Architecture
area: Exception Handling
bug
The issue is a bug, or the PR is fixing a bug
priority: medium
Medium impact/importance bug
Milestone
The AArch32 exception exit routine (
z_arm_exc_exit
) behaves incorrectly on fatal exceptions.There are two bugs that are currently identified in the
z_arm_exc_exit
implementation:1. Invalid return address when calling
z_arm_pendsv
When an exception is fatal and the current thread is aborted, the
z_arm_exc_exit
attempts to switch to the next scheduled thread by invokingz_arm_pendsv
:zephyr/arch/arm/core/aarch32/cortex_a_r/exc_exit.S
Lines 121 to 135 in c31ce55
The
z_arm_exc_exit
function is invoked by the exception handlers in the corresponding exception mode (e.g.MODE_UND
for undefined instruction exception), and the branch toz_arm_pendsv
here saves the return address to the corresponding exception mode link register (e.g.lr_und
for undefined instruction exception).The
z_arm_pendsv
function assumes that the calling mode is the SVC mode, as is the case for the normal IRQs handled by the_isr_wrapper
, and switches to the SVC mode during context switch:zephyr/arch/arm/core/aarch32/swap_helper.S
Lines 349 to 352 in c31ce55
When the
z_arm_pendsv
function returns, the current execution mode is the SVC mode, and the value oflr
at this point is that oflr_svc
.2. Caller-saved register is referenced after a call
The following code incorrectly assumes that
r3
, a caller-saved register, contains_kernel
after a call toz_arm_pendsv
:zephyr/arch/arm/core/aarch32/cortex_a_r/exc_exit.S
Lines 134 to 140 in c31ce55
r3
must be reloaded at this point. Note that using a callee-saved register here is not an option becausez_arm_pendsv
exits with the callee-saved registers of the incoming context.The text was updated successfully, but these errors were encountered: