From 09a2a11dd7cce584c255ad7d170461ae489ae8eb Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Sat, 27 Apr 2019 13:04:23 +0200 Subject: [PATCH] cpu/esp: fix computation of coprocessor save area `top_of_stack` isn't aligned down to the previous 16 byte aligned address. Furthermore, `top_of_stack` as well as `XT_CP_SIZE` are used unaligned in `cpu/esp_common/vendor/xtensa/portasm.S` in the address computation for the coprocessor save area, . Aligning pointer `p` down to the previous 16 byte aligned address results in a wrong address of the coprocessor save area during the initialization of the thread context. This leads to wrong values and wrong positions of these values in the coprocessor save area in inital thread context. Since ESP8266 doesn't have a coprocessor, this bug affects only ESP32. --- cpu/esp32/thread_arch.c | 2 +- cpu/esp8266/thread_arch.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cpu/esp32/thread_arch.c b/cpu/esp32/thread_arch.c index 75beeede20..6f02df8cbc 100644 --- a/cpu/esp32/thread_arch.c +++ b/cpu/esp32/thread_arch.c @@ -183,7 +183,7 @@ char* thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_sta uint32_t *p; - p = (uint32_t *)(((uint32_t)(top_of_stack + 1) - XT_CP_SIZE) & ~0xf); + p = (uint32_t *)(((uint32_t)(top_of_stack + 1) - XT_CP_SIZE)); p[0] = 0; p[1] = 0; p[2] = (((uint32_t) p) + 12 + XCHAL_TOTAL_SA_ALIGN - 1) & -XCHAL_TOTAL_SA_ALIGN; diff --git a/cpu/esp8266/thread_arch.c b/cpu/esp8266/thread_arch.c index 83816b7163..eca968959a 100644 --- a/cpu/esp8266/thread_arch.c +++ b/cpu/esp8266/thread_arch.c @@ -174,7 +174,7 @@ char* thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_sta */ uint32_t *p; - p = (uint32_t *)(((uint32_t) pxTopOfStack - XT_CP_SIZE) & ~0xf); + p = (uint32_t *)(((uint32_t) pxTopOfStack - XT_CP_SIZE)); p[0] = 0; p[1] = 0; p[2] = (((uint32_t) p) + 12 + XCHAL_TOTAL_SA_ALIGN - 1) & -XCHAL_TOTAL_SA_ALIGN;