arch/xtensa: Fix stack's alignment

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
Abdelatif Guettouche 2020-11-27 19:16:12 +00:00 committed by Alan Carvalho de Assis
parent fbb3cd660b
commit 967fbebcb9
3 changed files with 11 additions and 18 deletions

View File

@ -234,7 +234,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
* the stack are referenced as positive word offsets from sp.
*/
top_of_stack = (uintptr_t)tcb->stack_alloc_ptr + stack_size - 4;
top_of_stack = (uintptr_t)tcb->stack_alloc_ptr + stack_size - 16;
#if XCHAL_CP_NUM > 0
/* Allocate the co-processor save area at the top of the (push down)
@ -269,7 +269,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
*/
top_of_stack = STACK_ALIGN_DOWN(top_of_stack);
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 16;
/* Save the adjusted stack values in the struct tcb_s */

View File

@ -52,19 +52,13 @@
* Pre-processor Macros
****************************************************************************/
/* XTENSA requires at least a 4-byte stack alignment. For floating point
* use, however, the stack must be aligned to 8-byte addresses.
*/
/* XTENSA requires at least a 16-byte stack alignment. */
#ifdef CONFIG_LIBC_FLOATINGPOINT
# define STACK_ALIGNMENT 8
#else
# define STACK_ALIGNMENT 4
#endif
#define STACK_ALIGNMENT 16
/* Stack alignment macros */
#define STACK_ALIGN_MASK (STACK_ALIGNMENT-1)
#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1)
#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK)
#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK)

View File

@ -54,9 +54,9 @@
* Pre-processor Definitions
****************************************************************************/
/* XTENSA requires at least a 4-byte stack alignment. */
/* XTENSA requires at least a 16-byte stack alignment. */
#define STACK_ALIGNMENT 4
#define STACK_ALIGNMENT 16
/* Stack alignment macros */
@ -126,15 +126,14 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
* as positive word offsets from sp.
*/
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 16;
/* The XTENSA stack must be aligned at word (4 byte) or double word
* (8 byte) boundaries. If necessary top_of_stack must be rounded down to
* the next boundary
/* The XTENSA stack must be aligned at 16 bytes boundaries. If necessary
* top_of_stack must be rounded down to the next boundary.
*/
top_of_stack = STACK_ALIGN_DOWN(top_of_stack);
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 16;
/* Save the adjusted stack values in the struct tcb_s */