]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/powerpc/sysdep.h
1 /* Syscall definitions, Linux PowerPC generic version.
2 Copyright (C) 2019-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #ifndef _LINUX_POWERPC_SYSDEP_H
20 #define _LINUX_POWERPC_SYSDEP_H 1
22 #include <sysdeps/unix/sysv/linux/sysdep.h>
23 #include <sysdeps/unix/powerpc/sysdep.h>
25 /* Define __set_errno() for INLINE_SYSCALL macro below. */
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. */
33 #define SYS_ify(syscall_name) __NR_##syscall_name
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. */
41 #define INTERNAL_VSYSCALL_CALL_TYPE(funcptr, type, nr, args...) \
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__ \
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; \
64 #define INTERNAL_VSYSCALL_CALL(funcptr, nr, args...) \
65 INTERNAL_VSYSCALL_CALL_TYPE(funcptr, long int, nr, args)
67 #define DECLARE_REGS \
68 register long int r0 __asm__ ("r0"); \
69 register long int r3 __asm__ ("r3"); \
70 register long int r4 __asm__ ("r4"); \
71 register long int r5 __asm__ ("r5"); \
72 register long int r6 __asm__ ("r6"); \
73 register long int r7 __asm__ ("r7"); \
74 register long int r8 __asm__ ("r8");
76 #define SYSCALL_SCV(nr) \
78 __asm__ __volatile__ \
82 "=&r" (r3), "=&r" (r4), "=&r" (r5), \
83 "=&r" (r6), "=&r" (r7), "=&r" (r8) \
85 : "r9", "r10", "r11", "r12", \
86 "lr", "ctr", "memory"); \
90 #define SYSCALL_SC(nr) \
92 __asm__ __volatile__ \
97 "=&r" (r3), "=&r" (r4), "=&r" (r5), \
98 "=&r" (r6), "=&r" (r7), "=&r" (r8) \
100 : "r9", "r10", "r11", "r12", \
101 "cr0", "ctr", "memory"); \
102 r0 & (1 << 28) ? -r3 : r3; \
105 /* This will only be non-empty for 64-bit systems, see below. */
106 #define TRY_SYSCALL_SCV(nr)
108 #if defined(__PPC64__) || defined(__powerpc64__)
109 # define SYSCALL_ARG_SIZE 8
111 /* For the static case, unlike the dynamic loader, there is no compile-time way
112 to check if we are inside startup code. So we need to check if the thread
113 pointer has already been setup before trying to access the TLS. */
115 # define CHECK_THREAD_POINTER (__thread_register != 0)
117 # define CHECK_THREAD_POINTER (1)
120 /* When inside the dynamic loader, the thread pointer may not have been
121 initialized yet, so don't check for scv support in that case. */
123 # undef TRY_SYSCALL_SCV
124 # define TRY_SYSCALL_SCV(nr) \
125 CHECK_THREAD_POINTER && THREAD_GET_HWCAP() & PPC_FEATURE2_SCV ? \
130 # define SYSCALL_ARG_SIZE 4
133 # define INTERNAL_SYSCALL_NCS(name, nr, args...) \
136 LOADARGS_##nr (name, ##args); \
137 TRY_SYSCALL_SCV(nr) \
141 #undef INTERNAL_SYSCALL
142 #define INTERNAL_SYSCALL(name, nr, args...) \
143 INTERNAL_SYSCALL_NCS (__NR_##name, nr, args)
145 #define LOADARGS_0(name, dummy) \
147 #define LOADARGS_1(name, __arg1) \
148 long int _arg1 = (long int) (__arg1); \
149 LOADARGS_0(name, 0); \
150 extern void __illegally_sized_syscall_arg1 (void); \
151 if (__builtin_classify_type (__arg1) != 5 \
152 && sizeof (__arg1) > SYSCALL_ARG_SIZE) \
153 __illegally_sized_syscall_arg1 (); \
155 #define LOADARGS_2(name, __arg1, __arg2) \
156 long int _arg2 = (long int) (__arg2); \
157 LOADARGS_1(name, __arg1); \
158 extern void __illegally_sized_syscall_arg2 (void); \
159 if (__builtin_classify_type (__arg2) != 5 \
160 && sizeof (__arg2) > SYSCALL_ARG_SIZE) \
161 __illegally_sized_syscall_arg2 (); \
163 #define LOADARGS_3(name, __arg1, __arg2, __arg3) \
164 long int _arg3 = (long int) (__arg3); \
165 LOADARGS_2(name, __arg1, __arg2); \
166 extern void __illegally_sized_syscall_arg3 (void); \
167 if (__builtin_classify_type (__arg3) != 5 \
168 && sizeof (__arg3) > SYSCALL_ARG_SIZE) \
169 __illegally_sized_syscall_arg3 (); \
171 #define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \
172 long int _arg4 = (long int) (__arg4); \
173 LOADARGS_3(name, __arg1, __arg2, __arg3); \
174 extern void __illegally_sized_syscall_arg4 (void); \
175 if (__builtin_classify_type (__arg4) != 5 \
176 && sizeof (__arg4) > SYSCALL_ARG_SIZE) \
177 __illegally_sized_syscall_arg4 (); \
179 #define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
180 long int _arg5 = (long int) (__arg5); \
181 LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \
182 extern void __illegally_sized_syscall_arg5 (void); \
183 if (__builtin_classify_type (__arg5) != 5 \
184 && sizeof (__arg5) > SYSCALL_ARG_SIZE) \
185 __illegally_sized_syscall_arg5 (); \
187 #define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
188 long int _arg6 = (long int) (__arg6); \
189 LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
190 extern void __illegally_sized_syscall_arg6 (void); \
191 if (__builtin_classify_type (__arg6) != 5 \
192 && sizeof (__arg6) > SYSCALL_ARG_SIZE) \
193 __illegally_sized_syscall_arg6 (); \
196 #define ASM_INPUT_0 "0" (r0)
197 #define ASM_INPUT_1 ASM_INPUT_0, "1" (r3)
198 #define ASM_INPUT_2 ASM_INPUT_1, "2" (r4)
199 #define ASM_INPUT_3 ASM_INPUT_2, "3" (r5)
200 #define ASM_INPUT_4 ASM_INPUT_3, "4" (r6)
201 #define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
202 #define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
205 /* Pointer mangling support. */
207 /* We cannot use the thread descriptor because in ld.so we use setjmp
208 earlier than the descriptor is initialized. */
210 # ifdef __ASSEMBLER__
211 # if defined(__PPC64__) || defined(__powerpc64__)
218 # define PTR_MANGLE(reg, tmpreg) \
219 LOAD tmpreg,POINTER_GUARD(TPREG); \
221 # define PTR_MANGLE2(reg, tmpreg) \
223 # define PTR_MANGLE3(destreg, reg, tmpreg) \
224 LOAD tmpreg,POINTER_GUARD(TPREG); \
225 xor destreg,tmpreg,reg
226 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
227 # define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
228 # define PTR_DEMANGLE3(destreg, reg, tmpreg) PTR_MANGLE3 (destreg, reg, tmpreg)
230 # define PTR_MANGLE(var) \
231 (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
232 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
236 /* List of system calls which are supported as vsyscalls. */
237 #define VDSO_NAME "LINUX_2.6.15"
238 #define VDSO_HASH 123718565
240 #if defined(__PPC64__) || defined(__powerpc64__)
241 #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres"
242 #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime"
244 #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres"
245 #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime"
247 #define HAVE_GETCPU_VSYSCALL "__kernel_getcpu"
248 #define HAVE_TIME_VSYSCALL "__kernel_time"
249 #define HAVE_GETTIMEOFDAY_VSYSCALL "__kernel_gettimeofday"
250 #define HAVE_GET_TBFREQ "__kernel_get_tbfreq"
252 #if defined(__PPC64__) || defined(__powerpc64__)
253 # define HAVE_SIGTRAMP_RT64 "__kernel_sigtramp_rt64"
255 # define HAVE_SIGTRAMP_32 "__kernel_sigtramp32"
256 # define HAVE_SIGTRAMP_RT32 "__kernel_sigtramp_rt32"
259 #endif /* _LINUX_POWERPC_SYSDEP_H */