sem_wait.S 5.7 KB

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