sysdep.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* Copyright (C) 1992,1993,1995,1996,1997,1998,1999,2000,2002,2003,2004
  2. Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>, August 1995.
  5. Changed by Kaz Kojima, <kkojima@rr.iij4u.or.jp>.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with the GNU C Library; if not, write to the Free
  16. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  17. 02111-1307 USA. */
  18. #ifndef _LINUX_SH_SYSDEP_H
  19. #define _LINUX_SH_SYSDEP_H 1
  20. /* There is some commonality. */
  21. #include <sysdeps/unix/sh/sysdep.h>
  22. /* For Linux we can use the system call table in the header file
  23. /usr/include/asm/unistd.h
  24. of the kernel. But these symbols do not follow the SYS_* syntax
  25. so we have to redefine the `SYS_ify' macro here. */
  26. #undef SYS_ify
  27. #define SYS_ify(syscall_name) (__NR_##syscall_name)
  28. #ifdef __ASSEMBLER__
  29. /* Linux uses a negative return value to indicate syscall errors,
  30. unlike most Unices, which use the condition codes' carry flag.
  31. Since version 2.1 the return value of a system call might be
  32. negative even if the call succeeded. E.g., the `lseek' system call
  33. might return a large offset. Therefore we must not anymore test
  34. for < 0, but test for a real error by making sure the value in R0
  35. is a real error number. Linus said he will make sure the no syscall
  36. returns a value in -1 .. -4095 as a valid result so we can savely
  37. test with -4095. */
  38. #define _IMM1 #-1
  39. #define _IMM12 #-12
  40. #undef PSEUDO
  41. #define PSEUDO(name, syscall_name, args) \
  42. .text; \
  43. ENTRY (name); \
  44. DO_CALL (syscall_name, args); \
  45. mov r0,r1; \
  46. mov _IMM12,r2; \
  47. shad r2,r1; \
  48. not r1,r1; \
  49. tst r1,r1; \
  50. bf .Lpseudo_end; \
  51. SYSCALL_ERROR_HANDLER; \
  52. .Lpseudo_end:
  53. #undef PSEUDO_END
  54. #define PSEUDO_END(name) \
  55. END (name)
  56. #undef PSEUDO_NOERRNO
  57. #define PSEUDO_NOERRNO(name, syscall_name, args) \
  58. .text; \
  59. ENTRY (name); \
  60. DO_CALL (syscall_name, args)
  61. #undef PSEUDO_END_NOERRNO
  62. #define PSEUDO_END_NOERRNO(name) \
  63. END (name)
  64. #define ret_NOERRNO ret
  65. #define PSEUDO_ERRVAL(name, syscall_name, args) \
  66. .text; \
  67. ENTRY (name); \
  68. DO_CALL (syscall_name, args);
  69. #undef PSEUDO_END_ERRVAL
  70. #define PSEUDO_END_ERRVAL(name) \
  71. END (name)
  72. #define ret_ERRVAL ret
  73. #ifndef PIC
  74. # define SYSCALL_ERROR_HANDLER \
  75. mov.l 0f,r1; \
  76. jmp @r1; \
  77. mov r0,r4; \
  78. .align 2; \
  79. 0: .long __syscall_error
  80. #include <libc/sysdeps/linux/sh/syscall_error.S>
  81. #else
  82. # ifdef RTLD_PRIVATE_ERRNO
  83. # define SYSCALL_ERROR_HANDLER \
  84. neg r0,r1; \
  85. mov.l 0f,r12; \
  86. mova 0f,r0; \
  87. add r0,r12; \
  88. mov.l 1f,r0; \
  89. mov.l r1,@(r0,r12)
  90. bra .Lpseudo_end; \
  91. mov _IMM1,r0; \
  92. .align 2; \
  93. 0: .long _GLOBAL_OFFSET_TABLE_; \
  94. 1: .long rtld_errno@GOTOFF
  95. # elif defined _LIBC_REENTRANT
  96. # if USE___THREAD
  97. # ifndef NOT_IN_libc
  98. # define SYSCALL_ERROR_ERRNO __libc_errno
  99. # else
  100. # define SYSCALL_ERROR_ERRNO errno
  101. # endif
  102. # define SYSCALL_ERROR_HANDLER \
  103. neg r0,r1; \
  104. mov r12,r2; \
  105. mov.l 0f,r12; \
  106. mova 0f,r0; \
  107. add r0,r12; \
  108. mov.l 1f,r0; \
  109. stc gbr, r4; \
  110. mov.l @(r0,r12),r0; \
  111. bra .Lskip; \
  112. add r4,r0; \
  113. .align 2; \
  114. 1: .long SYSCALL_ERROR_ERRNO@GOTTPOFF; \
  115. .Lskip: \
  116. mov r2,r12; \
  117. mov.l r1,@r0; \
  118. bra .Lpseudo_end; \
  119. mov _IMM1,r0; \
  120. .align 2; \
  121. 0: .long _GLOBAL_OFFSET_TABLE_
  122. # else
  123. # define SYSCALL_ERROR_HANDLER \
  124. neg r0,r1; \
  125. mov.l r14,@-r15; \
  126. mov.l r12,@-r15; \
  127. mov.l r1,@-r15; \
  128. mov.l 0f,r12; \
  129. mova 0f,r0; \
  130. add r0,r12; \
  131. sts.l pr,@-r15; \
  132. mov r15,r14; \
  133. mov.l 1f,r1; \
  134. bsrf r1; \
  135. nop; \
  136. 2: mov r14,r15; \
  137. lds.l @r15+,pr; \
  138. mov.l @r15+,r1; \
  139. mov.l r1,@r0; \
  140. mov.l @r15+,r12; \
  141. mov.l @r15+,r14; \
  142. bra .Lpseudo_end; \
  143. mov _IMM1,r0; \
  144. .align 2; \
  145. 0: .long _GLOBAL_OFFSET_TABLE_; \
  146. 1: .long PLTJMP(C_SYMBOL_NAME(__errno_location))-(2b-.)
  147. /* A quick note: it is assumed that the call to `__errno_location' does
  148. not modify the stack! */
  149. # endif
  150. # else
  151. /* Store (-r0) into errno through the GOT. */
  152. # define SYSCALL_ERROR_HANDLER \
  153. neg r0,r1; \
  154. mov r12,r2; \
  155. mov.l 0f,r12; \
  156. mova 0f,r0; \
  157. add r0,r12; \
  158. mov.l 1f,r0; \
  159. mov.l @(r0,r12),r0; \
  160. mov r2,r12; \
  161. mov.l r1,@r0; \
  162. bra .Lpseudo_end; \
  163. mov _IMM1,r0; \
  164. .align 2; \
  165. 0: .long _GLOBAL_OFFSET_TABLE_; \
  166. 1: .long errno@GOT
  167. # endif /* _LIBC_REENTRANT */
  168. #endif /* PIC */
  169. # ifdef NEED_SYSCALL_INST_PAD
  170. # define SYSCALL_INST_PAD \
  171. or r0,r0; or r0,r0; or r0,r0; or r0,r0; or r0,r0
  172. # else
  173. # define SYSCALL_INST_PAD
  174. # endif
  175. #define SYSCALL_INST0 trapa #0x10
  176. #define SYSCALL_INST1 trapa #0x11
  177. #define SYSCALL_INST2 trapa #0x12
  178. #define SYSCALL_INST3 trapa #0x13
  179. #define SYSCALL_INST4 trapa #0x14
  180. #define SYSCALL_INST5 mov.l @(0,r15),r0; trapa #0x15
  181. #define SYSCALL_INST6 mov.l @(0,r15),r0; mov.l @(4,r15),r1; trapa #0x16
  182. #undef DO_CALL
  183. #define DO_CALL(syscall_name, args) \
  184. mov.l 1f,r3; \
  185. SYSCALL_INST##args; \
  186. SYSCALL_INST_PAD; \
  187. bra 2f; \
  188. nop; \
  189. .align 2; \
  190. 1: .long SYS_ify (syscall_name); \
  191. 2:
  192. #endif /* __ASSEMBLER__ */
  193. #endif /* linux/sh/sysdep.h */