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