OSDN Git Service

don't use __i686 in symbol names as it seems gcc can define it
[uclinux-h8/uClibc.git] / libpthread / nptl / sysdeps / unix / sysv / linux / i386 / pthread_once.S
1 /* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
4
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.
9
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.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #include <unwindbuf.h>
21 #include <sysdep.h>
22
23 #ifndef UP
24 # define LOCK lock
25 #else
26 # define LOCK
27 #endif
28
29 #define FUTEX_WAKE      1
30
31         .comm   __fork_generation, 4, 4
32
33         .text
34
35
36         .globl  __pthread_once
37         .type   __pthread_once,@function
38         .align  16
39         cfi_startproc
40 __pthread_once:
41         movl    4(%esp), %ecx
42         testl   $2, (%ecx)
43         jz      1f
44         xorl    %eax, %eax
45         ret
46
47 1:      pushl   %ebx
48         cfi_adjust_cfa_offset (4)
49         cfi_rel_offset (3, 0)
50         pushl   %esi
51         cfi_adjust_cfa_offset (4)
52         cfi_rel_offset (6, 0)
53         movl    %ecx, %ebx
54         xorl    %esi, %esi
55
56         /* Not yet initialized or initialization in progress.
57            Get the fork generation counter now.  */
58 6:      movl    (%ebx), %eax
59 #ifdef PIC
60         call    __x86.get_pc_thunk.cx
61         addl    $_GLOBAL_OFFSET_TABLE_, %ecx
62 #endif
63
64 5:      movl    %eax, %edx
65
66         testl   $2, %eax
67         jnz     4f
68
69         andl    $3, %edx
70 #ifdef PIC
71         orl     __fork_generation@GOTOFF(%ecx), %edx
72 #else
73         orl     __fork_generation, %edx
74 #endif
75         orl     $1, %edx
76
77         LOCK
78         cmpxchgl %edx, (%ebx)
79         jnz     5b
80
81         /* Check whether another thread already runs the initializer.  */
82         testl   $1, %eax
83         jz      3f      /* No -> do it.  */
84
85         /* Check whether the initializer execution was interrupted
86            by a fork.  */
87         xorl    %edx, %eax
88         testl   $0xfffffffc, %eax
89         jnz     3f      /* Different for generation -> run initializer.  */
90
91         /* Somebody else got here first.  Wait.  */
92         movl    %esi, %ecx              /* movl $FUTEX_WAIT, %ecx */
93         movl    $SYS_futex, %eax
94         ENTER_KERNEL
95         jmp     6b
96
97 3:      /* Call the initializer function after setting up the
98            cancellation handler.  Note that it is not possible here
99            to use the unwind-based cleanup handling.  This would require
100            that the user-provided function and all the code it calls
101            is compiled with exceptions.  Unfortunately this cannot be
102            guaranteed.  */
103         subl    $UNWINDBUFSIZE+8, %esp
104         cfi_adjust_cfa_offset (UNWINDBUFSIZE+8)
105         movl    %ecx, %ebx              /* PIC register value.  */
106
107         leal    8+UWJMPBUF(%esp), %eax
108         movl    $0, 4(%esp)
109         movl    %eax, (%esp)
110         call    __sigsetjmp@PLT
111         testl   %eax, %eax
112         jne     7f
113
114         leal    8(%esp), %eax
115         call    HIDDEN_JUMPTARGET(__pthread_register_cancel)
116
117         /* Call the user-provided initialization function.  */
118         call    *24+UNWINDBUFSIZE(%esp)
119
120         /* Pop the cleanup handler.  */
121         leal    8(%esp), %eax
122         call    HIDDEN_JUMPTARGET(__pthread_unregister_cancel)
123         addl    $UNWINDBUFSIZE+8, %esp
124         cfi_adjust_cfa_offset (-UNWINDBUFSIZE-8)
125
126         /* Sucessful run of the initializer.  Signal that we are done.  */
127         movl    12(%esp), %ebx
128         LOCK
129         addl    $1, (%ebx)
130
131         /* Wake up all other threads.  */
132         movl    $0x7fffffff, %edx
133         movl    $FUTEX_WAKE, %ecx
134         movl    $SYS_futex, %eax
135         ENTER_KERNEL
136
137 4:      popl    %esi
138         cfi_adjust_cfa_offset (-4)
139         cfi_restore (6)
140         popl    %ebx
141         cfi_adjust_cfa_offset (-4)
142         cfi_restore (3)
143         xorl    %eax, %eax
144         ret
145
146 7:      /* __sigsetjmp returned for the second time.  */
147         movl    20+UNWINDBUFSIZE(%esp), %ebx
148         cfi_adjust_cfa_offset (UNWINDBUFSIZE+16)
149         cfi_offset (3, -8)
150         cfi_offset (6, -12)
151         movl    $0, (%ebx)
152
153         movl    $0x7fffffff, %edx
154         movl    $FUTEX_WAKE, %ecx
155         movl    $SYS_futex, %eax
156         ENTER_KERNEL
157
158         leal    8(%esp), %eax
159         call    HIDDEN_JUMPTARGET (__pthread_unwind_next)
160         /* NOTREACHED */
161         hlt
162         cfi_endproc
163         .size   __pthread_once,.-__pthread_once
164
165         .globl  __pthread_once_internal
166 __pthread_once_internal = __pthread_once
167
168         .globl  pthread_once
169 pthread_once = __pthread_once
170
171
172 #ifdef PIC
173         .section .gnu.linkonce.t.__x86.get_pc_thunk.cx,"ax",@progbits
174         .globl  __x86.get_pc_thunk.cx
175         .hidden __x86.get_pc_thunk.cx
176         .type   __x86.get_pc_thunk.cx,@function
177 __x86.get_pc_thunk.cx:
178         movl (%esp), %ecx;
179         ret
180         .size   __x86.get_pc_thunk.cx,.-__x86.get_pc_thunk.cx
181 #endif