]>
Commit | Line | Data |
---|---|---|
1 | /* Copyright (C) 1992-2019 Free Software Foundation, Inc. | |
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 | |
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. | |
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 | |
12 | Lesser General Public License for more details. | |
13 | ||
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 | <https://www.gnu.org/licenses/>. */ | |
17 | ||
18 | #ifndef _LINUX_POWERPC_SYSDEP_H | |
19 | #define _LINUX_POWERPC_SYSDEP_H 1 | |
20 | ||
21 | #include <sysdeps/unix/sysv/linux/sysdep.h> | |
22 | #include <sysdeps/unix/powerpc/sysdep.h> | |
23 | #include <tls.h> | |
24 | ||
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 | |
31 | ||
32 | #ifndef __ASSEMBLER__ | |
33 | ||
34 | # include <errno.h> | |
35 | ||
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; \ | |
68 | }) | |
69 | ||
70 | #define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \ | |
71 | INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, nr, long int, args) | |
72 | ||
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; \ | |
84 | }) | |
85 | ||
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). */ | |
93 | ||
94 | # undef INTERNAL_SYSCALL_DECL | |
95 | # define INTERNAL_SYSCALL_DECL(err) long int err __attribute__ ((unused)) | |
96 | ||
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 | __asm__ __volatile__ \ | |
113 | ("sc \n\t" \ | |
114 | "mfcr %0" \ | |
115 | : "=&r" (r0), \ | |
116 | "=&r" (r3), "=&r" (r4), "=&r" (r5), "=&r" (r6), "=&r" (r7), \ | |
117 | "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12) \ | |
118 | : ASM_INPUT_##nr \ | |
119 | : "cr0", "ctr", "memory"); \ | |
120 | err = r0; \ | |
121 | (int) r3; \ | |
122 | }) | |
123 | # define INTERNAL_SYSCALL(name, err, nr, args...) \ | |
124 | INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args) | |
125 | ||
126 | # undef INTERNAL_SYSCALL_ERROR_P | |
127 | # define INTERNAL_SYSCALL_ERROR_P(val, err) \ | |
128 | ((void) (val), __builtin_expect ((err) & (1 << 28), 0)) | |
129 | ||
130 | # undef INTERNAL_SYSCALL_ERRNO | |
131 | # define INTERNAL_SYSCALL_ERRNO(val, err) (val) | |
132 | ||
133 | # define INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK(name, err, type, nr, args...) \ | |
134 | ({ \ | |
135 | type sc_ret = ENOSYS; \ | |
136 | \ | |
137 | __typeof (__vdso_##name) vdsop = __vdso_##name; \ | |
138 | PTR_DEMANGLE (vdsop); \ | |
139 | if (vdsop != NULL) \ | |
140 | sc_ret = \ | |
141 | INTERNAL_VSYSCALL_CALL_TYPE (vdsop, err, nr, type, ##args); \ | |
142 | else \ | |
143 | err = 1 << 28; \ | |
144 | sc_ret; \ | |
145 | }) | |
146 | ||
147 | /* List of system calls which are supported as vsyscalls. */ | |
148 | # define HAVE_CLOCK_GETRES_VSYSCALL 1 | |
149 | # define HAVE_CLOCK_GETTIME_VSYSCALL 1 | |
150 | # define HAVE_GETCPU_VSYSCALL 1 | |
151 | ||
152 | ||
153 | # define LOADARGS_0(name, dummy) \ | |
154 | r0 = name | |
155 | # define LOADARGS_1(name, __arg1) \ | |
156 | long int arg1 = (long int) (__arg1); \ | |
157 | LOADARGS_0(name, 0); \ | |
158 | extern void __illegally_sized_syscall_arg1 (void); \ | |
159 | if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 4) \ | |
160 | __illegally_sized_syscall_arg1 (); \ | |
161 | r3 = arg1 | |
162 | # define LOADARGS_2(name, __arg1, __arg2) \ | |
163 | long int arg2 = (long int) (__arg2); \ | |
164 | LOADARGS_1(name, __arg1); \ | |
165 | extern void __illegally_sized_syscall_arg2 (void); \ | |
166 | if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 4) \ | |
167 | __illegally_sized_syscall_arg2 (); \ | |
168 | r4 = arg2 | |
169 | # define LOADARGS_3(name, __arg1, __arg2, __arg3) \ | |
170 | long int arg3 = (long int) (__arg3); \ | |
171 | LOADARGS_2(name, __arg1, __arg2); \ | |
172 | extern void __illegally_sized_syscall_arg3 (void); \ | |
173 | if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 4) \ | |
174 | __illegally_sized_syscall_arg3 (); \ | |
175 | r5 = arg3 | |
176 | # define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \ | |
177 | long int arg4 = (long int) (__arg4); \ | |
178 | LOADARGS_3(name, __arg1, __arg2, __arg3); \ | |
179 | extern void __illegally_sized_syscall_arg4 (void); \ | |
180 | if (__builtin_classify_type (__arg4) != 5 && sizeof (__arg4) > 4) \ | |
181 | __illegally_sized_syscall_arg4 (); \ | |
182 | r6 = arg4 | |
183 | # define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \ | |
184 | long int arg5 = (long int) (__arg5); \ | |
185 | LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \ | |
186 | extern void __illegally_sized_syscall_arg5 (void); \ | |
187 | if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 4) \ | |
188 | __illegally_sized_syscall_arg5 (); \ | |
189 | r7 = arg5 | |
190 | # define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \ | |
191 | long int arg6 = (long int) (__arg6); \ | |
192 | LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \ | |
193 | extern void __illegally_sized_syscall_arg6 (void); \ | |
194 | if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 4) \ | |
195 | __illegally_sized_syscall_arg6 (); \ | |
196 | r8 = arg6 | |
197 | ||
198 | # define ASM_INPUT_0 "0" (r0) | |
199 | # define ASM_INPUT_1 ASM_INPUT_0, "1" (r3) | |
200 | # define ASM_INPUT_2 ASM_INPUT_1, "2" (r4) | |
201 | # define ASM_INPUT_3 ASM_INPUT_2, "3" (r5) | |
202 | # define ASM_INPUT_4 ASM_INPUT_3, "4" (r6) | |
203 | # define ASM_INPUT_5 ASM_INPUT_4, "5" (r7) | |
204 | # define ASM_INPUT_6 ASM_INPUT_5, "6" (r8) | |
205 | ||
206 | #endif /* __ASSEMBLER__ */ | |
207 | ||
208 | ||
209 | /* Pointer mangling support. */ | |
210 | #if IS_IN (rtld) | |
211 | /* We cannot use the thread descriptor because in ld.so we use setjmp | |
212 | earlier than the descriptor is initialized. */ | |
213 | #else | |
214 | # ifdef __ASSEMBLER__ | |
215 | # define PTR_MANGLE(reg, tmpreg) \ | |
216 | lwz tmpreg,POINTER_GUARD(r2); \ | |
217 | xor reg,tmpreg,reg | |
218 | # define PTR_MANGLE2(reg, tmpreg) \ | |
219 | xor reg,tmpreg,reg | |
220 | # define PTR_MANGLE3(destreg, reg, tmpreg) \ | |
221 | lwz tmpreg,POINTER_GUARD(r2); \ | |
222 | xor destreg,tmpreg,reg | |
223 | # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg) | |
224 | # define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg) | |
225 | # define PTR_DEMANGLE3(destreg, reg, tmpreg) PTR_MANGLE3 (destreg, reg, tmpreg) | |
226 | # else | |
227 | # define PTR_MANGLE(var) \ | |
228 | (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ()) | |
229 | # define PTR_DEMANGLE(var) PTR_MANGLE (var) | |
230 | # endif | |
231 | #endif | |
232 | ||
233 | #endif /* linux/powerpc/powerpc32/sysdep.h */ |