Fix pxTopOfStack calculation in configINIT_TLS_BLOCK for picolib (#739)

The pxTopOfStack calculation in configINIT_TLS_BLOCK for picolib needs
to decrement pxTopOfStack in order to meet the expectation of
 pxPortInitialiseStack function.
This commit is contained in:
bebebib-rs 2023-08-06 23:22:52 -07:00 committed by GitHub
parent 05d93e0990
commit b5f670f826
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -58,18 +58,19 @@
#endif #endif
/* Allocate thread local storage block off the end of the /* Allocate thread local storage block off the end of the
* stack. The _tls_size() function returns the size (in * stack. The picolibcTLS_SIZE macro returns the size (in
* bytes) of the total TLS area used by the application */ * bytes) of the total TLS area used by the application.
* Calculate the top of stack address. */
#if ( portSTACK_GROWTH < 0 ) #if ( portSTACK_GROWTH < 0 )
#define configINIT_TLS_BLOCK( xTLSBlock, pxTopOfStack ) \ #define configINIT_TLS_BLOCK( xTLSBlock, pxTopOfStack ) \
do { \ do { \
pxTopOfStack = ( StackType_t * ) ( ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) \ xTLSBlock = ( void * ) ( ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) - \
- picolibcTLS_SIZE ) & ~ \ picolibcTLS_SIZE ) & \
configMAX( picolibcSTACK_ALIGNMENT_MASK, \ ~picolibcTLS_ALIGNMENT_MASK ); \
picolibcTLS_ALIGNMENT_MASK ) ); \ pxTopOfStack = ( StackType_t * ) ( ( ( ( portPOINTER_SIZE_TYPE ) xTLSBlock ) - 1 ) & \
xTLSBlock = pxTopOfStack; \ ~picolibcSTACK_ALIGNMENT_MASK ); \
_init_tls( xTLSBlock ); \ _init_tls( xTLSBlock ); \
} while( 0 ) } while( 0 )
#else /* portSTACK_GROWTH */ #else /* portSTACK_GROWTH */
#define configINIT_TLS_BLOCK( xTLSBlock, pxTopOfStack ) \ #define configINIT_TLS_BLOCK( xTLSBlock, pxTopOfStack ) \