From 2867bfc1eb073868a59bfcfe94324e61a6d9c1e7 Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Sun, 17 Dec 2017 12:39:24 -0800 Subject: [PATCH] xtensa asm2: Fixup stack alignment at runtime The API allows any byte count for stack size, and tests in fact check that a stack with a 499 byte stack works correctly. No choice, have to do this at runtime. Signed-off-by: Andy Ross --- arch/xtensa/core/xtensa-asm2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/xtensa/core/xtensa-asm2.c b/arch/xtensa/core/xtensa-asm2.c index 92e77ed7222..1c258ada09a 100644 --- a/arch/xtensa/core/xtensa-asm2.c +++ b/arch/xtensa/core/xtensa-asm2.c @@ -64,7 +64,9 @@ void _new_thread(struct k_thread *thread, k_thread_stack_t *stack, size_t sz, { char *base = K_THREAD_STACK_BUFFER(stack); char *top = base + sz; - __ASSERT((((size_t)top) & 3) == 0, "Misaligned stack"); + + /* Align downward. The API as specified requires a runtime check. */ + top = (char *)(((unsigned int)top) & ~3); _new_thread_init(thread, base, sz, prio, opts);