or1k: syscall: Pass arguments on the stack
[uclibc-ng.git] / libpthread / nptl / sysdeps / unix / sysv / linux / sh / sem_timedwait.S
blobf8e8013060fa2b0b6c5f68bfbe7d366f2d47e48b
1 /* Copyright (C) 2003, 2004, 2007 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, see
16    <http://www.gnu.org/licenses/>.  */
18 #include <sysdep.h>
19 #include <pthread-errnos.h>
20 #include <tcb-offsets.h>
21 #include <structsem.h>
22 #include <lowlevellock.h>
23 #include "lowlevel-atomic.h"
26 #if VALUE != 0
27 # error "code needs to be rewritten for VALUE != 0"
28 #endif
30         .text
32         .globl  sem_timedwait
33         .type   sem_timedwait,@function
34         .align  5
35 sem_timedwait:
36 .LSTARTCODE:
37         mov.l   @r4, r0
39         tst     r0, r0
40         bt      1f
41         mov     r0, r3
42         mov     r0, r6
43         add     #-1, r3
44         CMPXCHG (r6, @r4, r3, r2)
45         bf/s    2b
46          mov    r2, r0
47         rts
48          mov    #0, r0
51         /* Check whether the timeout value is valid.  */
52         mov.l   r8, @-r15
53 .Lpush_r8:
54         mov.l   r9, @-r15
55 .Lpush_r9:
56         mov.l   r10, @-r15
57 .Lpush_r10:
58         mov.l   r12, @-r15
59 .Lpush_r12:
60         sts.l   pr, @-r15
61 .Lpush_pr:
62         add     #-8, r15
63 .Lalloc:
64         mov     r4, r8
65         mov     r5, r9
67         /* Check for invalid nanosecond field.  */
68         mov.l   @(4,r9), r0
69         mov.l   .L1g, r1
70         cmp/hs  r1, r0
71         bt/s    6f
72          mov    #EINVAL, r0
73         INC (@(NWAITERS,r8),r2)
76         /* Compute relative timeout.  */
77         mov     r15, r4
78         mov     #0, r5
79         mov     #__NR_gettimeofday, r3
80         trapa   #0x12
81         SYSCALL_INST_PAD
83         mov.l   @(4,r15), r0
84         mov.w   .L1k, r1
85         dmulu.l r0, r1          /* Milli seconds to nano seconds.  */
86         mov.l   @r9, r2
87         mov.l   @(4,r9), r3
88         mov.l   @r15, r0
89         sts     macl, r1
90         sub     r0, r2
91         clrt
92         subc    r1, r3
93         bf      5f
94         mov.l   .L1g, r1
95         add     r1, r3
96         add     #-1, r2
98         cmp/pz  r2
99         bf/s    6f              /* Time is already up.  */
100          mov    #ETIMEDOUT, r0
102         /* Store relative timeout.  */
103         mov.l   r2, @r15
104         mov.l   r3, @(4,r15)
106 .LcleanupSTART:
107         mov.l   .Lenable0, r1
108         bsrf    r1
109          nop
110 .Lenable0b:
111         mov     r0, r10
113         mov     r8, r4
114 #if FUTEX_WAIT == 0
115         mov.l   @(PRIVATE,r8), r5
116 #else
117         mov.l   @(PRIVATE,r8), r5
118         mov     #FUTEX_WAIT, r0
119         or      r0, r5
120 #endif
121         mov     #0, r6
122         mov     r15, r7
123         mov     #SYS_futex, r3
124         extu.b  r3, r3
125         trapa   #0x14
126         SYSCALL_INST_PAD
128         mov.l   .Ldisable0, r1
129         mov     r10, r4
130         bsrf    r1
131          mov    r0, r10
132 .Ldisable0b:
133         mov     r10, r0
134 .LcleanupEND:
136         tst     r0, r0
137         bt      9f
138         cmp/eq  #-EWOULDBLOCK, r0
139         bf      3f
141         mov.l   @r8, r0
143         tst     r0, r0
144         bt      7b
146         mov     r0, r3
147         mov     r0, r4
148         add     #-1, r3
149         CMPXCHG (r4, @r8, r3, r2)
150         bf/s    8b
151          mov    r2, r0
153         DEC (@(NWAITERS,r8), r2)
154         mov     #0, r0
157         add     #8, r15
158         lds.l   @r15+, pr
159         mov.l   @r15+, r12
160         mov.l   @r15+, r10
161         mov.l   @r15+, r9
162         mov.l   @r15+, r8
163         rts
164          nop
167         neg     r0, r0
169         mov     r0, r10
170         mova    .Lgot2, r0
171         mov.l   .Lgot2, r12
172         add     r0, r12
174 #if USE___THREAD
175         mov.l   .Lerrno2, r0
176         stc     gbr, r1
177         mov.l   @(r0, r12), r0
178         bra     .Lexit
179          add    r1, r0
180         .align  2
181 .Lerrno2:
182         .long   errno@GOTTPOFF
183 .Lexit:
184 #else
185         mov.l   .Lerrloc2, r1
186         bsrf    r1
187          nop
188 .Lerrloc2b:
189 #endif
190         mov.l   r10, @r0
191         DEC (@(NWAITERS,r8), r2)
192         bra     10b
193          mov    #-1, r0
195 .L1k:
196         .word   1000
197         .align  2
198 .L1g:
199         .long   1000000000
200 .Lgot2:
201         .long   _GLOBAL_OFFSET_TABLE_
202 #if !USE___THREAD
203 .Lerrloc2:
204         .long   __errno_location@PLT-(.Lerrloc2b-.)
205 #endif
206 .Lenable0:
207         .long   __pthread_enable_asynccancel-.Lenable0b
208 .Ldisable0:
209         .long   __pthread_disable_asynccancel-.Ldisable0b
210         .size   sem_timedwait,.-sem_timedwait
212         .type   sem_wait_cleanup,@function
213 sem_wait_cleanup:
214         DEC (@(NWAITERS,r8), r2)
215 .LcallUR:
216         mov.l   .Lresume, r1
217 #ifdef __PIC__
218         add     r12, r1
219 #endif
220         jsr     @r1
221          nop
222         sleep
224         .align  2
225 .Lresume:
226 #ifdef __PIC__
227         .long   _Unwind_Resume@GOTOFF
228 #else
229         .long   _Unwind_Resume
230 #endif
231 .LENDCODE:
232         .size   sem_wait_cleanup,.-sem_wait_cleanup
235         .section .gcc_except_table,"a",@progbits
236 .LexceptSTART:
237         .byte   0xff                            ! @LPStart format (omit)
238         .byte   0xff                            ! @TType format (omit)
239         .byte   0x01                            ! call-site format
240                                                 ! DW_EH_PE_uleb128
241         .uleb128 .Lcstend-.Lcstbegin
242 .Lcstbegin:
243         .uleb128 .LcleanupSTART-.LSTARTCODE
244         .uleb128 .LcleanupEND-.LcleanupSTART
245         .uleb128 sem_wait_cleanup-.LSTARTCODE
246         .uleb128  0
247         .uleb128 .LcallUR-.LSTARTCODE
248         .uleb128 .LENDCODE-.LcallUR
249         .uleb128 0
250         .uleb128  0
251 .Lcstend:
254         .section .eh_frame,"a",@progbits
255 .LSTARTFRAME:
256         .ualong .LENDCIE-.LSTARTCIE             ! Length of the CIE.
257 .LSTARTCIE:
258         .ualong 0                               ! CIE ID.
259         .byte   1                               ! Version number.
260 #ifdef SHARED
261         .string "zPLR"                          ! NUL-terminated augmentation
262                                                 ! string.
263 #else
264         .string "zPL"                           ! NUL-terminated augmentation
265                                                 ! string.
266 #endif
267         .uleb128 1                              ! Code alignment factor.
268         .sleb128 -4                             ! Data alignment factor.
269         .byte   0x11                            ! Return address register
270                                                 ! column.
271 #ifdef SHARED
272         .uleb128 7                              ! Augmentation value length.
273         .byte   0x9b                            ! Personality: DW_EH_PE_pcrel
274                                                 ! + DW_EH_PE_sdata4
275                                                 ! + DW_EH_PE_indirect
276         .ualong DW.ref.__gcc_personality_v0-.
277         .byte   0x1b                            ! LSDA Encoding: DW_EH_PE_pcrel
278                                                 ! + DW_EH_PE_sdata4.
279         .byte   0x1b                            ! FDE Encoding: DW_EH_PE_pcrel
280                                                 ! + DW_EH_PE_sdata4.
281 #else
282         .uleb128 6                              ! Augmentation value length.
283         .byte   0x0                             ! Personality: absolute
284         .ualong __gcc_personality_v0
285         .byte   0x0                             ! LSDA Encoding: absolute
286 #endif
287         .byte 0x0c                              ! DW_CFA_def_cfa
288         .uleb128 0xf
289         .uleb128 0
290         .align 4
291 .LENDCIE:
293         .ualong .LENDFDE-.LSTARTFDE             ! Length of the FDE.
294 .LSTARTFDE:
295         .ualong .LSTARTFDE-.LSTARTFRAME         ! CIE pointer.
296 #ifdef SHARED
297         .ualong .LSTARTCODE-.                   ! PC-relative start address
298                                                 ! of the code.
299 #else
300         .ualong .LSTARTCODE                     ! Start address of the code.
301 #endif
302         .ualong .LENDCODE-.LSTARTCODE           ! Length of the code.
303         .uleb128 4                              ! Augmentation size
304 #ifdef SHARED
305         .ualong .LexceptSTART-.
306 #else
307         .ualong .LexceptSTART
308 #endif
310         .byte   4                               ! DW_CFA_advance_loc4
311         .ualong .Lpush_r8-.LSTARTCODE
312         .byte   14                              ! DW_CFA_def_cfa_offset
313         .uleb128 4
314         .byte   0x88                            ! DW_CFA_offset r8
315         .uleb128 1
316         .byte   4                               ! DW_CFA_advance_loc4
317         .ualong .Lpush_r9-.Lpush_r8
318         .byte   14                              ! DW_CFA_def_cfa_offset
319         .uleb128 8
320         .byte   0x89                            ! DW_CFA_offset r9
321         .uleb128 2
322         .byte   4                               ! DW_CFA_advance_loc4
323         .ualong .Lpush_r10-.Lpush_r9
324         .byte   14                              ! DW_CFA_def_cfa_offset
325         .uleb128 12
326         .byte   0x8a                            ! DW_CFA_offset r10
327         .uleb128 3
328         .byte   4                               ! DW_CFA_advance_loc4
329         .ualong .Lpush_r12-.Lpush_r10
330         .byte   14                              ! DW_CFA_def_cfa_offset
331         .uleb128 16
332         .byte   0x8c                            ! DW_CFA_offset r12
333         .uleb128 4
334         .byte   4                               ! DW_CFA_advance_loc4
335         .ualong .Lpush_pr-.Lpush_r12
336         .byte   14                              ! DW_CFA_def_cfa_offset
337         .uleb128 20
338         .byte   0x91                            ! DW_CFA_offset pr
339         .uleb128 5
340         .byte   4                               ! DW_CFA_advance_loc4
341         .ualong .Lalloc-.Lpush_pr
342         .byte   14                              ! DW_CFA_def_cfa_offset
343         .uleb128 28
344         .align  4
345 .LENDFDE:
348 #ifdef SHARED
349         .hidden DW.ref.__gcc_personality_v0
350         .weak   DW.ref.__gcc_personality_v0
351         .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
352         .align  4
353         .type   DW.ref.__gcc_personality_v0, @object
354         .size   DW.ref.__gcc_personality_v0, 4
355 DW.ref.__gcc_personality_v0:
356         .long   __gcc_personality_v0
357 #endif