]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/m68k/sysdep.h
Update to LGPL v2.1.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / m68k / sysdep.h
1 /* Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Written by Andreas Schwab, <schwab@issan.informatik.uni-dortmund.de>,
4 December 1995.
5
6 The GNU C Library is free software; you can redistribute it and/or
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.
10
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
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 #include <sysdeps/unix/sysdep.h>
22 #include <sysdeps/m68k/sysdep.h>
23
24 /* For Linux we can use the system call table in the header file
25 /usr/include/asm/unistd.h
26 of the kernel. But these symbols do not follow the SYS_* syntax
27 so we have to redefine the `SYS_ify' macro here. */
28 #undef SYS_ify
29 #ifdef __STDC__
30 # define SYS_ify(syscall_name) __NR_##syscall_name
31 #else
32 # define SYS_ify(syscall_name) __NR_/**/syscall_name
33 #endif
34
35 #ifdef __ASSEMBLER__
36
37 /* Linux uses a negative return value to indicate syscall errors, unlike
38 most Unices, which use the condition codes' carry flag.
39
40 Since version 2.1 the return value of a system call might be negative
41 even if the call succeeded. E.g., the `lseek' system call might return
42 a large offset. Therefore we must not anymore test for < 0, but test
43 for a real error by making sure the value in %d0 is a real error
44 number. Linus said he will make sure the no syscall returns a value
45 in -1 .. -4095 as a valid result so we can savely test with -4095. */
46
47 /* We don't want the label for the error handler to be visible in the symbol
48 table when we define it here. */
49 #ifdef PIC
50 #define SYSCALL_ERROR_LABEL .Lsyscall_error
51 #else
52 #define SYSCALL_ERROR_LABEL __syscall_error
53 #endif
54
55 #undef PSEUDO
56 #define PSEUDO(name, syscall_name, args) \
57 .text; \
58 ENTRY (name) \
59 DO_CALL (syscall_name, args); \
60 cmp.l &-4095, %d0; \
61 jcc SYSCALL_ERROR_LABEL
62
63 #undef PSEUDO_END
64 #define PSEUDO_END(name) \
65 SYSCALL_ERROR_HANDLER; \
66 END (name)
67
68 #ifdef PIC
69 /* Store (- %d0) into errno through the GOT. */
70 #ifdef _LIBC_REENTRANT
71 #define SYSCALL_ERROR_HANDLER \
72 SYSCALL_ERROR_LABEL: \
73 neg.l %d0; \
74 move.l %d0, -(%sp); \
75 jbsr __errno_location@PLTPC; \
76 move.l (%sp)+, (%a0); \
77 move.l &-1, %d0; \
78 /* Copy return value to %a0 for syscalls that are declared to return \
79 a pointer (e.g., mmap). */ \
80 move.l %d0, %a0; \
81 rts;
82 #else /* !_LIBC_REENTRANT */
83 #define SYSCALL_ERROR_HANDLER \
84 SYSCALL_ERROR_LABEL: \
85 move.l (errno@GOTPC, %pc), %a0; \
86 neg.l %d0; \
87 move.l %d0, (%a0); \
88 move.l &-1, %d0; \
89 /* Copy return value to %a0 for syscalls that are declared to return \
90 a pointer (e.g., mmap). */ \
91 move.l %d0, %a0; \
92 rts;
93 #endif /* _LIBC_REENTRANT */
94 #else
95 #define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
96 #endif /* PIC */
97
98 /* Linux takes system call arguments in registers:
99
100 syscall number %d0 call-clobbered
101 arg 1 %d1 call-clobbered
102 arg 2 %d2 call-saved
103 arg 3 %d3 call-saved
104 arg 4 %d4 call-saved
105 arg 5 %d5 call-saved
106
107 The stack layout upon entering the function is:
108
109 20(%sp) Arg# 5
110 16(%sp) Arg# 4
111 12(%sp) Arg# 3
112 8(%sp) Arg# 2
113 4(%sp) Arg# 1
114 (%sp) Return address
115
116 (Of course a function with say 3 arguments does not have entries for
117 arguments 4 and 5.)
118
119 Separate move's are faster than movem, but need more space. Since
120 speed is more important, we don't use movem. Since %a0 and %a1 are
121 scratch registers, we can use them for saving as well. */
122
123 #define DO_CALL(syscall_name, args) \
124 move.l &SYS_ify(syscall_name), %d0; \
125 DOARGS_##args \
126 trap &0; \
127 UNDOARGS_##args
128
129 #define DOARGS_0 /* No arguments to frob. */
130 #define UNDOARGS_0 /* No arguments to unfrob. */
131 #define _DOARGS_0(n) /* No arguments to frob. */
132
133 #define DOARGS_1 _DOARGS_1 (4)
134 #define _DOARGS_1(n) move.l n(%sp), %d1; _DOARGS_0 (n)
135 #define UNDOARGS_1 UNDOARGS_0
136
137 #define DOARGS_2 _DOARGS_2 (8)
138 #define _DOARGS_2(n) move.l %d2, %a0; move.l n(%sp), %d2; _DOARGS_1 (n-4)
139 #define UNDOARGS_2 UNDOARGS_1; move.l %a0, %d2
140
141 #define DOARGS_3 _DOARGS_3 (12)
142 #define _DOARGS_3(n) move.l %d3, %a1; move.l n(%sp), %d3; _DOARGS_2 (n-4)
143 #define UNDOARGS_3 UNDOARGS_2; move.l %a1, %d3
144
145 #define DOARGS_4 _DOARGS_4 (16)
146 #define _DOARGS_4(n) move.l %d4, -(%sp); move.l n+4(%sp), %d4; _DOARGS_3 (n)
147 #define UNDOARGS_4 UNDOARGS_3; move.l (%sp)+, %d4
148
149 #define DOARGS_5 _DOARGS_5 (20)
150 #define _DOARGS_5(n) move.l %d5, -(%sp); move.l n+4(%sp), %d5; _DOARGS_4 (n)
151 #define UNDOARGS_5 UNDOARGS_4; move.l (%sp)+, %d5
152
153
154 #define ret rts
155 #if 0 /* Not used by Linux */
156 #define r0 %d0
157 #define r1 %d1
158 #define MOVE(x,y) movel x , y
159 #endif
160
161 #else /* not __ASSEMBLER__ */
162
163 /* Define a macro which expands into the inline wrapper code for a system
164 call. */
165 #undef INLINE_SYSCALL
166 #define INLINE_SYSCALL(name, nr, args...) \
167 ({ unsigned int _sys_result; \
168 { \
169 LOAD_ARGS_##nr (args) \
170 register int _d0 asm ("%d0") = __NR_##name; \
171 asm volatile ("trap #0" \
172 : "=d" (_d0) \
173 : "0" (_d0) ASM_ARGS_##nr \
174 : "d0", "memory"); \
175 _sys_result = _d0; \
176 } \
177 if (_sys_result >= (unsigned int) -4095) \
178 { \
179 __set_errno (-_sys_result); \
180 _sys_result = (unsigned int) -1; \
181 } \
182 (int) _sys_result; })
183
184 #define LOAD_ARGS_0()
185 #define ASM_ARGS_0
186 #define LOAD_ARGS_1(a1) \
187 register int _d1 asm ("d1") = (int) (a1); \
188 LOAD_ARGS_0 ()
189 #define ASM_ARGS_1 ASM_ARGS_0, "d" (_d1)
190 #define LOAD_ARGS_2(a1, a2) \
191 register int _d2 asm ("d2") = (int) (a2); \
192 LOAD_ARGS_1 (a1)
193 #define ASM_ARGS_2 ASM_ARGS_1, "d" (_d2)
194 #define LOAD_ARGS_3(a1, a2, a3) \
195 register int _d3 asm ("d3") = (int) (a3); \
196 LOAD_ARGS_2 (a1, a2)
197 #define ASM_ARGS_3 ASM_ARGS_2, "d" (_d3)
198 #define LOAD_ARGS_4(a1, a2, a3, a4) \
199 register int _d4 asm ("d4") = (int) (a4); \
200 LOAD_ARGS_3 (a1, a2, a3)
201 #define ASM_ARGS_4 ASM_ARGS_3, "d" (_d4)
202 #define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
203 register int _d5 asm ("d5") = (int) (a5); \
204 LOAD_ARGS_4 (a1, a2, a3, a4)
205 #define ASM_ARGS_5 ASM_ARGS_4, "d" (_d5)
206
207 #endif /* not __ASSEMBLER__ */