xref: /titanic_41/usr/src/lib/libc/sparc/inc/SYS.h (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_LIBC_SPARC_INC_SYS_H
28 #define	_LIBC_SPARC_INC_SYS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
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.
37  */
38 
39 #include <sys/asm_linkage.h>
40 #include <sys/syscall.h>
41 #include <sys/errno.h>
42 #include "synonyms.h"
43 
44 /*
45  * While it's tempting to imagine we could use 'rd %pc' here,
46  * in fact it's a rather slow operation that consumes many
47  * cycles, so we use the usual side-effect of 'call' instead.
48  */
49 #define	PIC_SETUP(r)						\
50 	mov	%o7, %g1;					\
51 9:	call	8f;						\
52 	sethi	%hi(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r;	\
53 8:	or	%r, %lo(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r;	\
54 	add	%r, %o7, %r;					\
55 	mov	%g1, %o7
56 
57 /*
58  * Trap number for system calls
59  */
60 #define	SYSCALL_TRAPNUM		8
61 #define	FASTSCALL_TRAPNUM	9
62 
63 /*
64  * Define the external symbols __cerror and __cerror64 for all files.
65  */
66 	.global	__cerror
67 	.global	__cerror64
68 
69 /*
70  * __SYSTRAP provides the basic trap sequence.  It assumes that an entry
71  * of the form SYS_name exists (probably from sys/syscall.h).
72  */
73 #define	__SYSTRAP(name)			\
74 	/* CSTYLED */			\
75 	mov	SYS_/**/name, %g1;	\
76 	ta	SYSCALL_TRAPNUM
77 
78 #define	SYSTRAP_RVAL1(name)		__SYSTRAP(name)
79 #define	SYSTRAP_RVAL2(name)		__SYSTRAP(name)
80 #define	SYSTRAP_2RVALS(name)		__SYSTRAP(name)
81 #define	SYSTRAP_64RVAL(name)		__SYSTRAP(name)
82 
83 /*
84  * SYSFASTTRAP provides the fast system call trap sequence.  It assumes
85  * that an entry of the form ST_name exists (probably from sys/trap.h).
86  */
87 #define	SYSFASTTRAP(name)		\
88 	/* CSTYLED */			\
89 	ta	ST_/**/name
90 
91 /*
92  * SYSCERROR provides the sequence to branch to __cerror if an error is
93  * indicated by the carry-bit being set upon return from a trap.
94  */
95 #define	SYSCERROR			\
96 	bcs	__cerror;		\
97 	nop
98 
99 /*
100  * SYSCERROR64 provides the sequence to branch to __cerror64 if an error is
101  * indicated by the carry-bit being set upon return from a trap.
102  */
103 #define	SYSCERROR64			\
104 	bcs	__cerror64;		\
105 	nop
106 
107 /*
108  * SYSLWPERR provides the sequence to return 0 on a successful trap
109  * and the error code if unsuccessful.
110  * Error is indicated by the carry-bit being set upon return from a trap.
111  */
112 #define	SYSLWPERR			\
113 	/* CSTYLED */			\
114 	bcc,a,pt %icc, 1f;		\
115 	clr	%o0;			\
116 	cmp	%o0, ERESTART;		\
117 	move	%icc, EINTR, %o0;	\
118 1:
119 
120 #define	SAVE_OFFSET	68
121 
122 /*
123  * SYSREENTRY provides the entry sequence for restartable system calls.
124  */
125 #define	SYSREENTRY(name)			\
126 	ENTRY(name);				\
127 	stn	%o0, [%sp + SAVE_OFFSET];	\
128 /* CSTYLED */					\
129 .restart_/**/name:
130 
131 /*
132  * SYSRESTART provides the error handling sequence for restartable
133  * system calls.
134  */
135 #define	SYSRESTART(name)					\
136 	/* CSTYLED */						\
137 	bcc,pt	%icc, 1f;					\
138 	cmp	%o0, ERESTART;					\
139 	/* CSTYLED */						\
140 	be,a,pn	%icc, name;					\
141 	ldn	[%sp + SAVE_OFFSET], %o0;			\
142 	/* CSTYLED */						\
143 	ba,a	__cerror;					\
144 1:
145 
146 /*
147  * SYSINTR_RESTART provides the error handling sequence for restartable
148  * system calls in case of EINTR or ERESTART.
149  */
150 #define	SYSINTR_RESTART(name)					\
151 	/* CSTYLED */						\
152 	bcc,a,pt %icc, 1f;					\
153 	clr	%o0;						\
154 	cmp	%o0, ERESTART;					\
155 	/* CSTYLED */						\
156 	be,a,pn	%icc, name;					\
157 	ldn	[%sp + SAVE_OFFSET], %o0;			\
158 	cmp	%o0, EINTR;					\
159 	/* CSTYLED */						\
160 	be,a,pn	%icc, name;					\
161 	ldn	[%sp + SAVE_OFFSET], %o0;			\
162 1:
163 
164 /*
165  * SYSCALL provides the standard (i.e.: most common) system call sequence.
166  */
167 #define	SYSCALL(name)						\
168 	ENTRY(name);						\
169 	SYSTRAP_2RVALS(name);					\
170 	SYSCERROR
171 
172 #define	SYSCALL_RVAL1(name)					\
173 	ENTRY(name);						\
174 	SYSTRAP_RVAL1(name);					\
175 	SYSCERROR
176 
177 /*
178  * SYSCALL64 provides the standard (i.e.: most common) system call sequence
179  * for system calls that return 64-bit values.
180  */
181 #define	SYSCALL64(name)						\
182 	ENTRY(name);						\
183 	SYSTRAP_64RVAL(name);					\
184 	SYSCERROR64
185 
186 /*
187  * SYSCALL_RESTART provides the most common restartable system call sequence.
188  */
189 #define	SYSCALL_RESTART(name)					\
190 	SYSREENTRY(name);					\
191 	SYSTRAP_2RVALS(name);					\
192 	/* CSTYLED */						\
193 	SYSRESTART(.restart_/**/name)
194 
195 #define	SYSCALL_RESTART_RVAL1(name)				\
196 	SYSREENTRY(name);					\
197 	SYSTRAP_RVAL1(name);					\
198 	/* CSTYLED */						\
199 	SYSRESTART(.restart_/**/name)
200 
201 /*
202  * SYSCALL2 provides a common system call sequence when the entry name
203  * is different than the trap name.
204  */
205 #define	SYSCALL2(entryname, trapname)				\
206 	ENTRY(entryname);					\
207 	SYSTRAP_2RVALS(trapname);				\
208 	SYSCERROR
209 
210 #define	SYSCALL2_RVAL1(entryname, trapname)			\
211 	ENTRY(entryname);					\
212 	SYSTRAP_RVAL1(trapname);				\
213 	SYSCERROR
214 
215 /*
216  * SYSCALL2_RESTART provides a common restartable system call sequence when the
217  * entry name is different than the trap name.
218  */
219 #define	SYSCALL2_RESTART(entryname, trapname)			\
220 	SYSREENTRY(entryname);					\
221 	SYSTRAP_2RVALS(trapname);				\
222 	/* CSTYLED */						\
223 	SYSRESTART(.restart_/**/entryname)
224 
225 #define	SYSCALL2_RESTART_RVAL1(entryname, trapname)		\
226 	SYSREENTRY(entryname);					\
227 	SYSTRAP_RVAL1(trapname);				\
228 	/* CSTYLED */						\
229 	SYSRESTART(.restart_/**/entryname)
230 
231 /*
232  * SYSCALL_NOERROR provides the most common system call sequence for those
233  * system calls which don't check the error return (carry bit).
234  */
235 #define	SYSCALL_NOERROR(name)					\
236 	ENTRY(name);						\
237 	SYSTRAP_2RVALS(name)
238 
239 #define	SYSCALL_NOERROR_RVAL1(name)				\
240 	ENTRY(name);						\
241 	SYSTRAP_RVAL1(name)
242 
243 /*
244  * Standard syscall return sequence, return code equal to rval1.
245  */
246 #define	RET			\
247 	retl;			\
248 	nop
249 
250 /*
251  * Syscall return sequence, return code equal to rval2.
252  */
253 #define	RET2			\
254 	retl;			\
255 	mov	%o1, %o0
256 
257 /*
258  * Syscall return sequence with return code forced to zero.
259  */
260 #define	RETC			\
261 	retl;			\
262 	clr	%o0
263 
264 #endif	/* _LIBC_SPARC_INC_SYS_H */
265