1 /* SPDX-License-Identifier: MIT */ 2 3 #ifndef LIBURING_ARCH_RISCV64_SYSCALL_H 4 #define LIBURING_ARCH_RISCV64_SYSCALL_H 5 6 #if defined(__riscv) && __riscv_xlen == 64 7 8 #define __do_syscallM(...) ({ \ 9 __asm__ volatile ( \ 10 "ecall" \ 11 : "=r"(a0) \ 12 : __VA_ARGS__ \ 13 : "memory", "a1"); \ 14 (long) a0; \ 15 }) 16 17 #define __do_syscallN(...) ({ \ 18 __asm__ volatile ( \ 19 "ecall" \ 20 : "=r"(a0) \ 21 : __VA_ARGS__ \ 22 : "memory"); \ 23 (long) a0; \ 24 }) 25 26 #define __do_syscall0(__n) ({ \ 27 register long a7 __asm__("a7") = __n; \ 28 register long a0 __asm__("a0"); \ 29 \ 30 __do_syscallM("r" (a7)); \ 31 }) 32 33 #define __do_syscall1(__n, __a) ({ \ 34 register long a7 __asm__("a7") = __n; \ 35 register __typeof__(__a) a0 __asm__("a0") = __a; \ 36 \ 37 __do_syscallM("r" (a7), "0" (a0)); \ 38 }) 39 40 #define __do_syscall2(__n, __a, __b) ({ \ 41 register long a7 __asm__("a7") = __n; \ 42 register __typeof__(__a) a0 __asm__("a0") = __a; \ 43 register __typeof__(__b) a1 __asm__("a1") = __b; \ 44 \ 45 __do_syscallN("r" (a7), "0" (a0), "r" (a1)); \ 46 }) 47 48 #define __do_syscall3(__n, __a, __b, __c) ({ \ 49 register long a7 __asm__("a7") = __n; \ 50 register __typeof__(__a) a0 __asm__("a0") = __a; \ 51 register __typeof__(__b) a1 __asm__("a1") = __b; \ 52 register __typeof__(__c) a2 __asm__("a2") = __c; \ 53 \ 54 __do_syscallN("r" (a7), "0" (a0), "r" (a1), "r" (a2)); \ 55 }) 56 57 #define __do_syscall4(__n, __a, __b, __c, __d) ({ \ 58 register long a7 __asm__("a7") = __n; \ 59 register __typeof__(__a) a0 __asm__("a0") = __a; \ 60 register __typeof__(__b) a1 __asm__("a1") = __b; \ 61 register __typeof__(__c) a2 __asm__("a2") = __c; \ 62 register __typeof__(__d) a3 __asm__("a3") = __d; \ 63 \ 64 __do_syscallN("r" (a7), "0" (a0), "r" (a1), "r" (a2), "r" (a3));\ 65 }) 66 67 #define __do_syscall5(__n, __a, __b, __c, __d, __e) ({ \ 68 register long a7 __asm__("a7") = __n; \ 69 register __typeof__(__a) a0 __asm__("a0") = __a; \ 70 register __typeof__(__b) a1 __asm__("a1") = __b; \ 71 register __typeof__(__c) a2 __asm__("a2") = __c; \ 72 register __typeof__(__d) a3 __asm__("a3") = __d; \ 73 register __typeof__(__e) a4 __asm__("a4") = __e; \ 74 \ 75 __do_syscallN("r" (a7), "0" (a0), "r" (a1), "r" (a2), "r" (a3), \ 76 "r"(a4)); \ 77 }) 78 79 #define __do_syscall6(__n, __a, __b, __c, __d, __e, __f) ({ \ 80 register long a7 __asm__("a7") = __n; \ 81 register __typeof__(__a) a0 __asm__("a0") = __a; \ 82 register __typeof__(__b) a1 __asm__("a1") = __b; \ 83 register __typeof__(__c) a2 __asm__("a2") = __c; \ 84 register __typeof__(__d) a3 __asm__("a3") = __d; \ 85 register __typeof__(__e) a4 __asm__("a4") = __e; \ 86 register __typeof__(__f) a5 __asm__("a5") = __f; \ 87 \ 88 __do_syscallN("r" (a7), "0" (a0), "r" (a1), "r" (a2), "r" (a3), \ 89 "r" (a4), "r"(a5)); \ 90 }) 91 92 #include "../syscall-defs.h" 93 94 #else /* #if defined(__riscv) && __riscv_xlen == 64 */ 95 96 #include "../generic/syscall.h" 97 98 #endif /* #if defined(__riscv) && __riscv_xlen == 64 */ 99 100 #endif /* #ifndef LIBURING_ARCH_RISCV64_SYSCALL_H */ 101