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_I386_INC_SYS_H 280Sstevel@tonic-gate #define _LIBC_I386_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 _prologue_ \ 400Sstevel@tonic-gate pushl %ebx; \ 410Sstevel@tonic-gate call 9f; \ 420Sstevel@tonic-gate 9: \ 430Sstevel@tonic-gate popl %ebx; \ 440Sstevel@tonic-gate addl $_GLOBAL_OFFSET_TABLE_ + [. - 9b], %ebx 450Sstevel@tonic-gate 460Sstevel@tonic-gate #define _epilogue_ \ 470Sstevel@tonic-gate popl %ebx 480Sstevel@tonic-gate 490Sstevel@tonic-gate #define _fref_(name) name@PLT 500Sstevel@tonic-gate #define _daref_(name) name@GOT(%ebx) 510Sstevel@tonic-gate #define _sref_(name) name@GOTOFF(%ebx) 520Sstevel@tonic-gate #define _esp_(offset) offset+4(%esp) /* add 4 for the saved %ebx */ 530Sstevel@tonic-gate 540Sstevel@tonic-gate /* 550Sstevel@tonic-gate * Define the external symbols __cerror and __cerror64 for all files. 560Sstevel@tonic-gate */ 570Sstevel@tonic-gate .globl __cerror 580Sstevel@tonic-gate .globl __cerror64 590Sstevel@tonic-gate 600Sstevel@tonic-gate /* 610Sstevel@tonic-gate * __SYSCALLINT provides the basic trap sequence. It assumes that an entry 620Sstevel@tonic-gate * of the form SYS_name exists (probably from sys/syscall.h). 630Sstevel@tonic-gate */ 640Sstevel@tonic-gate 650Sstevel@tonic-gate #define __SYSCALLINT(name) \ 660Sstevel@tonic-gate /* CSTYLED */ \ 670Sstevel@tonic-gate movl $SYS_/**/name, %eax; \ 680Sstevel@tonic-gate int $T_SYSCALLINT 690Sstevel@tonic-gate 700Sstevel@tonic-gate /* 710Sstevel@tonic-gate * __SYSENTER provides a faster variant that is only able to 720Sstevel@tonic-gate * return rval1. Note that %ecx and %edx are ALWAYS smashed. 730Sstevel@tonic-gate */ 740Sstevel@tonic-gate #define __SYSENTER(name) \ 750Sstevel@tonic-gate call 8f; \ 760Sstevel@tonic-gate 8: popl %edx; \ 770Sstevel@tonic-gate /* CSTYLED */ \ 780Sstevel@tonic-gate movl $SYS_/**/name, %eax; \ 790Sstevel@tonic-gate movl %esp, %ecx; \ 800Sstevel@tonic-gate add $[9f - 8b], %edx; \ 810Sstevel@tonic-gate sysenter; \ 820Sstevel@tonic-gate 9: 830Sstevel@tonic-gate 840Sstevel@tonic-gate /* 850Sstevel@tonic-gate * __SYSCALL provides a faster variant on processors and kernels 860Sstevel@tonic-gate * that support it. Note that %ecx is ALWAYS smashed. 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate #define __SYSCALL(name) \ 890Sstevel@tonic-gate /* CSTYLED */ \ 900Sstevel@tonic-gate movl $SYS_/**/name, %eax; \ 910Sstevel@tonic-gate .byte 0xf, 0x5 /* syscall */ 920Sstevel@tonic-gate 930Sstevel@tonic-gate #if defined(_SYSC_INSN) 940Sstevel@tonic-gate #define SYSTRAP_RVAL1(name) __SYSCALL(name) 950Sstevel@tonic-gate #define SYSTRAP_RVAL2(name) __SYSCALL(name) 960Sstevel@tonic-gate #define SYSTRAP_2RVALS(name) __SYSCALL(name) 970Sstevel@tonic-gate #define SYSTRAP_64RVAL(name) __SYSCALL(name) 980Sstevel@tonic-gate #else /* _SYSC_INSN */ 990Sstevel@tonic-gate #if defined(_SEP_INSN) 1000Sstevel@tonic-gate #define SYSTRAP_RVAL1(name) __SYSENTER(name) 1010Sstevel@tonic-gate #else /* _SEP_INSN */ 1020Sstevel@tonic-gate #define SYSTRAP_RVAL1(name) __SYSCALLINT(name) 1030Sstevel@tonic-gate #endif /* _SEP_INSN */ 1040Sstevel@tonic-gate #define SYSTRAP_RVAL2(name) __SYSCALLINT(name) 1050Sstevel@tonic-gate #define SYSTRAP_2RVALS(name) __SYSCALLINT(name) 1060Sstevel@tonic-gate #define SYSTRAP_64RVAL(name) __SYSCALLINT(name) 1070Sstevel@tonic-gate #endif /* _SYSC_INSN */ 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* 1100Sstevel@tonic-gate * SYSFASTTRAP provides the fast system call trap sequence. It assumes 1110Sstevel@tonic-gate * that an entry of the form T_name exists (probably from sys/trap.h). 1120Sstevel@tonic-gate */ 1130Sstevel@tonic-gate #define SYSFASTTRAP(name) \ 1140Sstevel@tonic-gate /* CSTYLED */ \ 1150Sstevel@tonic-gate movl $T_/**/name, %eax; \ 1160Sstevel@tonic-gate int $T_FASTTRAP 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate /* 1190Sstevel@tonic-gate * SYSCERROR provides the sequence to branch to __cerror if an error is 1200Sstevel@tonic-gate * indicated by the carry-bit being set upon return from a trap. 1210Sstevel@tonic-gate */ 1220Sstevel@tonic-gate #define SYSCERROR \ 1230Sstevel@tonic-gate jb __cerror 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate /* 1260Sstevel@tonic-gate * SYSCERROR64 provides the sequence to branch to __cerror64 if an error is 1270Sstevel@tonic-gate * indicated by the carry-bit being set upon return from a trap. 1280Sstevel@tonic-gate */ 1290Sstevel@tonic-gate #define SYSCERROR64 \ 1300Sstevel@tonic-gate jb __cerror64 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate /* 1330Sstevel@tonic-gate * SYSLWPERR provides the sequence to return 0 on a successful trap 1340Sstevel@tonic-gate * and the error code if unsuccessful. 1350Sstevel@tonic-gate * Error is indicated by the carry-bit being set upon return from a trap. 1360Sstevel@tonic-gate */ 1370Sstevel@tonic-gate #define SYSLWPERR \ 1380Sstevel@tonic-gate jae 1f; \ 1390Sstevel@tonic-gate cmpl $ERESTART, %eax; \ 1400Sstevel@tonic-gate jne 2f; \ 1410Sstevel@tonic-gate movl $EINTR, %eax; \ 1420Sstevel@tonic-gate jmp 2f; \ 1430Sstevel@tonic-gate 1: \ 1440Sstevel@tonic-gate xorl %eax, %eax; \ 1450Sstevel@tonic-gate 2: 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* 1480Sstevel@tonic-gate * SYSREENTRY provides the entry sequence for restartable system calls. 1490Sstevel@tonic-gate */ 1500Sstevel@tonic-gate #define SYSREENTRY(name) \ 1510Sstevel@tonic-gate /* CSTYLED */ \ 1520Sstevel@tonic-gate .restart_/**/name: \ 1530Sstevel@tonic-gate ENTRY(name) 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate /* 1560Sstevel@tonic-gate * SYSRESTART provides the error handling sequence for restartable 1570Sstevel@tonic-gate * system calls. 1580Sstevel@tonic-gate */ 1590Sstevel@tonic-gate #define SYSRESTART(name) \ 1600Sstevel@tonic-gate jae 1f; \ 1610Sstevel@tonic-gate cmpl $ERESTART, %eax; \ 1620Sstevel@tonic-gate je name; \ 1630Sstevel@tonic-gate jmp __cerror; \ 1640Sstevel@tonic-gate 1: 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate /* 1670Sstevel@tonic-gate * SYSINTR_RESTART provides the error handling sequence for restartable 1680Sstevel@tonic-gate * system calls in case of EINTR or ERESTART. 1690Sstevel@tonic-gate */ 1700Sstevel@tonic-gate #define SYSINTR_RESTART(name) \ 1710Sstevel@tonic-gate jae 1f; \ 1720Sstevel@tonic-gate cmpl $ERESTART, %eax; \ 1730Sstevel@tonic-gate je name; \ 1740Sstevel@tonic-gate cmpl $EINTR, %eax; \ 1750Sstevel@tonic-gate je name; \ 1760Sstevel@tonic-gate jmp 2f; \ 1770Sstevel@tonic-gate 1: \ 1780Sstevel@tonic-gate xorl %eax, %eax; \ 1790Sstevel@tonic-gate 2: 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate /* 1820Sstevel@tonic-gate * SYSCALL provides the standard (i.e.: most common) system call sequence. 1830Sstevel@tonic-gate */ 1840Sstevel@tonic-gate #define SYSCALL(name) \ 1850Sstevel@tonic-gate ENTRY(name); \ 1860Sstevel@tonic-gate SYSTRAP_2RVALS(name); \ 1870Sstevel@tonic-gate SYSCERROR 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate #define SYSCALL_RVAL1(name) \ 1900Sstevel@tonic-gate ENTRY(name); \ 1910Sstevel@tonic-gate SYSTRAP_RVAL1(name); \ 1920Sstevel@tonic-gate SYSCERROR 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate /* 1950Sstevel@tonic-gate * SYSCALL64 provides the standard (i.e.: most common) system call sequence 1960Sstevel@tonic-gate * for system calls that return 64-bit values. 1970Sstevel@tonic-gate */ 1980Sstevel@tonic-gate #define SYSCALL64(name) \ 1990Sstevel@tonic-gate ENTRY(name); \ 2000Sstevel@tonic-gate SYSTRAP_64RVAL(name); \ 2010Sstevel@tonic-gate SYSCERROR64 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate /* 2040Sstevel@tonic-gate * SYSCALL_RESTART provides the most common restartable system call sequence. 2050Sstevel@tonic-gate */ 2060Sstevel@tonic-gate #define SYSCALL_RESTART(name) \ 2070Sstevel@tonic-gate SYSREENTRY(name); \ 2080Sstevel@tonic-gate SYSTRAP_2RVALS(name); \ 2090Sstevel@tonic-gate /* CSTYLED */ \ 2100Sstevel@tonic-gate SYSRESTART(.restart_/**/name) 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate #define SYSCALL_RESTART_RVAL1(name) \ 2130Sstevel@tonic-gate SYSREENTRY(name); \ 2140Sstevel@tonic-gate SYSTRAP_RVAL1(name); \ 2150Sstevel@tonic-gate /* CSTYLED */ \ 2160Sstevel@tonic-gate SYSRESTART(.restart_/**/name) 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate /* 2190Sstevel@tonic-gate * SYSCALL2 provides a common system call sequence when the entry name 2200Sstevel@tonic-gate * is different than the trap name. 2210Sstevel@tonic-gate */ 2220Sstevel@tonic-gate #define SYSCALL2(entryname, trapname) \ 2230Sstevel@tonic-gate ENTRY(entryname); \ 2240Sstevel@tonic-gate SYSTRAP_2RVALS(trapname); \ 2250Sstevel@tonic-gate SYSCERROR 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate #define SYSCALL2_RVAL1(entryname, trapname) \ 2280Sstevel@tonic-gate ENTRY(entryname); \ 2290Sstevel@tonic-gate SYSTRAP_RVAL1(trapname); \ 2300Sstevel@tonic-gate SYSCERROR 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate /* 2330Sstevel@tonic-gate * SYSCALL2_RESTART provides a common restartable system call sequence when the 2340Sstevel@tonic-gate * entry name is different than the trap name. 2350Sstevel@tonic-gate */ 2360Sstevel@tonic-gate #define SYSCALL2_RESTART(entryname, trapname) \ 2370Sstevel@tonic-gate SYSREENTRY(entryname); \ 2380Sstevel@tonic-gate SYSTRAP_2RVALS(trapname); \ 2390Sstevel@tonic-gate /* CSTYLED */ \ 2400Sstevel@tonic-gate SYSRESTART(.restart_/**/entryname) 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate #define SYSCALL2_RESTART_RVAL1(entryname, trapname) \ 2430Sstevel@tonic-gate SYSREENTRY(entryname); \ 2440Sstevel@tonic-gate SYSTRAP_RVAL1(trapname); \ 2450Sstevel@tonic-gate /* CSTYLED */ \ 2460Sstevel@tonic-gate SYSRESTART(.restart_/**/entryname) 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate /* 2490Sstevel@tonic-gate * SYSCALL_NOERROR provides the most common system call sequence for those 2500Sstevel@tonic-gate * system calls which don't check the error return (carry bit). 2510Sstevel@tonic-gate */ 2520Sstevel@tonic-gate #define SYSCALL_NOERROR(name) \ 2530Sstevel@tonic-gate ENTRY(name); \ 2540Sstevel@tonic-gate SYSTRAP_2RVALS(name) 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate #define SYSCALL_NOERROR_RVAL1(name) \ 2570Sstevel@tonic-gate ENTRY(name); \ 2580Sstevel@tonic-gate SYSTRAP_RVAL1(name) 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate /* 2610Sstevel@tonic-gate * Standard syscall return sequence, return code equal to rval1. 2620Sstevel@tonic-gate */ 2630Sstevel@tonic-gate #define RET \ 2640Sstevel@tonic-gate ret 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate /* 2670Sstevel@tonic-gate * Syscall return sequence, return code equal to rval2. 2680Sstevel@tonic-gate */ 2690Sstevel@tonic-gate #define RET2 \ 2700Sstevel@tonic-gate movl %edx, %eax; \ 2710Sstevel@tonic-gate ret 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate /* 2740Sstevel@tonic-gate * Syscall return sequence with return code forced to zero. 2750Sstevel@tonic-gate */ 2760Sstevel@tonic-gate #define RETC \ 2770Sstevel@tonic-gate xorl %eax, %eax; \ 2780Sstevel@tonic-gate ret 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate #endif /* _LIBC_I386_INC_SYS_H */ 281