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
|
|
|
*/
|
|
|
|
|
2022-05-06 16:49:15 +08:00
|
|
|
#include <zephyr/kernel.h>
|
2019-10-24 23:08:21 +08:00
|
|
|
#include <ksched.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
|
2019-03-09 05:19:05 +08:00
|
|
|
* to z_thread_entry() since this arch puts the first four arguments
|
2016-06-18 04:09:40 +08:00
|
|
|
* in r4-r7 and not on the stack
|
|
|
|
*/
|
2019-03-14 23:20:46 +08:00
|
|
|
void z_thread_entry_wrapper(k_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 */
|
|
|
|
|
2019-03-14 23:20:46 +08:00
|
|
|
/* Used by z_thread_entry_wrapper. pulls these off the stack and
|
2019-03-09 05:19:05 +08:00
|
|
|
* into argument registers before calling z_thread_entry()
|
2016-06-18 04:09:40 +08:00
|
|
|
*/
|
2017-09-12 00:30:04 +08:00
|
|
|
k_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 */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-11-08 04:43:29 +08:00
|
|
|
void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
|
2020-04-24 04:55:56 +08:00
|
|
|
char *stack_ptr, k_thread_entry_t entry,
|
2020-04-24 02:17:14 +08:00
|
|
|
void *arg1, void *arg2, void *arg3)
|
2016-04-22 05:47:09 +08:00
|
|
|
{
|
2016-06-18 04:09:40 +08:00
|
|
|
struct init_stack_frame *iframe;
|
|
|
|
|
|
|
|
/* Initial stack frame data, stored at the base of the stack */
|
2020-04-24 04:55:56 +08:00
|
|
|
iframe = Z_STACK_PTR_TO_FRAME(struct init_stack_frame, stack_ptr);
|
2016-06-18 04:09:40 +08:00
|
|
|
|
|
|
|
/* Setup the initial stack frame */
|
2020-04-24 02:32:08 +08:00
|
|
|
iframe->entry_point = entry;
|
2016-06-18 04:09:40 +08:00
|
|
|
iframe->arg1 = arg1;
|
|
|
|
iframe->arg2 = arg2;
|
|
|
|
iframe->arg3 = arg3;
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
thread->callee_saved.sp = (uint32_t)iframe;
|
|
|
|
thread->callee_saved.ra = (uint32_t)z_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-04-22 05:47:09 +08:00
|
|
|
}
|