lowlevelrobustlock.S 4.9 KB

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