]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/powerpc/sysdep.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / 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.
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, 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, nr, args...) \
65 INTERNAL_VSYSCALL_CALL_TYPE(funcptr, long int, nr, args)
66
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");
75
76 #define SYSCALL_SCV(nr) \
77 ({ \
78 __asm__ __volatile__ \
79 ("scv 0\n\t" \
80 "0:" \
81 : "=&r" (r0), \
82 "=&r" (r3), "=&r" (r4), "=&r" (r5), \
83 "=&r" (r6), "=&r" (r7), "=&r" (r8) \
84 : ASM_INPUT_##nr \
85 : "r9", "r10", "r11", "r12", \
86 "lr", "ctr", "memory"); \
87 r3; \
88 })
89
90 #define SYSCALL_SC(nr) \
91 ({ \
92 __asm__ __volatile__ \
93 ("sc\n\t" \
94 "mfcr %0\n\t" \
95 "0:" \
96 : "=&r" (r0), \
97 "=&r" (r3), "=&r" (r4), "=&r" (r5), \
98 "=&r" (r6), "=&r" (r7), "=&r" (r8) \
99 : ASM_INPUT_##nr \
100 : "r9", "r10", "r11", "r12", \
101 "cr0", "ctr", "memory"); \
102 r0 & (1 << 28) ? -r3 : r3; \
103 })
104
105 /* This will only be non-empty for 64-bit systems, see below. */
106 #define TRY_SYSCALL_SCV(nr)
107
108 #if defined(__PPC64__) || defined(__powerpc64__)
109 # define SYSCALL_ARG_SIZE 8
110
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. */
114 # ifndef SHARED
115 # define CHECK_THREAD_POINTER (__thread_register != 0)
116 # else
117 # define CHECK_THREAD_POINTER (1)
118 # endif
119
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. */
122 # if !IS_IN(rtld)
123 # undef TRY_SYSCALL_SCV
124 # define TRY_SYSCALL_SCV(nr) \
125 CHECK_THREAD_POINTER && THREAD_GET_HWCAP() & PPC_FEATURE2_SCV ? \
126 SYSCALL_SCV(nr) :
127 # endif
128
129 #else
130 # define SYSCALL_ARG_SIZE 4
131 #endif
132
133 # define INTERNAL_SYSCALL_NCS(name, nr, args...) \
134 ({ \
135 DECLARE_REGS; \
136 LOADARGS_##nr (name, ##args); \
137 TRY_SYSCALL_SCV(nr) \
138 SYSCALL_SC(nr); \
139 })
140
141 #undef INTERNAL_SYSCALL
142 #define INTERNAL_SYSCALL(name, nr, args...) \
143 INTERNAL_SYSCALL_NCS (__NR_##name, nr, args)
144
145 #define LOADARGS_0(name, dummy) \
146 r0 = name
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 (); \
154 r3 = _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 (); \
162 r4 = _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 (); \
170 r5 = _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 (); \
178 r6 = _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 (); \
186 r7 = _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 (); \
194 r8 = _arg6
195
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)
203
204
205 /* Pointer mangling support. */
206 #if IS_IN (rtld)
207 /* We cannot use the thread descriptor because in ld.so we use setjmp
208 earlier than the descriptor is initialized. */
209 #else
210 # ifdef __ASSEMBLER__
211 # if defined(__PPC64__) || defined(__powerpc64__)
212 # define LOAD ld
213 # define TPREG r13
214 # else
215 # define LOAD lwz
216 # define TPREG r2
217 # endif
218 # define PTR_MANGLE(reg, tmpreg) \
219 LOAD tmpreg,POINTER_GUARD(TPREG); \
220 xor reg,tmpreg,reg
221 # define PTR_MANGLE2(reg, tmpreg) \
222 xor reg,tmpreg,reg
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)
229 # else
230 # define PTR_MANGLE(var) \
231 (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
232 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
233 # endif
234 #endif
235
236 /* List of system calls which are supported as vsyscalls. */
237 #define VDSO_NAME "LINUX_2.6.15"
238 #define VDSO_HASH 123718565
239
240 #if defined(__PPC64__) || defined(__powerpc64__)
241 #define HAVE_CLOCK_GETRES64_VSYSCALL "__kernel_clock_getres"
242 #define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime"
243 #else
244 #define HAVE_CLOCK_GETRES_VSYSCALL "__kernel_clock_getres"
245 #define HAVE_CLOCK_GETTIME_VSYSCALL "__kernel_clock_gettime"
246 #endif
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"
251
252 #if defined(__PPC64__) || defined(__powerpc64__)
253 # define HAVE_SIGTRAMP_RT64 "__kernel_sigtramp_rt64"
254 #else
255 # define HAVE_SIGTRAMP_32 "__kernel_sigtramp32"
256 # define HAVE_SIGTRAMP_RT32 "__kernel_sigtramp_rt32"
257 #endif
258
259 #endif /* _LINUX_POWERPC_SYSDEP_H */