aboutsummaryrefslogtreecommitdiffstats
path: root/os/ports/GCC
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-02-29 16:57:56 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-02-29 16:57:56 +0000
commit08d544d2f410357dc5fb484c3e9d476f60091079 (patch)
tree089e7e1f6d0b8a8cfcf3555ee48fec59478e03b4 /os/ports/GCC
parentd1df00f6a8f70d2013dc741524a3a967717ddae2 (diff)
downloadChibiOS-08d544d2f410357dc5fb484c3e9d476f60091079.tar.gz
ChibiOS-08d544d2f410357dc5fb484c3e9d476f60091079.tar.bz2
ChibiOS-08d544d2f410357dc5fb484c3e9d476f60091079.zip
Fixed bug 3495487.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4004 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/ports/GCC')
-rw-r--r--os/ports/GCC/SIMIA32/chcore.h11
1 files changed, 10 insertions, 1 deletions
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; \
}