Move all files into ports/ subdirectory in preparation for merge with glibc
[glibc.git] / ports / sysdeps / unix / sysv / linux / mips / mips32 / sysdep.h
blob8c024b024103c0e3394b540d7159965f945d2276
1 /* Copyright (C) 2000, 2002, 2003, 2004, 2005,
2 2009, 2012 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, see
17 <http://www.gnu.org/licenses/>. */
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 #include <tls.h>
27 /* In order to get __set_errno() definition in INLINE_SYSCALL. */
28 #ifndef __ASSEMBLER__
29 #include <errno.h>
30 #endif
32 /* For Linux we can use the system call table in the header file
33 /usr/include/asm/unistd.h
34 of the kernel. But these symbols do not follow the SYS_* syntax
35 so we have to redefine the `SYS_ify' macro here. */
36 #undef SYS_ify
37 #define SYS_ify(syscall_name) __NR_##syscall_name
39 #ifdef __ASSEMBLER__
41 /* We don't want the label for the error handler to be visible in the symbol
42 table when we define it here. */
43 #ifdef __PIC__
44 # define SYSCALL_ERROR_LABEL 99b
45 #endif
47 #else /* ! __ASSEMBLER__ */
49 /* Define a macro which expands into the inline wrapper code for a system
50 call. */
51 #undef INLINE_SYSCALL
52 #define INLINE_SYSCALL(name, nr, args...) \
53 ({ INTERNAL_SYSCALL_DECL(err); \
54 long result_var = INTERNAL_SYSCALL (name, err, nr, args); \
55 if ( INTERNAL_SYSCALL_ERROR_P (result_var, err) ) \
56 { \
57 __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err)); \
58 result_var = -1L; \
59 } \
60 result_var; })
62 #undef INTERNAL_SYSCALL_DECL
63 #define INTERNAL_SYSCALL_DECL(err) long err
65 #undef INTERNAL_SYSCALL_ERROR_P
66 #define INTERNAL_SYSCALL_ERROR_P(val, err) ((long) (err))
68 #undef INTERNAL_SYSCALL_ERRNO
69 #define INTERNAL_SYSCALL_ERRNO(val, err) (val)
71 #undef INTERNAL_SYSCALL
72 #define INTERNAL_SYSCALL(name, err, nr, args...) \
73 internal_syscall##nr (, "li\t$2, %2\t\t\t# " #name "\n\t", \
74 "i" (SYS_ify (name)), err, args)
76 #undef INTERNAL_SYSCALL_NCS
77 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
78 internal_syscall##nr (= number, , "r" (__v0), err, args)
80 #define internal_syscall0(ncs_init, cs_init, input, err, dummy...) \
81 ({ \
82 long _sys_result; \
84 { \
85 register long __v0 asm("$2") ncs_init; \
86 register long __a3 asm("$7"); \
87 __asm__ volatile ( \
88 ".set\tnoreorder\n\t" \
89 cs_init \
90 "syscall\n\t" \
91 ".set reorder" \
92 : "=r" (__v0), "=r" (__a3) \
93 : input \
94 : __SYSCALL_CLOBBERS); \
95 err = __a3; \
96 _sys_result = __v0; \
97 } \
98 _sys_result; \
101 #define internal_syscall1(ncs_init, cs_init, input, err, arg1) \
102 ({ \
103 long _sys_result; \
106 register long __v0 asm("$2") ncs_init; \
107 register long __a0 asm("$4") = (long) arg1; \
108 register long __a3 asm("$7"); \
109 __asm__ volatile ( \
110 ".set\tnoreorder\n\t" \
111 cs_init \
112 "syscall\n\t" \
113 ".set reorder" \
114 : "=r" (__v0), "=r" (__a3) \
115 : input, "r" (__a0) \
116 : __SYSCALL_CLOBBERS); \
117 err = __a3; \
118 _sys_result = __v0; \
120 _sys_result; \
123 #define internal_syscall2(ncs_init, cs_init, input, err, arg1, arg2) \
124 ({ \
125 long _sys_result; \
128 register long __v0 asm("$2") ncs_init; \
129 register long __a0 asm("$4") = (long) arg1; \
130 register long __a1 asm("$5") = (long) arg2; \
131 register long __a3 asm("$7"); \
132 __asm__ volatile ( \
133 ".set\tnoreorder\n\t" \
134 cs_init \
135 "syscall\n\t" \
136 ".set\treorder" \
137 : "=r" (__v0), "=r" (__a3) \
138 : input, "r" (__a0), "r" (__a1) \
139 : __SYSCALL_CLOBBERS); \
140 err = __a3; \
141 _sys_result = __v0; \
143 _sys_result; \
146 #define internal_syscall3(ncs_init, cs_init, input, err, arg1, arg2, arg3)\
147 ({ \
148 long _sys_result; \
151 register long __v0 asm("$2") ncs_init; \
152 register long __a0 asm("$4") = (long) arg1; \
153 register long __a1 asm("$5") = (long) arg2; \
154 register long __a2 asm("$6") = (long) arg3; \
155 register long __a3 asm("$7"); \
156 __asm__ volatile ( \
157 ".set\tnoreorder\n\t" \
158 cs_init \
159 "syscall\n\t" \
160 ".set\treorder" \
161 : "=r" (__v0), "=r" (__a3) \
162 : input, "r" (__a0), "r" (__a1), "r" (__a2) \
163 : __SYSCALL_CLOBBERS); \
164 err = __a3; \
165 _sys_result = __v0; \
167 _sys_result; \
170 #define internal_syscall4(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4)\
171 ({ \
172 long _sys_result; \
175 register long __v0 asm("$2") ncs_init; \
176 register long __a0 asm("$4") = (long) arg1; \
177 register long __a1 asm("$5") = (long) arg2; \
178 register long __a2 asm("$6") = (long) arg3; \
179 register long __a3 asm("$7") = (long) arg4; \
180 __asm__ volatile ( \
181 ".set\tnoreorder\n\t" \
182 cs_init \
183 "syscall\n\t" \
184 ".set\treorder" \
185 : "=r" (__v0), "+r" (__a3) \
186 : input, "r" (__a0), "r" (__a1), "r" (__a2) \
187 : __SYSCALL_CLOBBERS); \
188 err = __a3; \
189 _sys_result = __v0; \
191 _sys_result; \
194 /* We need to use a frame pointer for the functions in which we
195 adjust $sp around the syscall, or debug information and unwind
196 information will be $sp relative and thus wrong during the syscall. As
197 of GCC 4.7, this is sufficient. */
198 #define FORCE_FRAME_POINTER \
199 void *volatile __fp_force __attribute__ ((unused)) = alloca (4)
201 #define internal_syscall5(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5)\
202 ({ \
203 long _sys_result; \
205 FORCE_FRAME_POINTER; \
207 register long __v0 asm("$2") ncs_init; \
208 register long __a0 asm("$4") = (long) arg1; \
209 register long __a1 asm("$5") = (long) arg2; \
210 register long __a2 asm("$6") = (long) arg3; \
211 register long __a3 asm("$7") = (long) arg4; \
212 __asm__ volatile ( \
213 ".set\tnoreorder\n\t" \
214 "subu\t$29, 32\n\t" \
215 "sw\t%6, 16($29)\n\t" \
216 cs_init \
217 "syscall\n\t" \
218 "addiu\t$29, 32\n\t" \
219 ".set\treorder" \
220 : "=r" (__v0), "+r" (__a3) \
221 : input, "r" (__a0), "r" (__a1), "r" (__a2), \
222 "r" ((long)arg5) \
223 : __SYSCALL_CLOBBERS); \
224 err = __a3; \
225 _sys_result = __v0; \
227 _sys_result; \
230 #define internal_syscall6(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6)\
231 ({ \
232 long _sys_result; \
234 FORCE_FRAME_POINTER; \
236 register long __v0 asm("$2") ncs_init; \
237 register long __a0 asm("$4") = (long) arg1; \
238 register long __a1 asm("$5") = (long) arg2; \
239 register long __a2 asm("$6") = (long) arg3; \
240 register long __a3 asm("$7") = (long) arg4; \
241 __asm__ volatile ( \
242 ".set\tnoreorder\n\t" \
243 "subu\t$29, 32\n\t" \
244 "sw\t%6, 16($29)\n\t" \
245 "sw\t%7, 20($29)\n\t" \
246 cs_init \
247 "syscall\n\t" \
248 "addiu\t$29, 32\n\t" \
249 ".set\treorder" \
250 : "=r" (__v0), "+r" (__a3) \
251 : input, "r" (__a0), "r" (__a1), "r" (__a2), \
252 "r" ((long)arg5), "r" ((long)arg6) \
253 : __SYSCALL_CLOBBERS); \
254 err = __a3; \
255 _sys_result = __v0; \
257 _sys_result; \
260 #define internal_syscall7(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6, arg7)\
261 ({ \
262 long _sys_result; \
264 FORCE_FRAME_POINTER; \
266 register long __v0 asm("$2") ncs_init; \
267 register long __a0 asm("$4") = (long) arg1; \
268 register long __a1 asm("$5") = (long) arg2; \
269 register long __a2 asm("$6") = (long) arg3; \
270 register long __a3 asm("$7") = (long) arg4; \
271 __asm__ volatile ( \
272 ".set\tnoreorder\n\t" \
273 "subu\t$29, 32\n\t" \
274 "sw\t%6, 16($29)\n\t" \
275 "sw\t%7, 20($29)\n\t" \
276 "sw\t%8, 24($29)\n\t" \
277 cs_init \
278 "syscall\n\t" \
279 "addiu\t$29, 32\n\t" \
280 ".set\treorder" \
281 : "=r" (__v0), "+r" (__a3) \
282 : input, "r" (__a0), "r" (__a1), "r" (__a2), \
283 "r" ((long)arg5), "r" ((long)arg6), "r" ((long)arg7) \
284 : __SYSCALL_CLOBBERS); \
285 err = __a3; \
286 _sys_result = __v0; \
288 _sys_result; \
291 #define __SYSCALL_CLOBBERS "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", \
292 "$14", "$15", "$24", "$25", "hi", "lo", "memory"
294 #endif /* __ASSEMBLER__ */
296 /* Pointer mangling is not yet supported for MIPS. */
297 #define PTR_MANGLE(var) (void) (var)
298 #define PTR_DEMANGLE(var) (void) (var)
300 #endif /* linux/mips/mips32/sysdep.h */