Update copyright notices with scripts/update-copyrights.
[glibc.git] / ports / sysdeps / unix / sysv / linux / mips / mips32 / sysdep.h
blobe79fda9372d52f90deb3a4f5dc59dfe75b49ecd1
1 /* Copyright (C) 2000-2013 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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 <http://www.gnu.org/licenses/>. */
18 #ifndef _LINUX_MIPS_MIPS32_SYSDEP_H
19 #define _LINUX_MIPS_MIPS32_SYSDEP_H 1
21 /* There is some commonality. */
22 #include <sysdeps/unix/mips/mips32/sysdep.h>
24 #include <tls.h>
26 /* In order to get __set_errno() definition in INLINE_SYSCALL. */
27 #ifndef __ASSEMBLER__
28 #include <errno.h>
29 #endif
31 /* For Linux we can use the system call table in the header file
32 /usr/include/asm/unistd.h
33 of the kernel. But these symbols do not follow the SYS_* syntax
34 so we have to redefine the `SYS_ify' macro here. */
35 #undef SYS_ify
36 #define SYS_ify(syscall_name) __NR_##syscall_name
38 #ifdef __ASSEMBLER__
40 /* We don't want the label for the error handler to be visible in the symbol
41 table when we define it here. */
42 #ifdef __PIC__
43 # define SYSCALL_ERROR_LABEL 99b
44 #endif
46 #else /* ! __ASSEMBLER__ */
48 /* Define a macro which expands into the inline wrapper code for a system
49 call. */
50 #undef INLINE_SYSCALL
51 #define INLINE_SYSCALL(name, nr, args...) \
52 ({ INTERNAL_SYSCALL_DECL(err); \
53 long result_var = INTERNAL_SYSCALL (name, err, nr, args); \
54 if ( INTERNAL_SYSCALL_ERROR_P (result_var, err) ) \
55 { \
56 __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err)); \
57 result_var = -1L; \
58 } \
59 result_var; })
61 #undef INTERNAL_SYSCALL_DECL
62 #define INTERNAL_SYSCALL_DECL(err) long err __attribute__ ((unused))
64 #undef INTERNAL_SYSCALL_ERROR_P
65 #define INTERNAL_SYSCALL_ERROR_P(val, err) ((void) (val), (long) (err))
67 #undef INTERNAL_SYSCALL_ERRNO
68 #define INTERNAL_SYSCALL_ERRNO(val, err) ((void) (err), val)
70 #undef INTERNAL_SYSCALL
71 #define INTERNAL_SYSCALL(name, err, nr, args...) \
72 internal_syscall##nr (, "li\t$2, %2\t\t\t# " #name "\n\t", \
73 "i" (SYS_ify (name)), err, args)
75 #undef INTERNAL_SYSCALL_NCS
76 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
77 internal_syscall##nr (= number, , "r" (__v0), err, args)
79 #define internal_syscall0(ncs_init, cs_init, input, err, dummy...) \
80 ({ \
81 long _sys_result; \
83 { \
84 register long __v0 asm("$2") ncs_init; \
85 register long __a3 asm("$7"); \
86 __asm__ volatile ( \
87 ".set\tnoreorder\n\t" \
88 cs_init \
89 "syscall\n\t" \
90 ".set reorder" \
91 : "=r" (__v0), "=r" (__a3) \
92 : input \
93 : __SYSCALL_CLOBBERS); \
94 err = __a3; \
95 _sys_result = __v0; \
96 } \
97 _sys_result; \
100 #define internal_syscall1(ncs_init, cs_init, input, err, arg1) \
101 ({ \
102 long _sys_result; \
105 register long __v0 asm("$2") ncs_init; \
106 register long __a0 asm("$4") = (long) (arg1); \
107 register long __a3 asm("$7"); \
108 __asm__ volatile ( \
109 ".set\tnoreorder\n\t" \
110 cs_init \
111 "syscall\n\t" \
112 ".set reorder" \
113 : "=r" (__v0), "=r" (__a3) \
114 : input, "r" (__a0) \
115 : __SYSCALL_CLOBBERS); \
116 err = __a3; \
117 _sys_result = __v0; \
119 _sys_result; \
122 #define internal_syscall2(ncs_init, cs_init, input, err, arg1, arg2) \
123 ({ \
124 long _sys_result; \
127 register long __v0 asm("$2") ncs_init; \
128 register long __a0 asm("$4") = (long) (arg1); \
129 register long __a1 asm("$5") = (long) (arg2); \
130 register long __a3 asm("$7"); \
131 __asm__ volatile ( \
132 ".set\tnoreorder\n\t" \
133 cs_init \
134 "syscall\n\t" \
135 ".set\treorder" \
136 : "=r" (__v0), "=r" (__a3) \
137 : input, "r" (__a0), "r" (__a1) \
138 : __SYSCALL_CLOBBERS); \
139 err = __a3; \
140 _sys_result = __v0; \
142 _sys_result; \
145 #define internal_syscall3(ncs_init, cs_init, input, err, arg1, arg2, arg3)\
146 ({ \
147 long _sys_result; \
150 register long __v0 asm("$2") ncs_init; \
151 register long __a0 asm("$4") = (long) (arg1); \
152 register long __a1 asm("$5") = (long) (arg2); \
153 register long __a2 asm("$6") = (long) (arg3); \
154 register long __a3 asm("$7"); \
155 __asm__ volatile ( \
156 ".set\tnoreorder\n\t" \
157 cs_init \
158 "syscall\n\t" \
159 ".set\treorder" \
160 : "=r" (__v0), "=r" (__a3) \
161 : input, "r" (__a0), "r" (__a1), "r" (__a2) \
162 : __SYSCALL_CLOBBERS); \
163 err = __a3; \
164 _sys_result = __v0; \
166 _sys_result; \
169 #define internal_syscall4(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4)\
170 ({ \
171 long _sys_result; \
174 register long __v0 asm("$2") ncs_init; \
175 register long __a0 asm("$4") = (long) (arg1); \
176 register long __a1 asm("$5") = (long) (arg2); \
177 register long __a2 asm("$6") = (long) (arg3); \
178 register long __a3 asm("$7") = (long) (arg4); \
179 __asm__ volatile ( \
180 ".set\tnoreorder\n\t" \
181 cs_init \
182 "syscall\n\t" \
183 ".set\treorder" \
184 : "=r" (__v0), "+r" (__a3) \
185 : input, "r" (__a0), "r" (__a1), "r" (__a2) \
186 : __SYSCALL_CLOBBERS); \
187 err = __a3; \
188 _sys_result = __v0; \
190 _sys_result; \
193 /* We need to use a frame pointer for the functions in which we
194 adjust $sp around the syscall, or debug information and unwind
195 information will be $sp relative and thus wrong during the syscall. As
196 of GCC 4.7, this is sufficient. */
197 #define FORCE_FRAME_POINTER \
198 void *volatile __fp_force __attribute__ ((unused)) = alloca (4)
200 #define internal_syscall5(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5)\
201 ({ \
202 long _sys_result; \
204 FORCE_FRAME_POINTER; \
206 register long __v0 asm("$2") ncs_init; \
207 register long __a0 asm("$4") = (long) (arg1); \
208 register long __a1 asm("$5") = (long) (arg2); \
209 register long __a2 asm("$6") = (long) (arg3); \
210 register long __a3 asm("$7") = (long) (arg4); \
211 __asm__ volatile ( \
212 ".set\tnoreorder\n\t" \
213 "subu\t$29, 32\n\t" \
214 "sw\t%6, 16($29)\n\t" \
215 cs_init \
216 "syscall\n\t" \
217 "addiu\t$29, 32\n\t" \
218 ".set\treorder" \
219 : "=r" (__v0), "+r" (__a3) \
220 : input, "r" (__a0), "r" (__a1), "r" (__a2), \
221 "r" ((long) (arg5)) \
222 : __SYSCALL_CLOBBERS); \
223 err = __a3; \
224 _sys_result = __v0; \
226 _sys_result; \
229 #define internal_syscall6(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6)\
230 ({ \
231 long _sys_result; \
233 FORCE_FRAME_POINTER; \
235 register long __v0 asm("$2") ncs_init; \
236 register long __a0 asm("$4") = (long) (arg1); \
237 register long __a1 asm("$5") = (long) (arg2); \
238 register long __a2 asm("$6") = (long) (arg3); \
239 register long __a3 asm("$7") = (long) (arg4); \
240 __asm__ volatile ( \
241 ".set\tnoreorder\n\t" \
242 "subu\t$29, 32\n\t" \
243 "sw\t%6, 16($29)\n\t" \
244 "sw\t%7, 20($29)\n\t" \
245 cs_init \
246 "syscall\n\t" \
247 "addiu\t$29, 32\n\t" \
248 ".set\treorder" \
249 : "=r" (__v0), "+r" (__a3) \
250 : input, "r" (__a0), "r" (__a1), "r" (__a2), \
251 "r" ((long) (arg5)), "r" ((long) (arg6)) \
252 : __SYSCALL_CLOBBERS); \
253 err = __a3; \
254 _sys_result = __v0; \
256 _sys_result; \
259 #define internal_syscall7(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6, arg7)\
260 ({ \
261 long _sys_result; \
263 FORCE_FRAME_POINTER; \
265 register long __v0 asm("$2") ncs_init; \
266 register long __a0 asm("$4") = (long) (arg1); \
267 register long __a1 asm("$5") = (long) (arg2); \
268 register long __a2 asm("$6") = (long) (arg3); \
269 register long __a3 asm("$7") = (long) (arg4); \
270 __asm__ volatile ( \
271 ".set\tnoreorder\n\t" \
272 "subu\t$29, 32\n\t" \
273 "sw\t%6, 16($29)\n\t" \
274 "sw\t%7, 20($29)\n\t" \
275 "sw\t%8, 24($29)\n\t" \
276 cs_init \
277 "syscall\n\t" \
278 "addiu\t$29, 32\n\t" \
279 ".set\treorder" \
280 : "=r" (__v0), "+r" (__a3) \
281 : input, "r" (__a0), "r" (__a1), "r" (__a2), \
282 "r" ((long) (arg5)), "r" ((long) (arg6)), "r" ((long) (arg7)) \
283 : __SYSCALL_CLOBBERS); \
284 err = __a3; \
285 _sys_result = __v0; \
287 _sys_result; \
290 #define __SYSCALL_CLOBBERS "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", \
291 "$14", "$15", "$24", "$25", "hi", "lo", "memory"
293 #endif /* __ASSEMBLER__ */
295 /* Pointer mangling is not yet supported for MIPS. */
296 #define PTR_MANGLE(var) (void) (var)
297 #define PTR_DEMANGLE(var) (void) (var)
299 #endif /* linux/mips/mips32/sysdep.h */