Updated to fedora-glibc-20041102T1153
[glibc.git] / nptl / sysdeps / unix / sysv / linux / sh / sem_timedwait.S
blobacb7d0f78bd55d1728f5dc96c3338574f236b801
1 /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
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.
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
19 #include <sysdep.h>
20 #include <shlib-compat.h>
21 #include <pthread-errnos.h>
22 #include <tcb-offsets.h>
23 #include "lowlevel-atomic.h"
26 #define SYS_gettimeofday        __NR_gettimeofday
27 #define SYS_futex               240
28 #define FUTEX_WAIT              0
29 #define FUTEX_WAKE              1
31         .text
33         .globl  sem_timedwait
34         .type   sem_timedwait,@function
35         .align  5
36         cfi_startproc
37 sem_timedwait:
38         /* First check for cancellation.  */
39         stc     gbr, r0
40         mov.w   .Lchand, r1
41         mov.l   @(r0,r1), r0
42         mov     #0xf9, r1
43         and     r1, r0
44         cmp/eq  #8, r0
45         bf      0f
46         bra     10f
47          stc    gbr, r0
49         mov.l   @r4, r0
51         tst     r0, r0
52         bt      1f
53         mov     r0, r3
54         mov     r0, r6
55         add     #-1, r3
56         CMPXCHG (r6, @r4, r3, r2)
57         bf/s    2b
58          mov    r2, r0
59         rts
60          mov    #0, r0
63         /* Check whether the timeout value is valid.  */
64         mov.l   r8, @-r15
65         cfi_adjust_cfa_offset(4)
66         cfi_rel_offset (r8, 0)
67         mov.l   r9, @-r15
68         cfi_adjust_cfa_offset(4)
69         cfi_rel_offset (r9, 0)
70         mov.l   r10, @-r15
71         cfi_adjust_cfa_offset(4)
72         cfi_rel_offset (r10, 0)
73         mov.l   r12, @-r15
74         cfi_adjust_cfa_offset(4)
75         cfi_rel_offset (r12, 0)
76         sts.l   pr, @-r15
77         cfi_adjust_cfa_offset(4)
78         cfi_rel_offset (pr, 0)
79         add     #-8, r15
80         cfi_adjust_cfa_offset(8)
81         mov     r4, r8
82         mov     r5, r9
84         /* Check for invalid nanosecond field.  */
85         mov.l   @(4,r9), r0
86         mov.l   .L1g, r1
87         cmp/hs  r1, r0
88         bt/s    6f
89          mov    #EINVAL, r0
91         mov.l   .Lenable0, r1
92         bsrf    r1
93          nop
94 .Lenable0b:
95         mov     r0, r10
97         /* Compute relative timeout.  */
98         mov     r15, r4
99         mov     #0, r5
100         mov     #SYS_gettimeofday, r3
101         trapa   #0x12
102         SYSCALL_INST_PAD
104         mov.l   @(4,r15), r0
105         mov.w   .L1k, r1
106         dmulu.l r0, r1          /* Milli seconds to nano seconds.  */
107         mov.l   @r9, r2
108         mov.l   @(4,r9), r3
109         mov.l   @r15, r0
110         sts     macl, r1
111         sub     r0, r2
112         clrt
113         subc    r1, r3
114         bf      5f
115         mov.l   .L1g, r1
116         add     r1, r3
117         add     #-1, r2
119         cmp/pz  r2
120         bf/s    6f              /* Time is already up.  */
121          mov    #ETIMEDOUT, r0
123         /* Store relative timeout.  */
124         mov.l   r2, @r15
125         mov.l   r3, @(4,r15)
127         /* Futex call.  */
128         mov     r8, r4
129         mov     #FUTEX_WAIT, r5
130         mov     #0, r6
131         mov     r15, r7
132         mov     #SYS_futex, r3
133         extu.b  r3, r3
134         trapa   #0x14
135         SYSCALL_INST_PAD
137         mov.l   .Ldisable0, r1
138         mov     r10, r4
139         bsrf    r1
140          mov    r0, r10
141 .Ldisable0b:    
142         mov     r10, r0
144         tst     r0, r0
145         bt      9f
146         cmp/eq  #-EWOULDBLOCK, r0
147         bf      3f
149         mov.l   @r8, r0
151         tst     r0, r0
152         bt      7b
154         mov     r0, r3
155         mov     r0, r4
156         add     #-1, r3
157         CMPXCHG (r4, @r8, r3, r2)
158         bf/s    8b
159          mov    r2, r0
161         add     #8, r15
162         lds.l   @r15+, pr
163         mov.l   @r15+, r12
164         mov.l   @r15+, r10
165         mov.l   @r15+, r9
166         mov.l   @r15+, r8
167         rts
168          mov    #0, r0
171         neg     r0, r0
173         mov     r0, r8
174         mova    .Lgot2, r0
175         mov.l   .Lgot2, r12
176         add     r0, r12
178 #if USE___THREAD
179         mov.l   .Lerrno2, r0
180         stc     gbr, r1
181         mov.l   @(r0, r12), r0
182         add     r1, r0
183         mov.l   r8, @r0
184 #else
185         mov.l   .Lerrloc2, r1
186         bsrf    r1
187          nop
188 .Lerrloc2b:
189         mov.l   r8, @r0
190 #endif
191         add     #8, r15
192         lds.l   @r15+, pr
193         mov.l   @r15+, r12
194         mov.l   @r15+, r10
195         mov.l   @r15+, r9
196         mov.l   @r15+, r8
197         rts
198          mov    #-1, r0
201         /* Canceled.  */
202         mov.w   .Lresult, r1
203         mov     #-1, r2
204         mov.l   r2, @(r0,r1)
205         mov.w   .Lchand, r0
206         or.b    #0x10, @(r0,gbr)
207         stc     gbr, r0
208         mov.w   .Lclbuf, r1
209         mov.l   .Lunwind, r2
210         braf    r2
211          mov.l  @(r0,r1), r4
212 .Lunwindb:
213         cfi_endproc
215 .L1k:
216         .word   1000
217 .Lchand:
218         .word   CANCELHANDLING - TLS_PRE_TCB_SIZE
219 .Lresult:
220         .word   RESULT - TLS_PRE_TCB_SIZE
221 .Lclbuf:
222         .word   CLEANUP_JMP_BUF - TLS_PRE_TCB_SIZE
223         .align  2
224 .L1g:
225         .long   1000000000
226 .Lgot2:
227         .long   _GLOBAL_OFFSET_TABLE_
228 #if USE___THREAD
229 .Lerrno2:
230         .long   errno@GOTTPOFF
231 #else
232 .Lerrloc2:
233         .long   __errno_location@PLT-(.Lerrloc2b-.)
234 #endif
235 .Lenable0:
236         .long   __pthread_enable_asynccancel-.Lenable0b
237 .Ldisable0:
238         .long   __pthread_disable_asynccancel-.Ldisable0b
239 .Lunwind:
240         .long   HIDDEN_JUMPTARGET (__pthread_unwind)-.Lunwindb
241         .size   sem_timedwait,.-sem_timedwait