]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
1 /* Copyright (C) 1992-2016 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/sysv/linux/sysdep.h>
22 #include <sysdeps/unix/powerpc/sysdep.h>
25 /* Some systen calls got renamed over time, but retained the same semantics.
26 Handle them here so they can be catched by both C and assembler stubs in
31 # error "__NR_pread and __NR_pread64 both defined???"
33 # define __NR_pread __NR_pread64
38 # error "__NR_pwrite and __NR_pwrite64 both defined???"
40 # define __NR_pwrite __NR_pwrite64
43 /* For Linux we can use the system call table in the header file
44 /usr/include/asm/unistd.h
45 of the kernel. But these symbols do not follow the SYS_* syntax
46 so we have to redefine the `SYS_ify' macro here. */
48 #define SYS_ify(syscall_name) __NR_##syscall_name
54 /* Define a macro which expands inline into the wrapper code for a VDSO
55 call. This use is for internal calls that do not need to handle errors
56 normally. It will never touch errno.
57 On powerpc a system call basically clobbers the same registers like a
58 function call, with the exception of LR (which is needed for the
59 "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
60 an error return status). */
61 # define INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, nr, type, args...) \
63 register void *r0 __asm__ ("r0"); \
64 register long int r3 __asm__ ("r3"); \
65 register long int r4 __asm__ ("r4"); \
66 register long int r5 __asm__ ("r5"); \
67 register long int r6 __asm__ ("r6"); \
68 register long int r7 __asm__ ("r7"); \
69 register long int r8 __asm__ ("r8"); \
70 register long int r9 __asm__ ("r9"); \
71 register long int r10 __asm__ ("r10"); \
72 register long int r11 __asm__ ("r11"); \
73 register long int r12 __asm__ ("r12"); \
74 register type rval __asm__ ("r3"); \
75 LOADARGS_##nr (funcptr, args); \
76 __asm__ __volatile__ \
80 : "+r" (r0), "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7), \
81 "+r" (r8), "+r" (r9), "+r" (r10), "+r" (r11), "+r" (r12) \
82 : : "cr0", "ctr", "lr", "memory"); \
83 err = (long int) r0; \
84 __asm__ __volatile__ ("" : "=r" (rval) : "r" (r3), "r" (r4)); \
88 #define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \
89 INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, nr, long int, args)
91 # undef INLINE_SYSCALL
92 # define INLINE_SYSCALL(name, nr, args...) \
94 INTERNAL_SYSCALL_DECL (sc_err); \
95 long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args); \
96 if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
98 __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
104 /* Define a macro which expands inline into the wrapper code for a system
105 call. This use is for internal calls that do not need to handle errors
106 normally. It will never touch errno.
107 On powerpc a system call basically clobbers the same registers like a
108 function call, with the exception of LR (which is needed for the
109 "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
110 an error return status). */
112 # undef INTERNAL_SYSCALL_DECL
113 # define INTERNAL_SYSCALL_DECL(err) long int err __attribute__ ((unused))
115 # undef INTERNAL_SYSCALL
116 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
118 register long int r0 __asm__ ("r0"); \
119 register long int r3 __asm__ ("r3"); \
120 register long int r4 __asm__ ("r4"); \
121 register long int r5 __asm__ ("r5"); \
122 register long int r6 __asm__ ("r6"); \
123 register long int r7 __asm__ ("r7"); \
124 register long int r8 __asm__ ("r8"); \
125 register long int r9 __asm__ ("r9"); \
126 register long int r10 __asm__ ("r10"); \
127 register long int r11 __asm__ ("r11"); \
128 register long int r12 __asm__ ("r12"); \
129 LOADARGS_##nr(name, args); \
131 __asm__ __volatile__ \
135 "=&r" (r3), "=&r" (r4), "=&r" (r5), "=&r" (r6), "=&r" (r7), \
136 "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12) \
138 : "cr0", "ctr", "memory"); \
142 # define INTERNAL_SYSCALL(name, err, nr, args...) \
143 INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
145 # undef INTERNAL_SYSCALL_ERROR_P
146 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
147 ((void) (val), __builtin_expect ((err) & (1 << 28), 0))
149 # undef INTERNAL_SYSCALL_ERRNO
150 # define INTERNAL_SYSCALL_ERRNO(val, err) (val)
152 # define INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK(name, err, type, nr, args...) \
154 type sc_ret = ENOSYS; \
156 __typeof (__vdso_##name) vdsop = __vdso_##name; \
157 PTR_DEMANGLE (vdsop); \
160 INTERNAL_VSYSCALL_CALL_TYPE (vdsop, err, nr, type, ##args); \
166 /* List of system calls which are supported as vsyscalls. */
167 # define HAVE_CLOCK_GETRES_VSYSCALL 1
168 # define HAVE_CLOCK_GETTIME_VSYSCALL 1
169 # define HAVE_GETCPU_VSYSCALL 1
172 # define LOADARGS_0(name, dummy) \
174 # define LOADARGS_1(name, __arg1) \
175 long int arg1 = (long int) (__arg1); \
176 LOADARGS_0(name, 0); \
177 extern void __illegally_sized_syscall_arg1 (void); \
178 if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 4) \
179 __illegally_sized_syscall_arg1 (); \
181 # define LOADARGS_2(name, __arg1, __arg2) \
182 long int arg2 = (long int) (__arg2); \
183 LOADARGS_1(name, __arg1); \
184 extern void __illegally_sized_syscall_arg2 (void); \
185 if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 4) \
186 __illegally_sized_syscall_arg2 (); \
188 # define LOADARGS_3(name, __arg1, __arg2, __arg3) \
189 long int arg3 = (long int) (__arg3); \
190 LOADARGS_2(name, __arg1, __arg2); \
191 extern void __illegally_sized_syscall_arg3 (void); \
192 if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 4) \
193 __illegally_sized_syscall_arg3 (); \
195 # define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \
196 long int arg4 = (long int) (__arg4); \
197 LOADARGS_3(name, __arg1, __arg2, __arg3); \
198 extern void __illegally_sized_syscall_arg4 (void); \
199 if (__builtin_classify_type (__arg4) != 5 && sizeof (__arg4) > 4) \
200 __illegally_sized_syscall_arg4 (); \
202 # define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
203 long int arg5 = (long int) (__arg5); \
204 LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \
205 extern void __illegally_sized_syscall_arg5 (void); \
206 if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 4) \
207 __illegally_sized_syscall_arg5 (); \
209 # define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
210 long int arg6 = (long int) (__arg6); \
211 LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
212 extern void __illegally_sized_syscall_arg6 (void); \
213 if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 4) \
214 __illegally_sized_syscall_arg6 (); \
217 # define ASM_INPUT_0 "0" (r0)
218 # define ASM_INPUT_1 ASM_INPUT_0, "1" (r3)
219 # define ASM_INPUT_2 ASM_INPUT_1, "2" (r4)
220 # define ASM_INPUT_3 ASM_INPUT_2, "3" (r5)
221 # define ASM_INPUT_4 ASM_INPUT_3, "4" (r6)
222 # define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
223 # define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
225 #endif /* __ASSEMBLER__ */
228 /* Pointer mangling support. */
230 /* We cannot use the thread descriptor because in ld.so we use setjmp
231 earlier than the descriptor is initialized. */
233 # ifdef __ASSEMBLER__
234 # define PTR_MANGLE(reg, tmpreg) \
235 lwz tmpreg,POINTER_GUARD(r2); \
237 # define PTR_MANGLE2(reg, tmpreg) \
239 # define PTR_MANGLE3(destreg, reg, tmpreg) \
240 lwz tmpreg,POINTER_GUARD(r2); \
241 xor destreg,tmpreg,reg
242 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
243 # define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
244 # define PTR_DEMANGLE3(destreg, reg, tmpreg) PTR_MANGLE3 (destreg, reg, tmpreg)
246 # define PTR_MANGLE(var) \
247 (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
248 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
252 #endif /* linux/powerpc/powerpc32/sysdep.h */