4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _LIBC_I386_INC_SYS_H
28 #define _LIBC_I386_INC_SYS_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 * This file defines common code sequences for system calls.
35 #include <sys/asm_linkage.h>
36 #include <sys/syscall.h>
37 #include <sys/errno.h>
44 addl $_GLOBAL_OFFSET_TABLE_ + [. - 9b], %ebx
49 #define _fref_(name) name@PLT
50 #define _daref_(name) name@GOT(%ebx)
51 #define _sref_(name) name@GOTOFF(%ebx)
52 #define _esp_(offset) offset+4(%esp) /* add 4 for the saved %ebx */
55 * Define the external symbols __cerror and __cerror64 for all files.
61 * __SYSCALLINT provides the basic trap sequence. It assumes that an entry
62 * of the form SYS_name exists (probably from sys/syscall.h).
65 #define __SYSCALLINT(name) \
67 movl $SYS_##name, %eax; \
71 * __SYSENTER provides a faster variant that is only able to
72 * return rval1. Note that %ecx and %edx are ALWAYS smashed.
74 #define __SYSENTER(name) \
78 movl $SYS_##name, %eax; \
80 add $[9f - 8b], %edx; \
85 * __SYSCALL provides a faster variant on processors and kernels
86 * that support it. Note that %ecx is ALWAYS smashed.
88 #define __SYSCALL(name) \
90 movl $SYS_##name, %eax; \
91 .byte 0xf, 0x5 /* syscall */
93 #if defined(_SYSC_INSN)
94 #define SYSTRAP_RVAL1(name) __SYSCALL(name)
95 #define SYSTRAP_RVAL2(name) __SYSCALL(name)
96 #define SYSTRAP_2RVALS(name) __SYSCALL(name)
97 #define SYSTRAP_64RVAL(name) __SYSCALL(name)
98 #else /* _SYSC_INSN */
99 #if defined(_SEP_INSN)
100 #define SYSTRAP_RVAL1(name) __SYSENTER(name)
101 #else /* _SEP_INSN */
102 #define SYSTRAP_RVAL1(name) __SYSCALLINT(name)
103 #endif /* _SEP_INSN */
104 #define SYSTRAP_RVAL2(name) __SYSCALLINT(name)
105 #define SYSTRAP_2RVALS(name) __SYSCALLINT(name)
106 #define SYSTRAP_64RVAL(name) __SYSCALLINT(name)
107 #endif /* _SYSC_INSN */
110 * SYSFASTTRAP provides the fast system call trap sequence. It assumes
111 * that an entry of the form T_name exists (probably from sys/trap.h).
113 #define SYSFASTTRAP(name) \
115 movl $T_##name, %eax; \
119 * SYSCERROR provides the sequence to branch to __cerror if an error is
120 * indicated by the carry-bit being set upon return from a trap.
126 * SYSCERROR64 provides the sequence to branch to __cerror64 if an error is
127 * indicated by the carry-bit being set upon return from a trap.
129 #define SYSCERROR64 \
133 * SYSLWPERR provides the sequence to return 0 on a successful trap
134 * and the error code if unsuccessful.
135 * Error is indicated by the carry-bit being set upon return from a trap.
139 cmpl $ERESTART, %eax; \
148 * SYSREENTRY provides the entry sequence for restartable system calls.
150 #define SYSREENTRY(name) \
156 * SYSRESTART provides the error handling sequence for restartable
159 #define SYSRESTART(name) \
161 cmpl $ERESTART, %eax; \
167 * SYSINTR_RESTART provides the error handling sequence for restartable
168 * system calls in case of EINTR or ERESTART.
170 #define SYSINTR_RESTART(name) \
172 cmpl $ERESTART, %eax; \
182 * SYSCALL provides the standard (i.e.: most common) system call sequence.
184 #define SYSCALL(name) \
186 SYSTRAP_2RVALS(name); \
189 #define SYSCALL_RVAL1(name) \
191 SYSTRAP_RVAL1(name); \
195 * SYSCALL64 provides the standard (i.e.: most common) system call sequence
196 * for system calls that return 64-bit values.
198 #define SYSCALL64(name) \
200 SYSTRAP_64RVAL(name); \
204 * SYSCALL_RESTART provides the most common restartable system call sequence.
206 #define SYSCALL_RESTART(name) \
208 SYSTRAP_2RVALS(name); \
210 SYSRESTART(.restart_##name)
212 #define SYSCALL_RESTART_RVAL1(name) \
214 SYSTRAP_RVAL1(name); \
216 SYSRESTART(.restart_##name)
219 * SYSCALL2 provides a common system call sequence when the entry name
220 * is different than the trap name.
222 #define SYSCALL2(entryname, trapname) \
224 SYSTRAP_2RVALS(trapname); \
227 #define SYSCALL2_RVAL1(entryname, trapname) \
229 SYSTRAP_RVAL1(trapname); \
233 * SYSCALL2_RESTART provides a common restartable system call sequence when the
234 * entry name is different than the trap name.
236 #define SYSCALL2_RESTART(entryname, trapname) \
237 SYSREENTRY(entryname); \
238 SYSTRAP_2RVALS(trapname); \
240 SYSRESTART(.restart_##entryname)
242 #define SYSCALL2_RESTART_RVAL1(entryname, trapname) \
243 SYSREENTRY(entryname); \
244 SYSTRAP_RVAL1(trapname); \
246 SYSRESTART(.restart_##entryname)
249 * SYSCALL_NOERROR provides the most common system call sequence for those
250 * system calls which don't check the error return (carry bit).
252 #define SYSCALL_NOERROR(name) \
256 #define SYSCALL_NOERROR_RVAL1(name) \
261 * Standard syscall return sequence, return code equal to rval1.
267 * Syscall return sequence, return code equal to rval2.
274 * Syscall return sequence with return code forced to zero.
280 #endif /* _LIBC_I386_INC_SYS_H */