sysdep.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. # if defined _LIBC_REENTRANT
  109. # if defined USE___THREAD
  110. # define SYSCALL_ERROR_ERRNO errno
  111. # define SYSCALL_ERROR_HANDLER \
  112. neg r0,r1; \
  113. mov r12,r2; \
  114. mov.l 0f,r12; \
  115. mova 0f,r0; \
  116. add r0,r12; \
  117. mov.l 1f,r0; \
  118. stc gbr, r4; \
  119. mov.l @(r0,r12),r0; \
  120. bra .Lskip; \
  121. add r4,r0; \
  122. .align 2; \
  123. 1: .long SYSCALL_ERROR_ERRNO@GOTTPOFF; \
  124. .Lskip: \
  125. mov r2,r12; \
  126. mov.l r1,@r0; \
  127. bra .Lpseudo_end; \
  128. mov _IMM1,r0; \
  129. .align 2; \
  130. 0: .long _GLOBAL_OFFSET_TABLE_
  131. # else
  132. # define SYSCALL_ERROR_HANDLER \
  133. neg r0,r1; \
  134. mov.l r14,@-r15; \
  135. mov.l r12,@-r15; \
  136. mov.l r1,@-r15; \
  137. mov.l 0f,r12; \
  138. mova 0f,r0; \
  139. add r0,r12; \
  140. sts.l pr,@-r15; \
  141. mov r15,r14; \
  142. mov.l 1f,r1; \
  143. bsrf r1; \
  144. nop; \
  145. 2: mov r14,r15; \
  146. lds.l @r15+,pr; \
  147. mov.l @r15+,r1; \
  148. mov.l r1,@r0; \
  149. mov.l @r15+,r12; \
  150. mov.l @r15+,r14; \
  151. bra .Lpseudo_end; \
  152. mov _IMM1,r0; \
  153. .align 2; \
  154. 0: .long _GLOBAL_OFFSET_TABLE_; \
  155. 1: .long PLTJMP(C_SYMBOL_NAME(__errno_location))-(2b-.)
  156. /* A quick note: it is assumed that the call to `__errno_location' does
  157. not modify the stack! */
  158. # endif
  159. # else
  160. /* Store (-r0) into errno through the GOT. */
  161. # define SYSCALL_ERROR_HANDLER \
  162. neg r0,r1; \
  163. mov r12,r2; \
  164. mov.l 0f,r12; \
  165. mova 0f,r0; \
  166. add r0,r12; \
  167. mov.l 1f,r0; \
  168. mov.l @(r0,r12),r0; \
  169. mov r2,r12; \
  170. mov.l r1,@r0; \
  171. bra .Lpseudo_end; \
  172. mov _IMM1,r0; \
  173. .align 2; \
  174. 0: .long _GLOBAL_OFFSET_TABLE_; \
  175. 1: .long errno@GOT
  176. # endif /* _LIBC_REENTRANT */
  177. #endif /* __PIC__ */
  178. # ifdef __SH4__
  179. # define SYSCALL_INST_PAD \
  180. or r0,r0; or r0,r0; or r0,r0; or r0,r0; or r0,r0
  181. # else
  182. # define SYSCALL_INST_PAD
  183. # endif
  184. #define SYSCALL_INST0 trapa #0x10
  185. #define SYSCALL_INST1 trapa #0x11
  186. #define SYSCALL_INST2 trapa #0x12
  187. #define SYSCALL_INST3 trapa #0x13
  188. #define SYSCALL_INST4 trapa #0x14
  189. #define SYSCALL_INST5 mov.l @(0,r15),r0; trapa #0x15
  190. #define SYSCALL_INST6 mov.l @(0,r15),r0; mov.l @(4,r15),r1; trapa #0x16
  191. #undef DO_CALL
  192. #define DO_CALL(syscall_name, args) \
  193. mov.l 1f,r3; \
  194. SYSCALL_INST##args; \
  195. SYSCALL_INST_PAD; \
  196. bra 2f; \
  197. nop; \
  198. .align 2; \
  199. 1: .long SYS_ify (syscall_name); \
  200. 2:
  201. #endif /* __ASSEMBLER__ */