8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libc / sparc / inc / SYS.h
blob25a2a9b8988a9d69ecc056af28e23f2c56d5a9a5
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _LIBC_SPARC_INC_SYS_H
28 #define _LIBC_SPARC_INC_SYS_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 * This file defines common code sequences for system calls. Note that
34 * it is assumed that __cerror is within the short branch distance from
35 * all the traps (so that a simple bcs can follow the trap, rather than
36 * a position independent code sequence.) Ditto for __cerror64.
39 #include <sys/asm_linkage.h>
40 #include <sys/syscall.h>
41 #include <sys/errno.h>
44 * While it's tempting to imagine we could use 'rd %pc' here,
45 * in fact it's a rather slow operation that consumes many
46 * cycles, so we use the usual side-effect of 'call' instead.
48 #define PIC_SETUP(r) \
49 mov %o7, %g1; \
50 9: call 8f; \
51 sethi %hi(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r; \
52 8: or %r, %lo(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r; \
53 add %r, %o7, %r; \
54 mov %g1, %o7
57 * Trap number for system calls
59 #define SYSCALL_TRAPNUM 8
60 #define FASTSCALL_TRAPNUM 9
63 * Define the external symbols __cerror and __cerror64 for all files.
65 .global __cerror
66 .global __cerror64
69 * __SYSTRAP provides the basic trap sequence. It assumes that an entry
70 * of the form SYS_name exists (probably from sys/syscall.h).
72 #define __SYSTRAP(name) \
73 /* CSTYLED */ \
74 mov SYS_/**/name, %g1; \
75 ta SYSCALL_TRAPNUM
77 #define SYSTRAP_RVAL1(name) __SYSTRAP(name)
78 #define SYSTRAP_RVAL2(name) __SYSTRAP(name)
79 #define SYSTRAP_2RVALS(name) __SYSTRAP(name)
80 #define SYSTRAP_64RVAL(name) __SYSTRAP(name)
83 * SYSFASTTRAP provides the fast system call trap sequence. It assumes
84 * that an entry of the form ST_name exists (probably from sys/trap.h).
86 #define SYSFASTTRAP(name) \
87 /* CSTYLED */ \
88 ta ST_/**/name
91 * SYSCERROR provides the sequence to branch to __cerror if an error is
92 * indicated by the carry-bit being set upon return from a trap.
94 #define SYSCERROR \
95 bcs __cerror; \
96 nop
99 * SYSCERROR64 provides the sequence to branch to __cerror64 if an error is
100 * indicated by the carry-bit being set upon return from a trap.
102 #define SYSCERROR64 \
103 bcs __cerror64; \
107 * SYSLWPERR provides the sequence to return 0 on a successful trap
108 * and the error code if unsuccessful.
109 * Error is indicated by the carry-bit being set upon return from a trap.
111 #define SYSLWPERR \
112 /* CSTYLED */ \
113 bcc,a,pt %icc, 1f; \
114 clr %o0; \
115 cmp %o0, ERESTART; \
116 move %icc, EINTR, %o0; \
119 #define SAVE_OFFSET 68
122 * SYSREENTRY provides the entry sequence for restartable system calls.
124 #define SYSREENTRY(name) \
125 ENTRY(name); \
126 stn %o0, [%sp + SAVE_OFFSET]; \
127 /* CSTYLED */ \
128 .restart_/**/name:
131 * SYSRESTART provides the error handling sequence for restartable
132 * system calls.
134 #define SYSRESTART(name) \
135 /* CSTYLED */ \
136 bcc,pt %icc, 1f; \
137 cmp %o0, ERESTART; \
138 /* CSTYLED */ \
139 be,a,pn %icc, name; \
140 ldn [%sp + SAVE_OFFSET], %o0; \
141 /* CSTYLED */ \
142 ba,a __cerror; \
146 * SYSINTR_RESTART provides the error handling sequence for restartable
147 * system calls in case of EINTR or ERESTART.
149 #define SYSINTR_RESTART(name) \
150 /* CSTYLED */ \
151 bcc,a,pt %icc, 1f; \
152 clr %o0; \
153 cmp %o0, ERESTART; \
154 /* CSTYLED */ \
155 be,a,pn %icc, name; \
156 ldn [%sp + SAVE_OFFSET], %o0; \
157 cmp %o0, EINTR; \
158 /* CSTYLED */ \
159 be,a,pn %icc, name; \
160 ldn [%sp + SAVE_OFFSET], %o0; \
164 * SYSCALL provides the standard (i.e.: most common) system call sequence.
166 #define SYSCALL(name) \
167 ENTRY(name); \
168 SYSTRAP_2RVALS(name); \
169 SYSCERROR
171 #define SYSCALL_RVAL1(name) \
172 ENTRY(name); \
173 SYSTRAP_RVAL1(name); \
174 SYSCERROR
177 * SYSCALL64 provides the standard (i.e.: most common) system call sequence
178 * for system calls that return 64-bit values.
180 #define SYSCALL64(name) \
181 ENTRY(name); \
182 SYSTRAP_64RVAL(name); \
183 SYSCERROR64
186 * SYSCALL_RESTART provides the most common restartable system call sequence.
188 #define SYSCALL_RESTART(name) \
189 SYSREENTRY(name); \
190 SYSTRAP_2RVALS(name); \
191 /* CSTYLED */ \
192 SYSRESTART(.restart_/**/name)
194 #define SYSCALL_RESTART_RVAL1(name) \
195 SYSREENTRY(name); \
196 SYSTRAP_RVAL1(name); \
197 /* CSTYLED */ \
198 SYSRESTART(.restart_/**/name)
201 * SYSCALL2 provides a common system call sequence when the entry name
202 * is different than the trap name.
204 #define SYSCALL2(entryname, trapname) \
205 ENTRY(entryname); \
206 SYSTRAP_2RVALS(trapname); \
207 SYSCERROR
209 #define SYSCALL2_RVAL1(entryname, trapname) \
210 ENTRY(entryname); \
211 SYSTRAP_RVAL1(trapname); \
212 SYSCERROR
215 * SYSCALL2_RESTART provides a common restartable system call sequence when the
216 * entry name is different than the trap name.
218 #define SYSCALL2_RESTART(entryname, trapname) \
219 SYSREENTRY(entryname); \
220 SYSTRAP_2RVALS(trapname); \
221 /* CSTYLED */ \
222 SYSRESTART(.restart_/**/entryname)
224 #define SYSCALL2_RESTART_RVAL1(entryname, trapname) \
225 SYSREENTRY(entryname); \
226 SYSTRAP_RVAL1(trapname); \
227 /* CSTYLED */ \
228 SYSRESTART(.restart_/**/entryname)
231 * SYSCALL_NOERROR provides the most common system call sequence for those
232 * system calls which don't check the error return (carry bit).
234 #define SYSCALL_NOERROR(name) \
235 ENTRY(name); \
236 SYSTRAP_2RVALS(name)
238 #define SYSCALL_NOERROR_RVAL1(name) \
239 ENTRY(name); \
240 SYSTRAP_RVAL1(name)
243 * Standard syscall return sequence, return code equal to rval1.
245 #define RET \
246 retl; \
250 * Syscall return sequence, return code equal to rval2.
252 #define RET2 \
253 retl; \
254 mov %o1, %o0
257 * Syscall return sequence with return code forced to zero.
259 #define RETC \
260 retl; \
261 clr %o0
263 #endif /* _LIBC_SPARC_INC_SYS_H */