arch: Fix the stack boundary calculation and check

All supported arch uses a push-down stack:
The stack grows toward lower addresses in memory. The stack pointer
register points to the lowest, valid working address (the "top" of
the stack). Items on the stack are referenced as positive(include zero)
word offsets from sp.
Which means that for stack in the [begin, begin + size):
1.The initial SP point to begin + size
2.push equals sub and then store
3.pop equals load and then add

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2021-04-07 23:50:51 +08:00
committed by David Sidrane
parent 15932fa9ea
commit 3f67c67aaf
126 changed files with 210 additions and 281 deletions
+2 -2
View File
@@ -193,14 +193,14 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
* referenced as positive word offsets from sp.
*/
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size;
/* The Z80 stack does not need to be aligned. Here is is aligned at
* word (4 byte) boundary.
*/
top_of_stack &= ~3;
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr;
/* Save the adjusted stack values in the struct tcb_s */
+2 -2
View File
@@ -104,14 +104,14 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size)
* the stack are* referenced as positive word offsets from sp.
*/
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size;
/* The Z80 stack does not need to be aligned. Here is is aligned at
* word (4 byte) boundary.
*/
top_of_stack &= ~3;
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr;
/* Save the adjusted stack values in the struct tcb_s */
+1 -1
View File
@@ -49,7 +49,7 @@ extern far unsigned long far_heapbot;
#ifndef CONFIG_HEAP1_END
extern far unsigned long far_stacktop;
# define CONFIG_HEAP1_END \
(((uint16_t)&far_stacktop) - CONFIG_IDLETHREAD_STACKSIZE + 1)
(((uint16_t)&far_stacktop) - CONFIG_IDLETHREAD_STACKSIZE)
#endif
/************************************************************************************