Cleanup of redundant instructions

Signed-off-by: kar-rahul-aws <karahulx@amazon.com>
This commit is contained in:
kar-rahul-aws 2024-07-10 16:52:12 +05:30
parent d6fff2a530
commit e4d3814b31
3 changed files with 67 additions and 75 deletions

View file

@ -83,12 +83,12 @@
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* /*
* Starts the first task executing. These functions are necessarily written in * These functions are necessarily written in assembly code, so are implemented
* assembly code so is implemented in portASM.s. * in portASM.S.
*/ */
extern void vPortRestoreTaskContext( void ); extern void vPortRestoreTaskContext( void );
extern void vPortInitialiseFPSCR( void ); extern void vPortInitialiseFPSCR( void );
extern uint32_t ulReadValueAPSR( void ); extern uint32_t ulReadAPSR( void );
/* /*
* Used to catch tasks that attempt to return from their implementing function. * Used to catch tasks that attempt to return from their implementing function.
@ -220,7 +220,7 @@ BaseType_t xPortStartScheduler( void )
/* Only continue if the CPU is not in User mode. The CPU must be in a /* Only continue if the CPU is not in User mode. The CPU must be in a
* Privileged mode for the scheduler to start. */ * Privileged mode for the scheduler to start. */
ulAPSR = ulReadValueAPSR(); ulAPSR = ulReadAPSR();
ulAPSR &= portAPSR_MODE_BITS_MASK; ulAPSR &= portAPSR_MODE_BITS_MASK;
configASSERT( ulAPSR != portAPSR_USER_MODE ); configASSERT( ulAPSR != portAPSR_USER_MODE );
@ -321,4 +321,4 @@ void vPortTaskUsesFPU( void )
/* Initialise the floating point status register. */ /* Initialise the floating point status register. */
vPortInitialiseFPSCR(); vPortInitialiseFPSCR();
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/

View file

