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