ld_syscalls.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include <asm/unistd.h>
  2. #undef __syscall_return
  3. #undef _syscall0
  4. #undef _syscall1
  5. #undef _syscall2
  6. #undef _syscall3
  7. #undef _syscall4
  8. #undef _syscall5
  9. /* Here are the macros which define how this platform makes
  10. * system calls. This particular variant does _not_ set
  11. * errno (note how it is disabled in __syscall_return) since
  12. * these will get called before the errno symbol is dynamicly
  13. * linked. */
  14. #define __syscall_return(type, res) \
  15. do { \
  16. if ((unsigned long)(res) >= (unsigned long)(-125)) { \
  17. /* avoid using res which is declared to be in register d0; \
  18. errno might expand to a function call and clobber it. */ \
  19. /* int __err = -(res); \
  20. errno = __err; */ \
  21. res = -1; \
  22. } \
  23. return (type) (res); \
  24. } while (0)
  25. #define _syscall0(type, name) \
  26. type name(void) \
  27. { \
  28. long __res; \
  29. __asm__ __volatile__ ("movel %1, %%d0\n\t" \
  30. "trap #0\n\t" \
  31. "movel %%d0, %0" \
  32. : "=g" (__res) \
  33. : "i" (__NR_##name) \
  34. : "cc", "%d0"); \
  35. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  36. /* errno = -__res; */ \
  37. __res = -1; \
  38. } \
  39. return (type)__res; \
  40. }
  41. #define _syscall1(type, name, atype, a) \
  42. type name(atype a) \
  43. { \
  44. long __res; \
  45. __asm__ __volatile__ ("movel %2, %%d1\n\t" \
  46. "movel %1, %%d0\n\t" \
  47. "trap #0\n\t" \
  48. "movel %%d0, %0" \
  49. : "=g" (__res) \
  50. : "i" (__NR_##name), \
  51. "g" ((long)a) \
  52. : "cc", "%d0", "%d1"); \
  53. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  54. /* errno = -__res; */ \
  55. __res = -1; \
  56. } \
  57. return (type)__res; \
  58. }
  59. #define _syscall2(type, name, atype, a, btype, b) \
  60. type name(atype a, btype b) \
  61. { \
  62. long __res; \
  63. __asm__ __volatile__ ("movel %3, %%d2\n\t" \
  64. "movel %2, %%d1\n\t" \
  65. "movel %1, %%d0\n\t" \
  66. "trap #0\n\t" \
  67. "movel %%d0, %0" \
  68. : "=g" (__res) \
  69. : "i" (__NR_##name), \
  70. "a" ((long)a), \
  71. "g" ((long)b) \
  72. : "cc", "%d0", "%d1", "%d2"); \
  73. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  74. /* errno = -__res; */ \
  75. __res = -1; \
  76. } \
  77. return (type)__res; \
  78. }
  79. #define _syscall3(type, name, atype, a, btype, b, ctype, c) \
  80. type name(atype a, btype b, ctype c) \
  81. { \
  82. long __res; \
  83. __asm__ __volatile__ ("movel %4, %%d3\n\t" \
  84. "movel %3, %%d2\n\t" \
  85. "movel %2, %%d1\n\t" \
  86. "movel %1, %%d0\n\t" \
  87. "trap #0\n\t" \
  88. "movel %%d0, %0" \
  89. : "=g" (__res) \
  90. : "i" (__NR_##name), \
  91. "a" ((long)a), \
  92. "a" ((long)b), \
  93. "g" ((long)c) \
  94. : "cc", "%d0", "%d1", "%d2", "%d3"); \
  95. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  96. /* errno = -__res; */ \
  97. __res = -1; \
  98. } \
  99. return (type)__res; \
  100. }
  101. #define _syscall4(type, name, atype, a, btype, b, ctype, c, dtype, d) \
  102. type name(atype a, btype b, ctype c, dtype d) \
  103. { \
  104. long __res; \
  105. __asm__ __volatile__ ("movel %5, %%d4\n\t" \
  106. "movel %4, %%d3\n\t" \
  107. "movel %3, %%d2\n\t" \
  108. "movel %2, %%d1\n\t" \
  109. "movel %1, %%d0\n\t" \
  110. "trap #0\n\t" \
  111. "movel %%d0, %0" \
  112. : "=g" (__res) \
  113. : "i" (__NR_##name), \
  114. "a" ((long)a), \
  115. "a" ((long)b), \
  116. "a" ((long)c), \
  117. "g" ((long)d) \
  118. : "cc", "%d0", "%d1", "%d2", "%d3", \
  119. "%d4"); \
  120. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  121. /* errno = -__res; */ \
  122. __res = -1; \
  123. } \
  124. return (type)__res; \
  125. }
  126. #define _syscall5(type, name, atype, a, btype, b, ctype, c, dtype, d, etype, e)\
  127. type name(atype a, btype b, ctype c, dtype d, etype e) \
  128. { \
  129. long __res; \
  130. __asm__ __volatile__ ("movel %6, %%d5\n\t" \
  131. "movel %5, %%d4\n\t" \
  132. "movel %4, %%d3\n\t" \
  133. "movel %3, %%d2\n\t" \
  134. "movel %2, %%d1\n\t" \
  135. "movel %1, %%d0\n\t" \
  136. "trap #0\n\t" \
  137. "movel %%d0, %0" \
  138. : "=g" (__res) \
  139. : "i" (__NR_##name), \
  140. "a" ((long)a), \
  141. "a" ((long)b), \
  142. "a" ((long)c), \
  143. "a" ((long)d), \
  144. "g" ((long)e) \
  145. : "cc", "%d0", "%d1", "%d2", "%d3", \
  146. "%d4", "%d5"); \
  147. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  148. /* errno = -__res; */ \
  149. __res = -1; \
  150. } \
  151. return (type)__res; \
  152. }