2016-04-21 14:47:09 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-18 17:01:01 -08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-04-21 14:47:09 -07:00
|
|
|
*/
|
|
|
|
|
2016-11-08 10:36:50 -05:00
|
|
|
#include <kernel.h>
|
2019-10-25 00:08:21 +09:00
|
|
|
#include <ksched.h>
|
2016-04-21 14:47:09 -07:00
|
|
|
|
2016-06-17 13:09:40 -07:00
|
|
|
/* forward declaration to asm function to adjust setup the arguments
|
2019-03-08 14:19:05 -07:00
|
|
|
* to z_thread_entry() since this arch puts the first four arguments
|
2016-06-17 13:09:40 -07:00
|
|
|
* in r4-r7 and not on the stack
|
|
|
|
*/
|
2019-03-14 09:20:46 -06:00
|
|
|
void z_thread_entry_wrapper(k_thread_entry_t, void *, void *, void *);
|
2016-06-17 13:09:40 -07:00
|
|
|
|
|
|
|
struct init_stack_frame {
|
|
|
|
/* top of the stack / most recently pushed */
|
|
|
|
|
2019-03-14 09:20:46 -06:00
|
|
|
/* Used by z_thread_entry_wrapper. pulls these off the stack and
|
2019-03-08 14:19:05 -07:00
|
|
|
* into argument registers before calling z_thread_entry()
|
2016-06-17 13:09:40 -07:00
|
|
|
*/
|
2017-09-11 09:30:04 -07:00
|
|
|
k_thread_entry_t entry_point;
|
2016-10-25 11:47:52 -07:00
|
|
|
void *arg1;
|
|
|
|
void *arg2;
|
|
|
|
void *arg3;
|
2016-06-17 13:09:40 -07:00
|
|
|
|
|
|
|
/* least recently pushed */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-11-07 12:43:29 -08:00
|
|
|
void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
|
|
|
|
size_t stack_size, k_thread_entry_t thread_func,
|
|
|
|
void *arg1, void *arg2, void *arg3,
|
|
|
|
int priority, unsigned int options)
|
2016-04-21 14:47:09 -07:00
|
|
|
{
|
2019-04-04 12:05:28 -07:00
|
|
|
char *stack_memory = Z_THREAD_STACK_BUFFER(stack);
|
2016-06-17 13:09:40 -07:00
|
|
|
struct init_stack_frame *iframe;
|
|
|
|
|
2020-04-19 14:28:15 -07:00
|
|
|
z_new_thread_init(thread, stack_memory, stack_size);
|
2017-04-21 09:07:34 -05:00
|
|
|
|
2016-06-17 13:09:40 -07:00
|
|
|
/* Initial stack frame data, stored at the base of the stack */
|
|
|
|
iframe = (struct init_stack_frame *)
|
2020-04-19 15:06:31 -07:00
|
|
|
Z_STACK_PTR_ALIGN(stack_memory + stack_size - sizeof(*iframe));
|
2016-06-17 13:09:40 -07:00
|
|
|
|
|
|
|
/* Setup the initial stack frame */
|
|
|
|
iframe->entry_point = thread_func;
|
|
|
|
iframe->arg1 = arg1;
|
|
|
|
iframe->arg2 = arg2;
|
|
|
|
iframe->arg3 = arg3;
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
thread->callee_saved.sp = (uint32_t)iframe;
|
|
|
|
thread->callee_saved.ra = (uint32_t)z_thread_entry_wrapper;
|
2016-11-08 10:36:50 -05:00
|
|
|
thread->callee_saved.key = NIOS2_STATUS_PIE_MSK;
|
|
|
|
/* Leave the rest of thread->callee_saved junk */
|
2016-04-21 14:47:09 -07:00
|
|
|
}
|