From 50e77c2f9a76990a8a78ac0b6762136c0c28ea18 Mon Sep 17 00:00:00 2001 From: Dat Nguyen Duy Date: Tue, 17 Jan 2023 14:25:30 +0700 Subject: [PATCH] arch: arm: aarch32: cortex_a_r: disable interrupts before context switching Ultil now Cortex A/R aarch32 implementation for context switching expects that interrupts was disabled. This is true if a context switching happens at thread context. But if a context switching happens at last action during interrupt context, this assumption is not true because the interrupts are still enabled (to allow nesting interrupts). Disable interrupts at the last interrupt action to ensure the interrupts are always disabled before context switching is processed Signed-off-by: Dat Nguyen Duy --- arch/arm/core/aarch32/cortex_a_r/exc_exit.S | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/arm/core/aarch32/cortex_a_r/exc_exit.S b/arch/arm/core/aarch32/cortex_a_r/exc_exit.S index d10c9f7ce67..2978f64ae0e 100644 --- a/arch/arm/core/aarch32/cortex_a_r/exc_exit.S +++ b/arch/arm/core/aarch32/cortex_a_r/exc_exit.S @@ -129,6 +129,11 @@ SECTION_SUBSEC_FUNC(TEXT, _HandlerModeExit, z_arm_int_exit) bl z_check_stack_sentinel #endif /* CONFIG_STACK_SENTINEL */ + /* Disable nested interrupts while exiting, this should happens + * before context switch also, to ensure interrupts are disabled. + */ + cpsid i + #ifdef CONFIG_PREEMPT_ENABLED /* Do not context switch if exiting a nested interrupt */ ldr r3, =_kernel @@ -143,9 +148,6 @@ SECTION_SUBSEC_FUNC(TEXT, _HandlerModeExit, z_arm_int_exit) __EXIT_INT: #endif /* CONFIG_PREEMPT_ENABLED */ - /* Disable nested interrupts while exiting */ - cpsid i - /* Decrement interrupt nesting count */ ldr r2, =_kernel ldr r0, [r2, #_kernel_offset_to_nested]