xref: /openbsd/lib/libc/arch/hppa/SYS.h (revision 76d0caae)
1 /*	$OpenBSD: SYS.h,v 1.22 2016/05/07 19:05:21 guenther Exp $	*/
2 
3 /*
4  * Copyright (c) 1998-2002 Michael Shalayeff
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF MIND
22  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include <sys/syscall.h>
29 #include <machine/asm.h>
30 #undef _LOCORE
31 #define _LOCORE
32 #include <machine/frame.h>
33 #include <machine/vmparam.h>
34 #undef _LOCORE
35 
36 /* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */
37 #define TCB_OFFSET_ERRNO	-8
38 
39 /*
40  * We define a hidden alias with the prefix "_libc_" for each global symbol
41  * that may be used internally.  By referencing _libc_x instead of x, other
42  * parts of libc prevent overriding by the application and avoid unnecessary
43  * relocations.
44  */
45 #define _HIDDEN(x)		_libc_##x
46 #define _HIDDEN_ALIAS(x,y)			\
47 	STRONG_ALIAS(_HIDDEN(x),y)		!\
48 	.hidden _HIDDEN(x)
49 #define _HIDDEN_FALIAS(x,y)			\
50 	_HIDDEN_ALIAS(x,y)			!\
51 	.type _HIDDEN(x),@function
52 
53 /*
54  * For functions implemented in ASM that aren't syscalls.
55  *   EXIT_STRONG(x)	Like DEF_STRONG() in C; for standard/reserved C names
56  *   EXIT_WEAK(x)	Like DEF_WEAK() in C; for non-ISO C names
57  *   ALTEXIT_STRONG(x) and ALTEXIT_WEAK()
58  *			Matching macros for ALTENTRY functions
59  */
60 #define	ALTEXIT_STRONG(x)					\
61 			_HIDDEN_FALIAS(x,x)			!\
62 			.size _HIDDEN(x), . - _HIDDEN(x)
63 #define	ALTEXIT_WEAK(x)	ALTEXIT_STRONG(x)			!\
64 			.weak x
65 #define	EXIT_STRONG(x)	EXIT(x)					!\
66 			ALTEXIT_STRONG(x)
67 #define	EXIT_WEAK(x)	EXIT_STRONG(x)				!\
68 			.weak x
69 
70 
71 #define SYSENTRY(x)				!\
72 LEAF_ENTRY(__CONCAT(_thread_sys_,x))		!\
73 	WEAK_ALIAS(x,__CONCAT(_thread_sys_,x))
74 #define SYSENTRY_HIDDEN(x)			!\
75 LEAF_ENTRY(__CONCAT(_thread_sys_,x))
76 #define	SYSEXIT(x)				!\
77 	SYSEXIT_HIDDEN(x)			!\
78 	.size x, . - x
79 #define	SYSEXIT_HIDDEN(x)			!\
80 	EXIT(__CONCAT(_thread_sys_,x))		!\
81 	_HIDDEN_FALIAS(x,_thread_sys_##x)	!\
82 	.size _HIDDEN(x), . - _HIDDEN(x)
83 
84 #define	SYSCALL(x)				!\
85 	stw	rp, HPPA_FRAME_ERP(sr0,sp)	!\
86 	ldil	L%SYSCALLGATE, r1		!\
87 	ble	4(sr7, r1)			!\
88 	ldi	__CONCAT(SYS_,x), t1		!\
89 	comb,=	0, t1, 1f			!\
90 	ldw	HPPA_FRAME_ERP(sr0,sp), rp	!\
91 	/* set errno */				\
92 	mfctl	cr27, r1			!\
93 	stw	t1, TCB_OFFSET_ERRNO(r1)	!\
94 	ldi	-1, ret0			!\
95 	bv	r0(rp)				!\
96 	 ldi	-1, ret1			!\
97 1:
98 
99 #define	PSEUDO(x,y)				!\
100 SYSENTRY(x)					!\
101 	SYSCALL(y)				!\
102 	bv	r0(rp)				!\
103 	nop					!\
104 SYSEXIT(x)
105 #define	PSEUDO_HIDDEN(x,y)			!\
106 SYSENTRY_HIDDEN(x)				!\
107 	SYSCALL(y)				!\
108 	bv	r0(rp)				!\
109 	nop					!\
110 SYSEXIT_HIDDEN(x)
111 
112 #define	PSEUDO_NOERROR(x,y)			!\
113 SYSENTRY(x)					!\
114 	stw	rp, HPPA_FRAME_ERP(sr0,sp)	!\
115 	ldil	L%SYSCALLGATE, r1		!\
116 	ble	4(sr7, r1)			!\
117 	ldi	__CONCAT(SYS_,y), t1		!\
118 	ldw	HPPA_FRAME_ERP(sr0,sp), rp	!\
119 	bv	r0(rp)				!\
120 	nop					!\
121 SYSEXIT(x)
122 
123 #define	RSYSCALL(x)		PSEUDO(x,x)
124 #define	RSYSCALL_HIDDEN(x)	PSEUDO_HIDDEN(x,x)
125 
126