kernel: Refactor common _new_thread init code
We do a bit of the same stuff on all the arch's to setup a new thread. So lets put that code in a common place so we unify it for everyone and reduce some duplicated code. Change-Id: Ic04121bfd6846aece16aa7ffd4382bdcdb6136e3 Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
5742a508a2
commit
b8823c4efd
7 changed files with 44 additions and 95 deletions
|
@ -83,11 +83,9 @@ void _new_thread(char *pStackMem, size_t stackSize,
|
|||
char *stackEnd = pStackMem + stackSize;
|
||||
struct init_stack_frame *pInitCtx;
|
||||
|
||||
struct k_thread *thread = (struct k_thread *) pStackMem;
|
||||
struct k_thread *thread;
|
||||
|
||||
#ifdef CONFIG_INIT_STACKS
|
||||
memset(pStackMem, 0xaa, stackSize);
|
||||
#endif
|
||||
thread = _new_thread_init(pStackMem, stackSize, priority, options);
|
||||
|
||||
/* carve the thread entry struct from the "base" of the stack */
|
||||
|
||||
|
@ -113,18 +111,6 @@ void _new_thread(char *pStackMem, size_t stackSize,
|
|||
pInitCtx->status32 = _ARC_V2_STATUS32_E(_ARC_V2_DEF_IRQ_LEVEL);
|
||||
#endif
|
||||
|
||||
_init_thread_base(&thread->base, priority, _THREAD_PRESTART, options);
|
||||
|
||||
/* static threads overwrite them afterwards with real values */
|
||||
thread->init_data = NULL;
|
||||
thread->fn_abort = NULL;
|
||||
|
||||
#ifdef CONFIG_THREAD_CUSTOM_DATA
|
||||
/* Initialize custom data field (value is opaque to kernel) */
|
||||
|
||||
thread->custom_data = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_THREAD_MONITOR
|
||||
/*
|
||||
* In debug mode thread->entry give direct access to the thread entry
|
||||
|
|
|
@ -83,9 +83,7 @@ void _new_thread(char *pStackMem, size_t stackSize,
|
|||
struct __esf *pInitCtx;
|
||||
struct k_thread *thread = (struct k_thread *) pStackMem;
|
||||
|
||||
#ifdef CONFIG_INIT_STACKS
|
||||
memset(pStackMem, 0xaa, stackSize);
|
||||
#endif
|
||||
thread = _new_thread_init(pStackMem, stackSize, priority, options);
|
||||
|
||||
/* carve the thread entry struct from the "base" of the stack */
|
||||
|
||||
|
@ -100,18 +98,6 @@ void _new_thread(char *pStackMem, size_t stackSize,
|
|||
pInitCtx->xpsr =
|
||||
0x01000000UL; /* clear all, thumb bit is 1, even if RO */
|
||||
|
||||
_init_thread_base(&thread->base, priority, _THREAD_PRESTART, options);
|
||||
|
||||
/* static threads overwrite it afterwards with real value */
|
||||
thread->init_data = NULL;
|
||||
thread->fn_abort = NULL;
|
||||
|
||||
#ifdef CONFIG_THREAD_CUSTOM_DATA
|
||||
/* Initialize custom data field (value is opaque to kernel) */
|
||||
|
||||
thread->custom_data = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_THREAD_MONITOR
|
||||
/*
|
||||
* In debug mode thread->entry give direct access to the thread entry
|
||||
|
|
|
@ -60,9 +60,8 @@ void _new_thread(char *stack_memory, size_t stack_size,
|
|||
struct k_thread *thread;
|
||||
struct init_stack_frame *iframe;
|
||||
|
||||
#ifdef CONFIG_INIT_STACKS
|
||||
memset(stack_memory, 0xaa, stack_size);
|
||||
#endif
|
||||
thread = _new_thread_init(stack_memory, stack_size, priority, options);
|
||||
|
||||
/* Initial stack frame data, stored at the base of the stack */
|
||||
iframe = (struct init_stack_frame *)
|
||||
STACK_ROUND_DOWN(stack_memory + stack_size - sizeof(*iframe));
|
||||
|
@ -73,19 +72,6 @@ void _new_thread(char *stack_memory, size_t stack_size,
|
|||
iframe->arg2 = arg2;
|
||||
iframe->arg3 = arg3;
|
||||
|
||||
/* Initialize various struct k_thread members */
|
||||
thread = (struct k_thread *)stack_memory;
|
||||
|
||||
_init_thread_base(&thread->base, priority, _THREAD_PRESTART, options);
|
||||
|
||||
/* static threads overwrite it afterwards with real value */
|
||||
thread->init_data = NULL;
|
||||
thread->fn_abort = NULL;
|
||||
|
||||
#ifdef CONFIG_THREAD_CUSTOM_DATA
|
||||
/* Initialize custom data field (value is opaque to kernel) */
|
||||
thread->custom_data = NULL;
|
||||
#endif
|
||||
thread->callee_saved.sp = (u32_t)iframe;
|
||||
thread->callee_saved.ra = (u32_t)_thread_entry_wrapper;
|
||||
thread->callee_saved.key = NIOS2_STATUS_PIE_MSK;
|
||||
|
|
|
@ -44,9 +44,8 @@ void _new_thread(char *stack_memory, size_t stack_size,
|
|||
struct k_thread *thread;
|
||||
struct __esf *stack_init;
|
||||
|
||||
#ifdef CONFIG_INIT_STACKS
|
||||
memset(stack_memory, 0xaa, stack_size);
|
||||
#endif
|
||||
thread = _new_thread_init(stack_memory, stack_size, priority, options);
|
||||
|
||||
/* Initial stack frame for thread */
|
||||
stack_init = (struct __esf *)
|
||||
STACK_ROUND_DOWN(stack_memory +
|
||||
|
@ -83,20 +82,6 @@ void _new_thread(char *stack_memory, size_t stack_size,
|
|||
stack_init->mstatus = SOC_MSTATUS_DEF_RESTORE;
|
||||
stack_init->mepc = (u32_t)_thread_entry_wrapper;
|
||||
|
||||
/* Initialize various struct k_thread members */
|
||||
thread = (struct k_thread *)stack_memory;
|
||||
|
||||
_init_thread_base(&thread->base, priority, _THREAD_PRESTART, options);
|
||||
|
||||
/* static threads overwrite it afterwards with real value */
|
||||
thread->init_data = NULL;
|
||||
thread->fn_abort = NULL;
|
||||
|
||||
#ifdef CONFIG_THREAD_CUSTOM_DATA
|
||||
/* Initialize custom data field (value is opaque to kernel) */
|
||||
thread->custom_data = NULL;
|
||||
#endif
|
||||
|
||||
thread->callee_saved.sp = (u32_t)stack_init;
|
||||
|
||||
thread_monitor_init(thread);
|
||||
|
|
|
@ -67,28 +67,15 @@ static ALWAYS_INLINE void thread_monitor_init(struct k_thread *thread)
|
|||
*/
|
||||
static void _new_thread_internal(char *pStackMem, unsigned int stackSize,
|
||||
int priority,
|
||||
unsigned int options)
|
||||
unsigned int options,
|
||||
struct k_thread *thread)
|
||||
{
|
||||
unsigned long *pInitialCtx;
|
||||
/* ptr to the new task's k_thread */
|
||||
struct k_thread *thread = (struct k_thread *)pStackMem;
|
||||
|
||||
#if (defined(CONFIG_FP_SHARING) || defined(CONFIG_GDB_INFO))
|
||||
thread->arch.excNestCount = 0;
|
||||
#endif /* CONFIG_FP_SHARING || CONFIG_GDB_INFO */
|
||||
|
||||
_init_thread_base(&thread->base, priority, _THREAD_PRESTART, options);
|
||||
|
||||
/* static threads overwrite it afterwards with real value */
|
||||
thread->init_data = NULL;
|
||||
thread->fn_abort = NULL;
|
||||
|
||||
#ifdef CONFIG_THREAD_CUSTOM_DATA
|
||||
/* Initialize custom data field (value is opaque to kernel) */
|
||||
|
||||
thread->custom_data = NULL;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The creation of the initial stack for the task has already been done.
|
||||
* Now all that is needed is to set the ESP. However, we have been passed
|
||||
|
@ -235,10 +222,9 @@ void _new_thread(char *pStackMem, size_t stackSize,
|
|||
_ASSERT_VALID_PRIO(priority, pEntry);
|
||||
|
||||
unsigned long *pInitialThread;
|
||||
struct k_thread *thread;
|
||||
|
||||
#ifdef CONFIG_INIT_STACKS
|
||||
memset(pStackMem, 0xaa, stackSize);
|
||||
#endif
|
||||
thread = _new_thread_init(pStackMem, stackSize, priority, options);
|
||||
|
||||
/* carve the thread entry struct from the "base" of the stack */
|
||||
|
||||
|
@ -288,5 +274,5 @@ void _new_thread(char *pStackMem, size_t stackSize,
|
|||
* aside for the thread's stack.
|
||||
*/
|
||||
|
||||
_new_thread_internal(pStackMem, stackSize, priority, options);
|
||||
_new_thread_internal(pStackMem, stackSize, priority, options, thread);
|
||||
}
|
||||
|
|
|
@ -86,19 +86,18 @@ void _new_thread(char *pStack, size_t stackSize,
|
|||
/* k_thread is located at top of stack while frames are located at end
|
||||
* of it
|
||||
*/
|
||||
struct k_thread *thread = (struct k_thread *)(pStack);
|
||||
struct k_thread *thread;
|
||||
#if XCHAL_CP_NUM > 0
|
||||
u32_t *cpSA;
|
||||
char *cpStack;
|
||||
#endif
|
||||
|
||||
thread = _new_thread_init(pStack, stackSize, priority, options);
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
printk("\nstackPtr = %p, stackSize = %d\n", pStack, stackSize);
|
||||
printk("stackEnd = %p\n", stackEnd);
|
||||
#endif
|
||||
#ifdef CONFIG_INIT_STACKS
|
||||
memset(pStack, 0xaa, stackSize);
|
||||
#endif
|
||||
#if XCHAL_CP_NUM > 0
|
||||
/* Ensure CP state descriptor is correctly initialized */
|
||||
cpStack = thread->arch.preempCoprocReg.cpStack; /* short hand alias */
|
||||
|
@ -154,14 +153,6 @@ void _new_thread(char *pStack, size_t stackSize,
|
|||
#endif
|
||||
thread->callee_saved.topOfStack = pInitCtx;
|
||||
thread->arch.flags = 0;
|
||||
_init_thread_base(&thread->base, prio, _THREAD_PRESTART, options);
|
||||
/* static threads overwrite it afterwards with real value */
|
||||
thread->init_data = NULL;
|
||||
thread->fn_abort = NULL;
|
||||
#ifdef CONFIG_THREAD_CUSTOM_DATA
|
||||
/* Initialize custom data field (value is opaque to kernel) */
|
||||
thread->custom_data = NULL;
|
||||
#endif
|
||||
#ifdef CONFIG_THREAD_MONITOR
|
||||
/*
|
||||
* In debug mode thread->entry give direct access to the thread entry
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#if !defined(_ASMLANGUAGE)
|
||||
#include <atomic.h>
|
||||
#include <misc/dlist.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
@ -239,6 +240,34 @@ extern void _init_thread_base(struct _thread_base *thread_base,
|
|||
int priority, u32_t initial_state,
|
||||
unsigned int options);
|
||||
|
||||
static ALWAYS_INLINE struct k_thread *_new_thread_init(char *pStack,
|
||||
size_t stackSize,
|
||||
int prio,
|
||||
unsigned int options)
|
||||
{
|
||||
struct k_thread *thread;
|
||||
|
||||
#ifdef CONFIG_INIT_STACKS
|
||||
memset(pStack, 0xaa, stackSize);
|
||||
#endif
|
||||
|
||||
/* Initialize various struct k_thread members */
|
||||
thread = (struct k_thread *)pStack;
|
||||
|
||||
_init_thread_base(&thread->base, prio, _THREAD_PRESTART, options);
|
||||
|
||||
/* static threads overwrite it afterwards with real value */
|
||||
thread->init_data = NULL;
|
||||
thread->fn_abort = NULL;
|
||||
|
||||
#ifdef CONFIG_THREAD_CUSTOM_DATA
|
||||
/* Initialize custom data field (value is opaque to kernel) */
|
||||
thread->custom_data = NULL;
|
||||
#endif
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
#endif /* _ASMLANGUAGE */
|
||||
|
||||
#endif /* _kernel_structs__h_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue