1 /*
2  * Copyright (c) 2018 Lexmark International, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Exception/interrupt context helpers for Cortex-A and Cortex-R CPUs
10  *
11  * Exception/interrupt context helpers.
12  */
13 
14 #ifndef ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_A_R_EXCEPTION_H_
15 #define ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_A_R_EXCEPTION_H_
16 
17 #include <zephyr/arch/cpu.h>
18 
19 #ifdef _ASMLANGUAGE
20 
21 /* nothing */
22 
23 #else
24 
25 #include <zephyr/irq_offload.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 #ifdef CONFIG_IRQ_OFFLOAD
32 extern volatile irq_offload_routine_t offload_routine;
33 #endif
34 
35 /* Check the CPSR mode bits to see if we are in IRQ or FIQ mode */
arch_is_in_isr(void)36 static ALWAYS_INLINE bool arch_is_in_isr(void)
37 {
38 	return (arch_curr_cpu()->nested != 0U);
39 }
40 
arch_is_in_nested_exception(const struct arch_esf * esf)41 static ALWAYS_INLINE bool arch_is_in_nested_exception(const struct arch_esf *esf)
42 {
43 	return (arch_curr_cpu()->arch.exc_depth > 1U) ? (true) : (false);
44 }
45 
46 #if defined(CONFIG_USERSPACE)
47 /*
48  * This function is used by privileged code to determine if the thread
49  * associated with the stack frame is in user mode.
50  */
z_arm_preempted_thread_in_user_mode(const struct arch_esf * esf)51 static ALWAYS_INLINE bool z_arm_preempted_thread_in_user_mode(const struct arch_esf *esf)
52 {
53 	return ((esf->basic.xpsr & CPSR_M_Msk) == CPSR_M_USR);
54 }
55 #endif
56 
57 #ifndef CONFIG_USE_SWITCH
58 extern void z_arm_cortex_r_svc(void);
59 #endif
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 
65 #endif /* _ASMLANGUAGE */
66 
67 #endif /* ZEPHYR_ARCH_ARM_INCLUDE_CORTEX_A_R_EXCEPTION_H_ */
68