Update to LGPL v2.1.
[kopensolaris-gnu/glibc.git] / sysdeps / unix / alpha / sysdep.h
1 /* Copyright (C) 1992, 1995, 1996, 2000 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Brendan Kehoe (brendan@zen.org).
4
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9
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    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #include <sysdeps/unix/sysdep.h>
21
22 #ifdef __ASSEMBLER__
23
24 #ifdef __linux__
25 # include <alpha/regdef.h>
26 #else
27 # include <regdef.h>
28 #endif
29
30 #ifdef __STDC__
31 #define __LABEL(x)      x##:
32 #else
33 #define __LABEL(x)      x/**/:
34 #endif
35
36 #define LEAF(name, framesize)                   \
37   .globl name;                                  \
38   .align 3;                                     \
39   .ent name, 0;                                 \
40   __LABEL(name)                                 \
41   .frame sp, framesize, ra
42
43 #define ENTRY(name)                             \
44   .globl name;                                  \
45   .align 3;                                     \
46   .ent name, 0;                                 \
47   __LABEL(name)                                 \
48   .frame sp, 0, ra
49
50 /* Mark the end of function SYM.  */
51 #undef END
52 #define END(sym)        .end sym
53
54 /* Note that PSEUDO/PSEUDO_END use label number 1996---do not use a
55    label of that number between those two macros!  */
56
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;                      \
75 3:
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;                      \
89 3:
90 #endif
91
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
106
107 #define r0      v0
108 #define r1      a4
109
110 #define MOVE(x,y)       mov x,y
111
112 #else /* !ASSEMBLER */
113
114 /* Define a macro which expands inline into the wrapper code for a
115    system call.  */
116
117 #undef INLINE_SYSCALL
118 #define INLINE_SYSCALL(name, nr, args...)  INLINE_SYSCALL1(name, nr, args)
119
120 #define INLINE_SYSCALL1(name, nr, args...)      \
121 ({                                              \
122         long _sc_ret, _sc_err;                  \
123         inline_syscall##nr(name, args);         \
124         if (_sc_err)                            \
125           {                                     \
126             __set_errno (_sc_ret);              \
127             _sc_ret = -1L;                      \
128           }                                     \
129         _sc_ret;                                \
130 })
131
132 #define inline_syscall_clobbers                         \
133         "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", \
134         "$22", "$23", "$24", "$25", "$27", "$28", "memory"
135
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.  */
139
140 #define inline_syscall0(name)                   \
141 {                                               \
142         register long _sc_0 __asm__("$0");      \
143         register long _sc_19 __asm__("$19");    \
144                                                 \
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;      \
151 }
152
153 #define inline_syscall1(name,arg1)              \
154 {                                               \
155         register long _sc_0 __asm__("$0");      \
156         register long _sc_16 __asm__("$16");    \
157         register long _sc_19 __asm__("$19");    \
158                                                 \
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;      \
166 }
167
168 #define inline_syscall2(name,arg1,arg2)                 \
169 {                                                       \
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");            \
174                                                         \
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;              \
183 }
184
185 #define inline_syscall3(name,arg1,arg2,arg3)            \
186 {                                                       \
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");            \
192                                                         \
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;              \
203 }
204
205 #define inline_syscall4(name,arg1,arg2,arg3,arg4)       \
206 {                                                       \
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");            \
212                                                         \
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;              \
224 }
225
226 #define inline_syscall5(name,arg1,arg2,arg3,arg4,arg5)  \
227 {                                                       \
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");            \
234                                                         \
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;              \
247 }
248
249 #define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6)     \
250 {                                                               \
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");                    \
258                                                                 \
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;                      \
273 }
274
275 #endif /* ASSEMBLER */