sysdep.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /* Assembler macros for SH.
  2. Copyright (C) 1999, 2000, 2005 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <common/sysdep.h>
  16. #include <features.h>
  17. #ifdef __ASSEMBLER__
  18. /* Syntactic details of assembler. */
  19. #define LOCAL(X) .L_##X
  20. #define ALIGNARG(log2) log2
  21. /* For ELF we need the `.type' directive to make shared libs work right. */
  22. #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,@##typearg;
  23. #define ASM_SIZE_DIRECTIVE(name) .size name,.-name
  24. #ifdef SHARED
  25. #define PLTJMP(_x) _x##@PLT
  26. #else
  27. #define PLTJMP(_x) _x
  28. #endif
  29. /* Define an entry point visible from C. */
  30. #define ENTRY(name) \
  31. .globl C_SYMBOL_NAME(name); \
  32. ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),function) \
  33. .align ALIGNARG(5); \
  34. C_LABEL(name) \
  35. cfi_startproc;
  36. #undef END
  37. #define END(name) \
  38. cfi_endproc; \
  39. ASM_SIZE_DIRECTIVE(C_SYMBOL_NAME(name))
  40. #ifdef __UCLIBC_UNDERSCORES__
  41. /* Since C identifiers are not normally prefixed with an underscore
  42. on this system, the asm identifier `syscall_error' intrudes on the
  43. C name space. Make sure we use an innocuous name. */
  44. #define syscall_error __syscall_error
  45. #define mcount _mcount
  46. #endif
  47. /* For Linux we can use the system call table in the header file
  48. /usr/include/asm/unistd.h
  49. of the kernel. But these symbols do not follow the SYS_* syntax
  50. so we have to redefine the `SYS_ify' macro here. */
  51. #undef SYS_ify
  52. #define SYS_ify(syscall_name) (__NR_##syscall_name)
  53. #define ret rts ; nop
  54. /* The sh move insn is s, d. */
  55. #define MOVE(x,y) mov x , y
  56. /* Linux uses a negative return value to indicate syscall errors,
  57. unlike most Unices, which use the condition codes' carry flag.
  58. Since version 2.1 the return value of a system call might be
  59. negative even if the call succeeded. E.g., the `lseek' system call
  60. might return a large offset. Therefore we must not anymore test
  61. for < 0, but test for a real error by making sure the value in R0
  62. is a real error number. Linus said he will make sure the no syscall
  63. returns a value in -1 .. -4095 as a valid result so we can savely
  64. test with -4095. */
  65. #define _IMM1 #-1
  66. #define _IMM12 #-12
  67. #undef PSEUDO
  68. #define PSEUDO(name, syscall_name, args) \
  69. .text; \
  70. ENTRY (name); \
  71. DO_CALL (syscall_name, args); \
  72. mov r0,r1; \
  73. mov _IMM12,r2; \
  74. shad r2,r1; \
  75. not r1,r1; \
  76. tst r1,r1; \
  77. bf .Lpseudo_end; \
  78. SYSCALL_ERROR_HANDLER; \
  79. .Lpseudo_end:
  80. #undef PSEUDO_END
  81. #define PSEUDO_END(name) \
  82. END (name)
  83. #undef PSEUDO_NOERRNO
  84. #define PSEUDO_NOERRNO(name, syscall_name, args) \
  85. .text; \
  86. ENTRY (name); \
  87. DO_CALL (syscall_name, args)
  88. #undef PSEUDO_END_NOERRNO
  89. #define PSEUDO_END_NOERRNO(name) \
  90. END (name)
  91. #define ret_NOERRNO ret
  92. #define PSEUDO_ERRVAL(name, syscall_name, args) \
  93. .text; \
  94. ENTRY (name); \
  95. DO_CALL (syscall_name, args);
  96. #undef PSEUDO_END_ERRVAL
  97. #define PSEUDO_END_ERRVAL(name) \
  98. END (name)
  99. #ifndef __PIC__
  100. # define SYSCALL_ERROR_HANDLER \
  101. mov.l 0f,r1; \
  102. jmp @r1; \
  103. mov r0,r4; \
  104. .align 2; \
  105. 0: .long __syscall_error
  106. #include <libc/sysdeps/linux/sh/syscall_error.S>
  107. #else
  108. # ifdef RTLD_PRIVATE_ERRNO
  109. # define SYSCALL_ERROR_HANDLER \
  110. neg r0,r1; \
  111. mov.l 0f,r12; \
  112. mova 0f,r0; \
  113. add r0,r12; \
  114. mov.l 1f,r0; \
  115. mov.l r1,@(r0,r12)
  116. bra .Lpseudo_end; \
  117. mov _IMM1,r0; \
  118. .align 2; \
  119. 0: .long _GLOBAL_OFFSET_TABLE_; \
  120. 1: .long rtld_errno@GOTOFF
  121. # elif defined _LIBC_REENTRANT
  122. # if defined USE___THREAD
  123. # ifndef NOT_IN_libc
  124. # define SYSCALL_ERROR_ERRNO __libc_errno
  125. # else
  126. # define SYSCALL_ERROR_ERRNO errno
  127. # endif
  128. # define SYSCALL_ERROR_HANDLER \
  129. neg r0,r1; \
  130. mov r12,r2; \
  131. mov.l 0f,r12; \
  132. mova 0f,r0; \
  133. add r0,r12; \
  134. mov.l 1f,r0; \
  135. stc gbr, r4; \
  136. mov.l @(r0,r12),r0; \
  137. bra .Lskip; \
  138. add r4,r0; \
  139. .align 2; \
  140. 1: .long SYSCALL_ERROR_ERRNO@GOTTPOFF; \
  141. .Lskip: \
  142. mov r2,r12; \
  143. mov.l r1,@r0; \
  144. bra .Lpseudo_end; \
  145. mov _IMM1,r0; \
  146. .align 2; \
  147. 0: .long _GLOBAL_OFFSET_TABLE_
  148. # else
  149. # define SYSCALL_ERROR_HANDLER \
  150. neg r0,r1; \
  151. mov.l r14,@-r15; \
  152. mov.l r12,@-r15; \
  153. mov.l r1,@-r15; \
  154. mov.l 0f,r12; \
  155. mova 0f,r0; \
  156. add r0,r12; \
  157. sts.l pr,@-r15; \
  158. mov r15,r14; \
  159. mov.l 1f,r1; \
  160. bsrf r1; \
  161. nop; \
  162. 2: mov r14,r15; \
  163. lds.l @r15+,pr; \
  164. mov.l @r15+,r1; \
  165. mov.l r1,@r0; \
  166. mov.l @r15+,r12; \
  167. mov.l @r15+,r14; \
  168. bra .Lpseudo_end; \
  169. mov _IMM1,r0; \
  170. .align 2; \
  171. 0: .long _GLOBAL_OFFSET_TABLE_; \
  172. 1: .long PLTJMP(C_SYMBOL_NAME(__errno_location))-(2b-.)
  173. /* A quick note: it is assumed that the call to `__errno_location' does
  174. not modify the stack! */
  175. # endif
  176. # else
  177. /* Store (-r0) into errno through the GOT. */
  178. # define SYSCALL_ERROR_HANDLER \
  179. neg r0,r1; \
  180. mov r12,r2; \
  181. mov.l 0f,r12; \
  182. mova 0f,r0; \
  183. add r0,r12; \
  184. mov.l 1f,r0; \
  185. mov.l @(r0,r12),r0; \
  186. mov r2,r12; \
  187. mov.l r1,@r0; \
  188. bra .Lpseudo_end; \
  189. mov _IMM1,r0; \
  190. .align 2; \
  191. 0: .long _GLOBAL_OFFSET_TABLE_; \
  192. 1: .long errno@GOT
  193. # endif /* _LIBC_REENTRANT */
  194. #endif /* __PIC__ */
  195. # ifdef __SH4__
  196. # define SYSCALL_INST_PAD \
  197. or r0,r0; or r0,r0; or r0,r0; or r0,r0; or r0,r0
  198. # else
  199. # define SYSCALL_INST_PAD
  200. # endif
  201. #define SYSCALL_INST0 trapa #0x10
  202. #define SYSCALL_INST1 trapa #0x11
  203. #define SYSCALL_INST2 trapa #0x12
  204. #define SYSCALL_INST3 trapa #0x13
  205. #define SYSCALL_INST4 trapa #0x14
  206. #define SYSCALL_INST5 mov.l @(0,r15),r0; trapa #0x15
  207. #define SYSCALL_INST6 mov.l @(0,r15),r0; mov.l @(4,r15),r1; trapa #0x16
  208. #undef DO_CALL
  209. #define DO_CALL(syscall_name, args) \
  210. mov.l 1f,r3; \
  211. SYSCALL_INST##args; \
  212. SYSCALL_INST_PAD; \
  213. bra 2f; \
  214. nop; \
  215. .align 2; \
  216. 1: .long SYS_ify (syscall_name); \
  217. 2:
  218. #endif /* __ASSEMBLER__ */