Skip to content

Commit e4d3814

Browse files
committed
Cleanup of redundant instructions
Signed-off-by: kar-rahul-aws <[email protected]>
1 parent d6fff2a commit e4d3814

File tree

3 files changed

+67
-75
lines changed

3 files changed

+67
-75
lines changed

portable/GCC/ARM_CRx_No_GIC/port.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@
8383
/*-----------------------------------------------------------*/
8484

8585
/*
86-
* Starts the first task executing. These functions are necessarily written in
87-
* assembly code so is implemented in portASM.s.
86+
* These functions are necessarily written in assembly code, so are implemented
87+
* in portASM.S.
8888
*/
8989
extern void vPortRestoreTaskContext( void );
9090
extern void vPortInitialiseFPSCR( void );
91-
extern uint32_t ulReadValueAPSR( void );
91+
extern uint32_t ulReadAPSR( void );
9292

9393
/*
9494
* Used to catch tasks that attempt to return from their implementing function.
@@ -220,7 +220,7 @@ BaseType_t xPortStartScheduler( void )
220220

221221
/* Only continue if the CPU is not in User mode. The CPU must be in a
222222
* Privileged mode for the scheduler to start. */
223-
ulAPSR = ulReadValueAPSR();
223+
ulAPSR = ulReadAPSR();
224224

225225
ulAPSR &= portAPSR_MODE_BITS_MASK;
226226
configASSERT( ulAPSR != portAPSR_USER_MODE );
@@ -321,4 +321,4 @@ void vPortTaskUsesFPU( void )
321321
/* Initialise the floating point status register. */
322322
vPortInitialiseFPSCR();
323323
}
324-
/*-----------------------------------------------------------*/
324+
/*-----------------------------------------------------------*/

portable/GCC/ARM_CRx_No_GIC/portASM.S

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
.set IRQ_MODE, 0x12
3535

3636
/* Variables and functions. */
37-
.extern ulMaxAPIPriorityMask
38-
.extern _freertos_vector_table
3937
.extern pxCurrentTCB
4038
.extern vTaskSwitchContext
4139
.extern vApplicationIRQHandler
@@ -48,30 +46,31 @@
4846
.global FreeRTOS_SVC_Handler
4947
.global vPortRestoreTaskContext
5048
.global vPortInitialiseFPSCR
51-
.global ulReadValueAPSR
49+
.global ulReadAPSR
5250

51+
/*-----------------------------------------------------------*/
5352

5453
.macro portSAVE_CONTEXT
5554

5655
/* Save the LR and SPSR onto the system mode stack before switching to
57-
system mode to save the remaining system mode registers. */
56+
* system mode to save the remaining system mode registers. */
5857
SRSDB sp!, #SYS_MODE
5958
CPS #SYS_MODE
6059
PUSH {R0-R12, R14}
6160

6261
/* Push the critical nesting count. */
63-
LDR R2, ulCriticalNestingConst
62+
LDR R2, =ulCriticalNesting
6463
LDR R1, [R2]
6564
PUSH {R1}
6665

6766
/* Does the task have a floating point context that needs saving? If
68-
ulPortTaskHasFPUContext is 0 then no. */
69-
LDR R2, ulPortTaskHasFPUContextConst
67+
* ulPortTaskHasFPUContext is 0 then no. */
68+
LDR R2, =ulPortTaskHasFPUContext
7069
LDR R3, [R2]
7170
CMP R3, #0
7271

7372
/* Save the floating point context, if any. */
74-
FMRXNE R1, FPSCR
73+
VMRSNE R1, FPSCR
7574
VPUSHNE {D0-D15}
7675
#if configFPU_D32 == 1
7776
VPUSHNE {D16-D31}
@@ -82,24 +81,24 @@
8281
PUSH {R3}
8382

8483
/* Save the stack pointer in the TCB. */
85-
LDR R0, pxCurrentTCBConst
84+
LDR R0, =pxCurrentTCB
8685
LDR R1, [R0]
8786
STR SP, [R1]
8887

8988
.endm
9089

91-
; /**********************************************************************/
90+
/*-----------------------------------------------------------*/
9291

9392
.macro portRESTORE_CONTEXT
9493

9594
/* Set the SP to point to the stack of the task being restored. */
96-
LDR R0, pxCurrentTCBConst
95+
LDR R0, =pxCurrentTCB
9796
LDR R1, [R0]
9897
LDR SP, [R1]
9998

