Update.
[glibc.git] / sysdeps / unix / alpha / sysdep.h
blob80cb3e2486ac5a4528b6faca7b57e683a36aa53c
1 /* Copyright (C) 1992, 1995, 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Brendan Kehoe (brendan@zen.org).
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <sysdeps/unix/sysdep.h>
22 #ifdef __ASSEMBLER__
24 #ifdef __linux__
25 # include <alpha/regdef.h>
26 #else
27 # include <regdef.h>
28 #endif
30 #ifdef __STDC__
31 #define __LABEL(x) x##:
32 #else
33 #define __LABEL(x) x/**/:
34 #endif
36 #define LEAF(name, framesize) \
37 .globl name; \
38 .align 3; \
39 .ent name, 0; \
40 __LABEL(name) \
41 .frame sp, framesize, ra
43 #define ENTRY(name) \
44 .globl name; \
45 .align 3; \
46 .ent name, 0; \
47 __LABEL(name) \
48 .frame sp, 0, ra
50 /* Mark the end of function SYM. */
51 #undef END
52 #define END(sym) .end sym
54 /* Note that PSEUDO/PSEUDO_END use label number 1996---do not use a
55 label of that number between those two macros! */
57 #ifdef PROF
58 #define PSEUDO(name, syscall_name, args) \
59 .globl name; \
60 .align 3; \
61 .ent name,0; \
62 __LABEL(name) \
63 .frame sp, 0, ra; \
64 ldgp gp,0(pv); \
65 .set noat; \
66 lda AT,_mcount; \
67 jsr AT,(AT),_mcount; \
68 .set at; \
69 .prologue 1; \
70 ldiq v0, SYS_ify(syscall_name); \
71 .set noat; \
72 call_pal PAL_callsys; \
73 .set at; \
74 bne a3, 1996f; \
76 #else
77 #define PSEUDO(name, syscall_name, args) \
78 .globl name; \
79 .align 3; \
80 .ent name,0; \
81 __LABEL(name) \
82 .frame sp, 0, ra \
83 .prologue 0; \
84 ldiq v0, SYS_ify(syscall_name); \
85 .set noat; \
86 call_pal PAL_callsys; \
87 .set at; \
88 bne a3, 1996f; \
90 #endif
92 #undef PSEUDO_END
93 #ifdef PROF
94 #define PSEUDO_END(sym) \
95 1996: \
96 jmp zero, __syscall_error; \
97 END(sym)
98 #else
99 #define PSEUDO_END(sym) \
100 1996: \
101 br gp, 2f; \
102 2: ldgp gp, 0(gp); \
103 jmp zero, __syscall_error; \
104 END(sym)
105 #endif
107 #define r0 v0
108 #define r1 a4
110 #define MOVE(x,y) mov x,y
112 #else /* !ASSEMBLER */
114 /* Define a macro which expands inline into the wrapper code for a
115 system call. */
117 #undef INLINE_SYSCALL
118 #define INLINE_SYSCALL(name, nr, args...) INLINE_SYSCALL1(name, nr, args)
120 #define INLINE_SYSCALL1(name, nr, args...) \
121 ({ \
122 long _sc_ret, _sc_err; \
123 inline_syscall##nr(name, args); \
124 if (_sc_err) \
126 __set_errno (_sc_ret); \
127 _sc_ret = -1L; \
129 _sc_ret; \
132 #define inline_syscall_clobbers \
133 "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \
134 "$22", "$23", "$24", "$25", "$27", "$28"
136 /* It is moderately important optimization-wise to limit the lifetime
137 of the hard-register variables as much as possible. Thus we copy
138 in/out as close to the asm as possible. */
140 #define inline_syscall0(name) \
142 register long _sc_0 __asm__("$0"); \
143 register long _sc_19 __asm__("$19"); \
145 _sc_0 = __NR_##name; \
146 __asm__("callsys # %0 %1 <= %2" \
147 : "=r"(_sc_0), "=r"(_sc_19) \
148 : "0"(_sc_0) \
149 : inline_syscall_clobbers); \
150 _sc_ret = _sc_0, _sc_err = _sc_19; \
153 #define inline_syscall1(name,arg1) \
155 register long _sc_0 __asm__("$0"); \
156 register long _sc_16 __asm__("$16"); \
157 register long _sc_19 __asm__("$19"); \
159 _sc_0 = __NR_##name; \
160 _sc_16 = (long) (arg1); \
161 __asm__("callsys # %0 %1 <= %2 %3" \
162 : "=r"(_sc_0), "=r"(_sc_19) \
163 : "0"(_sc_0), "r"(_sc_16) \
164 : inline_syscall_clobbers); \
165 _sc_ret = _sc_0, _sc_err = _sc_19; \
168 #define inline_syscall2(name,arg1,arg2) \
170 register long _sc_0 __asm__("$0"); \
171 register long _sc_16 __asm__("$16"); \
172 register long _sc_17 __asm__("$17"); \
173 register long _sc_19 __asm__("$19"); \
175 _sc_0 = __NR_##name; \
176 _sc_16 = (long) (arg1); \
177 _sc_17 = (long) (arg2); \
178 __asm__("callsys # %0 %1 <= %2 %3 %4" \
179 : "=r"(_sc_0), "=r"(_sc_19) \
180 : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17) \
181 : inline_syscall_clobbers); \
182 _sc_ret = _sc_0, _sc_err = _sc_19; \
185 #define inline_syscall3(name,arg1,arg2,arg3) \
187 register long _sc_0 __asm__("$0"); \
188 register long _sc_16 __asm__("$16"); \
189 register long _sc_17 __asm__("$17"); \
190 register long _sc_18 __asm__("$18"); \
191 register long _sc_19 __asm__("$19"); \
193 _sc_0 = __NR_##name; \
194 _sc_16 = (long) (arg1); \
195 _sc_17 = (long) (arg2); \
196 _sc_18 = (long) (arg3); \
197 __asm__("callsys # %0 %1 <= %2 %3 %4 %5" \
198 : "=r"(_sc_0), "=r"(_sc_19) \
199 : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17), \
200 "r"(_sc_18) \
201 : inline_syscall_clobbers); \
202 _sc_ret = _sc_0, _sc_err = _sc_19; \
205 #define inline_syscall4(name,arg1,arg2,arg3,arg4) \
207 register long _sc_0 __asm__("$0"); \
208 register long _sc_16 __asm__("$16"); \
209 register long _sc_17 __asm__("$17"); \
210 register long _sc_18 __asm__("$18"); \
211 register long _sc_19 __asm__("$19"); \
213 _sc_0 = __NR_##name; \
214 _sc_16 = (long) (arg1); \
215 _sc_17 = (long) (arg2); \
216 _sc_18 = (long) (arg3); \
217 _sc_19 = (long) (arg4); \
218 __asm__("callsys # %0 %1 <= %2 %3 %4 %5 %6" \
219 : "=r"(_sc_0), "=r"(_sc_19) \
220 : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17), \
221 "r"(_sc_18), "1"(_sc_19) \
222 : inline_syscall_clobbers); \
223 _sc_ret = _sc_0, _sc_err = _sc_19; \
226 #define inline_syscall5(name,arg1,arg2,arg3,arg4,arg5) \
228 register long _sc_0 __asm__("$0"); \
229 register long _sc_16 __asm__("$16"); \
230 register long _sc_17 __asm__("$17"); \
231 register long _sc_18 __asm__("$18"); \
232 register long _sc_19 __asm__("$19"); \
233 register long _sc_20 __asm__("$20"); \
235 _sc_0 = __NR_##name; \
236 _sc_16 = (long) (arg1); \
237 _sc_17 = (long) (arg2); \
238 _sc_18 = (long) (arg3); \
239 _sc_19 = (long) (arg4); \
240 _sc_20 = (long) (arg5); \
241 __asm__("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7" \
242 : "=r"(_sc_0), "=r"(_sc_19) \
243 : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17), \
244 "r"(_sc_18), "1"(_sc_19), "r"(_sc_20) \
245 : inline_syscall_clobbers); \
246 _sc_ret = _sc_0, _sc_err = _sc_19; \
249 #define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6) \
251 register long _sc_0 __asm__("$0"); \
252 register long _sc_16 __asm__("$16"); \
253 register long _sc_17 __asm__("$17"); \
254 register long _sc_18 __asm__("$18"); \
255 register long _sc_19 __asm__("$19"); \
256 register long _sc_20 __asm__("$20"); \
257 register long _sc_21 __asm__("$21"); \
259 _sc_0 = __NR_##name; \
260 _sc_16 = (long) (arg1); \
261 _sc_17 = (long) (arg2); \
262 _sc_18 = (long) (arg3); \
263 _sc_19 = (long) (arg4); \
264 _sc_20 = (long) (arg5); \
265 _sc_21 = (long) (arg6); \
266 __asm__("callsys # %0 %1 <= %2 %3 %4 %5 %6 %7 %8" \
267 : "=r"(_sc_0), "=r"(_sc_19) \
268 : "0"(_sc_0), "r"(_sc_16), "r"(_sc_17), \
269 "r"(_sc_18), "1"(_sc_19), "r"(_sc_20), \
270 "r"(_sc_21) \
271 : inline_syscall_clobbers); \
272 _sc_ret = _sc_0, _sc_err = _sc_19; \
275 #endif /* ASSEMBLER */