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