Skip to content

Commit 5652423

Browse files
committed
Add user call back function for SVC Handler
1 parent 9e1b7c6 commit 5652423

File tree

1 file changed

+47
-14
lines changed

1 file changed

+47
-14
lines changed

portable/GCC/ARM_CRx_No_GIC/portASM.S

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
.text
3030
.arm
31+
.syntax unified
3132

3233
.set SYS_MODE, 0x1f
3334
.set SVC_MODE, 0x13
@@ -53,6 +54,7 @@
5354
.global vPortDisableInterrupts
5455
.global ulPortSetInterruptMaskFromISR
5556

57+
.weak vApplicationSVCHandler
5658
/*-----------------------------------------------------------*/
5759

5860
.macro portSAVE_CONTEXT
@@ -132,20 +134,6 @@
132134

133135
/*-----------------------------------------------------------*/
134136

135-
/*
136-
* SVC handler is used to yield.
137-
*/
138-
.align 4
139-
.type FreeRTOS_SVC_Handler, %function
140-
FreeRTOS_SVC_Handler:
141-
/* Save the context of the current task and select a new task to run. */
142-
portSAVE_CONTEXT
143-
BLX vTaskSwitchContext
144-
portRESTORE_CONTEXT
145-
146-
147-
/*-----------------------------------------------------------*/
148-
149137
/*
150138
* void vPortRestoreTaskContext( void );
151139
*
@@ -238,6 +226,51 @@ ulPortSetInterruptMaskFromISR:
238226

239227
/*-----------------------------------------------------------*/
240228

229+
/*
230+
* void vApplicationSVCHandler( uint32_t ulSvcNumber );
231+
*/
232+
.align 4
233+
.type vApplicationSVCHandler, %function
234+
vApplicationSVCHandler:
235+
B vApplicationSVCHandler
236+
237+
/*-----------------------------------------------------------*/
238+
239+
/*
240+
* SVC handler is used to yield.
241+
*/
242+
.align 4
243+
.type FreeRTOS_SVC_Handler, %function
244+
FreeRTOS_SVC_Handler:
245+
PUSH { R0-R1 }
246+
247+
/* ---------------------------- Get Caller SVC Number ---------------------------- */
248+
MRS R0, SPSR /* R0 = CPSR at the time of SVC. */
249+
TST R0, #0x20 /* Check Thumb bit (5) in CPSR. */
250+
LDRHNE R0, [LR, #-0x2] /* If Thumb, load halfword. */
251+
BICNE R0, R0, #0xFF00 /* And extract immidiate field (i.e. SVC number). */
252+
LDREQ R0, [LR, #-0x4] /* If ARM, load word. */
253+
BICEQ R0, R0, #0xFF000000 /* And extract immidiate field (i.e. SVC number). */
254+
255+
/* --------------------------------- SVC Routing --------------------------------- */
256+
CMP R0, #0
257+
BEQ svcPortYield
258+
BNE svcApplicationCall
259+
260+
svcPortYield:
261+
POP { R0-R1 }
262+
portSAVE_CONTEXT
263+
BLX vTaskSwitchContext
264+
portRESTORE_CONTEXT
265+
266+
svcApplicationCall:
267+
POP { R0-R1 }
268+
portSAVE_CONTEXT
269+
BLX vApplicationSVCHandler
270+
portRESTORE_CONTEXT
271+
272+
/*-----------------------------------------------------------*/
273+
241274
.align 4
242275
.type FreeRTOS_IRQ_Handler, %function
243276
FreeRTOS_IRQ_Handler:

0 commit comments

Comments
 (0)