1 /*
2  * Copyright (c) 2014-2016 Wind River Systems, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Private kernel definitions
10  *
11  * This file contains private kernel structures definitions and various
12  * other definitions for the ARCv2 processor architecture.
13  *
14  * This file is also included by assembly language files which must #define
15  * _ASMLANGUAGE before including this header file.  Note that kernel
16  * assembly source files obtains structure offset values via "absolute
17  * symbols" in the offsets.o module.
18  */
19 
20 #ifndef ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_FUNC_H_
21 #define ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_FUNC_H_
22 
23 #if !defined(_ASMLANGUAGE)
24 
25 #include <kernel_arch_data.h>
26 
27 #include <v2/irq.h>
28 
29 #include <zephyr/platform/hooks.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
arch_kernel_init(void)35 static ALWAYS_INLINE void arch_kernel_init(void)
36 {
37 	z_irq_setup();
38 
39 #ifdef CONFIG_SOC_PER_CORE_INIT_HOOK
40 	soc_per_core_init_hook();
41 #endif /* CONFIG_SOC_PER_CORE_INIT_HOOK */
42 }
43 
44 
45 /**
46  *
47  * @brief Indicates the interrupt number of the highest priority
48  * active interrupt
49  *
50  * @return IRQ number
51  */
Z_INTERRUPT_CAUSE(void)52 static ALWAYS_INLINE int Z_INTERRUPT_CAUSE(void)
53 {
54 	uint32_t irq_num = z_arc_v2_aux_reg_read(_ARC_V2_ICAUSE);
55 
56 	return irq_num;
57 }
58 
arch_is_in_isr(void)59 static inline bool arch_is_in_isr(void)
60 {
61 	return z_arc_v2_irq_unit_is_in_isr();
62 }
63 
64 extern void z_thread_entry_wrapper(void);
65 extern void z_user_thread_entry_wrapper(void);
66 
67 extern void z_arc_userspace_enter(k_thread_entry_t user_entry, void *p1,
68 		 void *p2, void *p3, uint32_t stack, uint32_t size,
69 		 struct k_thread *thread);
70 
71 extern void z_arc_fatal_error(unsigned int reason, const struct arch_esf *esf);
72 
73 extern void z_arc_switch(void *switch_to, void **switched_from);
74 
arch_switch(void * switch_to,void ** switched_from)75 static inline void arch_switch(void *switch_to, void **switched_from)
76 {
77 	z_arc_switch(switch_to, switched_from);
78 }
79 
80 #if !defined(CONFIG_MULTITHREADING)
81 extern FUNC_NORETURN void z_arc_switch_to_main_no_multithreading(
82 	k_thread_entry_t main_func, void *p1, void *p2, void *p3);
83 
84 #define ARCH_SWITCH_TO_MAIN_NO_MULTITHREADING \
85 	z_arc_switch_to_main_no_multithreading
86 
87 #endif /* !CONFIG_MULTITHREADING */
88 
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif /* _ASMLANGUAGE */
95 
96 #endif /* ZEPHYR_ARCH_ARC_INCLUDE_KERNEL_ARCH_FUNC_H_ */
97