Skip to content

Commit 72e590c

Browse files
committed
Cortex-R5/GNU: Replace MOV pc for return stack prediction
This replaces all MOV pc,lr and MOV pc,r3 return instructions with BX lr and BX r3 across the Cortex-R5 GNU port. Remove the now-unnecessary __THUMB_INTERWORK conditional compilation blocks. On ARMv7-R, BX is the architecturally correct return instruction: it handles ARM/Thumb interworking natively and feeds Cortex-R5 return stack predictor, whereas MOV pc,lr is treated as generic data move that bypasses branch prediction. Validated against Cortex-R5 TRM (DDI 0460D) and ARMv7-A/R ARM (DDI 0406C Section A2.3). Exception return via LDMIA {...,pc}^ correctly left untouched.
1 parent b0c54c6 commit 72e590c

11 files changed

Lines changed: 3 additions & 43 deletions

ports/cortex_r5/gnu/src/tx_thread_fiq_nesting_end.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ _tx_thread_fiq_nesting_end:
9999
ORR r0, r0, #FIQ_MODE_BITS @ Build IRQ mode CPSR
100100
MSR CPSR_c, r0 @ Reenter IRQ mode
101101

102-
#ifdef __THUMB_INTERWORK
103102
BX r3 @ Return to caller
104-
#else
105-
MOV pc, r3 @ Return to caller
106-
#endif
107103
@}
108104

ports/cortex_r5/gnu/src/tx_thread_fiq_nesting_start.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ _tx_thread_fiq_nesting_start:
9191
@ and push r1 just to keep 8-byte alignment
9292
BIC r0, r0, #FIQ_DISABLE @ Build enable FIQ CPSR
9393
MSR CPSR_c, r0 @ Enter system mode
94-
#ifdef __THUMB_INTERWORK
9594
BX r3 @ Return to caller
96-
#else
97-
MOV pc, r3 @ Return to caller
98-
#endif
9995
@}
10096

ports/cortex_r5/gnu/src/tx_thread_interrupt_control.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ _tx_thread_interrupt_control:
100100
@
101101
MSR CPSR_c, r1 @ Setup new CPSR
102102
BIC r0, r3, r2 @ Return previous interrupt mask
103-
#ifdef __THUMB_INTERWORK
104103
BX lr @ Return to caller
105-
#else
106-
MOV pc, lr @ Return to caller
107-
#endif
108104
@}
109105

ports/cortex_r5/gnu/src/tx_thread_interrupt_disable.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@ _tx_thread_interrupt_disable:
9898
DMB @ Memory barrier (acquire semantics)
9999
ISB @ Flush pipeline
100100

101-
#ifdef __THUMB_INTERWORK
102101
BX lr @ Return to caller
103-
#else
104-
MOV pc, lr @ Return to caller
105-
#endif
106102
@}
107103

108104

ports/cortex_r5/gnu/src/tx_thread_interrupt_restore.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ _tx_thread_interrupt_restore:
9090
DMB @ Memory barrier (release semantics)
9191
MSR CPSR_c, r0 @ Setup new CPSR
9292
ISB @ Synchronize context
93-
#ifdef __THUMB_INTERWORK
9493
BX lr @ Return to caller
95-
#else
96-
MOV pc, lr @ Return to caller
97-
#endif
9894
@}
9995

ports/cortex_r5/gnu/src/tx_thread_irq_nesting_end.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ _tx_thread_irq_nesting_end:
9898
BIC r0, r0, #MODE_MASK @ Clear mode bits
9999
ORR r0, r0, #IRQ_MODE_BITS @ Build IRQ mode CPSR
100100
MSR CPSR_c, r0 @ Reenter IRQ mode
101-
#ifdef __THUMB_INTERWORK
102101
BX r3 @ Return to caller
103-
#else
104-
MOV pc, r3 @ Return to caller
105-
#endif
106102
@}
107103

ports/cortex_r5/gnu/src/tx_thread_irq_nesting_start.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ _tx_thread_irq_nesting_start:
9191
@ and push r1 just to keep 8-byte alignment
9292
BIC r0, r0, #IRQ_DISABLE @ Build enable IRQ CPSR
9393
MSR CPSR_c, r0 @ Enter system mode
94-
#ifdef __THUMB_INTERWORK
9594
BX r3 @ Return to caller
96-
#else
97-
MOV pc, r3 @ Return to caller
98-
#endif
9995
@}
10096

ports/cortex_r5/gnu/src/tx_thread_schedule.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,7 @@ _tx_skip_solicited_vfp_restore:
190190
LDMIA sp!, {r4-r11, lr} @ Return to thread synchronously
191191
MSR CPSR_cxsf, r0 @ Recover CPSR
192192
@
193-
#ifdef __THUMB_INTERWORK
194193
BX lr @ Return to caller
195-
#else
196-
MOV pc, lr @ Return to caller
197-
#endif
198194
@
199195
@}
200196
@

ports/cortex_r5/gnu/src/tx_thread_stack_build.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,7 @@ _tx_thread_stack_build:
161161
@
162162
STR r2, [r0, #8] @ Save stack pointer in thread's
163163
@ control block
164-
#ifdef __THUMB_INTERWORK
165164
BX lr @ Return to caller
166-
#else
167-
MOV pc, lr @ Return to caller
168-
#endif
169165
@}
170166

171167

ports/cortex_r5/gnu/src/tx_thread_vectored_context_save.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ _tx_thread_vectored_context_save:
114114
POP {lr} @ Recover ISR lr
115115
#endif
116116

117-
MOV pc, lr @ Return to caller
117+
BX lr @ Return to caller
118118
@
119119
__tx_thread_not_nested_save:
120120
@ }
@@ -154,7 +154,7 @@ __tx_thread_not_nested_save:
154154
POP {lr} @ Recover ISR lr
155155
#endif
156156

157-
MOV pc, lr @ Return to caller
157+
BX lr @ Return to caller
158158
@
159159
@ }
160160
@ else
@@ -179,7 +179,7 @@ __tx_thread_idle_system_save:
179179
#endif
180180

181181
ADD sp, sp, #32 @ Recover saved registers
182-
MOV pc, lr @ Return to caller
182+
BX lr @ Return to caller
183183
@
184184
@ }
185185
@}

0 commit comments

Comments
 (0)