sem_wait.S 5.9 KB

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