Replace FSF snail mail address with URLs.
[glibc.git] / nptl / sysdeps / unix / sysv / linux / i386 / i486 / sem_timedwait.S
blob4740aee10dae584a3babf731353cf613439565bf
1 /* Copyright (C) 2002-2005, 2007, 2009, 2011-2012 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
31         .text
33         .globl  sem_timedwait
34         .type   sem_timedwait,@function
35         .align  16
36 sem_timedwait:
37 .LSTARTCODE:
38         movl    4(%esp), %ecx
40         movl    (%ecx), %eax
41 2:      testl   %eax, %eax
42         je      1f
44         leal    -1(%eax), %edx
45         LOCK
46         cmpxchgl %edx, (%ecx)
47         jne     2b
49         xorl    %eax, %eax
50         ret
52         /* Check whether the timeout value is valid.  */
53 1:      pushl   %esi
54 .Lpush_esi:
55         pushl   %edi
56 .Lpush_edi:
57         pushl   %ebx
58 .Lpush_ebx:
59         subl    $12, %esp
60 .Lsub_esp:
62         movl    32(%esp), %edi
64         /* Check for invalid nanosecond field.  */
65         cmpl    $1000000000, 4(%edi)
66         movl    $EINVAL, %esi
67         jae     6f
69         LOCK
70         incl    NWAITERS(%ecx)
72 7:      xorl    %ecx, %ecx
73         movl    %esp, %ebx
74         movl    %ecx, %edx
75         movl    $__NR_gettimeofday, %eax
76         ENTER_KERNEL
78         /* Compute relative timeout.  */
79         movl    4(%esp), %eax
80         movl    $1000, %edx
81         mul     %edx            /* Milli seconds to nano seconds.  */
82         movl    (%edi), %ecx
83         movl    4(%edi), %edx
84         subl    (%esp), %ecx
85         subl    %eax, %edx
86         jns     5f
87         addl    $1000000000, %edx
88         subl    $1, %ecx
89 5:      testl   %ecx, %ecx
90         movl    $ETIMEDOUT, %esi
91         js      6f              /* Time is already up.  */
93         movl    %ecx, (%esp)    /* Store relative timeout.  */
94         movl    %edx, 4(%esp)
96 .LcleanupSTART:
97         call    __pthread_enable_asynccancel
98         movl    %eax, 8(%esp)
100         movl    28(%esp), %ebx  /* Load semaphore address.  */
101 #if FUTEX_WAIT == 0
102         movl    PRIVATE(%ebx), %ecx
103 #else
104         movl    $FUTEX_WAIT, %ecx
105         orl     PRIVATE(%ebx), %ecx
106 #endif
107         movl    %esp, %esi
108         xorl    %edx, %edx
109         movl    $SYS_futex, %eax
110         ENTER_KERNEL
111         movl    %eax, %esi
113         movl    8(%esp), %eax
114         call    __pthread_disable_asynccancel
115 .LcleanupEND:
117         testl   %esi, %esi
118         je      9f
119         cmpl    $-EWOULDBLOCK, %esi
120         jne     3f
122 9:      movl    (%ebx), %eax
123 8:      testl   %eax, %eax
124         je      7b
126         leal    -1(%eax), %ecx
127         LOCK
128         cmpxchgl %ecx, (%ebx)
129         jne     8b
131         xorl    %eax, %eax
133         LOCK
134         decl    NWAITERS(%ebx)
136 10:     addl    $12, %esp
137 .Ladd_esp:
138         popl    %ebx
139 .Lpop_ebx:
140         popl    %edi
141 .Lpop_edi:
142         popl    %esi
143 .Lpop_esi:
144         ret
146 .Lafter_ret:
147 3:      negl    %esi
149 #ifdef PIC
150         SETUP_PIC_REG(bx)
151 #else
152         movl    $4f, %ebx
154 #endif
155         addl    $_GLOBAL_OFFSET_TABLE_, %ebx
156 #ifdef NO_TLS_DIRECT_SEG_REFS
157         movl    errno@gotntpoff(%ebx), %edx
158         addl    %gs:0, %edx
159         movl    %esi, (%edx)
160 #else
161         movl    errno@gotntpoff(%ebx), %edx
162         movl    %esi, %gs:(%edx)
163 #endif
165         movl    28(%esp), %ebx  /* Load semaphore address.  */
166         orl     $-1, %eax
167         jmp     10b
168         .size   sem_timedwait,.-sem_timedwait
171         .type   sem_wait_cleanup,@function
172 sem_wait_cleanup:
173         LOCK
174         decl    NWAITERS(%ebx)
175         movl    %eax, (%esp)
176 .LcallUR:
177         call    _Unwind_Resume@PLT
178         hlt
179 .LENDCODE:
180         .size   sem_wait_cleanup,.-sem_wait_cleanup
183         .section .gcc_except_table,"a",@progbits
184 .LexceptSTART:
185         .byte   0xff                            # @LPStart format (omit)
186         .byte   0xff                            # @TType format (omit)
187         .byte   0x01                            # call-site format
188                                                 # DW_EH_PE_uleb128
189         .uleb128 .Lcstend-.Lcstbegin
190 .Lcstbegin:
191         .uleb128 .LcleanupSTART-.LSTARTCODE
192         .uleb128 .LcleanupEND-.LcleanupSTART
193         .uleb128 sem_wait_cleanup-.LSTARTCODE
194         .uleb128  0
195         .uleb128 .LcallUR-.LSTARTCODE
196         .uleb128 .LENDCODE-.LcallUR
197         .uleb128 0
198         .uleb128  0
199 .Lcstend:
202         .section .eh_frame,"a",@progbits
203 .LSTARTFRAME:
204         .long   .LENDCIE-.LSTARTCIE             # Length of the CIE.
205 .LSTARTCIE:
206         .long   0                               # CIE ID.
207         .byte   1                               # Version number.
208 #ifdef SHARED
209         .string "zPLR"                          # NUL-terminated augmentation
210                                                 # string.
211 #else
212         .string "zPL"                           # NUL-terminated augmentation
213                                                 # string.
214 #endif
215         .uleb128 1                              # Code alignment factor.
216         .sleb128 -4                             # Data alignment factor.
217         .byte   8                               # Return address register
218                                                 # column.
219 #ifdef SHARED
220         .uleb128 7                              # Augmentation value length.
221         .byte   0x9b                            # Personality: DW_EH_PE_pcrel
222                                                 # + DW_EH_PE_sdata4
223                                                 # + DW_EH_PE_indirect
224         .long   DW.ref.__gcc_personality_v0-.
225         .byte   0x1b                            # LSDA Encoding: DW_EH_PE_pcrel
226                                                 # + DW_EH_PE_sdata4.
227         .byte   0x1b                            # FDE Encoding: DW_EH_PE_pcrel
228                                                 # + DW_EH_PE_sdata4.
229 #else
230         .uleb128 6                              # Augmentation value length.
231         .byte   0x0                             # Personality: absolute
232         .long   __gcc_personality_v0
233         .byte   0x0                             # LSDA Encoding: absolute
234 #endif
235         .byte 0x0c                              # DW_CFA_def_cfa
236         .uleb128 4
237         .uleb128 4
238         .byte   0x88                            # DW_CFA_offset, column 0x10
239         .uleb128 1
240         .align 4
241 .LENDCIE:
243         .long   .LENDFDE-.LSTARTFDE             # Length of the FDE.
244 .LSTARTFDE:
245         .long   .LSTARTFDE-.LSTARTFRAME         # CIE pointer.
246 #ifdef SHARED
247         .long   .LSTARTCODE-.                   # PC-relative start address
248                                                 # of the code.
249 #else
250         .long   .LSTARTCODE                     # Start address of the code.
251 #endif
252         .long   .LENDCODE-.LSTARTCODE           # Length of the code.
253         .uleb128 4                              # Augmentation size
254 #ifdef SHARED
255         .long   .LexceptSTART-.
256 #else
257         .long   .LexceptSTART
258 #endif
260         .byte   4                               # DW_CFA_advance_loc4
261         .long   .Lpush_esi-.LSTARTCODE
262         .byte   14                              # DW_CFA_def_cfa_offset
263         .uleb128 8
264         .byte   0x86                            # DW_CFA_offset %esi
265         .uleb128 2
266         .byte   4                               # DW_CFA_advance_loc4
267         .long   .Lpush_edi-.Lpush_esi
268         .byte   14                              # DW_CFA_def_cfa_offset
269         .uleb128 12
270         .byte   0x87                            # DW_CFA_offset %edi
271         .uleb128 3
272         .byte   4                               # DW_CFA_advance_loc4
273         .long   .Lpush_ebx-.Lpush_edi
274         .byte   14                              # DW_CFA_def_cfa_offset
275         .uleb128 16
276         .byte   0x83                            # DW_CFA_offset %ebx
277         .uleb128 4
278         .byte   4                               # DW_CFA_advance_loc4
279         .long   .Lsub_esp-.Lpush_ebx
280         .byte   14                              # DW_CFA_def_cfa_offset
281         .uleb128 28
282         .byte   4                               # DW_CFA_advance_loc4
283         .long   .Ladd_esp-.Lsub_esp
284         .byte   14                              # DW_CFA_def_cfa_offset
285         .uleb128 16
286         .byte   4                               # DW_CFA_advance_loc4
287         .long   .Lpop_ebx-.Ladd_esp
288         .byte   14                              # DW_CFA_def_cfa_offset
289         .uleb128 12
290         .byte   0xc3                            # DW_CFA_restore %ebx
291         .byte   4                               # DW_CFA_advance_loc4
292         .long   .Lpop_edi-.Lpop_ebx
293         .byte   14                              # DW_CFA_def_cfa_offset
294         .uleb128 8
295         .byte   0xc7                            # DW_CFA_restore %edi
296         .byte   4                               # DW_CFA_advance_loc4
297         .long   .Lpop_esi-.Lpop_edi
298         .byte   14                              # DW_CFA_def_cfa_offset
299         .uleb128 4
300         .byte   0xc6                            # DW_CFA_restore %esi
301         .byte   4                               # DW_CFA_advance_loc4
302         .long   .Lafter_ret-.Lpop_esi
303         .byte   14                              # DW_CFA_def_cfa_offset
304         .uleb128 28
305         .byte   0x86                            # DW_CFA_offset %esi
306         .uleb128 2
307         .byte   0x87                            # DW_CFA_offset %edi
308         .uleb128 3
309         .byte   0x83                            # DW_CFA_offset %ebx
310         .uleb128 4
311         .align  4
312 .LENDFDE:
315 #ifdef SHARED
316         .hidden DW.ref.__gcc_personality_v0
317         .weak   DW.ref.__gcc_personality_v0
318         .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
319         .align  4
320         .type   DW.ref.__gcc_personality_v0, @object
321         .size   DW.ref.__gcc_personality_v0, 4
322 DW.ref.__gcc_personality_v0:
323         .long   __gcc_personality_v0
324 #endif