arch: fix alignment bug for archs that need stack alignment

These archs only align the size of the stack, forgeting to do the
 stack start addr alignment, this patch fixes it.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
This commit is contained in:
wangchengdong
2025-09-18 17:31:43 +08:00
committed by Alan C. Assis
parent bd28635b68
commit b92e0b6730
17 changed files with 81 additions and 318 deletions
+4 -20
View File
@@ -85,27 +85,11 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
/* Save the new stack allocation */
tcb->stack_alloc_ptr = stack;
tcb->stack_base_ptr = (void *)STACK_ALIGN_UP((uintptr_t)stack);
/* sparc uses a push-down stack: the stack grows toward loweraddresses in
* memory. The stack pointer register, points to the lowest, valid work
* address (the "top" of the stack). Items on the stack are referenced
* as positive word offsets from sp.
*/
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size;
/* The sparc stack must be aligned at word (4 byte) or double word (8 byte)
* boundaries. If necessary top_of_stack must be rounded down to the
* next boundary
*/
top_of_stack = STACK_ALIGN_DOWN(top_of_stack);
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr;
/* Save the adjusted stack values in the struct tcb_s */
tcb->stack_base_ptr = tcb->stack_alloc_ptr;
tcb->adj_stack_size = size_of_stack;
top_of_stack = STACK_ALIGN_DOWN((uintptr_t)stack + stack_size);
size_of_stack = top_of_stack - (uintptr_t)tcb->stack_base_ptr;
tcb->adj_stack_size = size_of_stack;
#ifdef CONFIG_STACK_COLORATION
/* If stack debug is enabled, then fill the stack with a