Update.
[glibc.git] / sysdeps / unix / sysv / linux / mips / mips32 / sysdep.h
blob3da2412259b48dba04070e094e42a297438fe3d2
1 /* Copyright (C) 2000, 2002, 2003, 2004, 2005 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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #ifndef _LINUX_MIPS_MIPS32_SYSDEP_H
20 #define _LINUX_MIPS_MIPS32_SYSDEP_H 1
22 /* There is some commonality. */
23 #include <sysdeps/unix/mips/mips32/sysdep.h>
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
30 #ifdef __STDC__
31 # define SYS_ify(syscall_name) __NR_##syscall_name
32 #else
33 # define SYS_ify(syscall_name) __NR_/**/syscall_name
34 #endif
36 #ifdef __ASSEMBLER__
38 /* We don't want the label for the error handler to be visible in the symbol
39 table when we define it here. */
40 #ifdef __PIC__
41 # define SYSCALL_ERROR_LABEL 99b
42 #endif
44 #else /* ! __ASSEMBLER__ */
46 /* Define a macro which expands into the inline wrapper code for a system
47 call. */
48 #undef INLINE_SYSCALL
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) ) \
53 { \
54 __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err)); \
55 result_var = -1L; \
56 } \
57 result_var; })
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...) \
78 ({ \
79 long _sys_result; \
81 { \
82 register long __v0 asm("$2") ncs_init; \
83 register long __a3 asm("$7"); \
84 __asm__ volatile ( \
85 ".set\tnoreorder\n\t" \
86 cs_init \
87 "syscall\n\t" \
88 ".set reorder" \
89 : "=r" (__v0), "=r" (__a3) \
90 : input \
91 : __SYSCALL_CLOBBERS); \
92 err = __a3; \
93 _sys_result = __v0; \
94 } \
95 _sys_result; \
98 #define internal_syscall1(ncs_init, cs_init, input, err, arg1) \
99 ({ \
100 long _sys_result; \
103 register long __v0 asm("$2") ncs_init; \
104 register long __a0 asm("$4") = (long) arg1; \
105 register long __a3 asm("$7"); \
106 __asm__ volatile ( \
107 ".set\tnoreorder\n\t" \
108 cs_init \
109 "syscall\n\t" \
110 ".set reorder" \
111 : "=r" (__v0), "=r" (__a3) \
112 : input, "r" (__a0) \
113 : __SYSCALL_CLOBBERS); \
114 err = __a3; \
115 _sys_result = __v0; \
117 _sys_result; \
120 #define internal_syscall2(ncs_init, cs_init, input, err, arg1, arg2) \
121 ({ \
122 long _sys_result; \
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"); \
129 __asm__ volatile ( \
130 ".set\tnoreorder\n\t" \
131 cs_init \
132 "syscall\n\t" \
133 ".set\treorder" \
134 : "=r" (__v0), "=r" (__a3) \
135 : input, "r" (__a0), "r" (__a1) \
136 : __SYSCALL_CLOBBERS); \
137 err = __a3; \
138 _sys_result = __v0; \
140 _sys_result; \
143 #define internal_syscall3(ncs_init, cs_init, input, err, arg1, arg2, arg3)\
144 ({ \
145 long _sys_result; \
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"); \
153 __asm__ volatile ( \
154 ".set\tnoreorder\n\t" \
155 cs_init \
156 "syscall\n\t" \
157 ".set\treorder" \
158 : "=r" (__v0), "=r" (__a3) \
159 : input, "r" (__a0), "r" (__a1), "r" (__a2) \
160 : __SYSCALL_CLOBBERS); \
161 err = __a3; \
162 _sys_result = __v0; \
164 _sys_result; \
167 #define internal_syscall4(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4)\
168 ({ \
169 long _sys_result; \
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; \
177 __asm__ volatile ( \
178 ".set\tnoreorder\n\t" \
179 cs_init \
180 "syscall\n\t" \
181 ".set\treorder" \
182 : "=r" (__v0), "+r" (__a3) \
183 : input, "r" (__a0), "r" (__a1), "r" (__a2) \
184 : __SYSCALL_CLOBBERS); \
185 err = __a3; \
186 _sys_result = __v0; \
188 _sys_result; \
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)\
198 ({ \
199 long _sys_result; \
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; \
208 __asm__ volatile ( \
209 ".set\tnoreorder\n\t" \
210 "subu\t$29, 32\n\t" \
211 "sw\t%6, 16($29)\n\t" \
212 cs_init \
213 "syscall\n\t" \
214 "addiu\t$29, 32\n\t" \
215 ".set\treorder" \
216 : "=r" (__v0), "+r" (__a3) \
217 : input, "r" (__a0), "r" (__a1), "r" (__a2), \
218 "r" ((long)arg5) \
219 : __SYSCALL_CLOBBERS); \
220 err = __a3; \
221 _sys_result = __v0; \
223 _sys_result; \
226 #define internal_syscall6(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6)\
227 ({ \
228 long _sys_result; \
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; \
237 __asm__ volatile ( \
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" \
242 cs_init \
243 "syscall\n\t" \
244 "addiu\t$29, 32\n\t" \
245 ".set\treorder" \
246 : "=r" (__v0), "+r" (__a3) \
247 : input, "r" (__a0), "r" (__a1), "r" (__a2), \
248 "r" ((long)arg5), "r" ((long)arg6) \
249 : __SYSCALL_CLOBBERS); \
250 err = __a3; \
251 _sys_result = __v0; \
253 _sys_result; \
256 #define internal_syscall7(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6, arg7)\
257 ({ \
258 long _sys_result; \
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; \
267 __asm__ volatile ( \
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" \
273 cs_init \
274 "syscall\n\t" \
275 "addiu\t$29, 32\n\t" \
276 ".set\treorder" \
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); \
281 err = __a3; \
282 _sys_result = __v0; \
284 _sys_result; \
287 #define __SYSCALL_CLOBBERS "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", \
288 "$14", "$15", "$24", "$25", "memory"
290 #endif /* __ASSEMBLER__ */
292 #endif /* linux/mips/mips32/sysdep.h */