xref: /titanic_41/usr/src/lib/libc/i386/inc/SYS.h (revision 51b564aca190d2a430104dded1983d3a1fff66e2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_LIBC_I386_INC_SYS_H
28 #define	_LIBC_I386_INC_SYS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * This file defines common code sequences for system calls.
34  */
35 #include <sys/asm_linkage.h>
36 #include <sys/syscall.h>
37 #include <sys/trap.h>
38 #include <sys/errno.h>
39 #include "synonyms.h"
40 
41 #define	_prologue_			\
42 	pushl	%ebx;			\
43 	call	9f;			\
44 9:					\
45 	popl	%ebx;			\
46 	addl	$_GLOBAL_OFFSET_TABLE_ + [. - 9b], %ebx
47 
48 #define	_epilogue_			\
49 	popl	%ebx
50 
51 #define	_fref_(name)	name@PLT
52 #define	_daref_(name)	name@GOT(%ebx)
53 #define	_sref_(name)	name@GOTOFF(%ebx)
54 #define	_esp_(offset)	offset+4(%esp)	/* add 4 for the saved %ebx */
55 
56 /*
57  * Define the external symbols __cerror and __cerror64 for all files.
58  */
59 	.globl	__cerror
60 	.globl	__cerror64
61 
62 /*
63  * __SYSCALLINT provides the basic trap sequence.  It assumes that an entry
64  * of the form SYS_name exists (probably from sys/syscall.h).
65  */
66 
67 #define	__SYSCALLINT(name)		\
68 	/* CSTYLED */			\
69 	movl	$SYS_/**/name, %eax;	\
70 	int	$T_SYSCALLINT
71 
72 /*
73  * __SYSENTER provides a faster variant that is only able to
74  * return rval1.  Note that %ecx and %edx are ALWAYS smashed.
75  */
76 #define	__SYSENTER(name)		\
77 	call	8f;			\
78 8:	popl	%edx;			\
79 	/* CSTYLED */			\
80 	movl	$SYS_/**/name, %eax;	\
81 	movl	%esp, %ecx;		\
82 	add	$[9f - 8b], %edx;	\
83 	sysenter;			\
84 9:
85 
86 /*
87  * __SYSCALL provides a faster variant on processors and kernels
88  * that support it.  Note that %ecx is ALWAYS smashed.
89  */
90 #define	__SYSCALL(name)			\
91 	/* CSTYLED */			\
92 	movl	$SYS_/**/name, %eax;	\
93 	.byte	0xf, 0x5	/* syscall */
94 
95 #if defined(_SYSC_INSN)
96 #define	SYSTRAP_RVAL1(name)	__SYSCALL(name)
97 #define	SYSTRAP_RVAL2(name)	__SYSCALL(name)
98 #define	SYSTRAP_2RVALS(name)	__SYSCALL(name)
99 #define	SYSTRAP_64RVAL(name)	__SYSCALL(name)
100 #else	/* _SYSC_INSN */
101 #if defined(_SEP_INSN)
102 #define	SYSTRAP_RVAL1(name)	__SYSENTER(name)
103 #else	/* _SEP_INSN */
104 #define	SYSTRAP_RVAL1(name)	__SYSCALLINT(name)
105 #endif	/* _SEP_INSN */
106 #define	SYSTRAP_RVAL2(name)	__SYSCALLINT(name)
107 #define	SYSTRAP_2RVALS(name)	__SYSCALLINT(name)
108 #define	SYSTRAP_64RVAL(name)	__SYSCALLINT(name)
109 #endif	/* _SYSC_INSN */
110 
111 /*
112  * SYSFASTTRAP provides the fast system call trap sequence.  It assumes
113  * that an entry of the form T_name exists (probably from sys/trap.h).
114  */
115 #define	SYSFASTTRAP(name)		\
116 	/* CSTYLED */			\
117 	movl	$T_/**/name, %eax;	\
118 	int	$T_FASTTRAP
119 
120 /*
121  * SYSCERROR provides the sequence to branch to __cerror if an error is
122  * indicated by the carry-bit being set upon return from a trap.
123  */
124 #define	SYSCERROR		\
125 	jb	__cerror
126 
127 /*
128  * SYSCERROR64 provides the sequence to branch to __cerror64 if an error is
129  * indicated by the carry-bit being set upon return from a trap.
130  */
131 #define	SYSCERROR64		\
132 	jb	__cerror64
133 
134 /*
135  * SYSLWPERR provides the sequence to return 0 on a successful trap
136  * and the error code if unsuccessful.
137  * Error is indicated by the carry-bit being set upon return from a trap.
138  */
139 #define	SYSLWPERR			\
140 	jae	1f;			\
141 	cmpl	$ERESTART, %eax;	\
142 	jne	2f;			\
143 	movl	$EINTR, %eax;		\
144 	jmp	2f;			\
145 1:					\
146 	xorl	%eax, %eax;		\
147 2:
148 
149 /*
150  * SYSREENTRY provides the entry sequence for restartable system calls.
151  */
152 #define	SYSREENTRY(name)	\
153 /* CSTYLED */			\
154 .restart_/**/name:		\
155 	ENTRY(name)
156 
157 /*
158  * SYSRESTART provides the error handling sequence for restartable
159  * system calls.
160  */
161 #define	SYSRESTART(name)		\
162 	jae	1f;			\
163 	cmpl	$ERESTART, %eax;	\
164 	je	name;			\
165 	jmp	__cerror;		\
166 1:
167 
168 /*
169  * SYSINTR_RESTART provides the error handling sequence for restartable
170  * system calls in case of EINTR or ERESTART.
171  */
172 #define	SYSINTR_RESTART(name)		\
173 	jae	1f;			\
174 	cmpl	$ERESTART, %eax;	\
175 	je	name;			\
176 	cmpl	$EINTR, %eax;		\
177 	je	name;			\
178 	jmp	2f;			\
179 1:					\
180 	xorl	%eax, %eax;		\
181 2:
182 
183 /*
184  * SYSCALL provides the standard (i.e.: most common) system call sequence.
185  */
186 #define	SYSCALL(name)		\
187 	ENTRY(name);		\
188 	SYSTRAP_2RVALS(name);	\
189 	SYSCERROR
190 
191 #define	SYSCALL_RVAL1(name)	\
192 	ENTRY(name);		\
193 	SYSTRAP_RVAL1(name);	\
194 	SYSCERROR
195 
196 /*
197  * SYSCALL64 provides the standard (i.e.: most common) system call sequence
198  * for system calls that return 64-bit values.
199  */
200 #define	SYSCALL64(name)		\
201 	ENTRY(name);		\
202 	SYSTRAP_64RVAL(name);	\
203 	SYSCERROR64
204 
205 /*
206  * SYSCALL_RESTART provides the most common restartable system call sequence.
207  */
208 #define	SYSCALL_RESTART(name)	\
209 	SYSREENTRY(name);	\
210 	SYSTRAP_2RVALS(name);	\
211 	/* CSTYLED */		\
212 	SYSRESTART(.restart_/**/name)
213 
214 #define	SYSCALL_RESTART_RVAL1(name)	\
215 	SYSREENTRY(name);		\
216 	SYSTRAP_RVAL1(name);		\
217 	/* CSTYLED */			\
218 	SYSRESTART(.restart_/**/name)
219 
220 /*
221  * SYSCALL2 provides a common system call sequence when the entry name
222  * is different than the trap name.
223  */
224 #define	SYSCALL2(entryname, trapname)	\
225 	ENTRY(entryname);		\
226 	SYSTRAP_2RVALS(trapname);	\
227 	SYSCERROR
228 
229 #define	SYSCALL2_RVAL1(entryname, trapname)	\
230 	ENTRY(entryname);			\
231 	SYSTRAP_RVAL1(trapname);		\
232 	SYSCERROR
233 
234 /*
235  * SYSCALL2_RESTART provides a common restartable system call sequence when the
236  * entry name is different than the trap name.
237  */
238 #define	SYSCALL2_RESTART(entryname, trapname)	\
239 	SYSREENTRY(entryname);			\
240 	SYSTRAP_2RVALS(trapname);		\
241 	/* CSTYLED */				\
242 	SYSRESTART(.restart_/**/entryname)
243 
244 #define	SYSCALL2_RESTART_RVAL1(entryname, trapname)	\
245 	SYSREENTRY(entryname);				\
246 	SYSTRAP_RVAL1(trapname);			\
247 	/* CSTYLED */					\
248 	SYSRESTART(.restart_/**/entryname)
249 
250 /*
251  * SYSCALL_NOERROR provides the most common system call sequence for those
252  * system calls which don't check the error return (carry bit).
253  */
254 #define	SYSCALL_NOERROR(name)	\
255 	ENTRY(name);		\
256 	SYSTRAP_2RVALS(name)
257 
258 #define	SYSCALL_NOERROR_RVAL1(name)	\
259 	ENTRY(name);			\
260 	SYSTRAP_RVAL1(name)
261 
262 /*
263  * Standard syscall return sequence, return code equal to rval1.
264  */
265 #define	RET			\
266 	ret
267 
268 /*
269  * Syscall return sequence, return code equal to rval2.
270  */
271 #define	RET2			\
272 	movl	%edx, %eax;	\
273 	ret
274 
275 /*
276  * Syscall return sequence with return code forced to zero.
277  */
278 #define	RETC			\
279 	xorl	%eax, %eax;	\
280 	ret
281 
282 #endif	/* _LIBC_I386_INC_SYS_H */
283