lowlevelrobustlock.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /* Copyright (C) 2003, 2004, 2005, 2006, 2007
  2. 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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <sysdep.h>
  17. #include <pthread-errnos.h>
  18. #include <lowlevellock.h>
  19. #include <lowlevelrobustlock.h>
  20. #include <bits/kernel-features.h>
  21. #include <tcb-offsets.h>
  22. #include "lowlevel-atomic.h"
  23. .text
  24. #define FUTEX_WAITERS 0x80000000
  25. #define FUTEX_OWNER_DIED 0x40000000
  26. #ifdef __ASSUME_PRIVATE_FUTEX
  27. # define LOAD_FUTEX_WAIT(reg,tmp,tmp2) \
  28. mov #(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), tmp; \
  29. extu.b tmp, tmp; \
  30. xor tmp, reg
  31. #else
  32. # if FUTEX_WAIT == 0
  33. # define LOAD_FUTEX_WAIT(reg,tmp,tmp2) \
  34. stc gbr, tmp ; \
  35. mov.w 99f, tmp2 ; \
  36. add tmp2, tmp ; \
  37. mov.l @tmp, tmp2 ; \
  38. bra 98f ; \
  39. mov #FUTEX_PRIVATE_FLAG, tmp ; \
  40. 99: .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE ; \
  41. 98: extu.b tmp, tmp ; \
  42. xor tmp, reg ; \
  43. and tmp2, reg
  44. # else
  45. # define LOAD_FUTEX_WAIT(reg,tmp,tmp2) \
  46. stc gbr, tmp ; \
  47. mov.w 99f, tmp2 ; \
  48. add tmp2, tmp ; \
  49. mov.l @tmp, tmp2 ; \
  50. bra 98f ; \
  51. mov #FUTEX_PRIVATE_FLAG, tmp ; \
  52. 99: .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE ; \
  53. 98: extu.b tmp, tmp ; \
  54. xor tmp, reg ; \
  55. and tmp2, reg ; \
  56. mov #FUTEX_WAIT, tmp ; \
  57. or tmp, reg
  58. # endif
  59. #endif
  60. .globl __lll_robust_lock_wait
  61. .type __lll_robust_lock_wait,@function
  62. .hidden __lll_robust_lock_wait
  63. .align 5
  64. cfi_startproc
  65. __lll_robust_lock_wait:
  66. mov.l r8, @-r15
  67. cfi_adjust_cfa_offset(4)
  68. cfi_rel_offset (r8, 0)
  69. mov r5, r8
  70. mov #0, r7 /* No timeout. */
  71. mov r6, r5
  72. LOAD_FUTEX_WAIT (r5, r0, r1)
  73. 4:
  74. mov r4, r6
  75. mov.l .L_FUTEX_WAITERS, r0
  76. or r0, r6
  77. shlr r0 /* r0 = FUTEX_OWNER_DIED */
  78. tst r0, r4
  79. bf/s 3f
  80. cmp/eq r4, r6
  81. bt 1f
  82. CMPXCHG (r4, @r8, r6, r2)
  83. bf 2f
  84. 1:
  85. mov r8, r4
  86. mov #SYS_futex, r3
  87. extu.b r3, r3
  88. trapa #0x14
  89. SYSCALL_INST_PAD
  90. mov.l @r8, r2
  91. 2:
  92. tst r2, r2
  93. bf/s 4b
  94. mov r2, r4
  95. stc gbr, r1
  96. mov.w .Ltidoff, r2
  97. add r2, r1
  98. mov.l @r1, r6
  99. mov #0, r3
  100. CMPXCHG (r3, @r8, r6, r4)
  101. bf 4b
  102. mov #0, r4
  103. 3:
  104. mov.l @r15+, r8
  105. ret
  106. mov r4, r0
  107. cfi_endproc
  108. .align 2
  109. .L_FUTEX_WAITERS:
  110. .long FUTEX_WAITERS
  111. .Ltidoff:
  112. .word TID - TLS_PRE_TCB_SIZE
  113. .size __lll_robust_lock_wait,.-__lll_robust_lock_wait
  114. .globl __lll_robust_timedlock_wait
  115. .type __lll_robust_timedlock_wait,@function
  116. .hidden __lll_robust_timedlock_wait
  117. .align 5
  118. cfi_startproc
  119. __lll_robust_timedlock_wait:
  120. /* Check for a valid timeout value. */
  121. mov.l @(4,r6), r1
  122. mov.l .L1g, r0
  123. cmp/hs r0, r1
  124. bt 3f
  125. mov.l r11, @-r15
  126. cfi_adjust_cfa_offset(4)
  127. cfi_rel_offset (r11, 0)
  128. mov.l r10, @-r15
  129. cfi_adjust_cfa_offset(4)
  130. cfi_rel_offset (r10, 0)
  131. mov.l r9, @-r15
  132. cfi_adjust_cfa_offset(4)
  133. cfi_rel_offset (r9, 0)
  134. mov.l r8, @-r15
  135. cfi_adjust_cfa_offset(4)
  136. cfi_rel_offset (r8, 0)
  137. mov r7, r11
  138. mov r4, r10
  139. mov r6, r9
  140. mov r5, r8
  141. /* Stack frame for the timespec and timeval structs. */
  142. add #-8, r15
  143. cfi_adjust_cfa_offset(8)
  144. 1:
  145. /* Get current time. */
  146. mov r15, r4
  147. mov #0, r5
  148. mov #__NR_gettimeofday, r3
  149. trapa #0x12
  150. SYSCALL_INST_PAD
  151. /* Compute relative timeout. */
  152. mov.l @(4,r15), r0
  153. mov.w .L1k, r1
  154. dmulu.l r0, r1 /* Micro seconds to nano seconds. */
  155. mov.l @r9, r2
  156. mov.l @(4,r9), r3
  157. mov.l @r15, r0
  158. sts macl, r1
  159. sub r0, r2
  160. clrt
  161. subc r1, r3
  162. bf 4f
  163. mov.l .L1g, r1
  164. add r1, r3
  165. add #-1, r2
  166. 4:
  167. cmp/pz r2
  168. bf 8f /* Time is already up. */
  169. mov.l r2, @r15 /* Store relative timeout. */
  170. mov.l r3, @(4,r15)
  171. mov r10, r6
  172. mov.l .L_FUTEX_WAITERS2, r0
  173. or r0, r6
  174. shlr r0 /* r0 = FUTEX_OWNER_DIED */
  175. tst r0, r4
  176. bf/s 6f
  177. cmp/eq r4, r6
  178. bt 2f
  179. CMPXCHG (r4, @r8, r6, r2)
  180. bf/s 5f
  181. mov #0, r5
  182. 2:
  183. mov r8, r4
  184. mov r11, r5
  185. LOAD_FUTEX_WAIT (r5, r0, r1)
  186. mov r10, r6
  187. mov r15, r7
  188. mov #SYS_futex, r3
  189. extu.b r3, r3
  190. trapa #0x14
  191. SYSCALL_INST_PAD
  192. mov r0, r5
  193. mov.l @r8, r2
  194. 5:
  195. tst r2, r2
  196. bf/s 7f
  197. mov r2, r10
  198. stc gbr, r1
  199. mov.w .Ltidoff2, r2
  200. add r2, r1
  201. mov.l @r1, r4
  202. mov #0, r3
  203. CMPXCHG (r3, @r8, r4, r10)
  204. bf 7f
  205. mov #0, r0
  206. 6:
  207. add #8, r15
  208. mov.l @r15+, r8
  209. mov.l @r15+, r9
  210. mov.l @r15+, r10
  211. rts
  212. mov.l @r15+, r11
  213. 7:
  214. /* Check whether the time expired. */
  215. mov #-ETIMEDOUT, r1
  216. cmp/eq r5, r1
  217. bf 1b
  218. 8:
  219. bra 6b
  220. mov #ETIMEDOUT, r0
  221. 3:
  222. rts
  223. mov #EINVAL, r0
  224. cfi_endproc
  225. .align 2
  226. .L_FUTEX_WAITERS2:
  227. .long FUTEX_WAITERS
  228. .L1g:
  229. .long 1000000000
  230. .Ltidoff2:
  231. .word TID - TLS_PRE_TCB_SIZE
  232. .L1k:
  233. .word 1000
  234. .size __lll_robust_timedlock_wait,.-__lll_robust_timedlock_wait