Skip to content

Commit

Permalink
Add user call back function for SVC Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kar-rahul-aws committed Jul 10, 2024
1 parent 9e1b7c6 commit 5652423
Showing 1 changed file with 47 additions and 14 deletions.
61 changes: 47 additions & 14 deletions portable/GCC/ARM_CRx_No_GIC/portASM.S
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

.text
.arm
.syntax unified

.set SYS_MODE, 0x1f
.set SVC_MODE, 0x13
Expand All @@ -53,6 +54,7 @@
.global vPortDisableInterrupts
.global ulPortSetInterruptMaskFromISR

.weak vApplicationSVCHandler
/*-----------------------------------------------------------*/

.macro portSAVE_CONTEXT
Expand Down Expand Up @@ -132,20 +134,6 @@

/*-----------------------------------------------------------*/

/*
* SVC handler is used to yield.
*/
.align 4
.type FreeRTOS_SVC_Handler, %function
FreeRTOS_SVC_Handler:
/* Save the context of the current task and select a new task to run. */
portSAVE_CONTEXT
BLX vTaskSwitchContext
portRESTORE_CONTEXT


/*-----------------------------------------------------------*/

/*
* void vPortRestoreTaskContext( void );
*
Expand Down Expand Up @@ -238,6 +226,51 @@ ulPortSetInterruptMaskFromISR:

/*-----------------------------------------------------------*/

/*
* void vApplicationSVCHandler( uint32_t ulSvcNumber );
*/
.align 4
.type vApplicationSVCHandler, %function
vApplicationSVCHandler:
B vApplicationSVCHandler

/*-----------------------------------------------------------*/

/*
* SVC handler is used to yield.
*/
.align 4
.type FreeRTOS_SVC_Handler, %function
FreeRTOS_SVC_Handler:
PUSH { R0-R1 }

/* ---------------------------- Get Caller SVC Number ---------------------------- */
MRS R0, SPSR /* R0 = CPSR at the time of SVC. */
TST R0, #0x20 /* Check Thumb bit (5) in CPSR. */
LDRHNE R0, [LR, #-0x2] /* If Thumb, load halfword. */
BICNE R0, R0, #0xFF00 /* And extract immidiate field (i.e. SVC number). */
LDREQ R0, [LR, #-0x4] /* If ARM, load word. */
BICEQ R0, R0, #0xFF000000 /* And extract immidiate field (i.e. SVC number). */

/* --------------------------------- SVC Routing --------------------------------- */
CMP R0, #0
BEQ svcPortYield
BNE svcApplicationCall

svcPortYield:
POP { R0-R1 }
portSAVE_CONTEXT
BLX vTaskSwitchContext
portRESTORE_CONTEXT

svcApplicationCall:
POP { R0-R1 }
portSAVE_CONTEXT
BLX vApplicationSVCHandler
portRESTORE_CONTEXT

/*-----------------------------------------------------------*/

.align 4
.type FreeRTOS_IRQ_Handler, %function
FreeRTOS_IRQ_Handler:
Expand Down

0 comments on commit 5652423

Please sign in to comment.