syscalls.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #ifndef _BITS_SYSCALLS_H
  2. #define _BITS_SYSCALLS_H
  3. #ifndef _SYSCALL_H
  4. # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
  5. #endif
  6. /*
  7. Some of the sneaky macros in the code were taken from
  8. glibc-2.2.5/sysdeps/unix/sysv/linux/i386/sysdep.h
  9. */
  10. #ifndef __ASSEMBLER__
  11. #include <errno.h>
  12. /* We need some help from the assembler to generate optimal code. We
  13. define some macros here which later will be used. */
  14. #if defined __SUPPORT_LD_DEBUG__ && defined __DOMULTI__
  15. #error LD debugging and DOMULTI are incompatible
  16. #endif
  17. #ifdef __DOMULTI__
  18. __asm__ (".L__X'%ebx = 1\n\t"
  19. ".L__X'%ecx = 2\n\t"
  20. ".L__X'%edx = 2\n\t"
  21. ".L__X'%eax = 3\n\t"
  22. ".L__X'%esi = 3\n\t"
  23. ".L__X'%edi = 3\n\t"
  24. ".L__X'%ebp = 3\n\t"
  25. ".L__X'%esp = 3\n\t"
  26. ".ifndef _BITS_SYSCALLS_ASM\n\t"
  27. ".set _BITS_SYSCALLS_ASM,1\n\t"
  28. ".macro bpushl name reg\n\t"
  29. ".if 1 - \\name\n\t"
  30. ".if 2 - \\name\n\t"
  31. "pushl %ebx\n\t"
  32. ".else\n\t"
  33. "xchgl \\reg, %ebx\n\t"
  34. ".endif\n\t"
  35. ".endif\n\t"
  36. ".endm\n\t"
  37. ".macro bpopl name reg\n\t"
  38. ".if 1 - \\name\n\t"
  39. ".if 2 - \\name\n\t"
  40. "popl %ebx\n\t"
  41. ".else\n\t"
  42. "xchgl \\reg, %ebx\n\t"
  43. ".endif\n\t"
  44. ".endif\n\t"
  45. ".endm\n\t"
  46. ".macro bmovl name reg\n\t"
  47. ".if 1 - \\name\n\t"
  48. ".if 2 - \\name\n\t"
  49. "movl \\reg, %ebx\n\t"
  50. ".endif\n\t"
  51. ".endif\n\t"
  52. ".endm\n\t"
  53. ".endif\n\t");
  54. #else
  55. __asm__ (".L__X'%ebx = 1\n\t"
  56. ".L__X'%ecx = 2\n\t"
  57. ".L__X'%edx = 2\n\t"
  58. ".L__X'%eax = 3\n\t"
  59. ".L__X'%esi = 3\n\t"
  60. ".L__X'%edi = 3\n\t"
  61. ".L__X'%ebp = 3\n\t"
  62. ".L__X'%esp = 3\n\t"
  63. ".macro bpushl name reg\n\t"
  64. ".if 1 - \\name\n\t"
  65. ".if 2 - \\name\n\t"
  66. "pushl %ebx\n\t"
  67. ".else\n\t"
  68. "xchgl \\reg, %ebx\n\t"
  69. ".endif\n\t"
  70. ".endif\n\t"
  71. ".endm\n\t"
  72. ".macro bpopl name reg\n\t"
  73. ".if 1 - \\name\n\t"
  74. ".if 2 - \\name\n\t"
  75. "popl %ebx\n\t"
  76. ".else\n\t"
  77. "xchgl \\reg, %ebx\n\t"
  78. ".endif\n\t"
  79. ".endif\n\t"
  80. ".endm\n\t"
  81. ".macro bmovl name reg\n\t"
  82. ".if 1 - \\name\n\t"
  83. ".if 2 - \\name\n\t"
  84. "movl \\reg, %ebx\n\t"
  85. ".endif\n\t"
  86. ".endif\n\t"
  87. ".endm\n\t");
  88. #endif
  89. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  90. ({ \
  91. register unsigned int resultvar; \
  92. __asm__ __volatile__ ( \
  93. LOADARGS_##nr \
  94. "movl %1, %%eax\n\t" \
  95. "int $0x80\n\t" \
  96. RESTOREARGS_##nr \
  97. : "=a" (resultvar) \
  98. : "g" (name) ASMFMT_##nr(args) : "memory", "cc"); \
  99. (int) resultvar; })
  100. #define LOADARGS_0
  101. #define LOADARGS_1 \
  102. "bpushl .L__X'%k2, %k2\n\t" \
  103. "bmovl .L__X'%k2, %k2\n\t"
  104. #define LOADARGS_2 LOADARGS_1
  105. #define LOADARGS_3 LOADARGS_1
  106. #define LOADARGS_4 LOADARGS_1
  107. #define LOADARGS_5 LOADARGS_1
  108. #define LOADARGS_6 LOADARGS_1 "push %%ebp ; movl %7, %%ebp\n\t"
  109. #define RESTOREARGS_0
  110. #define RESTOREARGS_1 \
  111. "bpopl .L__X'%k2, %k2\n\t"
  112. #define RESTOREARGS_2 RESTOREARGS_1
  113. #define RESTOREARGS_3 RESTOREARGS_1
  114. #define RESTOREARGS_4 RESTOREARGS_1
  115. #define RESTOREARGS_5 RESTOREARGS_1
  116. #define RESTOREARGS_6 "pop %%ebp\n\t" RESTOREARGS_1
  117. #define ASMFMT_0()
  118. #define ASMFMT_1(arg1) \
  119. , "acdSD" (arg1)
  120. #define ASMFMT_2(arg1, arg2) \
  121. , "adSD" (arg1), "c" (arg2)
  122. #define ASMFMT_3(arg1, arg2, arg3) \
  123. , "aSD" (arg1), "c" (arg2), "d" (arg3)
  124. #define ASMFMT_4(arg1, arg2, arg3, arg4) \
  125. , "aD" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
  126. #define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
  127. , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
  128. #define ASMFMT_6(arg1, arg2, arg3, arg4, arg5, arg6) \
  129. , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5), "m" (arg6)
  130. #endif /* __ASSEMBLER__ */
  131. #endif /* _BITS_SYSCALLS_H */