Update copyright notices with scripts/update-copyrights
[glibc.git] / nptl / sysdeps / unix / sysv / linux / i386 / i486 / sem_timedwait.S
blob94d052afc00ab242b17cb57a1689e03a90cac12c
1 /* Copyright (C) 2002-2014 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     .Lerrno_exit
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         movl    28(%esp), %ebx  /* Load semaphore address.  */
150         LOCK
151         decl    NWAITERS(%ebx)
152 .Lerrno_exit:
153 #ifdef PIC
154         SETUP_PIC_REG(bx)
155 #else
156         movl    $4f, %ebx
158 #endif
159         addl    $_GLOBAL_OFFSET_TABLE_, %ebx
160 #ifdef NO_TLS_DIRECT_SEG_REFS
161         movl    errno@gotntpoff(%ebx), %edx
162         addl    %gs:0, %edx
163         movl    %esi, (%edx)
164 #else
165         movl    errno@gotntpoff(%ebx), %edx
166         movl    %esi, %gs:(%edx)
167 #endif
169         orl     $-1, %eax
170         jmp     10b
171         .size   sem_timedwait,.-sem_timedwait
174         .type   sem_wait_cleanup,@function
175 sem_wait_cleanup:
176         LOCK
177         decl    NWAITERS(%ebx)
178         movl    %eax, (%esp)
179 .LcallUR:
180         call    _Unwind_Resume@PLT
181         hlt
182 .LENDCODE:
183         .size   sem_wait_cleanup,.-sem_wait_cleanup
186         .section .gcc_except_table,"a",@progbits
187 .LexceptSTART:
188         .byte   0xff                            # @LPStart format (omit)
189         .byte   0xff                            # @TType format (omit)
190         .byte   0x01                            # call-site format
191                                                 # DW_EH_PE_uleb128
192         .uleb128 .Lcstend-.Lcstbegin
193 .Lcstbegin:
194         .uleb128 .LcleanupSTART-.LSTARTCODE
195         .uleb128 .LcleanupEND-.LcleanupSTART
196         .uleb128 sem_wait_cleanup-.LSTARTCODE
197         .uleb128  0
198         .uleb128 .LcallUR-.LSTARTCODE
199         .uleb128 .LENDCODE-.LcallUR
200         .uleb128 0
201         .uleb128  0
202 .Lcstend:
205         .section .eh_frame,"a",@progbits
206 .LSTARTFRAME:
207         .long   .LENDCIE-.LSTARTCIE             # Length of the CIE.
208 .LSTARTCIE:
209         .long   0                               # CIE ID.
210         .byte   1                               # Version number.
211 #ifdef SHARED
212         .string "zPLR"                          # NUL-terminated augmentation
213                                                 # string.
214 #else
215         .string "zPL"                           # NUL-terminated augmentation
216                                                 # string.
217 #endif
218         .uleb128 1                              # Code alignment factor.
219         .sleb128 -4                             # Data alignment factor.
220         .byte   8                               # Return address register
221                                                 # column.
222 #ifdef SHARED
223         .uleb128 7                              # Augmentation value length.
224         .byte   0x9b                            # Personality: DW_EH_PE_pcrel
225                                                 # + DW_EH_PE_sdata4
226                                                 # + DW_EH_PE_indirect
227         .long   DW.ref.__gcc_personality_v0-.
228         .byte   0x1b                            # LSDA Encoding: DW_EH_PE_pcrel
229                                                 # + DW_EH_PE_sdata4.
230         .byte   0x1b                            # FDE Encoding: DW_EH_PE_pcrel
231                                                 # + DW_EH_PE_sdata4.
232 #else
233         .uleb128 6                              # Augmentation value length.
234         .byte   0x0                             # Personality: absolute
235         .long   __gcc_personality_v0
236         .byte   0x0                             # LSDA Encoding: absolute
237 #endif
238         .byte 0x0c                              # DW_CFA_def_cfa
239         .uleb128 4
240         .uleb128 4
241         .byte   0x88                            # DW_CFA_offset, column 0x10
242         .uleb128 1
243         .align 4
244 .LENDCIE:
246         .long   .LENDFDE-.LSTARTFDE             # Length of the FDE.
247 .LSTARTFDE:
248         .long   .LSTARTFDE-.LSTARTFRAME         # CIE pointer.
249 #ifdef SHARED
250         .long   .LSTARTCODE-.                   # PC-relative start address
251                                                 # of the code.
252 #else
253         .long   .LSTARTCODE                     # Start address of the code.
254 #endif
255         .long   .LENDCODE-.LSTARTCODE           # Length of the code.
256         .uleb128 4                              # Augmentation size
257 #ifdef SHARED
258         .long   .LexceptSTART-.
259 #else
260         .long   .LexceptSTART
261 #endif
263         .byte   4                               # DW_CFA_advance_loc4
264         .long   .Lpush_esi-.LSTARTCODE
265         .byte   14                              # DW_CFA_def_cfa_offset
266         .uleb128 8
267         .byte   0x86                            # DW_CFA_offset %esi
268         .uleb128 2
269         .byte   4                               # DW_CFA_advance_loc4
270         .long   .Lpush_edi-.Lpush_esi
271         .byte   14                              # DW_CFA_def_cfa_offset
272         .uleb128 12
273         .byte   0x87                            # DW_CFA_offset %edi
274         .uleb128 3
275         .byte   4                               # DW_CFA_advance_loc4
276         .long   .Lpush_ebx-.Lpush_edi
277         .byte   14                              # DW_CFA_def_cfa_offset
278         .uleb128 16
279         .byte   0x83                            # DW_CFA_offset %ebx
280         .uleb128 4
281         .byte   4                               # DW_CFA_advance_loc4
282         .long   .Lsub_esp-.Lpush_ebx
283         .byte   14                              # DW_CFA_def_cfa_offset
284         .uleb128 28
285         .byte   4                               # DW_CFA_advance_loc4
286         .long   .Ladd_esp-.Lsub_esp
287         .byte   14                              # DW_CFA_def_cfa_offset
288         .uleb128 16
289         .byte   4                               # DW_CFA_advance_loc4
290         .long   .Lpop_ebx-.Ladd_esp
291         .byte   14                              # DW_CFA_def_cfa_offset
292         .uleb128 12
293         .byte   0xc3                            # DW_CFA_restore %ebx
294         .byte   4                               # DW_CFA_advance_loc4
295         .long   .Lpop_edi-.Lpop_ebx
296         .byte   14                              # DW_CFA_def_cfa_offset
297         .uleb128 8
298         .byte   0xc7                            # DW_CFA_restore %edi
299         .byte   4                               # DW_CFA_advance_loc4
300         .long   .Lpop_esi-.Lpop_edi
301         .byte   14                              # DW_CFA_def_cfa_offset
302         .uleb128 4
303         .byte   0xc6                            # DW_CFA_restore %esi
304         .byte   4                               # DW_CFA_advance_loc4
305         .long   .Lafter_ret-.Lpop_esi
306         .byte   14                              # DW_CFA_def_cfa_offset
307         .uleb128 28
308         .byte   0x86                            # DW_CFA_offset %esi
309         .uleb128 2
310         .byte   0x87                            # DW_CFA_offset %edi
311         .uleb128 3
312         .byte   0x83                            # DW_CFA_offset %ebx
313         .uleb128 4
314         .align  4
315 .LENDFDE:
318 #ifdef SHARED
319         .hidden DW.ref.__gcc_personality_v0
320         .weak   DW.ref.__gcc_personality_v0
321         .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
322         .align  4
323         .type   DW.ref.__gcc_personality_v0, @object
324         .size   DW.ref.__gcc_personality_v0, 4
325 DW.ref.__gcc_personality_v0:
326         .long   __gcc_personality_v0
327 #endif