]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/m68k/sysdep.h
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / m68k / sysdep.h
CommitLineData
2b778ceb 1/* Copyright (C) 1996-2021 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. */
fcb78a55 47#undef SYSCALL_ERROR_LABEL
2cd49338
AS
48#ifdef PIC
49#define SYSCALL_ERROR_LABEL .Lsyscall_error
50#else
51#define SYSCALL_ERROR_LABEL __syscall_error
52#endif
53
56d7f029 54#undef PSEUDO
9298f9e1
RM
55#define PSEUDO(name, syscall_name, args) \
56 .text; \
9298f9e1 57 ENTRY (name) \
56d7f029 58 DO_CALL (syscall_name, args); \
6acf09f4 59 cmp.l &-4095, %d0; \
2cd49338 60 jcc SYSCALL_ERROR_LABEL
5415516c
UD
61
62#undef PSEUDO_END
b8bd7edd
UD
63#define PSEUDO_END(name) \
64 SYSCALL_ERROR_HANDLER; \
65 END (name)
9298f9e1 66
98f7320f
UD
67#undef PSEUDO_NOERRNO
68#define PSEUDO_NOERRNO(name, syscall_name, args) \
69 .text; \
70 ENTRY (name) \
71 DO_CALL (syscall_name, args)
72
73#undef PSEUDO_END_NOERRNO
74#define PSEUDO_END_NOERRNO(name) \
75 END (name)
76
fd1f2c4a
AS
77#define ret_NOERRNO rts
78
79/* The function has to return the error code. */
80#undef PSEUDO_ERRVAL
81#define PSEUDO_ERRVAL(name, syscall_name, args) \
82 .text; \
83 ENTRY (name) \
84 DO_CALL (syscall_name, args); \
85 negl %d0
86
87#undef PSEUDO_END_ERRVAL
88#define PSEUDO_END_ERRVAL(name) \
89 END (name)
90
91#define ret_ERRVAL rts
64928a88 92
9298f9e1 93#ifdef PIC
4b5b9a07 94# if RTLD_PRIVATE_ERRNO
9d3831f3
AS
95# define SYSCALL_ERROR_HANDLER \
96SYSCALL_ERROR_LABEL: \
9c986f87 97 PCREL_OP (lea, rtld_errno, %a0, %a0); \
9d3831f3
AS
98 neg.l %d0; \
99 move.l %d0, (%a0); \
100 move.l &-1, %d0; \
101 /* Copy return value to %a0 for syscalls that are declared to return \
102 a pointer (e.g., mmap). */ \
103 move.l %d0, %a0; \
104 rts;
df62b0cd 105# elif defined _LIBC_REENTRANT
4f41c682 106# if IS_IN (libc)
dbd0094b
AS
107# define SYSCALL_ERROR_ERRNO __libc_errno
108# else
109# define SYSCALL_ERROR_ERRNO errno
110# endif
111# define SYSCALL_ERROR_HANDLER \
112SYSCALL_ERROR_LABEL: \
113 neg.l %d0; \
114 move.l %d0, -(%sp); \
50e73d13 115 cfi_adjust_cfa_offset (4); \
dbd0094b 116 jbsr __m68k_read_tp@PLTPC; \
690d264a 117 SYSCALL_ERROR_LOAD_GOT (%a1); \
dbd0094b
AS
118 add.l (SYSCALL_ERROR_ERRNO@TLSIE, %a1), %a0; \
119 move.l (%sp)+, (%a0); \
50e73d13 120 cfi_adjust_cfa_offset (-4); \
dbd0094b
AS
121 move.l &-1, %d0; \
122 /* Copy return value to %a0 for syscalls that are declared to return \
123 a pointer (e.g., mmap). */ \
124 move.l %d0, %a0; \
125 rts;
dbd0094b
AS
126# else /* !_LIBC_REENTRANT */
127/* Store (- %d0) into errno through the GOT. */
128# define SYSCALL_ERROR_HANDLER \
2cd49338 129SYSCALL_ERROR_LABEL: \
bf4b3107
UD
130 move.l (errno@GOTPC, %pc), %a0; \
131 neg.l %d0; \
132 move.l %d0, (%a0); \
5415516c 133 move.l &-1, %d0; \
bf4b3107
UD
134 /* Copy return value to %a0 for syscalls that are declared to return \
135 a pointer (e.g., mmap). */ \
136 move.l %d0, %a0; \
137 rts;
dbd0094b 138# endif /* _LIBC_REENTRANT */
bf4b3107 139#else
9d3831f3 140# define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
bf4b3107 141#endif /* PIC */
9298f9e1
RM
142
143/* Linux takes system call arguments in registers:
144
145 syscall number %d0 call-clobbered
146 arg 1 %d1 call-clobbered
147 arg 2 %d2 call-saved
148 arg 3 %d3 call-saved
149 arg 4 %d4 call-saved
150 arg 5 %d5 call-saved
40111cb9 151 arg 6 %a0 call-clobbered
9298f9e1
RM
152
153 The stack layout upon entering the function is:
154
40111cb9 155 24(%sp) Arg# 6
9298f9e1
RM
156 20(%sp) Arg# 5
157 16(%sp) Arg# 4
158 12(%sp) Arg# 3
159 8(%sp) Arg# 2
160 4(%sp) Arg# 1
161 (%sp) Return address
162
163 (Of course a function with say 3 arguments does not have entries for
164 arguments 4 and 5.)
165
166 Separate move's are faster than movem, but need more space. Since
167 speed is more important, we don't use movem. Since %a0 and %a1 are
168 scratch registers, we can use them for saving as well. */
169
56d7f029
AS
170#define DO_CALL(syscall_name, args) \
171 move.l &SYS_ify(syscall_name), %d0; \
9298f9e1 172 DOARGS_##args \
5415516c 173 trap &0; \
9298f9e1
RM
174 UNDOARGS_##args
175
176#define DOARGS_0 /* No arguments to frob. */
177#define UNDOARGS_0 /* No arguments to unfrob. */
178#define _DOARGS_0(n) /* No arguments to frob. */
179
180#define DOARGS_1 _DOARGS_1 (4)
181#define _DOARGS_1(n) move.l n(%sp), %d1; _DOARGS_0 (n)
182#define UNDOARGS_1 UNDOARGS_0
183
184#define DOARGS_2 _DOARGS_2 (8)
50e73d13
AS
185#define _DOARGS_2(n) move.l %d2, %a0; cfi_register (%d2, %a0); \
186 move.l n(%sp), %d2; _DOARGS_1 (n-4)
187#define UNDOARGS_2 UNDOARGS_1; move.l %a0, %d2; cfi_restore (%d2)
9298f9e1
RM
188
189#define DOARGS_3 _DOARGS_3 (12)
50e73d13
AS
190#define _DOARGS_3(n) move.l %d3, %a1; cfi_register (%d3, %a1); \
191 move.l n(%sp), %d3; _DOARGS_2 (n-4)
192#define UNDOARGS_3 UNDOARGS_2; move.l %a1, %d3; cfi_restore (%d3)
9298f9e1
RM
193
194#define DOARGS_4 _DOARGS_4 (16)
50e73d13
AS
195#define _DOARGS_4(n) move.l %d4, -(%sp); \
196 cfi_adjust_cfa_offset (4); cfi_rel_offset (%d4, 0); \
197 move.l n+4(%sp), %d4; _DOARGS_3 (n)
198#define UNDOARGS_4 UNDOARGS_3; move.l (%sp)+, %d4; \
199 cfi_adjust_cfa_offset (-4); cfi_restore (%d4)
9298f9e1
RM
200
201#define DOARGS_5 _DOARGS_5 (20)
50e73d13
AS
202#define _DOARGS_5(n) move.l %d5, -(%sp); \
203 cfi_adjust_cfa_offset (4); cfi_rel_offset (%d5, 0); \
204 move.l n+4(%sp), %d5; _DOARGS_4 (n)
205#define UNDOARGS_5 UNDOARGS_4; move.l (%sp)+, %d5; \
206 cfi_adjust_cfa_offset (-4); cfi_restore (%d5)
9298f9e1 207
5dde0182 208#define DOARGS_6 _DOARGS_6 (24)
50e73d13
AS
209#define _DOARGS_6(n) _DOARGS_5 (n-4); move.l %a0, -(%sp); \
210 cfi_adjust_cfa_offset (4); \
211 move.l n+12(%sp), %a0;
212#define UNDOARGS_6 move.l (%sp)+, %a0; cfi_adjust_cfa_offset (-4); \
213 UNDOARGS_5
5dde0182 214
9298f9e1
RM
215
216#define ret rts
217#if 0 /* Not used by Linux */
218#define r0 %d0
219#define r1 %d1
220#define MOVE(x,y) movel x , y
221#endif
222
dca17080
AS
223#else /* not __ASSEMBLER__ */
224
5d384858
AS
225/* Define a macro which expands inline into the wrapper code for a system
226 call. This use is for internal calls that do not need to handle errors
227 normally. It will never touch errno. This returns just what the kernel
228 gave back. */
229#undef INTERNAL_SYSCALL
bc2eb932 230#define INTERNAL_SYSCALL_NCS(name, nr, args...) \
dca17080
AS
231 ({ unsigned int _sys_result; \
232 { \
693687e6
AS
233 /* Load argument values in temporary variables
234 to perform side effects like function calls
235 before the call used registers are set. */ \
dca17080 236 LOAD_ARGS_##nr (args) \
693687e6 237 LOAD_REGS_##nr \
40111cb9 238 register int _d0 asm ("%d0") = name; \
dca17080
AS
239 asm volatile ("trap #0" \
240 : "=d" (_d0) \
ec2a735f 241 : "0" (_d0) ASM_ARGS_##nr \
48bfe445 242 : "memory"); \
dca17080
AS
243 _sys_result = _d0; \
244 } \
dca17080 245 (int) _sys_result; })
bc2eb932
AZ
246#define INTERNAL_SYSCALL(name, nr, args...) \
247 INTERNAL_SYSCALL_NCS (__NR_##name, nr, ##args)
dca17080
AS
248
249#define LOAD_ARGS_0()
693687e6 250#define LOAD_REGS_0
dca17080
AS
251#define ASM_ARGS_0
252#define LOAD_ARGS_1(a1) \
693687e6
AS
253 LOAD_ARGS_0 () \
254 int __arg1 = (int) (a1);
255#define LOAD_REGS_1 \
256 register int _d1 asm ("d1") = __arg1; \
257 LOAD_REGS_0
dca17080
AS
258#define ASM_ARGS_1 ASM_ARGS_0, "d" (_d1)
259#define LOAD_ARGS_2(a1, a2) \
693687e6
AS
260 LOAD_ARGS_1 (a1) \
261 int __arg2 = (int) (a2);
262#define LOAD_REGS_2 \
263 register int _d2 asm ("d2") = __arg2; \
264 LOAD_REGS_1
dca17080
AS
265#define ASM_ARGS_2 ASM_ARGS_1, "d" (_d2)
266#define LOAD_ARGS_3(a1, a2, a3) \
693687e6
AS
267 LOAD_ARGS_2 (a1, a2) \
268 int __arg3 = (int) (a3);
269#define LOAD_REGS_3 \
270 register int _d3 asm ("d3") = __arg3; \
271 LOAD_REGS_2
dca17080
AS
272#define ASM_ARGS_3 ASM_ARGS_2, "d" (_d3)
273#define LOAD_ARGS_4(a1, a2, a3, a4) \
693687e6
AS
274 LOAD_ARGS_3 (a1, a2, a3) \
275 int __arg4 = (int) (a4);
276#define LOAD_REGS_4 \
277 register int _d4 asm ("d4") = __arg4; \
278 LOAD_REGS_3
dca17080
AS
279#define ASM_ARGS_4 ASM_ARGS_3, "d" (_d4)
280#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
693687e6
AS
281 LOAD_ARGS_4 (a1, a2, a3, a4) \
282 int __arg5 = (int) (a5);
283#define LOAD_REGS_5 \
284 register int _d5 asm ("d5") = __arg5; \
285 LOAD_REGS_4
dca17080 286#define ASM_ARGS_5 ASM_ARGS_4, "d" (_d5)
0798f1ad 287#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
693687e6
AS
288 LOAD_ARGS_5 (a1, a2, a3, a4, a5) \
289 int __arg6 = (int) (a6);
290#define LOAD_REGS_6 \
291 register int _a0 asm ("a0") = __arg6; \
292 LOAD_REGS_5
0798f1ad 293#define ASM_ARGS_6 ASM_ARGS_5, "a" (_a0)
dca17080 294
72048093
AZ
295#undef HAVE_INTERNAL_BRK_ADDR_SYMBOL
296#define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1
297
dca17080 298#endif /* not __ASSEMBLER__ */
40111cb9
MK
299
300/* Pointer mangling is not yet supported for M68K. */
301#define PTR_MANGLE(var) (void) (var)
302#define PTR_DEMANGLE(var) (void) (var)
303
304#if defined NEED_DL_SYSINFO || defined NEED_DL_SYSINFO_DSO
305/* M68K needs system-supplied DSO to access TLS helpers
306 even when statically linked. */
307# define NEED_STATIC_SYSINFO_DSO 1
308#endif