xref: /openbsd/lib/libc/arch/sparc64/SYS.h (revision 610f49f8)
1 /*	$OpenBSD: SYS.h,v 1.6 2002/01/03 01:11:10 art Exp $	*/
2 /*-
3  * Copyright (c) 1992, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This software was developed by the Computer Systems Engineering group
7  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
8  * contributed to Berkeley.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)SYS.h	8.1 (Berkeley) 6/4/93
39  *
40  *	from: Header: SYS.h,v 1.2 92/07/03 18:57:00 torek Exp
41  *	$NetBSD: SYS.h,v 1.6 2001/07/23 07:26:50 thorpej Exp $
42  */
43 
44 #include <machine/asm.h>
45 #include <sys/syscall.h>
46 #include <machine/trap.h>
47 
48 #ifdef __STDC__
49 #define _CAT(x,y) x##y
50 #else
51 #define _CAT(x,y) x/**/y
52 #endif
53 
54 #define	__ENTRY(p,x)	ENTRY(_CAT(p,x)) ; .weak x; x = _CAT(p,x)
55 
56 /*
57  * ERROR branches to cerror.  This is done with a macro so that I can
58  * change it to be position independent later, if need be.
59  */
60 #ifdef PIC
61 #define	CALL(name) \
62 	PIC_PROLOGUE(%g1,%g2); \
63 	sethi %hi(name),%g2; \
64 	or %g2,%lo(name),%g2; \
65 	ldx [%g1+%g2],%g2; \
66 	jmp %g2; \
67 	nop
68 #else
69 #define	CALL(name) \
70 	sethi %hi(name),%g1; or %lo(name),%g1,%g1; \
71 	jmp %g1; nop
72 #endif
73 #define	ERROR()	CALL(_C_LABEL(__cerror))
74 
75 /*
76  * SYSCALL is used when further action must be taken before returning.
77  * Note that it adds a `nop' over what we could do, if we only knew what
78  * came at label 1....
79  */
80 #define	_SYSCALL(p,x,y) \
81 	__ENTRY(p,x); mov _CAT(SYS_,y),%g1; t ST_SYSCALL; bcc 1f; nop; ERROR(); 1:
82 
83 #define	__SYSCALL(p,x) \
84 	_SYSCALL(p,x,x)
85 
86 /*
87  * RSYSCALL is used when the system call should just return.  Here
88  * we use the SYSCALL_G2RFLAG to put the `success' return address in %g2
89  * and avoid a branch.
90  */
91 #define	__RSYSCALL(p,x) \
92 	__ENTRY(p,x); mov (_CAT(SYS_,x))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \
93 	t ST_SYSCALL; ERROR()
94 
95 /*
96  * PSEUDO(x,y) is like RSYSCALL(y) except that the name is x.
97  */
98 #define	__PSEUDO(p,x,y) \
99 	__ENTRY(p,x); mov (_CAT(SYS_,y))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \
100 	t ST_SYSCALL; ERROR()
101 
102 /*
103  * SYSCALL_NOERROR is like SYSCALL, except it's used for syscalls
104  * that never fail.
105  *
106  * XXX - This should be optimized.
107  */
108 #define __SYSCALL_NOERROR(p,x) \
109 	__ENTRY(p,x); mov _CAT(SYS_,x),%g1; t ST_SYSCALL
110 
111 /*
112  * RSYSCALL_NOERROR is like RSYSCALL, except it's used for syscalls
113  * that never fail.
114  *
115  * XXX - This should be optimized.
116  */
117 #define __RSYSCALL_NOERROR(p,x) \
118 	__ENTRY(p,x); mov (_CAT(SYS_,x))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \
119 	t ST_SYSCALL
120 
121 /*
122  * PSEUDO_NOERROR(x,y) is like RSYSCALL_NOERROR(y) except that the name is x.
123  */
124 #define __PSEUDO_NOERROR(p,x,y) \
125 	__ENTRY(p,x); mov (_CAT(SYS_,y))|SYSCALL_G2RFLAG,%g1; add %o7,8,%g2; \
126 	t ST_SYSCALL
127 
128 	.globl	_C_LABEL(__cerror)
129 
130 /*
131  * SYSENTRY is for functions that pretend to be syscalls.
132  */
133 #define __SYSENTRY(p,x) __ENTRY(p,x)
134 
135 #define	SYSCALL(x)		__SYSCALL(_thread_sys_,x)
136 #define	RSYSCALL(x)		__RSYSCALL(_thread_sys_,x)
137 #define	RSYSCALL_NOERROR(x,y)	__RSYSCALL_NOERROR(_thread_sys_,x,y)
138 #define	PSEUDO(x,y)		__PSEUDO(_thread_sys_,x,y)
139 #define	PSEUDO_NOERROR(x,y)	__PSEUDO_NOERROR(_thread_sys_,x,y)
140 #define	SYSENTRY(x)		__SYSENTRY(_thread_sys_,x)
141