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