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