diff --git a/os/ports/GCC/SIMIA32/chcore.h b/os/ports/GCC/SIMIA32/chcore.h index d7fe957a1..1dcab09d1 100644 --- a/os/ports/GCC/SIMIA32/chcore.h +++ b/os/ports/GCC/SIMIA32/chcore.h @@ -98,6 +98,12 @@ struct context { #define APUSH(p, a) (p) -= sizeof(void *), *(void **)(p) = (void*)(a) +/* Darwin requires the stack to be aligned to a 16-byte boundary at + * the time of a call instruction (in case the called function needs + * to save MMX registers). This aligns to 'mod' module 16, so that we'll end + * up with the right alignment after pushing the args. */ +#define AALIGN(p, mask, mod) p = (void *)((((uintptr_t)(p) - mod) & ~mask) + mod) + /** * Platform dependent part of the @p chThdCreateI() API. * This code usually setup the context switching frame represented by a @@ -105,6 +111,9 @@ struct context { */ #define SETUP_CONTEXT(workspace, wsize, pf, arg) { \ uint8_t *esp = (uint8_t *)workspace + wsize; \ + APUSH(esp, 0); \ + uint8_t *savebp = esp; \ + AALIGN(esp, 15, 8); \ APUSH(esp, arg); \ APUSH(esp, pf); \ APUSH(esp, 0); \ @@ -113,7 +122,7 @@ struct context { ((struct intctx *)esp)->ebx = 0; \ ((struct intctx *)esp)->edi = 0; \ ((struct intctx *)esp)->esi = 0; \ - ((struct intctx *)esp)->ebp = 0; \ + ((struct intctx *)esp)->ebp = savebp; \ tp->p_ctx.esp = (struct intctx *)esp; \ } diff --git a/readme.txt b/readme.txt index 4da234769..5280a83b5 100644 --- a/readme.txt +++ b/readme.txt @@ -79,6 +79,8 @@ ***************************************************************************** *** 2.5.0 *** +- FIX: Fixed stack misalignment on Posix-MacOSX (bug 3495487)(backported + in 2.2.9 and 2.4.1). - FIX: Fixed STM8S HSI clock initialization error (bug 3489727)(backported to 2.2.9 and 2.4.1). - FIX: Fixed MMC over SPI driver performs an unnecessary SPI read (bug