Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
error.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 BayLibre, SAS
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
13
14#ifndef ZEPHYR_INCLUDE_ARCH_RISCV_ERROR_H_
15#define ZEPHYR_INCLUDE_ARCH_RISCV_ERROR_H_
16
19#include <stdbool.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#ifdef CONFIG_RISCV_S_MODE
26/*
27 * In S-mode, ecall (cause=9) is kept in M-mode for SBI so it never reaches
28 * the S-mode exception handler. Kernel-context panics use ebreak (cause=3,
29 * breakpoint) which IS delegated to S-mode. isr.S treats ebreak with
30 * t0==RV_ECALL_RUNTIME_EXCEPT (0) as ARCH_EXCEPT and reads the reason from
31 * saved a0 — mirroring exactly how M-mode handles ecall with RV_ECALL_RUNTIME_EXCEPT.
32 */
33#define ARCH_EXCEPT(reason_p) do { \
34 if (k_is_user_context()) { \
35 arch_syscall_invoke1(reason_p, \
36 K_SYSCALL_USER_FAULT); \
37 } else { \
38 register unsigned long _r __asm__("a0") = \
39 (unsigned long)(reason_p); \
40 register unsigned long _t __asm__("t0") = 0; \
41 __asm__ volatile("ebreak" \
42 : : "r"(_r), "r"(_t) \
43 : "memory"); \
44 } \
45 CODE_UNREACHABLE; /* LCOV_EXCL_LINE */ \
46 } while (false)
47
48#elif defined(CONFIG_USERSPACE)
49
50#define ARCH_EXCEPT(reason_p) do { \
51 if (k_is_user_context()) { \
52 arch_syscall_invoke1(reason_p, \
53 K_SYSCALL_USER_FAULT); \
54 } else { \
55 compiler_barrier(); \
56 arch_syscall_invoke1(reason_p, \
57 RV_ECALL_RUNTIME_EXCEPT);\
58 } \
59 CODE_UNREACHABLE; /* LCOV_EXCL_LINE */ \
60 } while (false)
61#else
62#define ARCH_EXCEPT(reason_p) \
63 arch_syscall_invoke1(reason_p, RV_ECALL_RUNTIME_EXCEPT)
64#endif
65
66__syscall void user_fault(unsigned int reason);
67
68#include <zephyr/syscalls/error.h>
69
70#ifdef __cplusplus
71}
72#endif
73
74#endif /* ZEPHYR_INCLUDE_ARCH_RISCV_ERROR_H_ */
RISCV specific syscall header.
void user_fault(unsigned int reason)