sem_timedwait.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <sysdep.h>
  16. #include <pthread-errnos.h>
  17. #include <tcb-offsets.h>
  18. #include "lowlevel-atomic.h"
  19. #define SYS_gettimeofday __NR_gettimeofday
  20. #define FUTEX_WAIT 0
  21. #define FUTEX_WAKE 1
  22. .text
  23. .globl sem_timedwait
  24. .type sem_timedwait,@function
  25. .align 5
  26. cfi_startproc
  27. sem_timedwait:
  28. /* First check for cancellation. */
  29. stc gbr, r0
  30. mov.w .Lchand, r1
  31. mov.l @(r0,r1), r0
  32. mov #0xf9, r1
  33. and r1, r0
  34. cmp/eq #8, r0
  35. bf 0f
  36. bra 10f
  37. stc gbr, r0
  38. 0:
  39. mov.l @r4, r0
  40. 2:
  41. tst r0, r0
  42. bt 1f
  43. mov r0, r3
  44. mov r0, r6
  45. add #-1, r3
  46. CMPXCHG (r6, @r4, r3, r2)
  47. bf/s 2b
  48. mov r2, r0
  49. rts
  50. mov #0, r0
  51. 1:
  52. /* Check whether the timeout value is valid. */
  53. mov.l r8, @-r15
  54. cfi_adjust_cfa_offset(4)
  55. cfi_rel_offset (r8, 0)
  56. mov.l r9, @-r15
  57. cfi_adjust_cfa_offset(4)
  58. cfi_rel_offset (r9, 0)
  59. mov.l r10, @-r15
  60. cfi_adjust_cfa_offset(4)
  61. cfi_rel_offset (r10, 0)
  62. mov.l r12, @-r15
  63. cfi_adjust_cfa_offset(4)
  64. cfi_rel_offset (r12, 0)
  65. sts.l pr, @-r15
  66. cfi_adjust_cfa_offset(4)
  67. cfi_rel_offset (pr, 0)
  68. add #-8, r15
  69. cfi_adjust_cfa_offset(8)
  70. mov r4, r8
  71. mov r5, r9
  72. /* Check for invalid nanosecond field. */
  73. mov.l @(4,r9), r0
  74. mov.l .L1g, r1
  75. cmp/hs r1, r0
  76. bt/s 6f
  77. mov #EINVAL, r0
  78. 7:
  79. mov.l .Lenable0, r1
  80. bsrf r1
  81. nop
  82. .Lenable0b:
  83. mov r0, r10
  84. /* Compute relative timeout. */
  85. mov r15, r4
  86. mov #0, r5
  87. mov #SYS_gettimeofday, r3
  88. trapa #0x12
  89. SYSCALL_INST_PAD
  90. mov.l @(4,r15), r0
  91. mov.w .L1k, r1
  92. dmulu.l r0, r1 /* Milli seconds to nano seconds. */
  93. mov.l @r9, r2
  94. mov.l @(4,r9), r3
  95. mov.l @r15, r0
  96. sts macl, r1
  97. sub r0, r2
  98. clrt
  99. subc r1, r3
  100. bf 5f
  101. mov.l .L1g, r1
  102. add r1, r3
  103. add #-1, r2
  104. 5:
  105. cmp/pz r2
  106. bf/s 6f /* Time is already up. */
  107. mov #ETIMEDOUT, r0
  108. /* Store relative timeout. */
  109. mov.l r2, @r15
  110. mov.l r3, @(4,r15)
  111. /* Futex call. */
  112. mov r8, r4
  113. mov #FUTEX_WAIT, r5
  114. mov #0, r6
  115. mov r15, r7
  116. mov #SYS_futex, r3
  117. extu.b r3, r3
  118. trapa #0x14
  119. SYSCALL_INST_PAD
  120. mov.l .Ldisable0, r1
  121. mov r10, r4
  122. bsrf r1
  123. mov r0, r10
  124. .Ldisable0b:
  125. mov r10, r0
  126. tst r0, r0
  127. bt 9f
  128. cmp/eq #-EWOULDBLOCK, r0
  129. bf 3f
  130. 9:
  131. mov.l @r8, r0
  132. 8:
  133. tst r0, r0
  134. bt 7b
  135. mov r0, r3
  136. mov r0, r4
  137. add #-1, r3
  138. CMPXCHG (r4, @r8, r3, r2)
  139. bf/s 8b
  140. mov r2, r0
  141. add #8, r15
  142. lds.l @r15+, pr
  143. mov.l @r15+, r12
  144. mov.l @r15+, r10
  145. mov.l @r15+, r9
  146. mov.l @r15+, r8
  147. rts
  148. mov #0, r0
  149. 3:
  150. neg r0, r0
  151. 6:
  152. mov r0, r8
  153. mova .Lgot2, r0
  154. mov.l .Lgot2, r12
  155. add r0, r12
  156. #if USE___THREAD
  157. mov.l .Lerrno2, r0
  158. stc gbr, r1
  159. mov.l @(r0, r12), r0
  160. bra .Lexit
  161. add r1, r0
  162. .align 2
  163. .Lerrno2:
  164. .long errno@GOTTPOFF
  165. .Lexit:
  166. #else
  167. mov.l .Lerrloc2, r1
  168. bsrf r1
  169. nop
  170. .Lerrloc2b:
  171. #endif
  172. mov.l r8, @r0
  173. add #8, r15
  174. lds.l @r15+, pr
  175. mov.l @r15+, r12
  176. mov.l @r15+, r10
  177. mov.l @r15+, r9
  178. mov.l @r15+, r8
  179. rts
  180. mov #-1, r0
  181. 10:
  182. /* Canceled. */
  183. mov.w .Lresult, r1
  184. mov #-1, r2
  185. mov.l r2, @(r0,r1)
  186. mov.w .Lchand, r0
  187. or.b #0x10, @(r0,gbr)
  188. stc gbr, r0
  189. mov.w .Lclbuf, r1
  190. mov.l .Lunwind, r2
  191. braf r2
  192. mov.l @(r0,r1), r4
  193. .Lunwindb:
  194. cfi_endproc
  195. .L1k:
  196. .word 1000
  197. .Lchand:
  198. .word CANCELHANDLING - TLS_PRE_TCB_SIZE
  199. .Lresult:
  200. .word RESULT - TLS_PRE_TCB_SIZE
  201. .Lclbuf:
  202. .word CLEANUP_JMP_BUF - TLS_PRE_TCB_SIZE
  203. .align 2
  204. .L1g:
  205. .long 1000000000
  206. .Lgot2:
  207. .long _GLOBAL_OFFSET_TABLE_
  208. #if !USE___THREAD
  209. .Lerrloc2:
  210. .long __errno_location@PLT-(.Lerrloc2b-.)
  211. #endif
  212. .Lenable0:
  213. .long __pthread_enable_asynccancel-.Lenable0b
  214. .Ldisable0:
  215. .long __pthread_disable_asynccancel-.Ldisable0b
  216. .Lunwind:
  217. .long HIDDEN_JUMPTARGET (__pthread_unwind)-.Lunwindb
  218. .size sem_timedwait,.-sem_timedwait