@ -34,8 +34,6 @@
.set IRQ_MODE, 0x12 .set IRQ_MODE, 0x12
/* Variables and functions. */ /* Variables and functions. */
.extern ulMaxAPIPriorityMask
.extern _freertos_vector_table
.extern pxCurrentTCB .extern pxCurrentTCB
.extern vTaskSwitchContext .extern vTaskSwitchContext
.extern vApplicationIRQHandler .extern vApplicationIRQHandler
@ -48,30 +46,31 @@
.global FreeRTOS_SVC_Handler .global FreeRTOS_SVC_Handler
.global vPortRestoreTaskContext .global vPortRestoreTaskContext
.global vPortInitialiseFPSCR .global vPortInitialiseFPSCR
.global ulReadValueAPSR .global ulReadAPSR
/*-----------------------------------------------------------*/
.macro portSAVE_CONTEXT .macro portSAVE_CONTEXT
/* Save the LR and SPSR onto the system mode stack before switching to /* Save the LR and SPSR onto the system mode stack before switching to
system mode to save the remaining system mode registers. */ * system mode to save the remaining system mode registers. */
SRSDB sp!, #SYS_MODE SRSDB sp!, #SYS_MODE
CPS #SYS_MODE CPS #SYS_MODE
PUSH {R0-R12, R14} PUSH {R0-R12, R14}
/* Push the critical nesting count. */ /* Push the critical nesting count. */
LDR R2, ulCriticalNestingConst LDR R2, =ulCriticalNesting
LDR R1, [R2] LDR R1, [R2]
PUSH {R1} PUSH {R1}
/* Does the task have a floating point context that needs saving? If /* Does the task have a floating point context that needs saving? If
ulPortTaskHasFPUContext is 0 then no. */ * ulPortTaskHasFPUContext is 0 then no. */
LDR R2, ulPortTaskHasFPUContextConst LDR R2, =ulPortTaskHasFPUContext
LDR R3, [R2] LDR R3, [R2]
CMP R3, #0 CMP R3, #0
/* Save the floating point context, if any. */ /* Save the floating point context, if any. */
FMRXNE R1, FPSCR VMRSNE R1, FPSCR
VPUSHNE {D0-D15} VPUSHNE {D0-D15}
#if configFPU_D32 == 1 #if configFPU_D32 == 1
VPUSHNE {D16-D31} VPUSHNE {D16-D31}
@ -82,24 +81,24 @@
PUSH {R3} PUSH {R3}
/* Save the stack pointer in the TCB. */ /* Save the stack pointer in the TCB. */
LDR R0, pxCurrentTCBConst LDR R0, =pxCurrentTCB
LDR R1, [R0] LDR R1, [R0]
STR SP, [R1] STR SP, [R1]
.endm .endm
; /**********************************************************************/ /*-----------------------------------------------------------*/
.macro portRESTORE_CONTEXT .macro portRESTORE_CONTEXT
/* Set the SP to point to the stack of the task being restored. */ /* Set the SP to point to the stack of the task being restored. */
LDR R0, pxCurrentTCBConst LDR R0, =pxCurrentTCB
LDR R1, [R0] LDR R1, [R0]
LDR SP, [R1] LDR SP, [R1]
/* Is there a floating point context to restore? If the restored /* Is there a floating point context to restore? If the restored
ulPortTaskHasFPUContext is zero then no. */ * ulPortTaskHasFPUContext is zero then no. */
LDR R0, ulPortTaskHasFPUContextConst LDR R0, =ulPortTaskHasFPUContext
POP {R1} POP {R1}
STR R1, [R0] STR R1, [R0]
CMP R1, #0 CMP R1, #0
@ -113,7 +112,7 @@
VMSRNE FPSCR, R0 VMSRNE FPSCR, R0
/* Restore the critical section nesting depth. */ /* Restore the critical section nesting depth. */
LDR R0, ulCriticalNestingConst LDR R0, =ulCriticalNesting
POP {R1} POP {R1}
STR R1, [R0] STR R1, [R0]
@ -126,25 +125,25 @@
.endm .endm
/*-----------------------------------------------------------*/
/*
/******************************************************************************
* SVC handler is used to yield. * SVC handler is used to yield.
*****************************************************************************/ */
.align 4 .align 4
.type FreeRTOS_SVC_Handler, %function .type FreeRTOS_SVC_Handler, %function
FreeRTOS_SVC_Handler: FreeRTOS_SVC_Handler:
/* Save the context of the current task and select a new task to run. */ /* Save the context of the current task and select a new task to run. */
portSAVE_CONTEXT portSAVE_CONTEXT
LDR R0, vTaskSwitchContextConst BLX vTaskSwitchContext
BLX R0
portRESTORE_CONTEXT portRESTORE_CONTEXT
/****************************************************************************** /*-----------------------------------------------------------*/
/*
* vPortRestoreTaskContext is used to start the scheduler. * vPortRestoreTaskContext is used to start the scheduler.
*****************************************************************************/ */
.align 4 .align 4
.type vPortRestoreTaskContext, %function .type vPortRestoreTaskContext, %function
vPortRestoreTaskContext: vPortRestoreTaskContext:
@ -152,26 +151,31 @@ vPortRestoreTaskContext:
CPS #SYS_MODE CPS #SYS_MODE
portRESTORE_CONTEXT portRESTORE_CONTEXT
/*-----------------------------------------------------------*/
/****************************************************************************** /*
* vPortInitialiseFPSCR is used to initialize the FPSCR context. * vPortInitialiseFPSCR is used to initialize the FPSCR register.
*****************************************************************************/ */
.align 4 .align 4
.type vPortInitialiseFPSCR, %function .type vPortInitialiseFPSCR, %function
vPortInitialiseFPSCR: vPortInitialiseFPSCR:
MOV R0, #0 MOV R0, #0
FMXR FPSCR, R0 VMSR FPSCR, R0
BX LR BX LR
/****************************************************************************** /*-----------------------------------------------------------*/
* ulReadValueAPSR is used to read the value of APSR context.
*****************************************************************************/ /*
* ulReadAPSR is used to read the value of APSR context.
*/
.align 4 .align 4
.type ulReadValueAPSR, %function .type ulReadAPSR, %function
ulReadValueAPSR: ulReadAPSR:
MRS R0, APSR MRS R0, APSR
BX LR BX LR
/*-----------------------------------------------------------*/
.align 4 .align 4
.type FreeRTOS_IRQ_Handler, %function .type FreeRTOS_IRQ_Handler, %function
FreeRTOS_IRQ_Handler: FreeRTOS_IRQ_Handler:
@ -184,29 +188,28 @@ FreeRTOS_IRQ_Handler:
PUSH {lr} PUSH {lr}
/* Change to supervisor mode to allow reentry. */ /* Change to supervisor mode to allow reentry. */
CPS #0x13 CPS #SVC_MODE
/* Push used registers. */ /* Push used registers. */
PUSH {r0-r3, r12} PUSH {r0-r3, r12}
/* Increment nesting count. r3 holds the address of ulPortInterruptNesting /* Increment nesting count. r3 holds the address of ulPortInterruptNesting
for future use. r1 holds the original ulPortInterruptNesting value for * for future use. r1 holds the original ulPortInterruptNesting value for
future use. */ * future use. */
LDR r3, ulPortInterruptNestingConst LDR r3, =ulPortInterruptNesting
LDR r1, [r3] LDR r1, [r3]
ADD r0, r1, #1 ADD r0, r1, #1
STR r0, [r3] STR r0, [r3]
/* Ensure bit 2 of the stack pointer is clear. r2 holds the bit 2 value for /* Ensure bit 2 of the stack pointer is clear. r2 holds the bit 2 value for
future use. */ * future use. */
MOV r0, sp MOV r0, sp
AND r2, r0, #4 AND r2, r0, #4
SUB sp, sp, r2 SUB sp, sp, r2
/* Call the interrupt handler. */ /* Call the interrupt handler. */
PUSH {r0-r3, lr} PUSH {r0-r3, lr}
LDR r1, vApplicationIRQHandlerConst BLX vApplicationIRQHandler
BLX r1
POP {r0-r3, lr} POP {r0-r3, lr}
ADD sp, sp, r2 ADD sp, sp, r2
@ -215,7 +218,7 @@ FreeRTOS_IRQ_Handler:
ISB ISB
/* Write to the EOI register. */ /* Write to the EOI register. */
LDR r0, ulICCEOIRConst LDR r0, =ulICCEOIR
LDR r2, [r0] LDR r2, [r0]
STR r0, [r2] STR r0, [r2]
@ -227,16 +230,16 @@ FreeRTOS_IRQ_Handler:
BNE exit_without_switch BNE exit_without_switch
/* Did the interrupt request a context switch? r1 holds the address of /* Did the interrupt request a context switch? r1 holds the address of
ulPortYieldRequired and r0 the value of ulPortYieldRequired for future * ulPortYieldRequired and r0 the value of ulPortYieldRequired for future
use. */ * use. */
LDR r1, ulPortYieldRequiredConst LDR r1, =ulPortYieldRequired
LDR r0, [r1] LDR r0, [r1]
CMP r0, #0 CMP r0, #0
BNE switch_before_exit BNE switch_before_exit
exit_without_switch: exit_without_switch:
/* No context switch. Restore used registers, LR_irq and SPSR before /* No context switch. Restore used registers, LR_irq and SPSR before
returning. */ * returning. */
POP {r0-r3, r12} POP {r0-r3, r12}
CPS #IRQ_MODE CPS #IRQ_MODE
POP {LR} POP {LR}
@ -246,12 +249,12 @@ exit_without_switch:
switch_before_exit: switch_before_exit:
/* A context switch is to be performed. Clear the context switch pending /* A context switch is to be performed. Clear the context switch pending
flag. */ * flag. */
MOV r0, #0 MOV r0, #0
STR r0, [r1] STR r0, [r1]
/* Restore used registers, LR-irq and SPSR before saving the context /* Restore used registers, LR-irq and SPSR before saving the context
to the task stack. */ * to the task stack. */
POP {r0-r3, r12} POP {r0-r3, r12}
CPS #IRQ_MODE CPS #IRQ_MODE
POP {LR} POP {LR}
@ -260,23 +263,15 @@ switch_before_exit:
portSAVE_CONTEXT portSAVE_CONTEXT
/* Call the function that selects the new task to execute. /* Call the function that selects the new task to execute.
vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD * vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD
instructions, or 8 byte aligned stack allocated data. LR does not need * instructions, or 8 byte aligned stack allocated data. LR does not need
saving as a new LR will be loaded by portRESTORE_CONTEXT anyway. */ * saving as a new LR will be loaded by portRESTORE_CONTEXT anyway. */
LDR R0, vTaskSwitchContextConst BLX vTaskSwitchContext
BLX R0
/* Restore the context of, and branch to, the task selected to execute /* Restore the context of, and branch to, the task selected to execute
next. */ * next. */
portRESTORE_CONTEXT portRESTORE_CONTEXT
ulICCEOIRConst: .word ulICCEOIR /*-----------------------------------------------------------*/
pxCurrentTCBConst: .word pxCurrentTCB
ulCriticalNestingConst: .word ulCriticalNesting
ulPortTaskHasFPUContextConst: .word ulPortTaskHasFPUContext
vTaskSwitchContextConst: .word vTaskSwitchContext
vApplicationIRQHandlerConst: .word vApplicationIRQHandler
ulPortInterruptNestingConst: .word ulPortInterruptNesting
ulPortYieldRequiredConst: .word ulPortYieldRequired
.end .end

