11/*
22 * FreeRTOS Kernel <DEVELOPMENT BRANCH>
33 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4- * Copyright 2024 Arm Limited and/or its affiliates
4+ * Copyright 2024-2025 Arm Limited and/or its affiliates
5566 *
77 * SPDX-License-Identifier: MIT
@@ -1200,7 +1200,7 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
12001200 extern UBaseType_t uxSystemCallImplementations [ NUM_SYSTEM_CALLS ];
12011201 xMPU_SETTINGS * pxMpuSettings ;
12021202 uint32_t * pulSystemCallStack ;
1203- uint32_t ulStackFrameSize , ulSystemCallLocation , i ;
1203+ uint32_t ulHardwareSavedExceptionFrameSize , ulSystemCallLocation , i ;
12041204
12051205 #if defined( __ARMCC_VERSION )
12061206
@@ -1236,12 +1236,16 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
12361236 {
12371237 pulSystemCallStack = pxMpuSettings -> xSystemCallStackInfo .pulSystemCallStack ;
12381238
1239+ /* Hardware Saved Stack Frame Size upon Exception entry:
1240+ * - No FPU: basic frame (R0-R3, R12, LR, PC, and xPSR) = 8 words.
1241+ * - With FPU (lazy stacking): basic frame + S0–S15 + FPSCR + reserved word = 26 words.
1242+ */
12391243 #if ( ( configENABLE_FPU == 1 ) || ( configENABLE_MVE == 1 ) )
12401244 {
12411245 if ( ( ulLR & portEXC_RETURN_STACK_FRAME_TYPE_MASK ) == 0UL )
12421246 {
12431247 /* Extended frame i.e. FPU in use. */
1244- ulStackFrameSize = 26 ;
1248+ ulHardwareSavedExceptionFrameSize = 26 ;
12451249 __asm volatile (
12461250 " vpush {s0} \n" /* Trigger lazy stacking. */
12471251 " vpop {s0} \n" /* Nullify the affect of the above instruction. */
@@ -1251,20 +1255,20 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
12511255 else
12521256 {
12531257 /* Standard frame i.e. FPU not in use. */
1254- ulStackFrameSize = 8 ;
1258+ ulHardwareSavedExceptionFrameSize = 8 ;
12551259 }
12561260 }
12571261 #else /* if ( ( configENABLE_FPU == 1 ) || ( configENABLE_MVE == 1 ) ) */
12581262 {
1259- ulStackFrameSize = 8 ;
1263+ ulHardwareSavedExceptionFrameSize = 8 ;
12601264 }
12611265 #endif /* configENABLE_FPU || configENABLE_MVE */
12621266
12631267 /* Make space on the system call stack for the stack frame. */
1264- pulSystemCallStack = pulSystemCallStack - ulStackFrameSize ;
1268+ pulSystemCallStack = pulSystemCallStack - ulHardwareSavedExceptionFrameSize ;
12651269
12661270 /* Copy the stack frame. */
1267- for ( i = 0 ; i < ulStackFrameSize ; i ++ )
1271+ for ( i = 0 ; i < ulHardwareSavedExceptionFrameSize ; i ++ )
12681272 {
12691273 pulSystemCallStack [ i ] = pulTaskStack [ i ];
12701274 }
@@ -1300,7 +1304,7 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
13001304
13011305 /* Remember the location where we should copy the stack frame when we exit from
13021306 * the system call. */
1303- pxMpuSettings -> xSystemCallStackInfo .pulTaskStack = pulTaskStack + ulStackFrameSize ;
1307+ pxMpuSettings -> xSystemCallStackInfo .pulTaskStack = pulTaskStack + ulHardwareSavedExceptionFrameSize ;
13041308
13051309 /* Record if the hardware used padding to force the stack pointer
13061310 * to be double word aligned. */
@@ -1350,7 +1354,7 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
13501354 extern TaskHandle_t pxCurrentTCB ;
13511355 xMPU_SETTINGS * pxMpuSettings ;
13521356 uint32_t * pulTaskStack ;
1353- uint32_t ulStackFrameSize , ulSystemCallLocation , i ;
1357+ uint32_t ulHardwareSavedExceptionFrameSize , ulSystemCallLocation , i ;
13541358
13551359 #if defined( __ARMCC_VERSION )
13561360
@@ -1382,12 +1386,16 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
13821386 {
13831387 pulTaskStack = pxMpuSettings -> xSystemCallStackInfo .pulTaskStack ;
13841388
1389+ /* Hardware Saved Stack Frame Size upon Exception entry:
1390+ * - No FPU: basic frame (R0-R3, R12, LR, PC, and xPSR) = 8 words.
1391+ * - With FPU (lazy stacking): basic frame + S0–S15 + FPSCR + reserved word = 26 words.
1392+ */
13851393 #if ( ( configENABLE_FPU == 1 ) || ( configENABLE_MVE == 1 ) )
13861394 {
13871395 if ( ( ulLR & portEXC_RETURN_STACK_FRAME_TYPE_MASK ) == 0UL )
13881396 {
13891397 /* Extended frame i.e. FPU in use. */
1390- ulStackFrameSize = 26 ;
1398+ ulHardwareSavedExceptionFrameSize = 26 ;
13911399 __asm volatile (
13921400 " vpush {s0} \n" /* Trigger lazy stacking. */
13931401 " vpop {s0} \n" /* Nullify the affect of the above instruction. */
@@ -1397,20 +1405,20 @@ void vPortSVCHandler_C( uint32_t * pulCallerStackAddress ) /* PRIVILEGED_FUNCTIO
13971405 else
13981406 {
13991407 /* Standard frame i.e. FPU not in use. */
1400- ulStackFrameSize = 8 ;
1408+ ulHardwareSavedExceptionFrameSize = 8 ;
14011409 }
14021410 }
14031411 #else /* if ( ( configENABLE_FPU == 1 ) || ( configENABLE_MVE == 1 ) ) */
14041412 {
1405- ulStackFrameSize = 8 ;
1413+ ulHardwareSavedExceptionFrameSize = 8 ;
14061414 }
14071415 #endif /* configENABLE_FPU || configENABLE_MVE */
14081416
14091417 /* Make space on the task stack for the stack frame. */
1410- pulTaskStack = pulTaskStack - ulStackFrameSize ;
1418+ pulTaskStack = pulTaskStack - ulHardwareSavedExceptionFrameSize ;
14111419
14121420 /* Copy the stack frame. */
1413- for ( i = 0 ; i < ulStackFrameSize ; i ++ )
1421+ for ( i = 0 ; i < ulHardwareSavedExceptionFrameSize ; i ++ )
14141422 {
14151423 pulTaskStack [ i ] = pulSystemCallStack [ i ];
14161424 }
0 commit comments