sysdep.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /* Assembler macros for PA-RISC.
  2. Copyright (C) 1999-2018 Free Software Foundation, Inc.
  3. Contributed by Ulrich Drepper, <drepper@cygnus.com>, August 1999.
  4. Linux/PA-RISC changes by Philipp Rumpf, <prumpf@tux.org>, March 2000.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library. If not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef _LINUX_HPPA_SYSDEP_H
  17. #define _LINUX_HPPA_SYSDEP_H 1
  18. #include <common/sysdep.h>
  19. #include <sys/syscall.h>
  20. /* In order to get __set_errno() definition in INLINE_SYSCALL. */
  21. #ifndef __ASSEMBLER__
  22. #include <errno.h>
  23. #endif
  24. #undef ASM_LINE_SEP
  25. #define ASM_LINE_SEP !
  26. #undef SYS_ify
  27. #define SYS_ify(syscall_name) (__NR_##syscall_name)
  28. /* The vfork, fork, and clone syscalls clobber r19
  29. * and r21. We list r21 as either clobbered or as an
  30. * input to a 6-argument syscall. We must save and
  31. * restore r19 in both PIC and non-PIC cases.
  32. */
  33. /* WARNING: TREG must be a callee saves register so
  34. that it doesn't have to be restored after a call
  35. to another function */
  36. #define TREG 4
  37. #define SAVE_PIC(SREG) \
  38. copy %r19, SREG
  39. #define LOAD_PIC(LREG) \
  40. copy LREG , %r19
  41. /* Inline assembly defines */
  42. #define TREG_ASM "%r4" /* Cant clobber r3, it holds framemarker */
  43. #define SAVE_ASM_PIC " copy %%r19, %" TREG_ASM "\n"
  44. #define LOAD_ASM_PIC " copy %" TREG_ASM ", %%r19\n"
  45. #define CLOB_TREG TREG_ASM ,
  46. #define PIC_REG_DEF register unsigned long __r19 asm("r19");
  47. #define PIC_REG_USE , "r" (__r19)
  48. #ifdef __ASSEMBLER__
  49. /* Syntactic details of assembler. */
  50. #define ALIGNARG(log2) log2
  51. /* For Linux we can use the system call table in the header file
  52. /usr/include/asm/unistd.h
  53. of the kernel. But these symbols do not follow the SYS_* syntax
  54. so we have to redefine the `SYS_ify' macro here. */
  55. #undef SYS_ify
  56. #define SYS_ify(syscall_name) __NR_##syscall_name
  57. /* ELF-like local names start with `.L'. */
  58. #undef L
  59. #define L(name) .L##name
  60. /* Linux uses a negative return value to indicate syscall errors,
  61. unlike most Unices, which use the condition codes' carry flag.
  62. Since version 2.1 the return value of a system call might be
  63. negative even if the call succeeded. E.g., the `lseek' system call
  64. might return a large offset. Therefore we must not anymore test
  65. for < 0, but test for a real error by making sure the value in %eax
  66. is a real error number. Linus said he will make sure the no syscall
  67. returns a value in -1 .. -4095 as a valid result so we can safely
  68. test with -4095. */
  69. /* We don't want the label for the error handle to be global when we define
  70. it here. */
  71. /*#ifdef PIC
  72. # define SYSCALL_ERROR_LABEL 0f
  73. #else
  74. # define SYSCALL_ERROR_LABEL syscall_error
  75. #endif*/
  76. /* Argument manipulation from the stack for preparing to
  77. make a syscall */
  78. #define DOARGS_0 /* nothing */
  79. #define DOARGS_1 /* nothing */
  80. #define DOARGS_2 /* nothing */
  81. #define DOARGS_3 /* nothing */
  82. #define DOARGS_4 /* nothing */
  83. #define DOARGS_5 ldw -52(%sp), %r22 ASM_LINE_SEP
  84. #define DOARGS_6 DOARGS_5 ldw -56(%sp), %r21 ASM_LINE_SEP
  85. #define UNDOARGS_0 /* nothing */
  86. #define UNDOARGS_1 /* nothing */
  87. #define UNDOARGS_2 /* nothing */
  88. #define UNDOARGS_3 /* nothing */
  89. #define UNDOARGS_4 /* nothing */
  90. #define UNDOARGS_5 /* nothing */
  91. #define UNDOARGS_6 /* nothing */
  92. /* Define an entry point visible from C.
  93. There is currently a bug in gdb which prevents us from specifying
  94. incomplete stabs information. Fake some entries here which specify
  95. the current source file. */
  96. #undef ENTRY
  97. #define ENTRY(name) \
  98. .text ASM_LINE_SEP \
  99. .align ALIGNARG(4) ASM_LINE_SEP \
  100. .export C_SYMBOL_NAME(name) ASM_LINE_SEP \
  101. .type C_SYMBOL_NAME(name),@function ASM_LINE_SEP \
  102. cfi_startproc ASM_LINE_SEP \
  103. C_LABEL(name) ASM_LINE_SEP \
  104. .PROC ASM_LINE_SEP \
  105. .CALLINFO FRAME=64,CALLS,SAVE_RP,ENTRY_GR=3 ASM_LINE_SEP \
  106. .ENTRY ASM_LINE_SEP \
  107. /* SAVE_RP says we do */ ASM_LINE_SEP \
  108. stw %rp, -20(%sr0,%sp) ASM_LINE_SEP \
  109. .cfi_offset 2, -20 ASM_LINE_SEP \
  110. /*FIXME: Call mcount? (carefull with stack!) */
  111. /* Some syscall wrappers do not call other functions, and
  112. hence are classified as leaf, so add NO_CALLS for gdb */
  113. #define ENTRY_LEAF(name) \
  114. .text ASM_LINE_SEP \
  115. .align ALIGNARG(4) ASM_LINE_SEP \
  116. .export C_SYMBOL_NAME(name) ASM_LINE_SEP \
  117. .type C_SYMBOL_NAME(name),@function ASM_LINE_SEP \
  118. cfi_startproc ASM_LINE_SEP \
  119. C_LABEL(name) ASM_LINE_SEP \
  120. .PROC ASM_LINE_SEP \
  121. .CALLINFO FRAME=64,NO_CALLS,SAVE_RP,ENTRY_GR=3 ASM_LINE_SEP \
  122. .ENTRY ASM_LINE_SEP \
  123. /* SAVE_RP says we do */ ASM_LINE_SEP \
  124. stw %rp, -20(%sr0,%sp) ASM_LINE_SEP \
  125. .cfi_offset 2, -20 ASM_LINE_SEP \
  126. /*FIXME: Call mcount? (carefull with stack!) */
  127. #undef END
  128. #define END(name) \
  129. .EXIT ASM_LINE_SEP \
  130. .PROCEND ASM_LINE_SEP \
  131. cfi_endproc ASM_LINE_SEP \
  132. .size C_SYMBOL_NAME(name), .-C_SYMBOL_NAME(name) ASM_LINE_SEP
  133. /* If compiled for profiling, call `mcount' at the start
  134. of each function. No, don't bother. gcc will put the
  135. call in for us. */
  136. #define CALL_MCOUNT /* Do nothing. */
  137. /* syscall wrappers consist of
  138. #include <sysdep.h>
  139. PSEUDO(...)
  140. ret
  141. PSEUDO_END(...)
  142. which means
  143. ENTRY(name)
  144. DO_CALL(...)
  145. bv,n 0(2)
  146. */
  147. #undef PSEUDO
  148. #define PSEUDO(name, syscall_name, args) \
  149. ENTRY (name) ASM_LINE_SEP \
  150. /* If necc. load args from stack */ ASM_LINE_SEP \
  151. DOARGS_##args ASM_LINE_SEP \
  152. DO_CALL (syscall_name, args) ASM_LINE_SEP \
  153. UNDOARGS_##args ASM_LINE_SEP
  154. #define ret \
  155. /* Return value set by ERRNO code */ ASM_LINE_SEP \
  156. bv,n 0(2) ASM_LINE_SEP
  157. #undef PSEUDO_END
  158. #define PSEUDO_END(name) \
  159. END (name)
  160. /* We don't set the errno on the return from the syscall */
  161. #define PSEUDO_NOERRNO(name, syscall_name, args) \
  162. ENTRY_LEAF (name) ASM_LINE_SEP \
  163. DOARGS_##args ASM_LINE_SEP \
  164. DO_CALL_NOERRNO (syscall_name, args) ASM_LINE_SEP \
  165. UNDOARGS_##args ASM_LINE_SEP
  166. #define ret_NOERRNO ret
  167. #undef PSEUDO_END_NOERRNO
  168. #define PSEUDO_END_NOERRNO(name) \
  169. END (name)
  170. /* This has to return the error value */
  171. #undef PSEUDO_ERRVAL
  172. #define PSEUDO_ERRVAL(name, syscall_name, args) \
  173. ENTRY_LEAF (name) ASM_LINE_SEP \
  174. DOARGS_##args ASM_LINE_SEP \
  175. DO_CALL_ERRVAL (syscall_name, args) ASM_LINE_SEP \
  176. UNDOARGS_##args ASM_LINE_SEP
  177. #define ret_ERRVAL ret
  178. #undef PSEUDO_END_ERRVAL
  179. #define PSEUDO_END_ERRVAL(name) \
  180. END(name)
  181. #undef JUMPTARGET
  182. #define JUMPTARGET(name) name
  183. #define SYSCALL_PIC_SETUP /* Nothing. */
  184. /* FIXME: This comment is not true.
  185. * All the syscall assembly macros rely on finding the appropriate
  186. SYSCALL_ERROR_LABEL or rather HANDLER. */
  187. /* int * __errno_location(void) so you have to store your value
  188. into the return address! */
  189. #define DEFAULT_SYSCALL_ERROR_HANDLER \
  190. .import __errno_location,code ASM_LINE_SEP \
  191. /* branch to errno handler */ ASM_LINE_SEP \
  192. bl __errno_location,%rp ASM_LINE_SEP
  193. /* Here are the myriad of configuration options that the above can
  194. work for... what we've done is provide the framework for future
  195. changes if required to each section */
  196. #ifdef __PIC__
  197. # if defined _LIBC_REENTRANT
  198. # define SYSCALL_ERROR_HANDLER DEFAULT_SYSCALL_ERROR_HANDLER
  199. # else /* !_LIBC_REENTRANT */
  200. # define SYSCALL_ERROR_HANDLER DEFAULT_SYSCALL_ERROR_HANDLER
  201. # endif /* _LIBC_REENTRANT */
  202. #else
  203. # ifndef _LIBC_REENTRANT
  204. # define SYSCALL_ERROR_HANDLER DEFAULT_SYSCALL_ERROR_HANDLER
  205. # else
  206. # define SYSCALL_ERROR_HANDLER DEFAULT_SYSCALL_ERROR_HANDLER
  207. # endif
  208. #endif
  209. /* Linux takes system call arguments in registers:
  210. syscall number gr20
  211. arg 1 gr26
  212. arg 2 gr25
  213. arg 3 gr24
  214. arg 4 gr23
  215. arg 5 gr22
  216. arg 6 gr21
  217. The compiler calls us by the C convention:
  218. syscall number in the DO_CALL macro
  219. arg 1 gr26
  220. arg 2 gr25
  221. arg 3 gr24
  222. arg 4 gr23
  223. arg 5 -52(sp)
  224. arg 6 -56(sp)
  225. gr22 and gr21 are caller-saves, so we can just load the arguments
  226. there and generally be happy. */
  227. /* the cmpb...no_error code below inside DO_CALL
  228. * is intended to mimic the if (__sys_res...)
  229. * code inside INLINE_SYSCALL
  230. */
  231. #define NO_ERROR -0x1000
  232. #undef DO_CALL
  233. #define DO_CALL(syscall_name, args) \
  234. /* Create a frame */ ASM_LINE_SEP \
  235. stwm TREG, 64(%sp) ASM_LINE_SEP \
  236. .cfi_def_cfa_offset -64 ASM_LINE_SEP \
  237. .cfi_offset TREG, 0 ASM_LINE_SEP \
  238. stw %sp, -4(%sp) ASM_LINE_SEP \
  239. stw %r19, -32(%sp) ASM_LINE_SEP \
  240. .cfi_offset 19, 32 ASM_LINE_SEP \
  241. /* Save r19 */ ASM_LINE_SEP \
  242. SAVE_PIC(TREG) ASM_LINE_SEP \
  243. /* Do syscall, delay loads # */ ASM_LINE_SEP \
  244. ble 0x100(%sr2,%r0) ASM_LINE_SEP \
  245. ldi SYS_ify (syscall_name), %r20 ASM_LINE_SEP \
  246. ldi NO_ERROR,%r1 ASM_LINE_SEP \
  247. cmpb,>>=,n %r1,%ret0,L(pre_end) ASM_LINE_SEP \
  248. /* Restore r19 from TREG */ ASM_LINE_SEP \
  249. LOAD_PIC(TREG) /* delay */ ASM_LINE_SEP \
  250. SYSCALL_ERROR_HANDLER ASM_LINE_SEP \
  251. /* Use TREG for temp storage */ ASM_LINE_SEP \
  252. copy %ret0, TREG /* delay */ ASM_LINE_SEP \
  253. /* OPTIMIZE: Don't reload r19 */ ASM_LINE_SEP \
  254. /* do a -1*syscall_ret0 */ ASM_LINE_SEP \
  255. sub %r0, TREG, TREG ASM_LINE_SEP \
  256. /* Store into errno location */ ASM_LINE_SEP \
  257. stw TREG, 0(%sr0,%ret0) ASM_LINE_SEP \
  258. /* return -1 as error */ ASM_LINE_SEP \
  259. ldo -1(%r0), %ret0 ASM_LINE_SEP \
  260. L(pre_end): ASM_LINE_SEP \
  261. /* Restore our frame, restoring TREG */ ASM_LINE_SEP \
  262. ldwm -64(%sp), TREG ASM_LINE_SEP \
  263. /* Restore return pointer */ ASM_LINE_SEP \
  264. ldw -20(%sp),%rp ASM_LINE_SEP
  265. /* We do nothing with the return, except hand it back to someone else */
  266. #undef DO_CALL_NOERRNO
  267. #define DO_CALL_NOERRNO(syscall_name, args) \
  268. /* No need to store r19 */ ASM_LINE_SEP \
  269. ble 0x100(%sr2,%r0) ASM_LINE_SEP \
  270. ldi SYS_ify (syscall_name), %r20 ASM_LINE_SEP \
  271. /* Caller will restore r19 */ ASM_LINE_SEP
  272. /* Here, we return the ERRVAL in assembly, note we don't call the
  273. error handler function, but we do 'negate' the return _IF_
  274. it's an error. Not sure if this is the right semantic. */
  275. #undef DO_CALL_ERRVAL
  276. #define DO_CALL_ERRVAL(syscall_name, args) \
  277. /* No need to store r19 */ ASM_LINE_SEP \
  278. ble 0x100(%sr2,%r0) ASM_LINE_SEP \
  279. ldi SYS_ify (syscall_name), %r20 ASM_LINE_SEP \
  280. /* Caller will restore r19 */ ASM_LINE_SEP \
  281. ldi NO_ERROR,%r1 ASM_LINE_SEP \
  282. cmpb,>>=,n %r1,%ret0,0f ASM_LINE_SEP \
  283. sub %r0, %ret0, %ret0 ASM_LINE_SEP \
  284. 0: ASM_LINE_SEP
  285. #else
  286. /* GCC has to be warned that a syscall may clobber all the ABI
  287. registers listed as "caller-saves", see page 8, Table 2
  288. in section 2.2.6 of the PA-RISC RUN-TIME architecture
  289. document. However! r28 is the result and will conflict with
  290. the clobber list so it is left out. Also the input arguments
  291. registers r20 -> r26 will conflict with the list so they
  292. are treated specially. Although r19 is clobbered by the syscall
  293. we cannot say this because it would violate ABI, thus we say
  294. TREG is clobbered and use that register to save/restore r19
  295. across the syscall. */
  296. #define CALL_CLOB_REGS "%r1", "%r2", CLOB_TREG \
  297. "%r20", "%r29", "%r31"
  298. #endif /* __ASSEMBLER__ */
  299. #endif /* _LINUX_HPPA_SYSDEP_H */