]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/sh/sysdep.h
1 /* Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>, August 1995.
4 Changed by Kaz Kojima, <kkojima@rr.iij4u.or.jp>.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #ifndef _LINUX_SH_SYSDEP_H
22 #define _LINUX_SH_SYSDEP_H 1
24 /* There is some commonality. */
25 #include <sysdeps/unix/sh/sysdep.h>
27 /* For Linux we can use the system call table in the header file
28 /usr/include/asm/unistd.h
29 of the kernel. But these symbols do not follow the SYS_* syntax
30 so we have to redefine the `SYS_ify' macro here. */
32 #define SYS_ify(syscall_name) (__NR_##syscall_name)
37 /* Linux uses a negative return value to indicate syscall errors,
38 unlike most Unices, which use the condition codes' carry flag.
40 Since version 2.1 the return value of a system call might be
41 negative even if the call succeeded. E.g., the `lseek' system call
42 might return a large offset. Therefore we must not anymore test
43 for < 0, but test for a real error by making sure the value in R0
44 is a real error number. Linus said he will make sure the no syscall
45 returns a value in -1 .. -4095 as a valid result so we can savely
51 #define PSEUDO(name, syscall_name, args) \
54 DO_CALL (syscall_name, args); \
61 SYSCALL_ERROR_HANDLER; \
65 #define PSEUDO_END(name) \
69 # define SYSCALL_ERROR_HANDLER \
74 0: .long __syscall_error
76 # if RTLD_PRIVATE_ERRNO
77 # define SYSCALL_ERROR_HANDLER \
87 0: .long _GLOBAL_OFFSET_TABLE_
; \
90 # elif defined _LIBC_REENTRANT
94 # define SYSCALL_ERROR_ERRNO __libc_errno
96 # define SYSCALL_ERROR_ERRNO errno
98 # define SYSCALL_ERROR_HANDLER \
106 mov.l @(r0,r12),r0; \
113 0: .long _GLOBAL_OFFSET_TABLE_; \
114 1: .long SYSCALL_ERROR_ERRNO@GOTTPOFF
116 # define SYSCALL_ERROR_HANDLER \
134 0: .long _GLOBAL_OFFSET_TABLE_; \
135 1: .long PLTJMP(C_SYMBOL_NAME(__errno_location))-(2b+2-.)
136 /* A quick note: it is assumed that the call to `__errno_location' does
137 not modify the stack! */
140 /* Store (-r0) into errno through the GOT. */
141 # define SYSCALL_ERROR_HANDLER \
148 mov.l @(r0,r12),r0; \
154 0: .long _GLOBAL_OFFSET_TABLE_; \
156 # endif /* _LIBC_REENTRANT */
159 #define SYSCALL_INST0 trapa #0x10
160 #define SYSCALL_INST1 trapa #0x11
161 #define SYSCALL_INST2 trapa #0x12
162 #define SYSCALL_INST3 trapa #0x13
163 #define SYSCALL_INST4 trapa #0x14
164 #define SYSCALL_INST5 mov.l @(0,r15),r0; trapa #0x15
165 #define SYSCALL_INST6 mov.l @(0,r15),r0; mov.l @(4,r15),r1; trapa #0x16
168 #define DO_CALL(syscall_name, args) \
170 SYSCALL_INST##args; \
174 1: .long SYS_ify (syscall_name); \
177 #else /* not __ASSEMBLER__ */
179 #define SYSCALL_INST_STR0 "trapa #0x10\n\t"
180 #define SYSCALL_INST_STR1 "trapa #0x11\n\t"
181 #define SYSCALL_INST_STR2 "trapa #0x12\n\t"
182 #define SYSCALL_INST_STR3 "trapa #0x13\n\t"
183 #define SYSCALL_INST_STR4 "trapa #0x14\n\t"
184 #define SYSCALL_INST_STR5 "trapa #0x15\n\t"
185 #define SYSCALL_INST_STR6 "trapa #0x16\n\t"
193 , "r" (r4), "r" (r5), "r" (r6)
195 , "r" (r4), "r" (r5), "r" (r6), "r" (r7)
197 , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0)
199 , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0), "r" (r1)
201 , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0), "r" (r1), "r" (r2)
203 #define SUBSTITUTE_ARGS_0()
204 #define SUBSTITUTE_ARGS_1(arg1) \
205 register long r4 asm ("%r4") = (long)(arg1)
206 #define SUBSTITUTE_ARGS_2(arg1, arg2) \
207 register long r4 asm ("%r4") = (long)(arg1); \
208 register long r5 asm ("%r5") = (long)(arg2)
209 #define SUBSTITUTE_ARGS_3(arg1, arg2, arg3) \
210 register long r4 asm ("%r4") = (long)(arg1); \
211 register long r5 asm ("%r5") = (long)(arg2); \
212 register long r6 asm ("%r6") = (long)(arg3)
213 #define SUBSTITUTE_ARGS_4(arg1, arg2, arg3, arg4) \
214 register long r4 asm ("%r4") = (long)(arg1); \
215 register long r5 asm ("%r5") = (long)(arg2); \
216 register long r6 asm ("%r6") = (long)(arg3); \
217 register long r7 asm ("%r7") = (long)(arg4)
218 #define SUBSTITUTE_ARGS_5(arg1, arg2, arg3, arg4, arg5) \
219 register long r4 asm ("%r4") = (long)(arg1); \
220 register long r5 asm ("%r5") = (long)(arg2); \
221 register long r6 asm ("%r6") = (long)(arg3); \
222 register long r7 asm ("%r7") = (long)(arg4); \
223 register long r0 asm ("%r0") = (long)(arg5)
224 #define SUBSTITUTE_ARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
225 register long r4 asm ("%r4") = (long)(arg1); \
226 register long r5 asm ("%r5") = (long)(arg2); \
227 register long r6 asm ("%r6") = (long)(arg3); \
228 register long r7 asm ("%r7") = (long)(arg4); \
229 register long r0 asm ("%r0") = (long)(arg5); \
230 register long r1 asm ("%r1") = (long)(arg6)
231 #define SUBSTITUTE_ARGS_7(arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
232 register long r4 asm ("%r4") = (long)(arg1); \
233 register long r5 asm ("%r5") = (long)(arg2); \
234 register long r6 asm ("%r6") = (long)(arg3); \
235 register long r7 asm ("%r7") = (long)(arg4); \
236 register long r0 asm ("%r0") = (long)(arg5) \
237 register long r1 asm ("%r1") = (long)(arg6); \
238 register long r2 asm ("%r2") = (long)(arg7)
240 #undef INLINE_SYSCALL
241 #define INLINE_SYSCALL(name, nr, args...) \
243 unsigned long resultvar; \
244 register long r3 asm ("%r3") = SYS_ify (name); \
245 SUBSTITUTE_ARGS_##nr(args); \
247 asm volatile (SYSCALL_INST_STR##nr \
249 : "r" (r3) ASMFMT_##nr \
252 if (resultvar >= 0xfffff001) \
254 __set_errno (-resultvar); \
255 resultvar = 0xffffffff; \
259 #endif /* __ASSEMBLER__ */
261 #endif /* linux/sh/sysdep.h */