xref: /openbsd-src/lib/libc/arch/mips64/SYS.h (revision 50b7afb2c2c0993b0894d4e34bf857cb13ed9c80)
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.6 2014/06/04 20:13:49 matthew 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 # define __ENTRY(p,x)		ENTRY(p ## x)
42 
43 # define __DO_SYSCALL(x)				\
44 				li	v0,SYS_ ## x;	\
45 				syscall
46 
47 # define __LEAF2(p,x,sz)	LEAF(p ## x, sz) \
48 				WEAK_ALIAS(x, p ## x);
49 
50 # define __END2(p,x)		END(p ## x)
51 
52 # define __CLABEL2(p,x)		_C_LABEL(p ## x)
53 
54 #define __PSEUDO_NOERROR(p,x,y)				\
55 		__LEAF2(p,x, 0);			\
56 			__DO_SYSCALL(y);		\
57 			j	ra;			\
58 		__END2(p,x)
59 
60 #define __PSEUDO(p,x,y)   				\
61 		__LEAF2(p,x,32);			\
62 			PTR_SUBU sp,32;			\
63 			SETUP_GP64(16,__CLABEL2(p,x));	\
64 			__DO_SYSCALL(y);		\
65 			bne	a3,zero,err;		\
66 			RESTORE_GP64;			\
67 			PTR_ADDU sp,32;			\
68 			j	ra;			\
69 		err:	LA	t9,CERROR;		\
70 			RESTORE_GP64;			\
71 			PTR_ADDU sp,32;			\
72 			jr	t9;			\
73 		__END2(p,x)
74 
75 
76 #define RSYSCALL(x)		__PSEUDO(_thread_sys_,x,x)
77 #define PSEUDO(x,y)		__PSEUDO(_thread_sys_,x,y)
78 #define PSEUDO_NOERROR(x,y)	__PSEUDO_NOERROR(_thread_sys_,x,y)
79 
80 #define	SYSLEAF(x, sz)		__LEAF2(_thread_sys_,x, sz)
81 #define	SYSEND(x)		__END2(_thread_sys_,x)
82 
83