Skip to content

Commit 5588ae6

Browse files
Update ARM_CRx_No_GIC port (#1101)
This PR makes the following improvements to the ARM_CRx_No_GIC port- 1. Remove inline assembly and move all the assembly code to the portASM.S file. 2. Add support for configUSE_TASK_FPU_SUPPORT - - When configUSE_TASK_FPU_SUPPORT is defined to 1, tasks are created without floating point context. Tasks that want to use floating point, need to call portTASK_USES_FLOATING_POINT(). This is the current behavior. - When configUSE_TASK_FPU_SUPPORT is defined to 2, each task is created with a floating point context. If left undefined, configUSE_TASK_FPU_SUPPORT defaults to 1 for backward compatibility. 3. The application writer can now implement vApplicationSVCHandler to handle the SVC calls raised within the application. SVC 0 is used for the yield kernel operation and the application can use all the SVC calls other than 0. Signed-off-by: kar-rahul-aws <[email protected]>
1 parent 0452603 commit 5588ae6

File tree

3 files changed

+305
-145
lines changed

3 files changed

+305
-145
lines changed

portable/GCC/ARM_CRx_No_GIC/port.c

+50-17
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
/* Standard includes. */
3030
#include <stdlib.h>
31+
#include <string.h>
3132

3233
/* Scheduler includes. */
3334
#include "FreeRTOS.h"
@@ -80,13 +81,22 @@
8081
#define portTASK_RETURN_ADDRESS prvTaskExitError
8182
#endif
8283

84+
/* The space on the stack required to hold the FPU registers. */
85+
#if ( configFPU_D32 == 1 )
86+
#define portFPU_REGISTER_WORDS ( ( 32 * 2 ) + 1 ) /* D0-D31 and FPSCR. */
87+
#else
88+
#define portFPU_REGISTER_WORDS ( ( 16 * 2 ) + 1 ) /* D0-D15 and FPSCR. */
89+
#endif /* configFPU_D32 */
90+
8391
/*-----------------------------------------------------------*/
8492

8593
/*
86-
* Starts the first task executing. This function is necessarily written in
87-
* assembly code so is implemented in portASM.s.
94+
* These functions are necessarily written in assembly code, so are implemented
95+
* in portASM.S.
8896
*/
8997
extern void vPortRestoreTaskContext( void );
98+
extern void vPortInitialiseFPSCR( void );
99+
extern uint32_t ulReadAPSR( void );
90100

91101
/*
92102
* Used to catch tasks that attempt to return from their implementing function.
@@ -184,12 +194,33 @@ StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
184194
/* The task will start with a critical nesting count of 0 as interrupts are
185195
* enabled. */
186196
*pxTopOfStack = portNO_CRITICAL_NESTING;
187-
pxTopOfStack--;
188197

189-
/* The task will start without a floating point context. A task that uses
190-
* the floating point hardware must call vPortTaskUsesFPU() before executing
191-
* any floating point instructions. */
192-
*pxTopOfStack = portNO_FLOATING_POINT_CONTEXT;
198+
#if ( configUSE_TASK_FPU_SUPPORT == 1 )
199+
{
200+
/* The task will start without a floating point context. A task that uses
201+
* the floating point hardware must call vPortTaskUsesFPU() before executing
202+
* any floating point instructions. */
203+
pxTopOfStack--;
204+
*pxTopOfStack = portNO_FLOATING_POINT_CONTEXT;
205+
}
206+
#elif ( configUSE_TASK_FPU_SUPPORT == 2 )
207+
{
208+
/* The task will start with a floating point context. Leave enough
209+
* space for the registers - and ensure they are initialised to 0. */
210+
pxTopOfStack -= portFPU_REGISTER_WORDS;
211+
memset( pxTopOfStack, 0x00, portFPU_REGISTER_WORDS * sizeof( StackType_t ) );
212+
213+
/* Initialise the slot containing ulPortTaskHasFPUContext to true as
214+
* the task starts with a floating point context. */
215+
pxTopOfStack--;
216+
*pxTopOfStack = pdTRUE;
217+
ulPortTaskHasFPUContext = pdTRUE;
218+
}
219+
#else
220+
{
221+
#error "Invalid configUSE_TASK_FPU_SUPPORT value - configUSE_TASK_FPU_SUPPORT must be set to 1, 2, or left undefined."
222+
}
223+
#endif /* if ( configUSE_TASK_FPU_SUPPORT == 1 ) */
193224

194225
return pxTopOfStack;
195226
}
@@ -218,7 +249,7 @@ BaseType_t xPortStartScheduler( void )
218249

219250
/* Only continue if the CPU is not in User mode. The CPU must be in a
220251
* Privileged mode for the scheduler to start. */
221-
__asm volatile ( "MRS %0, APSR" : "=r" ( ulAPSR )::"memory" );
252+
ulAPSR = ulReadAPSR();
222253

223254
ulAPSR &= portAPSR_MODE_BITS_MASK;
224255
configASSERT( ulAPSR != portAPSR_USER_MODE );
@@ -310,15 +341,17 @@ void FreeRTOS_Tick_Handler( void )
310341
}
311342
/*-----------------------------------------------------------*/
312343

313-
void vPortTaskUsesFPU( void )
314-
{
315-
uint32_t ulInitialFPSCR = 0;
344+
#if ( configUSE_TASK_FPU_SUPPORT != 2 )
316345

317-
/* A task is registering the fact that it needs an FPU context. Set the
318-
* FPU flag (which is saved as part of the task context). */
319-
ulPortTaskHasFPUContext = pdTRUE;
346+
void vPortTaskUsesFPU( void )
347+
{
348+
/* A task is registering the fact that it needs an FPU context. Set the
349+
* FPU flag (which is saved as part of the task context). */
350+
ulPortTaskHasFPUContext = pdTRUE;
320351

321-
/* Initialise the floating point status register. */
322-
__asm volatile ( "FMXR FPSCR, %0" ::"r" ( ulInitialFPSCR ) : "memory" );
323-
}
352+
/* Initialise the floating point status register. */
353+
vPortInitialiseFPSCR();
354+
}
355+
356+
#endif /* configUSE_TASK_FPU_SUPPORT */
324357
/*-----------------------------------------------------------*/

0 commit comments

Comments
 (0)