]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/m68k/sysdep.h
9cddd205523f78fd42da790cb992f4386ddda204
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / m68k / sysdep.h
1 /* Copyright (C) 1996 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 Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 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 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If
18 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 Cambridge, MA 02139, USA. */
20
21 #include <sysdeps/unix/sysdep.h>
22
23 /* For Linux we can use the system call table in the header file
24 /usr/include/asm/unistd.h
25 of the kernel. But these symbols do not follow the SYS_* syntax
26 so we have to redefine the `SYS_ify' macro here. */
27 #undef SYS_ify
28 #ifdef __STDC__
29 # define SYS_ify(syscall_name) __NR_##syscall_name
30 #else
31 # define SYS_ify(syscall_name) __NR_/**/syscall_name
32 #endif
33
34 #ifdef ASSEMBLER
35
36 /* Define an entry point visible from C. */
37 #define ENTRY(name) \
38 .globl name; \
39 .type name, @function; \
40 .align 4; \
41 C_LABEL(name) \
42 CALL_MCOUNT
43
44 /* If compiled for profiling, call `_mcount' at the start of each function. */
45 #ifdef PROF
46 /* The mcount code relies on a normal frame pointer being on the stack
47 to locate our caller, so push one just for its benefit. */
48 #define CALL_MCOUNT \
49 move.l %fp, -(%sp); move.l %sp, %fp; \
50 jbsr JUMPTARGET (_mcount); \
51 move.l (%sp)+, %fp;
52 #else
53 #define CALL_MCOUNT /* Do nothing. */
54 #endif
55
56 #ifdef PIC
57 #define JUMPTARGET(name) name##@PLTPC
58 #else
59 #define JUMPTARGET(name) name
60 #endif
61
62 /* Since C identifiers are not normally prefixed with an underscore
63 on this system, the asm identifier `syscall_error' intrudes on the
64 C name space. Make sure we use an innocuous name. */
65 #define syscall_error __syscall_error
66
67 /* Linux uses a negative return value to indicate syscall errors, unlike
68 most Unices, which use the condition codes' carry flag.
69
70 Since version 2.1 the return value of a system call might be negative
71 even if the call succeeded. E.g., the `lseek' system call might return
72 a large offset. Therefore we must not anymore test for < 0, but test
73 for a real error by making sure the value in %d0 is a real error
74 number. For now (as of 2.1.1) 122 is the largest defined error number.
75 We allow for a bit of room for development and treat -128 to -1 as
76 error values. */
77 #define PSEUDO(name, syscall_name, args) \
78 .text; \
79 SYSCALL_ERROR_HANDLER \
80 ENTRY (name) \
81 DO_CALL (&SYS_ify (syscall_name), args); \
82 moveq.l &-128, %d1; \
83 cmp.l %d1, %d0; \
84 jcc syscall_error
85
86 #undef PSEUDO_END
87 #define PSEUDO_END(name) .size name, . - name
88
89 #ifdef PIC
90 /* Store (- %d0) into errno through the GOT. */
91 #ifdef _LIBC_REENTRANT
92 #define SYSCALL_ERROR_HANDLER \
93 .type syscall_error, @function; \
94 syscall_error: \
95 move.l (errno@GOTPC, %pc), %a0; \
96 neg.l %d0; \
97 move.l %d0, (%a0); \
98 move.l %d0, -(%sp); \
99 jbsr __errno_location@PLTPC; \
100 move.l (%sp)+, (%a0); \
101 move.l &-1, %d0; \
102 /* Copy return value to %a0 for syscalls that are declared to return \
103 a pointer (e.g., mmap). */ \
104 move.l %d0, %a0; \
105 rts;
106 #else
107 #define SYSCALL_ERROR_HANDLER \
108 .type syscall_error, @function; \
109 syscall_error: \
110 move.l (errno@GOTPC, %pc), %a0; \
111 neg.l %d0; \
112 move.l %d0, (%a0); \
113 move.l &-1, %d0; \
114 /* Copy return value to %a0 for syscalls that are declared to return \
115 a pointer (e.g., mmap). */ \
116 move.l %d0, %a0; \
117 rts;
118 #endif /* _LIBC_REENTRANT */
119 #else
120 #define SYSCALL_ERROR_HANDLER /* Nothing here; code in sysdep.S is used. */
121 #endif /* PIC */
122
123 /* Linux takes system call arguments in registers:
124
125 syscall number %d0 call-clobbered
126 arg 1 %d1 call-clobbered
127 arg 2 %d2 call-saved
128 arg 3 %d3 call-saved
129 arg 4 %d4 call-saved
130 arg 5 %d5 call-saved
131
132 The stack layout upon entering the function is:
133
134 20(%sp) Arg# 5
135 16(%sp) Arg# 4
136 12(%sp) Arg# 3
137 8(%sp) Arg# 2
138 4(%sp) Arg# 1
139 (%sp) Return address
140
141 (Of course a function with say 3 arguments does not have entries for
142 arguments 4 and 5.)
143
144 Separate move's are faster than movem, but need more space. Since
145 speed is more important, we don't use movem. Since %a0 and %a1 are
146 scratch registers, we can use them for saving as well. */
147
148 #define DO_CALL(syscall, args) \
149 move.l syscall, %d0; \
150 DOARGS_##args \
151 trap &0; \
152 UNDOARGS_##args
153
154 #define DOARGS_0 /* No arguments to frob. */
155 #define UNDOARGS_0 /* No arguments to unfrob. */
156 #define _DOARGS_0(n) /* No arguments to frob. */
157
158 #define DOARGS_1 _DOARGS_1 (4)
159 #define _DOARGS_1(n) move.l n(%sp), %d1; _DOARGS_0 (n)
160 #define UNDOARGS_1 UNDOARGS_0
161
162 #define DOARGS_2 _DOARGS_2 (8)
163 #define _DOARGS_2(n) move.l %d2, %a0; move.l n(%sp), %d2; _DOARGS_1 (n-4)
164 #define UNDOARGS_2 UNDOARGS_1; move.l %a0, %d2
165
166 #define DOARGS_3 _DOARGS_3 (12)
167 #define _DOARGS_3(n) move.l %d3, %a1; move.l n(%sp), %d3; _DOARGS_2 (n-4)
168 #define UNDOARGS_3 UNDOARGS_2; move.l %a1, %d3
169
170 #define DOARGS_4 _DOARGS_4 (16)
171 #define _DOARGS_4(n) move.l %d4, -(%sp); move.l n+4(%sp), %d4; _DOARGS_3 (n)
172 #define UNDOARGS_4 UNDOARGS_3; move.l (%sp)+, %d4
173
174 #define DOARGS_5 _DOARGS_5 (20)
175 #define _DOARGS_5(n) move.l %d5, -(%sp); move.l n+4(%sp), %d5; _DOARGS_4 (n)
176 #define UNDOARGS_5 UNDOARGS_4; move.l (%sp)+, %d5
177
178
179 #define ret rts
180 #if 0 /* Not used by Linux */
181 #define r0 %d0
182 #define r1 %d1
183 #define MOVE(x,y) movel x , y
184 #endif
185
186 #endif /* ASSEMBLER */