]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/sh/sysdep.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / sh / sysdep.h
1 /* Copyright (C) 1992-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>, August 1995.
4 Changed by Kaz Kojima, <kkojima@rr.iij4u.or.jp>.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
19
20 #ifndef _LINUX_SH_SYSDEP_H
21 #define _LINUX_SH_SYSDEP_H 1
22
23 /* There is some commonality. */
24 #include <sysdeps/unix/sysv/linux/sysdep.h>
25 #include <sysdeps/unix/sh/sysdep.h>
26 #include <tls.h>
27
28 /* For Linux we can use the system call table in the header file
29 /usr/include/asm/unistd.h
30 of the kernel. But these symbols do not follow the SYS_* syntax
31 so we have to redefine the `SYS_ify' macro here. */
32 #undef SYS_ify
33 #define SYS_ify(syscall_name) (__NR_##syscall_name)
34
35
36 #ifdef __ASSEMBLER__
37
38 /* Linux uses a negative return value to indicate syscall errors,
39 unlike most Unices, which use the condition codes' carry flag.
40
41 Since version 2.1 the return value of a system call might be
42 negative even if the call succeeded. E.g., the `lseek' system call
43 might return a large offset. Therefore we must not anymore test
44 for < 0, but test for a real error by making sure the value in R0
45 is a real error number. Linus said he will make sure the no syscall
46 returns a value in -1 .. -4095 as a valid result so we can savely
47 test with -4095. */
48
49 #define _IMM1 #-1
50 #define _IMM12 #-12
51 #undef PSEUDO
52 #define PSEUDO(name, syscall_name, args) \
53 .text; \
54 ENTRY (name); \
55 DO_CALL (syscall_name, args); \
56 mov r0,r1; \
57 mov _IMM12,r2; \
58 shad r2,r1; \
59 not r1,r1; \
60 tst r1,r1; \
61 bf .Lpseudo_end; \
62 SYSCALL_ERROR_HANDLER; \
63 .Lpseudo_end:
64
65 #undef PSEUDO_END
66 #define PSEUDO_END(name) \
67 END (name)
68
69 #undef PSEUDO_NOERRNO
70 #define PSEUDO_NOERRNO(name, syscall_name, args) \
71 .text; \
72 ENTRY (name); \
73 DO_CALL (syscall_name, args)
74
75 #undef PSEUDO_END_NOERRNO
76 #define PSEUDO_END_NOERRNO(name) \
77 END (name)
78
79 #define ret_NOERRNO ret
80
81 #define PSEUDO_ERRVAL(name, syscall_name, args) \
82 .text; \
83 ENTRY (name); \
84 DO_CALL (syscall_name, args);
85
86 #undef PSEUDO_END_ERRVAL
87 #define PSEUDO_END_ERRVAL(name) \
88 END (name)
89
90 #define ret_ERRVAL ret
91
92 #ifndef PIC
93 # define SYSCALL_ERROR_HANDLER \
94 mov.l 0f,r1; \
95 jmp @r1; \
96 mov r0,r4; \
97 .align 2; \
98 0: .long __syscall_error
99 #else
100 # if RTLD_PRIVATE_ERRNO
101 # define SYSCALL_ERROR_HANDLER \
102 neg r0,r1; \
103 mov r12,r2; \
104 cfi_register (r12, r2); \
105 mov.l 0f,r12; \
106 mova 0f,r0; \
107 add r0,r12; \
108 mov.l 1f,r0; \
109 mov.l r1,@(r0,r12); \
110 mov r2,r12; \
111 cfi_restore (r12); \
112 bra .Lpseudo_end; \
113 mov _IMM1,r0; \
114 .align 2; \
115 0: .long _GLOBAL_OFFSET_TABLE_; \
116 1: .long rtld_errno@GOTOFF
117
118 # elif defined _LIBC_REENTRANT
119
120 # if IS_IN (libc)
121 # define SYSCALL_ERROR_ERRNO __libc_errno
122 # else
123 # define SYSCALL_ERROR_ERRNO errno
124 # endif
125 # define SYSCALL_ERROR_HANDLER \
126 neg r0,r1; \
127 mov r12,r2; \
128 cfi_register (r12, r2); \
129 mov.l 0f,r12; \
130 mova 0f,r0; \
131 add r0,r12; \
132 mov.l 1f,r0; \
133 stc gbr, r4; \
134 mov.l @(r0,r12),r0; \
135 mov r2,r12; \
136 cfi_restore (r12); \
137 add r4,r0; \
138 mov.l r1,@r0; \
139 bra .Lpseudo_end; \
140 mov _IMM1,r0; \
141 .align 2; \
142 0: .long _GLOBAL_OFFSET_TABLE_; \
143 1: .long SYSCALL_ERROR_ERRNO@GOTTPOFF
144 # else
145 /* Store (-r0) into errno through the GOT. */
146 # define SYSCALL_ERROR_HANDLER \
147 neg r0,r1; \
148 mov r12,r2; \
149 cfi_register (r12, r2); \
150 mov.l 0f,r12; \
151 mova 0f,r0; \
152 add r0,r12; \
153 mov.l 1f,r0; \
154 mov.l @(r0,r12),r0; \
155 mov r2,r12; \
156 cfi_restore (r12); \
157 mov.l r1,@r0; \
158 bra .Lpseudo_end; \
159 mov _IMM1,r0; \
160 .align 2; \
161 0: .long _GLOBAL_OFFSET_TABLE_; \
162 1: .long errno@GOT
163 # endif /* _LIBC_REENTRANT */
164 #endif /* PIC */
165
166 # ifdef NEED_SYSCALL_INST_PAD
167 # define SYSCALL_INST_PAD \
168 or r0,r0; or r0,r0; or r0,r0; or r0,r0; or r0,r0
169 # else
170 # define SYSCALL_INST_PAD
171 # endif
172
173 #define SYSCALL_INST0 trapa #0x10
174 #define SYSCALL_INST1 trapa #0x11
175 #define SYSCALL_INST2 trapa #0x12
176 #define SYSCALL_INST3 trapa #0x13
177 #define SYSCALL_INST4 trapa #0x14
178 #define SYSCALL_INST5 mov.l @(0,r15),r0; trapa #0x15
179 #define SYSCALL_INST6 mov.l @(0,r15),r0; mov.l @(4,r15),r1; trapa #0x16
180
181 #undef DO_CALL
182 #define DO_CALL(syscall_name, args) \
183 mov.l 1f,r3; \
184 SYSCALL_INST##args; \
185 SYSCALL_INST_PAD; \
186 bra 2f; \
187 nop; \
188 .align 2; \
189 1: .long SYS_ify (syscall_name); \
190 2:
191
192 #else /* not __ASSEMBLER__ */
193
194 #define SYSCALL_INST_STR0 "trapa #0x10\n\t"
195 #define SYSCALL_INST_STR1 "trapa #0x11\n\t"
196 #define SYSCALL_INST_STR2 "trapa #0x12\n\t"
197 #define SYSCALL_INST_STR3 "trapa #0x13\n\t"
198 #define SYSCALL_INST_STR4 "trapa #0x14\n\t"
199 #define SYSCALL_INST_STR5 "trapa #0x15\n\t"
200 #define SYSCALL_INST_STR6 "trapa #0x16\n\t"
201
202 # ifdef NEED_SYSCALL_INST_PAD
203 # define SYSCALL_INST_PAD "\
204 or r0,r0; or r0,r0; or r0,r0; or r0,r0; or r0,r0"
205 # else
206 # define SYSCALL_INST_PAD
207 # endif
208
209 #define ASMFMT_0
210 #define ASMFMT_1 \
211 , "r" (r4)
212 #define ASMFMT_2 \
213 , "r" (r4), "r" (r5)
214 #define ASMFMT_3 \
215 , "r" (r4), "r" (r5), "r" (r6)
216 #define ASMFMT_4 \
217 , "r" (r4), "r" (r5), "r" (r6), "r" (r7)
218 #define ASMFMT_5 \
219 , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0)
220 #define ASMFMT_6 \
221 , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0), "r" (r1)
222 #define ASMFMT_7 \
223 , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0), "r" (r1), "r" (r2)
224
225 #define SUBSTITUTE_ARGS_0()
226 #define SUBSTITUTE_ARGS_1(arg1) \
227 long int _arg1 = (long int) (arg1); \
228 register long int r4 asm ("%r4") = (long int) (_arg1)
229 #define SUBSTITUTE_ARGS_2(arg1, arg2) \
230 long int _arg1 = (long int) (arg1); \
231 long int _arg2 = (long int) (arg2); \
232 register long int r4 asm ("%r4") = (long int) (_arg1); \
233 register long int r5 asm ("%r5") = (long int) (_arg2)
234 #define SUBSTITUTE_ARGS_3(arg1, arg2, arg3) \
235 long int _arg1 = (long int) (arg1); \
236 long int _arg2 = (long int) (arg2); \
237 long int _arg3 = (long int) (arg3); \
238 register long int r4 asm ("%r4") = (long int) (_arg1); \
239 register long int r5 asm ("%r5") = (long int) (_arg2); \
240 register long int r6 asm ("%r6") = (long int) (_arg3)
241 #define SUBSTITUTE_ARGS_4(arg1, arg2, arg3, arg4) \
242 long int _arg1 = (long int) (arg1); \
243 long int _arg2 = (long int) (arg2); \
244 long int _arg3 = (long int) (arg3); \
245 long int _arg4 = (long int) (arg4); \
246 register long int r4 asm ("%r4") = (long int) (_arg1); \
247 register long int r5 asm ("%r5") = (long int) (_arg2); \
248 register long int r6 asm ("%r6") = (long int) (_arg3); \
249 register long int r7 asm ("%r7") = (long int) (_arg4)
250 #define SUBSTITUTE_ARGS_5(arg1, arg2, arg3, arg4, arg5) \
251 long int _arg1 = (long int) (arg1); \
252 long int _arg2 = (long int) (arg2); \
253 long int _arg3 = (long int) (arg3); \
254 long int _arg4 = (long int) (arg4); \
255 long int _arg5 = (long int) (arg5); \
256 register long int r4 asm ("%r4") = (long int) (_arg1); \
257 register long int r5 asm ("%r5") = (long int) (_arg2); \
258 register long int r6 asm ("%r6") = (long int) (_arg3); \
259 register long int r7 asm ("%r7") = (long int) (_arg4); \
260 register long int r0 asm ("%r0") = (long int) (_arg5)
261 #define SUBSTITUTE_ARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
262 long int _arg1 = (long int) (arg1); \
263 long int _arg2 = (long int) (arg2); \
264 long int _arg3 = (long int) (arg3); \
265 long int _arg4 = (long int) (arg4); \
266 long int _arg5 = (long int) (arg5); \
267 long int _arg6 = (long int) (arg6); \
268 register long int r4 asm ("%r4") = (long int)(_arg1); \
269 register long int r5 asm ("%r5") = (long int) (_arg2); \
270 register long int r6 asm ("%r6") = (long int) (_arg3); \
271 register long int r7 asm ("%r7") = (long int) (_arg4); \
272 register long int r0 asm ("%r0") = (long int) (_arg5); \
273 register long int r1 asm ("%r1") = (long int) (_arg6)
274 #define SUBSTITUTE_ARGS_7(arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
275 long int _arg1 = (long int) (arg1); \
276 long int _arg2 = (long int) (arg2); \
277 long int _arg3 = (long int) (arg3); \
278 long int _arg4 = (long int) (arg4); \
279 long int _arg5 = (long int) (arg5); \
280 long int _arg6 = (long int) (arg6); \
281 long int _arg7 = (long int) (arg7); \
282 register long int r4 asm ("%r4") = (long int) (_arg1); \
283 register long int r5 asm ("%r5") = (long int) (_arg2); \
284 register long int r6 asm ("%r6") = (long int) (_arg3); \
285 register long int r7 asm ("%r7") = (long int) (_arg4); \
286 register long int r0 asm ("%r0") = (long int) (_arg5); \
287 register long int r1 asm ("%r1") = (long int) (_arg6); \
288 register long int r2 asm ("%r2") = (long int) (_arg7)
289
290 #undef INLINE_SYSCALL
291 #define INLINE_SYSCALL(name, nr, args...) \
292 ({ \
293 unsigned int resultvar = INTERNAL_SYSCALL (name, , nr, args); \
294 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0)) \
295 { \
296 __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, )); \
297 resultvar = 0xffffffff; \
298 } \
299 (int) resultvar; })
300
301 #undef INTERNAL_SYSCALL
302 #define INTERNAL_SYSCALL(name, err, nr, args...) \
303 ({ \
304 unsigned long int resultvar; \
305 register long int r3 asm ("%r3") = SYS_ify (name); \
306 SUBSTITUTE_ARGS_##nr(args); \
307 \
308 asm volatile (SYSCALL_INST_STR##nr SYSCALL_INST_PAD \
309 : "=z" (resultvar) \
310 : "r" (r3) ASMFMT_##nr \
311 : "memory", "t"); \
312 \
313 (int) resultvar; })
314
315 /* The _NCS variant allows non-constant syscall numbers. */
316 #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
317 ({ \
318 unsigned long int resultvar; \
319 register long int r3 asm ("%r3") = (name); \
320 SUBSTITUTE_ARGS_##nr(args); \
321 \
322 asm volatile (SYSCALL_INST_STR##nr SYSCALL_INST_PAD \
323 : "=z" (resultvar) \
324 : "r" (r3) ASMFMT_##nr \
325 : "memory", "t"); \
326 \
327 (int) resultvar; })
328
329 #undef INTERNAL_SYSCALL_DECL
330 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
331
332 #undef INTERNAL_SYSCALL_ERROR_P
333 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
334 ((unsigned int) (val) >= 0xfffff001u)
335
336 #undef INTERNAL_SYSCALL_ERRNO
337 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
338
339 #endif /* __ASSEMBLER__ */
340
341 /* Pointer mangling support. */
342 #if IS_IN (rtld)
343 /* We cannot use the thread descriptor because in ld.so we use setjmp
344 earlier than the descriptor is initialized. Using a global variable
345 is too complicated here since we have no PC-relative addressing mode. */
346 #else
347 # ifdef __ASSEMBLER__
348 # define PTR_MANGLE(reg, tmp) \
349 stc gbr,tmp; mov.l @(POINTER_GUARD,tmp),tmp; xor tmp,reg
350 # define PTR_MANGLE2(reg, tmp) xor tmp,reg
351 # define PTR_DEMANGLE(reg, tmp) PTR_MANGLE (reg, tmp)
352 # define PTR_DEMANGLE2(reg, tmp) PTR_MANGLE2 (reg, tmp)
353 # else
354 # define PTR_MANGLE(var) \
355 (var) = (void *) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
356 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
357 # endif
358 #endif
359
360 #endif /* linux/sh/sysdep.h */