sem_wait.S 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  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 <structsem.h>
  18. #include <lowlevellock.h>
  19. #if VALUE != 0
  20. # error "code needs to be rewritten for VALUE != 0"
  21. #endif
  22. .text
  23. .globl sem_wait
  24. .type sem_wait,@function
  25. .align 16
  26. sem_wait:
  27. .LSTARTCODE:
  28. pushl %ebx
  29. .Lpush_ebx:
  30. pushl %esi
  31. .Lpush_esi:
  32. subl $4, %esp
  33. .Lsub_esp:
  34. movl 16(%esp), %ebx
  35. movl (%ebx), %eax
  36. 2: testl %eax, %eax
  37. je 1f
  38. leal -1(%eax), %edx
  39. LOCK
  40. cmpxchgl %edx, (%ebx)
  41. jne 2b
  42. 7: xorl %eax, %eax
  43. 9: movl 4(%esp), %esi
  44. movl 8(%esp), %ebx
  45. addl $12, %esp
  46. .Ladd_esp:
  47. ret
  48. .Lafter_ret:
  49. 1: LOCK
  50. incl NWAITERS(%ebx)
  51. .LcleanupSTART:
  52. 6: call __pthread_enable_asynccancel
  53. movl %eax, (%esp)
  54. #if FUTEX_WAIT == 0
  55. movl PRIVATE(%ebx), %ecx
  56. #else
  57. movl $FUTEX_WAIT, %ecx
  58. orl PRIVATE(%ebx), %ecx
  59. #endif
  60. xorl %esi, %esi
  61. xorl %edx, %edx
  62. movl $SYS_futex, %eax
  63. ENTER_KERNEL
  64. movl %eax, %esi
  65. movl (%esp), %eax
  66. call __pthread_disable_asynccancel
  67. .LcleanupEND:
  68. testl %esi, %esi
  69. je 3f
  70. cmpl $-EWOULDBLOCK, %esi
  71. jne 4f
  72. 3:
  73. movl (%ebx), %eax
  74. 5: testl %eax, %eax
  75. je 6b
  76. leal -1(%eax), %edx
  77. LOCK
  78. cmpxchgl %edx, (%ebx)
  79. jne 5b
  80. LOCK
  81. decl NWAITERS(%ebx)
  82. jmp 7b
  83. 4: LOCK
  84. decl NWAITERS(%ebx)
  85. negl %esi
  86. #ifdef __PIC__
  87. call __x86.get_pc_thunk.bx
  88. #else
  89. movl $8f, %ebx
  90. 8:
  91. #endif
  92. addl $_GLOBAL_OFFSET_TABLE_, %ebx
  93. #if USE___THREAD
  94. # ifdef NO_TLS_DIRECT_SEG_REFS
  95. movl errno@gotntpoff(%ebx), %edx
  96. addl %gs:0, %edx
  97. movl %esi, (%edx)
  98. # else
  99. movl errno@gotntpoff(%ebx), %edx
  100. movl %esi, %gs:(%edx)
  101. # endif
  102. #else
  103. call __errno_location@plt
  104. movl %esi, (%eax)
  105. #endif
  106. orl $-1, %eax
  107. jmp 9b
  108. .size sem_wait,.-sem_wait
  109. .type sem_wait_cleanup,@function
  110. sem_wait_cleanup:
  111. LOCK
  112. decl NWAITERS(%ebx)
  113. movl %eax, (%esp)
  114. .LcallUR:
  115. call _Unwind_Resume@PLT
  116. hlt
  117. .LENDCODE:
  118. .size sem_wait_cleanup,.-sem_wait_cleanup
  119. .section .gcc_except_table,"a",@progbits
  120. .LexceptSTART:
  121. .byte 0xff # @LPStart format (omit)
  122. .byte 0xff # @TType format (omit)
  123. .byte 0x01 # call-site format
  124. # DW_EH_PE_uleb128
  125. .uleb128 .Lcstend-.Lcstbegin
  126. .Lcstbegin:
  127. .uleb128 .LcleanupSTART-.LSTARTCODE
  128. .uleb128 .LcleanupEND-.LcleanupSTART
  129. .uleb128 sem_wait_cleanup-.LSTARTCODE
  130. .uleb128 0
  131. .uleb128 .LcallUR-.LSTARTCODE
  132. .uleb128 .LENDCODE-.LcallUR
  133. .uleb128 0
  134. .uleb128 0
  135. .Lcstend:
  136. .section .eh_frame,"a",@progbits
  137. .LSTARTFRAME:
  138. .long .LENDCIE-.LSTARTCIE # Length of the CIE.
  139. .LSTARTCIE:
  140. .long 0 # CIE ID.
  141. .byte 1 # Version number.
  142. #ifdef SHARED
  143. .string "zPLR" # NUL-terminated augmentation
  144. # string.
  145. #else
  146. .string "zPL" # NUL-terminated augmentation
  147. # string.
  148. #endif
  149. .uleb128 1 # Code alignment factor.
  150. .sleb128 -4 # Data alignment factor.
  151. .byte 8 # Return address register
  152. # column.
  153. #ifdef SHARED
  154. .uleb128 7 # Augmentation value length.
  155. .byte 0x9b # Personality: DW_EH_PE_pcrel
  156. # + DW_EH_PE_sdata4
  157. # + DW_EH_PE_indirect
  158. .long DW.ref.__gcc_personality_v0-.
  159. .byte 0x1b # LSDA Encoding: DW_EH_PE_pcrel
  160. # + DW_EH_PE_sdata4.
  161. .byte 0x1b # FDE Encoding: DW_EH_PE_pcrel
  162. # + DW_EH_PE_sdata4.
  163. #else
  164. .uleb128 6 # Augmentation value length.
  165. .byte 0x0 # Personality: absolute
  166. .long __gcc_personality_v0
  167. .byte 0x0 # LSDA Encoding: absolute
  168. #endif
  169. .byte 0x0c # DW_CFA_def_cfa
  170. .uleb128 4
  171. .uleb128 4
  172. .byte 0x88 # DW_CFA_offset, column 0x10
  173. .uleb128 1
  174. .align 4
  175. .LENDCIE:
  176. .long .LENDFDE-.LSTARTFDE # Length of the FDE.
  177. .LSTARTFDE:
  178. .long .LSTARTFDE-.LSTARTFRAME # CIE pointer.
  179. #ifdef SHARED
  180. .long .LSTARTCODE-. # PC-relative start address
  181. # of the code.
  182. #else
  183. .long .LSTARTCODE # Start address of the code.
  184. #endif
  185. .long .LENDCODE-.LSTARTCODE # Length of the code.
  186. .uleb128 4 # Augmentation size
  187. #ifdef SHARED
  188. .long .LexceptSTART-.
  189. #else
  190. .long .LexceptSTART
  191. #endif
  192. .byte 4 # DW_CFA_advance_loc4
  193. .long .Lpush_ebx-.LSTARTCODE
  194. .byte 14 # DW_CFA_def_cfa_offset
  195. .uleb128 8
  196. .byte 0x83 # DW_CFA_offset %ebx
  197. .uleb128 2
  198. .byte 4 # DW_CFA_advance_loc4
  199. .long .Lpush_esi-.Lpush_ebx
  200. .byte 14 # DW_CFA_def_cfa_offset
  201. .uleb128 12
  202. .byte 0x86 # DW_CFA_offset %esi
  203. .uleb128 3
  204. .byte 4 # DW_CFA_advance_loc4
  205. .long .Lsub_esp-.Lpush_esi
  206. .byte 14 # DW_CFA_def_cfa_offset
  207. .uleb128 16
  208. .byte 4 # DW_CFA_advance_loc4
  209. .long .Ladd_esp-.Lsub_esp
  210. .byte 14 # DW_CFA_def_cfa_offset
  211. .uleb128 4
  212. .byte 0xc3 # DW_CFA_restore %ebx
  213. .byte 0xc6 # DW_CFA_restore %esi
  214. .byte 4 # DW_CFA_advance_loc4
  215. .long .Lafter_ret-.Ladd_esp
  216. .byte 14 # DW_CFA_def_cfa_offset
  217. .uleb128 16
  218. .byte 0x83 # DW_CFA_offset %ebx
  219. .uleb128 2
  220. .byte 0x86 # DW_CFA_offset %esi
  221. .uleb128 3
  222. .align 4
  223. .LENDFDE:
  224. #ifdef SHARED
  225. .hidden DW.ref.__gcc_personality_v0
  226. .weak DW.ref.__gcc_personality_v0
  227. .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
  228. .align 4
  229. .type DW.ref.__gcc_personality_v0, @object
  230. .size DW.ref.__gcc_personality_v0, 4
  231. DW.ref.__gcc_personality_v0:
  232. .long __gcc_personality_v0
  233. #endif