2016-04-22 05:47:09 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-04-22 05:47:09 +08:00
|
|
|
*/
|
|
|
|
|
2016-11-08 23:36:50 +08:00
|
|
|
#include <kernel.h>
|
|
|
|
#include <nano_internal.h>
|
|
|
|
#include <kernel_structs.h>
|
2016-06-18 04:09:40 +08:00
|
|
|
#include <wait_q.h>
|
|
|
|
#include <string.h>
|
2016-04-22 05:47:09 +08:00
|
|
|
|
2016-06-18 04:09:40 +08:00
|
|
|
/* forward declaration to asm function to adjust setup the arguments
|
|
|
|
* to _thread_entry() since this arch puts the first four arguments
|
|
|
|
* in r4-r7 and not on the stack
|
|
|
|
*/
|
2016-10-26 02:47:52 +08:00
|
|
|
void _thread_entry_wrapper(_thread_entry_t, void *, void *, void *);
|
2016-06-18 04:09:40 +08:00
|
|
|
|
|
|
|
struct init_stack_frame {
|
|
|
|
/* top of the stack / most recently pushed */
|
|
|
|
|
|
|
|
/* Used by _thread_entry_wrapper. pulls these off the stack and
|
|
|
|
* into argument registers before calling _thread_entry()
|
|
|
|
*/
|
|
|
|
_thread_entry_t entry_point;
|
2016-10-26 02:47:52 +08:00
|
|
|
void *arg1;
|
|
|
|
void *arg2;
|
|
|
|
void *arg3;
|
2016-06-18 04:09:40 +08:00
|
|
|
|
|
|
|
/* least recently pushed */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-11-15 05:46:14 +08:00
|
|
|
void _new_thread(char *stack_memory, size_t stack_size,
|
2016-11-20 01:31:53 +08:00
|
|
|
_thread_entry_t thread_func,
|
2016-10-26 02:47:52 +08:00
|
|
|
void *arg1, void *arg2, void *arg3,
|
2017-04-22 00:41:26 +08:00
|
|
|
int priority, unsigned int options)
|
2016-04-22 05:47:09 +08:00
|
|
|
{
|
2016-11-09 04:44:05 +08:00
|
|
|
_ASSERT_VALID_PRIO(priority, thread_func);
|
|
|
|
|
2016-11-08 23:36:50 +08:00
|
|
|
struct k_thread *thread;
|
2016-06-18 04:09:40 +08:00
|
|
|
struct init_stack_frame *iframe;
|
|
|
|
|
2017-04-21 22:07:34 +08:00
|
|
|
thread = _new_thread_init(stack_memory, stack_size, priority, options);
|
|
|
|
|
2016-06-18 04:09:40 +08:00
|
|
|
/* 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));
|
|
|
|
|
|
|
|
/* Setup the initial stack frame */
|
|
|
|
iframe->entry_point = thread_func;
|
|
|
|
iframe->arg1 = arg1;
|
|
|
|
iframe->arg2 = arg2;
|
|
|
|
iframe->arg3 = arg3;
|
|
|
|
|
2017-04-21 02:30:33 +08:00
|
|
|
thread->callee_saved.sp = (u32_t)iframe;
|
|
|
|
thread->callee_saved.ra = (u32_t)_thread_entry_wrapper;
|
2016-11-08 23:36:50 +08:00
|
|
|
thread->callee_saved.key = NIOS2_STATUS_PIE_MSK;
|
|
|
|
/* Leave the rest of thread->callee_saved junk */
|
2016-06-18 04:09:40 +08:00
|
|
|
|
2016-11-08 23:36:50 +08:00
|
|
|
thread_monitor_init(thread);
|
2016-04-22 05:47:09 +08:00
|
|
|
}
|