sysdep.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. //#include <sysdeps/generic/sysdep.h>
  2. #ifdef __ASSEMBLER__
  3. /* Define an entry point visible from C. */
  4. #ifdef PIC
  5. #define ENTRY(name) \
  6. .pic \
  7. .align 2; \
  8. .globl C_SYMBOL_NAME(name); \
  9. .func C_SYMBOL_NAME(name); \
  10. .type C_SYMBOL_NAME(name), @function; \
  11. C_SYMBOL_NAME(name):
  12. #else
  13. #define ENTRY(name) \
  14. .align 2; \
  15. .globl C_SYMBOL_NAME(name); \
  16. .func C_SYMBOL_NAME(name); \
  17. .type C_SYMBOL_NAME(name), @function; \
  18. C_SYMBOL_NAME(name):
  19. #endif
  20. #undef END
  21. #define END(name) \
  22. .endfunc; \
  23. .size C_SYMBOL_NAME(name), .-C_SYMBOL_NAME(name)
  24. /* If compiled for profiling, call `mcount' at the start of each function. */
  25. #ifdef HAVE_ELF
  26. #undef NO_UNDERSCORES
  27. #define NO_UNDERSCORES
  28. #endif
  29. #ifdef NO_UNDERSCORES
  30. #define syscall_error __syscall_error
  31. #endif
  32. #define SYS_ify(syscall_name) (__NR_##syscall_name)
  33. #define __do_syscall(syscall_name) \
  34. syscall SYS_ify(syscall_name);
  35. #define SYSCALL_ERROR_HANDLER
  36. #define SYSCALL_ERROR __syscall_error
  37. #ifdef PIC
  38. #ifdef __NDS32_N1213_43U1H__
  39. #ifdef NDS_ABI_V0
  40. #define PSEUDO(name, syscall_name, args) \
  41. .pic; \
  42. .align 2; \
  43. 1: ret; \
  44. 99: addi $r0, $lp, 0; \
  45. jal 1b; \
  46. sethi $r1, hi20(_GLOBAL_OFFSET_TABLE_); \
  47. ori $r1, $r1, lo12(_GLOBAL_OFFSET_TABLE_+4); \
  48. add $r1, $lp, $r1; \
  49. addi $lp, $r0, 0; \
  50. sethi $r15, hi20(SYSCALL_ERROR@PLT); \
  51. ori $r15, $r15, lo12(SYSCALL_ERROR@PLT); \
  52. add $r15, $r15, $r1; \
  53. jr $r15; \
  54. nop; \
  55. ENTRY(name); \
  56. __do_syscall(syscall_name); \
  57. bgez $r5, 2f; \
  58. sltsi $r0, $r5, -4096; \
  59. beqz $r0, 99b; \
  60. 2:
  61. #else
  62. #define PSEUDO(name, syscall_name, args) \
  63. .pic; \
  64. .align 2; \
  65. 1: ret; \
  66. 99: addi $r2, $lp, 0; \
  67. jal 1b; \
  68. sethi $r1, hi20(_GLOBAL_OFFSET_TABLE_); \
  69. ori $r1, $r1, lo12(_GLOBAL_OFFSET_TABLE_+4); \
  70. add $r1, $lp, $r1; \
  71. addi $lp, $r2, 0; \
  72. sethi $r15, hi20(SYSCALL_ERROR@PLT); \
  73. ori $r15, $r15, lo12(SYSCALL_ERROR@PLT); \
  74. add $r15, $r15, $r1; \
  75. jr $r15; \
  76. nop; \
  77. ENTRY(name); \
  78. __do_syscall(syscall_name); \
  79. bgez $r0, 2f; \
  80. sltsi $r1, $r0, -4096; \
  81. beqz $r1, 99b; \
  82. 2:
  83. #endif
  84. #else
  85. #define PSEUDO(name, syscall_name, args) \
  86. .pic; \
  87. .align 2; \
  88. 99: mfusr $r15, $PC; \
  89. sethi $r1, hi20(_GLOBAL_OFFSET_TABLE_ + 4); \
  90. ori $r1, $r1, lo12(_GLOBAL_OFFSET_TABLE_ + 8); \
  91. add $r1, $r15, $r1; \
  92. sethi $r15, hi20(SYSCALL_ERROR@PLT); \
  93. ori $r15, $r15, lo12(SYSCALL_ERROR@PLT); \
  94. add $r15, $r15, $r1; \
  95. jr $r15; \
  96. nop; \
  97. ENTRY(name); \
  98. __do_syscall(syscall_name); \
  99. bgez $r0, 2f; \
  100. sltsi $r1, $r0, -4096; \
  101. beqz $r1, 99b; \
  102. 2:
  103. #endif
  104. #else
  105. #ifdef OLD2_ABI
  106. #define PSEUDO(name, syscall_name, args) \
  107. .align 2; \
  108. 99: j SYSCALL_ERROR; \
  109. nop; \
  110. ENTRY(name); \
  111. __do_syscall(syscall_name); \
  112. bgez $r5, 2f; \
  113. sltsi $r0, $r5, -4096; \
  114. beqz $r0, 99b; \
  115. 2:
  116. #else
  117. #define PSEUDO(name, syscall_name, args) \
  118. .align 2; \
  119. 99: j SYSCALL_ERROR; \
  120. nop; \
  121. ENTRY(name); \
  122. __do_syscall(syscall_name); \
  123. bgez $r0, 2f; \
  124. sltsi $r1, $r0, -4096; \
  125. beqz $r1, 99b; \
  126. 2:
  127. #endif
  128. #endif
  129. #define PSEUDO_NOERRNO(name, syscall_name, args) \
  130. ENTRY(name); \
  131. __do_syscall(syscall_name);
  132. #undef PSEUDO_END
  133. #define PSEUDO_END(sym) \
  134. SYSCALL_ERROR_HANDLER \
  135. END(sym)
  136. #undef PSEUDO_END_ERRVAL
  137. #define PSEUDO_END_ERRVAL(sym) END(sym)
  138. #define PSEUDO_ERRVAL(name, syscall_name, args) PSEUDO_NOERRNO(name, syscall_name, args)
  139. #define ret_ERRVAL ret
  140. #define ret_NOERRNO ret
  141. #if defined NOT_IN_libc
  142. #define SYSCALL_ERROR __local_syscall_error
  143. #ifdef PIC
  144. #ifdef __NDS32_N1213_43U1H__
  145. #ifdef NDS_ABI_V0
  146. #define SYSCALL_ERROR_HANDLER \
  147. __local_syscall_error: pushm $gp, $lp, $sp; \
  148. jal 1f; \
  149. sethi $gp, hi20(_GLOBAL_OFFSET_TABLE_); \
  150. ori $gp, $gp, lo12(_GLOBAL_OFFSET_TABLE_+4); \
  151. add $gp, $gp, $lp; \
  152. neg $r5, $r5; \
  153. push $r5; \
  154. addi $sp, $sp, -28; \
  155. bal C_SYMBOL_NAME(__errno_location@PLT); \
  156. addi $sp, $sp, 28; \
  157. pop $r1; \
  158. swi $r1, [$r5]; \
  159. li $r5, -1; \
  160. popm $gp, $lp, $sp; \
  161. 1: ret;
  162. #else
  163. #define SYSCALL_ERROR_HANDLER \
  164. __local_syscall_error: pushm $gp, $lp, $sp; \
  165. jal 1f; \
  166. sethi $gp, hi20(_GLOBAL_OFFSET_TABLE_); \
  167. ori $gp, $gp, lo12(_GLOBAL_OFFSET_TABLE_+4); \
  168. add $gp, $gp, $lp; \
  169. neg $r0, $r0; \
  170. push $r0; \
  171. #if defined(NDS32_ABI_2) || defined(NDS32_ABI_2FP) \
  172. addi $sp, $sp, -4; \
  173. #else \
  174. addi $sp, $sp, -28; \
  175. #endif \
  176. bal C_SYMBOL_NAME(__errno_location@PLT); \
  177. #if defined(NDS32_ABI_2) || defined(NDS32_ABI_2FP) \
  178. addi $sp, $sp, 4; \
  179. #else \
  180. addi $sp, $sp, 28; \
  181. #endif \
  182. pop $r1; \
  183. swi $r1, [$r0]; \
  184. li $r0, -1; \
  185. popm $gp, $lp, $sp; \
  186. 1: ret;
  187. #endif
  188. #else
  189. #define SYSCALL_ERROR_HANDLER \
  190. __local_syscall_error: pushm $gp, $lp, $sp; \
  191. mfusr $r15, $PC; \
  192. sethi $gp, hi20(_GLOBAL_OFFSET_TABLE_+4); \
  193. ori $gp, $gp, lo12(_GLOBAL_OFFSET_TABLE_+8); \
  194. add $gp, $gp, $r15; \
  195. neg $r0, $r0; \
  196. push $r0; \
  197. #if defined(NDS32_ABI_2) || defined(NDS32_ABI_2FP) \
  198. addi $sp, $sp, -4; \
  199. #else \
  200. addi $sp, $sp, -28; \
  201. #endif \
  202. bal C_SYMBOL_NAME(__errno_location@PLT); \
  203. #if defined(NDS32_ABI_2) || defined(NDS32_ABI_2FP) \
  204. addi $sp, $sp, 4; \
  205. #else \
  206. addi $sp, $sp, 28; \
  207. #endif \
  208. pop $r1; \
  209. swi $r1, [$r0]; \
  210. li $r0, -1; \
  211. popm $gp, $lp, $sp; \
  212. 1: ret;
  213. #endif
  214. #else
  215. #ifdef NDS_ABI_V0
  216. #define SYSCALL_ERROR_HANDLER \
  217. __local_syscall_error: push $lp; \
  218. neg $r5, $r5; \
  219. push $r5; \
  220. addi $sp, $sp, -28; \
  221. bal C_SYMBOL_NAME(__errno_location); \
  222. addi $sp, $sp, 28; \
  223. pop $r1; \
  224. swi $r1, [$r5]; \
  225. li $r5, -1; \
  226. pop $lp; \
  227. ret;
  228. #else
  229. #define SYSCALL_ERROR_HANDLER \
  230. __local_syscall_error: push $lp; \
  231. neg $r0, $r0; \
  232. push $r0; \
  233. #if defined(NDS32_ABI_2) || defined(NDS32_ABI_2FP) \
  234. addi $sp, $sp, -4; \
  235. #else \
  236. addi $sp, $sp, -28; \
  237. #endif \
  238. bal C_SYMBOL_NAME(__errno_location); \
  239. #if defined(NDS32_ABI_2) || defined(NDS32_ABI_2FP) \
  240. addi $sp, $sp, 4; \
  241. #else \
  242. addi $sp, $sp, 28; \
  243. #endif \
  244. pop $r1; \
  245. swi $r1, [$r0]; \
  246. li $r0, -1; \
  247. pop $lp; \
  248. ret;
  249. #endif
  250. #endif
  251. #else
  252. #define SYSCALL_ERROR_HANDLER
  253. #define SYSCALL_ERROR __syscall_error
  254. #endif
  255. #endif /* __ASSEMBLER__ */