1 /* Copyright (C) 1992-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #ifndef _LINUX_SH_SYSDEP_H
19 #define _LINUX_SH_SYSDEP_H 1
21 /* There is some commonality. */
22 #include <sysdeps/unix/sysv/linux/sysdep.h>
23 #include <sysdeps/unix/sh/sysdep.h>
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. */
31 #define SYS_ify(syscall_name) (__NR_##syscall_name)
36 /* Linux uses a negative return value to indicate syscall errors,
37 unlike most Unices, which use the condition codes' carry flag.
39 Since version 2.1 the return value of a system call might be
40 negative even if the call succeeded. E.g., the `lseek' system call
41 might return a large offset. Therefore we must not anymore test
42 for < 0, but test for a real error by making sure the value in R0
43 is a real error number. Linus said he will make sure the no syscall
44 returns a value in -1 .. -4095 as a valid result so we can safely
50 #define PSEUDO(name, syscall_name, args) \
53 DO_CALL (syscall_name, args); \
60 SYSCALL_ERROR_HANDLER; \
64 #define PSEUDO_END(name) \
68 #define PSEUDO_NOERRNO(name, syscall_name, args) \
71 DO_CALL (syscall_name, args)
73 #undef PSEUDO_END_NOERRNO
74 #define PSEUDO_END_NOERRNO(name) \
77 #define ret_NOERRNO ret
79 #define PSEUDO_ERRVAL(name, syscall_name, args) \
82 DO_CALL (syscall_name, args);
84 #undef PSEUDO_END_ERRVAL
85 #define PSEUDO_END_ERRVAL(name) \
88 #define ret_ERRVAL ret
91 # define SYSCALL_ERROR_HANDLER \
96 0: .long __syscall_error
98 # if RTLD_PRIVATE_ERRNO
99 # define SYSCALL_ERROR_HANDLER \
102 cfi_register (r12, r2); \
107 mov.l r1,@(r0,r12); \
113 0: .long _GLOBAL_OFFSET_TABLE_; \
114 1: .long rtld_errno@GOTOFF
116 # elif defined _LIBC_REENTRANT
119 # define SYSCALL_ERROR_ERRNO __libc_errno
121 # define SYSCALL_ERROR_ERRNO errno
123 # define SYSCALL_ERROR_HANDLER \
126 cfi_register (r12, r2); \
132 mov.l @(r0,r12),r0; \
140 0: .long _GLOBAL_OFFSET_TABLE_; \
141 1: .long SYSCALL_ERROR_ERRNO@GOTTPOFF
143 /* Store (-r0) into errno through the GOT. */
144 # define SYSCALL_ERROR_HANDLER \
147 cfi_register (r12, r2); \
152 mov.l @(r0,r12),r0; \
159 0: .long _GLOBAL_OFFSET_TABLE_; \
161 # endif /* _LIBC_REENTRANT */
164 # ifdef NEED_SYSCALL_INST_PAD
165 # define SYSCALL_INST_PAD \
166 or r0,r0; or r0,r0; or r0,r0; or r0,r0; or r0,r0
168 # define SYSCALL_INST_PAD
171 #define SYSCALL_INST0 trapa #0x10
172 #define SYSCALL_INST1 trapa #0x11
173 #define SYSCALL_INST2 trapa #0x12
174 #define SYSCALL_INST3 trapa #0x13
175 #define SYSCALL_INST4 trapa #0x14
176 #define SYSCALL_INST5 mov.l @(0,r15),r0; trapa #0x15
177 #define SYSCALL_INST6 mov.l @(0,r15),r0; mov.l @(4,r15),r1; trapa #0x16
180 #define DO_CALL(syscall_name, args) \
182 SYSCALL_INST##args; \
187 1: .long SYS_ify (syscall_name); \
190 #else /* not __ASSEMBLER__ */
192 #define SYSCALL_INST_STR0 "trapa #0x10\n\t"
193 #define SYSCALL_INST_STR1 "trapa #0x11\n\t"
194 #define SYSCALL_INST_STR2 "trapa #0x12\n\t"
195 #define SYSCALL_INST_STR3 "trapa #0x13\n\t"
196 #define SYSCALL_INST_STR4 "trapa #0x14\n\t"
197 #define SYSCALL_INST_STR5 "trapa #0x15\n\t"
198 #define SYSCALL_INST_STR6 "trapa #0x16\n\t"
200 # ifdef NEED_SYSCALL_INST_PAD
201 # define SYSCALL_INST_PAD "\
202 or r0,r0; or r0,r0; or r0,r0; or r0,r0; or r0,r0"
204 # define SYSCALL_INST_PAD
213 , "r" (r4), "r" (r5), "r" (r6)
215 , "r" (r4), "r" (r5), "r" (r6), "r" (r7)
217 , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0)
219 , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0), "r" (r1)
221 , "r" (r4), "r" (r5), "r" (r6), "r" (r7), "0" (r0), "r" (r1), "r" (r2)
223 #define SUBSTITUTE_ARGS_0()
224 #define SUBSTITUTE_ARGS_1(arg1) \
225 long int _arg1 = (long int) (arg1); \
226 register long int r4 asm ("%r4") = (long int) (_arg1)
227 #define SUBSTITUTE_ARGS_2(arg1, arg2) \
228 long int _arg1 = (long int) (arg1); \
229 long int _arg2 = (long int) (arg2); \
230 register long int r4 asm ("%r4") = (long int) (_arg1); \
231 register long int r5 asm ("%r5") = (long int) (_arg2)
232 #define SUBSTITUTE_ARGS_3(arg1, arg2, arg3) \
233 long int _arg1 = (long int) (arg1); \
234 long int _arg2 = (long int) (arg2); \
235 long int _arg3 = (long int) (arg3); \
236 register long int r4 asm ("%r4") = (long int) (_arg1); \
237 register long int r5 asm ("%r5") = (long int) (_arg2); \
238 register long int r6 asm ("%r6") = (long int) (_arg3)
239 #define SUBSTITUTE_ARGS_4(arg1, arg2, arg3, arg4) \
240 long int _arg1 = (long int) (arg1); \
241 long int _arg2 = (long int) (arg2); \
242 long int _arg3 = (long int) (arg3); \
243 long int _arg4 = (long int) (arg4); \
244 register long int r4 asm ("%r4") = (long int) (_arg1); \
245 register long int r5 asm ("%r5") = (long int) (_arg2); \
246 register long int r6 asm ("%r6") = (long int) (_arg3); \
247 register long int r7 asm ("%r7") = (long int) (_arg4)
248 #define SUBSTITUTE_ARGS_5(arg1, arg2, arg3, arg4, arg5) \
249 long int _arg1 = (long int) (arg1); \
250 long int _arg2 = (long int) (arg2); \
251 long int _arg3 = (long int) (arg3); \
252 long int _arg4 = (long int) (arg4); \
253 long int _arg5 = (long int) (arg5); \
254 register long int r4 asm ("%r4") = (long int) (_arg1); \
255 register long int r5 asm ("%r5") = (long int) (_arg2); \
256 register long int r6 asm ("%r6") = (long int) (_arg3); \
257 register long int r7 asm ("%r7") = (long int) (_arg4); \
258 register long int r0 asm ("%r0") = (long int) (_arg5)
259 #define SUBSTITUTE_ARGS_6(arg1, arg2, arg3, arg4, arg5, arg6) \
260 long int _arg1 = (long int) (arg1); \
261 long int _arg2 = (long int) (arg2); \
262 long int _arg3 = (long int) (arg3); \
263 long int _arg4 = (long int) (arg4); \
264 long int _arg5 = (long int) (arg5); \
265 long int _arg6 = (long int) (arg6); \
266 register long int r4 asm ("%r4") = (long int)(_arg1); \
267 register long int r5 asm ("%r5") = (long int) (_arg2); \
268 register long int r6 asm ("%r6") = (long int) (_arg3); \
269 register long int r7 asm ("%r7") = (long int) (_arg4); \
270 register long int r0 asm ("%r0") = (long int) (_arg5); \
271 register long int r1 asm ("%r1") = (long int) (_arg6)
272 #define SUBSTITUTE_ARGS_7(arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
273 long int _arg1 = (long int) (arg1); \
274 long int _arg2 = (long int) (arg2); \
275 long int _arg3 = (long int) (arg3); \
276 long int _arg4 = (long int) (arg4); \
277 long int _arg5 = (long int) (arg5); \
278 long int _arg6 = (long int) (arg6); \
279 long int _arg7 = (long int) (arg7); \
280 register long int r4 asm ("%r4") = (long int) (_arg1); \
281 register long int r5 asm ("%r5") = (long int) (_arg2); \
282 register long int r6 asm ("%r6") = (long int) (_arg3); \
283 register long int r7 asm ("%r7") = (long int) (_arg4); \
284 register long int r0 asm ("%r0") = (long int) (_arg5); \
285 register long int r1 asm ("%r1") = (long int) (_arg6); \
286 register long int r2 asm ("%r2") = (long int) (_arg7)
288 #undef INTERNAL_SYSCALL
289 #define INTERNAL_SYSCALL(name, nr, args...) \
291 unsigned long int resultvar; \
292 register long int r3 asm ("%r3") = SYS_ify (name); \
293 SUBSTITUTE_ARGS_##nr(args); \
295 asm volatile (SYSCALL_INST_STR##nr SYSCALL_INST_PAD \
297 : "r" (r3) ASMFMT_##nr \
302 /* The _NCS variant allows non-constant syscall numbers. */
303 #define INTERNAL_SYSCALL_NCS(name, nr, args...) \
305 unsigned long int resultvar; \
306 register long int r3 asm ("%r3") = (name); \
307 SUBSTITUTE_ARGS_##nr(args); \
309 asm volatile (SYSCALL_INST_STR##nr SYSCALL_INST_PAD \
311 : "r" (r3) ASMFMT_##nr \
316 #endif /* __ASSEMBLER__ */
318 #endif /* linux/sh/sysdep.h */