10099
/* Is there a floating point context to restore? If the restored
101-
ulPortTaskHasFPUContext is zero then no. */
102-
LDR R0, ulPortTaskHasFPUContextConst
100+
* ulPortTaskHasFPUContext is zero then no. */
101+
LDR R0, =ulPortTaskHasFPUContext
103102
POP {R1}
104103
STR R1, [R0]
105104
CMP R1, #0
@@ -113,7 +112,7 @@
113112
VMSRNE FPSCR, R0
114113

115114
/* Restore the critical section nesting depth. */
116-
LDR R0, ulCriticalNestingConst
115+
LDR R0, =ulCriticalNesting
117116
POP {R1}
118117
STR R1, [R0]
119118

@@ -126,52 +125,57 @@
126125

127126
.endm
128127

128+
/*-----------------------------------------------------------*/
129129

130-
131-
132-
/******************************************************************************
130+
/*
133131
* SVC handler is used to yield.
134-
*****************************************************************************/
132+
*/
135133
.align 4
136134
.type FreeRTOS_SVC_Handler, %function
137135
FreeRTOS_SVC_Handler:
138136
/* Save the context of the current task and select a new task to run. */
139137
portSAVE_CONTEXT
140-
LDR R0, vTaskSwitchContextConst
141-
BLX R0
138+
BLX vTaskSwitchContext
142139
portRESTORE_CONTEXT
143140

144141

145-
/******************************************************************************
142+
/*-----------------------------------------------------------*/
143+
144+
/*
146145
* vPortRestoreTaskContext is used to start the scheduler.
147-
*****************************************************************************/
146+
*/
148147
.align 4
149148
.type vPortRestoreTaskContext, %function
150149
vPortRestoreTaskContext:
151150
/* Switch to system mode. */
152151
CPS #SYS_MODE
153152
portRESTORE_CONTEXT
154153

154+
/*-----------------------------------------------------------*/
155155

156-
/******************************************************************************
157-
* vPortInitialiseFPSCR is used to initialize the FPSCR context.
158-
*****************************************************************************/
156+
/*
157+
* vPortInitialiseFPSCR is used to initialize the FPSCR register.
158+
*/
159159
.align 4
160160
.type vPortInitialiseFPSCR, %function
161161
vPortInitialiseFPSCR:
162162
MOV R0, #0
163-
FMXR FPSCR, R0
163+
VMSR FPSCR, R0
164164
BX LR
165165

166-
/******************************************************************************
167-
* ulReadValueAPSR is used to read the value of APSR context.
168-
*****************************************************************************/
166+
/*-----------------------------------------------------------*/
167+
168+
/*
169+
* ulReadAPSR is used to read the value of APSR context.
170+
*/
169171
.align 4
170-
.type ulReadValueAPSR, %function
171-
ulReadValueAPSR:
172+
.type ulReadAPSR, %function
173+
ulReadAPSR:
172174
MRS R0, APSR
173175
BX LR
174176

177+
/*-----------------------------------------------------------*/
178+
175179
.align 4
176180
.type FreeRTOS_IRQ_Handler, %function
177181
FreeRTOS_IRQ_Handler:
@@ -184,29 +188,28 @@ FreeRTOS_IRQ_Handler:
184188
PUSH {lr}
185189

186190
/* Change to supervisor mode to allow reentry. */
187-
CPS #0x13
191+
CPS #SVC_MODE
188192

189193
/* Push used registers. */
190194
PUSH {r0-r3, r12}
191195

192196
/* Increment nesting count. r3 holds the address of ulPortInterruptNesting
193-
for future use. r1 holds the original ulPortInterruptNesting value for
194-
future use. */
195-
LDR r3, ulPortInterruptNestingConst
197+
* for future use. r1 holds the original ulPortInterruptNesting value for
198+
* future use. */
199+
LDR r3, =ulPortInterruptNesting
196200
LDR r1, [r3]
197201
ADD r0, r1, #1
198202
STR r0, [r3]
199203

200204
/* Ensure bit 2 of the stack pointer is clear. r2 holds the bit 2 value for
201-
future use. */
205+
* future use. */
202206
MOV r0, sp
203207
AND r2, r0, #4
204208
SUB sp, sp, r2
205209

206210
/* Call the interrupt handler. */
207211
PUSH {r0-r3, lr}
208-
LDR r1, vApplicationIRQHandlerConst
209-
BLX r1
212+
BLX vApplicationIRQHandler
210213
POP {r0-r3, lr}
211214
ADD sp, sp, r2
212215

@@ -215,7 +218,7 @@ FreeRTOS_IRQ_Handler:
215218
ISB
216219

217220
/* Write to the EOI register. */
218-
LDR r0, ulICCEOIRConst
221+
LDR r0, =ulICCEOIR
219222
LDR r2, [r0]
220223
STR r0, [r2]
221224

