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_SPARC_INC_SYS_H
28 #define _LIBC_SPARC_INC_SYS_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 * This file defines common code sequences for system calls. Note that
34 * it is assumed that __cerror is within the short branch distance from
35 * all the traps (so that a simple bcs can follow the trap, rather than
36 * a position independent code sequence.) Ditto for __cerror64.
39 #include <sys/asm_linkage.h>
40 #include <sys/syscall.h>
41 #include <sys/errno.h>
44 * While it's tempting to imagine we could use 'rd %pc' here,
45 * in fact it's a rather slow operation that consumes many
46 * cycles, so we use the usual side-effect of 'call' instead.
48 #define PIC_SETUP(r) \
51 sethi %hi(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r; \
52 8: or %r, %lo(_GLOBAL_OFFSET_TABLE_ - (9b - .)), %r; \
57 * Trap number for system calls
59 #define SYSCALL_TRAPNUM 8
60 #define FASTSCALL_TRAPNUM 9
63 * Define the external symbols __cerror and __cerror64 for all files.
69 * __SYSTRAP provides the basic trap sequence. It assumes that an entry
70 * of the form SYS_name exists (probably from sys/syscall.h).
72 #define __SYSTRAP(name) \
74 mov SYS_/**/name, %g1; \
77 #define SYSTRAP_RVAL1(name) __SYSTRAP(name)
78 #define SYSTRAP_RVAL2(name) __SYSTRAP(name)
79 #define SYSTRAP_2RVALS(name) __SYSTRAP(name)
80 #define SYSTRAP_64RVAL(name) __SYSTRAP(name)
83 * SYSFASTTRAP provides the fast system call trap sequence. It assumes
84 * that an entry of the form ST_name exists (probably from sys/trap.h).
86 #define SYSFASTTRAP(name) \
91 * SYSCERROR provides the sequence to branch to __cerror if an error is
92 * indicated by the carry-bit being set upon return from a trap.
99 * SYSCERROR64 provides the sequence to branch to __cerror64 if an error is
100 * indicated by the carry-bit being set upon return from a trap.
102 #define SYSCERROR64 \
107 * SYSLWPERR provides the sequence to return 0 on a successful trap
108 * and the error code if unsuccessful.
109 * Error is indicated by the carry-bit being set upon return from a trap.
116 move %icc, EINTR, %o0; \
119 #define SAVE_OFFSET 68
122 * SYSREENTRY provides the entry sequence for restartable system calls.
124 #define SYSREENTRY(name) \
126 stn %o0, [%sp + SAVE_OFFSET]; \
131 * SYSRESTART provides the error handling sequence for restartable
134 #define SYSRESTART(name) \
139 be,a,pn %icc, name; \
140 ldn [%sp + SAVE_OFFSET], %o0; \
146 * SYSINTR_RESTART provides the error handling sequence for restartable
147 * system calls in case of EINTR or ERESTART.
149 #define SYSINTR_RESTART(name) \
155 be,a,pn %icc, name; \
156 ldn [%sp + SAVE_OFFSET], %o0; \
159 be,a,pn %icc, name; \
160 ldn [%sp + SAVE_OFFSET], %o0; \
164 * SYSCALL provides the standard (i.e.: most common) system call sequence.
166 #define SYSCALL(name) \
168 SYSTRAP_2RVALS(name); \
171 #define SYSCALL_RVAL1(name) \
173 SYSTRAP_RVAL1(name); \
177 * SYSCALL64 provides the standard (i.e.: most common) system call sequence
178 * for system calls that return 64-bit values.
180 #define SYSCALL64(name) \
182 SYSTRAP_64RVAL(name); \
186 * SYSCALL_RESTART provides the most common restartable system call sequence.
188 #define SYSCALL_RESTART(name) \
190 SYSTRAP_2RVALS(name); \
192 SYSRESTART(.restart_/**/name)
194 #define SYSCALL_RESTART_RVAL1(name) \
196 SYSTRAP_RVAL1(name); \
198 SYSRESTART(.restart_/**/name)
201 * SYSCALL2 provides a common system call sequence when the entry name
202 * is different than the trap name.
204 #define SYSCALL2(entryname, trapname) \
206 SYSTRAP_2RVALS(trapname); \
209 #define SYSCALL2_RVAL1(entryname, trapname) \
211 SYSTRAP_RVAL1(trapname); \
215 * SYSCALL2_RESTART provides a common restartable system call sequence when the
216 * entry name is different than the trap name.
218 #define SYSCALL2_RESTART(entryname, trapname) \
219 SYSREENTRY(entryname); \
220 SYSTRAP_2RVALS(trapname); \
222 SYSRESTART(.restart_/**/entryname)
224 #define SYSCALL2_RESTART_RVAL1(entryname, trapname) \
225 SYSREENTRY(entryname); \
226 SYSTRAP_RVAL1(trapname); \
228 SYSRESTART(.restart_/**/entryname)
231 * SYSCALL_NOERROR provides the most common system call sequence for those
232 * system calls which don't check the error return (carry bit).
234 #define SYSCALL_NOERROR(name) \
238 #define SYSCALL_NOERROR_RVAL1(name) \
243 * Standard syscall return sequence, return code equal to rval1.
250 * Syscall return sequence, return code equal to rval2.
257 * Syscall return sequence with return code forced to zero.
263 #endif /* _LIBC_SPARC_INC_SYS_H */