1 /*
2  * Copyright (c) 2013-2016 Wind River Systems, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Private kernel definitions (ARM)
10  *
11  * This file contains private kernel function definitions and various
12  * other definitions for the 32-bit ARM Cortex-A/R/M processor architecture
13  * family.
14  *
15  * This file is also included by assembly language files which must #define
16  * _ASMLANGUAGE before including this header file.  Note that kernel
17  * assembly source files obtains structure offset values via "absolute symbols"
18  * in the offsets.o module.
19  */
20 
21 #ifndef ZEPHYR_ARCH_ARM_INCLUDE_AARCH32_KERNEL_ARCH_FUNC_H_
22 #define ZEPHYR_ARCH_ARM_INCLUDE_AARCH32_KERNEL_ARCH_FUNC_H_
23 
24 #include <kernel_arch_data.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #ifndef _ASMLANGUAGE
31 extern void z_arm_fault_init(void);
32 extern void z_arm_cpu_idle_init(void);
33 #ifdef CONFIG_ARM_MPU
34 extern void z_arm_configure_static_mpu_regions(void);
35 extern void z_arm_configure_dynamic_mpu_regions(struct k_thread *thread);
36 extern int z_arm_mpu_init(void);
37 #endif /* CONFIG_ARM_MPU */
38 
arch_kernel_init(void)39 static ALWAYS_INLINE void arch_kernel_init(void)
40 {
41 	z_arm_interrupt_stack_setup();
42 	z_arm_exc_setup();
43 	z_arm_fault_init();
44 	z_arm_cpu_idle_init();
45 	z_arm_clear_faults();
46 #if defined(CONFIG_ARM_MPU)
47 	z_arm_mpu_init();
48 	/* Configure static memory map. This will program MPU regions,
49 	 * to set up access permissions for fixed memory sections, such
50 	 * as Application Memory or No-Cacheable SRAM area.
51 	 *
52 	 * This function is invoked once, upon system initialization.
53 	 */
54 	z_arm_configure_static_mpu_regions();
55 #endif
56 }
57 
58 static ALWAYS_INLINE void
arch_thread_return_value_set(struct k_thread * thread,unsigned int value)59 arch_thread_return_value_set(struct k_thread *thread, unsigned int value)
60 {
61 	thread->arch.swap_return_value = value;
62 }
63 
64 #if !defined(CONFIG_MULTITHREADING) && defined(CONFIG_CPU_CORTEX_M)
65 extern FUNC_NORETURN void z_arm_switch_to_main_no_multithreading(
66 	k_thread_entry_t main_func,
67 	void *p1, void *p2, void *p3);
68 
69 #define ARCH_SWITCH_TO_MAIN_NO_MULTITHREADING \
70 	z_arm_switch_to_main_no_multithreading
71 
72 #endif /* !CONFIG_MULTITHREADING && CONFIG_CPU_CORTEX_M */
73 
74 extern FUNC_NORETURN void z_arm_userspace_enter(k_thread_entry_t user_entry,
75 					       void *p1, void *p2, void *p3,
76 					       uint32_t stack_end,
77 					       uint32_t stack_start);
78 
79 extern void z_arm_fatal_error(unsigned int reason, const z_arch_esf_t *esf);
80 
81 #endif /* _ASMLANGUAGE */
82 
83 #ifdef __cplusplus
84 }
85 #endif
86 
87 #endif /* ZEPHYR_ARCH_ARM_INCLUDE_AARCH32_KERNEL_ARCH_FUNC_H_ */
88