]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/sh/sysdep.h
Update.
[thirdparty/glibc.git] / 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>.
5
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.
10
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.
15
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
19 02111-1307 USA. */
20
21 #ifndef _LINUX_SH_SYSDEP_H
22 #define _LINUX_SH_SYSDEP_H 1
23
24 /* There is some commonality. */
25 #include <sysdeps/unix/sh/sysdep.h>
26
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. */
31 #undef SYS_ify
32 #define SYS_ify(syscall_name) (__NR_##syscall_name)
33
34
35 #ifdef __ASSEMBLER__
36
37 /* Linux uses a negative return value to indicate syscall errors,
38 unlike most Unices, which use the condition codes' carry flag.
39
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
46 test with -4095. */
47
48 #define _IMM1 #-1
49 #define _IMM12 #-12
50 #undef PSEUDO
51 #define PSEUDO(name, syscall_name, args) \
52 .text; \
53 ENTRY (name); \
54 DO_CALL (syscall_name, args); \
55 mov r0,r1; \
56 mov _IMM12,r2; \
57 shad r2,r1; \
58 not r1,r1; \
59 tst r1,r1; \
60 bf .Lpseudo_end; \
61 SYSCALL_ERROR_HANDLER; \
62 .Lpseudo_end:
63
64 #undef PSEUDO_END
65 #define PSEUDO_END(name) \
66 END (name)
67
68 #ifndef PIC
69 # define SYSCALL_ERROR_HANDLER \
70 mov.l 0f,r1; \
71 jmp @r1; \
72 mov r0,r4; \
73 .align 2; \
74 0: .long __syscall_error
75 #else
76 # if RTLD_PRIVATE_ERRNO
77 # define SYSCALL_ERROR_HANDLER \
78 neg r0,r1; \
79 mov.l 0f,r12; \
80 mova 0f,r0; \
81 add r0,r12; \
82 mov.l 1f,r0; \
83 mov.l r1,@(r0,r12)
84 bra .Lpseudo_end; \
85 mov _IMM1,r0; \
86 .align 2; \
87 0: .long _GLOBAL_OFFSET_TABLE_; \
88 1: .long errno@GOTOFF
89
90 # elif defined _LIBC_REENTRANT
91
92 # if USE___THREAD
93 # ifndef NOT_IN_libc
94 # define SYSCALL_ERROR_ERRNO __libc_errno
95 # else
96 # define SYSCALL_ERROR_ERRNO errno
97 # endif
98 # define SYSCALL_ERROR_HANDLER \
99 neg r0,r1; \
100 mov r12,r2; \
101 mov.l 0f,r12; \
102 mova 0f,r0; \
103 add r0,r12; \
104 mov.l 1f,r0; \
105 stc gbr, r4; \
106 mov.l @(r0,r12),r0; \
107 mov r2,r12; \
108 add r4,r0; \
109 mov.l r1,@r0; \
110 bra .Lpseudo_end; \
111 mov _IMM1,r0; \
112 .align 2; \
113 0: .long _GLOBAL_OFFSET_TABLE_; \
114 1: .long SYSCALL_ERROR_ERRNO@GOTTPOFF
115 # else
116 # define SYSCALL_ERROR_HANDLER \
117 neg r0,r1; \
118 mov.l r12,@-r15; \
119 mov.l r1,@-r15; \
120 mov.l 0f,r12; \
121 mova 0f,r0; \
122 add r0,r12; \
123 sts.l pr,@-r15; \
124 mov.l 1f,r1; \
125 bsrf r1; \
126 nop; \
127 2: lds.l @r15+,pr; \
128 mov.l @r15+,r1; \
129 mov.l r1,@r0; \
130 mov.l @r15+,r12; \
131 bra .Lpseudo_end; \
132 mov _IMM1,r0; \
133 .align 2; \
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! */
138 # endif
139 # else
140 /* Store (-r0) into errno through the GOT. */
141 # define SYSCALL_ERROR_HANDLER \
142 neg r0,r1; \
143 mov r12,r2; \
144 mov.l 0f,r12; \
145 mova 0f,r0; \
146 add r0,r12; \
147 mov.l 1f,r0; \
148 mov.l @(r0,r12),r0; \
149 mov r2,r12; \
150 mov.l r1,@r0; \
151 bra .Lpseudo_end; \
152 mov _IMM1,r0; \
153 .align 2; \
154 0: .long _GLOBAL_OFFSET_TABLE_; \
155 1: .long errno@GOT
156 # endif /* _LIBC_REENTRANT */
157 #endif /* PIC */
158
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
166
167 #undef DO_CALL
168 #define DO_CALL(syscall_name, args) \
169 mov.l 1f,r3; \
170 SYSCALL_INST##args; \
171 bra 2f; \
172 nop; \
173 .align 2; \
174 1: .long SYS_ify (syscall_name); \
175 2:
176
177 #else /* not __ASSEMBLER__ */
178
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"
186
187 #define ASMFMT_0
188 #define ASMFMT_1 \
189 , "r" (r4)
190 #define ASMFMT_2 \
191 , "r" (r4), "r" (r5)
192 #define ASMFMT_3 \
193 , "r" (r4), "r" (r5), "r" (r6)
194 #define ASMFMT_4 \
195 , "r" (r4), "r" (r5), "r" (r6), "r" (r7)
196 #define ASMFMT_5 \
197 , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0)
198 #define ASMFMT_6 \
199 , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0), "r" (r1)
200 #define ASMFMT_7 \
201 , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0), "r" (r1), "r" (r2)
202
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)
239
240 #undef INLINE_SYSCALL
241 #define INLINE_SYSCALL(name, nr, args...) \
242 ({ \
243 unsigned long resultvar; \
244 register long r3 asm ("%r3") = SYS_ify (name); \
245 SUBSTITUTE_ARGS_##nr(args); \
246 \
247 asm volatile (SYSCALL_INST_STR##nr \
248 : "=z" (resultvar) \
249 : "r" (r3) ASMFMT_##nr \
250 : "memory"); \
251 \
252 if (resultvar >= 0xfffff001) \
253 { \
254 __set_errno (-resultvar); \
255 resultvar = 0xffffffff; \
256 } \
257 (int) resultvar; })
258
259 #endif /* __ASSEMBLER__ */
260
261 #endif /* linux/sh/sysdep.h */