]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
1cbf1596d58eff691600cb9243d2da7542bea8cd
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / powerpc / powerpc32 / sysdep.h
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/powerpc/sysdep.h>
22 #include <sysdeps/unix/sysv/linux/sysdep.h>
23 #include <sysdeps/unix/powerpc/sysdep.h>
24 #include <tls.h>
25
26 /* For Linux we can use the system call table in the header file
27 /usr/include/asm/unistd.h
28 of the kernel. But these symbols do not follow the SYS_* syntax
29 so we have to redefine the `SYS_ify' macro here. */
30 #undef SYS_ify
31 #define SYS_ify(syscall_name) __NR_##syscall_name
32
33 #ifndef __ASSEMBLER__
34
35 # include <errno.h>
36
37 /* Define a macro which expands inline into the wrapper code for a VDSO
38 call. This use is for internal calls that do not need to handle errors
39 normally. It will never touch errno.
40 On powerpc a system call basically clobbers the same registers like a
41 function call, with the exception of LR (which is needed for the
42 "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
43 an error return status). */
44 # define INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, nr, type, args...) \
45 ({ \
46 register void *r0 __asm__ ("r0"); \
47 register long int r3 __asm__ ("r3"); \
48 register long int r4 __asm__ ("r4"); \
49 register long int r5 __asm__ ("r5"); \
50 register long int r6 __asm__ ("r6"); \
51 register long int r7 __asm__ ("r7"); \
52 register long int r8 __asm__ ("r8"); \
53 register long int r9 __asm__ ("r9"); \
54 register long int r10 __asm__ ("r10"); \
55 register long int r11 __asm__ ("r11"); \
56 register long int r12 __asm__ ("r12"); \
57 register type rval __asm__ ("r3"); \
58 LOADARGS_##nr (funcptr, args); \
59 __asm__ __volatile__ \
60 ("mtctr %0\n\t" \
61 "bctrl\n\t" \
62 "mfcr %0" \
63 : "+r" (r0), "+r" (r3), "+r" (r4), "+r" (r5), "+r" (r6), "+r" (r7), \
64 "+r" (r8), "+r" (r9), "+r" (r10), "+r" (r11), "+r" (r12) \
65 : : "cr0", "ctr", "lr", "memory"); \
66 err = (long int) r0; \
67 __asm__ __volatile__ ("" : "=r" (rval) : "r" (r3), "r" (r4)); \
68 rval; \
69 })
70
71 #define INTERNAL_VSYSCALL_CALL(funcptr, err, nr, args...) \
72 INTERNAL_VSYSCALL_CALL_TYPE(funcptr, err, nr, long int, args)
73
74 # undef INLINE_SYSCALL
75 # define INLINE_SYSCALL(name, nr, args...) \
76 ({ \
77 INTERNAL_SYSCALL_DECL (sc_err); \
78 long int sc_ret = INTERNAL_SYSCALL (name, sc_err, nr, args); \
79 if (INTERNAL_SYSCALL_ERROR_P (sc_ret, sc_err)) \
80 { \
81 __set_errno (INTERNAL_SYSCALL_ERRNO (sc_ret, sc_err)); \
82 sc_ret = -1L; \
83 } \
84 sc_ret; \
85 })
86
87 /* Define a macro which expands inline into the wrapper code for a system
88 call. This use is for internal calls that do not need to handle errors
89 normally. It will never touch errno.
90 On powerpc a system call basically clobbers the same registers like a
91 function call, with the exception of LR (which is needed for the
92 "sc; bnslr+" sequence) and CR (where only CR0.SO is clobbered to signal
93 an error return status). */
94
95 # undef INTERNAL_SYSCALL_DECL
96 # define INTERNAL_SYSCALL_DECL(err) long int err __attribute__ ((unused))
97
98 # undef INTERNAL_SYSCALL
99 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
100 ({ \
101 register long int r0 __asm__ ("r0"); \
102 register long int r3 __asm__ ("r3"); \
103 register long int r4 __asm__ ("r4"); \
104 register long int r5 __asm__ ("r5"); \
105 register long int r6 __asm__ ("r6"); \
106 register long int r7 __asm__ ("r7"); \
107 register long int r8 __asm__ ("r8"); \
108 register long int r9 __asm__ ("r9"); \
109 register long int r10 __asm__ ("r10"); \
110 register long int r11 __asm__ ("r11"); \
111 register long int r12 __asm__ ("r12"); \
112 LOADARGS_##nr(name, args); \
113 __asm__ __volatile__ \
114 ("sc \n\t" \
115 "mfcr %0" \
116 : "=&r" (r0), \
117 "=&r" (r3), "=&r" (r4), "=&r" (r5), "=&r" (r6), "=&r" (r7), \
118 "=&r" (r8), "=&r" (r9), "=&r" (r10), "=&r" (r11), "=&r" (r12) \
119 : ASM_INPUT_##nr \
120 : "cr0", "ctr", "memory"); \
121 err = r0; \
122 (int) r3; \
123 })
124 # define INTERNAL_SYSCALL(name, err, nr, args...) \
125 INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
126
127 # undef INTERNAL_SYSCALL_ERROR_P
128 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
129 ((void) (val), __builtin_expect ((err) & (1 << 28), 0))
130
131 # undef INTERNAL_SYSCALL_ERRNO
132 # define INTERNAL_SYSCALL_ERRNO(val, err) (val)
133
134 # define INTERNAL_VSYSCALL_NO_SYSCALL_FALLBACK(name, err, type, nr, args...) \
135 ({ \
136 type sc_ret = ENOSYS; \
137 \
138 __typeof (__vdso_##name) vdsop = __vdso_##name; \
139 PTR_DEMANGLE (vdsop); \
140 if (vdsop != NULL) \
141 sc_ret = \
142 INTERNAL_VSYSCALL_CALL_TYPE (vdsop, err, nr, type, ##args); \
143 else \
144 err = 1 << 28; \
145 sc_ret; \
146 })
147
148 # define LOADARGS_0(name, dummy) \
149 r0 = name
150 # define LOADARGS_1(name, __arg1) \
151 long int arg1 = (long int) (__arg1); \
152 LOADARGS_0(name, 0); \
153 extern void __illegally_sized_syscall_arg1 (void); \
154 if (__builtin_classify_type (__arg1) != 5 && sizeof (__arg1) > 4) \
155 __illegally_sized_syscall_arg1 (); \
156 r3 = arg1
157 # define LOADARGS_2(name, __arg1, __arg2) \
158 long int arg2 = (long int) (__arg2); \
159 LOADARGS_1(name, __arg1); \
160 extern void __illegally_sized_syscall_arg2 (void); \
161 if (__builtin_classify_type (__arg2) != 5 && sizeof (__arg2) > 4) \
162 __illegally_sized_syscall_arg2 (); \
163 r4 = arg2
164 # define LOADARGS_3(name, __arg1, __arg2, __arg3) \
165 long int arg3 = (long int) (__arg3); \
166 LOADARGS_2(name, __arg1, __arg2); \
167 extern void __illegally_sized_syscall_arg3 (void); \
168 if (__builtin_classify_type (__arg3) != 5 && sizeof (__arg3) > 4) \
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 && sizeof (__arg4) > 4) \
176 __illegally_sized_syscall_arg4 (); \
177 r6 = arg4
178 # define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
179 long int arg5 = (long int) (__arg5); \
180 LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \
181 extern void __illegally_sized_syscall_arg5 (void); \
182 if (__builtin_classify_type (__arg5) != 5 && sizeof (__arg5) > 4) \
183 __illegally_sized_syscall_arg5 (); \
184 r7 = arg5
185 # define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
186 long int arg6 = (long int) (__arg6); \
187 LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
188 extern void __illegally_sized_syscall_arg6 (void); \
189 if (__builtin_classify_type (__arg6) != 5 && sizeof (__arg6) > 4) \
190 __illegally_sized_syscall_arg6 (); \
191 r8 = arg6
192
193 # define ASM_INPUT_0 "0" (r0)
194 # define ASM_INPUT_1 ASM_INPUT_0, "1" (r3)
195 # define ASM_INPUT_2 ASM_INPUT_1, "2" (r4)
196 # define ASM_INPUT_3 ASM_INPUT_2, "3" (r5)
197 # define ASM_INPUT_4 ASM_INPUT_3, "4" (r6)
198 # define ASM_INPUT_5 ASM_INPUT_4, "5" (r7)
199 # define ASM_INPUT_6 ASM_INPUT_5, "6" (r8)
200
201 #endif /* __ASSEMBLER__ */
202
203
204 /* Pointer mangling support. */
205 #if IS_IN (rtld)
206 /* We cannot use the thread descriptor because in ld.so we use setjmp
207 earlier than the descriptor is initialized. */
208 #else
209 # ifdef __ASSEMBLER__
210 # define PTR_MANGLE(reg, tmpreg) \
211 lwz tmpreg,POINTER_GUARD(r2); \
212 xor reg,tmpreg,reg
213 # define PTR_MANGLE2(reg, tmpreg) \
214 xor reg,tmpreg,reg
215 # define PTR_MANGLE3(destreg, reg, tmpreg) \
216 lwz tmpreg,POINTER_GUARD(r2); \
217 xor destreg,tmpreg,reg
218 # define PTR_DEMANGLE(reg, tmpreg) PTR_MANGLE (reg, tmpreg)
219 # define PTR_DEMANGLE2(reg, tmpreg) PTR_MANGLE2 (reg, tmpreg)
220 # define PTR_DEMANGLE3(destreg, reg, tmpreg) PTR_MANGLE3 (destreg, reg, tmpreg)
221 # else
222 # define PTR_MANGLE(var) \
223 (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
224 # define PTR_DEMANGLE(var) PTR_MANGLE (var)
225 # endif
226 #endif
227
228 #endif /* linux/powerpc/powerpc32/sysdep.h */