From 967fbebcb960e22e49c31d48128ab5888000c32c Mon Sep 17 00:00:00 2001 From: Abdelatif Guettouche Date: Fri, 27 Nov 2020 19:16:12 +0000 Subject: [PATCH] arch/xtensa: Fix stack's alignment Signed-off-by: Abdelatif Guettouche --- arch/xtensa/src/common/xtensa_createstack.c | 4 ++-- arch/xtensa/src/common/xtensa_stackframe.c | 12 +++--------- arch/xtensa/src/common/xtensa_usestack.c | 13 ++++++------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/arch/xtensa/src/common/xtensa_createstack.c b/arch/xtensa/src/common/xtensa_createstack.c index 2dce2dceea..8d39529c18 100644 --- a/arch/xtensa/src/common/xtensa_createstack.c +++ b/arch/xtensa/src/common/xtensa_createstack.c @@ -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 */ diff --git a/arch/xtensa/src/common/xtensa_stackframe.c b/arch/xtensa/src/common/xtensa_stackframe.c index 3e88f51d37..6f74a192cf 100644 --- a/arch/xtensa/src/common/xtensa_stackframe.c +++ b/arch/xtensa/src/common/xtensa_stackframe.c @@ -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) diff --git a/arch/xtensa/src/common/xtensa_usestack.c b/arch/xtensa/src/common/xtensa_usestack.c index 06c1dcf8d6..7330b55e0a 100644 --- a/arch/xtensa/src/common/xtensa_usestack.c +++ b/arch/xtensa/src/common/xtensa_usestack.c @@ -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 */