@@ -227,16 +230,16 @@ FreeRTOS_IRQ_Handler:
227230
BNE exit_without_switch
228231

229232
/* Did the interrupt request a context switch? r1 holds the address of
230-
ulPortYieldRequired and r0 the value of ulPortYieldRequired for future
231-
use. */
232-
LDR r1, ulPortYieldRequiredConst
233+
* ulPortYieldRequired and r0 the value of ulPortYieldRequired for future
234+
* use. */
235+
LDR r1, =ulPortYieldRequired
233236
LDR r0, [r1]
234237
CMP r0, #0
235238
BNE switch_before_exit
236239

237240
exit_without_switch:
238241
/* No context switch. Restore used registers, LR_irq and SPSR before
239-
returning. */
242+
* returning. */
240243
POP {r0-r3, r12}
241244
CPS #IRQ_MODE
242245
POP {LR}
@@ -246,12 +249,12 @@ exit_without_switch:
246249

247250
switch_before_exit:
248251
/* A context switch is to be performed. Clear the context switch pending
249-
flag. */
252+
* flag. */
250253
MOV r0, #0
251254
STR r0, [r1]
252255

253256
/* Restore used registers, LR-irq and SPSR before saving the context
254-
to the task stack. */
257+
* to the task stack. */
255258
POP {r0-r3, r12}
256259
CPS #IRQ_MODE
257260
POP {LR}
@@ -260,23 +263,15 @@ switch_before_exit:
260263
portSAVE_CONTEXT
261264

262265
/* Call the function that selects the new task to execute.
263-
vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD
264-
instructions, or 8 byte aligned stack allocated data. LR does not need
265-
saving as a new LR will be loaded by portRESTORE_CONTEXT anyway. */
266-
LDR R0, vTaskSwitchContextConst
267-
BLX R0
266+
* vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD
267+
* instructions, or 8 byte aligned stack allocated data. LR does not need
268+
* saving as a new LR will be loaded by portRESTORE_CONTEXT anyway. */
269+
BLX vTaskSwitchContext
268270

269271
/* Restore the context of, and branch to, the task selected to execute
270-
next. */
272+
* next. */
271273
portRESTORE_CONTEXT
272274

273-
ulICCEOIRConst: .word ulICCEOIR
274-
pxCurrentTCBConst: .word pxCurrentTCB
275-
ulCriticalNestingConst: .word ulCriticalNesting
276-
ulPortTaskHasFPUContextConst: .word ulPortTaskHasFPUContext
277-
vTaskSwitchContextConst: .word vTaskSwitchContext
278-
vApplicationIRQHandlerConst: .word vApplicationIRQHandler
279-
ulPortInterruptNestingConst: .word ulPortInterruptNesting
280-
ulPortYieldRequiredConst: .word ulPortYieldRequired
275+
/*-----------------------------------------------------------*/
281276

282277
.end

portable/GCC/ARM_CRx_No_GIC/portmacro.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ typedef long BaseType_t;
5959
typedef unsigned long UBaseType_t;
6060

6161
typedef uint32_t TickType_t;
62-
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
62+
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
6363

6464
/* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
6565
* not need to be guarded with a critical section. */
@@ -92,10 +92,11 @@ typedef uint32_t TickType_t;
9292
__asm volatile ( "SWI 0 \n" \
9393
"ISB " ::: "memory" );
9494

95+
/*-----------------------------------------------------------*/
9596

96-
/*-----------------------------------------------------------
97-
* Critical section control
98-
*----------------------------------------------------------*/
97+
/*
98+
* Critical section management.
99+
*/
99100

100101
extern void vPortEnterCritical( void );
101102
extern void vPortExitCritical( void );
@@ -163,19 +164,15 @@ void vPortTaskUsesFPU( void );
163164

164165
#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
165166

166-
/* Store/clear the ready priorities in a bit map. */
167+
/* Store, clear and get the ready priorities in a bit map. */
167168
#define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
168169
#define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
169-
170-
/*-----------------------------------------------------------*/
171-
172-
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) __builtin_clz( uxReadyPriorities ) )
170+
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) __builtin_clz( uxReadyPriorities ) )
173171

174172
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
175173

176174
#define portNOP() __asm volatile ( "NOP" )
177-
#define portINLINE __inline
178-
175+
#define portINLINE __inline
179176
#define portMEMORY_BARRIER() __asm volatile ( "" ::: "memory" )
180177

181178
/* *INDENT-OFF* */

0 commit comments

Comments
 (0)