Consolidate pwrite/pwrite64 implementations
[glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc32 / sysdep.h
blob273d78babceba4b4f307566d077aa6b29a02862a
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>
23 #include <tls.h>
25 /* For Linux we can use the system call table in the header file
26 /usr/include/asm/unistd.h
27 of the kernel. But these symbols do not follow the SYS_* syntax
28 so we have to redefine the `SYS_ify' macro here. */
29 #undef SYS_ify
30 #define SYS_ify(syscall_name) __NR_##syscall_name
32 #ifndef __ASSEMBLER__
34 # include <errno.h>
36 /* Define a macro which expands inline into the wrapper code for a VDSO
37 call. This use is for internal calls that do not need to handle errors
38 normally. It will never touch errno.
39 On powerpc a system call basically clobbers the same registers like a
40 function call, with the exception of LR (which is needed for the
41 "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
42 an error return status). */
43 # define INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, nr, type, args...) \
44 ({ \
45 register void *r0 __asm__ ("r0"); \
46 register long int r3 __asm__ ("r3"); \
47 register long int r4 __asm__ ("r4"); \
48 register long int r5 __asm__ ("r5"); \
49 register long int r6 __asm__ ("r6"); \
50 register long int r7 __asm__ ("r7"); \
51 register long int r8 __asm__ ("r8"); \
52 register long int r9 __asm__ ("r9"); \
53 register long int r10 __asm__ ("r10"); \
54 register long int r11 __asm__ ("r11"); \
55 register long int r12 __asm__ ("r12"); \
56 register type rval __asm__ ("r3"); \
57 LOADARGS_##nr (funcptr, args); \
58 __asm__ __volatile__ \
59 ("mtctr %0\n\t" \
60 "bctrl\n\t" \
61 "mfcr %0" \
62 : "+r" (r0), "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7), \
63 "+r" (r8), "+r" (r9), "+r" (r10), "+r" (r11), "+r" (r12) \
64 : : "cr0", "ctr", "lr", "memory"); \
65 err = (long int) r0; \
66 __asm__ __volatile__ ("" : "=r" (rval) : "r" (r3), "r" (r4)); \
67 rval; \
70 #define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \
71 INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, nr, long int, args)
73 # undef INLINE_SYSCALL
74 # define INLINE_SYSCALL(name, nr, args...) \
75 ({ \
76 INTERNAL_SYSCALL_DECL (sc_err); \
77 long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args); \
78 if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
79 { \
80 __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
81 sc_ret = -1L; \
82 } \
83 sc_ret; \
86 /* Define a macro which expands inline into the wrapper code for a system
87 call. This use is for internal calls that do not need to handle errors
88 normally. It will never touch errno.
89 On powerpc a system call basically clobbers the same registers like a
90 function call, with the exception of LR (which is needed for the
91 "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
92 an error return status). */
94 # undef INTERNAL_SYSCALL_DECL
95 # define INTERNAL_SYSCALL_DECL(err) long int err __attribute__ ((unused))
97 # undef INTERNAL_SYSCALL
98 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
99 ({ \
100 register long int r0 __asm__ ("r0"); \
101 register long int r3 __asm__ ("r3"); \
102 register long int r4 __asm__ ("r4"); \
103 register long int r5 __asm__ ("r5"); \
104 register long int r6 __asm__ ("r6"); \
105 register long int r7 __asm__ ("r7"); \
106 register long int r8 __asm__ ("r8"); \
107 register long int r9 __asm__ ("r9"); \
108 register long int r10 __asm__ ("r10"); \
109 register long int r11 __asm__ ("r11"); \
110 register long int r12 __asm__ ("r12"); \
111 LOADARGS_##nr(name, args); \
112 ABORT_TRANSACTION; \
113 __asm__ __volatile__ \
114 ("sc \n\t" \
115 "mfcr %0" \
116 : "=&r" (r0), \
117 "=&r" (r3), "=&r" (r4), "=&r" (r5), "=&r" (r6), "=&r" (r7), \
118 "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12) \
119 : ASM_INPUT_##nr \
120 : "cr0", "ctr", "memory"); \
121 err = r0; \
122 (int) r3; \
124 # define INTERNAL_SYSCALL(name, err, nr, args...) \
125 INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
127 # undef INTERNAL_SYSCALL_ERROR_P
128 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
129 ((void) (val), __builtin_expect ((err) & (1 << 28), 0))
131 # undef INTERNAL_SYSCALL_ERRNO
132 # define INTERNAL_SYSCALL_ERRNO(val, err) (val)
134 # define INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK(name, err, type, nr, args...) \
135 ({ \
136 type sc_ret = ENOSYS; \
138 __typeof (__vdso_##name) vdsop = __vdso_##name; \
139 PTR_DEMANGLE (vdsop); \
140 if (vdsop != NULL) \
141 sc_ret = \
142 INTERNAL_VSYSCALL_CALL_TYPE (vdsop, err, nr, type, ##args); \
143 else \
144 err = 1 << 28; \
145 sc_ret; \
148 /* List of system calls which are supported as vsyscalls. */
149 # define HAVE_CLOCK_GETRES_VSYSCALL 1
150 # define HAVE_CLOCK_GETTIME_VSYSCALL 1
151 # define HAVE_GETCPU_VSYSCALL 1
154 # define LOADARGS_0(name, dummy) \
155 r0 = name
156 # define LOADARGS_1(name, __arg1) \
157 long int arg1 = (long int) (__arg1); \
158 LOADARGS_0(name, 0); \
159 extern void __illegally_sized_syscall_arg1 (void); \
160 if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 4) \
161 __illegally_sized_syscall_arg1 (); \
162 r3 = arg1
163 # define LOADARGS_2(name, __arg1, __arg2) \
164 long int arg2 = (long int) (__arg2); \
165 LOADARGS_1(name, __arg1); \
166 extern void __illegally_sized_syscall_arg2 (void); \
167 if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 4) \
168 __illegally_sized_syscall_arg2 (); \
169 r4 = arg2
170 # define LOADARGS_3(name, __arg1, __arg2, __arg3) \
171 long int arg3 = (long int) (__arg3); \
172 LOADARGS_2(name, __arg1, __arg2); \
173 extern void __illegally_sized_syscall_arg3 (void); \
174 if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 4) \
175 __illegally_sized_syscall_arg3 (); \
176 r5 = arg3
177 # define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \
178 long int arg4 = (long int) (__arg4); \
179 LOADARGS_3(name, __arg1, __arg2, __arg3); \
180 extern void __illegally_sized_syscall_arg4 (void); \
181 if (__builtin_classify_type (__arg4) != 5 && sizeof (__arg4) > 4) \
182 __illegally_sized_syscall_arg4 (); \
183 r6 = arg4
184 # define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
185 long int arg5 = (long int) (__arg5); \
186 LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \
187 extern void __illegally_sized_syscall_arg5 (void); \
188 if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 4) \
189 __illegally_sized_syscall_arg5 (); \
190 r7 = arg5
191 # define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
192 long int arg6 = (long int) (__arg6); \
193 LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
194 extern void __illegally_sized_syscall_arg6 (void); \
195 if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 4) \
196 __illegally_sized_syscall_arg6 (); \
197 r8 = arg6
199 # define ASM_INPUT_0 "0" (r0)
200 # define ASM_INPUT_1 ASM_INPUT_0, "1" (r3)
201 # define ASM_INPUT_2 ASM_INPUT_1, "2" (r4)
202 # define ASM_INPUT_3 ASM_INPUT_2, "3" (r5)
203 # define ASM_INPUT_4 ASM_INPUT_3, "4" (r6)
204 # define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
205 # define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
207 #endif /* __ASSEMBLER__ */
210 /* Pointer mangling support. */
211 #if IS_IN (rtld)
212 /* We cannot use the thread descriptor because in ld.so we use setjmp
213 earlier than the descriptor is initialized. */
214 #else
215 # ifdef __ASSEMBLER__
216 # define PTR_MANGLE(reg, tmpreg) \
217 lwz tmpreg,POINTER_GUARD(r2); \
218 xor reg,tmpreg,reg
219 # define PTR_MANGLE2(reg, tmpreg) \
220 xor reg,tmpreg,reg
221 # define PTR_MANGLE3(destreg, reg, tmpreg) \
222 lwz tmpreg,POINTER_GUARD(r2); \
223 xor destreg,tmpreg,reg
224 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
225 # define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
226 # define PTR_DEMANGLE3(destreg, reg, tmpreg) PTR_MANGLE3 (destreg, reg, tmpreg)
227 # else
228 # define PTR_MANGLE(var) \
229 (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
230 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
231 # endif
232 #endif
234 #endif /* linux/powerpc/powerpc32/sysdep.h */