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