1 /*
2  * Copyright (c) 2021 KT-Elektronik, Klaucke und Partner GmbH
3  * Copyright (c) 2024 Renesas Electronics Corporation
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <kernel_internal.h>
9 #include <zephyr/logging/log.h>
10 LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
11 
12 /* variables to store the arguments of z_rx_context_switch_isr() (zephyr\arch\rx\core\switch.S)
13  * when performing a cooperative thread switch. In that case, z_rx_context_switch_isr() triggerss
14  * unmaskable interrupt 1 to actually perform the switch. The ISR to interrupt 1
15  * (switch_isr_wrapper()) reads the arguments from these variables.
16  */
17 void *coop_switch_to;
18 void **coop_switched_from;
19 
arch_new_thread(struct k_thread * thread,k_thread_stack_t * stack,char * stack_ptr,k_thread_entry_t entry,void * arg1,void * arg2,void * arg3)20 void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack, char *stack_ptr,
21 			 k_thread_entry_t entry, void *arg1, void *arg2, void *arg3)
22 {
23 	struct arch_esf *iframe;
24 
25 	iframe = Z_STACK_PTR_TO_FRAME(struct arch_esf, stack_ptr);
26 
27 	/* initial value for the PSW (bits U and I are set) */
28 	iframe->psw = 0x30000;
29 	/* the initial entry point is the function z_thread_entry */
30 	iframe->entry_point = (uint32_t)z_thread_entry;
31 	/* arguments for the call of z_thread_entry (to be written to r1-r4) */
32 	iframe->r1 = (uint32_t)entry;
33 	iframe->r2 = (uint32_t)arg1;
34 	iframe->r3 = (uint32_t)arg2;
35 	iframe->r4 = (uint32_t)arg3;
36 	/* for debugging: */
37 	iframe->r5 = 5;
38 	iframe->r6 = 6;
39 	iframe->r7 = 7;
40 	iframe->r8 = 8;
41 	iframe->r9 = 9;
42 	iframe->r10 = 10;
43 	iframe->r11 = 11;
44 	iframe->r12 = 12;
45 	iframe->r13 = 13;
46 	iframe->r14 = 14;
47 	iframe->r15 = 15;
48 	iframe->acc_l = 16;
49 	iframe->acc_h = 17;
50 
51 	thread->switch_handle = (void *)iframe;
52 }
53 
arch_coprocessors_disable(struct k_thread * thread)54 int arch_coprocessors_disable(struct k_thread *thread)
55 {
56 	return -ENOTSUP;
57 }
58