]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/powerpc/sysdep.h
powerpc: Use Linux kABI for syscall return
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / powerpc / sysdep.h
1 /* Syscall definitions, Linux PowerPC generic version.
2 Copyright (C) 2019-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #ifndef _LINUX_POWERPC_SYSDEP_H
20 #define _LINUX_POWERPC_SYSDEP_H 1
21
22 #include <sysdeps/unix/sysv/linux/sysdep.h>
23 #include <sysdeps/unix/powerpc/sysdep.h>
24 #include <tls.h>
25 /* Define __set_errno() for INLINE_SYSCALL macro below. */
26 #include <errno.h>
27
28 /* For Linux we can use the system call table in the header file
29 /usr/include/asm/unistd.h
30 of the kernel. But these symbols do not follow the SYS_* syntax
31 so we have to redefine the `SYS_ify' macro here. */
32 #undef SYS_ify
33 #define SYS_ify(syscall_name) __NR_##syscall_name
34
35 /* Define a macro which expands inline into the wrapper code for a system
36 call. This use is for internal calls that do not need to handle errors
37 normally. It will never touch errno. This returns just what the kernel
38 gave back in the non-error (CR0.SO cleared) case, otherwise (CR0.SO set)
39 the negation of the return value in the kernel gets reverted. */
40
41 #define INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, type, nr, args...) \
42 ({ \
43 register void *r0 __asm__ ("r0"); \
44 register long int r3 __asm__ ("r3"); \
45 register long int r4 __asm__ ("r4"); \
46 register long int r5 __asm__ ("r5"); \
47 register long int r6 __asm__ ("r6"); \
48 register long int r7 __asm__ ("r7"); \
49 register long int r8 __asm__ ("r8"); \
50 register type rval __asm__ ("r3"); \
51 LOADARGS_##nr (funcptr, args); \
52 __asm__ __volatile__ \
53 ("mtctr %0\n\t" \
54 "bctrl\n\t" \
55 "mfcr %0\n\t" \
56 "0:" \
57 : "+r" (r0), "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), \
58 "+r" (r7), "+r" (r8) \
59 : : "r9", "r10", "r11", "r12", "cr0", "ctr", "lr", "memory"); \
60 __asm__ __volatile__ ("" : "=r" (rval) : "r" (r3)); \
61 (long int) r0 & (1 << 28) ? -rval : rval; \
62 })
63
64 #define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \
65 INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, long int, nr, args)
66
67 /* This version is for kernels that implement system calls that
68 behave like function calls as far as register saving. */
69 #undef INLINE_SYSCALL
70 #define INLINE_SYSCALL(name, nr, args...) \
71 ({ \
72 INTERNAL_SYSCALL_DECL (sc_err); \
73 long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args); \
74 if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
75 { \
76 __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
77 sc_ret = -1L; \
78 } \
79 sc_ret; \
80 })
81
82 /* Define a macro which expands inline into the wrapper code for a system
83 call. This use is for internal calls that do not need to handle errors
84 normally. It will never touch errno. This returns just what the kernel
85 gave back in the non-error (CR0.SO cleared) case, otherwise (CR0.SO set)
86 the negation of the return value in the kernel gets reverted. */
87
88 #undef INTERNAL_SYSCALL
89 #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
90 ({ \
91 register long int r0 __asm__ ("r0"); \
92 register long int r3 __asm__ ("r3"); \
93 register long int r4 __asm__ ("r4"); \
94 register long int r5 __asm__ ("r5"); \
95 register long int r6 __asm__ ("r6"); \
96 register long int r7 __asm__ ("r7"); \
97 register long int r8 __asm__ ("r8"); \
98 LOADARGS_##nr (name, ##args); \
99 __asm__ __volatile__ \
100 ("sc\n\t" \
101 "mfcr %0\n\t" \
102 "0:" \
103 : "=&r" (r0), \
104 "=&r" (r3), "=&r" (r4), "=&r" (r5), \
105 "=&r" (r6), "=&r" (r7), "=&r" (r8) \
106 : ASM_INPUT_##nr \
107 : "r9", "r10", "r11", "r12", \
108 "cr0", "ctr", "memory"); \
109 r0 & (1 << 28) ? -r3 : r3; \
110 })
111 #define INTERNAL_SYSCALL(name, err, nr, args...) \
112 INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, args)
113
114 #undef INTERNAL_SYSCALL_DECL
115 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
116
117 #undef INTERNAL_SYSCALL_ERROR_P
118 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
119 ((unsigned long int) (val) > -4096UL)
120
121 #undef INTERNAL_SYSCALL_ERRNO
122 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
123
124 #if defined(__PPC64__) || defined(__powerpc64__)
125 # define SYSCALL_ARG_SIZE 8
126 #else
127 # define SYSCALL_ARG_SIZE 4
128 #endif
129
130 #define LOADARGS_0(name, dummy) \
131 r0 = name
132 #define LOADARGS_1(name, __arg1) \
133 long int arg1 = (long int) (__arg1); \
134 LOADARGS_0(name, 0); \
135 extern void __illegally_sized_syscall_arg1 (void); \
136 if (__builtin_classify_type (__arg1) != 5 \
137 && sizeof (__arg1) > SYSCALL_ARG_SIZE) \
138 __illegally_sized_syscall_arg1 (); \
139 r3 = arg1
140 #define LOADARGS_2(name, __arg1, __arg2) \
141 long int arg2 = (long int) (__arg2); \
142 LOADARGS_1(name, __arg1); \
143 extern void __illegally_sized_syscall_arg2 (void); \
144 if (__builtin_classify_type (__arg2) != 5 \
145 && sizeof (__arg2) > SYSCALL_ARG_SIZE) \
146 __illegally_sized_syscall_arg2 (); \
147 r4 = arg2
148 #define LOADARGS_3(name, __arg1, __arg2, __arg3) \
149 long int arg3 = (long int) (__arg3); \
150 LOADARGS_2(name, __arg1, __arg2); \
151 extern void __illegally_sized_syscall_arg3 (void); \
152 if (__builtin_classify_type (__arg3) != 5 \
153 && sizeof (__arg3) > SYSCALL_ARG_SIZE) \
154 __illegally_sized_syscall_arg3 (); \
155 r5 = arg3
156 #define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \
157 long int arg4 = (long int) (__arg4); \
158 LOADARGS_3(name, __arg1, __arg2, __arg3); \
159 extern void __illegally_sized_syscall_arg4 (void); \
160 if (__builtin_classify_type (__arg4) != 5 \
161 && sizeof (__arg4) > SYSCALL_ARG_SIZE) \
162 __illegally_sized_syscall_arg4 (); \
163 r6 = arg4
164 #define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
165 long int arg5 = (long int) (__arg5); \
166 LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \
167 extern void __illegally_sized_syscall_arg5 (void); \
168 if (__builtin_classify_type (__arg5) != 5 \
169 && sizeof (__arg5) > SYSCALL_ARG_SIZE) \
170 __illegally_sized_syscall_arg5 (); \
171 r7 = arg5
172 #define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
173 long int arg6 = (long int) (__arg6); \
174 LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
175 extern void __illegally_sized_syscall_arg6 (void); \
176 if (__builtin_classify_type (__arg6) != 5 \
177 && sizeof (__arg6) > SYSCALL_ARG_SIZE) \
178 __illegally_sized_syscall_arg6 (); \
179 r8 = arg6
180
181 #define ASM_INPUT_0 "0" (r0)
182 #define ASM_INPUT_1 ASM_INPUT_0, "1" (r3)
183 #define ASM_INPUT_2 ASM_INPUT_1, "2" (r4)
184 #define ASM_INPUT_3 ASM_INPUT_2, "3" (r5)
185 #define ASM_INPUT_4 ASM_INPUT_3, "4" (r6)
186 #define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
187 #define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
188
189
190 /* Pointer mangling support. */
191 #if IS_IN (rtld)
192 /* We cannot use the thread descriptor because in ld.so we use setjmp
193 earlier than the descriptor is initialized. */
194 #else
195 # ifdef __ASSEMBLER__
196 # if defined(__PPC64__) || defined(__powerpc64__)
197 # define LOAD ld
198 # define TPREG r13
199 # else
200 # define LOAD lwz
201 # define TPREG r2
202 # endif
203 # define PTR_MANGLE(reg, tmpreg) \
204 LOAD tmpreg,POINTER_GUARD(TPREG); \
205 xor reg,tmpreg,reg
206 # define PTR_MANGLE2(reg, tmpreg) \
207 xor reg,tmpreg,reg
208 # define PTR_MANGLE3(destreg, reg, tmpreg) \
209 LOAD tmpreg,POINTER_GUARD(TPREG); \
210 xor destreg,tmpreg,reg
211 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
212 # define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
213 # define PTR_DEMANGLE3(destreg, reg, tmpreg) PTR_MANGLE3 (destreg, reg, tmpreg)
214 # else
215 # define PTR_MANGLE(var) \
216 (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
217 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
218 # endif
219 #endif
220
221 /* List of system calls which are supported as vsyscalls. */
222 #define VDSO_NAME "LINUX_2.6.15"
223 #define VDSO_HASH 123718565
224
225 #if defined(__PPC64__) || defined(__powerpc64__)
226 #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres"
227 #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime"
228 #else
229 #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres"
230 #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime"
231 #endif
232 #define HAVE_GETCPU_VSYSCALL "__kernel_getcpu"
233 #define HAVE_TIME_VSYSCALL "__kernel_time"
234 #define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday"
235 #define HAVE_GET_TBFREQ "__kernel_get_tbfreq"
236
237 #if defined(__PPC64__) || defined(__powerpc64__)
238 # define HAVE_SIGTRAMP_RT64 "__kernel_sigtramp_rt64"
239 #else
240 # define HAVE_SIGTRAMP_32 "__kernel_sigtramp32"
241 # define HAVE_SIGTRAMP_RT32 "__kernel_sigtramp_rt32"
242 #endif
243
244 #endif /* _LINUX_POWERPC_SYSDEP_H */