17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57257d1b4Sraf * Common Development and Distribution License (the "License"). 67257d1b4Sraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217257d1b4Sraf 227c478bd9Sstevel@tonic-gate /* 237257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _LIBC_I386_INC_SYS_H 287c478bd9Sstevel@tonic-gate #define _LIBC_I386_INC_SYS_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate /* 317c478bd9Sstevel@tonic-gate * This file defines common code sequences for system calls. 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate #include <sys/asm_linkage.h> 347c478bd9Sstevel@tonic-gate #include <sys/syscall.h> 357c478bd9Sstevel@tonic-gate #include <sys/errno.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #define _prologue_ \ 387c478bd9Sstevel@tonic-gate pushl %ebx; \ 397c478bd9Sstevel@tonic-gate call 9f; \ 407c478bd9Sstevel@tonic-gate 9: \ 417c478bd9Sstevel@tonic-gate popl %ebx; \ 427c478bd9Sstevel@tonic-gate addl $_GLOBAL_OFFSET_TABLE_ + [. - 9b], %ebx 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #define _epilogue_ \ 457c478bd9Sstevel@tonic-gate popl %ebx 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #define _fref_(name) name@PLT 487c478bd9Sstevel@tonic-gate #define _daref_(name) name@GOT(%ebx) 497c478bd9Sstevel@tonic-gate #define _sref_(name) name@GOTOFF(%ebx) 507c478bd9Sstevel@tonic-gate #define _esp_(offset) offset+4(%esp) /* add 4 for the saved %ebx */ 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * Define the external symbols __cerror and __cerror64 for all files. 547c478bd9Sstevel@tonic-gate */ 557c478bd9Sstevel@tonic-gate .globl __cerror 567c478bd9Sstevel@tonic-gate .globl __cerror64 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * __SYSCALLINT provides the basic trap sequence. It assumes that an entry 607c478bd9Sstevel@tonic-gate * of the form SYS_name exists (probably from sys/syscall.h). 617c478bd9Sstevel@tonic-gate */ 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate #define __SYSCALLINT(name) \ 647c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 65*5d9d9091SRichard Lowe movl $SYS_##name, %eax; \ 667c478bd9Sstevel@tonic-gate int $T_SYSCALLINT 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * __SYSENTER provides a faster variant that is only able to 707c478bd9Sstevel@tonic-gate * return rval1. Note that %ecx and %edx are ALWAYS smashed. 717c478bd9Sstevel@tonic-gate */ 727c478bd9Sstevel@tonic-gate #define __SYSENTER(name) \ 737c478bd9Sstevel@tonic-gate call 8f; \ 747c478bd9Sstevel@tonic-gate 8: popl %edx; \ 757c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 76*5d9d9091SRichard Lowe movl $SYS_##name, %eax; \ 777c478bd9Sstevel@tonic-gate movl %esp, %ecx; \ 787c478bd9Sstevel@tonic-gate add $[9f - 8b], %edx; \ 797c478bd9Sstevel@tonic-gate sysenter; \ 807c478bd9Sstevel@tonic-gate 9: 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate /* 837c478bd9Sstevel@tonic-gate * __SYSCALL provides a faster variant on processors and kernels 847c478bd9Sstevel@tonic-gate * that support it. Note that %ecx is ALWAYS smashed. 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate #define __SYSCALL(name) \ 877c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 88*5d9d9091SRichard Lowe movl $SYS_##name, %eax; \ 897c478bd9Sstevel@tonic-gate .byte 0xf, 0x5 /* syscall */ 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate #if defined(_SYSC_INSN) 927c478bd9Sstevel@tonic-gate #define SYSTRAP_RVAL1(name) __SYSCALL(name) 937c478bd9Sstevel@tonic-gate #define SYSTRAP_RVAL2(name) __SYSCALL(name) 947c478bd9Sstevel@tonic-gate #define SYSTRAP_2RVALS(name) __SYSCALL(name) 957c478bd9Sstevel@tonic-gate #define SYSTRAP_64RVAL(name) __SYSCALL(name) 967c478bd9Sstevel@tonic-gate #else /* _SYSC_INSN */ 977c478bd9Sstevel@tonic-gate #if defined(_SEP_INSN) 987c478bd9Sstevel@tonic-gate #define SYSTRAP_RVAL1(name) __SYSENTER(name) 997c478bd9Sstevel@tonic-gate #else /* _SEP_INSN */ 1007c478bd9Sstevel@tonic-gate #define SYSTRAP_RVAL1(name) __SYSCALLINT(name) 1017c478bd9Sstevel@tonic-gate #endif /* _SEP_INSN */ 1027c478bd9Sstevel@tonic-gate #define SYSTRAP_RVAL2(name) __SYSCALLINT(name) 1037c478bd9Sstevel@tonic-gate #define SYSTRAP_2RVALS(name) __SYSCALLINT(name) 1047c478bd9Sstevel@tonic-gate #define SYSTRAP_64RVAL(name) __SYSCALLINT(name) 1057c478bd9Sstevel@tonic-gate #endif /* _SYSC_INSN */ 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* 1087c478bd9Sstevel@tonic-gate * SYSFASTTRAP provides the fast system call trap sequence. It assumes 1097c478bd9Sstevel@tonic-gate * that an entry of the form T_name exists (probably from sys/trap.h). 1107c478bd9Sstevel@tonic-gate */ 1117c478bd9Sstevel@tonic-gate #define SYSFASTTRAP(name) \ 1127c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 113*5d9d9091SRichard Lowe movl $T_##name, %eax; \ 1147c478bd9Sstevel@tonic-gate int $T_FASTTRAP 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate /* 1177c478bd9Sstevel@tonic-gate * SYSCERROR provides the sequence to branch to __cerror if an error is 1187c478bd9Sstevel@tonic-gate * indicated by the carry-bit being set upon return from a trap. 1197c478bd9Sstevel@tonic-gate */ 1207c478bd9Sstevel@tonic-gate #define SYSCERROR \ 1217c478bd9Sstevel@tonic-gate jb __cerror 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* 1247c478bd9Sstevel@tonic-gate * SYSCERROR64 provides the sequence to branch to __cerror64 if an error is 1257c478bd9Sstevel@tonic-gate * indicated by the carry-bit being set upon return from a trap. 1267c478bd9Sstevel@tonic-gate */ 1277c478bd9Sstevel@tonic-gate #define SYSCERROR64 \ 1287c478bd9Sstevel@tonic-gate jb __cerror64 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate /* 1317c478bd9Sstevel@tonic-gate * SYSLWPERR provides the sequence to return 0 on a successful trap 1327c478bd9Sstevel@tonic-gate * and the error code if unsuccessful. 1337c478bd9Sstevel@tonic-gate * Error is indicated by the carry-bit being set upon return from a trap. 1347c478bd9Sstevel@tonic-gate */ 1357c478bd9Sstevel@tonic-gate #define SYSLWPERR \ 1367c478bd9Sstevel@tonic-gate jae 1f; \ 1377c478bd9Sstevel@tonic-gate cmpl $ERESTART, %eax; \ 1387c478bd9Sstevel@tonic-gate jne 2f; \ 1397c478bd9Sstevel@tonic-gate movl $EINTR, %eax; \ 1407c478bd9Sstevel@tonic-gate jmp 2f; \ 1417c478bd9Sstevel@tonic-gate 1: \ 1427c478bd9Sstevel@tonic-gate xorl %eax, %eax; \ 1437c478bd9Sstevel@tonic-gate 2: 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * SYSREENTRY provides the entry sequence for restartable system calls. 1477c478bd9Sstevel@tonic-gate */ 1487c478bd9Sstevel@tonic-gate #define SYSREENTRY(name) \ 1497c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 150*5d9d9091SRichard Lowe .restart_##name: \ 1517c478bd9Sstevel@tonic-gate ENTRY(name) 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate /* 1547c478bd9Sstevel@tonic-gate * SYSRESTART provides the error handling sequence for restartable 1557c478bd9Sstevel@tonic-gate * system calls. 1567c478bd9Sstevel@tonic-gate */ 1577c478bd9Sstevel@tonic-gate #define SYSRESTART(name) \ 1587c478bd9Sstevel@tonic-gate jae 1f; \ 1597c478bd9Sstevel@tonic-gate cmpl $ERESTART, %eax; \ 1607c478bd9Sstevel@tonic-gate je name; \ 1617c478bd9Sstevel@tonic-gate jmp __cerror; \ 1627c478bd9Sstevel@tonic-gate 1: 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate /* 1657c478bd9Sstevel@tonic-gate * SYSINTR_RESTART provides the error handling sequence for restartable 1667c478bd9Sstevel@tonic-gate * system calls in case of EINTR or ERESTART. 1677c478bd9Sstevel@tonic-gate */ 1687c478bd9Sstevel@tonic-gate #define SYSINTR_RESTART(name) \ 1697c478bd9Sstevel@tonic-gate jae 1f; \ 1707c478bd9Sstevel@tonic-gate cmpl $ERESTART, %eax; \ 1717c478bd9Sstevel@tonic-gate je name; \ 1727c478bd9Sstevel@tonic-gate cmpl $EINTR, %eax; \ 1737c478bd9Sstevel@tonic-gate je name; \ 1747c478bd9Sstevel@tonic-gate jmp 2f; \ 1757c478bd9Sstevel@tonic-gate 1: \ 1767c478bd9Sstevel@tonic-gate xorl %eax, %eax; \ 1777c478bd9Sstevel@tonic-gate 2: 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate /* 1807c478bd9Sstevel@tonic-gate * SYSCALL provides the standard (i.e.: most common) system call sequence. 1817c478bd9Sstevel@tonic-gate */ 1827c478bd9Sstevel@tonic-gate #define SYSCALL(name) \ 1837c478bd9Sstevel@tonic-gate ENTRY(name); \ 1847c478bd9Sstevel@tonic-gate SYSTRAP_2RVALS(name); \ 1857c478bd9Sstevel@tonic-gate SYSCERROR 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate #define SYSCALL_RVAL1(name) \ 1887c478bd9Sstevel@tonic-gate ENTRY(name); \ 1897c478bd9Sstevel@tonic-gate SYSTRAP_RVAL1(name); \ 1907c478bd9Sstevel@tonic-gate SYSCERROR 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate /* 1937c478bd9Sstevel@tonic-gate * SYSCALL64 provides the standard (i.e.: most common) system call sequence 1947c478bd9Sstevel@tonic-gate * for system calls that return 64-bit values. 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate #define SYSCALL64(name) \ 1977c478bd9Sstevel@tonic-gate ENTRY(name); \ 1987c478bd9Sstevel@tonic-gate SYSTRAP_64RVAL(name); \ 1997c478bd9Sstevel@tonic-gate SYSCERROR64 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate /* 2027c478bd9Sstevel@tonic-gate * SYSCALL_RESTART provides the most common restartable system call sequence. 2037c478bd9Sstevel@tonic-gate */ 2047c478bd9Sstevel@tonic-gate #define SYSCALL_RESTART(name) \ 2057c478bd9Sstevel@tonic-gate SYSREENTRY(name); \ 2067c478bd9Sstevel@tonic-gate SYSTRAP_2RVALS(name); \ 2077c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 208*5d9d9091SRichard Lowe SYSRESTART(.restart_##name) 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate #define SYSCALL_RESTART_RVAL1(name) \ 2117c478bd9Sstevel@tonic-gate SYSREENTRY(name); \ 2127c478bd9Sstevel@tonic-gate SYSTRAP_RVAL1(name); \ 2137c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 214*5d9d9091SRichard Lowe SYSRESTART(.restart_##name) 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate /* 2177c478bd9Sstevel@tonic-gate * SYSCALL2 provides a common system call sequence when the entry name 2187c478bd9Sstevel@tonic-gate * is different than the trap name. 2197c478bd9Sstevel@tonic-gate */ 2207c478bd9Sstevel@tonic-gate #define SYSCALL2(entryname, trapname) \ 2217c478bd9Sstevel@tonic-gate ENTRY(entryname); \ 2227c478bd9Sstevel@tonic-gate SYSTRAP_2RVALS(trapname); \ 2237c478bd9Sstevel@tonic-gate SYSCERROR 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate #define SYSCALL2_RVAL1(entryname, trapname) \ 2267c478bd9Sstevel@tonic-gate ENTRY(entryname); \ 2277c478bd9Sstevel@tonic-gate SYSTRAP_RVAL1(trapname); \ 2287c478bd9Sstevel@tonic-gate SYSCERROR 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate /* 2317c478bd9Sstevel@tonic-gate * SYSCALL2_RESTART provides a common restartable system call sequence when the 2327c478bd9Sstevel@tonic-gate * entry name is different than the trap name. 2337c478bd9Sstevel@tonic-gate */ 2347c478bd9Sstevel@tonic-gate #define SYSCALL2_RESTART(entryname, trapname) \ 2357c478bd9Sstevel@tonic-gate SYSREENTRY(entryname); \ 2367c478bd9Sstevel@tonic-gate SYSTRAP_2RVALS(trapname); \ 2377c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 238*5d9d9091SRichard Lowe SYSRESTART(.restart_##entryname) 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate #define SYSCALL2_RESTART_RVAL1(entryname, trapname) \ 2417c478bd9Sstevel@tonic-gate SYSREENTRY(entryname); \ 2427c478bd9Sstevel@tonic-gate SYSTRAP_RVAL1(trapname); \ 2437c478bd9Sstevel@tonic-gate /* CSTYLED */ \ 244*5d9d9091SRichard Lowe SYSRESTART(.restart_##entryname) 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate /* 2477c478bd9Sstevel@tonic-gate * SYSCALL_NOERROR provides the most common system call sequence for those 2487c478bd9Sstevel@tonic-gate * system calls which don't check the error return (carry bit). 2497c478bd9Sstevel@tonic-gate */ 2507c478bd9Sstevel@tonic-gate #define SYSCALL_NOERROR(name) \ 2517c478bd9Sstevel@tonic-gate ENTRY(name); \ 2527c478bd9Sstevel@tonic-gate SYSTRAP_2RVALS(name) 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate #define SYSCALL_NOERROR_RVAL1(name) \ 2557c478bd9Sstevel@tonic-gate ENTRY(name); \ 2567c478bd9Sstevel@tonic-gate SYSTRAP_RVAL1(name) 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate /* 2597c478bd9Sstevel@tonic-gate * Standard syscall return sequence, return code equal to rval1. 2607c478bd9Sstevel@tonic-gate */ 2617c478bd9Sstevel@tonic-gate #define RET \ 2627c478bd9Sstevel@tonic-gate ret 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate /* 2657c478bd9Sstevel@tonic-gate * Syscall return sequence, return code equal to rval2. 2667c478bd9Sstevel@tonic-gate */ 2677c478bd9Sstevel@tonic-gate #define RET2 \ 2687c478bd9Sstevel@tonic-gate movl %edx, %eax; \ 2697c478bd9Sstevel@tonic-gate ret 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate /* 2727c478bd9Sstevel@tonic-gate * Syscall return sequence with return code forced to zero. 2737c478bd9Sstevel@tonic-gate */ 2747c478bd9Sstevel@tonic-gate #define RETC \ 2757c478bd9Sstevel@tonic-gate xorl %eax, %eax; \ 2767c478bd9Sstevel@tonic-gate ret 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate #endif /* _LIBC_I386_INC_SYS_H */ 279