Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc32 / sysdep.h
blob8feafb808240c949bd8219bb014a4ba1cb58dadd
1 /* Copyright (C) 1992-2014 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, see
16 <http://www.gnu.org/licenses/>. */
18 #ifndef _LINUX_POWERPC_SYSDEP_H
19 #define _LINUX_POWERPC_SYSDEP_H 1
21 #include <sysdeps/unix/powerpc/sysdep.h>
22 #include <tls.h>
24 /* Some systen calls got renamed over time, but retained the same semantics.
25 Handle them here so they can be catched by both C and assembler stubs in
26 glibc. */
28 #ifdef __NR_pread64
29 # ifdef __NR_pread
30 # error "__NR_pread and __NR_pread64 both defined???"
31 # endif
32 # define __NR_pread __NR_pread64
33 #endif
35 #ifdef __NR_pwrite64
36 # ifdef __NR_pwrite
37 # error "__NR_pwrite and __NR_pwrite64 both defined???"
38 # endif
39 # define __NR_pwrite __NR_pwrite64
40 #endif
42 /* For Linux we can use the system call table in the header file
43 /usr/include/asm/unistd.h
44 of the kernel. But these symbols do not follow the SYS_* syntax
45 so we have to redefine the `SYS_ify' macro here. */
46 #undef SYS_ify
47 #define SYS_ify(syscall_name) __NR_##syscall_name
49 #ifndef __ASSEMBLER__
51 # include <errno.h>
53 # ifdef SHARED
54 # define INLINE_VSYSCALL(name, nr, args...) \
55 ({ \
56 __label__ out; \
57 __label__ iserr; \
58 INTERNAL_SYSCALL_DECL (sc_err); \
59 long int sc_ret; \
61 if (__vdso_##name != NULL) \
62 { \
63 sc_ret = \
64 INTERNAL_VSYSCALL_NCS (__vdso_##name, sc_err, long int, nr, ##args);\
65 if (!INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
66 goto out; \
67 if (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err) != ENOSYS) \
68 goto iserr; \
69 } \
71 sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, ##args); \
72 if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
73 { \
74 iserr: \
75 __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
76 sc_ret = -1L; \
77 } \
78 out: \
79 sc_ret; \
81 # else
82 # define INLINE_VSYSCALL(name, nr, args...) \
83 INLINE_SYSCALL (name, nr, ##args)
84 # endif
86 # ifdef SHARED
87 # define INTERNAL_VSYSCALL(name, err, nr, args...) \
88 ({ \
89 __label__ out; \
90 long int v_ret; \
92 if (__vdso_##name != NULL) \
93 { \
94 v_ret = \
95 INTERNAL_VSYSCALL_NCS (__vdso_##name, err, long int, nr, ##args); \
96 if (!INTERNAL_SYSCALL_ERROR_P (v_ret, err) \
97 || INTERNAL_SYSCALL_ERRNO (v_ret, err) != ENOSYS) \
98 goto out; \
99 } \
100 v_ret = INTERNAL_SYSCALL (name, err, nr, ##args); \
101 out: \
102 v_ret; \
104 # else
105 # define INTERNAL_VSYSCALL(name, err, nr, args...) \
106 INTERNAL_SYSCALL (name, err, nr, ##args)
107 # endif
109 # define INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK(name, err, type, nr, args...) \
110 ({ \
111 type sc_ret = ENOSYS; \
113 if (__vdso_##name != NULL) \
114 sc_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, err, type, nr, ##args); \
115 else \
116 err = 1 << 28; \
117 sc_ret; \
120 /* List of system calls which are supported as vsyscalls. */
121 # define HAVE_CLOCK_GETRES_VSYSCALL 1
122 # define HAVE_CLOCK_GETTIME_VSYSCALL 1
124 /* Define a macro which expands inline into the wrapper code for a VDSO
125 call. This use is for internal calls that do not need to handle errors
126 normally. It will never touch errno.
127 On powerpc a system call basically clobbers the same registers like a
128 function call, with the exception of LR (which is needed for the
129 "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
130 an error return status). */
131 # define INTERNAL_VSYSCALL_NCS(funcptr, err, type, nr, args...) \
132 ({ \
133 register void *r0 __asm__ ("r0"); \
134 register long int r3 __asm__ ("r3"); \
135 register long int r4 __asm__ ("r4"); \
136 register long int r5 __asm__ ("r5"); \
137 register long int r6 __asm__ ("r6"); \
138 register long int r7 __asm__ ("r7"); \
139 register long int r8 __asm__ ("r8"); \
140 register long int r9 __asm__ ("r9"); \
141 register long int r10 __asm__ ("r10"); \
142 register long int r11 __asm__ ("r11"); \
143 register long int r12 __asm__ ("r12"); \
144 register type rval __asm__ ("r3"); \
145 LOADARGS_##nr (funcptr, args); \
146 __asm__ __volatile__ \
147 ("mtctr %0\n\t" \
148 "bctrl\n\t" \
149 "mfcr %0" \
150 : "+r" (r0), "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7), \
151 "+r" (r8), "+r" (r9), "+r" (r10), "+r" (r11), "+r" (r12) \
152 : : "cr0", "ctr", "lr", "memory"); \
153 err = (long int) r0; \
154 __asm__ __volatile__ ("" : "=r" (rval) : "r" (r3), "r" (r4)); \
155 rval; \
158 # undef INLINE_SYSCALL
159 # define INLINE_SYSCALL(name, nr, args...) \
160 ({ \
161 INTERNAL_SYSCALL_DECL (sc_err); \
162 long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args); \
163 if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
165 __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
166 sc_ret = -1L; \
168 sc_ret; \
171 /* Define a macro which expands inline into the wrapper code for a system
172 call. This use is for internal calls that do not need to handle errors
173 normally. It will never touch errno.
174 On powerpc a system call basically clobbers the same registers like a
175 function call, with the exception of LR (which is needed for the
176 "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
177 an error return status). */
179 # undef INTERNAL_SYSCALL_DECL
180 # define INTERNAL_SYSCALL_DECL(err) long int err __attribute__ ((unused))
182 # undef INTERNAL_SYSCALL
183 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
184 ({ \
185 register long int r0 __asm__ ("r0"); \
186 register long int r3 __asm__ ("r3"); \
187 register long int r4 __asm__ ("r4"); \
188 register long int r5 __asm__ ("r5"); \
189 register long int r6 __asm__ ("r6"); \
190 register long int r7 __asm__ ("r7"); \
191 register long int r8 __asm__ ("r8"); \
192 register long int r9 __asm__ ("r9"); \
193 register long int r10 __asm__ ("r10"); \
194 register long int r11 __asm__ ("r11"); \
195 register long int r12 __asm__ ("r12"); \
196 LOADARGS_##nr(name, args); \
197 __asm__ __volatile__ \
198 ("sc \n\t" \
199 "mfcr %0" \
200 : "=&r" (r0), \
201 "=&r" (r3), "=&r" (r4), "=&r" (r5), "=&r" (r6), "=&r" (r7), \
202 "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12) \
203 : ASM_INPUT_##nr \
204 : "cr0", "ctr", "memory"); \
205 err = r0; \
206 (int) r3; \
208 # define INTERNAL_SYSCALL(name, err, nr, args...) \
209 INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
211 # undef INTERNAL_SYSCALL_ERROR_P
212 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
213 ((void) (val), __builtin_expect ((err) & (1 << 28), 0))
215 # undef INTERNAL_SYSCALL_ERRNO
216 # define INTERNAL_SYSCALL_ERRNO(val, err) (val)
218 # define LOADARGS_0(name, dummy) \
219 r0 = name
220 # define LOADARGS_1(name, __arg1) \
221 long int arg1 = (long int) (__arg1); \
222 LOADARGS_0(name, 0); \
223 extern void __illegally_sized_syscall_arg1 (void); \
224 if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 4) \
225 __illegally_sized_syscall_arg1 (); \
226 r3 = arg1
227 # define LOADARGS_2(name, __arg1, __arg2) \
228 long int arg2 = (long int) (__arg2); \
229 LOADARGS_1(name, __arg1); \
230 extern void __illegally_sized_syscall_arg2 (void); \
231 if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 4) \
232 __illegally_sized_syscall_arg2 (); \
233 r4 = arg2
234 # define LOADARGS_3(name, __arg1, __arg2, __arg3) \
235 long int arg3 = (long int) (__arg3); \
236 LOADARGS_2(name, __arg1, __arg2); \
237 extern void __illegally_sized_syscall_arg3 (void); \
238 if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 4) \
239 __illegally_sized_syscall_arg3 (); \
240 r5 = arg3
241 # define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \
242 long int arg4 = (long int) (__arg4); \
243 LOADARGS_3(name, __arg1, __arg2, __arg3); \
244 extern void __illegally_sized_syscall_arg4 (void); \
245 if (__builtin_classify_type (__arg4) != 5 && sizeof (__arg4) > 4) \
246 __illegally_sized_syscall_arg4 (); \
247 r6 = arg4
248 # define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
249 long int arg5 = (long int) (__arg5); \
250 LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \
251 extern void __illegally_sized_syscall_arg5 (void); \
252 if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 4) \
253 __illegally_sized_syscall_arg5 (); \
254 r7 = arg5
255 # define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
256 long int arg6 = (long int) (__arg6); \
257 LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
258 extern void __illegally_sized_syscall_arg6 (void); \
259 if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 4) \
260 __illegally_sized_syscall_arg6 (); \
261 r8 = arg6
263 # define ASM_INPUT_0 "0" (r0)
264 # define ASM_INPUT_1 ASM_INPUT_0, "1" (r3)
265 # define ASM_INPUT_2 ASM_INPUT_1, "2" (r4)
266 # define ASM_INPUT_3 ASM_INPUT_2, "3" (r5)
267 # define ASM_INPUT_4 ASM_INPUT_3, "4" (r6)
268 # define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
269 # define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
271 #endif /* __ASSEMBLER__ */
274 /* Pointer mangling support. */
275 #if defined NOT_IN_libc && defined IS_IN_rtld
276 /* We cannot use the thread descriptor because in ld.so we use setjmp
277 earlier than the descriptor is initialized. */
278 #else
279 # ifdef __ASSEMBLER__
280 # define PTR_MANGLE(reg, tmpreg) \
281 lwz tmpreg,POINTER_GUARD(r2); \
282 xor reg,tmpreg,reg
283 # define PTR_MANGLE2(reg, tmpreg) \
284 xor reg,tmpreg,reg
285 # define PTR_MANGLE3(destreg, reg, tmpreg) \
286 lwz tmpreg,POINTER_GUARD(r2); \
287 xor destreg,tmpreg,reg
288 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
289 # define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
290 # define PTR_DEMANGLE3(destreg, reg, tmpreg) PTR_MANGLE3 (destreg, reg, tmpreg)
291 # else
292 # define PTR_MANGLE(var) \
293 (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
294 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
295 # endif
296 #endif
298 #endif /* linux/powerpc/powerpc32/sysdep.h */