summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/nds32/bits/syscalls.h
blob: 50e30db7d86ad3ae6f0b46ad8968d59c9b25ad10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
 * Copyright (C) 2016 Andes Technology, Inc.
 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
 */

/*
 * For nds32 ISA, the syscall number(SWID) shall be determined at compile time.
 * (ex: asm("syscall SWID"); )
 * If the value of syscall number is determined at run time, we shall issue
 * this syscall through sys_syscall.
 * (ex:
 *     asm("move $r0, SYSCALL_number"
 *         "syscall 0x5071");
 *     where 0x5071 is syscall number for sys_syscall
 * )
 *
 * The following two macros are implemented according that syscall number
 * is determined in compiler time or run time,
 *
 * 1. INTERNAL_SYSCALL_NCS: the syscall number is determined at run time
 * 2. INTERNAL_SYSCALL: the syscall number is determined at compile time
 *
 */


#ifndef _BITS_SYSCALLS_H
#define _BITS_SYSCALLS_H
#ifndef _SYSCALL_H
# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
#endif

#ifndef __ASSEMBLER__
#include <errno.h>
#include <common/sysdep.h>

#define X(x) #x
#define Y(x) X(x)
#define        LIB_SYSCALL    __NR_syscall

#define __issue_syscall(syscall_name) "syscall  0x0;\n"

#undef INTERNAL_SYSCALL_ERROR_P
#define INTERNAL_SYSCALL_ERROR_P(val, err) ((unsigned int) (val) >= 0xfffff001u)

#undef INTERNAL_SYSCALL_ERRNO
#define INTERNAL_SYSCALL_ERRNO(val, err)	(-(val))

#undef INLINE_SYSCALL
#define INLINE_SYSCALL(name, nr, args...)                        	\
  ({                                                             	\
     INTERNAL_SYSCALL_DECL (err);                                	\
     long result_var = INTERNAL_SYSCALL (name, err, nr, args);   	\
     if (INTERNAL_SYSCALL_ERROR_P (result_var, err))             	\
       {                                                         	\
         __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err)); 	\
			result_var = -1 ;			 	\
       }                                                         	\
     result_var;                                                 	\
  })


#undef INTERNAL_SYSCALL_DECL
#define INTERNAL_SYSCALL_DECL(err) do { } while (0)


#undef INTERNAL_SYSCALL
#define INTERNAL_SYSCALL(name, err, nr, args...) internal_syscall##nr(__NR_##name, err, args)

/*
   The _NCS variant allows non-constant syscall numbers
 */
#undef INTERNAL_SYSCALL_NCS
#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) internal_syscall_ncs##nr(name, err, args)


