00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef compile_um
00021 #include "sysdepum.h"
00022 #else
00023
00024 #ifndef _LINUX_I386_SYSDEP_H
00025 #define _LINUX_I386_SYSDEP_H 1
00026
00027
00028
00029
00030
00031
00032 #ifdef __i386__
00033
00034
00035
00036
00037 #undef SYS_ify
00038 #define SYS_ify(syscall_name) __NR_##syscall_name
00039
00040
00041 #undef L
00042 #define L(name) .L##name
00043
00044 #ifdef __ASSEMBLER__
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #ifdef PIC
00060 # define SYSCALL_ERROR_LABEL 0f
00061 #else
00062 # define SYSCALL_ERROR_LABEL syscall_error
00063 #endif
00064
00065 #undef PSEUDO
00066 #define PSEUDO(name, syscall_name, args) \
00067 .text; \
00068 ENTRY (name) \
00069 DO_CALL (args, syscall_name); \
00070 cmpl _-4095, %eax; \
00071 jae SYSCALL_ERROR_LABEL; \
00072 L(pseudo_end):
00073
00074 #undef PSEUDO_END
00075 #define PSEUDO_END(name) \
00076 SYSCALL_ERROR_HANDLER \
00077 END (name)
00078
00079 #ifndef PIC
00080 #define SYSCALL_ERROR_HANDLER
00081 #else
00082
00083 #ifdef _LIBC_REENTRANT
00084 #define SYSCALL_ERROR_HANDLER \
00085 0:pushl %ebx; \
00086 call 1f; \
00087 1:popl %ebx; \
00088 xorl %edx, %edx; \
00089 addl __GLOBAL_OFFSET_TABLE_+[.-1b], %ebx; \
00090 subl %eax, %edx; \
00091 pushl %edx; \
00092 PUSH_ERRNO_LOCATION_RETURN; \
00093 call BP_SYM (__errno_location)@PLT; \
00094 POP_ERRNO_LOCATION_RETURN; \
00095 popl %ecx; \
00096 popl %ebx; \
00097 movl %ecx, (%eax); \
00098 orl _-1, %eax; \
00099 jmp L(pseudo_end);
00100
00101
00102 #else
00103 #define SYSCALL_ERROR_HANDLER \
00104 0:call 1f; \
00105 1:popl %ecx; \
00106 xorl %edx, %edx; \
00107 addl __GLOBAL_OFFSET_TABLE_+[.-1b], %ecx; \
00108 subl %eax, %edx; \
00109 movl errno@GOT(%ecx), %ecx; \
00110 movl %edx, (%ecx); \
00111 orl _-1, %eax; \
00112 jmp L(pseudo_end);
00113 #endif
00114 #endif
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 #undef DO_CALL
00161 #define DO_CALL(args, syscall_name) \
00162 PUSHARGS_##args \
00163 DOARGS_##args \
00164 movl _SYS_ify (syscall_name), %eax; \
00165 int _0x81 \
00166 POPARGS_##args
00167
00168 #define PUSHARGS_0
00169 #define DOARGS_0
00170 #define POPARGS_0
00171 #define _PUSHARGS_0
00172 #define _DOARGS_0(n)
00173 #define _POPARGS_0
00174
00175 #define PUSHARGS_1 movl %ebx, %edx; PUSHARGS_0
00176 #define DOARGS_1 _DOARGS_1 (4)
00177 #define POPARGS_1 POPARGS_0; movl %edx, %ebx
00178 #define _PUSHARGS_1 pushl %ebx; _PUSHARGS_0
00179 #define _DOARGS_1(n) movl n(%esp), %ebx; _DOARGS_0(n-4)
00180 #define _POPARGS_1 _POPARGS_0; popl %ebx
00181
00182 #define PUSHARGS_2 PUSHARGS_1
00183 #define DOARGS_2 _DOARGS_2 (8)
00184 #define POPARGS_2 POPARGS_1
00185 #define _PUSHARGS_2 _PUSHARGS_1
00186 #define _DOARGS_2(n) movl n(%esp), %ecx; _DOARGS_1 (n-4)
00187 #define _POPARGS_2 _POPARGS_1
00188
00189 #define PUSHARGS_3 _PUSHARGS_2
00190 #define DOARGS_3 _DOARGS_3 (16)
00191 #define POPARGS_3 _POPARGS_3
00192 #define _PUSHARGS_3 _PUSHARGS_2
00193 #define _DOARGS_3(n) movl n(%esp), %edx; _DOARGS_2 (n-4)
00194 #define _POPARGS_3 _POPARGS_2
00195
00196 #define PUSHARGS_4 _PUSHARGS_4
00197 #define DOARGS_4 _DOARGS_4 (24)
00198 #define POPARGS_4 _POPARGS_4
00199 #define _PUSHARGS_4 pushl %esi; _PUSHARGS_3
00200 #define _DOARGS_4(n) movl n(%esp), %esi; _DOARGS_3 (n-4)
00201 #define _POPARGS_4 _POPARGS_3; popl %esi
00202
00203 #define PUSHARGS_5 _PUSHARGS_5
00204 #define DOARGS_5 _DOARGS_5 (32)
00205 #define POPARGS_5 _POPARGS_5
00206 #define _PUSHARGS_5 pushl %edi; _PUSHARGS_4
00207 #define _DOARGS_5(n) movl n(%esp), %edi; _DOARGS_4 (n-4)
00208 #define _POPARGS_5 _POPARGS_4; popl %edi
00209
00210 #else
00211
00212
00213
00214 asm (".L__X'%ebx = 1\n\t"
00215 ".L__X'%ecx = 2\n\t"
00216 ".L__X'%edx = 2\n\t"
00217 ".L__X'%eax = 3\n\t"
00218 ".L__X'%esi = 3\n\t"
00219 ".L__X'%edi = 3\n\t"
00220 ".L__X'%ebp = 3\n\t"
00221 ".L__X'%esp = 3\n\t"
00222 ".macro bpushl name reg\n\t"
00223 ".if 1 - \\name\n\t"
00224 ".if 2 - \\name\n\t"
00225 "pushl %ebx\n\t"
00226 ".else\n\t"
00227 "xchgl \\reg, %ebx\n\t"
00228 ".endif\n\t"
00229 ".endif\n\t"
00230 ".endm\n\t"
00231 ".macro bpopl name reg\n\t"
00232 ".if 1 - \\name\n\t"
00233 ".if 2 - \\name\n\t"
00234 "popl %ebx\n\t"
00235 ".else\n\t"
00236 "xchgl \\reg, %ebx\n\t"
00237 ".endif\n\t"
00238 ".endif\n\t"
00239 ".endm\n\t"
00240 ".macro bmovl name reg\n\t"
00241 ".if 1 - \\name\n\t"
00242 ".if 2 - \\name\n\t"
00243 "movl \\reg, %ebx\n\t"
00244 ".endif\n\t"
00245 ".endif\n\t"
00246 ".endm\n\t");
00247
00248
00249 #ifndef __KERNEL__
00250 #include <errno.h>
00251 #else
00252 extern int kernel_errno;
00253 #define errno kernel_errno
00254 #endif
00255
00256
00257
00258 #undef INLINE_SYSCALL
00259 #define INLINE_SYSCALL(name, nr, args...) \
00260 ({ \
00261 unsigned int resultvar; \
00262 asm volatile ( \
00263 LOADARGS_##nr \
00264 "movl %1, %%eax\n\t" \
00265 "int _0x81\n\t" \
00266 RESTOREARGS_##nr \
00267 : "=a" (resultvar) \
00268 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
00269 if (resultvar >= 0xfffff001) \
00270 { \
00271 errno= (-resultvar); \
00272 resultvar = 0xffffffff; \
00273 } \
00274 (int) resultvar; })
00275
00276 #undef INLINE_SYSCALL1
00277 #define INLINE_SYSCALL1(name, nr, args...) \
00278 ({ \
00279 unsigned int resultvar; \
00280 asm volatile ( \
00281 LOADARGS_##nr \
00282 "movl %1, %%eax\n\t" \
00283 "int _0x82\n\t" \
00284 RESTOREARGS_##nr \
00285 : "=a" (resultvar) \
00286 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
00287 if (resultvar >= 0xfffff001) \
00288 { \
00289 errno= (-resultvar); \
00290 resultvar = 0xffffffff; \
00291 } \
00292 (int) resultvar; })
00293
00294 #undef INLINE_SYSCALL3
00295 #define INLINE_SYSCALL3(name, nr, args...) \
00296 ({ \
00297 unsigned int resultvar; \
00298 asm volatile ( \
00299 LOADARGS_##nr \
00300 "movl %1, %%eax\n\t" \
00301 "int _0x84\n\t" \
00302 RESTOREARGS_##nr \
00303 : "=a" (resultvar) \
00304 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
00305 if (resultvar >= 0xfffff001) \
00306 { \
00307 errno= (-resultvar); \
00308 resultvar = 0xffffffff; \
00309 } \
00310 (int) resultvar; })
00311
00312 #undef INLINE_SYSCALLTEST
00313 #define INLINE_SYSCALLTEST(name, nr, args...) \
00314 ({ \
00315 unsigned int resultvar; \
00316 asm volatile ( \
00317 LOADARGS_##nr \
00318 "movl %1, %%eax\n\t" \
00319 "call 0xc0100010\n\t" \
00320 RESTOREARGS_##nr \
00321 : "=a" (resultvar) \
00322 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
00323 if (resultvar >= 0xfffff001) \
00324 { \
00325 errno= (-resultvar); \
00326 resultvar = 0xffffffff; \
00327 } \
00328 (int) resultvar; })
00329
00330 #define LOADARGS_0
00331 #define LOADARGS_1 \
00332 "bpushl .L__X'%k2, %k2\n\t" \
00333 "bmovl .L__X'%k2, %k2\n\t"
00334 #define LOADARGS_2 LOADARGS_1
00335 #define LOADARGS_3 LOADARGS_1
00336 #define LOADARGS_4 LOADARGS_1
00337 #define LOADARGS_5 LOADARGS_1
00338
00339 #define RESTOREARGS_0
00340 #define RESTOREARGS_1 \
00341 "bpopl .L__X'%k2, %k2\n\t"
00342 #define RESTOREARGS_2 RESTOREARGS_1
00343 #define RESTOREARGS_3 RESTOREARGS_1
00344 #define RESTOREARGS_4 RESTOREARGS_1
00345 #define RESTOREARGS_5 RESTOREARGS_1
00346
00347 #define ASMFMT_0()
00348 #define ASMFMT_1(arg1) \
00349 , "acdSD" (arg1)
00350 #define ASMFMT_2(arg1, arg2) \
00351 , "adCD" (arg1), "c" (arg2)
00352 #define ASMFMT_3(arg1, arg2, arg3) \
00353 , "aCD" (arg1), "c" (arg2), "d" (arg3)
00354 #define ASMFMT_4(arg1, arg2, arg3, arg4) \
00355 , "aD" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
00356 #define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
00357 , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
00358
00359 #endif
00360
00361 #endif
00362 #ifdef __x86_64__
00363 #if 1
00364
00365
00366
00367
00368 #undef SYS_ify
00369 #define SYS_ify(syscall_name) __NR_##syscall_name
00370
00371
00372
00373
00374 #if !defined __NR_pread && defined __NR_pread64
00375 # define __NR_pread __NR_pread64
00376 #endif
00377 #if !defined __NR_pwrite && defined __NR_pwrite64
00378 # define __NR_pwrite __NR_pwrite64
00379 #endif
00380
00381
00382
00383 #ifndef __NR_semtimedop
00384 # define __NR_semtimedop 220
00385 #endif
00386
00387
00388 #ifdef __ASSEMBLER__
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403 #ifdef PIC
00404 # define SYSCALL_ERROR_LABEL 0f
00405 #else
00406 # define SYSCALL_ERROR_LABEL syscall_error
00407 #endif
00408
00409 #undef PSEUDO
00410 #define PSEUDO(name, syscall_name, args) \
00411 .text; \
00412 ENTRY (name) \
00413 DO_CALL (syscall_name, args); \
00414 cmpq _-4095, %rax; \
00415 jae SYSCALL_ERROR_LABEL; \
00416 L(pseudo_end):
00417
00418 #undef PSEUDO_END
00419 #define PSEUDO_END(name) \
00420 SYSCALL_ERROR_HANDLER \
00421 END (name)
00422
00423 #undef PSEUDO_NOERRNO
00424 #define PSEUDO_NOERRNO(name, syscall_name, args) \
00425 .text; \
00426 ENTRY (name) \
00427 DO_CALL (syscall_name, args)
00428
00429 #undef PSEUDO_END_NOERRNO
00430 #define PSEUDO_END_NOERRNO(name) \
00431 END (name)
00432
00433 #define ret_NOERRNO ret
00434
00435 #undef PSEUDO_ERRVAL
00436 #define PSEUDO_ERRVAL(name, syscall_name, args) \
00437 .text; \
00438 ENTRY (name) \
00439 DO_CALL (syscall_name, args); \
00440 negq %rax
00441
00442 #undef PSEUDO_END_ERRVAL
00443 #define PSEUDO_END_ERRVAL(name) \
00444 END (name)
00445
00446 #define ret_ERRVAL ret
00447
00448 #ifndef PIC
00449 #define SYSCALL_ERROR_HANDLER
00450 #elif RTLD_PRIVATE_ERRNO
00451 # define SYSCALL_ERROR_HANDLER \
00452 0: \
00453 leaq errno(%rip), %rcx; \
00454 xorq %rdx, %rdx; \
00455 subq %rax, %rdx; \
00456 movl %edx, (%rcx); \
00457 orq _-1, %rax; \
00458 jmp L(pseudo_end);
00459 #elif USE___THREAD
00460 # ifndef NOT_IN_libc
00461 # define SYSCALL_ERROR_ERRNO __libc_errno
00462 # else
00463 # define SYSCALL_ERROR_ERRNO errno
00464 # endif
00465 # define SYSCALL_ERROR_HANDLER \
00466 0: \
00467 movq SYSCALL_ERROR_ERRNO@GOTTPOFF(%rip), %rcx;\
00468 xorq %rdx, %rdx; \
00469 subq %rax, %rdx; \
00470 movl %edx, %fs:(%rcx); \
00471 orq _-1, %rax; \
00472 jmp L(pseudo_end);
00473 #elif defined _LIBC_REENTRANT
00474
00475
00476 # define SYSCALL_ERROR_HANDLER \
00477 0: \
00478 xorq %rdx, %rdx; \
00479 subq %rax, %rdx; \
00480 pushq %rdx; \
00481 cfi_adjust_cfa_offset(8); \
00482 PUSH_ERRNO_LOCATION_RETURN; \
00483 call BP_SYM (__errno_location)@PLT; \
00484 POP_ERRNO_LOCATION_RETURN; \
00485 popq %rdx; \
00486 cfi_adjust_cfa_offset(-8); \
00487 movl %edx, (%rax); \
00488 orq _-1, %rax; \
00489 jmp L(pseudo_end);
00490
00491
00492
00493 #else
00494 # define SYSCALL_ERROR_HANDLER \
00495 0:movq errno@GOTPCREL(%RIP), %rcx; \
00496 xorq %rdx, %rdx; \
00497 subq %rax, %rdx; \
00498 movl %edx, (%rcx); \
00499 orq _-1, %rax; \
00500 jmp L(pseudo_end);
00501 #endif
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540 #undef DO_CALL
00541 #define DO_CALL(syscall_name, args) \
00542 DOARGS_##args \
00543 movq _SYS_ify (syscall_name), %rax; \
00544 syscall;
00545
00546 #define DOARGS_0
00547 #define DOARGS_1
00548 #define DOARGS_2
00549 #define DOARGS_3
00550 #define DOARGS_4 movq %rcx, %r10;
00551 #define DOARGS_5 DOARGS_4
00552 #define DOARGS_6 DOARGS_5
00553
00554 #else
00555
00556
00557 #undef INLINE_SYSCALL
00558 #define INLINE_SYSCALL(name, nr, args...) \
00559 ({ \
00560 unsigned long resultvar = INTERNAL_SYSCALL (name, , nr, args); \
00561 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
00562 { \
00563 __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
00564 resultvar = (unsigned long) -1; \
00565 } \
00566 (long) resultvar; })
00567
00568 #undef INTERNAL_SYSCALL_DECL
00569 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
00570
00571 #undef INLINE_SYSCALL
00572 #undef INTERNAL_SYSCALL
00573 #define INLINE_SYSCALL(name, nr, args...) \
00574 ({ \
00575 unsigned long resultvar; \
00576 LOAD_ARGS_##nr (args) \
00577 asm volatile ( \
00578 "movq %1, %%rax\n\t" \
00579 "int _0x81\n\t" \
00580 : "=a" (resultvar) \
00581 : "i" (__NR_##name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
00582 (long) resultvar; })
00583
00584 #define INLINE_SYSCALL1(name, nr, args...) \
00585 ({ \
00586 unsigned long resultvar; \
00587 LOAD_ARGS_##nr (args) \
00588 asm volatile ( \
00589 "movq %1, %%rax\n\t" \
00590 "int _0x82\n\t" \
00591 : "=a" (resultvar) \
00592 : "i" (__NR_##name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
00593 (long) resultvar; })
00594
00595 #define INLINE_SYSCALL3(name, nr, args...) \
00596 ({ \
00597 unsigned long resultvar; \
00598 LOAD_ARGS_##nr (args) \
00599 asm volatile ( \
00600 "movq %1, %%rax\n\t" \
00601 "int _0x84\n\t" \
00602 : "=a" (resultvar) \
00603 : "i" (__NR_##name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx"); \
00604 (long) resultvar; })
00605
00606 #undef INTERNAL_SYSCALL_ERROR_P
00607 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
00608 ((unsigned long) (val) >= -4095L)
00609
00610 #undef INTERNAL_SYSCALL_ERRNO
00611 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
00612
00613 #define LOAD_ARGS_0()
00614 #define ASM_ARGS_0
00615
00616 #define LOAD_ARGS_1(a1) \
00617 register long int _a1 asm ("rdi") = (long) (a1); \
00618 LOAD_ARGS_0 ()
00619 #define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
00620
00621 #define LOAD_ARGS_2(a1, a2) \
00622 register long int _a2 asm ("rsi") = (long) (a2); \
00623 LOAD_ARGS_1 (a1)
00624 #define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
00625
00626 #define LOAD_ARGS_3(a1, a2, a3) \
00627 register long int _a3 asm ("rdx") = (long) (a3); \
00628 LOAD_ARGS_2 (a1, a2)
00629 #define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
00630
00631 #define LOAD_ARGS_4(a1, a2, a3, a4) \
00632 register long int _a4 asm ("r10") = (long) (a4); \
00633 LOAD_ARGS_3 (a1, a2, a3)
00634 #define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
00635
00636 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
00637 register long int _a5 asm ("r8") = (long) (a5); \
00638 LOAD_ARGS_4 (a1, a2, a3, a4)
00639 #define ASM_ARGS_5 ASM_ARGS_4, "r" (_a5)
00640
00641 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
00642 register long int _a6 asm ("r9") = (long) (a6); \
00643 LOAD_ARGS_5 (a1, a2, a3, a4, a5)
00644 #define ASM_ARGS_6 ASM_ARGS_5, "r" (_a6)
00645
00646 #endif
00647 #else
00648
00649
00650
00651
00652 #undef SYS_ify
00653 #define SYS_ify(syscall_name) __NR_##syscall_name
00654
00655
00656 #undef L
00657 #define L(name) .L##name
00658
00659 #ifdef __ASSEMBLER__
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674 #ifdef PIC
00675 # define SYSCALL_ERROR_LABEL 0f
00676 #else
00677 # define SYSCALL_ERROR_LABEL syscall_error
00678 #endif
00679
00680 #undef PSEUDO
00681 #define PSEUDO(name, syscall_name, args) \
00682 .text; \
00683 ENTRY (name) \
00684 DO_CALL (args, syscall_name); \
00685 cmpq _-4095, %rax; \
00686 jae SYSCALL_ERROR_LABEL; \
00687 L(pseudo_end):
00688
00689 #undef PSEUDO_END
00690 #define PSEUDO_END(name) \
00691 SYSCALL_ERROR_HANDLER \
00692 END (name)
00693
00694 #ifndef PIC
00695 #define SYSCALL_ERROR_HANDLER
00696 #else
00697
00698 #ifdef _LIBC_REENTRANT
00699 #define SYSCALL_ERROR_HANDLER \
00700 0:pushq %rbx; \
00701 call 1f; \
00702 1:popq %rbx; \
00703 xorq %rdx, %rdx; \
00704 addq __GLOBAL_OFFSET_TABLE_+[.-1b], %rbx; \
00705 subq %rax, %rdx; \
00706 pushq %rdx; \
00707 PUSH_ERRNO_LOCATION_RETURN; \
00708 call BP_SYM (__errno_location)@PLT; \
00709 POP_ERRNO_LOCATION_RETURN; \
00710 popq %rcx; \
00711 popq %rbx; \
00712 movq %rcx, (%rax); \
00713 orq _-1, %rax; \
00714 jmp L(pseudo_end);
00715
00716
00717 #else
00718 #define SYSCALL_ERROR_HANDLER \
00719 0:call 1f; \
00720 1:popq %rcx; \
00721 xorq %rdx, %rdx; \
00722 addq __GLOBAL_OFFSET_TABLE_+[.-1b], %rcx; \
00723 subq %rax, %rdx; \
00724 movq errno@GOT(%rcx), %rcx; \
00725 movq %rdx, (%rcx); \
00726 orq _-1, %rax; \
00727 jmp L(pseudo_end);
00728 #endif
00729 #endif
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775 #undef DO_CALL
00776 #define DO_CALL(args, syscall_name) \
00777 PUSHARGS_##args \
00778 DOARGS_##args \
00779 movq _SYS_ify (syscall_name), %rax; \
00780 int _0x81 \
00781 POPARGS_##args
00782
00783 #define PUSHARGS_0
00784 #define DOARGS_0
00785 #define POPARGS_0
00786 #define _PUSHARGS_0
00787 #define _DOARGS_0(n)
00788 #define _POPARGS_0
00789
00790 #define PUSHARGS_1 movq %rbx, %rdx; PUSHARGS_0
00791 #define DOARGS_1 _DOARGS_1 (4)
00792 #define POPARGS_1 POPARGS_0; movq %rdx, %rbx
00793 #define _PUSHARGS_1 pushq %rbx; _PUSHARGS_0
00794 #define _DOARGS_1(n) movq n(%rsp), %rbx; _DOARGS_0(n-4)
00795 #define _POPARGS_1 _POPARGS_0; popq %rbx
00796
00797 #define PUSHARGS_2 PUSHARGS_1
00798 #define DOARGS_2 _DOARGS_2 (8)
00799 #define POPARGS_2 POPARGS_1
00800 #define _PUSHARGS_2 _PUSHARGS_1
00801 #define _DOARGS_2(n) movq n(%rsp), %rcx; _DOARGS_1 (n-4)
00802 #define _POPARGS_2 _POPARGS_1
00803
00804 #define PUSHARGS_3 _PUSHARGS_2
00805 #define DOARGS_3 _DOARGS_3 (16)
00806 #define POPARGS_3 _POPARGS_3
00807 #define _PUSHARGS_3 _PUSHARGS_2
00808 #define _DOARGS_3(n) movq n(%rsp), %rdx; _DOARGS_2 (n-4)
00809 #define _POPARGS_3 _POPARGS_2
00810
00811 #define PUSHARGS_4 _PUSHARGS_4
00812 #define DOARGS_4 _DOARGS_4 (24)
00813 #define POPARGS_4 _POPARGS_4
00814 #define _PUSHARGS_4 pushq %rsi; _PUSHARGS_3
00815 #define _DOARGS_4(n) movq n(%rsp), %rsi; _DOARGS_3 (n-4)
00816 #define _POPARGS_4 _POPARGS_3; popq %rsi
00817
00818 #define PUSHARGS_5 _PUSHARGS_5
00819 #define DOARGS_5 _DOARGS_5 (32)
00820 #define POPARGS_5 _POPARGS_5
00821 #define _PUSHARGS_5 pushq %rdi; _PUSHARGS_4
00822 #define _DOARGS_5(n) movq n(%rsp), %rdi; _DOARGS_4 (n-4)
00823 #define _POPARGS_5 _POPARGS_4; popq %rdi
00824
00825 #else
00826
00827
00828
00829 asm (".L__X'%rbx = 1\n\t"
00830 ".L__X'%rcx = 2\n\t"
00831 ".L__X'%rdx = 2\n\t"
00832 ".L__X'%rax = 3\n\t"
00833 ".L__X'%rsi = 3\n\t"
00834 ".L__X'%rdi = 3\n\t"
00835 ".L__X'%rbp = 3\n\t"
00836 ".L__X'%rsp = 3\n\t"
00837 #if 0
00838 ".L__X'%ebx = .L__X'%rbx\n\t"
00839 ".L__X'%ecx = .L__X'%rcx\n\t"
00840 ".L__X'%edx = .L__X'%rdx\n\t"
00841 ".L__X'%eax = .L__X'%rax\n\t"
00842 ".L__X'%esi = .L__X'%rsi\n\t"
00843 ".L__X'%edi = .L__X'%rdi\n\t"
00844 ".L__X'%ebp = .L__X'%rbp\n\t"
00845 ".L__X'%esp = .L__X'%rsp\n\t"
00846 #endif
00847 ".macro bpushq name reg\n\t"
00848 ".if 1 - \\name\n\t"
00849 ".if 2 - \\name\n\t"
00850 "pushq %rbx\n\t"
00851 ".else\n\t"
00852 "xchgq \\reg, %rbx\n\t"
00853 ".endif\n\t"
00854 ".endif\n\t"
00855 ".endm\n\t"
00856 ".macro bpopq name reg\n\t"
00857 ".if 1 - \\name\n\t"
00858 ".if 2 - \\name\n\t"
00859 "popq %rbx\n\t"
00860 ".else\n\t"
00861 "xchgq \\reg, %rbx\n\t"
00862 ".endif\n\t"
00863 ".endif\n\t"
00864 ".endm\n\t"
00865 ".macro bmovq name reg\n\t"
00866 ".if 1 - \\name\n\t"
00867 ".if 2 - \\name\n\t"
00868 "movq \\reg, %rbx\n\t"
00869 ".endif\n\t"
00870 ".endif\n\t"
00871 ".endm\n\t");
00872
00873 extern int errno;
00874
00875
00876
00877 #undef INLINE_SYSCALL
00878 #define INLINE_SYSCALL(name, nr, args...) \
00879 ({ \
00880 unsigned int resultvar; \
00881 asm volatile ( \
00882 LOADARGS_##nr \
00883 "movq %1, %%rax\n\t" \
00884 "int _0x81\n\t" \
00885 RESTOREARGS_##nr \
00886 : "=a" (resultvar) \
00887 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
00888 if (resultvar >= 0xfffff001) \
00889 { \
00890 errno= (-resultvar); \
00891 resultvar = 0xffffffff; \
00892 } \
00893 (int) resultvar; })
00894
00895 #undef INLINE_SYSCALL1
00896 #define INLINE_SYSCALL1(name, nr, args...) \
00897 ({ \
00898 unsigned int resultvar; \
00899 asm volatile ( \
00900 LOADARGS_##nr \
00901 "movq %1, %%rax\n\t" \
00902 "int _0x82\n\t" \
00903 RESTOREARGS_##nr \
00904 : "=a" (resultvar) \
00905 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
00906 if (resultvar >= 0xfffff001) \
00907 { \
00908 errno= (-resultvar); \
00909 resultvar = 0xffffffff; \
00910 } \
00911 (int) resultvar; })
00912
00913 #undef INLINE_SYSCALL3
00914 #define INLINE_SYSCALL3(name, nr, args...) \
00915 ({ \
00916 unsigned int resultvar; \
00917 asm volatile ( \
00918 LOADARGS_##nr \
00919 "movq %1, %%rax\n\t" \
00920 "int _0x84\n\t" \
00921 RESTOREARGS_##nr \
00922 : "=a" (resultvar) \
00923 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
00924 if (resultvar >= 0xfffff001) \
00925 { \
00926 errno= (-resultvar); \
00927 resultvar = 0xffffffff; \
00928 } \
00929 (int) resultvar; })
00930
00931 #undef INLINE_SYSCALLTEST
00932 #define INLINE_SYSCALLTEST(name, nr, args...) \
00933 ({ \
00934 unsigned int resultvar; \
00935 asm volatile ( \
00936 LOADARGS_##nr \
00937 "movq %1, %%rax\n\t" \
00938 "call 0xc0100010\n\t" \
00939 RESTOREARGS_##nr \
00940 : "=a" (resultvar) \
00941 : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc"); \
00942 if (resultvar >= 0xfffff001) \
00943 { \
00944 errno= (-resultvar); \
00945 resultvar = 0xffffffff; \
00946 } \
00947 (int) resultvar; })
00948
00949 #define LOADARGS_0
00950 #define LOADARGS_1 \
00951 "bpushq .L__X'%k2, %k2\n\t" \
00952 "bmovq .L__X'%k2, %k2\n\t"
00953 #define LOADARGS_2 LOADARGS_1
00954 #define LOADARGS_3 LOADARGS_1
00955 #define LOADARGS_4 LOADARGS_1
00956 #define LOADARGS_5 LOADARGS_1
00957
00958 #define RESTOREARGS_0
00959 #define RESTOREARGS_1 \
00960 "bpopq .L__X'%k2, %k2\n\t"
00961 #define RESTOREARGS_2 RESTOREARGS_1
00962 #define RESTOREARGS_3 RESTOREARGS_1
00963 #define RESTOREARGS_4 RESTOREARGS_1
00964 #define RESTOREARGS_5 RESTOREARGS_1
00965
00966 #define ASMFMT_0()
00967 #define ASMFMT_1(arg1) \
00968 , "acdSD" (arg1)
00969 #define ASMFMT_2(arg1, arg2) \
00970 , "adCD" (arg1), "c" (arg2)
00971 #define ASMFMT_3(arg1, arg2, arg3) \
00972 , "aCD" (arg1), "c" (arg2), "d" (arg3)
00973 #define ASMFMT_4(arg1, arg2, arg3, arg4) \
00974 , "aD" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
00975 #define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
00976 , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
00977
00978 #endif
00979 #endif
00980 #endif
00981 #endif
00982 #endif
00983