xref: /onnv-gate/usr/src/lib/libc/amd64/inc/SYS.h (revision 1928:dae0f98da698)
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*1928Scraigm  * Common Development and Distribution License (the "License").
6*1928Scraigm  * 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  */
210Sstevel@tonic-gate /*
22*1928Scraigm  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_LIBC_AMD64_INC_SYS_H
270Sstevel@tonic-gate #define	_LIBC_AMD64_INC_SYS_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate /*
320Sstevel@tonic-gate  * This file defines common code sequences for system calls.
330Sstevel@tonic-gate  */
340Sstevel@tonic-gate #include <sys/asm_linkage.h>
350Sstevel@tonic-gate #include <sys/syscall.h>
360Sstevel@tonic-gate #include <sys/errno.h>
370Sstevel@tonic-gate #include "synonyms.h"
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #undef	syscall		/* override synonyms.h */
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /*
420Sstevel@tonic-gate  * XX64 -- the SOS9 assembler doesn't recognize the 'syscall' instruction yet.
430Sstevel@tonic-gate  * We compensate by defining the byte sequence here.
440Sstevel@tonic-gate  */
450Sstevel@tonic-gate #define	syscall	.byte 0xf, 0x5
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #define	_fref_(name)	name@PLT
480Sstevel@tonic-gate #define	_daref_(name)	name@GOTPCREL(%rip)
490Sstevel@tonic-gate #define	_sref_(name)	name(%rip)
500Sstevel@tonic-gate 
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate  * Define the external symbol __cerror for all files.
530Sstevel@tonic-gate  */
540Sstevel@tonic-gate 	.globl	__cerror
550Sstevel@tonic-gate 
560Sstevel@tonic-gate /*
570Sstevel@tonic-gate  * __SYSCALL provides the basic trap sequence.  It assumes that
580Sstevel@tonic-gate  * an entry of the form SYS_name exists (from sys/syscall.h).
590Sstevel@tonic-gate  * Note that %rcx is smashed by the syscall instruction,
600Sstevel@tonic-gate  * so we move it to %r10 in order to pass it to the kernel.
610Sstevel@tonic-gate  */
620Sstevel@tonic-gate #define	__SYSCALL(name)			\
630Sstevel@tonic-gate 	movq	%rcx, %r10;		\
640Sstevel@tonic-gate 	/* CSTYLED */			\
650Sstevel@tonic-gate 	movl	$SYS_/**/name, %eax;	\
660Sstevel@tonic-gate 	syscall
670Sstevel@tonic-gate 
680Sstevel@tonic-gate #define	SYSTRAP_RVAL1(name)	__SYSCALL(name)
690Sstevel@tonic-gate #define	SYSTRAP_RVAL2(name)	__SYSCALL(name)
700Sstevel@tonic-gate #define	SYSTRAP_2RVALS(name)	__SYSCALL(name)
710Sstevel@tonic-gate #define	SYSTRAP_64RVAL(name)	__SYSCALL(name)
720Sstevel@tonic-gate 
730Sstevel@tonic-gate /*
740Sstevel@tonic-gate  * SYSFASTTRAP provides the fast system call trap sequence.  It assumes
750Sstevel@tonic-gate  * that an entry of the form T_name exists (probably from sys/trap.h).
760Sstevel@tonic-gate  */
770Sstevel@tonic-gate #define	SYSFASTTRAP(name)		\
780Sstevel@tonic-gate 	/* CSTYLED */			\
790Sstevel@tonic-gate 	movl	$T_/**/name, %eax;	\
800Sstevel@tonic-gate 	int	$T_FASTTRAP
810Sstevel@tonic-gate 
820Sstevel@tonic-gate /*
830Sstevel@tonic-gate  * SYSCERROR provides the sequence to branch to __cerror if an error is
840Sstevel@tonic-gate  * indicated by the carry-bit being set upon return from a trap.
850Sstevel@tonic-gate  */
860Sstevel@tonic-gate #define	SYSCERROR		\
870Sstevel@tonic-gate 	jb	__cerror
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate  * SYSLWPERR provides the sequence to return 0 on a successful trap
910Sstevel@tonic-gate  * and the error code if unsuccessful.
920Sstevel@tonic-gate  * Error is indicated by the carry-bit being set upon return from a trap.
930Sstevel@tonic-gate  */
940Sstevel@tonic-gate #define	SYSLWPERR			\
950Sstevel@tonic-gate 	jae	1f;			\
960Sstevel@tonic-gate 	cmpl	$ERESTART, %eax;	\
970Sstevel@tonic-gate 	jne	2f;			\
980Sstevel@tonic-gate 	movl	$EINTR, %eax;		\
990Sstevel@tonic-gate 	jmp	2f;			\
1000Sstevel@tonic-gate 1:					\
1010Sstevel@tonic-gate 	xorq	%rax, %rax;		\
1020Sstevel@tonic-gate 2:
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate /*
1050Sstevel@tonic-gate  * SYSREENTRY provides the entry sequence for restartable system calls.
1060Sstevel@tonic-gate  */
1070Sstevel@tonic-gate #define	SYSREENTRY(name)	\
1080Sstevel@tonic-gate 	ENTRY(name);		\
1090Sstevel@tonic-gate 1:
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate /*
1120Sstevel@tonic-gate  * SYSRESTART provides the error handling sequence for restartable
1130Sstevel@tonic-gate  * system calls.
1140Sstevel@tonic-gate  * XX64 -- Are all of the argument registers restored to their
1150Sstevel@tonic-gate  * original values on an ERESTART return (including %rcx)?
1160Sstevel@tonic-gate  */
1170Sstevel@tonic-gate #define	SYSRESTART(name)		\
1180Sstevel@tonic-gate 	jae	1f;			\
1190Sstevel@tonic-gate 	cmpl	$ERESTART, %eax;	\
1200Sstevel@tonic-gate 	je	1b;			\
1210Sstevel@tonic-gate 	jmp	__cerror;		\
1220Sstevel@tonic-gate 1:
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate /*
1250Sstevel@tonic-gate  * SYSINTR_RESTART provides the error handling sequence for restartable
1260Sstevel@tonic-gate  * system calls in case of EINTR or ERESTART.
1270Sstevel@tonic-gate  */
1280Sstevel@tonic-gate #define	SYSINTR_RESTART(name)		\
1290Sstevel@tonic-gate 	jae	1f;			\
1300Sstevel@tonic-gate 	cmpl	$ERESTART, %eax;	\
1310Sstevel@tonic-gate 	je	1b;			\
1320Sstevel@tonic-gate 	cmpl	$EINTR, %eax;		\
1330Sstevel@tonic-gate 	je	1b;			\
1340Sstevel@tonic-gate 	jmp	2f;			\
1350Sstevel@tonic-gate 1:					\
1360Sstevel@tonic-gate 	xorq	%rax, %rax;		\
1370Sstevel@tonic-gate 2:
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate /*
1400Sstevel@tonic-gate  * SYSCALL provides the standard (i.e.: most common) system call sequence.
1410Sstevel@tonic-gate  */
1420Sstevel@tonic-gate #define	SYSCALL(name)			\
1430Sstevel@tonic-gate 	ENTRY(name);			\
1440Sstevel@tonic-gate 	SYSTRAP_2RVALS(name);		\
1450Sstevel@tonic-gate 	SYSCERROR
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate #define	SYSCALL_RVAL1(name)		\
1480Sstevel@tonic-gate 	ENTRY(name);			\
1490Sstevel@tonic-gate 	SYSTRAP_RVAL1(name);		\
1500Sstevel@tonic-gate 	SYSCERROR
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate /*
1530Sstevel@tonic-gate  * SYSCALL64 provides the standard (i.e.: most common) system call sequence
1540Sstevel@tonic-gate  * for system calls that return 64-bit values.
1550Sstevel@tonic-gate  */
1560Sstevel@tonic-gate #define	SYSCALL64(name)			\
157*1928Scraigm 	SYSCALL(name)
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate /*
1600Sstevel@tonic-gate  * SYSCALL_RESTART provides the most common restartable system call sequence.
1610Sstevel@tonic-gate  */
1620Sstevel@tonic-gate #define	SYSCALL_RESTART(name)		\
1630Sstevel@tonic-gate 	SYSREENTRY(name);		\
1640Sstevel@tonic-gate 	SYSTRAP_2RVALS(name);		\
1650Sstevel@tonic-gate 	SYSRESTART()
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate #define	SYSCALL_RESTART_RVAL1(name)	\
1680Sstevel@tonic-gate 	SYSREENTRY(name);		\
1690Sstevel@tonic-gate 	SYSTRAP_RVAL1(name);		\
1700Sstevel@tonic-gate 	SYSRESTART()
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate /*
1730Sstevel@tonic-gate  * SYSCALL2 provides a common system call sequence when the entry name
1740Sstevel@tonic-gate  * is different than the trap name.
1750Sstevel@tonic-gate  */
1760Sstevel@tonic-gate #define	SYSCALL2(entryname, trapname)	\
1770Sstevel@tonic-gate 	ENTRY(entryname);		\
1780Sstevel@tonic-gate 	SYSTRAP_2RVALS(trapname);	\
1790Sstevel@tonic-gate 	SYSCERROR
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate #define	SYSCALL2_RVAL1(entryname, trapname)	\
1820Sstevel@tonic-gate 	ENTRY(entryname);			\
1830Sstevel@tonic-gate 	SYSTRAP_RVAL1(trapname);		\
1840Sstevel@tonic-gate 	SYSCERROR
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate /*
1870Sstevel@tonic-gate  * SYSCALL2_RESTART provides a common restartable system call sequence when the
1880Sstevel@tonic-gate  * entry name is different than the trap name.
1890Sstevel@tonic-gate  */
1900Sstevel@tonic-gate #define	SYSCALL2_RESTART(entryname, trapname)	\
1910Sstevel@tonic-gate 	SYSREENTRY(entryname);			\
1920Sstevel@tonic-gate 	SYSTRAP_2RVALS(trapname);		\
1930Sstevel@tonic-gate 	SYSRESTART()
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate #define	SYSCALL2_RESTART_RVAL1(entryname, trapname)	\
1960Sstevel@tonic-gate 	SYSREENTRY(entryname);				\
1970Sstevel@tonic-gate 	SYSTRAP_RVAL1(trapname);			\
1980Sstevel@tonic-gate 	SYSRESTART()
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate /*
2010Sstevel@tonic-gate  * SYSCALL_NOERROR provides the most common system call sequence for those
2020Sstevel@tonic-gate  * system calls which don't check the error reture (carry bit).
2030Sstevel@tonic-gate  */
2040Sstevel@tonic-gate #define	SYSCALL_NOERROR(name)		\
2050Sstevel@tonic-gate 	ENTRY(name);			\
2060Sstevel@tonic-gate 	SYSTRAP_2RVALS(name)
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate #define	SYSCALL_NOERROR_RVAL1(name)	\
2090Sstevel@tonic-gate 	ENTRY(name);			\
2100Sstevel@tonic-gate 	SYSTRAP_RVAL1(name)
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate /*
2130Sstevel@tonic-gate  * Standard syscall return sequence, return code equal to rval1.
2140Sstevel@tonic-gate  */
2150Sstevel@tonic-gate #define	RET			\
2160Sstevel@tonic-gate 	ret
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate /*
2190Sstevel@tonic-gate  * Syscall return sequence, return code equal to rval2.
2200Sstevel@tonic-gate  */
2210Sstevel@tonic-gate #define	RET2			\
2220Sstevel@tonic-gate 	movq	%rdx, %rax;	\
2230Sstevel@tonic-gate 	ret
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate /*
2260Sstevel@tonic-gate  * Syscall return sequence with return code forced to zero.
2270Sstevel@tonic-gate  */
2280Sstevel@tonic-gate #define	RETC			\
2290Sstevel@tonic-gate 	xorq	%rax, %rax;	\
2300Sstevel@tonic-gate 	ret
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate #endif	/* _LIBC_AMD64_INC_SYS_H */
233