syscalls.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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.
  13. * We 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__ (
  19. ".L__X'%ebx = 1\n\t"
  20. ".L__X'%ecx = 2\n\t"
  21. ".L__X'%edx = 2\n\t"
  22. ".L__X'%eax = 3\n\t"
  23. ".L__X'%esi = 3\n\t"
  24. ".L__X'%edi = 3\n\t"
  25. ".L__X'%ebp = 3\n\t"
  26. ".L__X'%esp = 3\n\t"
  27. ".ifndef _BITS_SYSCALLS_ASM\n\t"
  28. ".set _BITS_SYSCALLS_ASM,1\n\t"
  29. /* Loading param #1 (ebx) is done by loading it into
  30. * another register, and then performing bpushl+bmovl,
  31. * since we must preserve ebx */
  32. ".macro bpushl name reg\n\t"
  33. ".if 1 - \\name\n\t" /* if reg!=ebx... */
  34. ".if 2 - \\name\n\t" /* if reg can't be clobbered... */
  35. "pushl %ebx\n\t" /* save ebx on stack */
  36. ".else\n\t"
  37. "xchgl \\reg, %ebx\n\t" /* else save ebx in reg, and load reg to ebx */
  38. ".endif\n\t"
  39. ".endif\n\t"
  40. ".endm\n\t"
  41. ".macro bmovl name reg\n\t"
  42. ".if 1 - \\name\n\t"
  43. ".if 2 - \\name\n\t" /* if reg can't be clobbered... */
  44. "movl \\reg, %ebx\n\t" /* load reg to ebx */
  45. ".endif\n\t"
  46. ".endif\n\t"
  47. ".endm\n\t"
  48. ".endif\n\t" /* _BITS_SYSCALLS_ASM */
  49. ".macro bpopl name reg\n\t"
  50. ".if 1 - \\name\n\t"
  51. ".if 2 - \\name\n\t" /* if reg can't be clobbered... */
  52. "popl %ebx\n\t" /* restore ebx from stack */
  53. ".else\n\t"
  54. "xchgl \\reg, %ebx\n\t" /* else restore ebx from reg */
  55. ".endif\n\t"
  56. ".endif\n\t"
  57. ".endm\n\t"
  58. );
  59. #else
  60. __asm__ (
  61. ".L__X'%ebx = 1\n\t"
  62. ".L__X'%ecx = 2\n\t"
  63. ".L__X'%edx = 2\n\t"
  64. ".L__X'%eax = 3\n\t"
  65. ".L__X'%esi = 3\n\t"
  66. ".L__X'%edi = 3\n\t"
  67. ".L__X'%ebp = 3\n\t"
  68. ".L__X'%esp = 3\n\t"
  69. ".macro bpushl name reg\n\t"
  70. ".if 1 - \\name\n\t"
  71. ".if 2 - \\name\n\t"
  72. "pushl %ebx\n\t"
  73. ".else\n\t"
  74. "xchgl \\reg, %ebx\n\t"
  75. ".endif\n\t"
  76. ".endif\n\t"
  77. ".endm\n\t"
  78. ".macro bmovl name reg\n\t"
  79. ".if 1 - \\name\n\t"
  80. ".if 2 - \\name\n\t"
  81. "movl \\reg, %ebx\n\t"
  82. ".endif\n\t"
  83. ".endif\n\t"
  84. ".endm\n\t"
  85. ".macro bpopl name reg\n\t"
  86. ".if 1 - \\name\n\t"
  87. ".if 2 - \\name\n\t"
  88. "popl %ebx\n\t"
  89. ".else\n\t"
  90. "xchgl \\reg, %ebx\n\t"
  91. ".endif\n\t"
  92. ".endif\n\t"
  93. ".endm\n\t"
  94. );
  95. #endif
  96. #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
  97. ({ \
  98. register unsigned int resultvar; \
  99. __asm__ __volatile__ ( \
  100. LOADARGS_##nr \
  101. "movl %1, %%eax\n\t" \
  102. "int $0x80\n\t" \
  103. RESTOREARGS_##nr \
  104. : "=a" (resultvar) \
  105. : "i" (name) ASMFMT_##nr(args) : "memory", "cc" \
  106. ); \
  107. (int) resultvar; \
  108. })
  109. #define LOADARGS_0
  110. #define LOADARGS_1 "bpushl .L__X'%k2, %k2\n\t" "bmovl .L__X'%k2, %k2\n\t"
  111. #define LOADARGS_2 LOADARGS_1
  112. #define LOADARGS_3 LOADARGS_1
  113. #define LOADARGS_4 LOADARGS_1
  114. #define LOADARGS_5 LOADARGS_1
  115. #define LOADARGS_6 LOADARGS_1 "push %%ebp\n\t" "movl %7, %%ebp\n\t"
  116. #define RESTOREARGS_0
  117. #define RESTOREARGS_1 "bpopl .L__X'%k2, %k2\n\t"
  118. #define RESTOREARGS_2 RESTOREARGS_1
  119. #define RESTOREARGS_3 RESTOREARGS_1
  120. #define RESTOREARGS_4 RESTOREARGS_1
  121. #define RESTOREARGS_5 RESTOREARGS_1
  122. #define RESTOREARGS_6 "pop %%ebp\n\t" RESTOREARGS_1
  123. #define ASMFMT_0()
  124. #define ASMFMT_1(arg1) \
  125. , "acdSD" (arg1)
  126. #define ASMFMT_2(arg1, arg2) \
  127. , "adSD" (arg1), "c" (arg2)
  128. #define ASMFMT_3(arg1, arg2, arg3) \
  129. , "aSD" (arg1), "c" (arg2), "d" (arg3)
  130. #define ASMFMT_4(arg1, arg2, arg3, arg4) \
  131. , "aD" (arg1), "c" (arg2), "d" (arg3), "S" (arg4)
  132. #define ASMFMT_5(arg1, arg2, arg3, arg4, arg5) \
  133. , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5)
  134. #define ASMFMT_6(arg1, arg2, arg3, arg4, arg5, arg6) \
  135. , "a" (arg1), "c" (arg2), "d" (arg3), "S" (arg4), "D" (arg5), "m" (arg6)
  136. #endif /* __ASSEMBLER__ */
  137. #endif /* _BITS_SYSCALLS_H */