#define internal_syscall0(name, err, dummy...)                   	\
  ({                                                             	\
       register long ___res  __asm__("$r0");               		\
       __asm__ volatile (                                        	\
       __issue_syscall (name)                                    	\
       : "=r" (___res)         /* output operands  */             	\
       :							 	\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */ 	\
       ___res;							 	\
  })

#define internal_syscall1(name, err, arg1)                       	\
  ({                                                             	\
       register long ___res  __asm__("$r0");                         	\
       register long __arg1 __asm__("$r0") = (long) (arg1);         	\
       __asm__ volatile (                                        	\
       __issue_syscall (name)                                    	\
       : "=r" (___res)         /* output operands  */             	\
       : "r" (__arg1)         /* input operands  */              	\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */ 	\
        ___res;                                                   	\
  })

#define internal_syscall2(name, err, arg1, arg2)                 	\
  ({                                                             	\
       register long ___res  __asm__("$r0");                         	\
       register long __arg1 __asm__("$r0") = (long) (arg1);         	\
       register long __arg2 __asm__("$r1") = (long) (arg2);         	\
       __asm__ volatile (                                        	\
       __issue_syscall (name)                                    	\
       : "=r" (___res)         /* output operands  */             	\
       : "r" (__arg1)         /* input operands  */              	\
       , "r" (__arg2)         /* input operands  */              	\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */ 	\
        ___res;                                                   	\
  })

#define internal_syscall3(name, err, arg1, arg2, arg3)           	\
  ({                                                             	\
       register long ___res  __asm__("$r0");                         	\
       register long __arg1 __asm__("$r0") = (long) (arg1);         	\
       register long __arg2 __asm__("$r1") = (long) (arg2);         	\
       register long __arg3 __asm__("$r2") = (long) (arg3);         	\
       __asm__ volatile (                                        	\
       __issue_syscall (name)                                    	\
       : "=r" (___res)         /* output operands  */             	\
       : "r" (__arg1)         /* input operands  */              	\
       , "r" (__arg2)         /* input operands  */              	\
       , "r" (__arg3)         /* input operands  */              	\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */ 	\
        ___res;                                                   	\
  })

#define internal_syscall4(name, err, arg1, arg2, arg3, arg4)     	\
  ({                                                             	\
       register long ___res  __asm__("$r0");                         	\
       register long __arg1 __asm__("$r0") = (long) (arg1);         	\
       register long __arg2 __asm__("$r1") = (long) (arg2);         	\
       register long __arg3 __asm__("$r2") = (long) (arg3);         	\
       register long __arg4 __asm__("$r3") = (long) (arg4);         	\
       __asm__ volatile (                                        	\
       __issue_syscall (name)                                    	\
       : "=r" (___res)         /* output operands  */             	\
       : "r" (__arg1)         /* input operands  */              	\
       , "r" (__arg2)         /* input operands  */              	\
       , "r" (__arg3)         /* input operands  */              	\
       , "r" (__arg4)         /* input operands  */              	\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */ 	\
        ___res;                                                   	\
  })

#define internal_syscall5(name, err, arg1, arg2, arg3, arg4, arg5) 	\
  ({                                                             	\
       register long ___res  __asm__("$r0");                         	\
       register long __arg1 __asm__("$r0") = (long) (arg1);         	\
       register long __arg2 __asm__("$r1") = (long) (arg2);         	\
       register long __arg3 __asm__("$r2") = (long) (arg3);         	\
       register long __arg4 __asm__("$r3") = (long) (arg4);         	\
       register long __arg5 __asm__("$r4") = (long) (arg5);         	\
       __asm__ volatile (                                        	\
       __issue_syscall (name)                                    	\
       : "=r" (___res)         /* output operands  */             	\
       : "r" (__arg1)         /* input operands  */              	\
       , "r" (__arg2)         /* input operands  */              	\
       , "r" (__arg3)         /* input operands  */              	\
       , "r" (__arg4)         /* input operands  */              	\
       , "r" (__arg5)         /* input operands  */              	\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */ 	\
        ___res;                                                   	\
  })

#define internal_syscall6(name, err, arg1, arg2, arg3, arg4, arg5, arg6) 	\
  ({                                                             		\
       register long ___res  __asm__("$r0");                         		\
       register long __arg1 __asm__("$r0") = (long) (arg1);         		\
       register long __arg2 __asm__("$r1") = (long) (arg2);         		\
       register long __arg3 __asm__("$r2") = (long) (arg3);         		\
       register long __arg4 __asm__("$r3") = (long) (arg4);         		\
       register long __arg5 __asm__("$r4") = (long) (arg5);         		\
       register long __arg6 __asm__("$r5") = (long) (arg6);         		\
       __asm__ volatile (                                        		\
       __issue_syscall (name)                                    		\
       : "=r" (___res)         /* output operands  */             		\
       : "r" (__arg1)         /* input operands  */              		\
       , "r" (__arg2)         /* input operands  */              		\
       , "r" (__arg3)         /* input operands  */              		\
       , "r" (__arg4)         /* input operands  */              		\
       , "r" (__arg5)         /* input operands  */              		\
       , "r" (__arg6)         /* input operands  */              		\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */ 		\
        ___res;                                                   		\
  })
#define internal_syscall7(name, err, arg1, arg2, arg3, arg4, arg5, arg6, arg7) 	\
  ({                                                             		\
       register long ___res  __asm__("$r0");                         		\
       register long __arg1 __asm__("$r0") = (long) (arg1);         		\
       register long __arg2 __asm__("$r1") = (long) (arg2);         		\
       register long __arg3 __asm__("$r2") = (long) (arg3);         		\
       register long __arg4 __asm__("$r3") = (long) (arg4);         		\
       register long __arg5 __asm__("$r4") = (long) (arg5);         		\
       register long __arg6 __asm__("$r5") = (long) (arg6);         		\
       __asm__ volatile (                                        		\
	"addi10.sp\t  #-4\n\t"							\
	CFI_ADJUST_CFA_OFFSET(4)"\n\t"						\
        "push\t %7\n\t"								\
	CFI_ADJUST_CFA_OFFSET(4)"\n\t"						\
       __issue_syscall (name)                                    		\
	"addi10.sp\t  #4\n\t"							\
	CFI_ADJUST_CFA_OFFSET(-4)"\n\t"						\
        "pop\t %7\n\t"								\
	CFI_ADJUST_CFA_OFFSET(-4)"\n\t"						\
       : "=r" (___res)         /* output operands  */             		\
       : "r" (__arg1)         /* input operands  */              		\
       , "r" (__arg2)         /* input operands  */              		\
       , "r" (__arg3)         /* input operands  */              		\
       , "r" (__arg4)         /* input operands  */              		\
       , "r" (__arg5)         /* input operands  */              		\
       , "r" (__arg6)         /* input operands  */              		\
       , "r" (arg7)         /* input operands  */              		\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */ 		\
        ___res;                                                   		\
  })

#define internal_syscall_ncs0(name, err, dummy...)               	\
  ({                                                             	\
       register long __res  __asm__("$r0");                         	\
       register long __no   __asm__("$r0") = (long) (name);         	\
       __asm__ volatile (                                        	\
       __issue_syscall (LIB_SYSCALL)                             	\
       : "=r" (__res)         /* output operands  */             	\
       : "r" (__no)           /* input operands  */              	\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */ 	\
       __res;							 	\
  })

#define internal_syscall_ncs1(name, err, arg1)                   	\
  ({                                                             	\
       register long __res  __asm__("$r0");                         	\
       register long __no   __asm__("$r0") = (long) (name);         	\
       register long __arg1 __asm__("$r1") = (long) (arg1);         	\
       __asm__ volatile (                                        	\
       __issue_syscall (LIB_SYSCALL)                             	\
       : "=r" (__res)         /* output operands  */             	\
       : "r" (__arg1)         /* input operands  */              	\
       , "r" (__no)           /* input operands  */              	\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */ 	\
        __res;                                                   	\
  })

#define internal_syscall_ncs2(name, err, arg1, arg2)             	\
  ({                                                             	\
       register long __res  __asm__("$r0");                         	\
       register long __no   __asm__("$r0") = (long) (name);         	\
       register long __arg1 __asm__("$r1") = (long) (arg1);         	\
       register long __arg2 __asm__("$r2") = (long) (arg2);         	\
       __asm__ volatile (                                        	\
       __issue_syscall (LIB_SYSCALL)                             	\
       : "=r" (__res)         /* output operands  */             	\
       : "r" (__arg1)         /* input operands  */              	\
       , "r" (__arg2)         /* input operands  */              	\
       , "r" (__no)           /* input operands  */              	\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */ 	\
        __res;                                                   	\
  })

#define internal_syscall_ncs3(name, err, arg1, arg2, arg3)      	\
  ({                                                            	\
       register long __res  __asm__("$r0");                     	\
       register long __no   __asm__("$r0") = (long) (name);     	\
       register long __arg1 __asm__("$r1") = (long) (arg1);     	\
       register long __arg2 __asm__("$r2") = (long) (arg2);     	\
       register long __arg3 __asm__("$r3") = (long) (arg3);     	\
       __asm__ volatile (                                       	\
       __issue_syscall (LIB_SYSCALL)                            	\
       : "=r" (__res)         /* output operands  */            	\
       : "r" (__arg1)         /* input operands  */             	\
       , "r" (__arg2)         /* input operands  */             	\
       , "r" (__arg3)         /* input operands  */             	\
       , "r" (__no)           /* input operands  */             	\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */	\
        __res;                                                  	\
  })

#define internal_syscall_ncs4(name, err, arg1, arg2, arg3, arg4) 	\
  ({                                                             	\
       register long __res  __asm__("$r0");                      	\
       register long __no   __asm__("$r0") = (long) (name);      	\
       register long __arg1 __asm__("$r1") = (long) (arg1);      	\
       register long __arg2 __asm__("$r2") = (long) (arg2);      	\
       register long __arg3 __asm__("$r3") = (long) (arg3);      	\
       register long __arg4 __asm__("$r4") = (long) (arg4);      	\
       __asm__ volatile (                                        	\
       __issue_syscall (LIB_SYSCALL)                             	\
       : "=r" (__res)         /* output operands  */             	\
       : "r" (__arg1)         /* input operands  */              	\
       , "r" (__arg2)         /* input operands  */              	\
       , "r" (__arg3)         /* input operands  */              	\
       , "r" (__arg4)         /* input operands  */              	\
       , "r" (__no)           /* input operands  */              	\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */ 	\
        __res;                                                   	\
  })

#define internal_syscall_ncs5(name, err, arg1, arg2, arg3, arg4, arg5) 	\
  ({                                                             	\
       register long ___res __asm__("$r0");                         	\
       register long __no   __asm__("$r0") = (long) (name);         	\
       register long __arg1 __asm__("$r1") = (long) (arg1);         	\
       register long __arg2 __asm__("$r2") = (long) (arg2);         	\
       register long __arg3 __asm__("$r3") = (long) (arg3);         	\
       register long __arg4 __asm__("$r4") = (long) (arg4);         	\
       register long __arg5 __asm__("$r5") = (long) (arg5);         	\
       __asm__ volatile (                                        	\
       __issue_syscall (LIB_SYSCALL)                                   	\
       : "=r" (___res)         /* output operands  */             	\
       : "r" (__arg1)         /* input operands  */              	\
       , "r" (__arg2)         /* input operands  */              	\
       , "r" (__arg3)         /* input operands  */              	\
       , "r" (__arg4)         /* input operands  */              	\
       , "r" (__arg5)         /* input operands  */              	\
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */ 	\
        ___res;                                                   	\
  })

#define internal_syscall_ncs6(name, err, arg1, arg2, arg3, arg4, arg5, arg6)	\
  ({                                                                            \
       register long __res  __asm__("$r0");                                     \
       register long __no   __asm__("$r0") = (long) (name);                     \
       register long __arg1 __asm__("$r1") = (long) (arg1);                     \
       register long __arg2 __asm__("$r2") = (long) (arg2);                     \
       register long __arg3 __asm__("$r3") = (long) (arg3);                     \
       register long __arg4 __asm__("$r4") = (long) (arg4);                     \
       register long __arg5 __asm__("$r5") = (long) (arg5);                     \
       __asm__ volatile (                                                       \
        "addi10.sp\t  #-4\n\t"                                                  \
        CFI_ADJUST_CFA_OFFSET(4)"\n\t"                                          \
        "push\t %7\n\t"                                                         \
        CFI_ADJUST_CFA_OFFSET(4)"\n\t"                                          \
       __issue_syscall (LIB_SYSCALL)                                            \
        "pop\t %7\n\t"                                                          \
        CFI_ADJUST_CFA_OFFSET(-4)"\n\t"                                         \
        "addi10.sp\t  #4\n\t"                                                   \
        CFI_ADJUST_CFA_OFFSET(-4)"\n\t"                                         \
       : "=r" (__res)         /* output operands  */                            \
       : "r" (__no)           /* input operands  */                             \
       , "r" (__arg1)         /* input operands  */                             \
       , "r" (__arg2)         /* input operands  */                             \
       , "r" (__arg3)         /* input operands  */                             \
       , "r" (__arg4)         /* input operands  */                             \
       , "r" (__arg5)         /* input operands  */                             \
       , "r" (arg6)         /* input operands  */                               \
       : __SYSCALL_CLOBBERS); /* list of clobbered registers  */                \
        __res;                                                                  \
  })

#define __SYSCALL_CLOBBERS "$lp", "memory"
#endif /* ! __ASSEMBLER__  */
#endif /* _BITS_SYSCALLS_H */