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