xref: /openbsd-src/lib/libc/arch/mips64/SYS.h (revision 4c1e55dc91edd6e69ccc60ce855900fbc12cf34f)
1 /*-
2  * Copyright (c) 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Ralph Campbell.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *      $OpenBSD: SYS.h,v 1.5 2011/04/04 12:42:39 guenther Exp $
33  */
34 
35 #include <sys/syscall.h>
36 #include <machine/asm.h>
37 
38 #define CERROR		_C_LABEL(__cerror)
39 #define _CERROR		_C_LABEL(___cerror)
40 
41 #ifdef __STDC__
42 # define __ENTRY(p,x)		ENTRY(p ## x)
43 
44 # define __DO_SYSCALL(x)				\
45 				li	v0,SYS_ ## x;	\
46 				syscall
47 
48 # define __LEAF2(p,x,sz)	LEAF(p ## x, sz) \
49 				WEAK_ALIAS(x, p ## x);
50 
51 # define __END2(p,x)		END(p ## x)
52 
53 # define __CLABEL2(p,x)		_C_LABEL(p ## x)
54 #else
55 # define __ENTRY(p,x)		ENTRY(p/**/x)
56 
57 # define __DO_SYSCALL(x)				\
58 				li	v0,SYS_/**/x;	\
59 				syscall
60 
61 # define __LEAF2(p,x,sz)	LEAF(p/**/x, sz) \
62 				WEAK_ALIAS(x, p/**/x);
63 
64 # define __END2(p,x)		END(p/**/x)
65 
66 # define __CLABEL2(p,x)		_C_LABEL(p/**/x)
67 #endif
68 
69 #define __PSEUDO_NOERROR(p,x,y)				\
70 		__LEAF2(p,x, 0);			\
71 			__DO_SYSCALL(y);		\
72 			j	ra;			\
73 		__END2(p,x)
74 
75 #define __PSEUDO(p,x,y)   				\
76 		__LEAF2(p,x,32);			\
77 			PTR_SUBU sp,32;			\
78 			SETUP_GP64(16,__CLABEL2(p,x));	\
79 			__DO_SYSCALL(y);		\
80 			bne	a3,zero,err;		\
81 			RESTORE_GP64;			\
82 			PTR_ADDU sp,32;			\
83 			j	ra;			\
84 		err:	LA	t9,CERROR;		\
85 			RESTORE_GP64;			\
86 			PTR_ADDU sp,32;			\
87 			jr	t9;			\
88 		__END2(p,x)
89 
90 
91 #define RSYSCALL(x)		__PSEUDO(_thread_sys_,x,x)
92 #define PSEUDO(x,y)		__PSEUDO(_thread_sys_,x,y)
93 #define PSEUDO_NOERROR(x,y)	__PSEUDO_NOERROR(_thread_sys_,x,y)
94 
95 #define	SYSLEAF(x, sz)		__LEAF2(_thread_sys_,x, sz)
96 #define	SYSEND(x)		__END2(_thread_sys_,x)
97 
98