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