From f94093bc2eb95c1f737dde4501aa8487dbac3942 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 12 Mar 2022 23:46:52 +0800 Subject: [PATCH] arch/ceva: Move the idle stack initialization to up_initial_state to follow other arch's implementation Signed-off-by: Xiang Xiao --- arch/ceva/include/arch.h | 2 ++ arch/ceva/src/common/up_createstack.c | 8 ++++++-- arch/ceva/src/common/up_initialize.c | 11 ----------- arch/ceva/src/common/up_start.c | 4 ---- arch/ceva/src/xc5/up_initialstate.c | 19 +++++++++++++++++++ arch/ceva/src/xm6/up_initialstate.c | 19 +++++++++++++++++++ 6 files changed, 46 insertions(+), 17 deletions(-) diff --git a/arch/ceva/include/arch.h b/arch/ceva/include/arch.h index 4dfdd2df8b..ecb877d07b 100644 --- a/arch/ceva/include/arch.h +++ b/arch/ceva/include/arch.h @@ -30,6 +30,8 @@ ****************************************************************************/ #include + +#include #include /**************************************************************************** diff --git a/arch/ceva/src/common/up_createstack.c b/arch/ceva/src/common/up_createstack.c index 0868af0778..1eab7ad0d9 100644 --- a/arch/ceva/src/common/up_createstack.c +++ b/arch/ceva/src/common/up_createstack.c @@ -230,8 +230,12 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) #ifdef CONFIG_STACK_COLORATION void up_stack_color(FAR void *stackbase, size_t nbytes) { - uint32_t *stkptr = stackbase; - size_t nwords = nbytes / sizeof(uint32_t); + /* Take extra care that we do not write outsize the stack boundaries */ + + uint32_t *stkptr = (uint32_t *)(((uintptr_t)stackbase + 3) & ~3); + uintptr_t stkend = nbytes ? (((uintptr_t)stackbase + nbytes) & ~3) : + up_getsp(); /* 0: colorize the running stack */ + size_t nwords = (stkend - (uintptr_t)stackbase) >> 2; /* Set the entire stack to the coloration value */ diff --git a/arch/ceva/src/common/up_initialize.c b/arch/ceva/src/common/up_initialize.c index 8a82cf88eb..c2476b0ccf 100644 --- a/arch/ceva/src/common/up_initialize.c +++ b/arch/ceva/src/common/up_initialize.c @@ -47,8 +47,6 @@ #include "up_internal.h" #include "chip.h" -#include "sched/sched.h" - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -98,19 +96,10 @@ static inline void up_color_intstack(void) void up_initialize(void) { - struct tcb_s *idle; - /* Initialize global variables */ CURRENT_REGS = NULL; - /* Initialize the idle task stack info */ - - idle = this_task(); /* It should be idle task */ - idle->stack_alloc_ptr = g_idle_basestack; - idle->stack_base_ptr = g_idle_topstack; - idle->adj_stack_size = g_idle_topstack - g_idle_basestack; - /* Colorize the interrupt stack */ up_color_intstack(); diff --git a/arch/ceva/src/common/up_start.c b/arch/ceva/src/common/up_start.c index 754f36c3ce..94e91e4371 100644 --- a/arch/ceva/src/common/up_start.c +++ b/arch/ceva/src/common/up_start.c @@ -243,10 +243,6 @@ static void init_kernelspace(void) mpu_priv_data(g_idle_basestack, g_idle_topstack - g_idle_basestack); -#ifdef CONFIG_STACK_COLORATION - up_stack_color(g_idle_basestack, - g_idle_topstack - g_idle_basestack - 256); -#endif } #ifdef CONFIG_BUILD_PROTECTED diff --git a/arch/ceva/src/xc5/up_initialstate.c b/arch/ceva/src/xc5/up_initialstate.c index 6c94a2d68f..bdd62bdfc4 100644 --- a/arch/ceva/src/xc5/up_initialstate.c +++ b/arch/ceva/src/xc5/up_initialstate.c @@ -29,6 +29,8 @@ #include #include +#include "up_internal.h" + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -51,6 +53,23 @@ void up_initial_state(struct tcb_s *tcb) { struct xcptcontext *xcp = &tcb->xcp; + /* Initialize the idle thread stack */ + + if (tcb->pid == 0) + { + tcb->stack_alloc_ptr = g_idle_basestack; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->adj_stack_size = g_idle_topstack - g_idle_basestack; +#ifdef CONFIG_STACK_COLORATION + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + up_stack_color(tcb->stack_alloc_ptr, 0); +#endif /* CONFIG_STACK_COLORATION */ + } + /* Initialize the initial exception register context structure */ memset(xcp, 0, sizeof(struct xcptcontext)); diff --git a/arch/ceva/src/xm6/up_initialstate.c b/arch/ceva/src/xm6/up_initialstate.c index d9f7025aff..d7207cb8b1 100644 --- a/arch/ceva/src/xm6/up_initialstate.c +++ b/arch/ceva/src/xm6/up_initialstate.c @@ -29,6 +29,8 @@ #include #include +#include "up_internal.h" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -57,6 +59,23 @@ void up_initial_state(struct tcb_s *tcb) { struct xcptcontext *xcp = &tcb->xcp; + /* Initialize the idle thread stack */ + + if (tcb->pid == 0) + { + tcb->stack_alloc_ptr = g_idle_basestack; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->adj_stack_size = g_idle_topstack - g_idle_basestack; +#ifdef CONFIG_STACK_COLORATION + /* If stack debug is enabled, then fill the stack with a + * recognizable value that we can use later to test for high + * water marks. + */ + + up_stack_color(tcb->stack_alloc_ptr, 0); +#endif /* CONFIG_STACK_COLORATION */ + } + /* Initialize the initial exception register context structure */ memset(xcp, 0, sizeof(struct xcptcontext));