Skip to content

Commit cd90d49

Browse files
stephanosioioannisg
authored andcommitted
arch: arm: Optimise Cortex-R exception return function.
z_arm_exc_exit (z_arm_int_exit) requires the current execution mode to be specified as a parameter (through r0). This is not necessary because this value can be directly read from CPSR. This commit modifies the exception return function to retrieve the current execution mode from CPSR and removes all provisions for passing the execution mode parameter. Signed-off-by: Stephanos Ioannidis <[email protected]>
1 parent 1c3b46d commit cd90d49

File tree

4 files changed

+4
-27
lines changed

4 files changed

+4
-27
lines changed

arch/arm/core/aarch32/exc_exit.S

+4-18
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ SECTION_SUBSEC_FUNC(TEXT, _HandlerModeExit, z_arm_int_exit)
7171
*/
7272

7373
SECTION_SUBSEC_FUNC(TEXT, _HandlerModeExit, z_arm_exc_exit)
74-
#if defined(CONFIG_CPU_CORTEX_R)
75-
/* r0 contains the caller mode */
76-
push {r0, lr}
77-
#endif
7874

7975
#ifdef CONFIG_PREEMPT_ENABLED
8076
ldr r0, =_kernel
@@ -117,9 +113,6 @@ _EXIT_EXC:
117113
#if defined(CONFIG_CPU_CORTEX_M)
118114
bx lr
119115
#elif defined(CONFIG_CPU_CORTEX_R)
120-
/* Restore the caller mode to r0 */
121-
pop {r0, lr}
122-
123116
/*
124117
* Restore r0-r3, r12 and lr stored into the process stack by the mode
125118
* entry function. These registers are saved by _isr_wrapper for IRQ mode
@@ -128,22 +121,15 @@ _EXIT_EXC:
128121
* r0-r3 are either the values from the thread before it was switched out
129122
* or they are the args to _new_thread for a new thread.
130123
*/
131-
push {r4, r5}
124+
push {r4-r6}
125+
mrs r6, cpsr
132126

133-
cmp r0, #RET_FROM_SVC
134127
cps #MODE_SYS
135128
ldmia sp!, {r0-r5}
136-
beq _svc_exit
137-
138-
cps #MODE_IRQ
139-
b _exc_exit
140-
141-
_svc_exit:
142-
cps #MODE_SVC
129+
msr cpsr_c, r6
143130

144-
_exc_exit:
145131
mov r12, r4
146132
mov lr, r5
147-
pop {r4, r5}
133+
pop {r4-r6}
148134
movs pc, lr
149135
#endif

arch/arm/core/aarch32/isr_wrapper.S

-4
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,6 @@ _idle_state_cleared:
195195
#error Unknown ARM architecture
196196
#endif /* CONFIG_ARMV6_M_ARMV8_M_BASELINE */
197197

198-
#if defined(CONFIG_CPU_CORTEX_R)
199-
mov r0, #RET_FROM_IRQ
200-
#endif
201-
202198
/* Use 'bx' instead of 'b' because 'bx' can jump further, and use
203199
* 'bx' instead of 'blx' because exception return is done in
204200
* z_arm_int_exit() */

arch/arm/core/aarch32/swap_helper.S

-2
Original file line numberDiff line numberDiff line change
@@ -625,15 +625,13 @@ demux:
625625
blx z_irq_do_offload /* call C routine which executes the offload */
626626

627627
/* exception return is done in z_arm_int_exit() */
628-
mov r0, #RET_FROM_SVC
629628
b z_arm_int_exit
630629
#endif
631630

632631
_context_switch:
633632
/* handler mode exit, to PendSV */
634633
bl z_arm_pendsv
635634

636-
mov r0, #RET_FROM_SVC
637635
b z_arm_int_exit
638636

639637
_oops:

include/arch/arm/aarch32/cortex_r/cpu.h

-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131

3232
#define FPEXC_EN (1 << 30)
3333

34-
#define RET_FROM_SVC 0
35-
#define RET_FROM_IRQ 1
36-
3734
#define __ISB() __asm__ volatile ("isb sy" : : : "memory")
3835
#define __DMB() __asm__ volatile ("dmb sy" : : : "memory")
3936

0 commit comments

Comments
 (0)