dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libc / i386 / inc / SYS.h
blob4e23328a60a2ac3a1753aa946f914aa7713f6da0
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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>
39 #define _prologue_ \
40 pushl %ebx; \
41 call 9f; \
42 9: \
43 popl %ebx; \
44 addl $_GLOBAL_OFFSET_TABLE_ + [. - 9b], %ebx
46 #define _epilogue_ \
47 popl %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.
57 .globl __cerror
58 .globl __cerror64
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) \
66 /* CSTYLED */ \
67 movl $SYS_##name, %eax; \
68 int $T_SYSCALLINT
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) \
75 call 8f; \
76 8: popl %edx; \
77 /* CSTYLED */ \
78 movl $SYS_##name, %eax; \
79 movl %esp, %ecx; \
80 add $[9f - 8b], %edx; \
81 sysenter; \
85 * __SYSCALL provides a faster variant on processors and kernels
86 * that support it. Note that %ecx is ALWAYS smashed.
88 #define __SYSCALL(name) \
89 /* CSTYLED */ \
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) \
114 /* CSTYLED */ \
115 movl $T_##name, %eax; \
116 int $T_FASTTRAP
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.
122 #define SYSCERROR \
123 jb __cerror
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 \
130 jb __cerror64
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.
137 #define SYSLWPERR \
138 jae 1f; \
139 cmpl $ERESTART, %eax; \
140 jne 2f; \
141 movl $EINTR, %eax; \
142 jmp 2f; \
143 1: \
144 xorl %eax, %eax; \
148 * SYSREENTRY provides the entry sequence for restartable system calls.
150 #define SYSREENTRY(name) \
151 /* CSTYLED */ \
152 .restart_##name: \
153 ENTRY(name)
156 * SYSRESTART provides the error handling sequence for restartable
157 * system calls.
159 #define SYSRESTART(name) \
160 jae 1f; \
161 cmpl $ERESTART, %eax; \
162 je name; \
163 jmp __cerror; \
167 * SYSINTR_RESTART provides the error handling sequence for restartable
168 * system calls in case of EINTR or ERESTART.
170 #define SYSINTR_RESTART(name) \
171 jae 1f; \
172 cmpl $ERESTART, %eax; \
173 je name; \
174 cmpl $EINTR, %eax; \
175 je name; \
176 jmp 2f; \
177 1: \
178 xorl %eax, %eax; \
182 * SYSCALL provides the standard (i.e.: most common) system call sequence.
184 #define SYSCALL(name) \
185 ENTRY(name); \
186 SYSTRAP_2RVALS(name); \
187 SYSCERROR
189 #define SYSCALL_RVAL1(name) \
190 ENTRY(name); \
191 SYSTRAP_RVAL1(name); \
192 SYSCERROR
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) \
199 ENTRY(name); \
200 SYSTRAP_64RVAL(name); \
201 SYSCERROR64
204 * SYSCALL_RESTART provides the most common restartable system call sequence.
206 #define SYSCALL_RESTART(name) \
207 SYSREENTRY(name); \
208 SYSTRAP_2RVALS(name); \
209 /* CSTYLED */ \
210 SYSRESTART(.restart_##name)
212 #define SYSCALL_RESTART_RVAL1(name) \
213 SYSREENTRY(name); \
214 SYSTRAP_RVAL1(name); \
215 /* CSTYLED */ \
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) \
223 ENTRY(entryname); \
224 SYSTRAP_2RVALS(trapname); \
225 SYSCERROR
227 #define SYSCALL2_RVAL1(entryname, trapname) \
228 ENTRY(entryname); \
229 SYSTRAP_RVAL1(trapname); \
230 SYSCERROR
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); \
239 /* CSTYLED */ \
240 SYSRESTART(.restart_##entryname)
242 #define SYSCALL2_RESTART_RVAL1(entryname, trapname) \
243 SYSREENTRY(entryname); \
244 SYSTRAP_RVAL1(trapname); \
245 /* CSTYLED */ \
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) \
253 ENTRY(name); \
254 SYSTRAP_2RVALS(name)
256 #define SYSCALL_NOERROR_RVAL1(name) \
257 ENTRY(name); \
258 SYSTRAP_RVAL1(name)
261 * Standard syscall return sequence, return code equal to rval1.
263 #define RET \
267 * Syscall return sequence, return code equal to rval2.
269 #define RET2 \
270 movl %edx, %eax; \
274 * Syscall return sequence with return code forced to zero.
276 #define RETC \
277 xorl %eax, %eax; \
280 #endif /* _LIBC_I386_INC_SYS_H */