syscalls.h 4.2 KB

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