]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libpthread/linuxthreads/sysdeps/unix/sysv/linux/sh/sysdep-cancel.h
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libpthread / linuxthreads / sysdeps / unix / sysv / linux / sh / sysdep-cancel.h
1 /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
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.
8
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.
13
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/>.  */
17
18 #include <sysdep.h>
19 #include <tls.h>
20 #include <pt-machine.h>
21 #ifndef __ASSEMBLER__
22 # include <linuxthreads/internals.h>
23 #endif
24
25 #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
26
27 # define _IMM12 #-12
28 # define _IMM16 #-16
29 # define _IMP16 #16
30 # undef PSEUDO
31 # define PSEUDO(name, syscall_name, args) \
32   .text; \
33   ENTRY (name); \
34     SINGLE_THREAD_P; \
35     bf .Lpseudo_cancel; \
36     DO_CALL (syscall_name, args); \
37     mov r0,r1; \
38     mov _IMM12,r2; \
39     shad r2,r1; \
40     not r1,r1; \
41     tst r1,r1; \
42     bt .Lsyscall_error; \
43     bra .Lpseudo_end; \
44      nop; \
45  .Lpseudo_cancel: \
46     sts.l pr,@-r15; \
47     add _IMM16,r15; \
48     SAVE_ARGS_##args; \
49     CENABLE; \
50     LOAD_ARGS_##args; \
51     add _IMP16,r15; \
52     lds.l @r15+,pr; \
53     DO_CALL(syscall_name, args); \
54     SYSCALL_INST_PAD; \
55     sts.l pr,@-r15; \
56     mov.l r0,@-r15; \
57     CDISABLE; \
58     mov.l @r15+,r0; \
59     lds.l @r15+,pr; \
60     mov r0,r1; \
61     mov _IMM12,r2; \
62     shad r2,r1; \
63     not r1,r1; \
64     tst r1,r1; \
65     bf .Lpseudo_end; \
66  .Lsyscall_error: \
67     SYSCALL_ERROR_HANDLER; \
68  .Lpseudo_end:
69
70 # undef PSEUDO_END
71 # define PSEUDO_END(sym) \
72   END (sym)
73
74 # define SAVE_ARGS_0    /* Nothing.  */
75 # define SAVE_ARGS_1    SAVE_ARGS_0; mov.l r4,@(0,r15)
76 # define SAVE_ARGS_2    SAVE_ARGS_1; mov.l r5,@(4,r15)
77 # define SAVE_ARGS_3    SAVE_ARGS_2; mov.l r6,@(8,r15)
78 # define SAVE_ARGS_4    SAVE_ARGS_3; mov.l r7,@(12,r15)
79 # define SAVE_ARGS_5    SAVE_ARGS_4
80 # define SAVE_ARGS_6    SAVE_ARGS_5
81
82 # define LOAD_ARGS_0    /* Nothing.  */
83 # define LOAD_ARGS_1    LOAD_ARGS_0; mov.l @(0,r15),r4
84 # define LOAD_ARGS_2    LOAD_ARGS_1; mov.l @(4,r15),r5
85 # define LOAD_ARGS_3    LOAD_ARGS_2; mov.l @(8,r15),r6
86 # define LOAD_ARGS_4    LOAD_ARGS_3; mov.l @(12,r15),r7
87 # define LOAD_ARGS_5    LOAD_ARGS_4
88 # define LOAD_ARGS_6    LOAD_ARGS_5
89
90 # ifdef IS_IN_libpthread
91 #  define __local_enable_asynccancel    __pthread_enable_asynccancel
92 #  define __local_disable_asynccancel   __pthread_disable_asynccancel
93 #  define __local_multiple_threads      __pthread_multiple_threads
94 # elif !defined NOT_IN_libc
95 #  define __local_enable_asynccancel    __libc_enable_asynccancel
96 #  define __local_disable_asynccancel   __libc_disable_asynccancel
97 #  define __local_multiple_threads      __libc_multiple_threads
98 # else
99 #  define __local_enable_asynccancel    __librt_enable_asynccancel
100 #  define __local_disable_asynccancel   __librt_disable_asynccancel
101 #  define __local_multiple_threads      __librt_multiple_threads
102 # endif
103
104 # if defined IS_IN_librt && defined __PIC__
105 #  define CENABLE \
106         mov.l r12,@-r15; \
107         mov.l 1f,r12; \
108         mova 1f,r0; \
109         add r0,r12; \
110         mov.l 2f,r0; \
111         bsrf r0; \
112          nop; \
113      0: bra 3f; \
114          mov r0,r2; \
115         .align 2; \
116      1: .long _GLOBAL_OFFSET_TABLE_; \
117      2: .long __local_enable_asynccancel@PLT - (0b-.); \
118      3: mov.l @r15+,r12
119
120 #  define CDISABLE \
121         mov.l r12,@-r15; \
122         mov.l 1f,r12; \
123         mova 1f,r0; \
124         add r0,r12; \
125         mov.l 2f,r0; \
126         bsrf r0; \
127          mov r2,r4; \
128      0: bra 3f; \
129          nop; \
130         .align 2; \
131      1: .long _GLOBAL_OFFSET_TABLE_; \
132      2: .long __local_disable_asynccancel@PLT - (0b-.); \
133      3: mov.l @r15+,r12
134 # else
135 #  define CENABLE \
136         mov.l 1f,r0; \
137         bsrf r0; \
138          nop; \
139      0: bra 2f; \
140          mov r0,r2; \
141         .align 2; \
142      1: .long __local_enable_asynccancel - 0b; \
143      2:
144
145 #  define CDISABLE \
146         mov.l 1f,r0; \
147         bsrf r0; \
148          mov r2,r4; \
149      0: bra 2f; \
150          nop; \
151         .align 2; \
152      1: .long __local_disable_asynccancel - 0b; \
153      2:
154 # endif
155
156 # ifndef __ASSEMBLER__
157 #  if defined FLOATING_STACKS && defined __UCLIBC_HAS_TLS__ && defined __PIC__
158 #   define SINGLE_THREAD_P \
159   __builtin_expect (THREAD_GETMEM (THREAD_SELF, p_multiple_threads) == 0, 1)
160 #  else
161 extern int __local_multiple_threads attribute_hidden;
162 #   define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
163 #  endif
164 # else
165 #  if !defined __PIC__
166 #   define SINGLE_THREAD_P \
167         mov.l 1f,r0; \
168         mov.l @r0,r0; \
169         bra 2f; \
170          tst r0,r0; \
171         .align 2; \
172      1: .long __local_multiple_threads; \
173      2:
174 #  elif defined FLOATING_STACKS && defined __UCLIBC_HAS_TLS__
175 #   define SINGLE_THREAD_P \
176         stc gbr,r0; \
177         mov.w 0f,r1; \
178         sub r1,r0; \
179         mov.l @(MULTIPLE_THREADS_OFFSET,r0),r0; \
180         bra 1f; \
181          tst r0,r0; \
182      0: .word TLS_PRE_TCB_SIZE; \
183      1:
184
185 #  else
186 #   if !defined NOT_IN_libc || defined IS_IN_libpthread
187 #    define SINGLE_THREAD_P \
188         mov r12,r2; \
189         mov.l 0f,r12; \
190         mova 0f,r0; \
191         add r0,r12; \
192         mov.l 1f,r0; \
193         mov.l @(r0,r12),r0; \
194         mov r2,r12; \
195         bra 2f; \
196          tst r0,r0; \
197         .align 2; \
198      0: .long _GLOBAL_OFFSET_TABLE_; \
199      1: .long __local_multiple_threads@GOTOFF; \
200      2:
201 #   else
202 #    define SINGLE_THREAD_P \
203         mov r12,r2; \
204         mov.l 0f,r12; \
205         mova 0f,r0; \
206         add r0,r12; \
207         mov.l 1f,r0; \
208         mov.l @(r0,r12),r0; \
209         mov.l @r0,r0; \
210         mov r2,r12; \
211         bra 2f; \
212          tst r0,r0; \
213         .align 2; \
214      0: .long _GLOBAL_OFFSET_TABLE_; \
215      1: .long __local_multiple_threads@GOT; \
216      2:
217 #   endif
218 #  endif
219 # endif
220
221 #elif !defined __ASSEMBLER__
222
223 /* This code should never be used but we define it anyhow.  */
224 # define SINGLE_THREAD_P (1)
225
226 #endif