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