syscalls.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. /* This includes the `__NR_<name>' syscall numbers taken from the Linux kernel
  11. * header files. It also defines the traditional `SYS_<name>' macros for older
  12. * programs. */
  13. #include <bits/sysnum.h>
  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. register long __res __asm__("er0"); \
  29. __asm__ __volatile__ ("mov.l %1,er0\n\t" \
  30. "trapa #0\n\t" \
  31. : "=r" (__res) \
  32. : "ir" (__NR_##name) \
  33. : "cc"); \
  34. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  35. errno = -__res; \
  36. __res = -1; \
  37. } \
  38. return (type)__res; \
  39. }
  40. #define _syscall1(type, name, atype, a) \
  41. type name(atype a) \
  42. { \
  43. register long __res __asm__("er0"); \
  44. __asm__ __volatile__ ("mov.l %2, er1\n\t" \
  45. "mov.l %1, er0\n\t" \
  46. "trapa #0\n\t" \
  47. : "=r" (__res) \
  48. : "ir" (__NR_##name), \
  49. "g" ((long)a) \
  50. : "cc", "er1"); \
  51. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  52. errno = -__res; \
  53. __res = -1; \
  54. } \
  55. return (type)__res; \
  56. }
  57. #define _syscall2(type, name, atype, a, btype, b) \
  58. type name(atype a, btype b) \
  59. { \
  60. register long __res __asm__("er0"); \
  61. __asm__ __volatile__ ("mov.l %3, er2\n\t" \
  62. "mov.l %2, er1\n\t" \
  63. "mov.l %1, er0\n\t" \
  64. "trapa #0\n\t" \
  65. : "=r" (__res) \
  66. : "ir" (__NR_##name), \
  67. "g" ((long)a), \
  68. "g" ((long)b) \
  69. : "cc", "er1", "er2"); \
  70. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  71. errno = -__res; \
  72. __res = -1; \
  73. } \
  74. return (type)__res; \
  75. }
  76. #define _syscall3(type, name, atype, a, btype, b, ctype, c) \
  77. type name(atype a, btype b, ctype c) \
  78. { \
  79. register long __res __asm__("er0"); \
  80. __asm__ __volatile__ ("mov.l %4, er3\n\t" \
  81. "mov.l %3, er2\n\t" \
  82. "mov.l %2, er1\n\t" \
  83. "mov.l %1, er0\n\t" \
  84. "trapa #0\n\t" \
  85. : "=r" (__res) \
  86. : "ir" (__NR_##name), \
  87. "g" ((long)a), \
  88. "g" ((long)b), \
  89. "g" ((long)c) \
  90. : "cc", "er1", "er2", "er3"); \
  91. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  92. errno = -__res; \
  93. __res = -1; \
  94. } \
  95. return (type)__res; \
  96. }
  97. #define _syscall4(type, name, atype, a, btype, b, ctype, c, dtype, d) \
  98. type name(atype a, btype b, ctype c, dtype d) \
  99. { \
  100. register long __res __asm__("er0"); \
  101. __asm__ __volatile__ ("mov.l %5, er4\n\t" \
  102. "mov.l %4, er3\n\t" \
  103. "mov.l %3, er2\n\t" \
  104. "mov.l %2, er1\n\t" \
  105. "mov.l %1, er0\n\t" \
  106. "trapa #0\n\t" \
  107. : "=r" (__res) \
  108. : "ir" (__NR_##name), \
  109. "g" ((long)a), \
  110. "g" ((long)b), \
  111. "g" ((long)c), \
  112. "g" ((long)d) \
  113. : "cc", "er1", "er2", "er3", "er4"); \
  114. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  115. errno = -__res; \
  116. __res = -1; \
  117. } \
  118. return (type)__res; \
  119. }
  120. #define _syscall5(type, name, atype, a, btype, b, ctype, c, dtype, d, etype, e) \
  121. type name(atype a, btype b, ctype c, dtype d, etype e) \
  122. { \
  123. register long __res __asm__("er0"); \
  124. __asm__ __volatile__ ( \
  125. "mov.l er5,@-sp\n\t" \
  126. "mov.l %5, er4\n\t" \
  127. "mov.l %4, er3\n\t" \
  128. "mov.l %3, er2\n\t" \
  129. "mov.l %2, er1\n\t" \
  130. "mov.l %1, er0\n\t" \
  131. "mov.l %6, er5\n\t" \
  132. "trapa #0\n\t" \
  133. "mov.l @sp+,er5\n\t" \
  134. : "=r" (__res) \
  135. : "ir" (__NR_##name), \
  136. "g" ((long)a), \
  137. "g" ((long)b), \
  138. "g" ((long)c), \
  139. "g" ((long)d), \
  140. "m" ((long)e) \
  141. : "cc", "er1", "er2", "er3", "er4"); \
  142. if ((unsigned long)(__res) >= (unsigned long)(-125)) { \
  143. errno = -__res; \
  144. __res = -1; \
  145. } \
  146. return (type)__res; \
  147. }