View file

@ -59,7 +59,7 @@ typedef long BaseType_t;
typedef unsigned long UBaseType_t; typedef unsigned long UBaseType_t;
typedef uint32_t TickType_t; typedef uint32_t TickType_t;
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
/* 32-bit tick type on a 32-bit architecture, so reads of the tick count do /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
* not need to be guarded with a critical section. */ * not need to be guarded with a critical section. */
@ -92,10 +92,11 @@ typedef uint32_t TickType_t;
__asm volatile ( "SWI 0 \n" \ __asm volatile ( "SWI 0 \n" \
"ISB " ::: "memory" ); "ISB " ::: "memory" );
/*-----------------------------------------------------------*/
/*----------------------------------------------------------- /*
* Critical section control * Critical section management.
*----------------------------------------------------------*/ */
extern void vPortEnterCritical( void ); extern void vPortEnterCritical( void );
extern void vPortExitCritical( void ); extern void vPortExitCritical( void );
@ -163,19 +164,15 @@ void vPortTaskUsesFPU( void );
#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
/* Store/clear the ready priorities in a bit map. */ /* Store, clear and get the ready priorities in a bit map. */
#define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) ) #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
#define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) ) #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) __builtin_clz( uxReadyPriorities ) )
/*-----------------------------------------------------------*/
#define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) __builtin_clz( uxReadyPriorities ) )
#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */ #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
#define portNOP() __asm volatile ( "NOP" ) #define portNOP() __asm volatile ( "NOP" )
#define portINLINE __inline #define portINLINE __inline
#define portMEMORY_BARRIER() __asm volatile ( "" ::: "memory" ) #define portMEMORY_BARRIER() __asm volatile ( "" ::: "memory" )
/* *INDENT-OFF* */ /* *INDENT-OFF* */