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>
26 /* In order to get __set_errno() definition in INLINE_SYSCALL. */
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. */
36 #define SYS_ify(syscall_name) __NR_##syscall_name
40 /* We don't want the label for the error handler to be visible in the symbol
41 table when we define it here. */
43 # define SYSCALL_ERROR_LABEL 99b
46 #else /* ! __ASSEMBLER__ */
48 /* Define a macro which expands into the inline wrapper code for a system
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) ) \
56 __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err)); \
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...) \
84 register long __v0 asm("$2") ncs_init; \
85 register long __a3 asm("$7"); \
87 ".set\tnoreorder\n\t" \
91 : "=r" (__v0), "=r" (__a3) \
93 : __SYSCALL_CLOBBERS); \
100 #define internal_syscall1(ncs_init, cs_init, input, err, arg1) \
105 register long __v0 asm("$2") ncs_init; \
106 register long __a0 asm("$4") = (long) (arg1); \
107 register long __a3 asm("$7"); \
109 ".set\tnoreorder\n\t" \
113 : "=r" (__v0), "=r" (__a3) \
114 : input, "r" (__a0) \
115 : __SYSCALL_CLOBBERS); \
117 _sys_result = __v0; \
122 #define internal_syscall2(ncs_init, cs_init, input, err, arg1, arg2) \
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"); \
132 ".set\tnoreorder\n\t" \
136 : "=r" (__v0), "=r" (__a3) \
137 : input, "r" (__a0), "r" (__a1) \
138 : __SYSCALL_CLOBBERS); \
140 _sys_result = __v0; \
145 #define internal_syscall3(ncs_init, cs_init, input, err, arg1, arg2, arg3)\
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"); \
156 ".set\tnoreorder\n\t" \
160 : "=r" (__v0), "=r" (__a3) \
161 : input, "r" (__a0), "r" (__a1), "r" (__a2) \
162 : __SYSCALL_CLOBBERS); \
164 _sys_result = __v0; \
169 #define internal_syscall4(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4)\
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); \
180 ".set\tnoreorder\n\t" \
184 : "=r" (__v0), "+r" (__a3) \
185 : input, "r" (__a0), "r" (__a1), "r" (__a2) \
186 : __SYSCALL_CLOBBERS); \
188 _sys_result = __v0; \
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)\
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); \
212 ".set\tnoreorder\n\t" \
213 "subu\t$29, 32\n\t" \
214 "sw\t%6, 16($29)\n\t" \
217 "addiu\t$29, 32\n\t" \
219 : "=r" (__v0), "+r" (__a3) \
220 : input, "r" (__a0), "r" (__a1), "r" (__a2), \
221 "r" ((long) (arg5)) \
222 : __SYSCALL_CLOBBERS); \
224 _sys_result = __v0; \
229 #define internal_syscall6(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6)\
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); \
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" \
247 "addiu\t$29, 32\n\t" \
249 : "=r" (__v0), "+r" (__a3) \
250 : input, "r" (__a0), "r" (__a1), "r" (__a2), \
251 "r" ((long) (arg5)), "r" ((long) (arg6)) \
252 : __SYSCALL_CLOBBERS); \
254 _sys_result = __v0; \
259 #define internal_syscall7(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6, arg7)\
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); \
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" \
278 "addiu\t$29, 32\n\t" \
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); \
285 _sys_result = __v0; \
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 */