sem_wait.S 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /* Copyright (C) 2003, 2004, 2007 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 <structsem.h>
  19. #include <lowlevellock.h>
  20. #include "lowlevel-atomic.h"
  21. #if VALUE != 0
  22. # error "code needs to be rewritten for VALUE != 0"
  23. #endif
  24. .text
  25. .globl sem_wait
  26. .type sem_wait,@function
  27. .align 5
  28. sem_wait:
  29. .LSTARTCODE:
  30. mov.l r8, @-r15
  31. .Lpush_r8:
  32. mov.l r10, @-r15
  33. .Lpush_r10:
  34. mov.l r12, @-r15
  35. .Lpush_r12:
  36. sts.l pr, @-r15
  37. .Lpush_pr:
  38. mov r4, r8
  39. mov.l @r8, r0
  40. 2:
  41. tst r0, r0
  42. bt 1f
  43. mov r0, r3
  44. mov r0, r4
  45. add #-1, r3
  46. CMPXCHG (r4, @r8, r3, r2)
  47. bf/s 2b
  48. mov r2, r0
  49. 7:
  50. mov #0, r0
  51. 9:
  52. lds.l @r15+, pr
  53. mov.l @r15+, r12
  54. mov.l @r15+, r10
  55. rts
  56. mov.l @r15+, r8
  57. .Lafter_ret:
  58. 1:
  59. INC (@(NWAITERS,r8),r2)
  60. .LcleanupSTART:
  61. 6:
  62. mov.l .Lenable0, r1
  63. bsrf r1
  64. nop
  65. .Lenable0b:
  66. mov r0, r10
  67. mov r8, r4
  68. #if FUTEX_WAIT == 0
  69. mov.l @(PRIVATE,r8), r5
  70. #else
  71. mov.l @(PRIVATE,r8), r5
  72. mov #FUTEX_WAIT, r0
  73. or r0, r5
  74. #endif
  75. mov #0, r6
  76. mov #0, r7
  77. mov #SYS_futex, r3
  78. extu.b r3, r3
  79. trapa #0x14
  80. SYSCALL_INST_PAD
  81. mov.l .Ldisable0, r1
  82. mov r10, r4
  83. bsrf r1
  84. mov r0, r10
  85. .Ldisable0b:
  86. mov r10, r0
  87. .LcleanupEND:
  88. tst r0, r0
  89. bt 3f
  90. cmp/eq #-EWOULDBLOCK, r0
  91. bf 4f
  92. 3:
  93. mov.l @r8, r0
  94. 5:
  95. tst r0, r0
  96. bt 6b
  97. mov r0, r3
  98. mov r0, r4
  99. add #-1, r3
  100. CMPXCHG (r4, @r8, r3, r2)
  101. bf/s 5b
  102. mov r2, r0
  103. DEC (@(NWAITERS,r8), r2)
  104. bra 7b
  105. nop
  106. 4:
  107. neg r0, r0
  108. mov r0, r4
  109. DEC (@(NWAITERS,r8), r2)
  110. mov r4, r8
  111. mova .Lgot0, r0
  112. mov.l .Lgot0, r12
  113. add r0, r12
  114. #if USE___THREAD
  115. mov.l .Lerrno0, r0
  116. stc gbr, r1
  117. mov.l @(r0, r12), r0
  118. bra .Lexit
  119. add r1, r0
  120. .align 2
  121. .Lerrno0:
  122. .long errno@GOTTPOFF
  123. .Lexit:
  124. #else
  125. mov.l .Lerrloc0, r1
  126. bsrf r1
  127. nop
  128. .Lerrloc0b:
  129. #endif
  130. mov.l r8, @r0
  131. bra 9b
  132. mov #-1, r0
  133. .align 2
  134. .Lgot0:
  135. .long _GLOBAL_OFFSET_TABLE_
  136. #if !USE___THREAD
  137. .Lerrloc0:
  138. .long __errno_location@PLT-(.Lerrloc0b-.)
  139. #endif
  140. .Lenable0:
  141. .long __pthread_enable_asynccancel-.Lenable0b
  142. .Ldisable0:
  143. .long __pthread_disable_asynccancel-.Ldisable0b
  144. .size sem_wait,.-sem_wait
  145. .type sem_wait_cleanup,@function
  146. sem_wait_cleanup:
  147. DEC (@(NWAITERS,r8), r2)
  148. .LcallUR:
  149. mov.l .Lresume, r1
  150. #ifdef __PIC__
  151. add r12, r1
  152. #endif
  153. jsr @r1
  154. nop
  155. sleep
  156. .align 2
  157. .Lresume:
  158. #ifdef __PIC__
  159. .long _Unwind_Resume@GOTOFF
  160. #else
  161. .long _Unwind_Resume
  162. #endif
  163. .LENDCODE:
  164. .size sem_wait_cleanup,.-sem_wait_cleanup
  165. .section .gcc_except_table,"a",@progbits
  166. .LexceptSTART:
  167. .byte 0xff ! @LPStart format (omit)
  168. .byte 0xff ! @TType format (omit)
  169. .byte 0x01 ! call-site format
  170. ! DW_EH_PE_uleb128
  171. .uleb128 .Lcstend-.Lcstbegin
  172. .Lcstbegin:
  173. .uleb128 .LcleanupSTART-.LSTARTCODE
  174. .uleb128 .LcleanupEND-.LcleanupSTART
  175. .uleb128 sem_wait_cleanup-.LSTARTCODE
  176. .uleb128 0
  177. .uleb128 .LcallUR-.LSTARTCODE
  178. .uleb128 .LENDCODE-.LcallUR
  179. .uleb128 0
  180. .uleb128 0
  181. .Lcstend:
  182. .section .eh_frame,"a",@progbits
  183. .LSTARTFRAME:
  184. .ualong .LENDCIE-.LSTARTCIE ! Length of the CIE.
  185. .LSTARTCIE:
  186. .ualong 0 ! CIE ID.
  187. .byte 1 ! Version number.
  188. #ifdef SHARED
  189. .string "zPLR" ! NUL-terminated augmentation
  190. ! string.
  191. #else
  192. .string "zPL" ! NUL-terminated augmentation
  193. ! string.
  194. #endif
  195. .uleb128 1 ! Code alignment factor.
  196. .sleb128 -4 ! Data alignment factor.
  197. .byte 0x11 ! Return address register
  198. ! column.
  199. #ifdef SHARED
  200. .uleb128 7 ! Augmentation value length.
  201. .byte 0x9b ! Personality: DW_EH_PE_pcrel
  202. ! + DW_EH_PE_sdata4
  203. ! + DW_EH_PE_indirect
  204. .ualong DW.ref.__gcc_personality_v0-.
  205. .byte 0x1b ! LSDA Encoding: DW_EH_PE_pcrel
  206. ! + DW_EH_PE_sdata4.
  207. .byte 0x1b ! FDE Encoding: DW_EH_PE_pcrel
  208. ! + DW_EH_PE_sdata4.
  209. #else
  210. .uleb128 6 ! Augmentation value length.
  211. .byte 0x0 ! Personality: absolute
  212. .ualong __gcc_personality_v0
  213. .byte 0x0 ! LSDA Encoding: absolute
  214. #endif
  215. .byte 0x0c ! DW_CFA_def_cfa
  216. .uleb128 0xf
  217. .uleb128 0
  218. .align 4
  219. .LENDCIE:
  220. .ualong .LENDFDE-.LSTARTFDE ! Length of the FDE.
  221. .LSTARTFDE:
  222. .ualong .LSTARTFDE-.LSTARTFRAME ! CIE pointer.
  223. #ifdef SHARED
  224. .ualong .LSTARTCODE-. ! PC-relative start address
  225. ! of the code.
  226. #else
  227. .ualong .LSTARTCODE ! Start address of the code.
  228. #endif
  229. .ualong .LENDCODE-.LSTARTCODE ! Length of the code.
  230. .uleb128 4 ! Augmentation size
  231. #ifdef SHARED
  232. .ualong .LexceptSTART-.
  233. #else
  234. .ualong .LexceptSTART
  235. #endif
  236. .byte 4 ! DW_CFA_advance_loc4
  237. .ualong .Lpush_r8-.LSTARTCODE
  238. .byte 14 ! DW_CFA_def_cfa_offset
  239. .uleb128 4
  240. .byte 0x88 ! DW_CFA_offset r8
  241. .uleb128 1
  242. .byte 4 ! DW_CFA_advance_loc4
  243. .ualong .Lpush_r10-.Lpush_r8
  244. .byte 14 ! DW_CFA_def_cfa_offset
  245. .uleb128 8
  246. .byte 0x8a ! DW_CFA_offset r10
  247. .uleb128 2
  248. .byte 4 ! DW_CFA_advance_loc4
  249. .ualong .Lpush_r12-.Lpush_r10
  250. .byte 14 ! DW_CFA_def_cfa_offset
  251. .uleb128 12
  252. .byte 0x8c ! DW_CFA_offset r12
  253. .uleb128 3
  254. .byte 4 ! DW_CFA_advance_loc4
  255. .ualong .Lpush_pr-.Lpush_r12
  256. .byte 14 ! DW_CFA_def_cfa_offset
  257. .uleb128 16
  258. .byte 0x91 ! DW_CFA_offset pr
  259. .uleb128 4
  260. .align 4
  261. .LENDFDE:
  262. #ifdef SHARED
  263. .hidden DW.ref.__gcc_personality_v0
  264. .weak DW.ref.__gcc_personality_v0
  265. .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
  266. .align 4
  267. .type DW.ref.__gcc_personality_v0, @object
  268. .size DW.ref.__gcc_personality_v0, 4
  269. DW.ref.__gcc_personality_v0:
  270. .long __gcc_personality_v0
  271. #endif