• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 
13 #define __asm_syscall(...)                      \
14     do {                                        \
15         __asm__ __volatile__("svc 0"            \
16                              : "=r"(x0)         \
17                              : __VA_ARGS__      \
18                              : "memory", "cc"); \
19         return x0;                              \
20     } while (0)
21 
chcore_syscall0(long n)22 static inline long chcore_syscall0(long n)
23 {
24     register long x8 __asm__("x8") = n;
25     register long x0 __asm__("x0");
26     __asm_syscall("r"(x8));
27 }
28 
chcore_syscall1(long n,long a)29 static inline long chcore_syscall1(long n, long a)
30 {
31     register long x8 __asm__("x8") = n;
32     register long x0 __asm__("x0") = a;
33     __asm_syscall("r"(x8), "0"(x0));
34 }
35 
chcore_syscall2(long n,long a,long b)36 static inline long chcore_syscall2(long n, long a, long b)
37 {
38     register long x8 __asm__("x8") = n;
39     register long x0 __asm__("x0") = a;
40     register long x1 __asm__("x1") = b;
41     __asm_syscall("r"(x8), "0"(x0), "r"(x1));
42 }
43 
chcore_syscall3(long n,long a,long b,long c)44 static inline long chcore_syscall3(long n, long a, long b, long c)
45 {
46     register long x8 __asm__("x8") = n;
47     register long x0 __asm__("x0") = a;
48     register long x1 __asm__("x1") = b;
49     register long x2 __asm__("x2") = c;
50     __asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2));
51 }
52 
chcore_syscall4(long n,long a,long b,long c,long d)53 static inline long chcore_syscall4(long n, long a, long b, long c, long d)
54 {
55     register long x8 __asm__("x8") = n;
56     register long x0 __asm__("x0") = a;
57     register long x1 __asm__("x1") = b;
58     register long x2 __asm__("x2") = c;
59     register long x3 __asm__("x3") = d;
60     __asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3));
61 }
62 
chcore_syscall5(long n,long a,long b,long c,long d,long e)63 static inline long chcore_syscall5(long n, long a, long b, long c, long d,
64                                    long e)
65 {
66     register long x8 __asm__("x8") = n;
67     register long x0 __asm__("x0") = a;
68     register long x1 __asm__("x1") = b;
69     register long x2 __asm__("x2") = c;
70     register long x3 __asm__("x3") = d;
71     register long x4 __asm__("x4") = e;
72     __asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4));
73 }
74 
chcore_syscall6(long n,long a,long b,long c,long d,long e,long f)75 static inline long chcore_syscall6(long n, long a, long b, long c, long d,
76                                    long e, long f)
77 {
78     register long x8 __asm__("x8") = n;
79     register long x0 __asm__("x0") = a;
80     register long x1 __asm__("x1") = b;
81     register long x2 __asm__("x2") = c;
82     register long x3 __asm__("x3") = d;
83     register long x4 __asm__("x4") = e;
84     register long x5 __asm__("x5") = f;
85     __asm_syscall(
86         "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x5));
87 }