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