syscalls.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* Unlike the asm/unistd.h kernel header file (which this is partly based on),
  2. * this file must be able to cope with PIC and non-PIC code. For some arches
  3. * there is no difference. For x86 (which has far too few registers) there is
  4. * a difference. Regardless, including asm/unistd.h is hereby officially
  5. * forbidden. Don't do it. It is bad for you.
  6. */
  7. #ifndef _SYSCALL_H
  8. # error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
  9. #endif
  10. #define __syscall_return(type, res) \
  11. do { \
  12. if ((unsigned long)(res) >= (unsigned long)(-125)) { \
  13. /* avoid using res which is declared to be in register d0; \
  14. errno might expand to a function call and clobber it. */ \
  15. int __err = -(res); \
  16. errno = __err; \
  17. res = -1; \
  18. } \
  19. return (type) (res); \
  20. } while (0)
  21. #define _syscall0(type, name) \
  22. type name(void) \
  23. { \
  24. register long __res __asm__("er0"); \
  25. __asm__ __volatile__ ("mov.l %1,er0\n\t" \
  26. "trapa #0\n\t" \
  27. : "=r" (__res) \
  28. : "ir" (__NR_##name) \
  29. : "cc"); \
  30. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  31. errno = -__res; \
  32. __res = -1; \
  33. } \
  34. return (type)__res; \
  35. }
  36. #define _syscall1(type, name, atype, a) \
  37. type name(atype a) \
  38. { \
  39. register long __res __asm__("er0"); \
  40. __asm__ __volatile__ ("mov.l %2, er1\n\t" \
  41. "mov.l %1, er0\n\t" \
  42. "trapa #0\n\t" \
  43. : "=r" (__res) \
  44. : "ir" (__NR_##name), \
  45. "g" ((long)a) \
  46. : "cc", "er1"); \
  47. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  48. errno = -__res; \
  49. __res = -1; \
  50. } \
  51. return (type)__res; \
  52. }
  53. #define _syscall2(type, name, atype, a, btype, b) \
  54. type name(atype a, btype b) \
  55. { \
  56. register long __res __asm__("er0"); \
  57. __asm__ __volatile__ ("mov.l %3, er2\n\t" \
  58. "mov.l %2, er1\n\t" \
  59. "mov.l %1, er0\n\t" \
  60. "trapa #0\n\t" \
  61. : "=r" (__res) \
  62. : "ir" (__NR_##name), \
  63. "g" ((long)a), \
  64. "g" ((long)b) \
  65. : "cc", "er1", "er2"); \
  66. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  67. errno = -__res; \
  68. __res = -1; \
  69. } \
  70. return (type)__res; \
  71. }
  72. #define _syscall3(type, name, atype, a, btype, b, ctype, c) \
  73. type name(atype a, btype b, ctype c) \
  74. { \
  75. register long __res __asm__("er0"); \
  76. __asm__ __volatile__ ("mov.l %4, er3\n\t" \
  77. "mov.l %3, er2\n\t" \
  78. "mov.l %2, er1\n\t" \
  79. "mov.l %1, er0\n\t" \
  80. "trapa #0\n\t" \
  81. : "=r" (__res) \
  82. : "ir" (__NR_##name), \
  83. "g" ((long)a), \
  84. "g" ((long)b), \
  85. "g" ((long)c) \
  86. : "cc", "er1", "er2", "er3"); \
  87. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  88. errno = -__res; \
  89. __res = -1; \
  90. } \
  91. return (type)__res; \
  92. }
  93. #define _syscall4(type, name, atype, a, btype, b, ctype, c, dtype, d) \
  94. type name(atype a, btype b, ctype c, dtype d) \
  95. { \
  96. register long __res __asm__("er0"); \
  97. __asm__ __volatile__ ("mov.l %5, er4\n\t" \
  98. "mov.l %4, er3\n\t" \
  99. "mov.l %3, er2\n\t" \
  100. "mov.l %2, er1\n\t" \
  101. "mov.l %1, er0\n\t" \
  102. "trapa #0\n\t" \
  103. : "=r" (__res) \
  104. : "ir" (__NR_##name), \
  105. "g" ((long)a), \
  106. "g" ((long)b), \
  107. "g" ((long)c), \
  108. "g" ((long)d) \
  109. : "cc", "er1", "er2", "er3", "er4"); \
  110. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  111. errno = -__res; \
  112. __res = -1; \
  113. } \
  114. return (type)__res; \
  115. }
  116. #define _syscall5(type, name, atype, a, btype, b, ctype, c, dtype, d, etype, e) \
  117. type name(atype a, btype b, ctype c, dtype d, etype e) \
  118. { \
  119. register long __res __asm__("er0"); \
  120. __asm__ __volatile__ ( \
  121. "mov.l er5,@-sp\n\t" \
  122. "mov.l %5, er4\n\t" \
  123. "mov.l %4, er3\n\t" \
  124. "mov.l %3, er2\n\t" \
  125. "mov.l %2, er1\n\t" \
  126. "mov.l %1, er0\n\t" \
  127. "mov.l %6, er5\n\t" \
  128. "trapa #0\n\t" \
  129. "mov.l @sp+,er5\n\t" \
  130. : "=r" (__res) \
  131. : "ir" (__NR_##name), \
  132. "g" ((long)a), \
  133. "g" ((long)b), \
  134. "g" ((long)c), \
  135. "g" ((long)d), \
  136. "m" ((long)e) \
  137. : "cc", "er1", "er2", "er3", "er4"); \
  138. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  139. errno = -__res; \
  140. __res = -1; \
  141. } \
  142. return (type)__res; \
  143. }