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