]>
Commit | Line | Data |
---|---|---|
a2274a08 | 1 | /* Copyright (C) 1992,1997-2003,2004,2005 Free Software Foundation, Inc. |
4cca6b86 UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
4cca6b86 UD |
8 | |
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 | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
4cca6b86 | 13 | |
41bdb6e2 AJ |
14 | You should have received a copy of the GNU Lesser General Public |
15 | License along with the GNU C Library; if not, write to the Free | |
16 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
17 | 02111-1307 USA. */ | |
4cca6b86 | 18 | |
924102e7 UD |
19 | #ifndef _LINUX_POWERPC_SYSDEP_H |
20 | #define _LINUX_POWERPC_SYSDEP_H 1 | |
21 | ||
be9cd93a | 22 | #include <sysdeps/unix/powerpc/sysdep.h> |
00c2b3b9 | 23 | #include <tls.h> |
4cca6b86 | 24 | |
5bfed16d UD |
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 | |
27 | glibc. */ | |
28 | ||
29 | #ifdef __NR_pread64 | |
30 | # ifdef __NR_pread | |
31 | # error "__NR_pread and __NR_pread64 both defined???" | |
32 | # endif | |
33 | # define __NR_pread __NR_pread64 | |
34 | #endif | |
35 | ||
36 | #ifdef __NR_pwrite64 | |
37 | # ifdef __NR_pwrite | |
38 | # error "__NR_pwrite and __NR_pwrite64 both defined???" | |
39 | # endif | |
40 | # define __NR_pwrite __NR_pwrite64 | |
41 | #endif | |
42 | ||
4cca6b86 UD |
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. */ | |
47 | #undef SYS_ify | |
48 | #ifdef __STDC__ | |
49 | # define SYS_ify(syscall_name) __NR_##syscall_name | |
50 | #else | |
51 | # define SYS_ify(syscall_name) __NR_/**/syscall_name | |
52 | #endif | |
53 | ||
735d67f2 RM |
54 | #ifndef __ASSEMBLER__ |
55 | ||
56 | # include <errno.h> | |
57 | ||
8c2e201b UD |
58 | # ifdef SHARED |
59 | # define INLINE_VSYSCALL(name, nr, args...) \ | |
60 | ({ \ | |
61 | __label__ out; \ | |
62 | __label__ iserr; \ | |
63 | INTERNAL_SYSCALL_DECL (sc_err); \ | |
64 | long int sc_ret; \ | |
65 | \ | |
66 | if (__vdso_##name != NULL) \ | |
67 | { \ | |
68 | sc_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, sc_err, nr, ##args); \ | |
69 | if (!INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \ | |
70 | goto out; \ | |
71 | if (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err) != ENOSYS) \ | |
72 | goto iserr; \ | |
73 | } \ | |
74 | \ | |
75 | sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, ##args); \ | |
76 | if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \ | |
77 | { \ | |
78 | iserr: \ | |
79 | __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \ | |
80 | sc_ret = -1L; \ | |
81 | } \ | |
82 | out: \ | |
83 | sc_ret; \ | |
84 | }) | |
85 | # else | |
86 | # define INLINE_VSYSCALL(name, nr, args...) \ | |
87 | INLINE_SYSCALL (name, nr, ##args) | |
88 | # endif | |
89 | ||
90 | # ifdef SHARED | |
91 | # define INTERNAL_VSYSCALL(name, err, nr, args...) \ | |
92 | ({ \ | |
93 | __label__ out; \ | |
94 | long int v_ret; \ | |
95 | \ | |
96 | if (__vdso_##name != NULL) \ | |
97 | { \ | |
98 | v_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, err, nr, ##args); \ | |
99 | if (!INTERNAL_SYSCALL_ERROR_P (v_ret, err) \ | |
100 | || INTERNAL_SYSCALL_ERRNO (v_ret, err) != ENOSYS) \ | |
101 | goto out; \ | |
102 | } \ | |
103 | v_ret = INTERNAL_SYSCALL (name, err, nr, ##args); \ | |
104 | out: \ | |
105 | v_ret; \ | |
106 | }) | |
107 | # else | |
108 | # define INTERNAL_VSYSCALL(name, err, nr, args...) \ | |
109 | INTERNAL_SYSCALL (name, err, nr, ##args) | |
110 | # endif | |
111 | ||
112 | # define INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK(name, err, nr, args...) \ | |
113 | ({ \ | |
114 | long int sc_ret = ENOSYS; \ | |
115 | \ | |
116 | if (__vdso_##name != NULL) \ | |
117 | sc_ret = INTERNAL_VSYSCALL_NCS (__vdso_##name, err, nr, ##args); \ | |
118 | else \ | |
119 | err = 1 << 28; \ | |
120 | sc_ret; \ | |
121 | }) | |
122 | ||
123 | /* List of system calls which are supported as vsyscalls. */ | |
124 | # define HAVE_CLOCK_GETRES_VSYSCALL 1 | |
125 | # define HAVE_CLOCK_GETTIME_VSYSCALL 1 | |
126 | ||
127 | /* Define a macro which expands inline into the wrapper code for a VDSO | |
128 | call. This use is for internal calls that do not need to handle errors | |
129 | normally. It will never touch errno. | |
130 | On powerpc a system call basically clobbers the same registers like a | |
131 | function call, with the exception of LR (which is needed for the | |
132 | "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal | |
133 | an error return status). */ | |
134 | # define INTERNAL_VSYSCALL_NCS(funcptr, err, nr, args...) \ | |
135 | ({ \ | |
136 | register void *r0 __asm__ ("r0"); \ | |
137 | register long int r3 __asm__ ("r3"); \ | |
138 | register long int r4 __asm__ ("r4"); \ | |
139 | register long int r5 __asm__ ("r5"); \ | |
140 | register long int r6 __asm__ ("r6"); \ | |
141 | register long int r7 __asm__ ("r7"); \ | |
142 | register long int r8 __asm__ ("r8"); \ | |
143 | register long int r9 __asm__ ("r9"); \ | |
144 | register long int r10 __asm__ ("r10"); \ | |
145 | register long int r11 __asm__ ("r11"); \ | |
146 | register long int r12 __asm__ ("r12"); \ | |
147 | LOADARGS_##nr (funcptr, args); \ | |
148 | __asm__ __volatile__ \ | |
149 | ("mtctr %0\n\t" \ | |
150 | "bctrl\n\t" \ | |
151 | "mfcr %0" \ | |
152 | : "=&r" (r0), \ | |
153 | "=&r" (r3), "=&r" (r4), "=&r" (r5), "=&r" (r6), "=&r" (r7), \ | |
154 | "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12) \ | |
155 | : ASM_INPUT_##nr \ | |
156 | : "cr0", "ctr", "lr", "memory"); \ | |
157 | err = (long int) r0; \ | |
158 | (int) r3; \ | |
159 | }) | |
160 | ||
735d67f2 | 161 | # undef INLINE_SYSCALL |
704bb2fd RM |
162 | # define INLINE_SYSCALL(name, nr, args...) \ |
163 | ({ \ | |
b398ae3c | 164 | INTERNAL_SYSCALL_DECL (sc_err); \ |
c67a469f | 165 | long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args); \ |
b398ae3c | 166 | if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \ |
704bb2fd | 167 | { \ |
b398ae3c UD |
168 | __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \ |
169 | sc_ret = -1L; \ | |
704bb2fd | 170 | } \ |
b398ae3c | 171 | sc_ret; \ |
735d67f2 RM |
172 | }) |
173 | ||
73e9ae88 UD |
174 | /* Define a macro which expands inline into the wrapper code for a system |
175 | call. This use is for internal calls that do not need to handle errors | |
b398ae3c UD |
176 | normally. It will never touch errno. |
177 | On powerpc a system call basically clobbers the same registers like a | |
178 | function call, with the exception of LR (which is needed for the | |
179 | "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal | |
180 | an error return status). */ | |
73e9ae88 | 181 | |
6aca81bb | 182 | # undef INTERNAL_SYSCALL_DECL |
c67a469f | 183 | # define INTERNAL_SYSCALL_DECL(err) long int err |
6aca81bb | 184 | |
52f3d213 | 185 | # undef INTERNAL_SYSCALL |
2edb61e3 | 186 | # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \ |
73e9ae88 | 187 | ({ \ |
c67a469f UD |
188 | register long int r0 __asm__ ("r0"); \ |
189 | register long int r3 __asm__ ("r3"); \ | |
190 | register long int r4 __asm__ ("r4"); \ | |
191 | register long int r5 __asm__ ("r5"); \ | |
192 | register long int r6 __asm__ ("r6"); \ | |
193 | register long int r7 __asm__ ("r7"); \ | |
194 | register long int r8 __asm__ ("r8"); \ | |
195 | register long int r9 __asm__ ("r9"); \ | |
196 | register long int r10 __asm__ ("r10"); \ | |
197 | register long int r11 __asm__ ("r11"); \ | |
198 | register long int r12 __asm__ ("r12"); \ | |
8c2e201b | 199 | LOADARGS_##nr(name, args); \ |
73e9ae88 | 200 | __asm__ __volatile__ \ |
b398ae3c UD |
201 | ("sc \n\t" \ |
202 | "mfcr %0" \ | |
73e9ae88 UD |
203 | : "=&r" (r0), \ |
204 | "=&r" (r3), "=&r" (r4), "=&r" (r5), "=&r" (r6), "=&r" (r7), \ | |
205 | "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12) \ | |
206 | : ASM_INPUT_##nr \ | |
207 | : "cr0", "ctr", "memory"); \ | |
b398ae3c | 208 | err = r0; \ |
73e9ae88 UD |
209 | (int) r3; \ |
210 | }) | |
2edb61e3 UD |
211 | # define INTERNAL_SYSCALL(name, err, nr, args...) \ |
212 | INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args) | |
6aca81bb | 213 | |
52f3d213 | 214 | # undef INTERNAL_SYSCALL_ERROR_P |
6aca81bb | 215 | # define INTERNAL_SYSCALL_ERROR_P(val, err) \ |
a2274a08 | 216 | ((void) (val), __builtin_expect ((err) & (1 << 28), 0)) |
6aca81bb | 217 | |
52f3d213 | 218 | # undef INTERNAL_SYSCALL_ERRNO |
b398ae3c | 219 | # define INTERNAL_SYSCALL_ERRNO(val, err) (val) |
73e9ae88 | 220 | |
8c2e201b | 221 | # define LOADARGS_0(name, dummy) \ |
2edb61e3 | 222 | r0 = name |
c67a469f UD |
223 | # define LOADARGS_1(name, __arg1) \ |
224 | long int arg1 = (long int) (__arg1); \ | |
8c2e201b | 225 | LOADARGS_0(name, 0); \ |
2edb61e3 | 226 | extern void __illegally_sized_syscall_arg1 (void); \ |
c67a469f | 227 | if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 4) \ |
2edb61e3 | 228 | __illegally_sized_syscall_arg1 (); \ |
c67a469f UD |
229 | r3 = arg1 |
230 | # define LOADARGS_2(name, __arg1, __arg2) \ | |
231 | long int arg2 = (long int) (__arg2); \ | |
232 | LOADARGS_1(name, __arg1); \ | |
2edb61e3 | 233 | extern void __illegally_sized_syscall_arg2 (void); \ |
c67a469f | 234 | if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 4) \ |
2edb61e3 | 235 | __illegally_sized_syscall_arg2 (); \ |
c67a469f UD |
236 | r4 = arg2 |
237 | # define LOADARGS_3(name, __arg1, __arg2, __arg3) \ | |
238 | long int arg3 = (long int) (__arg3); \ | |
239 | LOADARGS_2(name, __arg1, __arg2); \ | |
2edb61e3 | 240 | extern void __illegally_sized_syscall_arg3 (void); \ |
c67a469f | 241 | if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 4) \ |
2edb61e3 | 242 | __illegally_sized_syscall_arg3 (); \ |
c67a469f UD |
243 | r5 = arg3 |
244 | # define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \ | |
245 | long int arg4 = (long int) (__arg4); \ | |
246 | LOADARGS_3(name, __arg1, __arg2, __arg3); \ | |
2edb61e3 | 247 | extern void __illegally_sized_syscall_arg4 (void); \ |
c67a469f | 248 | if (__builtin_classify_type (__arg4) != 5 && sizeof (__arg4) > 4) \ |
2edb61e3 | 249 | __illegally_sized_syscall_arg4 (); \ |
c67a469f UD |
250 | r6 = arg4 |
251 | # define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \ | |
252 | long int arg5 = (long int) (__arg5); \ | |
253 | LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \ | |
2edb61e3 | 254 | extern void __illegally_sized_syscall_arg5 (void); \ |
c67a469f | 255 | if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 4) \ |
2edb61e3 | 256 | __illegally_sized_syscall_arg5 (); \ |
c67a469f UD |
257 | r7 = arg5 |
258 | # define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \ | |
259 | long int arg6 = (long int) (__arg6); \ | |
260 | LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \ | |
2edb61e3 | 261 | extern void __illegally_sized_syscall_arg6 (void); \ |
c67a469f | 262 | if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 4) \ |
2edb61e3 | 263 | __illegally_sized_syscall_arg6 (); \ |
c67a469f | 264 | r8 = arg6 |
735d67f2 | 265 | |
704bb2fd RM |
266 | # define ASM_INPUT_0 "0" (r0) |
267 | # define ASM_INPUT_1 ASM_INPUT_0, "1" (r3) | |
268 | # define ASM_INPUT_2 ASM_INPUT_1, "2" (r4) | |
269 | # define ASM_INPUT_3 ASM_INPUT_2, "3" (r5) | |
270 | # define ASM_INPUT_4 ASM_INPUT_3, "4" (r6) | |
271 | # define ASM_INPUT_5 ASM_INPUT_4, "5" (r7) | |
272 | # define ASM_INPUT_6 ASM_INPUT_5, "6" (r8) | |
735d67f2 RM |
273 | |
274 | #endif /* __ASSEMBLER__ */ | |
275 | ||
276 | ||
00c2b3b9 UD |
277 | /* Pointer mangling support. */ |
278 | #if defined NOT_IN_libc && defined IS_IN_rtld | |
279 | /* We cannot use the thread descriptor because in ld.so we use setjmp | |
280 | earlier than the descriptor is initialized. */ | |
281 | #else | |
282 | # ifdef __ASSEMBLER__ | |
283 | # define PTR_MANGLE(reg, tmpreg) \ | |
284 | lwz tmpreg,POINTER_GUARD(r2); \ | |
285 | xor reg,tmpreg,reg | |
286 | # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg) | |
4e54d7e4 UD |
287 | # define PTR_DEMANGLE2(reg, tmpreg) \ |
288 | xor reg,tmpreg,reg | |
00c2b3b9 UD |
289 | # else |
290 | # define PTR_MANGLE(var) \ | |
db169ed5 | 291 | (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ()) |
00c2b3b9 UD |
292 | # define PTR_DEMANGLE(var) PTR_MANGLE (var) |
293 | # endif | |
294 | #endif | |
295 | ||
b398ae3c | 296 | #endif /* linux/powerpc/powerpc32/sysdep.h */ |