2.9
[glibc/nacl-glibc.git] / nptl / sysdeps / unix / sysv / linux / sh / sem_wait.S
blob6ef7fcf0cbd3217caf81fbcfda30c53cc7cba5c2
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, 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 <structsem.h>
24 #include <lowlevellock.h>
25 #include "lowlevel-atomic.h"
28 #if VALUE != 0
29 # error "code needs to be rewritten for VALUE != 0"
30 #endif
32         .text
34         .globl  __new_sem_wait
35         .type   __new_sem_wait,@function
36         .align  5
37 __new_sem_wait:
38 .LSTARTCODE:
39         mov.l   r8, @-r15
40 .Lpush_r8:
41         mov.l   r10, @-r15
42 .Lpush_r10:
43         mov.l   r12, @-r15
44 .Lpush_r12:
45         sts.l   pr, @-r15
46 .Lpush_pr:
47         mov     r4, r8
49         mov.l   @r8, r0
51         tst     r0, r0
52         bt      1f
53         mov     r0, r3
54         mov     r0, r4
55         add     #-1, r3
56         CMPXCHG (r4, @r8, r3, r2)
57         bf/s    2b
58          mov    r2, r0
60         mov     #0, r0
62         lds.l   @r15+, pr
63         mov.l   @r15+, r12
64         mov.l   @r15+, r10
65         rts
66          mov.l  @r15+, r8
68 .Lafter_ret:
70         INC (@(NWAITERS,r8),r2)
71         
72 .LcleanupSTART:
74         mov.l   .Lenable0, r1
75         bsrf    r1
76          nop
77 .Lenable0b:
78         mov     r0, r10
80         mov     r8, r4
81 #if FUTEX_WAIT == 0
82         mov.l   @(PRIVATE,r8), r5
83 #else
84         mov.l   @(PRIVATE,r8), r5
85         mov     #FUTEX_WAIT, r0
86         or      r0, r5
87 #endif
88         mov     #0, r6
89         mov     #0, r7
90         mov     #SYS_futex, r3
91         extu.b  r3, r3
92         trapa   #0x14
93         SYSCALL_INST_PAD
95         mov.l   .Ldisable0, r1
96         mov     r10, r4
97         bsrf    r1
98          mov    r0, r10
99 .Ldisable0b:    
100         mov     r10, r0
101 .LcleanupEND:
103         tst     r0, r0
104         bt      3f
105         cmp/eq  #-EWOULDBLOCK, r0
106         bf      4f
109         mov.l   @r8, r0
111         tst     r0, r0
112         bt      6b
114         mov     r0, r3
115         mov     r0, r4
116         add     #-1, r3
117         CMPXCHG (r4, @r8, r3, r2)
118         bf/s    5b
119          mov    r2, r0
121         DEC (@(NWAITERS,r8), r2)
122         bra     7b
123          nop
126         neg     r0, r0
127         mov     r0, r4
128         DEC (@(NWAITERS,r8), r2)
129         mov     r4, r8
130         mova    .Lgot0, r0
131         mov.l   .Lgot0, r12
132         add     r0, r12
134 #if USE___THREAD
135         mov.l   .Lerrno0, r0
136         stc     gbr, r1
137         mov.l   @(r0, r12), r0
138         bra     .Lexit
139          add    r1, r0
140         .align  2
141 .Lerrno0:
142         .long   errno@GOTTPOFF
143 .Lexit:
144 #else
145         mov.l   .Lerrloc0, r1
146         bsrf    r1
147          nop
148 .Lerrloc0b:
149 #endif
150         mov.l   r8, @r0
151         bra     9b
152          mov    #-1, r0
154         .align  2
155 .Lgot0:
156         .long   _GLOBAL_OFFSET_TABLE_
157 #if !USE___THREAD
158 .Lerrloc0:
159         .long   __errno_location@PLT-(.Lerrloc0b-.)
160 #endif
161 .Lenable0:
162         .long   __pthread_enable_asynccancel-.Lenable0b
163 .Ldisable0:
164         .long   __pthread_disable_asynccancel-.Ldisable0b
165         .size   __new_sem_wait,.-__new_sem_wait
166         versioned_symbol(libpthread, __new_sem_wait, sem_wait, GLIBC_2_1)
169         .type   sem_wait_cleanup,@function
170 sem_wait_cleanup:
171         DEC (@(NWAITERS,r8), r2)
172 .LcallUR:
173         mov.l   .Lresume, r1
174 #ifdef PIC
175         add     r12, r1
176 #endif
177         jsr     @r1
178          nop
179         sleep
181         .align  2
182 .Lresume:
183 #ifdef PIC
184         .long   _Unwind_Resume@GOTOFF
185 #else
186         .long   _Unwind_Resume
187 #endif
188 .LENDCODE:
189         .size   sem_wait_cleanup,.-sem_wait_cleanup
192         .section .gcc_except_table,"a",@progbits
193 .LexceptSTART:
194         .byte   0xff                            ! @LPStart format (omit)
195         .byte   0xff                            ! @TType format (omit)
196         .byte   0x01                            ! call-site format
197                                                 ! DW_EH_PE_uleb128
198         .uleb128 .Lcstend-.Lcstbegin
199 .Lcstbegin:
200         .uleb128 .LcleanupSTART-.LSTARTCODE
201         .uleb128 .LcleanupEND-.LcleanupSTART
202         .uleb128 sem_wait_cleanup-.LSTARTCODE
203         .uleb128  0
204         .uleb128 .LcallUR-.LSTARTCODE
205         .uleb128 .LENDCODE-.LcallUR
206         .uleb128 0
207         .uleb128  0
208 .Lcstend:
211         .section .eh_frame,"a",@progbits
212 .LSTARTFRAME:
213         .ualong .LENDCIE-.LSTARTCIE             ! Length of the CIE.
214 .LSTARTCIE:
215         .ualong 0                               ! CIE ID.
216         .byte   1                               ! Version number.
217 #ifdef SHARED
218         .string "zPLR"                          ! NUL-terminated augmentation
219                                                 ! string.
220 #else
221         .string "zPL"                           ! NUL-terminated augmentation
222                                                 ! string.
223 #endif
224         .uleb128 1                              ! Code alignment factor.
225         .sleb128 -4                             ! Data alignment factor.
226         .byte   0x11                            ! Return address register
227                                                 ! column.
228 #ifdef SHARED
229         .uleb128 7                              ! Augmentation value length.
230         .byte   0x9b                            ! Personality: DW_EH_PE_pcrel
231                                                 ! + DW_EH_PE_sdata4
232                                                 ! + DW_EH_PE_indirect
233         .ualong DW.ref.__gcc_personality_v0-.
234         .byte   0x1b                            ! LSDA Encoding: DW_EH_PE_pcrel
235                                                 ! + DW_EH_PE_sdata4.
236         .byte   0x1b                            ! FDE Encoding: DW_EH_PE_pcrel
237                                                 ! + DW_EH_PE_sdata4.
238 #else
239         .uleb128 6                              ! Augmentation value length.
240         .byte   0x0                             ! Personality: absolute
241         .ualong __gcc_personality_v0
242         .byte   0x0                             ! LSDA Encoding: absolute
243 #endif
244         .byte 0x0c                              ! DW_CFA_def_cfa
245         .uleb128 0xf
246         .uleb128 0
247         .align 4
248 .LENDCIE:
250         .ualong .LENDFDE-.LSTARTFDE             ! Length of the FDE.
251 .LSTARTFDE:
252         .ualong .LSTARTFDE-.LSTARTFRAME         ! CIE pointer.
253 #ifdef SHARED
254         .ualong .LSTARTCODE-.                   ! PC-relative start address
255                                                 ! of the code.
256 #else
257         .ualong .LSTARTCODE                     ! Start address of the code.
258 #endif
259         .ualong .LENDCODE-.LSTARTCODE           ! Length of the code.
260         .uleb128 4                              ! Augmentation size
261 #ifdef SHARED
262         .ualong .LexceptSTART-.
263 #else
264         .ualong .LexceptSTART
265 #endif
267         .byte   4                               ! DW_CFA_advance_loc4
268         .ualong .Lpush_r8-.LSTARTCODE
269         .byte   14                              ! DW_CFA_def_cfa_offset
270         .uleb128 4
271         .byte   0x88                            ! DW_CFA_offset r8
272         .uleb128 1
273         .byte   4                               ! DW_CFA_advance_loc4
274         .ualong .Lpush_r10-.Lpush_r8
275         .byte   14                              ! DW_CFA_def_cfa_offset
276         .uleb128 8
277         .byte   0x8a                            ! DW_CFA_offset r10
278         .uleb128 2
279         .byte   4                               ! DW_CFA_advance_loc4
280         .ualong .Lpush_r12-.Lpush_r10
281         .byte   14                              ! DW_CFA_def_cfa_offset
282         .uleb128 12
283         .byte   0x8c                            ! DW_CFA_offset r12
284         .uleb128 3
285         .byte   4                               ! DW_CFA_advance_loc4
286         .ualong .Lpush_pr-.Lpush_r12
287         .byte   14                              ! DW_CFA_def_cfa_offset
288         .uleb128 16
289         .byte   0x91                            ! DW_CFA_offset pr
290         .uleb128 4
291         .align  4
292 .LENDFDE:
295 #ifdef SHARED
296         .hidden DW.ref.__gcc_personality_v0
297         .weak   DW.ref.__gcc_personality_v0
298         .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
299         .align  4
300         .type   DW.ref.__gcc_personality_v0, @object
301         .size   DW.ref.__gcc_personality_v0, 4
302 DW.ref.__gcc_personality_v0:
303         .long   __gcc_personality_v0
304 #endif