From b2ddedb941a7418510e25e13400d75a284f129ce Mon Sep 17 00:00:00 2001 From: Omar Chebib Date: Fri, 11 Nov 2022 15:00:42 +0800 Subject: [PATCH] FreeRTOS: Make the default stack alignment 16 for Xtensa --- components/freertos/port/riscv/port.c | 4 +++- components/freertos/port/xtensa/include/freertos/portmacro.h | 2 +- components/freertos/port/xtensa/port.c | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/freertos/port/riscv/port.c b/components/freertos/port/riscv/port.c index a71a589602..51bcc61031 100644 --- a/components/freertos/port/riscv/port.c +++ b/components/freertos/port/riscv/port.c @@ -95,7 +95,7 @@ #include "portmacro.h" #include "port_systick.h" - +_Static_assert(portBYTE_ALIGNMENT == 16, "portBYTE_ALIGNMENT must be set to 16"); /* ---------------------------------------------------- Variables ------------------------------------------------------ * @@ -248,6 +248,8 @@ StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxC frame->gp = (UBaseType_t)&__global_pointer$; frame->tp = (UBaseType_t)threadptr; + configASSERT(((uint32_t) frame & portBYTE_ALIGNMENT_MASK) == 0); + //TODO: IDF-2393 return (StackType_t *)frame; } diff --git a/components/freertos/port/xtensa/include/freertos/portmacro.h b/components/freertos/port/xtensa/include/freertos/portmacro.h index 2ee4c12c2b..bce731d331 100644 --- a/components/freertos/port/xtensa/include/freertos/portmacro.h +++ b/components/freertos/port/xtensa/include/freertos/portmacro.h @@ -106,7 +106,7 @@ typedef uint32_t TickType_t; #define portCRITICAL_NESTING_IN_TCB 0 #define portSTACK_GROWTH ( -1 ) #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) -#define portBYTE_ALIGNMENT 4 +#define portBYTE_ALIGNMENT 16 // Xtensa Windowed ABI requires the stack pointer to always be 16-byte aligned. See "isa_rm.pdf 8.1.1 Windowed Register Usage and Stack Layout" #define portNOP() XT_NOP() diff --git a/components/freertos/port/xtensa/port.c b/components/freertos/port/xtensa/port.c index 84d8d99f41..191b580533 100644 --- a/components/freertos/port/xtensa/port.c +++ b/components/freertos/port/xtensa/port.c @@ -66,6 +66,8 @@ #include "task.h" /* Required for TaskHandle_t, tskNO_AFFINITY, and vTaskStartScheduler */ #include "port_systick.h" +_Static_assert(portBYTE_ALIGNMENT == 16, "portBYTE_ALIGNMENT must be set to 16"); + _Static_assert(tskNO_AFFINITY == CONFIG_FREERTOS_NO_AFFINITY, "incorrect tskNO_AFFINITY value"); @@ -241,6 +243,8 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px p[2] = (((uint32_t) p) + 12 + XCHAL_TOTAL_SA_ALIGN - 1) & -XCHAL_TOTAL_SA_ALIGN; #endif /* XCHAL_CP_NUM */ + configASSERT(((uint32_t) sp & portBYTE_ALIGNMENT_MASK) == 0); + return sp; }