]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/m68k/sysdep.h
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / m68k / sysdep.h
CommitLineData
04277e02 1/* Copyright (C) 1996-2019 Free Software Foundation, Inc.
36e28152
UD
2 This file is part of the GNU C Library.
3 Written by Andreas Schwab, <schwab@issan.informatik.uni-dortmund.de>,
4 December 1995.
9298f9e1 5
36e28152 6 The GNU C Library is free software; you can redistribute it and/or
3214b89b
AJ
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.
9298f9e1 10
36e28152
UD
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
3214b89b 14 Lesser General Public License for more details.
9298f9e1 15
3214b89b 16 You should have received a copy of the GNU Lesser General Public
ab84e3ff 17 License along with the GNU C Library. If not, see
5a82c748 18 <https://www.gnu.org/licenses/>. */
9298f9e1 19
fb1cf108 20#include <sysdeps/unix/sysv/linux/sysdep.h>
40111cb9 21#include <tls.h>
9298f9e1 22
9d3831f3
AS
23/* Defines RTLD_PRIVATE_ERRNO. */
24#include <dl-sysdep.h>
25
b2801dda
RM
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
53bce1b5 31#define SYS_ify(syscall_name) __NR_##syscall_name
b2801dda 32
e0ebc3b2 33#ifdef __ASSEMBLER__
9298f9e1 34
9298f9e1 35/* Linux uses a negative return value to indicate syscall errors, unlike
5415516c
UD
36 most Unices, which use the condition codes' carry flag.
37
38 Since version 2.1 the return value of a system call might be negative
39 even if the call succeeded. E.g., the `lseek' system call might return
40 a large offset. Therefore we must not anymore test for < 0, but test
41 for a real error by making sure the value in %d0 is a real error
dd4b8913 42 number. Linus said he will make sure the no syscall returns a value
6acf09f4 43 in -1 .. -4095 as a valid result so we can savely test with -4095. */
2cd49338
AS
44
45/* We don't want the label for the error handler to be visible in the symbol
46 table when we define it here. */
47#ifdef PIC
48#define SYSCALL_ERROR_LABEL .Lsyscall_error
49#else
50#define SYSCALL_ERROR_LABEL __syscall_error
51#endif
52
56d7f029 53#undef PSEUDO
9298f9e1
RM
54#define PSEUDO(name, syscall_name, args) \
55 .text; \
9298f9e1 56 ENTRY (name) \
56d7f029 57 DO_CALL (syscall_name, args); \
6acf09f4 58 cmp.l &-4095, %d0; \
2cd49338 59 jcc SYSCALL_ERROR_LABEL
5415516c
UD
60
61#undef PSEUDO_END
b8bd7edd
UD
62#define PSEUDO_END(name) \
63 SYSCALL_ERROR_HANDLER; \
64 END (name)
9298f9e1 65
98f7320f
UD
66#undef PSEUDO_NOERRNO
67#define PSEUDO_NOERRNO(name, syscall_name, args) \
68 .text; \
69 ENTRY (name) \
70 DO_CALL (syscall_name, args)
71
72#undef PSEUDO_END_NOERRNO
73#define PSEUDO_END_NOERRNO(name) \
74 END (name)
75
fd1f2c4a
AS
76#define ret_NOERRNO rts
77
78/* The function has to return the error code. */
79#undef PSEUDO_ERRVAL
80#define PSEUDO_ERRVAL(name, syscall_name, args) \
81 .text; \
82 ENTRY (name) \
83 DO_CALL (syscall_name, args); \
84 negl %d0
85
86#undef PSEUDO_END_ERRVAL
87#define PSEUDO_END_ERRVAL(name) \
88 END (name)
89
90#define ret_ERRVAL rts
64928a88 91
9298f9e1 92#ifdef PIC
4b5b9a07 93# if RTLD_PRIVATE_ERRNO
9d3831f3
AS
94# define SYSCALL_ERROR_HANDLER \
95SYSCALL_ERROR_LABEL: \
9c986f87 96 PCREL_OP (lea, rtld_errno, %a0, %a0); \
9d3831f3
AS
97 neg.l %d0; \
98 move.l %d0, (%a0); \
99 move.l &-1, %d0; \
100 /* Copy return value to %a0 for syscalls that are declared to return \
101 a pointer (e.g., mmap). */ \
102 move.l %d0, %a0; \
103 rts;
df62b0cd 104# elif defined _LIBC_REENTRANT
4f41c682 105# if IS_IN (libc)
dbd0094b
AS
106# define SYSCALL_ERROR_ERRNO __libc_errno
107# else
108# define SYSCALL_ERROR_ERRNO errno
109# endif
110# define SYSCALL_ERROR_HANDLER \
111SYSCALL_ERROR_LABEL: \
112 neg.l %d0; \
113 move.l %d0, -(%sp); \
50e73d13 114 cfi_adjust_cfa_offset (4); \
dbd0094b 115 jbsr __m68k_read_tp@PLTPC; \
690d264a 116 SYSCALL_ERROR_LOAD_GOT (%a1); \
dbd0094b
AS
117 add.l (SYSCALL_ERROR_ERRNO@TLSIE, %a1), %a0; \
118 move.l (%sp)+, (%a0); \
50e73d13 119 cfi_adjust_cfa_offset (-4); \
dbd0094b
AS
120 move.l &-1, %d0; \
121 /* Copy return value to %a0 for syscalls that are declared to return \
122 a pointer (e.g., mmap). */ \
123 move.l %d0, %a0; \
124 rts;
dbd0094b
AS
125# else /* !_LIBC_REENTRANT */
126/* Store (- %d0) into errno through the GOT. */
127# define SYSCALL_ERROR_HANDLER \
2cd49338 128SYSCALL_ERROR_LABEL: \
bf4b3107
UD
129 move.l (errno@GOTPC, %pc), %a0; \
130 neg.l %d0; \
131 move.l %d0, (%a0); \
5415516c 132 move.l &-1, %d0; \
bf4b3107
UD
133 /* Copy return value to %a0 for syscalls that are declared to return \
134 a pointer (e.g., mmap). */ \
135 move.l %d0, %a0; \
136 rts;
dbd0094b 137# endif /* _LIBC_REENTRANT */
bf4b3107 138#else
9d3831f3 139# define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
bf4b3107 140#endif /* PIC */
9298f9e1
RM
141
142/* Linux takes system call arguments in registers:
143
144 syscall number %d0 call-clobbered
145 arg 1 %d1 call-clobbered
146 arg 2 %d2 call-saved
147 arg 3 %d3 call-saved
148 arg 4 %d4 call-saved
149 arg 5 %d5 call-saved
40111cb9 150 arg 6 %a0 call-clobbered
9298f9e1
RM
151
152 The stack layout upon entering the function is:
153
40111cb9 154 24(%sp) Arg# 6
9298f9e1
RM
155 20(%sp) Arg# 5
156 16(%sp) Arg# 4
157 12(%sp) Arg# 3
158 8(%sp) Arg# 2
159 4(%sp) Arg# 1
160 (%sp) Return address
161
162 (Of course a function with say 3 arguments does not have entries for
163 arguments 4 and 5.)
164
165 Separate move's are faster than movem, but need more space. Since
166 speed is more important, we don't use movem. Since %a0 and %a1 are
167 scratch registers, we can use them for saving as well. */
168
56d7f029
AS
169#define DO_CALL(syscall_name, args) \
170 move.l &SYS_ify(syscall_name), %d0; \
9298f9e1 171 DOARGS_##args \
5415516c 172 trap &0; \
9298f9e1
RM
173 UNDOARGS_##args
174
175#define DOARGS_0 /* No arguments to frob. */
176#define UNDOARGS_0 /* No arguments to unfrob. */
177#define _DOARGS_0(n) /* No arguments to frob. */
178
179#define DOARGS_1 _DOARGS_1 (4)
180#define _DOARGS_1(n) move.l n(%sp), %d1; _DOARGS_0 (n)
181#define UNDOARGS_1 UNDOARGS_0
182
183#define DOARGS_2 _DOARGS_2 (8)
50e73d13
AS
184#define _DOARGS_2(n) move.l %d2, %a0; cfi_register (%d2, %a0); \
185 move.l n(%sp), %d2; _DOARGS_1 (n-4)
186#define UNDOARGS_2 UNDOARGS_1; move.l %a0, %d2; cfi_restore (%d2)
9298f9e1
RM
187
188#define DOARGS_3 _DOARGS_3 (12)
50e73d13
AS
189#define _DOARGS_3(n) move.l %d3, %a1; cfi_register (%d3, %a1); \
190 move.l n(%sp), %d3; _DOARGS_2 (n-4)
191#define UNDOARGS_3 UNDOARGS_2; move.l %a1, %d3; cfi_restore (%d3)
9298f9e1
RM
192
193#define DOARGS_4 _DOARGS_4 (16)
50e73d13
AS
194#define _DOARGS_4(n) move.l %d4, -(%sp); \
195 cfi_adjust_cfa_offset (4); cfi_rel_offset (%d4, 0); \
196 move.l n+4(%sp), %d4; _DOARGS_3 (n)
197#define UNDOARGS_4 UNDOARGS_3; move.l (%sp)+, %d4; \
198 cfi_adjust_cfa_offset (-4); cfi_restore (%d4)
9298f9e1
RM
199
200#define DOARGS_5 _DOARGS_5 (20)
50e73d13
AS
201#define _DOARGS_5(n) move.l %d5, -(%sp); \
202 cfi_adjust_cfa_offset (4); cfi_rel_offset (%d5, 0); \
203 move.l n+4(%sp), %d5; _DOARGS_4 (n)
204#define UNDOARGS_5 UNDOARGS_4; move.l (%sp)+, %d5; \
205 cfi_adjust_cfa_offset (-4); cfi_restore (%d5)
9298f9e1 206
5dde0182 207#define DOARGS_6 _DOARGS_6 (24)
50e73d13
AS
208#define _DOARGS_6(n) _DOARGS_5 (n-4); move.l %a0, -(%sp); \
209 cfi_adjust_cfa_offset (4); \
210 move.l n+12(%sp), %a0;
211#define UNDOARGS_6 move.l (%sp)+, %a0; cfi_adjust_cfa_offset (-4); \
212 UNDOARGS_5
5dde0182 213
9298f9e1
RM
214
215#define ret rts
216#if 0 /* Not used by Linux */
217#define r0 %d0
218#define r1 %d1
219#define MOVE(x,y) movel x , y
220#endif
221
dca17080
AS
222#else /* not __ASSEMBLER__ */
223
224/* Define a macro which expands into the inline wrapper code for a system
225 call. */
226#undef INLINE_SYSCALL
5d384858 227#define INLINE_SYSCALL(name, nr, args...) \
aeeec7fb
UD
228 ({ unsigned int _sys_result = INTERNAL_SYSCALL (name, , nr, args); \
229 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0))\
5d384858 230 { \
aeeec7fb 231 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \
5d384858
AS
232 _sys_result = (unsigned int) -1; \
233 } \
234 (int) _sys_result; })
235
aeeec7fb
UD
236#undef INTERNAL_SYSCALL_DECL
237#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
238
5d384858
AS
239/* Define a macro which expands inline into the wrapper code for a system
240 call. This use is for internal calls that do not need to handle errors
241 normally. It will never touch errno. This returns just what the kernel
242 gave back. */
243#undef INTERNAL_SYSCALL
40111cb9 244#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
dca17080
AS
245 ({ unsigned int _sys_result; \
246 { \
693687e6
AS
247 /* Load argument values in temporary variables
248 to perform side effects like function calls
249 before the call used registers are set. */ \
dca17080 250 LOAD_ARGS_##nr (args) \
693687e6 251 LOAD_REGS_##nr \
40111cb9 252 register int _d0 asm ("%d0") = name; \
dca17080
AS
253 asm volatile ("trap #0" \
254 : "=d" (_d0) \
ec2a735f 255 : "0" (_d0) ASM_ARGS_##nr \
48bfe445 256 : "memory"); \
dca17080
AS
257 _sys_result = _d0; \
258 } \
dca17080 259 (int) _sys_result; })
40111cb9
MK
260#define INTERNAL_SYSCALL(name, err, nr, args...) \
261 INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
dca17080 262
5d384858 263#undef INTERNAL_SYSCALL_ERROR_P
aeeec7fb
UD
264#define INTERNAL_SYSCALL_ERROR_P(val, err) \
265 ((unsigned int) (val) >= -4095U)
5d384858
AS
266
267#undef INTERNAL_SYSCALL_ERRNO
aeeec7fb 268#define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
5d384858 269
dca17080 270#define LOAD_ARGS_0()
693687e6 271#define LOAD_REGS_0
dca17080
AS
272#define ASM_ARGS_0
273#define LOAD_ARGS_1(a1) \
693687e6
AS
274 LOAD_ARGS_0 () \
275 int __arg1 = (int) (a1);
276#define LOAD_REGS_1 \
277 register int _d1 asm ("d1") = __arg1; \
278 LOAD_REGS_0
dca17080
AS
279#define ASM_ARGS_1 ASM_ARGS_0, "d" (_d1)
280#define LOAD_ARGS_2(a1, a2) \
693687e6
AS
281 LOAD_ARGS_1 (a1) \
282 int __arg2 = (int) (a2);
283#define LOAD_REGS_2 \
284 register int _d2 asm ("d2") = __arg2; \
285 LOAD_REGS_1
dca17080
AS
286#define ASM_ARGS_2 ASM_ARGS_1, "d" (_d2)
287#define LOAD_ARGS_3(a1, a2, a3) \
693687e6
AS
288 LOAD_ARGS_2 (a1, a2) \
289 int __arg3 = (int) (a3);
290#define LOAD_REGS_3 \
291 register int _d3 asm ("d3") = __arg3; \
292 LOAD_REGS_2
dca17080
AS
293#define ASM_ARGS_3 ASM_ARGS_2, "d" (_d3)
294#define LOAD_ARGS_4(a1, a2, a3, a4) \
693687e6
AS
295 LOAD_ARGS_3 (a1, a2, a3) \
296 int __arg4 = (int) (a4);
297#define LOAD_REGS_4 \
298 register int _d4 asm ("d4") = __arg4; \
299 LOAD_REGS_3
dca17080
AS
300#define ASM_ARGS_4 ASM_ARGS_3, "d" (_d4)
301#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
693687e6
AS
302 LOAD_ARGS_4 (a1, a2, a3, a4) \
303 int __arg5 = (int) (a5);
304#define LOAD_REGS_5 \
305 register int _d5 asm ("d5") = __arg5; \
306 LOAD_REGS_4
dca17080 307#define ASM_ARGS_5 ASM_ARGS_4, "d" (_d5)
0798f1ad 308#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
693687e6
AS
309 LOAD_ARGS_5 (a1, a2, a3, a4, a5) \
310 int __arg6 = (int) (a6);
311#define LOAD_REGS_6 \
312 register int _a0 asm ("a0") = __arg6; \
313 LOAD_REGS_5
0798f1ad 314#define ASM_ARGS_6 ASM_ARGS_5, "a" (_a0)
dca17080
AS
315
316#endif /* not __ASSEMBLER__ */
40111cb9
MK
317
318/* Pointer mangling is not yet supported for M68K. */
319#define PTR_MANGLE(var) (void) (var)
320#define PTR_DEMANGLE(var) (void) (var)
321
322#if defined NEED_DL_SYSINFO || defined NEED_DL_SYSINFO_DSO
323/* M68K needs system-supplied DSO to access TLS helpers
324 even when statically linked. */
325# define NEED_STATIC_SYSINFO_DSO 1
326#endif