1 /*
2  * Copyright (c) 2020 BayLibre, SAS
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief RISCV public error handling
10  *
11  * RISCV-specific kernel error handling interface. Included by riscv/arch.h.
12  */
13 
14 #ifndef ZEPHYR_INCLUDE_ARCH_RISCV_ERROR_H_
15 #define ZEPHYR_INCLUDE_ARCH_RISCV_ERROR_H_
16 
17 #include <zephyr/arch/riscv/syscall.h>
18 #include <zephyr/arch/riscv/exp.h>
19 #include <stdbool.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #ifdef CONFIG_USERSPACE
26 
27 #define ARCH_EXCEPT(reason_p)	do {			\
28 		if (k_is_user_context()) {		\
29 			arch_syscall_invoke1(reason_p,	\
30 				K_SYSCALL_USER_FAULT);	\
31 		} else {				\
32 			compiler_barrier();		\
33 			arch_syscall_invoke1(reason_p,	\
34 				RV_ECALL_RUNTIME_EXCEPT);\
35 		}					\
36 		CODE_UNREACHABLE; /* LCOV_EXCL_LINE */	\
37 	} while (false)
38 #else
39 #define ARCH_EXCEPT(reason_p) \
40 	arch_syscall_invoke1(reason_p, RV_ECALL_RUNTIME_EXCEPT)
41 #endif
42 
43 __syscall void user_fault(unsigned int reason);
44 
45 #include <syscalls/error.h>
46 
47 #ifdef __cplusplus
48 }
49 #endif
50 
51 #endif /* ZEPHYR_INCLUDE_ARCH_RISCV_ERROR_H_ */
52