]> sourceware.org Git - glibc.git/blob - sysdeps/unix/sysv/linux/m68k/sysdep.h
NPTL support for m68k/ColdFire
[glibc.git] / sysdeps / unix / sysv / linux / m68k / sysdep.h
1 /* Copyright (C) 1996, 1997, 1998, 2000, 2003, 2004, 2006, 2010
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Written by Andreas Schwab, <schwab@issan.informatik.uni-dortmund.de>,
5 December 1995.
6
7 The GNU C Library is free software; you can redistribute it and/or
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.
11
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
15 Lesser General Public License for more details.
16
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. */
21
22 #ifndef _LINUX_M68K_SYSDEP_H
23 #define _LINUX_M68K_SYSDEP_H 1
24
25 #include <sysdeps/unix/sysdep.h>
26 #include <sysdeps/m68k/sysdep.h>
27 #include <tls.h>
28
29 /* Defines RTLD_PRIVATE_ERRNO. */
30 #include <dl-sysdep.h>
31
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
43 #ifdef __ASSEMBLER__
44
45 /* Linux uses a negative return value to indicate syscall errors, unlike
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
52 number. Linus said he will make sure the no syscall returns a value
53 in -1 .. -4095 as a valid result so we can savely test with -4095. */
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
63 #undef PSEUDO
64 #define PSEUDO(name, syscall_name, args) \
65 .text; \
66 ENTRY (name) \
67 DO_CALL (syscall_name, args); \
68 cmp.l &-4095, %d0; \
69 jcc SYSCALL_ERROR_LABEL
70
71 #undef PSEUDO_END
72 #define PSEUDO_END(name) \
73 SYSCALL_ERROR_HANDLER; \
74 END (name)
75
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
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
101
102 #ifdef PIC
103 # if RTLD_PRIVATE_ERRNO
104 # define SYSCALL_ERROR_HANDLER \
105 SYSCALL_ERROR_LABEL: \
106 PCREL_OP (lea, rtld_errno, %a0, %a0); \
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 */
115 /* Store (- %d0) into errno through the GOT. */
116 # if defined _LIBC_REENTRANT
117 # define SYSCALL_ERROR_HANDLER \
118 SYSCALL_ERROR_LABEL: \
119 neg.l %d0; \
120 move.l %d0, -(%sp); \
121 jbsr __errno_location@PLTPC; \
122 move.l (%sp)+, (%a0); \
123 move.l &-1, %d0; \
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;
128 # else /* !_LIBC_REENTRANT */
129 # define SYSCALL_ERROR_HANDLER \
130 SYSCALL_ERROR_LABEL: \
131 move.l (errno@GOTPC, %pc), %a0; \
132 neg.l %d0; \
133 move.l %d0, (%a0); \
134 move.l &-1, %d0; \
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;
139 # endif /* _LIBC_REENTRANT */
140 # endif /* RTLD_PRIVATE_ERRNO */
141 #else
142 # define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
143 #endif /* PIC */
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
153 arg 6 %a0 call-clobbered
154
155 The stack layout upon entering the function is:
156
157 24(%sp) Arg# 6
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
172 #define DO_CALL(syscall_name, args) \
173 move.l &SYS_ify(syscall_name), %d0; \
174 DOARGS_##args \
175 trap &0; \
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
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
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
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
219 #define INLINE_SYSCALL(name, nr, args...) \
220 ({ unsigned int _sys_result = INTERNAL_SYSCALL (name, , nr, args); \
221 if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_sys_result, ), 0))\
222 { \
223 __set_errno (INTERNAL_SYSCALL_ERRNO (_sys_result, )); \
224 _sys_result = (unsigned int) -1; \
225 } \
226 (int) _sys_result; })
227
228 #undef INTERNAL_SYSCALL_DECL
229 #define INTERNAL_SYSCALL_DECL(err) do { } while (0)
230
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
236 #define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
237 ({ unsigned int _sys_result; \
238 { \
239 /* Load argument values in temporary variables
240 to perform side effects like function calls
241 before the call used registers are set. */ \
242 LOAD_ARGS_##nr (args) \
243 LOAD_REGS_##nr \
244 register int _d0 asm ("%d0") = name; \
245 asm volatile ("trap #0" \
246 : "=d" (_d0) \
247 : "0" (_d0) ASM_ARGS_##nr \
248 : "memory"); \
249 _sys_result = _d0; \
250 } \
251 (int) _sys_result; })
252 #define INTERNAL_SYSCALL(name, err, nr, args...) \
253 INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
254
255 #undef INTERNAL_SYSCALL_ERROR_P
256 #define INTERNAL_SYSCALL_ERROR_P(val, err) \
257 ((unsigned int) (val) >= -4095U)
258
259 #undef INTERNAL_SYSCALL_ERRNO
260 #define INTERNAL_SYSCALL_ERRNO(val, err) (-(val))
261
262 #define LOAD_ARGS_0()
263 #define LOAD_REGS_0
264 #define ASM_ARGS_0
265 #define LOAD_ARGS_1(a1) \
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
271 #define ASM_ARGS_1 ASM_ARGS_0, "d" (_d1)
272 #define LOAD_ARGS_2(a1, a2) \
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
278 #define ASM_ARGS_2 ASM_ARGS_1, "d" (_d2)
279 #define LOAD_ARGS_3(a1, a2, a3) \
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
285 #define ASM_ARGS_3 ASM_ARGS_2, "d" (_d3)
286 #define LOAD_ARGS_4(a1, a2, a3, a4) \
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
292 #define ASM_ARGS_4 ASM_ARGS_3, "d" (_d4)
293 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
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
299 #define ASM_ARGS_5 ASM_ARGS_4, "d" (_d5)
300 #define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
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
306 #define ASM_ARGS_6 ASM_ARGS_5, "a" (_a0)
307
308 #endif /* not __ASSEMBLER__ */
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
320 #endif
This page took 0.052102 seconds and 5 git commands to generate.