xref: /openbsd-src/lib/libc/arch/mips64/SYS.h (revision 2b0358df1d88d06ef4139321dd05bd5e05d91eaf)
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.3 2004/09/09 16:14:02 pefo Exp $
33  */
34 
35 #include <sys/syscall.h>
36 #include <machine/asm.h>
37 
38 #ifdef __STDC__
39 # define __ENTRY(p,x)		ENTRY(p ## x)
40 
41 # define __DO_SYSCALL(x)				\
42 				li	v0,SYS_ ## x;	\
43 				syscall
44 
45 # define __LEAF2(p,x,sz)	LEAF(p ## x, sz) \
46 				.weak x; x = p ## x;
47 
48 # define __END2(p,x)		END(p ## x)
49 
50 # define __CLABEL2(p,x)		_C_LABEL(p ## x)
51 #else
52 # define __ENTRY(p,x)		ENTRY(p/**/x)
53 
54 # define __DO_SYSCALL(x)				\
55 				li	v0,SYS_/**/x;	\
56 				syscall
57 
58 # define __LEAF2(p,x,sz)	LEAF(p/**/x, sz) \
59 				.weak x; x = p/**/x;
60 
61 # define __END2(p,x)		END(p/**/x)
62 
63 # define __CLABEL2(p,x)		_C_LABEL(p/**/x)
64 #endif
65 
66 #define __PSEUDO_NOERROR(p,x,y)				\
67 		__LEAF2(p,x, 0);			\
68 			__DO_SYSCALL(y);		\
69 			j	ra;			\
70 		__END2(p,x)
71 
72 #define __PSEUDO(p,x,y)   				\
73 		__LEAF2(p,x,32);			\
74 			PTR_SUBU sp,32;			\
75 			SETUP_GP64(16,__CLABEL2(p,x));	\
76 			__DO_SYSCALL(y);		\
77 			bne	a3,zero,err;		\
78 			RESTORE_GP64;			\
79 			PTR_ADDU sp,32;			\
80 			j	ra;			\
81 		err:	LA	t9,_C_LABEL(cerror);	\
82 			RESTORE_GP64;			\
83 			PTR_ADDU sp,32;			\
84 			jr	t9;			\
85 		__END2(p,x)
86 
87 
88 #define RSYSCALL(x)		__PSEUDO(_thread_sys_,x,x)
89 #define PSEUDO(x,y)		__PSEUDO(_thread_sys_,x,y)
90 #define PSEUDO_NOERROR(x,y)	__PSEUDO_NOERROR(_thread_sys_,x,y)
91 
92 #define	SYSLEAF(x, sz)		__LEAF2(_thread_sys_,x, sz)
93 #define	SYSEND(x)		__END2(_thread_sys_,x)
94 
95