From 839edec64c1968cd4a4ac45d9d9a3c3316aaed9c Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 26 Apr 2023 22:41:45 +0200 Subject: [PATCH] cortexm: fix stack size offset The old code was broken and led to a HardFault in a rather convoluted way: 1. The CFA offset was incorrect, in fact it was not aligned (the stack is supposed to always be aligned to 4 bytes at least). 2. This unaligned size was then used for stack size calculations. 3. A stack that wasn't a multiple of 4 was allocated. 4. The calleeSavedRegs struct (in `(internal/task.state).archInit`) was not correctly aligned. 5. Writing to this struct resulted in a HardFault. --- src/internal/task/task_stack_cortexm.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internal/task/task_stack_cortexm.S b/src/internal/task/task_stack_cortexm.S index afb23eb2..fe1f44e0 100644 --- a/src/internal/task/task_stack_cortexm.S +++ b/src/internal/task/task_stack_cortexm.S @@ -114,9 +114,9 @@ tinygo_swapTask: pop {r4-r11, pc} #else pop {r4-r7} - .cfi_def_cfa_offset 5*9 + .cfi_def_cfa_offset 5*4 pop {r0-r3} - .cfi_def_cfa_offset 1*9 + .cfi_def_cfa_offset 1*4 mov r8, r0 mov r9, r1 mov r10, r2