]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc32 / sysdep.h
CommitLineData
04277e02 1/* Copyright (C) 1992-2019 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 14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
4cca6b86 17
924102e7
UD
18#ifndef _LINUX_POWERPC_SYSDEP_H
19#define _LINUX_POWERPC_SYSDEP_H 1
20
fb1cf108 21#include <sysdeps/unix/sysv/linux/sysdep.h>
be9cd93a 22#include <sysdeps/unix/powerpc/sysdep.h>
00c2b3b9 23#include <tls.h>
4cca6b86
UD
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
965a54a4 30#define SYS_ify(syscall_name) __NR_##syscall_name
4cca6b86 31
735d67f2
RM
32#ifndef __ASSEMBLER__
33
34# include <errno.h>
35
8c2e201b
UD
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). */
f534255e 43# define INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, nr, type, args...) \
8c2e201b
UD
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"); \
471a1672 56 register type rval __asm__ ("r3"); \
8c2e201b
UD
57 LOADARGS_##nr (funcptr, args); \
58 __asm__ __volatile__ \
59 ("mtctr %0\n\t" \
60 "bctrl\n\t" \
61 "mfcr %0" \
471a1672
AB
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"); \
8c2e201b 65 err = (long int) r0; \
471a1672
AB
66 __asm__ __volatile__ ("" : "=r" (rval) : "r" (r3), "r" (r4)); \
67 rval; \
8c2e201b
UD
68 })
69
f534255e
AZ
70#define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \
71 INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, nr, long int, args)
72
735d67f2 73# undef INLINE_SYSCALL
704bb2fd
RM
74# define INLINE_SYSCALL(name, nr, args...) \
75 ({ \
b398ae3c 76 INTERNAL_SYSCALL_DECL (sc_err); \
c67a469f 77 long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args); \
b398ae3c 78 if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
704bb2fd 79 { \
b398ae3c
UD
80 __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
81 sc_ret = -1L; \
704bb2fd 82 } \
b398ae3c 83 sc_ret; \
735d67f2
RM
84 })
85
73e9ae88
UD
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
b398ae3c
UD
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). */
73e9ae88 93
6aca81bb 94# undef INTERNAL_SYSCALL_DECL
20f0018d 95# define INTERNAL_SYSCALL_DECL(err) long int err __attribute__ ((unused))
6aca81bb 96
52f3d213 97# undef INTERNAL_SYSCALL
2edb61e3 98# define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
73e9ae88 99 ({ \
c67a469f
UD
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"); \
471a1672 111 LOADARGS_##nr(name, args); \
73e9ae88 112 __asm__ __volatile__ \
b398ae3c
UD
113 ("sc \n\t" \
114 "mfcr %0" \
73e9ae88
UD
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"); \
b398ae3c 120 err = r0; \
73e9ae88
UD
121 (int) r3; \
122 })
2edb61e3
UD
123# define INTERNAL_SYSCALL(name, err, nr, args...) \
124 INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
6aca81bb 125
52f3d213 126# undef INTERNAL_SYSCALL_ERROR_P
6aca81bb 127# define INTERNAL_SYSCALL_ERROR_P(val, err) \
a2274a08 128 ((void) (val), __builtin_expect ((err) & (1 << 28), 0))
6aca81bb 129
52f3d213 130# undef INTERNAL_SYSCALL_ERRNO
b398ae3c 131# define INTERNAL_SYSCALL_ERRNO(val, err) (val)
73e9ae88 132
f534255e
AZ
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
dd26c444 150# define HAVE_GETCPU_VSYSCALL 1
f534255e
AZ
151
152
8c2e201b 153# define LOADARGS_0(name, dummy) \
2edb61e3 154 r0 = name
c67a469f
UD
155# define LOADARGS_1(name, __arg1) \
156 long int arg1 = (long int) (__arg1); \
8c2e201b 157 LOADARGS_0(name, 0); \
2edb61e3 158 extern void __illegally_sized_syscall_arg1 (void); \
c67a469f 159 if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 4) \
2edb61e3 160 __illegally_sized_syscall_arg1 (); \
c67a469f
UD
161 r3 = arg1
162# define LOADARGS_2(name, __arg1, __arg2) \
163 long int arg2 = (long int) (__arg2); \
164 LOADARGS_1(name, __arg1); \
2edb61e3 165 extern void __illegally_sized_syscall_arg2 (void); \
c67a469f 166 if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 4) \
2edb61e3 167 __illegally_sized_syscall_arg2 (); \
c67a469f
UD
168 r4 = arg2
169# define LOADARGS_3(name, __arg1, __arg2, __arg3) \
170 long int arg3 = (long int) (__arg3); \
171 LOADARGS_2(name, __arg1, __arg2); \
2edb61e3 172 extern void __illegally_sized_syscall_arg3 (void); \
c67a469f 173 if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 4) \
2edb61e3 174 __illegally_sized_syscall_arg3 (); \
c67a469f
UD
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); \
2edb61e3 179 extern void __illegally_sized_syscall_arg4 (void); \
c67a469f 180 if (__builtin_classify_type (__arg4) != 5 && sizeof (__arg4) > 4) \
2edb61e3 181 __illegally_sized_syscall_arg4 (); \
c67a469f
UD
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); \
2edb61e3 186 extern void __illegally_sized_syscall_arg5 (void); \
c67a469f 187 if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 4) \
2edb61e3 188 __illegally_sized_syscall_arg5 (); \
c67a469f
UD
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); \
2edb61e3 193 extern void __illegally_sized_syscall_arg6 (void); \
c67a469f 194 if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 4) \
2edb61e3 195 __illegally_sized_syscall_arg6 (); \
c67a469f 196 r8 = arg6
735d67f2 197
704bb2fd
RM
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)
735d67f2
RM
205
206#endif /* __ASSEMBLER__ */
207
208
00c2b3b9 209/* Pointer mangling support. */
a3848485 210#if IS_IN (rtld)
00c2b3b9
UD
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
5ad77144 218# define PTR_MANGLE2(reg, tmpreg) \
4e54d7e4 219 xor reg,tmpreg,reg
4a132246
UD
220# define PTR_MANGLE3(destreg, reg, tmpreg) \
221 lwz tmpreg,POINTER_GUARD(r2); \
222 xor destreg,tmpreg,reg
5ad77144
UD
223# define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
224# define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
4a132246 225# define PTR_DEMANGLE3(destreg, reg, tmpreg) PTR_MANGLE3 (destreg, reg, tmpreg)
00c2b3b9
UD
226# else
227# define PTR_MANGLE(var) \
db169ed5 228 (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
00c2b3b9
UD
229# define PTR_DEMANGLE(var) PTR_MANGLE (var)
230# endif
231#endif
232
b398ae3c 233#endif /* linux/powerpc/powerpc32/sysdep.h */