import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / amd64 / inc / SYS.h
blob686b41e53179f981a19f2b7f2fd53ada34243009
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_AMD64_INC_SYS_H
28 #define _LIBC_AMD64_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 _fref_(name) name@PLT
40 #define _daref_(name) name@GOTPCREL(%rip)
41 #define _sref_(name) name(%rip)
44 * Define the external symbol __cerror for all files.
46 .globl __cerror
49 * __SYSCALL provides the basic trap sequence. It assumes that
50 * an entry of the form SYS_name exists (from sys/syscall.h).
51 * Note that %rcx is smashed by the syscall instruction,
52 * so we move it to %r10 in order to pass it to the kernel.
54 #define __SYSCALL(name) \
55 movq %rcx, %r10; \
56 /* CSTYLED */ \
57 movl $SYS_##name, %eax; \
58 syscall
60 #define SYSTRAP_RVAL1(name) __SYSCALL(name)
61 #define SYSTRAP_RVAL2(name) __SYSCALL(name)
62 #define SYSTRAP_2RVALS(name) __SYSCALL(name)
63 #define SYSTRAP_64RVAL(name) __SYSCALL(name)
66 * SYSFASTTRAP provides the fast system call trap sequence. It assumes
67 * that an entry of the form T_name exists (probably from sys/trap.h).
69 #define SYSFASTTRAP(name) \
70 /* CSTYLED */ \
71 movl $T_##name, %eax; \
72 int $T_FASTTRAP
75 * SYSCERROR provides the sequence to branch to __cerror if an error is
76 * indicated by the carry-bit being set upon return from a trap.
78 #define SYSCERROR \
79 jb __cerror
82 * SYSLWPERR provides the sequence to return 0 on a successful trap
83 * and the error code if unsuccessful.
84 * Error is indicated by the carry-bit being set upon return from a trap.
86 #define SYSLWPERR \
87 jae 1f; \
88 cmpl $ERESTART, %eax; \
89 jne 2f; \
90 movl $EINTR, %eax; \
91 jmp 2f; \
92 1: \
93 xorq %rax, %rax; \
97 * SYSREENTRY provides the entry sequence for restartable system calls.
99 #define SYSREENTRY(name) \
100 ENTRY(name); \
104 * SYSRESTART provides the error handling sequence for restartable
105 * system calls.
106 * XX64 -- Are all of the argument registers restored to their
107 * original values on an ERESTART return (including %rcx)?
109 #define SYSRESTART(name) \
110 jae 1f; \
111 cmpl $ERESTART, %eax; \
112 je 1b; \
113 jmp __cerror; \
117 * SYSINTR_RESTART provides the error handling sequence for restartable
118 * system calls in case of EINTR or ERESTART.
120 #define SYSINTR_RESTART(name) \
121 jae 1f; \
122 cmpl $ERESTART, %eax; \
123 je 1b; \
124 cmpl $EINTR, %eax; \
125 je 1b; \
126 jmp 2f; \
127 1: \
128 xorq %rax, %rax; \
132 * SYSCALL provides the standard (i.e.: most common) system call sequence.
134 #define SYSCALL(name) \
135 ENTRY(name); \
136 SYSTRAP_2RVALS(name); \
137 SYSCERROR
139 #define SYSCALL_RVAL1(name) \
140 ENTRY(name); \
141 SYSTRAP_RVAL1(name); \
142 SYSCERROR
145 * SYSCALL64 provides the standard (i.e.: most common) system call sequence
146 * for system calls that return 64-bit values.
148 #define SYSCALL64(name) \
149 SYSCALL(name)
152 * SYSCALL_RESTART provides the most common restartable system call sequence.
154 #define SYSCALL_RESTART(name) \
155 SYSREENTRY(name); \
156 SYSTRAP_2RVALS(name); \
157 SYSRESTART()
159 #define SYSCALL_RESTART_RVAL1(name) \
160 SYSREENTRY(name); \
161 SYSTRAP_RVAL1(name); \
162 SYSRESTART()
165 * SYSCALL2 provides a common system call sequence when the entry name
166 * is different than the trap name.
168 #define SYSCALL2(entryname, trapname) \
169 ENTRY(entryname); \
170 SYSTRAP_2RVALS(trapname); \
171 SYSCERROR
173 #define SYSCALL2_RVAL1(entryname, trapname) \
174 ENTRY(entryname); \
175 SYSTRAP_RVAL1(trapname); \
176 SYSCERROR
179 * SYSCALL2_RESTART provides a common restartable system call sequence when the
180 * entry name is different than the trap name.
182 #define SYSCALL2_RESTART(entryname, trapname) \
183 SYSREENTRY(entryname); \
184 SYSTRAP_2RVALS(trapname); \
185 SYSRESTART()
187 #define SYSCALL2_RESTART_RVAL1(entryname, trapname) \
188 SYSREENTRY(entryname); \
189 SYSTRAP_RVAL1(trapname); \
190 SYSRESTART()
193 * SYSCALL_NOERROR provides the most common system call sequence for those
194 * system calls which don't check the error reture (carry bit).
196 #define SYSCALL_NOERROR(name) \
197 ENTRY(name); \
198 SYSTRAP_2RVALS(name)
200 #define SYSCALL_NOERROR_RVAL1(name) \
201 ENTRY(name); \
202 SYSTRAP_RVAL1(name)
205 * Standard syscall return sequence, return code equal to rval1.
207 #define RET \
211 * Syscall return sequence, return code equal to rval2.
213 #define RET2 \
214 movq %rdx, %rax; \
218 * Syscall return sequence with return code forced to zero.
220 #define RETC \
221 xorq %rax, %rax; \
224 #endif /* _LIBC_AMD64_INC_SYS_H */