From 8c4de7e4b092de3f67492568737198f99edf240e Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Thu, 26 Sep 2019 15:03:34 +0900 Subject: [PATCH] arch: arm: Remove unnecessary register preservation in Cortex-R port. The interrupt exit and swap service routines for Cortex-R unnecessarily preserve r0 and lr registers when making function calls using bl instruction. In case of _IntExit in exc_exit.S, the r0 register containing the caller mode is preserved at the top, and the lr register can safely be assumed to have been saved into the system mode stack by the interrupt service routine. In case of __svc in swap_helper.S, since the function saves lr to the system mode stack at the top and exits through _IntExit, it is not necessary to preserve lr register when executing bl instructions. Signed-off-by: Stephanos Ioannidis --- arch/arm/core/exc_exit.S | 6 ++++-- arch/arm/core/swap_helper.S | 4 ---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/arm/core/exc_exit.S b/arch/arm/core/exc_exit.S index 012f54f9d00..051f8ea506c 100644 --- a/arch/arm/core/exc_exit.S +++ b/arch/arm/core/exc_exit.S @@ -90,9 +90,7 @@ SECTION_SUBSEC_FUNC(TEXT, _HandlerModeExit, z_arm_exc_exit) ldr r2, =_SCS_ICSR_PENDSV str r2, [r1] #elif defined(CONFIG_CPU_CORTEX_R) - push {r0, lr} bl z_arm_pendsv - pop {r0, lr} #endif _ExcExitWithGdbStub: @@ -101,6 +99,7 @@ _EXIT_EXC: #endif /* CONFIG_PREEMPT_ENABLED */ #ifdef CONFIG_STACK_SENTINEL +#if defined(CONFIG_CPU_CORTEX_M) push {r0, lr} bl z_check_stack_sentinel #if defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE) @@ -109,6 +108,9 @@ _EXIT_EXC: #else pop {r0, lr} #endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */ +#else + bl z_check_stack_sentinel +#endif /* CONFIG_CPU_CORTEX_M */ #endif /* CONFIG_STACK_SENTINEL */ #if defined(CONFIG_CPU_CORTEX_M) diff --git a/arch/arm/core/swap_helper.S b/arch/arm/core/swap_helper.S index a3535ce1b57..4fa0a329080 100644 --- a/arch/arm/core/swap_helper.S +++ b/arch/arm/core/swap_helper.S @@ -560,9 +560,7 @@ demux: beq _oops #if CONFIG_IRQ_OFFLOAD - push {r0, lr} blx z_irq_do_offload /* call C routine which executes the offload */ - pop {r0, lr} /* exception return is done in z_arm_int_exit() */ mov r0, #RET_FROM_SVC @@ -571,9 +569,7 @@ demux: _context_switch: /* handler mode exit, to PendSV */ - push {r0, lr} bl z_arm_pendsv - pop {r0, lr} mov r0, #RET_FROM_SVC b z_arm_int_exit