Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / unix / sysv / linux / i386 / i486 / sem_wait.S
blob9121041ecca5584238793e8b4fa9faac4805832a
1 /* Copyright (C) 2002-2015 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
20 #include <shlib-compat.h>
21 #include <pthread-errnos.h>
22 #include <structsem.h>
23 #include <lowlevellock.h>
26 #if VALUE != 0
27 # error "code needs to be rewritten for VALUE != 0"
28 #endif
30         .text
32         .globl  __new_sem_wait
33         .type   __new_sem_wait,@function
34         .align  16
35 __new_sem_wait:
36 .LSTARTCODE:
37         pushl   %ebx
38 .Lpush_ebx:
39         pushl   %esi
40 .Lpush_esi:
41         subl    $4, %esp
42 .Lsub_esp:
44         movl    16(%esp), %ebx
46         movl    (%ebx), %eax
47 2:      testl   %eax, %eax
48         je      1f
50         leal    -1(%eax), %edx
51         LOCK
52         cmpxchgl %edx, (%ebx)
53         jne     2b
54 7:      xorl    %eax, %eax
56 9:      movl    4(%esp), %esi
57         movl    8(%esp), %ebx
58         addl    $12, %esp
59 .Ladd_esp:
60         ret
62 .Lafter_ret:
63 1:      LOCK
64         incl    NWAITERS(%ebx)
66 .LcleanupSTART:
67 6:      call    __pthread_enable_asynccancel
68         movl    %eax, (%esp)
70 #if FUTEX_WAIT == 0
71         movl    PRIVATE(%ebx), %ecx
72 #else
73         movl    $FUTEX_WAIT, %ecx
74         orl     PRIVATE(%ebx), %ecx
75 #endif
76         xorl    %esi, %esi
77         xorl    %edx, %edx
78         movl    $SYS_futex, %eax
79         ENTER_KERNEL
80         movl    %eax, %esi
82         movl    (%esp), %eax
83         call    __pthread_disable_asynccancel
84 .LcleanupEND:
86         testl   %esi, %esi
87         je      3f
88         cmpl    $-EWOULDBLOCK, %esi
89         jne     4f
92         movl    (%ebx), %eax
93 5:      testl   %eax, %eax
94         je      6b
96         leal    -1(%eax), %edx
97         LOCK
98         cmpxchgl %edx, (%ebx)
99         jne     5b
101         LOCK
102         decl    NWAITERS(%ebx)
103         jmp     7b
105 4:      LOCK
106         decl    NWAITERS(%ebx)
108         negl    %esi
109 #ifdef PIC
110         SETUP_PIC_REG(bx)
111 #else
112         movl    $8f, %ebx
114 #endif
115         addl    $_GLOBAL_OFFSET_TABLE_, %ebx
116 #ifdef NO_TLS_DIRECT_SEG_REFS
117         movl    errno@gotntpoff(%ebx), %edx
118         addl    %gs:0, %edx
119         movl    %esi, (%edx)
120 #else
121         movl    errno@gotntpoff(%ebx), %edx
122         movl    %esi, %gs:(%edx)
123 #endif
124         orl     $-1, %eax
126         jmp     9b
127         .size   __new_sem_wait,.-__new_sem_wait
128         versioned_symbol(libpthread, __new_sem_wait, sem_wait, GLIBC_2_1)
131         .type   sem_wait_cleanup,@function
132 sem_wait_cleanup:
133         LOCK
134         decl    NWAITERS(%ebx)
135         movl    %eax, (%esp)
136 .LcallUR:
137         call    _Unwind_Resume@PLT
138         hlt
139 .LENDCODE:
140         .size   sem_wait_cleanup,.-sem_wait_cleanup
143         .section .gcc_except_table,"a",@progbits
144 .LexceptSTART:
145         .byte   0xff                            # @LPStart format (omit)
146         .byte   0xff                            # @TType format (omit)
147         .byte   0x01                            # call-site format
148                                                 # DW_EH_PE_uleb128
149         .uleb128 .Lcstend-.Lcstbegin
150 .Lcstbegin:
151         .uleb128 .LcleanupSTART-.LSTARTCODE
152         .uleb128 .LcleanupEND-.LcleanupSTART
153         .uleb128 sem_wait_cleanup-.LSTARTCODE
154         .uleb128  0
155         .uleb128 .LcallUR-.LSTARTCODE
156         .uleb128 .LENDCODE-.LcallUR
157         .uleb128 0
158         .uleb128  0
159 .Lcstend:
162         .section .eh_frame,"a",@progbits
163 .LSTARTFRAME:
164         .long   .LENDCIE-.LSTARTCIE             # Length of the CIE.
165 .LSTARTCIE:
166         .long   0                               # CIE ID.
167         .byte   1                               # Version number.
168 #ifdef SHARED
169         .string "zPLR"                          # NUL-terminated augmentation
170                                                 # string.
171 #else
172         .string "zPL"                           # NUL-terminated augmentation
173                                                 # string.
174 #endif
175         .uleb128 1                              # Code alignment factor.
176         .sleb128 -4                             # Data alignment factor.
177         .byte   8                               # Return address register
178                                                 # column.
179 #ifdef SHARED
180         .uleb128 7                              # Augmentation value length.
181         .byte   0x9b                            # Personality: DW_EH_PE_pcrel
182                                                 # + DW_EH_PE_sdata4
183                                                 # + DW_EH_PE_indirect
184         .long   DW.ref.__gcc_personality_v0-.
185         .byte   0x1b                            # LSDA Encoding: DW_EH_PE_pcrel
186                                                 # + DW_EH_PE_sdata4.
187         .byte   0x1b                            # FDE Encoding: DW_EH_PE_pcrel
188                                                 # + DW_EH_PE_sdata4.
189 #else
190         .uleb128 6                              # Augmentation value length.
191         .byte   0x0                             # Personality: absolute
192         .long   __gcc_personality_v0
193         .byte   0x0                             # LSDA Encoding: absolute
194 #endif
195         .byte 0x0c                              # DW_CFA_def_cfa
196         .uleb128 4
197         .uleb128 4
198         .byte   0x88                            # DW_CFA_offset, column 0x10
199         .uleb128 1
200         .align 4
201 .LENDCIE:
203         .long   .LENDFDE-.LSTARTFDE             # Length of the FDE.
204 .LSTARTFDE:
205         .long   .LSTARTFDE-.LSTARTFRAME         # CIE pointer.
206 #ifdef SHARED
207         .long   .LSTARTCODE-.                   # PC-relative start address
208                                                 # of the code.
209 #else
210         .long   .LSTARTCODE                     # Start address of the code.
211 #endif
212         .long   .LENDCODE-.LSTARTCODE           # Length of the code.
213         .uleb128 4                              # Augmentation size
214 #ifdef SHARED
215         .long   .LexceptSTART-.
216 #else
217         .long   .LexceptSTART
218 #endif
220         .byte   4                               # DW_CFA_advance_loc4
221         .long   .Lpush_ebx-.LSTARTCODE
222         .byte   14                              # DW_CFA_def_cfa_offset
223         .uleb128 8
224         .byte   0x83                            # DW_CFA_offset %ebx
225         .uleb128 2
226         .byte   4                               # DW_CFA_advance_loc4
227         .long   .Lpush_esi-.Lpush_ebx
228         .byte   14                              # DW_CFA_def_cfa_offset
229         .uleb128 12
230         .byte   0x86                            # DW_CFA_offset %esi
231         .uleb128 3
232         .byte   4                               # DW_CFA_advance_loc4
233         .long   .Lsub_esp-.Lpush_esi
234         .byte   14                              # DW_CFA_def_cfa_offset
235         .uleb128 16
236         .byte   4                               # DW_CFA_advance_loc4
237         .long   .Ladd_esp-.Lsub_esp
238         .byte   14                              # DW_CFA_def_cfa_offset
239         .uleb128 4
240         .byte   0xc3                            # DW_CFA_restore %ebx
241         .byte   0xc6                            # DW_CFA_restore %esi
242         .byte   4                               # DW_CFA_advance_loc4
243         .long   .Lafter_ret-.Ladd_esp
244         .byte   14                              # DW_CFA_def_cfa_offset
245         .uleb128 16
246         .byte   0x83                            # DW_CFA_offset %ebx
247         .uleb128 2
248         .byte   0x86                            # DW_CFA_offset %esi
249         .uleb128 3
250         .align  4
251 .LENDFDE:
254 #ifdef SHARED
255         .hidden DW.ref.__gcc_personality_v0
256         .weak   DW.ref.__gcc_personality_v0
257         .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
258         .align  4
259         .type   DW.ref.__gcc_personality_v0, @object
260         .size   DW.ref.__gcc_personality_v0, 4
261 DW.ref.__gcc_personality_v0:
262         .long   __gcc_personality_v0
263 #endif
266 #if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
267         .section ".text.compat", "ax"
268         .global __old_sem_wait
269         .type   __old_sem_wait,@function
270         .align  16
271         cfi_startproc
272 __old_sem_wait:
273         pushl   %ebx
274         cfi_adjust_cfa_offset(4)
275         pushl   %esi
276         cfi_adjust_cfa_offset(4)
277         subl    $4, %esp
278         cfi_adjust_cfa_offset(4)
280         movl    16(%esp), %ebx
281         cfi_offset(ebx, -8)
283         cfi_offset(esi, -12)
284 3:      movl    (%ebx), %eax
285 2:      testl   %eax, %eax
286         je      1f
288         leal    -1(%eax), %edx
289         LOCK
290         cmpxchgl %edx, (%ebx)
291         jne     2b
292         xorl    %eax, %eax
294 5:      movl    4(%esp), %esi
295         movl    8(%esp), %ebx
296         addl    $12, %esp
297         cfi_restore(ebx)
298         cfi_restore(esi)
299         cfi_adjust_cfa_offset(-12)
300         ret
302         cfi_adjust_cfa_offset(12)
303         cfi_offset(ebx, -8)
304         cfi_offset(esi, -12)
305 1:      call    __pthread_enable_asynccancel
306         movl    %eax, (%esp)
308         xorl    %esi, %esi
309         movl    $SYS_futex, %eax
310         movl    %esi, %ecx
311         movl    %esi, %edx
312         ENTER_KERNEL
313         movl    %eax, %esi
315         movl    (%esp), %eax
316         call    __pthread_disable_asynccancel
318         testl   %esi, %esi
319         je      3b
320         cmpl    $-EWOULDBLOCK, %esi
321         je      3b
322         negl    %esi
323 #ifdef PIC
324         SETUP_PIC_REG(bx)
325 #else
326         movl    $4f, %ebx
328 #endif
329         addl    $_GLOBAL_OFFSET_TABLE_, %ebx
330 #ifdef NO_TLS_DIRECT_SEG_REFS
331         movl    errno@gotntpoff(%ebx), %edx
332         addl    %gs:0, %edx
333         movl    %esi, (%edx)
334 #else
335         movl    errno@gotntpoff(%ebx), %edx
336         movl    %esi, %gs:(%edx)
337 #endif
338         orl     $-1, %eax
339         jmp     5b
340         cfi_endproc
341         .size   __old_sem_wait,.-__old_sem_wait
342         compat_symbol(libpthread, __old_sem_wait, sem_wait, GLIBC_2_0)
343 #endif