gentoo: use /var/run for new /run compatibility
[util-vserver.git] / lib / syscall-alternative.h
1  // from http://vserver.13thfloor.at/Experimental/SYSCALL/syscall_shiny17.h
2
3 #ifndef __SYSCALL_NEW_H
4 #define __SYSCALL_NEW_H
5
6 /*      Copyright (C) 2005-2007 Herbert Pƶtzl
7
8                 global config options
9
10         __sysc_seterr   ... set error value (def: errno)
11         __sysc_cid(N)   ... syscall 'name' id (def: __NR_<N>)
12
13                 arch specific config
14
15         __sysc_regs     ... the syscall registers (asm load)
16         __sysc_cmd(n)   ... the syscall
17         __sysc_reg_cid  ... syscall id register (asm load)
18         __sysc_reg_ret  ... syscall return register (asm out)
19         __sysc_reg_err  ... syscall error register (asm out)
20
21         __sysc_clbrs    ... the clobbered syscall registers
22         __sysc_clobber  ... clobbered registers (def: memory)
23         __sysc_max_err  ... maximum error number (def: separate)
24         __sysc_errc(r,e)... error condition (def: e)
25
26         __sysc_type     ... type of syscall arguments (def: long)
27         __sysc_acon(n)  ... argument constraint (def: "r")
28         __sysc_con_cid  ... syscall id constraint (def: "i"/"r")
29         __sysc_con_ret  ... return value contraint (def: "=r")
30         __sysc_con_err  ... error value contraint (def: "=r")
31
32                 hard core replacements
33
34         __sc_body(n,type,name,...)
35           __sc_results
36           __sc_cidvar(N)
37           __sc_input(n,...)
38           __sc_syscall(n,N,...)
39           __sc_return(t)
40
41 */
42
43         /* some fallback defaults */
44
45 #ifndef __sysc_seterr
46 #define __sysc_seterr(e)        do { errno = (e); } while(0)
47 #endif
48
49 #ifndef __sysc_cid
50 #define __sysc_cid(N)           __NR_##N
51 #endif
52
53
54 /*      *****************************************
55         ALPHA   ALPHA   ALPHA   ALPHA           *
56         alpha kernel interface                  */
57
58 #if     defined(__alpha__)
59
60 /*      The Alpha calling convention doesn't use the stack until
61         after the first six arguments have been passed in registers.
62
63         scnr:   v0($0)
64         args:   a1($16), a2($17), a3($18), a4($19), a5($20), a6($21)
65         sret:   r0($0)
66         serr:   e0($19) (!=0, err=sret)
67         call:   callsys
68         clob:   memory
69         move:   mov $sR,$dR
70         picr:   pr($29) do we need to save that?
71 */
72
73 #define __sysc_cmd(n)   "callsys"
74
75 #define __sysc_reg_cid  "$0"
76 #define __sysc_con_cid  "v"
77 #define __sysc_reg_ret  "$0"
78 #define __sysc_con_ret  "=v"
79 #define __sysc_reg_err  "$19"
80
81 #define __sysc_regs     "$16", "$17", "$18", "$19", "$20", "$21"
82 #define __sysc_clbrs    "$16", "$17", "$18", "memory", "$20", "$21"
83 #define __sysc_clobber  "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \
84                         "$22", "$23", "$24", "$25", "$27", "$28", "memory"
85
86
87 /*      *****************************************
88         ARM     ARM     ARM     ARM             *
89         arm kernel interface                    */
90
91 #elif   defined(__arm__)
92
93 #ifdef __ARM_EABI__
94
95 /*      The Arm calling convention uses stack args after four arguments
96         but the Linux kernel gets up to seven arguments in registers.
97         
98         scnr:   r7
99         args:   a1(r0), a2(r1), a3(r2), a4(r3), a5(r4), a6(r5),
100         sret:   r0(r0)
101         serr:   (sret >= (unsigned)-EMAXERRNO)
102         call:   swi
103         clob:   memory
104         move:   mov $dR,$sR
105 */
106
107 #define __sysc_max_err  125
108
109 #define __sysc_cmd(n)   "swi $0x0"
110
111 #define __sysc_regs     "r0", "r1", "r2", "r3", "r4", "r5"
112 #define __sysc_reg_cid  "r7"
113 #define __sysc_reg_ret  "r0"
114
115 #warning syscall arch armel not tested yet
116
117 #else
118
119 /*      The Arm calling convention uses stack args after four arguments
120         but the Linux kernel gets up to seven arguments in registers.
121         
122         scnr:   imm
123         args:   a1(r0), a2(r1), a3(r2), a4(r3), a5(r4), a6(r5),
124         sret:   r0(r0)
125         serr:   (sret >= (unsigned)-EMAXERRNO)
126         call:   swi
127         clob:   memory
128         move:   mov $dR,$sR
129 */
130
131 #define __sysc_max_err  125
132
133 #define __sysc_cmd(n)   "swi    %1"
134
135 #define __sysc_regs     "r0", "r1", "r2", "r3", "r4", "r5"
136 #define __sysc_reg_ret  "r0"
137
138 #warning syscall arch arm not tested yet
139
140 #endif
141
142
143 /*      *****************************************
144         CRIS    CRIS    CRIS    CRIS            *
145         cris v10 kernel interface               */
146
147 #elif   defined(__cris__)
148
149 /*      The Cris calling convention uses stack args after four arguments
150         but the Linux kernel gets up to six arguments in registers.
151
152         scnr:   id(r9)
153         args:   a1(r10), a2(r11), a3(r12), a4(r13), a5(mof), a6(srp),
154         sret:   r0(r10)
155         serr:   (sret >= (unsigned)-EMAXERRNO)
156         call:   break 13
157         clob:   memory
158 */
159
160 #error syscall arch cris not implemented yet
161
162
163
164 /*      *****************************************
165         FRV     FRV     FRV     FRV             *
166         frv kernel interface            */
167
168 #elif   defined(__frv__)
169
170 /*      The C calling convention on FR-V uses the gr8-gr13 registers
171         for the first six arguments, the remainder is spilled onto the
172         stack. the linux kernel syscall interface does so too.
173         
174         scnr:   id(gr7)
175         args:   a1(gr8), a2(gr9), a3(gr10), a4(gr11), a5(gr12), a6(gr13)
176         sret:   r0(gr8)
177         serr:   (sret >= (unsigned)-EMAXERRNO)
178         call:   tra gr0,gr0
179         clob:   memory
180 */
181
182 #error syscall arch frv not implemented yet
183
184
185
186 /*      *****************************************
187         H8300   H8300   H8300   H8300           *
188         h8/300 kernel interface                 */
189
190 #elif   defined(__H8300__)
191
192 /*      The H8/300 C calling convention passes the first three
193         arguments in registers. However the linux kernel calling
194         convention passes the first six arguments in registers
195         er1-er6
196
197         scnr:   id(er0)
198         args:   a1(er1), a2(er2), a3(er3), a4(er4), a5(er5), a6(er6)
199         sret:   r0(er0)
200         serr:   (sret >= (unsigned)-EMAXERRNO)
201         call:   trapa #0
202         clob:   memory
203 */
204
205 #error syscall arch h8300 not implemented yet
206
207
208
209 /*      *****************************************
210         HPPA    HPPA    HPPA    HPPA            *
211         hppa/64 kernel interface                */
212
213 #elif   defined(__hppa__)
214
215 /*      The hppa calling convention uses r26-r23 for the first 4
216         arguments, the rest is spilled onto the stack. However the
217         Linux kernel passes the first six arguments in the registers
218         r26-r21.
219
220         The system call number MUST ALWAYS be loaded in the delay
221         slot of the ble instruction, or restarting system calls
222         WILL NOT WORK.
223
224         scnr:   id(r20)
225         args:   a1(r26), a2(r25), a3(r24), a4(r23), a5(r22), a6(r21)
226         sret:   r0(r28)
227         serr:   (sret >= (unsigned)-EMAXERRNO)
228         call:   ble  0x100(%%sr2, %%r0)
229         clob:   r1, r2, (r4), r20, r29, r31, memory
230         picr:   pr(r19) do we need to save that?
231 */
232
233 #define __sysc_max_err  4095
234
235 #define __sysc_cmd(n)   \
236         __pasm(n,1,1,   "copy %%r19, %%r4"      ,)\
237         __casm(n,0,1,   "ble 0x100(%%sr2,%%r0)" ,)\
238         __casm(n,0,1,   "ldi %1,%%r20"          ,)\
239         __pasm(n,1,1,   "copy %%r4, %%r19"      ,)
240
241 #define __sysc_regs     "r26", "r25", "r24", "r23", "r22", "r21"
242
243 #ifndef __PIC__
244 #define __sysc_clobber  "r1", "r2", "r20", "r29", "r31", "memory"
245 #else
246 #define __sysc_clobber  "r1", "r2", "r4", "r20", "r29", "r31", "memory"
247 #endif
248
249 #warning syscall arch hppa not tested yet
250
251
252
253 /*      *****************************************
254         I386    I386    I386    I386            *
255         i386 kernel interface                   */
256
257 #elif   defined(__i386__)
258
259 /*      The x86 calling convention uses stack args for all arguments,
260         but the Linux kernel passes the first six arguments in the
261         following registers: ebx, ecx, edx, esi, edi, ebp.
262         
263         scnr:   id(eax)
264         args:   a1(ebx), a2(ecx), a3(edx), a4(esi), a5(edi), a6(ebp) 
265         sret:   r0(eax)
266         serr:   (sret >= (unsigned)-EMAXERRNO)
267         call:   int 0x80
268         picr:   pr(ebx)
269         clob:   memory
270         move:   movl $sR,$dR
271 */
272
273 #define __sysc_max_err  129
274
275 #define __sc_reg1(...) __sc_cast(__arg_1(__VA_ARGS__,,,,,,))
276 #define __sc_reg6(...) __sc_cast(__arg_6(__VA_ARGS__,,,,,,))
277
278 #define __scsd  struct { __sc_ldef(__a); __sc_ldef(__b); } __scs
279 #define __scsa(n,...) \
280         __scs.__a = __sc_reg1(__VA_ARGS__);     \
281         __scs.__b = __sc_reg6(__VA_ARGS__);
282
283 #define __sc_input(n,...) __casm(n,6,0,         \
284         __scsd; __scsa(n,__VA_ARGS__),  )
285
286 #define __cm    ,
287 #define __sc_null(n)    __arg_##n(              \
288         __cm,__cm,__cm,__cm,__cm,__cm)
289
290 #define __sc_rvcs(r,v)  r (__sc_cast(v))
291
292 #define __sc_rvrd(n,N)  __arg_##n(,             \
293         __cm    __sc_rvcs("c", N),              \
294         __cm    __sc_rvcs("d", N),              \
295         __cm    __sc_rvcs("S", N),              \
296         __cm    __sc_rvcs("D", N),)
297
298 #define __sc_arg1(n,...) __Casm(n,1,6,0,,       \
299         __sc_rvcs(__pic("ri") __nopic("b"),     \
300         __sc_reg1(__VA_ARGS__)),                \
301         __sc_rvcs("0", &__scs))
302
303 #define __sc_syscall(n,N,...) \
304         __sc_asm_vol (__sysc_cmd(n)             \
305           : __sc_oregs                          \
306           : __sc_cidval(N) __sc_null(n)         \
307             __sc_arg1(n,__VA_ARGS__)            \
308             __con_##n(__sc_rvrd,__VA_ARGS__)    \
309           : "memory" )
310
311 #define __sysc_cmd(n)   \
312         __pasm(n,1,1,   "pushl  %%ebx"          ,)\
313         __Pasm(n,1,5,1,,"movl   %2, %%ebx"      ,)\
314         __casm(n,6,1,   "pushl  %%ebp"          ,)\
315         __casm(n,6,1,   "movl   0(%2), %%ebx"   ,)\
316         __casm(n,6,1,   "movl   4(%2), %%ebp"   ,)\
317         __casm(n,0,1,   "movl   %1, %%eax"      ,)\
318         __casm(n,0,1,   "int    $0x80"          ,)\
319         __casm(n,6,1,   "popl   %%ebp"          ,)\
320         __pasm(n,1,1,   "popl   %%ebx"          ,)
321
322 #define __sysc_reg_ret  "eax"
323 #define __sysc_con_ret  "=a"
324
325
326
327 /*      *****************************************
328         IA64    IA64    IA64    IA64            *
329         ia64 kernel interface                   */
330
331 #elif   defined(__ia64__)
332
333 /*      The ia64 calling convention uses out0-out7 to pass the first
334         eight arguments (mapped via register windows).
335
336         scnr:   id(r15)
337         args:   a1(out0), a2(out1), ... a5(out4), a6(out5)
338         sret:   r0(r8)
339         serr:   e0(r10)
340         call:   break 0x100000
341         clob:   out6/7, r2/3/9, r11-r14, r16-r31, p6-p15, f6-f15, b6/7
342         move:   mov %dR = %sR
343 */
344
345 #define __sysc_errc(r,e)        ((e) == -1)
346
347 #define __sysc_cmd(n)   "break.i 0x100000"
348
349 #define __sysc_regs     "out0", "out1", "out2", "out3", "out4", "out5"
350 #define __sysc_reg_cid  "r15"
351 #define __sysc_reg_ret  "r8"
352 #define __sysc_reg_err  "r10"
353
354 #define __sysc_clobber  \
355         "out6", "out7", "r2", "r3", "r9", "r11", "r12", "r13",          \
356         "r14", "r16", "r17", "r18", "r19", "r20", "r21", "r22",         \
357         "r23", "r24", "r25", "r26", "r27", "r28", "r29", "r30",         \
358         "r31", "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13",      \
359         "p14", "p15", "f6", "f7", "f8", "f9", "f10", "f11", "f12",      \
360         "f13", "f14", "f15", "f16", "b6", "b7", "cc", "memory"
361
362 #warning syscall arch ia64 not tested yet
363
364
365
366 /*      *****************************************
367         M32R    M32R    M32R    M32R            *
368         m32r kernel interface                   */
369
370 #elif   defined(__M32R__)
371
372 /*      The m32r calling convention uses r0-r7 to pass the first
373         eight arguments (mapped via register windows).
374
375         scnr:   id(r0)
376         args:   a1(r1), a2(r2), a3(r3), a4(r4), a5(r5), a6(r6)
377         sret:   r0(r0)
378         serr:   (sret >= (unsigned)-EMAXERRNO)
379         call:   trap #2
380         clob:   out6/7, r2/3/9, r11-r14, r16-r31, p6-p15, f6-f15, b6/7
381         move:   mv %dR,%sR
382 */
383
384 #define __sysc_max_err  125
385
386 #define __sysc_cmd(n)   "trap #2"
387
388 #define __sysc_regs     "r0", "r1", "r2", "r3", "r4", "r5"
389 #define __sysc_reg_cid  "r7"
390 #define __sysc_reg_ret  "r0"
391
392 #warning syscall arch m32r not tested yet
393
394
395
396 /*      *****************************************
397         M68K    M68K    M68K    M68K            *
398         m68k kernel interface                   */
399
400 #elif   defined(__m68000__)
401
402 #error syscall arch m68k not implemented yet
403
404
405
406 /*      *****************************************
407         MIPS    MIPS    MIPS    MIPS            *
408         mips kernel interface                   */
409
410 #elif   defined(__mips__)
411
412 /*      The ABIO32 calling convention uses a0-a3  to pass the first
413         four arguments, the rest is passed on the userspace stack.  
414         The 5th arg starts at 16($sp). The new mips calling abi uses 
415         registers a0-a5, restart requires a reload of v0 (#syscall)
416
417         ABIN32 and ABI64 pass 6 args in a0-a3, t0-t1.
418
419         scnr:   id(v0)
420         args:   a1(a0), a2(a1), a3(a2), a4(a3), a5(t0), a6(t1)
421         sret:   r0(v0)
422         serr:   e0(a3)
423         call:   syscall
424         clob:   at, v1, t2-t7, t8-t9
425         move:   move    %dR,%sR
426 */
427
428 #define __sysc_cmd(n)   \
429         __casm(n,0,1,   "ori    $v0,$0,%2"      ,)\
430         __casm(n,0,1,   "syscall"               ,)
431
432 #define __sysc_regs     "a0","a1","a2","a3", "t0", "t1"
433 #define __sysc_reg_ret  "v0"
434 #define __sysc_reg_err  "a3"
435
436 #define __sysc_clobber  "$1", "$3", "$10", "$11", "$12",                \
437                         "$13", "$14", "$15", "$24", "$25", "memory"
438
439 #warning syscall arch mips not tested yet
440
441
442
443 /*      *****************************************
444         PPC     PPC     PPC     PPC             *
445         ppc/64 kernel interface                 */
446
447 #elif   defined(__powerpc__)
448
449 /*      The powerpc calling convention uses r3-r10 to pass the first
450         eight arguments, the remainder is spilled onto the stack.
451         
452         scnr:   id(r0)
453         args:   a1(r3), a2(r4), a3(r5), a4(r6), a5(r7), a6(r8)
454         sret:   r0(r3)
455         serr:   (carry)
456         call:   sc
457         clob:   r9-r12, cr0, ctr
458         move:   mr %dR,%sR
459 */
460
461 #define __sysc_errc(r,e)        ((e) & 0x10000000)
462
463 #define __sysc_cmd(n)   \
464         __casm(n,0,1,   "sc"                    ,)\
465         __casm(n,0,1,   "mfcr %1"               ,)
466
467 #define __sysc_regs     "r3", "r4", "r5", "r6", "r7", "r8"
468 #define __sysc_reg_cid  "r0"
469 #define __sysc_reg_ret  "r3"
470
471 #define __sysc_clobber  "r9", "r10", "r11", "r12", "cr0", "ctr", "memory"
472
473
474
475 /*      *****************************************
476         S390    S390    S390    S390            *
477         s390/x kernel interface                 */
478
479 #elif   defined(__s390__)
480
481 /*      The s390x calling convention passes the first five arguments
482         in r2-r6, the remainder is spilled onto the stack. However
483         the Linux kernel passes the first six arguments in r2-r7.
484         
485         scnr:   imm, id(r1)
486         args:   a1(r2), a2(r3), a3(r4), a4(r5), a5(r6), a6(r7)
487         sret:   r0(r2)
488         serr:   (sret >= (unsigned)-EMAXERRNO)
489         call:   svc
490         clob:   memory
491 */
492
493 #define __sysc_max_err  4095
494
495 #define __sysc_cmd(n)   "svc    0"
496
497 // #define      __sysc_type     unsigned long
498
499 #define __sysc_regs     "r2", "r3", "r4", "r5", "r6", "r7"
500 #define __sysc_reg_cid  "r1"
501 #define __sysc_reg_ret  "r2"
502
503 #warning syscall arch s390 not tested yet
504
505
506
507 /*      *****************************************
508         SH      SH      SH      SH              *
509         sh kernel interface                     */
510
511 #elif   defined(__sh__) && !defined(__SH5__)
512
513 /*      The SuperH calling convention passes the first four arguments
514         in r4-r7, the remainder is spilled onto the stack. However
515         the Linux kernel passes the remainder in r0-r1.
516
517         scnr:   id(r3)
518         args:   a1(r4), a2(r5), a3(r6), a4(r7), a5(r0), a6(r1)
519         sret:   r0(r0)
520         serr:   (sret >= (unsigned)-EMAXERRNO)
521         call:   trapa #0x1x (x=#args)
522         clob:   memory
523         move:   ori     %sR,0,%dR
524 */
525
526 #ifdef  __sh2__
527 #define __sysc_arch     "trapa  #0x2"
528 #else
529 #define __sysc_arch     "trapa  #0x1"
530 #endif
531
532 #define __sysc_max_err  4095
533
534 #define __sysc_cmd(n)   __sysc_arch #n
535
536 #define __sysc_regs     "r4", "r5", "r6", "r7", "r0", "r1"
537 #define __sysc_reg_cid  "r3"
538 #define __sysc_reg_ret  "r0"
539
540 #warning syscall arch sh not tested yet
541
542
543
544 /*      *****************************************
545         SH64    SH64    SH64    SH64            *
546         sh64 kernel interface                   */
547
548 #elif defined(__sh__) && defined(__SH5__)
549
550 /*      The SuperH-5 calling convention passes the first eight
551         arguments in r2-r9. The Linux kernel uses only six of
552         them as arguments, and the last one for the syscall id.
553
554         scnr:   id(r9)
555         args:   a1(r2), a2(r3), a3(r4), a4(r5), a5(r6), a6(r7)
556         sret:   r0(r9)
557         serr:   (sret >= (unsigned)-EMAXERRNO)
558         call:   trapa #0x1x (x=#args)
559         clob:   memory
560         move:   ori     %sR,0,%dR
561 */
562
563 #define __sysc_max_err  4095
564
565 #define __sysc_cmd(n)   \
566         __casm(n,0,1,   "movi   0x1" #n ",r9"   ,)\
567         __casm(n,0,1,   "shori  %1,r9"          ,)\
568         __casm(n,0,1,   "trapa  r9"             ,)
569
570 #define __sysc_regs     "r2", "r3", "r4", "r5", "r6", "r7"
571 #define __sysc_reg_ret  "r9"
572
573 #warning syscall arch sh64 not tested yet
574
575
576
577 /*      *****************************************
578         SPARC64 SPARC64 SPARC64 SPARC64         *
579         sparc64 kernel interface                */
580
581 #elif   defined(__sparc__)
582
583 /*      The sparc/64 calling convention uses o0-o5 to pass the first
584         six arguments (mapped via register windows).
585
586         scnr:   id(g1)
587         args:   a1(o0), a2(o1), a3(o2), a4(o3), a5(o4), a6(o5)
588         sret:   r0(o0)
589         serr:   (carry)
590         call:   ta 0x6d, t 0x10
591         clob:   g1-g6, g7?, o7?, f0-f31, cc
592         move:   mov     %sR,%dR
593 */
594
595 #ifdef  __arch64__
596 #define __sysc_arch     "ta     0x6d"
597 #else
598 #define __sysc_arch     "ta     0x10"
599 #endif
600
601 #define __sysc_cmd(n)   \
602         __casm(n,0,1,   __sysc_arch             ,)\
603         __casm(n,0,1,   "addx   %%g0,%%g0,%1"   ,)
604
605 #define __sysc_regs     "o0", "o1", "o2", "o3", "o4", "o5"
606 #define __sysc_reg_cid  "g1"
607 #define __sysc_reg_ret  "o0"
608
609 #define __sysc_clobber  "g2", "g3", "g4", "g5", "g6",                   \
610         "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8",           \
611         "f9", "f10", "f11", "f12", "f13", "f14", "f15", "f16",          \
612         "f17", "f18", "f19", "f20", "f21", "f22", "f23", "f24",         \
613         "f25", "f26", "f27", "f28", "f29", "f30", "f31", "f32",         \
614         "f34", "f36", "f38", "f40", "f42", "f44", "f46", "f48",         \
615         "f50", "f52", "f54", "f56", "f58", "f60", "f62",                \
616         "cc", "memory"
617
618
619
620 /*      *****************************************
621         V850    V850    V850    V850            *
622         v850 kernel interface                   */
623
624 #elif   defined(__v850__)
625
626 /*      The V850 calling convention passes the first four arguments
627         in registers r6-r9, the rest is spilled onto the stack.
628         but the Linux kernel interface uses r6-r9 and r13/14.
629
630         scnr:   id(r12)
631         args:   a1(r6), a2(r7), a3(r8), a4(r9), a5(r13), a6(r14)
632         sret:   r0(r10)
633         serr:   (sret >= (unsigned)-EMAXERRNO)
634         call:   trap 0, trap 1
635         clob:   r1, r5, r11, r15-r19
636 */
637
638 #define __sysc_max_err  515
639
640 #define __sysc_cmd(n)   \
641         __casm(n,4,0,   "trap 1"        ,"trap 0"       )
642
643 #define __sysc_regs     "r6", "r7", "r8", "r9", "r13", "r14"
644 #define __sysc_reg_cid  "r12"
645 #define __sysc_reg_ret  "r10"
646
647 #define __sysc_clobber  "r1", "r5", "r11",                              \
648                         "r15", "r16", "r17", "r18", "r19", "memory"
649
650 #warning syscall arch v850 not tested yet
651
652
653
654 /*      *****************************************
655         X86_64  X86_64  X86_64  X86_64          *
656         x86_64 kernel interface                 */
657
658 #elif   defined(__x86_64__)
659
660 /*      The x86_64 calling convention uses rdi, rsi, rdx, rcx, r8, r9
661         but the Linux kernel interface uses rdi, rsi, rdx, r10, r8, r9.
662         
663         scnr:   id(rax)
664         args:   a1(rdi), a2(rsi), a3(rdx), a4(r10), a5(r8), a6(r9)
665         sret:   r0(rax)
666         serr:   (err= sret > (unsigned)-EMAXERRNO)
667         call:   syscall
668         clob:   rcx, r11
669 */
670
671 #define __sysc_max_err  4095
672
673 #define __sysc_cmd(n)   "syscall"
674
675 #define __sysc_regs     "rdi", "rsi", "rdx", "r10", "r8", "r9"
676 #define __sysc_reg_cid  "rax"
677 #define __sysc_reg_ret  "rax"
678 #define __sysc_con_ret  "=a"
679
680 #define __sysc_clobber  "cc", "r11", "rcx", "memory"
681
682 #else
683 #error unknown kernel arch
684 #endif
685
686         
687         /* implementation defaults */
688
689
690
691 #ifndef __sysc_clobber
692 #define __sysc_clobber          "memory"
693 #endif
694
695 #ifndef __sysc_acon
696 #define __sysc_acon(n)          "r"
697 #endif
698
699 #ifndef __sysc_con_ret
700 #define __sysc_con_ret          "=r"
701 #endif
702
703 #ifndef __sysc_con_err
704 #define __sysc_con_err          "=r"
705 #endif
706
707 #ifndef __sysc_con_cid
708 #ifdef  __sysc_reg_cid
709 #define __sysc_con_cid          "r"
710 #else
711 #define __sysc_con_cid          "i"
712 #endif
713 #endif
714
715 #ifndef __sysc_type
716 #define __sysc_type             long
717 #endif
718
719 #ifdef  __sysc_regs
720 #define __sysc_rega(n,...)      __arg_##n(__VA_ARGS__)
721 #ifndef __sysc_reg
722 #define __sysc_reg(n)           __sysc_rega(n,__sysc_regs)
723 #endif
724 #endif
725
726
727
728         /* argument list */
729
730 #define __lst_6(x,a1,a2,a3,a4,a5,a6)    __lst_5(x,a1,a2,a3,a4,a5),x(6,a6)
731 #define __lst_5(x,a1,a2,a3,a4,a5)       __lst_4(x,a1,a2,a3,a4),x(5,a5)
732 #define __lst_4(x,a1,a2,a3,a4)          __lst_3(x,a1,a2,a3),x(4,a4)
733 #define __lst_3(x,a1,a2,a3)             __lst_2(x,a1,a2),x(3,a3)
734 #define __lst_2(x,a1,a2)                __lst_1(x,a1),x(2,a2)
735 #define __lst_1(x,a1)                   __lst_0(x,*),x(1,a1)
736 #define __lst_0(x,a0)
737
738         /* argument concatenation */
739
740 #define __con_6(x,a1,a2,a3,a4,a5,a6)    __con_5(x,a1,a2,a3,a4,a5)x(6,a6)
741 #define __con_5(x,a1,a2,a3,a4,a5)       __con_4(x,a1,a2,a3,a4)x(5,a5)
742 #define __con_4(x,a1,a2,a3,a4)          __con_3(x,a1,a2,a3)x(4,a4)
743 #define __con_3(x,a1,a2,a3)             __con_2(x,a1,a2)x(3,a3)
744 #define __con_2(x,a1,a2)                __con_1(x,a1)x(2,a2)
745 #define __con_1(x,a1)                   __con_0(x,*)x(1,a1)
746 #define __con_0(x,a0)
747
748         /* argument selection */
749
750 #define __arg_0(...)
751 #define __arg_1(a1,...)                 a1
752 #define __arg_2(a1,a2,...)              a2
753 #define __arg_3(a1,a2,a3,...)           a3
754 #define __arg_4(a1,a2,a3,a4,...)        a4
755 #define __arg_5(a1,a2,a3,a4,a5,...)     a5
756 #define __arg_6(a1,a2,a3,a4,a5,a6,...)  a6
757
758         /* list remainder */
759
760 #define __rem_0(a1,a2,a3,a4,a5,a6)      ,a1,a2,a3,a4,a5,a6
761 #define __rem_1(a1,a2,a3,a4,a5,a6)      ,a2,a3,a4,a5,a6
762 #define __rem_2(a1,a2,a3,a4,a5,a6)      ,a3,a4,a5,a6
763 #define __rem_3(a1,a2,a3,a4,a5,a6)      ,a4,a5,a6
764 #define __rem_4(a1,a2,a3,a4,a5,a6)      ,a5,a6
765 #define __rem_5(a1,a2,a3,a4,a5,a6)      ,a6
766 #define __rem_6(...)
767
768
769         /* conditional asm */
770
771 #define __casm_use(q,r,v)       v __casm_use_##q##r(__casm_nl(""))
772
773 #define __casm_use_10(v)
774 #define __casm_use_11(v)        v
775 #define __casm_use_12(v)
776 #define __casm_use_13(v)        v
777
778 #define __casm_use_20(v)
779 #define __casm_use_21(v)
780 #define __casm_use_22(v)        v
781 #define __casm_use_23(v)        v
782
783
784 #define __casm_00(v,w,r)        __casm_use(1,r,v)
785 #define __casm_01(v,w,r)        __casm_use(2,r,w)
786 #define __casm_02(v,w,r)        __casm_use(2,r,w)
787 #define __casm_03(v,w,r)        __casm_use(2,r,w)
788 #define __casm_04(v,w,r)        __casm_use(2,r,w)
789 #define __casm_05(v,w,r)        __casm_use(2,r,w)
790 #define __casm_06(v,w,r)        __casm_use(2,r,w)
791
792 #define __casm_10(v,w,r)        __casm_use(1,r,v)
793 #define __casm_11(v,w,r)        __casm_use(1,r,v)
794 #define __casm_12(v,w,r)        __casm_use(2,r,w)
795 #define __casm_13(v,w,r)        __casm_use(2,r,w)
796 #define __casm_14(v,w,r)        __casm_use(2,r,w)
797 #define __casm_15(v,w,r)        __casm_use(2,r,w)
798 #define __casm_16(v,w,r)        __casm_use(2,r,w)
799
800 #define __casm_20(v,w,r)        __casm_use(1,r,v)
801 #define __casm_21(v,w,r)        __casm_use(1,r,v)
802 #define __casm_22(v,w,r)        __casm_use(1,r,v)
803 #define __casm_23(v,w,r)        __casm_use(2,r,w)
804 #define __casm_24(v,w,r)        __casm_use(2,r,w)
805 #define __casm_25(v,w,r)        __casm_use(2,r,w)
806 #define __casm_26(v,w,r)        __casm_use(2,r,w)
807
808 #define __casm_30(v,w,r)        __casm_use(1,r,v)
809 #define __casm_31(v,w,r)        __casm_use(1,r,v)
810 #define __casm_32(v,w,r)        __casm_use(1,r,v)
811 #define __casm_33(v,w,r)        __casm_use(1,r,v)
812 #define __casm_34(v,w,r)        __casm_use(2,r,w)
813 #define __casm_35(v,w,r)        __casm_use(2,r,w)
814 #define __casm_36(v,w,r)        __casm_use(2,r,w)
815
816 #define __casm_40(v,w,r)        __casm_use(1,r,v)
817 #define __casm_41(v,w,r)        __casm_use(1,r,v)
818 #define __casm_42(v,w,r)        __casm_use(1,r,v)
819 #define __casm_43(v,w,r)        __casm_use(1,r,v)
820 #define __casm_44(v,w,r)        __casm_use(1,r,v)
821 #define __casm_45(v,w,r)        __casm_use(2,r,w)
822 #define __casm_46(v,w,r)        __casm_use(2,r,w)
823
824 #define __casm_50(v,w,r)        __casm_use(1,r,v)
825 #define __casm_51(v,w,r)        __casm_use(1,r,v)
826 #define __casm_52(v,w,r)        __casm_use(1,r,v)
827 #define __casm_53(v,w,r)        __casm_use(1,r,v)
828 #define __casm_54(v,w,r)        __casm_use(1,r,v)
829 #define __casm_55(v,w,r)        __casm_use(1,r,v)
830 #define __casm_56(v,w,r)        __casm_use(2,r,w)
831
832 #define __casm_60(v,w,r)        __casm_use(1,r,v)
833 #define __casm_61(v,w,r)        __casm_use(1,r,v)
834 #define __casm_62(v,w,r)        __casm_use(1,r,v)
835 #define __casm_63(v,w,r)        __casm_use(1,r,v)
836 #define __casm_64(v,w,r)        __casm_use(1,r,v)
837 #define __casm_65(v,w,r)        __casm_use(1,r,v)
838 #define __casm_66(v,w,r)        __casm_use(1,r,v)
839
840
841         /* special PIC handling */
842
843 #ifdef  __PIC__
844 #define __pic(v)                v
845 #define __nopic(v)
846 #else
847 #define __pic(v)
848 #define __nopic(v)              v
849 #endif
850
851 #define __casm_nl(v)            v "\n\t"
852
853 #define __casm(n,a,r,v,w)       __casm_##n##a(v,w,r)
854 #define __Casm(n,a,b,r,u,v,w)   __casm_##n##b(w,__casm_##n##a(v,u,r),r)
855
856 #define __pasm(n,a,r,v,w)       __pic(__casm(n,a,r,v,w))
857 #define __Pasm(n,a,b,r,u,v,w)   __pic(__Casm(n,a,b,r,u,v,w))
858
859 #define __nasm(n,a,r,v,w)       __nopic(__casm(n,a,r,v,w))
860 #define __Nasm(n,a,b,r,u,v,w)   __nopic(__Casm(n,a,b,r,u,v,w))
861
862
863 #define __sc_cast(v)            (__sysc_type)(v)
864 #define __sc_ldef(N)            __sysc_type N
865 #define __sc_rdef(N,R)          register __sc_ldef(N) __sc_asm (R)
866
867 #define __sc_scid(N,v)          __sc_ldef(N) = __sc_cast(v)
868 #define __sc_areg(N,R,v)        __sc_rdef(N,R) = __sc_cast(v)
869
870 #define __sc_rval(n,v)          "r"(__sc_a##n)
871 #define __sc_ival(n,v)          __sysc_acon(n)(__sc_cast(v))
872 #define __sc_idef(n,v)          __sc_areg(__sc_a##n, __sysc_reg(n), v);
873
874 #ifdef  __sysc_clbrs
875 #define __sc_cregs(n,...)       __rem_##n(__VA_ARGS__)
876 #else
877 #define __sc_cregs(n,...)
878 #endif
879
880 #ifdef  __sysc_regs
881 #define __sc_input(n,...)       __con_##n(__sc_idef,__VA_ARGS__)
882 #define __sc_ivals(n,...)       __lst_##n(__sc_rval,__VA_ARGS__)
883 #else
884 #define __sc_ivals(n,...)       __lst_##n(__sc_ival,__VA_ARGS__)
885 #endif
886
887 #ifdef  __sysc_reg_cid
888 #define __sc_cidvar(N)          __sc_areg(__sc_id, \
889                                 __sysc_reg_cid, __sysc_cid(N))
890 #define __sc_cidval(N)          __sysc_con_cid (__sc_id)
891 #endif
892
893 #ifndef __sc_input
894 #define __sc_input(n,...)
895 #endif
896
897 #ifndef __sc_cidval
898 #define __sc_cidval(N)          __sysc_con_cid (__sysc_cid(N))
899 #endif
900
901 #ifndef __sc_cidvar
902 #define __sc_cidvar(N)
903 #endif
904
905
906 #ifdef  __sysc_reg_ret
907 #define __sc_ret        __ret
908 #define __sc_def_ret    __sc_ldef(ret); __sc_rdef(__sc_ret,__sysc_reg_ret)
909 #else
910 #define __sc_ret        ret
911 #define __sc_def_ret    __sc_ldef(__sc_ret)
912 #endif
913
914 #ifdef  __sysc_reg_err
915 #define __sc_err        __err
916 #define __sc_def_err    __sc_ldef(err); __sc_rdef(__sc_err,__sysc_reg_err)
917 #else
918 #define __sc_err        err
919 #define __sc_def_err    __sc_ldef(__sc_err)
920 #endif
921
922
923 #ifndef __sysc_max_err
924 #define __sc_complex
925 #endif
926
927 #ifdef  __sc_complex    /* complex result */
928
929 #ifndef __sc_results
930 #define __sc_results    __sc_def_ret; __sc_def_err
931 #endif
932
933 #ifndef __sysc_errc
934 #define __sysc_errc(ret, err) (err)
935 #endif
936
937 #ifndef __sysc_retv
938 #define __sysc_retv(type, ret, err)                                     \
939         if (__sysc_errc(ret, err)) {                                    \
940                 __sysc_seterr(ret);                                     \
941                 ret = -1;                                               \
942         }                                                               \
943         return (type)(ret)
944 #endif
945
946 #define __sc_oregs      __sysc_con_ret (__sc_ret),                      \
947                         __sysc_con_err (__sc_err)
948 #ifndef __sc_return
949 #define __sc_return(t)  ret = __sc_ret; err = __sc_err;                 \
950                         __sysc_retv(t, ret, err)
951 #endif
952 #else                   /* simple result  */
953
954 #ifndef __sc_results
955 #define __sc_results    __sc_def_ret
956 #endif
957
958 #ifndef __sysc_errc
959 #define __sysc_errc(ret)                                                \
960         ((unsigned __sysc_type)(ret) >=                                 \
961                 (unsigned __sysc_type)(-(__sysc_max_err)))
962 #endif
963
964 #ifndef __sysc_retv
965 #define __sysc_retv(type, ret)                                          \
966         if (__sysc_errc(ret)) {                                         \
967                 __sysc_seterr(-ret);                                    \
968                 ret = -1;                                               \
969         }                                                               \
970         return (type)(ret)
971 #endif
972
973 #define __sc_oregs      __sysc_con_ret (__sc_ret)
974 #ifndef __sc_return
975 #define __sc_return(t)  ret = __sc_ret; __sysc_retv(t, ret)
976 #endif
977 #endif                  /* simple/complex */
978
979
980
981         /* the inline syscall */
982
983 #define __sc_asm        __asm__
984 #define __sc_asm_vol    __asm__ __volatile__
985
986 #ifndef __sc_syscall
987 #define __sc_syscall(n,N,...)                                           \
988         __sc_asm_vol (__sysc_cmd(n)                                     \
989           : __sc_oregs                                                  \
990           : __sc_cidval(N) __sc_ivals(n,__VA_ARGS__)                    \
991           : __sysc_clobber __sc_cregs(n,__sysc_clbrs))
992 #endif
993
994 #ifndef __sc_body
995 #define __sc_body(n, type, name, ...)                                   \
996 {                                                                       \
997         __sc_results;__sc_cidvar(name);                                 \
998         __sc_input(n,__VA_ARGS__)                                       \
999         __sc_syscall(n,name,__VA_ARGS__);                               \
1000         __sc_return(type);                                              \
1001 }
1002 #endif
1003
1004 #define _syscall0(type, name)                                           \
1005 type name(void)                                                         \
1006 __sc_body(0, type, name, *)
1007
1008 #define _syscall1(type, name, type1, arg1)                              \
1009 type name(type1 arg1)                                                   \
1010 __sc_body(1, type, name, arg1)
1011
1012 #define _syscall2(type, name, type1, arg1, type2, arg2)                 \
1013 type name(type1 arg1, type2 arg2)                                       \
1014 __sc_body(2, type, name, arg1, arg2)
1015
1016 #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)    \
1017 type name(type1 arg1, type2 arg2, type3 arg3)                           \
1018 __sc_body(3, type, name, arg1, arg2, arg3)
1019
1020 #define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1021                               type4, arg4)                              \
1022 type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4)               \
1023 __sc_body(4, type, name, arg1, arg2, arg3, arg4)
1024
1025 #define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1026                               type4, arg4, type5, arg5)                 \
1027 type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)   \
1028 __sc_body(5, type, name, arg1, arg2, arg3, arg4, arg5)
1029
1030 #define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,    \
1031                         type4, arg4, type5, arg5, type6, arg6)          \
1032 type name(type1 arg1, type2 arg2, type3 arg3,                           \
1033           type4 arg4, type5 arg5, type6 arg6)                           \
1034 __sc_body(6, type, name, arg1, arg2, arg3, arg4, arg5, arg6)
1035
1036
1037
1038 #endif  /* __SYSCALL_NEW_H */