mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-06-06 12:29:03 -04:00
Xtensa: fix stack overlap coproc_area issue (#118)
In function pxPortInitialiseStack of port.c: sp = ( StackType_t * ) ( ( ( UBaseType_t ) ( pxTopOfStack + 1 ) - XT_CP_SIZE - XT_STK_FRMSZ ) & ~0xf ); We assume XT_CP_SIZE is 0xE4, XT_STK_FRMSZ is 0xA0, pxTopOfStack is 0xA0000000, sp is 0x9FFFFE80. From port.c, we know the frame->a1 as below: frame->a1 = ( UBaseType_t ) sp + XT_STK_FRMSZ; /* physical top of stack frame */ So frame->a1 is 0x9FFFFF20. Therefore the interrupt stack frame range is 0x9FFFFE80 ~ 0x9FFFFF20. The coproc_area is: p = ( uint32_t * ) ( ( ( uint32_t ) pxTopOfStack - XT_CP_SIZE ) & ~0xf ); So its value is 0x9FFFFF10. Obviously, the interrupt stack frame overlaps the coproc_area. Co-authored-by: Carl Lundin <53273776+lundinc2@users.noreply.github.com>
This commit is contained in:
parent
f376c3bd71
commit
b9748e50ea
7
portable/ThirdParty/XCC/Xtensa/port.c
vendored
7
portable/ThirdParty/XCC/Xtensa/port.c
vendored
|
@ -92,16 +92,19 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px
|
||||||
{
|
{
|
||||||
StackType_t * sp, * tp;
|
StackType_t * sp, * tp;
|
||||||
XtExcFrame * frame;
|
XtExcFrame * frame;
|
||||||
|
|
||||||
#if XCHAL_CP_NUM > 0
|
#if XCHAL_CP_NUM > 0
|
||||||
uint32_t * p;
|
uint32_t * p;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Create interrupt stack frame aligned to 16 byte boundary */
|
/* Create interrupt stack frame aligned to 16 byte boundary */
|
||||||
sp = (StackType_t *) (((UBaseType_t)(pxTopOfStack + 1) - XT_CP_SIZE - XT_STK_FRMSZ) & ~0xf);
|
sp = ( StackType_t * ) ( ( ( UBaseType_t ) pxTopOfStack - XT_CP_SIZE - XT_STK_FRMSZ ) & ~0xf );
|
||||||
|
|
||||||
/* Clear the entire frame (do not use memset() because we don't depend on C library) */
|
/* Clear the entire frame (do not use memset() because we don't depend on C library) */
|
||||||
for( tp = sp; tp <= pxTopOfStack; ++tp )
|
for( tp = sp; tp <= pxTopOfStack; ++tp )
|
||||||
|
{
|
||||||
*tp = 0;
|
*tp = 0;
|
||||||
|
}
|
||||||
|
|
||||||
frame = ( XtExcFrame * ) sp;
|
frame = ( XtExcFrame * ) sp;
|
||||||
|
|
||||||
|
@ -129,10 +132,12 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px
|
||||||
|
|
||||||
#if XCHAL_CP_NUM > 0
|
#if XCHAL_CP_NUM > 0
|
||||||
/* Init the coprocessor save area (see xtensa_context.h) */
|
/* Init the coprocessor save area (see xtensa_context.h) */
|
||||||
|
|
||||||
/* No access to TCB here, so derive indirectly. Stack growth is top to bottom.
|
/* No access to TCB here, so derive indirectly. Stack growth is top to bottom.
|
||||||
* //p = (uint32_t *) xMPUSettings->coproc_area;
|
* //p = (uint32_t *) xMPUSettings->coproc_area;
|
||||||
*/
|
*/
|
||||||
p = ( uint32_t * ) ( ( ( uint32_t ) pxTopOfStack - XT_CP_SIZE ) & ~0xf );
|
p = ( uint32_t * ) ( ( ( uint32_t ) pxTopOfStack - XT_CP_SIZE ) & ~0xf );
|
||||||
|
configASSERT( ( uint32_t ) p >= frame->a1 );
|
||||||
p[ 0 ] = 0;
|
p[ 0 ] = 0;
|
||||||
p[ 1 ] = 0;
|
p[ 1 ] = 0;
|
||||||
p[ 2 ] = ( ( ( uint32_t ) p ) + 12 + XCHAL_TOTAL_SA_ALIGN - 1 ) & -XCHAL_TOTAL_SA_ALIGN;
|
p[ 2 ] = ( ( ( uint32_t ) p ) + 12 + XCHAL_TOTAL_SA_ALIGN - 1 ) & -XCHAL_TOTAL_SA_ALIGN;
|
||||||
|
|
Loading…
Reference in a new issue