syscalls.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #include <features.h>
  7. // TODO -- Add support for __UCLIBC_USE_UNIFIED_SYSCALL__
  8. #define __sys2(x) #x
  9. #define __sys1(x) __sys2(x)
  10. #ifndef __syscall
  11. #define __syscall(name) "swi\t" __sys1(__NR_##name) "\n\t"
  12. #endif
  13. #define __syscall_return(type, res) \
  14. do { \
  15. if ((unsigned long)(res) >= (unsigned long)(-125)) { \
  16. errno = -(res); \
  17. res = -1; \
  18. } \
  19. return (type) (res); \
  20. } while (0)
  21. #define _syscall0(type,name) \
  22. type name(void) { \
  23. long __res; \
  24. __asm__ __volatile__ ( \
  25. __syscall(name) \
  26. "mov %0,r0" \
  27. :"=r" (__res) : : "r0","lr"); \
  28. __syscall_return(type,__res); \
  29. }
  30. #define _syscall1(type,name,type1,arg1) \
  31. type name(type1 arg1) { \
  32. long __res; \
  33. __asm__ __volatile__ ( \
  34. "mov\tr0,%1\n\t" \
  35. __syscall(name) \
  36. "mov %0,r0" \
  37. : "=r" (__res) \
  38. : "r" ((long)(arg1)) \
  39. : "r0","lr"); \
  40. __syscall_return(type,__res); \
  41. }
  42. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  43. type name(type1 arg1,type2 arg2) { \
  44. long __res; \
  45. __asm__ __volatile__ ( \
  46. "mov\tr0,%1\n\t" \
  47. "mov\tr1,%2\n\t" \
  48. __syscall(name) \
  49. "mov\t%0,r0" \
  50. : "=r" (__res) \
  51. : "r" ((long)(arg1)),"r" ((long)(arg2)) \
  52. : "r0","r1","lr"); \
  53. __syscall_return(type,__res); \
  54. }
  55. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  56. type name(type1 arg1,type2 arg2,type3 arg3) { \
  57. long __res; \
  58. __asm__ __volatile__ ( \
  59. "mov\tr0,%1\n\t" \
  60. "mov\tr1,%2\n\t" \
  61. "mov\tr2,%3\n\t" \
  62. __syscall(name) \
  63. "mov\t%0,r0" \
  64. : "=r" (__res) \
  65. : "r" ((long)(arg1)),"r" ((long)(arg2)),"r" ((long)(arg3)) \
  66. : "r0","r1","r2","lr"); \
  67. __syscall_return(type,__res); \
  68. }
  69. #undef _syscall4
  70. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\
  71. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
  72. long __res; \
  73. __asm__ __volatile__ ( \
  74. "mov\tr0,%1\n\t" \
  75. "mov\tr1,%2\n\t" \
  76. "mov\tr2,%3\n\t" \
  77. "mov\tr3,%4\n\t" \
  78. __syscall(name) \
  79. "mov\t%0,r0" \
  80. : "=r" (__res) \
  81. : "r" ((long)(arg1)),"r" ((long)(arg2)), \
  82. "r" ((long)(arg3)),"r" ((long)(arg4)) \
  83. : "r0","r1","r2","r3","lr"); \
  84. __syscall_return(type,__res); \
  85. }
  86. #undef _syscall5
  87. #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5)\
  88. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) { \
  89. long __res; \
  90. __asm__ __volatile__ ( \
  91. "mov\tr0,%1\n\t" \
  92. "mov\tr1,%2\n\t" \
  93. "mov\tr2,%3\n\t" \
  94. "mov\tr3,%4\n\t" \
  95. "mov\tr4,%5\n\t" \
  96. __syscall(name) \
  97. "mov\t%0,r0" \
  98. : "=r" (__res) \
  99. : "r" ((long)(arg1)),"r" ((long)(arg2)), \
  100. "r" ((long)(arg3)),"r" ((long)(arg4)), \
  101. "r" ((long)(arg5)) \
  102. : "r0","r1","r2","r3","r4","lr"); \
  103. __syscall_return(type,__res); \
  104. }