ld_syscalls.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * This file contains the system call macros and syscall
  3. * numbers used by the shared library loader.
  4. */
  5. #define __NR_SYSCALL_BASE 0x900000
  6. #define __NR_exit (__NR_SYSCALL_BASE+ 1)
  7. #define __NR_read (__NR_SYSCALL_BASE+ 3)
  8. #define __NR_write (__NR_SYSCALL_BASE+ 4)
  9. #define __NR_open (__NR_SYSCALL_BASE+ 5)
  10. #define __NR_close (__NR_SYSCALL_BASE+ 6)
  11. #define __NR_getuid (__NR_SYSCALL_BASE+ 24)
  12. #define __NR_geteuid (__NR_SYSCALL_BASE+ 49)
  13. #define __NR_getgid (__NR_SYSCALL_BASE+ 47)
  14. #define __NR_getegid (__NR_SYSCALL_BASE+ 50)
  15. #define __NR_readlink (__NR_SYSCALL_BASE+ 85)
  16. #define __NR_mmap (__NR_SYSCALL_BASE+ 90)
  17. #define __NR_munmap (__NR_SYSCALL_BASE+ 91)
  18. #define __NR_stat (__NR_SYSCALL_BASE+106)
  19. #define __NR_mprotect (__NR_SYSCALL_BASE+125)
  20. /* Here are the macros which define how this platform makes
  21. * system calls. This particular variant does _not_ set
  22. * errno (note how it is disabled in __syscall_return) since
  23. * these will get called before the errno symbol is dynamicly
  24. * linked. */
  25. /* These are Erik's versions of the syscall routines. His were
  26. * cleaner than mine, so I adopted them instead with some
  27. * reformating. Shane Nay.
  28. */
  29. #define __sys2(x) #x
  30. #define __sys1(x) __sys2(x)
  31. #ifndef __syscall
  32. #define __syscall(name) "swi\t" __sys1(__NR_##name) "\n\t"
  33. #endif
  34. #undef __syscall_return
  35. #define __syscall_return(type, res) \
  36. do { \
  37. if ((unsigned long)(res) >= (unsigned long)(-125)) { \
  38. /*errno = -(res);*/ \
  39. res = -1; \
  40. } \
  41. return (type) (res); \
  42. } while (0)
  43. #define _syscall0(type,name) \
  44. type name(void) { \
  45. long __res; \
  46. __asm__ __volatile__ ( \
  47. __syscall(name) \
  48. "mov %0,r0" \
  49. :"=r" (__res) : : "r0","lr"); \
  50. __syscall_return(type,__res); \
  51. }
  52. #define _syscall1(type,name,type1,arg1) \
  53. type name(type1 arg1) { \
  54. long __res; \
  55. __asm__ __volatile__ ( \
  56. "mov\tr0,%1\n\t" \
  57. __syscall(name) \
  58. "mov %0,r0" \
  59. : "=r" (__res) \
  60. : "r" ((long)(arg1)) \
  61. : "r0","lr"); \
  62. __syscall_return(type,__res); \
  63. }
  64. #define _syscall2(type,name,type1,arg1,type2,arg2) \
  65. type name(type1 arg1,type2 arg2) { \
  66. long __res; \
  67. __asm__ __volatile__ ( \
  68. "mov\tr0,%1\n\t" \
  69. "mov\tr1,%2\n\t" \
  70. __syscall(name) \
  71. "mov\t%0,r0" \
  72. : "=r" (__res) \
  73. : "r" ((long)(arg1)),"r" ((long)(arg2)) \
  74. : "r0","r1","lr"); \
  75. __syscall_return(type,__res); \
  76. }
  77. #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \
  78. type name(type1 arg1,type2 arg2,type3 arg3) { \
  79. long __res; \
  80. __asm__ __volatile__ ( \
  81. "mov\tr0,%1\n\t" \
  82. "mov\tr1,%2\n\t" \
  83. "mov\tr2,%3\n\t" \
  84. __syscall(name) \
  85. "mov\t%0,r0" \
  86. : "=r" (__res) \
  87. : "r" ((long)(arg1)),"r" ((long)(arg2)),"r" ((long)(arg3)) \
  88. : "r0","r1","r2","lr"); \
  89. __syscall_return(type,__res); \
  90. }
  91. #undef _syscall4
  92. #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)\
  93. type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4) { \
  94. long __res; \
  95. __asm__ __volatile__ ( \
  96. "mov\tr0,%1\n\t" \
  97. "mov\tr1,%2\n\t" \
  98. "mov\tr2,%3\n\t" \
  99. "mov\tr3,%4\n\t" \
  100. __syscall(name) \
  101. "mov\t%0,r0" \
  102. : "=r" (__res) \
  103. : "r" ((long)(arg1)),"r" ((long)(arg2)), \
  104. "r" ((long)(arg3)),"r" ((long)(arg4)) \
  105. : "r0","r1","r2","r3","lr"); \
  106. __syscall_return(type,__res); \
  107. }