1 /* Copyright (C) 2000-2014 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 License as
7 published by the Free Software Foundation; either version 2.1 of the
8 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 #include <sysdeps/microblaze/sysdep.h>
20 #include <sys/syscall.h>
22 /* Defines RTLD_PRIVATE_ERRNO. */
23 #include <dl-sysdep.h>
25 /* In order to get __set_errno() definition in INLINE_SYSCALL. */
30 /* For Linux we can use the system call table in the header file
31 /usr/include/asm/unistd.h
32 of the kernel. But these symbols do not follow the SYS_* syntax
33 so we have to redefine the `SYS_ify' macro here. */
35 #define SYS_ify(syscall_name) __NR_##syscall_name
39 /* In microblaze ABI function call arguments are passed in registers
40 r5...r10. The return value is stored in r3 (or r3:r4 regiters pair).
41 Linux syscall uses the same convention with the addition that the
42 syscall number is passed in r12. To enter the kernel "brki r14,8"
44 None of the abovementioned registers are presumed across function call
47 /* Linux uses a negative return value to indicate syscall errors, unlike
48 most Unices, which use the condition codes' carry flag.
50 Since version 2.1 the return value of a system call might be negative
51 even if the call succeeded. E.g., the `lseek' system call might return
52 a large offset. Therefore we must not anymore test for < 0, but test
53 for a real error by making sure the value in %d0 is a real error
54 number. Linus said he will make sure the no syscall returns a value
55 in -1 .. -4095 as a valid result so we can savely test with -4095. */
57 /* We don't want the label for the error handler to be visible in the symbol
58 table when we define it here. */
60 # define SYSCALL_ERROR_LABEL 0f
62 # define SYSCALL_ERROR_LABEL __syscall_error
66 # define PSEUDO(name, syscall_name, args) \
69 DO_CALL (syscall_name, args); \
72 bgei r12,SYSCALL_ERROR_LABEL;
75 # define PSEUDO_END(name) \
76 SYSCALL_ERROR_HANDLER; \
79 # undef PSEUDO_NOERRNO
80 # define PSEUDO_NOERRNO(name, syscall_name, args) \
83 DO_CALL (syscall_name, args);
85 # undef PSEUDO_END_NOERRNO
86 # define PSEUDO_END_NOERRNO(name) \
89 /* The function has to return the error code. */
91 # define PSEUDO_ERRVAL(name, syscall_name, args) \
94 DO_CALL (syscall_name, args); \
96 # undef PSEUDO_END_ERRVAL
97 # define PSEUDO_END_ERRVAL(name) \
100 # define ret_NOERRNO \
101 rtsd r15,8; addk r0,r0,r0;
103 # define ret_ERRVAL \
104 rtsd r15,8; rsubk r3,r3,r0;
107 # define SYSCALL_ERROR_LABEL_DCL 0
108 # if RTLD_PRIVATE_ERRNO
109 # define SYSCALL_ERROR_HANDLER \
110 SYSCALL_ERROR_LABEL_DCL: \
112 addik r12,r12,_GLOBAL_OFFSET_TABLE_+8; \
113 lwi r12,r12,rtld_errno@GOT; \
118 # else /* !RTLD_PRIVATE_ERRNO. */
119 /* Store (-r3) into errno through the GOT. */
120 # if defined _LIBC_REENTRANT
121 # define SYSCALL_ERROR_HANDLER \
122 SYSCALL_ERROR_LABEL_DCL: \
129 addik r20,r20,_GLOBAL_OFFSET_TABLE_+8; \
130 brlid r15,__errno_location@PLT; \
139 # else /* !_LIBC_REENTRANT. */
140 # define SYSCALL_ERROR_HANDLER \
141 SYSCALL_ERROR_LABEL_DCL: \
143 addik r12,r12,_GLOBAL_OFFSET_TABLE_+8; \
144 lwi r12,r12,errno@GOT; \
149 # endif /* _LIBC_REENTRANT. */
150 # endif /* RTLD_PRIVATE_ERRNO. */
152 # define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
155 # define DO_CALL(syscall_name, args) \
156 addik r12,r0,SYS_ify (syscall_name); \
160 #else /* not __ASSEMBLER__ */
162 /* Define a macro which expands into the inline wrapper code for a system
164 # undef INLINE_SYSCALL
165 # define INLINE_SYSCALL(name, nr, args...) \
166 ({ INTERNAL_SYSCALL_DECL(err); \
167 unsigned long resultvar = INTERNAL_SYSCALL(name, err, nr, args); \
168 if (INTERNAL_SYSCALL_ERROR_P (resultvar, err)) \
170 __set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, err)); \
171 resultvar = (unsigned long) -1; \
176 # undef INTERNAL_SYSCALL_DECL
177 # define INTERNAL_SYSCALL_DECL(err) do { } while (0)
179 /* Define a macro which expands inline into the wrapper code for a system
180 call. This use is for internal calls that do not need to handle errors
181 normally. It will never touch errno. This returns just what the kernel
183 # undef INTERNAL_SYSCALL
184 # define INTERNAL_SYSCALL(name, err, nr, args...) \
185 inline_syscall##nr(SYS_ify(name), args)
187 # undef INTERNAL_SYSCALL_NCS
188 # define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
189 inline_syscall##nr(name, args)
191 # undef INTERNAL_SYSCALL_ERROR_P
192 # define INTERNAL_SYSCALL_ERROR_P(val, err) \
193 ((unsigned int) (val) >= -4095U)
195 # undef INTERNAL_SYSCALL_ERRNO
196 # define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
198 # define SYSCALL_CLOBBERS_6 "r11", "r4", "memory"
199 # define SYSCALL_CLOBBERS_5 "r10", SYSCALL_CLOBBERS_6
200 # define SYSCALL_CLOBBERS_4 "r9", SYSCALL_CLOBBERS_5
201 # define SYSCALL_CLOBBERS_3 "r8", SYSCALL_CLOBBERS_4
202 # define SYSCALL_CLOBBERS_2 "r7", SYSCALL_CLOBBERS_3
203 # define SYSCALL_CLOBBERS_1 "r6", SYSCALL_CLOBBERS_2
204 # define SYSCALL_CLOBBERS_0 "r5", SYSCALL_CLOBBERS_1
206 # define inline_syscall0(name,dummy) \
208 register long ret __asm__("r3"); \
209 register long __r12 __asm__("r12") = name; \
210 __asm__ __volatile__( "brki r14,8; nop;" \
213 : SYSCALL_CLOBBERS_0 ); ret; \
216 # define inline_syscall1(name,arg1) \
218 register long ret __asm__("r3"); \
219 register long __r12 __asm__("r12") = name; \
220 register long __r5 __asm__("r5") = (long)(arg1); \
221 __asm__ __volatile__( "brki r14,8; nop;" \
223 : "r"(__r5), "r"(__r12) \
224 : SYSCALL_CLOBBERS_1 ); ret; \
227 # define inline_syscall2(name,arg1,arg2) \
229 register long ret __asm__("r3"); \
230 register long __r12 __asm__("r12") = name; \
231 register long __r5 __asm__("r5") = (long)(arg1); \
232 register long __r6 __asm__("r6") = (long)(arg2); \
233 __asm__ __volatile__( "brki r14,8; nop;" \
235 : "r"(__r5), "r"(__r6), "r"(__r12) \
236 : SYSCALL_CLOBBERS_2 ); ret; \
240 # define inline_syscall3(name,arg1,arg2,arg3) \
242 register long ret __asm__("r3"); \
243 register long __r12 __asm__("r12") = name; \
244 register long __r5 __asm__("r5") = (long)(arg1); \
245 register long __r6 __asm__("r6") = (long)(arg2); \
246 register long __r7 __asm__("r7") = (long)(arg3); \
247 __asm__ __volatile__( "brki r14,8; nop;" \
249 : "r"(__r5), "r"(__r6), "r"(__r7), "r"(__r12) \
250 : SYSCALL_CLOBBERS_3 ); ret; \
254 # define inline_syscall4(name,arg1,arg2,arg3,arg4) \
256 register long ret __asm__("r3"); \
257 register long __r12 __asm__("r12") = name; \
258 register long __r5 __asm__("r5") = (long)(arg1); \
259 register long __r6 __asm__("r6") = (long)(arg2); \
260 register long __r7 __asm__("r7") = (long)(arg3); \
261 register long __r8 __asm__("r8") = (long)(arg4); \
262 __asm__ __volatile__( "brki r14,8; nop;" \
264 : "r"(__r5), "r"(__r6), "r"(__r7), "r"(__r8),"r"(__r12) \
265 : SYSCALL_CLOBBERS_4 ); ret; \
269 # define inline_syscall5(name,arg1,arg2,arg3,arg4,arg5) \
271 register long ret __asm__("r3"); \
272 register long __r12 __asm__("r12") = name; \
273 register long __r5 __asm__("r5") = (long)(arg1); \
274 register long __r6 __asm__("r6") = (long)(arg2); \
275 register long __r7 __asm__("r7") = (long)(arg3); \
276 register long __r8 __asm__("r8") = (long)(arg4); \
277 register long __r9 __asm__("r9") = (long)(arg5); \
278 __asm__ __volatile__( "brki r14,8; nop;" \
280 : "r"(__r5), "r"(__r6), "r"(__r7), "r"(__r8),"r"(__r9), "r"(__r12) \
281 : SYSCALL_CLOBBERS_5 ); ret; \
285 # define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6) \
287 register long ret __asm__("r3"); \
288 register long __r12 __asm__("r12") = name; \
289 register long __r5 __asm__("r5") = (long)(arg1); \
290 register long __r6 __asm__("r6") = (long)(arg2); \
291 register long __r7 __asm__("r7") = (long)(arg3); \
292 register long __r8 __asm__("r8") = (long)(arg4); \
293 register long __r9 __asm__("r9") = (long)(arg5); \
294 register long __r10 __asm__("r10") = (long)(arg6); \
295 __asm__ __volatile__( "brki r14,8; nop;" \
297 : "r"(__r5), "r"(__r6), "r"(__r7), "r"(__r8),"r"(__r9), "r"(__r10), \
299 : SYSCALL_CLOBBERS_6 ); ret; \
303 /* Pointer mangling is not yet supported for Microblaze. */
304 # define PTR_MANGLE(var) (void) (var)
305 # define PTR_DEMANGLE(var) (void) (var)
307 #endif /* not __ASSEMBLER__ */