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