xref: /onnv-gate/usr/src/lib/libc/sparc/inc/SYS.h (revision 6812:febeba71273d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*6812Sraf  * Common Development and Distribution License (the "License").
6*6812Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*6812Sraf 
220Sstevel@tonic-gate /*
23*6812Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #ifndef	_LIBC_SPARC_INC_SYS_H
280Sstevel@tonic-gate #define	_LIBC_SPARC_INC_SYS_H
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate  * This file defines common code sequences for system calls.  Note that
340Sstevel@tonic-gate  * it is assumed that __cerror is within the short branch distance from
350Sstevel@tonic-gate  * all the traps (so that a simple bcs can follow the trap, rather than
360Sstevel@tonic-gate  * a position independent code sequence.)  Ditto for __cerror64.
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #include <sys/asm_linkage.h>
400Sstevel@tonic-gate #include <sys/syscall.h>
410Sstevel@tonic-gate #include <sys/errno.h>
420Sstevel@tonic-gate 
430Sstevel@tonic-gate /*
440Sstevel@tonic-gate  * While it's tempting to imagine we could use 'rd %pc' here,
450Sstevel@tonic-gate  * in fact it's a rather slow operation that consumes many
460Sstevel@tonic-gate  * cycles, so we use the usual side-effect of 'call' instead.
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate #define	PIC_SETUP(r)						\
490Sstevel@tonic-gate 	mov	%o7, %g1;					\
500Sstevel@tonic-gate 9:	call	8f;						\
510Sstevel@tonic-gate 	sethi	%hi(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r;	\
520Sstevel@tonic-gate 8:	or	%r, %lo(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r;	\
530Sstevel@tonic-gate 	add	%r, %o7, %r;					\
540Sstevel@tonic-gate 	mov	%g1, %o7
550Sstevel@tonic-gate 
560Sstevel@tonic-gate /*
570Sstevel@tonic-gate  * Trap number for system calls
580Sstevel@tonic-gate  */
590Sstevel@tonic-gate #define	SYSCALL_TRAPNUM		8
600Sstevel@tonic-gate #define	FASTSCALL_TRAPNUM	9
610Sstevel@tonic-gate 
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate  * Define the external symbols __cerror and __cerror64 for all files.
640Sstevel@tonic-gate  */
650Sstevel@tonic-gate 	.global	__cerror
660Sstevel@tonic-gate 	.global	__cerror64
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate  * __SYSTRAP provides the basic trap sequence.  It assumes that an entry
700Sstevel@tonic-gate  * of the form SYS_name exists (probably from sys/syscall.h).
710Sstevel@tonic-gate  */
720Sstevel@tonic-gate #define	__SYSTRAP(name)			\
730Sstevel@tonic-gate 	/* CSTYLED */			\
740Sstevel@tonic-gate 	mov	SYS_/**/name, %g1;	\
750Sstevel@tonic-gate 	ta	SYSCALL_TRAPNUM
760Sstevel@tonic-gate 
770Sstevel@tonic-gate #define	SYSTRAP_RVAL1(name)		__SYSTRAP(name)
780Sstevel@tonic-gate #define	SYSTRAP_RVAL2(name)		__SYSTRAP(name)
790Sstevel@tonic-gate #define	SYSTRAP_2RVALS(name)		__SYSTRAP(name)
800Sstevel@tonic-gate #define	SYSTRAP_64RVAL(name)		__SYSTRAP(name)
810Sstevel@tonic-gate 
820Sstevel@tonic-gate /*
830Sstevel@tonic-gate  * SYSFASTTRAP provides the fast system call trap sequence.  It assumes
840Sstevel@tonic-gate  * that an entry of the form ST_name exists (probably from sys/trap.h).
850Sstevel@tonic-gate  */
860Sstevel@tonic-gate #define	SYSFASTTRAP(name)		\
870Sstevel@tonic-gate 	/* CSTYLED */			\
880Sstevel@tonic-gate 	ta	ST_/**/name
890Sstevel@tonic-gate 
900Sstevel@tonic-gate /*
910Sstevel@tonic-gate  * SYSCERROR provides the sequence to branch to __cerror if an error is
920Sstevel@tonic-gate  * indicated by the carry-bit being set upon return from a trap.
930Sstevel@tonic-gate  */
940Sstevel@tonic-gate #define	SYSCERROR			\
950Sstevel@tonic-gate 	bcs	__cerror;		\
960Sstevel@tonic-gate 	nop
970Sstevel@tonic-gate 
980Sstevel@tonic-gate /*
990Sstevel@tonic-gate  * SYSCERROR64 provides the sequence to branch to __cerror64 if an error is
1000Sstevel@tonic-gate  * indicated by the carry-bit being set upon return from a trap.
1010Sstevel@tonic-gate  */
1020Sstevel@tonic-gate #define	SYSCERROR64			\
1030Sstevel@tonic-gate 	bcs	__cerror64;		\
1040Sstevel@tonic-gate 	nop
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate /*
1070Sstevel@tonic-gate  * SYSLWPERR provides the sequence to return 0 on a successful trap
1080Sstevel@tonic-gate  * and the error code if unsuccessful.
1090Sstevel@tonic-gate  * Error is indicated by the carry-bit being set upon return from a trap.
1100Sstevel@tonic-gate  */
1110Sstevel@tonic-gate #define	SYSLWPERR			\
1120Sstevel@tonic-gate 	/* CSTYLED */			\
1130Sstevel@tonic-gate 	bcc,a,pt %icc, 1f;		\
1140Sstevel@tonic-gate 	clr	%o0;			\
1150Sstevel@tonic-gate 	cmp	%o0, ERESTART;		\
1160Sstevel@tonic-gate 	move	%icc, EINTR, %o0;	\
1170Sstevel@tonic-gate 1:
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate #define	SAVE_OFFSET	68
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate /*
1220Sstevel@tonic-gate  * SYSREENTRY provides the entry sequence for restartable system calls.
1230Sstevel@tonic-gate  */
1240Sstevel@tonic-gate #define	SYSREENTRY(name)			\
1250Sstevel@tonic-gate 	ENTRY(name);				\
1260Sstevel@tonic-gate 	stn	%o0, [%sp + SAVE_OFFSET];	\
1270Sstevel@tonic-gate /* CSTYLED */					\
1280Sstevel@tonic-gate .restart_/**/name:
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate /*
1310Sstevel@tonic-gate  * SYSRESTART provides the error handling sequence for restartable
1320Sstevel@tonic-gate  * system calls.
1330Sstevel@tonic-gate  */
1340Sstevel@tonic-gate #define	SYSRESTART(name)					\
1350Sstevel@tonic-gate 	/* CSTYLED */						\
1360Sstevel@tonic-gate 	bcc,pt	%icc, 1f;					\
1370Sstevel@tonic-gate 	cmp	%o0, ERESTART;					\
1380Sstevel@tonic-gate 	/* CSTYLED */						\
1390Sstevel@tonic-gate 	be,a,pn	%icc, name;					\
1400Sstevel@tonic-gate 	ldn	[%sp + SAVE_OFFSET], %o0;			\
1410Sstevel@tonic-gate 	/* CSTYLED */						\
1420Sstevel@tonic-gate 	ba,a	__cerror;					\
1430Sstevel@tonic-gate 1:
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate /*
1460Sstevel@tonic-gate  * SYSINTR_RESTART provides the error handling sequence for restartable
1470Sstevel@tonic-gate  * system calls in case of EINTR or ERESTART.
1480Sstevel@tonic-gate  */
1490Sstevel@tonic-gate #define	SYSINTR_RESTART(name)					\
1500Sstevel@tonic-gate 	/* CSTYLED */						\
1510Sstevel@tonic-gate 	bcc,a,pt %icc, 1f;					\
1520Sstevel@tonic-gate 	clr	%o0;						\
1530Sstevel@tonic-gate 	cmp	%o0, ERESTART;					\
1540Sstevel@tonic-gate 	/* CSTYLED */						\
1550Sstevel@tonic-gate 	be,a,pn	%icc, name;					\
1560Sstevel@tonic-gate 	ldn	[%sp + SAVE_OFFSET], %o0;			\
1570Sstevel@tonic-gate 	cmp	%o0, EINTR;					\
1580Sstevel@tonic-gate 	/* CSTYLED */						\
1590Sstevel@tonic-gate 	be,a,pn	%icc, name;					\
1600Sstevel@tonic-gate 	ldn	[%sp + SAVE_OFFSET], %o0;			\
1610Sstevel@tonic-gate 1:
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate /*
1640Sstevel@tonic-gate  * SYSCALL provides the standard (i.e.: most common) system call sequence.
1650Sstevel@tonic-gate  */
1660Sstevel@tonic-gate #define	SYSCALL(name)						\
1670Sstevel@tonic-gate 	ENTRY(name);						\
1680Sstevel@tonic-gate 	SYSTRAP_2RVALS(name);					\
1690Sstevel@tonic-gate 	SYSCERROR
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate #define	SYSCALL_RVAL1(name)					\
1720Sstevel@tonic-gate 	ENTRY(name);						\
1730Sstevel@tonic-gate 	SYSTRAP_RVAL1(name);					\
1740Sstevel@tonic-gate 	SYSCERROR
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate /*
1770Sstevel@tonic-gate  * SYSCALL64 provides the standard (i.e.: most common) system call sequence
1780Sstevel@tonic-gate  * for system calls that return 64-bit values.
1790Sstevel@tonic-gate  */
1800Sstevel@tonic-gate #define	SYSCALL64(name)						\
1810Sstevel@tonic-gate 	ENTRY(name);						\
1820Sstevel@tonic-gate 	SYSTRAP_64RVAL(name);					\
1830Sstevel@tonic-gate 	SYSCERROR64
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate /*
1860Sstevel@tonic-gate  * SYSCALL_RESTART provides the most common restartable system call sequence.
1870Sstevel@tonic-gate  */
1880Sstevel@tonic-gate #define	SYSCALL_RESTART(name)					\
1890Sstevel@tonic-gate 	SYSREENTRY(name);					\
1900Sstevel@tonic-gate 	SYSTRAP_2RVALS(name);					\
1910Sstevel@tonic-gate 	/* CSTYLED */						\
1920Sstevel@tonic-gate 	SYSRESTART(.restart_/**/name)
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate #define	SYSCALL_RESTART_RVAL1(name)				\
1950Sstevel@tonic-gate 	SYSREENTRY(name);					\
1960Sstevel@tonic-gate 	SYSTRAP_RVAL1(name);					\
1970Sstevel@tonic-gate 	/* CSTYLED */						\
1980Sstevel@tonic-gate 	SYSRESTART(.restart_/**/name)
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate /*
2010Sstevel@tonic-gate  * SYSCALL2 provides a common system call sequence when the entry name
2020Sstevel@tonic-gate  * is different than the trap name.
2030Sstevel@tonic-gate  */
2040Sstevel@tonic-gate #define	SYSCALL2(entryname, trapname)				\
2050Sstevel@tonic-gate 	ENTRY(entryname);					\
2060Sstevel@tonic-gate 	SYSTRAP_2RVALS(trapname);				\
2070Sstevel@tonic-gate 	SYSCERROR
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate #define	SYSCALL2_RVAL1(entryname, trapname)			\
2100Sstevel@tonic-gate 	ENTRY(entryname);					\
2110Sstevel@tonic-gate 	SYSTRAP_RVAL1(trapname);				\
2120Sstevel@tonic-gate 	SYSCERROR
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate /*
2150Sstevel@tonic-gate  * SYSCALL2_RESTART provides a common restartable system call sequence when the
2160Sstevel@tonic-gate  * entry name is different than the trap name.
2170Sstevel@tonic-gate  */
2180Sstevel@tonic-gate #define	SYSCALL2_RESTART(entryname, trapname)			\
2190Sstevel@tonic-gate 	SYSREENTRY(entryname);					\
2200Sstevel@tonic-gate 	SYSTRAP_2RVALS(trapname);				\
2210Sstevel@tonic-gate 	/* CSTYLED */						\
2220Sstevel@tonic-gate 	SYSRESTART(.restart_/**/entryname)
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate #define	SYSCALL2_RESTART_RVAL1(entryname, trapname)		\
2250Sstevel@tonic-gate 	SYSREENTRY(entryname);					\
2260Sstevel@tonic-gate 	SYSTRAP_RVAL1(trapname);				\
2270Sstevel@tonic-gate 	/* CSTYLED */						\
2280Sstevel@tonic-gate 	SYSRESTART(.restart_/**/entryname)
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate /*
2310Sstevel@tonic-gate  * SYSCALL_NOERROR provides the most common system call sequence for those
2320Sstevel@tonic-gate  * system calls which don't check the error return (carry bit).
2330Sstevel@tonic-gate  */
2340Sstevel@tonic-gate #define	SYSCALL_NOERROR(name)					\
2350Sstevel@tonic-gate 	ENTRY(name);						\
2360Sstevel@tonic-gate 	SYSTRAP_2RVALS(name)
2370Sstevel@tonic-gate 
2380Sstevel@tonic-gate #define	SYSCALL_NOERROR_RVAL1(name)				\
2390Sstevel@tonic-gate 	ENTRY(name);						\
2400Sstevel@tonic-gate 	SYSTRAP_RVAL1(name)
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate /*
2430Sstevel@tonic-gate  * Standard syscall return sequence, return code equal to rval1.
2440Sstevel@tonic-gate  */
2450Sstevel@tonic-gate #define	RET			\
2460Sstevel@tonic-gate 	retl;			\
2470Sstevel@tonic-gate 	nop
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate /*
2500Sstevel@tonic-gate  * Syscall return sequence, return code equal to rval2.
2510Sstevel@tonic-gate  */
2520Sstevel@tonic-gate #define	RET2			\
2530Sstevel@tonic-gate 	retl;			\
2540Sstevel@tonic-gate 	mov	%o1, %o0
2550Sstevel@tonic-gate 
2560Sstevel@tonic-gate /*
2570Sstevel@tonic-gate  * Syscall return sequence with return code forced to zero.
2580Sstevel@tonic-gate  */
2590Sstevel@tonic-gate #define	RETC			\
2600Sstevel@tonic-gate 	retl;			\
2610Sstevel@tonic-gate 	clr	%o0
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate #endif	/* _LIBC_SPARC_INC_SYS_H */
264