xref: /openbsd/lib/libc/arch/mips64/SYS.h (revision d415bd75)
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.12 2016/05/07 19:05:22 guenther Exp $
33  */
34 
35 #include <sys/syscall.h>
36 #include <machine/asm.h>
37 
38 /*
39  * We define a hidden alias with the prefix "_libc_" for each global symbol
40  * that may be used internally.  By referencing _libc_x instead of x, other
41  * parts of libc prevent overriding by the application and avoid unnecessary
42  * relocations.
43  */
44 #define _HIDDEN(x)		_libc_##x
45 #define _HIDDEN_ALIAS(x,y)			\
46 	STRONG_ALIAS(_HIDDEN(x),y);		\
47 	.hidden _HIDDEN(x)
48 #define _HIDDEN_FALIAS(x,y)			\
49 	_HIDDEN_ALIAS(x,y);			\
50 	.type _HIDDEN(x),@function
51 
52 /*
53  * For functions implemented in ASM that aren't syscalls.
54  *   END_STRONG(x)	Like DEF_STRONG() in C; for standard/reserved C names
55  *   END_WEAK(x)	Like DEF_WEAK() in C; for non-ISO C names
56  */
57 #define	END_STRONG(x)	END(x);					\
58 			_HIDDEN_FALIAS(x,x);			\
59 			.size _HIDDEN(x), . - _HIDDEN(x)
60 #define	END_WEAK(x)	END_STRONG(x); .weak x
61 
62 
63 #define CERROR		__cerror
64 	.hidden	CERROR
65 
66 # define __ENTRY(p,x)		ENTRY(p ## x)
67 
68 # define __DO_SYSCALL(x)				\
69 				li	v0,SYS_ ## x;	\
70 				syscall
71 
72 # define __LEAF2(p,x,sz)	LEAF(p ## x, sz) \
73 				WEAK_ALIAS(x, p ## x);
74 
75 # define __END2_HIDDEN(p,x)	END(p ## x); 		\
76 				_HIDDEN_FALIAS(x, p ## x); \
77 				.size _HIDDEN(x), . - _HIDDEN(x)
78 # define __END2(p,x)		__END2_HIDDEN(p,x);	\
79 				.size x, . - x
80 
81 #define __PSEUDO_NOERROR(p,x,y)				\
82 		__LEAF2(p,x, 0);			\
83 			__DO_SYSCALL(y);		\
84 			j	ra;			\
85 		__END2(p,x)
86 
87 #define __PSEUDO(p,x,y)   				\
88 		__LEAF2(p,x,32);			\
89 			PTR_SUBU sp,32;			\
90 			SETUP_GP64(16,_HIDDEN(x));	\
91 			__DO_SYSCALL(y);		\
92 			bne	a3,zero,1f;		\
93 			RESTORE_GP64;			\
94 			PTR_ADDU sp,32;			\
95 			j	ra;			\
96 		1:	LA	t9,CERROR;		\
97 			RESTORE_GP64;			\
98 			PTR_ADDU sp,32;			\
99 			jr	t9;			\
100 		__END2(p,x)
101 #define __PSEUDO_HIDDEN(p,x,y)   			\
102 		LEAF(p ## x,32);			\
103 			PTR_SUBU sp,32;			\
104 			SETUP_GP64(16,_HIDDEN(x));	\
105 			__DO_SYSCALL(y);		\
106 			bne	a3,zero,1f;		\
107 			RESTORE_GP64;			\
108 			PTR_ADDU sp,32;			\
109 			j	ra;			\
110 		1:	LA	t9,CERROR;		\
111 			RESTORE_GP64;			\
112 			PTR_ADDU sp,32;			\
113 			jr	t9;			\
114 		__END2_HIDDEN(p,x)
115 
116 
117 #define RSYSCALL(x)		__PSEUDO(_thread_sys_,x,x)
118 #define RSYSCALL_HIDDEN(x)	__PSEUDO_HIDDEN(_thread_sys_,x,x)
119 #define PSEUDO(x,y)		__PSEUDO(_thread_sys_,x,y)
120 #define PSEUDO_NOERROR(x,y)	__PSEUDO_NOERROR(_thread_sys_,x,y)
121 
122 #define	SYSLEAF(x, sz)		__LEAF2(_thread_sys_,x, sz)
123 #define	SYSLEAF_HIDDEN(x, sz)	LEAF(_thread_sys_ ## x, sz)
124 #define	SYSCALL_END(x)		__END2(_thread_sys_,x)
125 #define	SYSCALL_END_HIDDEN(x)	__END2_HIDDEN(_thread_sys_,x)
126 
127