lowlevellock.S 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 "lowlevel-atomic.h"
  18. .text
  19. #define SYS_gettimeofday __NR_gettimeofday
  20. #define FUTEX_WAIT 0
  21. #define FUTEX_WAKE 1
  22. .globl __lll_mutex_lock_wait
  23. .type __lll_mutex_lock_wait,@function
  24. .hidden __lll_mutex_lock_wait
  25. .align 5
  26. /* void __lll_mutex_lock_wait (int val, int *__futex) */
  27. __lll_mutex_lock_wait:
  28. mov #2, r6
  29. cmp/eq r4, r6
  30. mov r5, r4
  31. mov #0, r7 /* No timeout. */
  32. mov #FUTEX_WAIT, r5
  33. bf 2f
  34. 1:
  35. mov #SYS_futex, r3
  36. extu.b r3, r3
  37. trapa #0x14
  38. SYSCALL_INST_PAD
  39. 2:
  40. XCHG (r6, @r4, r2)
  41. tst r2, r2
  42. bf 1b
  43. rts
  44. nop
  45. .size __lll_mutex_lock_wait,.-__lll_mutex_lock_wait
  46. #ifdef NOT_IN_libc
  47. .globl __lll_mutex_timedlock_wait
  48. .type __lll_mutex_timedlock_wait,@function
  49. .hidden __lll_mutex_timedlock_wait
  50. .align 5
  51. /* int __lll_mutex_timedlock_wait (int val, int *__futex,
  52. const struct timespec *abstime) */
  53. __lll_mutex_timedlock_wait:
  54. /* Check for a valid timeout value. */
  55. mov.l @(4,r6), r1
  56. mov.l .L1g, r0
  57. cmp/hs r0, r1
  58. bt 3f
  59. mov.l r9, @-r15
  60. mov.l r8, @-r15
  61. mov r6, r9
  62. mov r5, r8
  63. /* Stack frame for the timespec and timeval structs. */
  64. add #-8, r15
  65. 1:
  66. /* Get current time. */
  67. mov r15, r4
  68. mov #0, r5
  69. mov #SYS_gettimeofday, r3
  70. trapa #0x12
  71. SYSCALL_INST_PAD
  72. /* Compute relative timeout. */
  73. mov.l @(4,r15), r0
  74. mov.w .L1k, r1
  75. dmulu.l r0, r1 /* Micro seconds to nano seconds. */
  76. mov.l @r9, r2
  77. mov.l @(4,r9), r3
  78. mov.l @r15, r0
  79. sts macl, r1
  80. sub r0, r2
  81. clrt
  82. subc r1, r3
  83. bf 4f
  84. mov.l .L1g, r1
  85. add r1, r3
  86. add #-1, r2
  87. 4:
  88. cmp/pz r2
  89. bf 5f /* Time is already up. */
  90. mov.l r2, @r15 /* Store relative timeout. */
  91. mov.l r3, @(4,r15)
  92. mov #1, r3
  93. mov #2, r6
  94. CMPXCHG (r3, @r8, r6, r2)
  95. tst r2, r2
  96. bt 8f
  97. mov r8, r4
  98. mov #FUTEX_WAIT, r5
  99. mov r15, r7
  100. mov #SYS_futex, r3
  101. extu.b r3, r3
  102. trapa #0x14
  103. SYSCALL_INST_PAD
  104. mov r0, r4
  105. 8:
  106. mov #0, r3
  107. CMPXCHG (r3, @r8, r6, r2)
  108. bf/s 7f
  109. mov #0, r0
  110. 6:
  111. add #8, r15
  112. mov.l @r15+, r8
  113. rts
  114. mov.l @r15+, r9
  115. 7:
  116. /* Check whether the time expired. */
  117. mov #-ETIMEDOUT, r1
  118. cmp/eq r5, r1
  119. bt 5f
  120. /* Make sure the current holder knows we are going to sleep. */
  121. XCHG (r2, @r8, r3)
  122. tst r3, r3
  123. bt/s 6b
  124. mov #0, r0
  125. bra 1b
  126. nop
  127. 3:
  128. rts
  129. mov #EINVAL, r0
  130. 5:
  131. bra 6b
  132. mov #ETIMEDOUT, r0
  133. .L1k:
  134. .word 1000
  135. .align 2
  136. .L1g:
  137. .long 1000000000
  138. .size __lll_mutex_timedlock_wait,.-__lll_mutex_timedlock_wait
  139. #endif
  140. #ifdef NOT_IN_libc
  141. .globl lll_unlock_wake_cb
  142. .type lll_unlock_wake_cb,@function
  143. .hidden lll_unlock_wake_cb
  144. .align 5
  145. lll_unlock_wake_cb:
  146. DEC (@r4, r2)
  147. tst r2, r2
  148. bt 1f
  149. mov #FUTEX_WAKE, r5
  150. mov #1, r6 /* Wake one thread. */
  151. mov #0, r7
  152. mov.l r7, @r4 /* Stores 0. */
  153. mov #SYS_futex, r3
  154. extu.b r3, r3
  155. trapa #0x14
  156. SYSCALL_INST_PAD
  157. 1:
  158. rts
  159. nop
  160. .size lll_unlock_wake_cb,.-lll_unlock_wake_cb
  161. #endif
  162. .globl __lll_mutex_unlock_wake
  163. .type __lll_mutex_unlock_wake,@function
  164. .hidden __lll_mutex_unlock_wake
  165. .align 5
  166. /* void __lll_mutex_unlock_wake(int *__futex) */
  167. __lll_mutex_unlock_wake:
  168. mov #FUTEX_WAKE, r5
  169. mov #1, r6 /* Wake one thread. */
  170. mov #0, r7
  171. mov.l r7, @r4 /* Stores 0. */
  172. mov #SYS_futex, r3
  173. extu.b r3, r3
  174. trapa #0x14
  175. SYSCALL_INST_PAD
  176. rts
  177. nop
  178. .size __lll_mutex_unlock_wake,.-__lll_mutex_unlock_wake
  179. #ifdef NOT_IN_libc
  180. .globl __lll_timedwait_tid
  181. .type __lll_timedwait_tid,@function
  182. .hidden __lll_timedwait_tid
  183. .align 5
  184. __lll_timedwait_tid:
  185. mov.l r9, @-r15
  186. mov.l r8, @-r15
  187. mov r4, r8
  188. mov r5, r9
  189. /* Stack frame for the timespec and timeval structs. */
  190. add #-8, r15
  191. 2:
  192. /* Get current time. */
  193. mov r15, r4
  194. mov #0, r5
  195. mov #SYS_gettimeofday, r3
  196. trapa #0x12
  197. SYSCALL_INST_PAD
  198. /* Compute relative timeout. */
  199. mov.l @(4,r15), r0
  200. mov.w .L1k2, r1
  201. dmulu.l r0, r1 /* Micro seconds to nano seconds. */
  202. mov.l @r9, r2
  203. mov.l @(4,r9), r3
  204. mov.l @r15, r0
  205. sts macl, r1
  206. sub r0, r2
  207. clrt
  208. subc r1, r3
  209. bf 5f
  210. mov.l .L1g2, r1
  211. add r1, r3
  212. add #-1, r2
  213. 5:
  214. cmp/pz r2
  215. bf 6f /* Time is already up. */
  216. mov.l r2, @r15 /* Store relative timeout. */
  217. mov.l r3, @(4,r15)
  218. mov.l @r8, r2
  219. tst r2, r2
  220. bt 4f
  221. mov r8, r4
  222. mov #FUTEX_WAIT, r5
  223. mov r2, r6
  224. mov r15, r7
  225. mov #SYS_futex, r3
  226. extu.b r3, r3
  227. trapa #0x14
  228. SYSCALL_INST_PAD
  229. mov.l @r8, r2
  230. tst r2, r2
  231. bf 1f
  232. 4:
  233. mov #0, r0
  234. 3:
  235. add #8, r15
  236. mov.l @r15+, r8
  237. rts
  238. mov.l @r15+, r9
  239. 1:
  240. /* Check whether the time expired. */
  241. mov #-ETIMEDOUT, r1
  242. cmp/eq r0, r1
  243. bf 2b
  244. 6:
  245. bra 3b
  246. mov #ETIMEDOUT, r0
  247. .L1k2:
  248. .word 1000
  249. .align 2
  250. .L1g2:
  251. .long 1000000000
  252. .size __lll_timedwait_tid,.-__lll_timedwait_tid
  253. #endif