1 /* Copyright (C) 2000, 2002, 2003, 2004, 2005,
2 2009 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 #ifndef _LINUX_MIPS_MIPS32_SYSDEP_H
21 #define _LINUX_MIPS_MIPS32_SYSDEP_H 1
23 /* There is some commonality. */
24 #include <sysdeps/unix/mips/mips32/sysdep.h>
28 /* In order to get __set_errno() definition in INLINE_SYSCALL. */
33 /* For Linux we can use the system call table in the header file
34 /usr/include/asm/unistd.h
35 of the kernel. But these symbols do not follow the SYS_* syntax
36 so we have to redefine the `SYS_ify' macro here. */
39 # define SYS_ify(syscall_name) __NR_##syscall_name
41 # define SYS_ify(syscall_name) __NR_/**/syscall_name
46 /* Define a macro which expands into the inline wrapper code for a system
49 #define INLINE_SYSCALL(name, nr, args...) \
50 ({ INTERNAL_SYSCALL_DECL(err); \
51 long result_var = INTERNAL_SYSCALL (name, err, nr, args); \
52 if ( INTERNAL_SYSCALL_ERROR_P (result_var, err) ) \
54 __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err)); \
59 #undef INTERNAL_SYSCALL_DECL
60 #define INTERNAL_SYSCALL_DECL(err) long err
62 #undef INTERNAL_SYSCALL_ERROR_P
63 #define INTERNAL_SYSCALL_ERROR_P(val, err) ((long) (err))
65 #undef INTERNAL_SYSCALL_ERRNO
66 #define INTERNAL_SYSCALL_ERRNO(val, err) (val)
68 #undef INTERNAL_SYSCALL
69 #define INTERNAL_SYSCALL(name, err, nr, args...) \
70 internal_syscall##nr (, "li\t$2, %2\t\t\t# " #name "\n\t", \
71 "i" (SYS_ify (name)), err, args)
73 #undef INTERNAL_SYSCALL_NCS
74 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
75 internal_syscall##nr (= number, , "r" (__v0), err, args)
77 #define internal_syscall0(ncs_init, cs_init, input, err, dummy...) \
82 register long __v0 asm("$2") ncs_init; \
83 register long __a3 asm("$7"); \
85 ".set\tnoreorder\n\t" \
89 : "=r" (__v0), "=r" (__a3) \
91 : __SYSCALL_CLOBBERS); \
98 #define internal_syscall1(ncs_init, cs_init, input, err, arg1) \
103 register long __v0 asm("$2") ncs_init; \
104 register long __a0 asm("$4") = (long) arg1; \
105 register long __a3 asm("$7"); \
107 ".set\tnoreorder\n\t" \
111 : "=r" (__v0), "=r" (__a3) \
112 : input, "r" (__a0) \
113 : __SYSCALL_CLOBBERS); \
115 _sys_result = __v0; \
120 #define internal_syscall2(ncs_init, cs_init, input, err, arg1, arg2) \
125 register long __v0 asm("$2") ncs_init; \
126 register long __a0 asm("$4") = (long) arg1; \
127 register long __a1 asm("$5") = (long) arg2; \
128 register long __a3 asm("$7"); \
130 ".set\tnoreorder\n\t" \
134 : "=r" (__v0), "=r" (__a3) \
135 : input, "r" (__a0), "r" (__a1) \
136 : __SYSCALL_CLOBBERS); \
138 _sys_result = __v0; \
143 #define internal_syscall3(ncs_init, cs_init, input, err, arg1, arg2, arg3)\
148 register long __v0 asm("$2") ncs_init; \
149 register long __a0 asm("$4") = (long) arg1; \
150 register long __a1 asm("$5") = (long) arg2; \
151 register long __a2 asm("$6") = (long) arg3; \
152 register long __a3 asm("$7"); \
154 ".set\tnoreorder\n\t" \
158 : "=r" (__v0), "=r" (__a3) \
159 : input, "r" (__a0), "r" (__a1), "r" (__a2) \
160 : __SYSCALL_CLOBBERS); \
162 _sys_result = __v0; \
167 #define internal_syscall4(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4)\
172 register long __v0 asm("$2") ncs_init; \
173 register long __a0 asm("$4") = (long) arg1; \
174 register long __a1 asm("$5") = (long) arg2; \
175 register long __a2 asm("$6") = (long) arg3; \
176 register long __a3 asm("$7") = (long) arg4; \
178 ".set\tnoreorder\n\t" \
182 : "=r" (__v0), "+r" (__a3) \
183 : input, "r" (__a0), "r" (__a1), "r" (__a2) \
184 : __SYSCALL_CLOBBERS); \
186 _sys_result = __v0; \
191 /* We need to use a frame pointer for the functions in which we
192 adjust $sp around the syscall, or debug information and unwind
193 information will be $sp relative and thus wrong during the syscall. As
194 of GCC 3.4.3, this is sufficient. */
195 #define FORCE_FRAME_POINTER alloca (4)
197 #define internal_syscall5(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5)\
201 FORCE_FRAME_POINTER; \
203 register long __v0 asm("$2") ncs_init; \
204 register long __a0 asm("$4") = (long) arg1; \
205 register long __a1 asm("$5") = (long) arg2; \
206 register long __a2 asm("$6") = (long) arg3; \
207 register long __a3 asm("$7") = (long) arg4; \
209 ".set\tnoreorder\n\t" \
210 "subu\t$29, 32\n\t" \
211 "sw\t%6, 16($29)\n\t" \
214 "addiu\t$29, 32\n\t" \
216 : "=r" (__v0), "+r" (__a3) \
217 : input, "r" (__a0), "r" (__a1), "r" (__a2), \
219 : __SYSCALL_CLOBBERS); \
221 _sys_result = __v0; \
226 #define internal_syscall6(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6)\
230 FORCE_FRAME_POINTER; \
232 register long __v0 asm("$2") ncs_init; \
233 register long __a0 asm("$4") = (long) arg1; \
234 register long __a1 asm("$5") = (long) arg2; \
235 register long __a2 asm("$6") = (long) arg3; \
236 register long __a3 asm("$7") = (long) arg4; \
238 ".set\tnoreorder\n\t" \
239 "subu\t$29, 32\n\t" \
240 "sw\t%6, 16($29)\n\t" \
241 "sw\t%7, 20($29)\n\t" \
244 "addiu\t$29, 32\n\t" \
246 : "=r" (__v0), "+r" (__a3) \
247 : input, "r" (__a0), "r" (__a1), "r" (__a2), \
248 "r" ((long)arg5), "r" ((long)arg6) \
249 : __SYSCALL_CLOBBERS); \
251 _sys_result = __v0; \
256 #define internal_syscall7(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6, arg7)\
260 FORCE_FRAME_POINTER; \
262 register long __v0 asm("$2") ncs_init; \
263 register long __a0 asm("$4") = (long) arg1; \
264 register long __a1 asm("$5") = (long) arg2; \
265 register long __a2 asm("$6") = (long) arg3; \
266 register long __a3 asm("$7") = (long) arg4; \
268 ".set\tnoreorder\n\t" \
269 "subu\t$29, 32\n\t" \
270 "sw\t%6, 16($29)\n\t" \
271 "sw\t%7, 20($29)\n\t" \
272 "sw\t%8, 24($29)\n\t" \
275 "addiu\t$29, 32\n\t" \
277 : "=r" (__v0), "+r" (__a3) \
278 : input, "r" (__a0), "r" (__a1), "r" (__a2), \
279 "r" ((long)arg5), "r" ((long)arg6), "r" ((long)arg7) \
280 : __SYSCALL_CLOBBERS); \
282 _sys_result = __v0; \
287 #define __SYSCALL_CLOBBERS "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", \
288 "$14", "$15", "$24", "$25", "hi", "lo", "memory"
290 #endif /* __ASSEMBLER__ */
292 /* Pointer mangling is not yet supported for MIPS. */
293 #define PTR_MANGLE(var) (void) (var)
294 #define PTR_DEMANGLE(var) (void) (var)
296 #endif /* linux/mips/mips32/sysdep.h */