t/nvmept_pi: add support for xNVMe ioengine
[fio.git] / arch / arch-riscv64.h
1 #ifndef ARCH_RISCV64_H
2 #define ARCH_RISCV64_H
3
4 #include <unistd.h>
5 #include <stdlib.h>
6 #include <sys/types.h>
7 #include <sys/wait.h>
8
9 #define FIO_ARCH        (arch_riscv64)
10
11 #define nop             __asm__ __volatile__ ("nop")
12 #define read_barrier()          __asm__ __volatile__("fence r, r": : :"memory")
13 #define write_barrier()         __asm__ __volatile__("fence w, w": : :"memory")
14
15 static inline unsigned long long get_cpu_clock(void)
16 {
17         unsigned long val;
18
19         asm volatile("rdtime %0" : "=r"(val));
20         return val;
21 }
22 #define ARCH_HAVE_CPU_CLOCK
23
24 #define ARCH_HAVE_INIT
25 extern bool tsc_reliable;
26 static inline int arch_init(char *envp[])
27 {
28         tsc_reliable = true;
29         return 0;
30 }
31
32 #define __do_syscallM(...) ({                                           \
33         __asm__ volatile (                                              \
34                 "ecall"                                                 \
35                 : "=r"(a0)                                              \
36                 : __VA_ARGS__                                           \
37                 : "memory", "a1");                                      \
38         (long) a0;                                                      \
39 })
40
41 #define __do_syscallN(...) ({                                           \
42         __asm__ volatile (                                              \
43                 "ecall"                                                 \
44                 : "=r"(a0)                                              \
45                 : __VA_ARGS__                                           \
46                 : "memory");                                    \
47         (long) a0;                                                      \
48 })
49
50 #define __do_syscall0(__n) ({                                           \
51         register long a7 __asm__("a7") = __n;                           \
52         register long a0 __asm__("a0");                                 \
53                                                                         \
54         __do_syscallM("r" (a7));                                        \
55 })
56
57 #define __do_syscall1(__n, __a) ({                                      \
58         register long a7 __asm__("a7") = __n;                           \
59         register __typeof__(__a) a0 __asm__("a0") = __a;                \
60                                                                         \
61         __do_syscallM("r" (a7), "0" (a0));                              \
62 })
63
64 #define __do_syscall2(__n, __a, __b) ({                                 \
65         register long a7 __asm__("a7") = __n;                           \
66         register __typeof__(__a) a0 __asm__("a0") = __a;                \
67         register __typeof__(__b) a1 __asm__("a1") = __b;                \
68                                                                         \
69         __do_syscallN("r" (a7), "0" (a0), "r" (a1));                    \
70 })
71
72 #define __do_syscall3(__n, __a, __b, __c) ({                            \
73         register long a7 __asm__("a7") = __n;                           \
74         register __typeof__(__a) a0 __asm__("a0") = __a;                \
75         register __typeof__(__b) a1 __asm__("a1") = __b;                \
76         register __typeof__(__c) a2 __asm__("a2") = __c;                \
77                                                                         \
78         __do_syscallN("r" (a7), "0" (a0), "r" (a1), "r" (a2));          \
79 })
80
81 #define __do_syscall4(__n, __a, __b, __c, __d) ({                       \
82         register long a7 __asm__("a7") = __n;                           \
83         register __typeof__(__a) a0 __asm__("a0") = __a;                \
84         register __typeof__(__b) a1 __asm__("a1") = __b;                \
85         register __typeof__(__c) a2 __asm__("a2") = __c;                \
86         register __typeof__(__d) a3 __asm__("a3") = __d;                \
87                                                                         \
88         __do_syscallN("r" (a7), "0" (a0), "r" (a1), "r" (a2), "r" (a3));\
89 })
90
91 #define __do_syscall5(__n, __a, __b, __c, __d, __e) ({                  \
92         register long a7 __asm__("a7") = __n;                           \
93         register __typeof__(__a) a0 __asm__("a0") = __a;                \
94         register __typeof__(__b) a1 __asm__("a1") = __b;                \
95         register __typeof__(__c) a2 __asm__("a2") = __c;                \
96         register __typeof__(__d) a3 __asm__("a3") = __d;                \
97         register __typeof__(__e) a4 __asm__("a4") = __e;                \
98                                                                         \
99         __do_syscallN("r" (a7), "0" (a0), "r" (a1), "r" (a2), "r" (a3), \
100                         "r"(a4));                                       \
101 })
102
103 #define __do_syscall6(__n, __a, __b, __c, __d, __e, __f) ({             \
104         register long a7 __asm__("a7") = __n;                           \
105         register __typeof__(__a) a0 __asm__("a0") = __a;                \
106         register __typeof__(__b) a1 __asm__("a1") = __b;                \
107         register __typeof__(__c) a2 __asm__("a2") = __c;                \
108         register __typeof__(__d) a3 __asm__("a3") = __d;                \
109         register __typeof__(__e) a4 __asm__("a4") = __e;                \
110         register __typeof__(__f) a5 __asm__("a5") = __f;                \
111                                                                         \
112         __do_syscallN("r" (a7), "0" (a0), "r" (a1), "r" (a2), "r" (a3), \
113                         "r" (a4), "r"(a5));                             \
114 })
115
116 #define FIO_ARCH_HAS_SYSCALL
117
118 #endif