1 /*
2 * Copyright (c) 2021 Antony Pavlov <antonynpavlov@gmail.com>
3 *
4 * based on arch/riscv/core/thread.c
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9 #include <zephyr/kernel.h>
10
11 extern uint32_t mips_cp0_status_int_mask;
12
13 void z_thread_entry(k_thread_entry_t thread,
14 void *arg1,
15 void *arg2,
16 void *arg3);
17
arch_new_thread(struct k_thread * thread,k_thread_stack_t * stack,char * stack_ptr,k_thread_entry_t entry,void * p1,void * p2,void * p3)18 void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
19 char *stack_ptr, k_thread_entry_t entry,
20 void *p1, void *p2, void *p3)
21 {
22 struct arch_esf *stack_init;
23
24 /* Initial stack frame for thread */
25 stack_init = (struct arch_esf *)Z_STACK_PTR_ALIGN(
26 Z_STACK_PTR_TO_FRAME(struct arch_esf, stack_ptr)
27 );
28
29 /* Setup the initial stack frame */
30 stack_init->a0 = (unsigned long)entry;
31 stack_init->a1 = (unsigned long)p1;
32 stack_init->a2 = (unsigned long)p2;
33 stack_init->a3 = (unsigned long)p3;
34
35 stack_init->status = CP0_STATUS_DEF_RESTORE
36 | mips_cp0_status_int_mask;
37
38 stack_init->epc = (unsigned long)z_thread_entry;
39
40 thread->callee_saved.sp = (unsigned long)stack_init;
41 }
42