]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h
* sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / mips / mips64 / n32 / sysdep.h
1 /* Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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
18 02111-1307 USA. */
19
20 #ifndef _LINUX_MIPS_SYSDEP_H
21 #define _LINUX_MIPS_SYSDEP_H 1
22
23 /* There is some commonality. */
24 #include <sysdeps/unix/mips/mips64/n32/sysdep.h>
25
26 /* For Linux we can use the system call table in the header file
27 /usr/include/asm/unistd.h
28 of the kernel. But these symbols do not follow the SYS_* syntax
29 so we have to redefine the `SYS_ify' macro here. */
30 #undef SYS_ify
31 #ifdef __STDC__
32 # define SYS_ify(syscall_name) __NR_##syscall_name
33 #else
34 # define SYS_ify(syscall_name) __NR_/**/syscall_name
35 #endif
36
37 #ifdef __ASSEMBLER__
38
39 /* We don't want the label for the error handler to be visible in the symbol
40 table when we define it here. */
41 #ifdef __PIC__
42 # define SYSCALL_ERROR_LABEL 99b
43 #endif
44
45 #else /* ! __ASSEMBLER__ */
46
47 /* Define a macro which expands into the inline wrapper code for a system
48 call. */
49 #undef INLINE_SYSCALL
50 #define INLINE_SYSCALL(name, nr, args...) \
51 ({ INTERNAL_SYSCALL_DECL(err); \
52 long result_var = INTERNAL_SYSCALL (name, err, nr, args); \
53 if ( INTERNAL_SYSCALL_ERROR_P (result_var, err) ) \
54 { \
55 __set_errno (INTERNAL_SYSCALL_ERRNO (result_var, err)); \
56 result_var = -1L; \
57 } \
58 result_var; })
59
60 #undef INTERNAL_SYSCALL_DECL
61 #define INTERNAL_SYSCALL_DECL(err) long err
62
63 #undef INTERNAL_SYSCALL_ERROR_P
64 #define INTERNAL_SYSCALL_ERROR_P(val, err) ((long) (err))
65
66 #undef INTERNAL_SYSCALL_ERRNO
67 #define INTERNAL_SYSCALL_ERRNO(val, err) (val)
68
69 #undef INTERNAL_SYSCALL
70 #define INTERNAL_SYSCALL(name, err, nr, args...) \
71 internal_syscall##nr (, "li\t$2, %2\t\t\t# " #name "\n\t", \
72 "i" (SYS_ify (name)), err, args)
73
74 #undef INTERNAL_SYSCALL_NCS
75 #define INTERNAL_SYSCALL_NCS(number, err, nr, args...) \
76 internal_syscall##nr (= number, , "r" (__v0), err, args)
77
78 #define internal_syscall0(ncs_init, cs_init, input, err, dummy...) \
79 ({ \
80 long _sys_result; \
81 \
82 { \
83 register long long __v0 asm("$2") ncs_init; \
84 register long long __a3 asm("$7"); \
85 __asm__ volatile ( \
86 ".set\tnoreorder\n\t" \
87 cs_init \
88 "syscall\n\t" \
89 ".set reorder" \
90 : "=r" (__v0), "=r" (__a3) \
91 : input \
92 : __SYSCALL_CLOBBERS); \
93 err = __a3; \
94 _sys_result = __v0; \
95 } \
96 _sys_result; \
97 })
98
99 #define internal_syscall1(ncs_init, cs_init, input, err, arg1) \
100 ({ \
101 long _sys_result; \
102 \
103 { \
104 register long long __v0 asm("$2") ncs_init; \
105 register long long __a0 asm("$4") = (long long) arg1; \
106 register long long __a3 asm("$7"); \
107 __asm__ volatile ( \
108 ".set\tnoreorder\n\t" \
109 cs_init \
110 "syscall\n\t" \
111 ".set reorder" \
112 : "=r" (__v0), "=r" (__a3) \
113 : input, "r" (__a0) \
114 : __SYSCALL_CLOBBERS); \
115 err = __a3; \
116 _sys_result = __v0; \
117 } \
118 _sys_result; \
119 })
120
121 #define internal_syscall2(ncs_init, cs_init, input, err, arg1, arg2) \
122 ({ \
123 long _sys_result; \
124 \
125 { \
126 register long long __v0 asm("$2") ncs_init; \
127 register long long __a0 asm("$4") = (long long) arg1; \
128 register long long __a1 asm("$5") = (long long) arg2; \
129 register long long __a3 asm("$7"); \
130 __asm__ volatile ( \
131 ".set\tnoreorder\n\t" \
132 cs_init \
133 "syscall\n\t" \
134 ".set\treorder" \
135 : "=r" (__v0), "=r" (__a3) \
136 : input, "r" (__a0), "r" (__a1) \
137 : __SYSCALL_CLOBBERS); \
138 err = __a3; \
139 _sys_result = __v0; \
140 } \
141 _sys_result; \
142 })
143
144 #define internal_syscall3(ncs_init, cs_init, input, err, arg1, arg2, arg3) \
145 ({ \
146 long _sys_result; \
147 \
148 { \
149 register long long __v0 asm("$2") ncs_init; \
150 register long long __a0 asm("$4") = (long long) arg1; \
151 register long long __a1 asm("$5") = (long long) arg2; \
152 register long long __a2 asm("$6") = (long long) arg3; \
153 register long long __a3 asm("$7"); \
154 __asm__ volatile ( \
155 ".set\tnoreorder\n\t" \
156 cs_init \
157 "syscall\n\t" \
158 ".set\treorder" \
159 : "=r" (__v0), "=r" (__a3) \
160 : input, "r" (__a0), "r" (__a1), "r" (__a2) \
161 : __SYSCALL_CLOBBERS); \
162 err = __a3; \
163 _sys_result = __v0; \
164 } \
165 _sys_result; \
166 })
167
168 #define internal_syscall4(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4) \
169 ({ \
170 long _sys_result; \
171 \
172 { \
173 register long long __v0 asm("$2") ncs_init; \
174 register long long __a0 asm("$4") = (long long) arg1; \
175 register long long __a1 asm("$5") = (long long) arg2; \
176 register long long __a2 asm("$6") = (long long) arg3; \
177 register long long __a3 asm("$7") = (long long) arg4; \
178 __asm__ volatile ( \
179 ".set\tnoreorder\n\t" \
180 cs_init \
181 "syscall\n\t" \
182 ".set\treorder" \
183 : "=r" (__v0), "+r" (__a3) \
184 : input, "r" (__a0), "r" (__a1), "r" (__a2) \
185 : __SYSCALL_CLOBBERS); \
186 err = __a3; \
187 _sys_result = __v0; \
188 } \
189 _sys_result; \
190 })
191
192 #define internal_syscall5(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5) \
193 ({ \
194 long _sys_result; \
195 \
196 { \
197 register long long __v0 asm("$2") ncs_init; \
198 register long long __a0 asm("$4") = (long long) arg1; \
199 register long long __a1 asm("$5") = (long long) arg2; \
200 register long long __a2 asm("$6") = (long long) arg3; \
201 register long long __a3 asm("$7") = (long long) arg4; \
202 register long long __a4 asm("$8") = (long long) arg5; \
203 __asm__ volatile ( \
204 ".set\tnoreorder\n\t" \
205 cs_init \
206 "syscall\n\t" \
207 ".set\treorder" \
208 : "=r" (__v0), "+r" (__a3) \
209 : input, "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a4) \
210 : __SYSCALL_CLOBBERS); \
211 err = __a3; \
212 _sys_result = __v0; \
213 } \
214 _sys_result; \
215 })
216
217 #define internal_syscall6(ncs_init, cs_init, input, err, arg1, arg2, arg3, arg4, arg5, arg6) \
218 ({ \
219 long _sys_result; \
220 \
221 { \
222 register long long __v0 asm("$2") ncs_init; \
223 register long long __a0 asm("$4") = (long long) arg1; \
224 register long long __a1 asm("$5") = (long long) arg2; \
225 register long long __a2 asm("$6") = (long long) arg3; \
226 register long long __a3 asm("$7") = (long long) arg4; \
227 register long long __a4 asm("$8") = (long long) arg5; \
228 register long long __a5 asm("$9") = (long long) arg6; \
229 __asm__ volatile ( \
230 ".set\tnoreorder\n\t" \
231 cs_init \
232 "syscall\n\t" \
233 ".set\treorder" \
234 : "=r" (__v0), "+r" (__a3) \
235 : input, "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a4), \
236 "r" (__a5) \
237 : __SYSCALL_CLOBBERS); \
238 err = __a3; \
239 _sys_result = __v0; \
240 } \
241 _sys_result; \
242 })
243
244 #define __SYSCALL_CLOBBERS "$1", "$3", "$10", "$11", "$12", "$13", \
245 "$14", "$15", "$24", "$25", "memory"
246 #endif /* __ASSEMBLER__ */
247
248 #endif /* linux/mips/sysdep.h */