xref: /titanic_52/usr/src/lib/libc/sparcv9/inc/SYS.h (revision d58fda4376e4bf67072ce2e69f6f47036f9dbb68)
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_SPARCV9_INC_SYS_H
28 #define	_LIBC_SPARCV9_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.)
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	64
61 
62 /*
63  * Define the external symbol __cerror for all files.
64  */
65 	.global	__cerror
66 
67 /*
68  * __SYSTRAP provides the basic trap sequence.  It assumes that an entry
69  * of the form SYS_name exists (probably from sys/syscall.h).
70  */
71 #define	__SYSTRAP(name)			\
72 	/* CSTYLED */			\
73 	mov	SYS_/**/name, %g1;	\
74 	ta	SYSCALL_TRAPNUM
75 
76 #define	SYSTRAP_RVAL1(name)		__SYSTRAP(name)
77 #define	SYSTRAP_RVAL2(name)		__SYSTRAP(name)
78 #define	SYSTRAP_2RVALS(name)		__SYSTRAP(name)
79 #define	SYSTRAP_64RVAL(name)		__SYSTRAP(name)
80 
81 /*
82  * SYSFASTTRAP provides the fast system call trap sequence.  It assumes
83  * that an entry of the form ST_name exists (probably from sys/trap.h).
84  */
85 #define	SYSFASTTRAP(name)		\
86 	/* CSTYLED */			\
87 	ta	ST_/**/name
88 
89 /*
90  * SYSCERROR provides the sequence to branch to __cerror if an error is
91  * indicated by the carry-bit being set upon return from a trap.
92  */
93 #define	SYSCERROR			\
94 	/* CSTYLED */			\
95 	bcs	__cerror;		\
96 	nop
97 
98 /*
99  * SYSLWPERR provides the sequence to return 0 on a successful trap
100  * and the error code if unsuccessful.
101  * Error is indicated by the carry-bit being set upon return from a trap.
102  */
103 #define	SYSLWPERR			\
104 	/* CSTYLED */			\
105 	bcc,a,pt %icc, 1f;		\
106 	clr	%o0;			\
107 	cmp	%o0, ERESTART;		\
108 	move	%icc, EINTR, %o0;	\
109 1:
110 
111 #define	SAVE_OFFSET	(STACK_BIAS + 8 * 16)
112 
113 /*
114  * SYSREENTRY provides the entry sequence for restartable system calls.
115  */
116 #define	SYSREENTRY(name)			\
117 	ENTRY(name);				\
118 	stn	%o0, [%sp + SAVE_OFFSET];	\
119 /* CSTYLED */					\
120 .restart_/**/name:
121 
122 /*
123  * SYSRESTART provides the error handling sequence for restartable
124  * system calls.
125  */
126 #define	SYSRESTART(name)					\
127 	/* CSTYLED */						\
128 	bcc,pt	%icc, 1f;					\
129 	cmp	%o0, ERESTART;					\
130 	/* CSTYLED */						\
131 	be,a,pn	%icc, name;					\
132 	ldn	[%sp + SAVE_OFFSET], %o0;			\
133 	/* CSTYLED */						\
134 	ba,a	__cerror;					\
135 1:
136 
137 /*
138  * SYSINTR_RESTART provides the error handling sequence for restartable
139  * system calls in case of EINTR or ERESTART.
140  */
141 #define	SYSINTR_RESTART(name)					\
142 	/* CSTYLED */						\
143 	bcc,a,pt %icc, 1f;					\
144 	clr	%o0;						\
145 	cmp	%o0, ERESTART;					\
146 	/* CSTYLED */						\
147 	be,a,pn	%icc, name;					\
148 	ldn	[%sp + SAVE_OFFSET], %o0;			\
149 	cmp	%o0, EINTR;					\
150 	/* CSTYLED */						\
151 	be,a,pn	%icc, name;					\
152 	ldn	[%sp + SAVE_OFFSET], %o0;			\
153 1:
154 
155 /*
156  * SYSCALL provides the standard (i.e.: most common) system call sequence.
157  */
158 #define	SYSCALL(name)						\
159 	ENTRY(name);						\
160 	SYSTRAP_2RVALS(name);					\
161 	SYSCERROR
162 
163 #define	SYSCALL_RVAL1(name)					\
164 	ENTRY(name);						\
165 	SYSTRAP_RVAL1(name);					\
166 	SYSCERROR
167 
168 /*
169  * SYSCALL_RESTART provides the most common restartable system call sequence.
170  */
171 #define	SYSCALL_RESTART(name)					\
172 	SYSREENTRY(name);					\
173 	SYSTRAP_2RVALS(name);					\
174 	/* CSTYLED */						\
175 	SYSRESTART(.restart_/**/name)
176 
177 #define	SYSCALL_RESTART_RVAL1(name)				\
178 	SYSREENTRY(name);					\
179 	SYSTRAP_RVAL1(name);					\
180 	/* CSTYLED */						\
181 	SYSRESTART(.restart_/**/name)
182 
183 /*
184  * SYSCALL2 provides a common system call sequence when the entry name
185  * is different than the trap name.
186  */
187 #define	SYSCALL2(entryname, trapname)				\
188 	ENTRY(entryname);					\
189 	SYSTRAP_2RVALS(trapname);				\
190 	SYSCERROR
191 
192 #define	SYSCALL2_RVAL1(entryname, trapname)			\
193 	ENTRY(entryname);					\
194 	SYSTRAP_RVAL1(trapname);				\
195 	SYSCERROR
196 
197 /*
198  * SYSCALL2_RESTART provides a common restartable system call sequence when the
199  * entry name is different than the trap name.
200  */
201 #define	SYSCALL2_RESTART(entryname, trapname)			\
202 	SYSREENTRY(entryname);					\
203 	SYSTRAP_2RVALS(trapname);				\
204 	/* CSTYLED */						\
205 	SYSRESTART(.restart_/**/entryname)
206 
207 #define	SYSCALL2_RESTART_RVAL1(entryname, trapname)		\
208 	SYSREENTRY(entryname);					\
209 	SYSTRAP_RVAL1(trapname);				\
210 	/* CSTYLED */						\
211 	SYSRESTART(.restart_/**/entryname)
212 
213 /*
214  * SYSCALL_NOERROR provides the most common system call sequence for those
215  * system calls which don't check the error return (carry bit).
216  */
217 #define	SYSCALL_NOERROR(name)					\
218 	ENTRY(name);						\
219 	SYSTRAP_2RVALS(name)
220 
221 #define	SYSCALL_NOERROR_RVAL1(name)				\
222 	ENTRY(name);						\
223 	SYSTRAP_RVAL1(name)
224 
225 /*
226  * Standard syscall return sequence, return code equal to rval1.
227  */
228 #define	RET			\
229 	retl;			\
230 	nop
231 
232 /*
233  * Syscall return sequence, return code equal to rval2.
234  */
235 #define	RET2			\
236 	retl;			\
237 	mov	%o1, %o0
238 
239 /*
240  * Syscall return sequence with return code forced to zero.
241  */
242 #define	RETC			\
243 	retl;			\
244 	clr	%o0
245 
246 #endif	/* _LIBC_SPARCV9_INC_SYS_H */
247