xref: /openbsd/lib/libc/arch/hppa/SYS.h (revision ba8732b6)
1 /*	$OpenBSD: SYS.h,v 1.9 2001/09/20 20:52:09 millert Exp $	*/
2 
3 /*
4  * Copyright (c) 1998-1999 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  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by Michael Shalayeff.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF MIND
27  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/syscall.h>
34 #include <machine/asm.h>
35 #include <machine/vmparam.h>
36 #undef _LOCORE
37 #define _LOCORE
38 #include <machine/frame.h>
39 
40 #define	__ENTRY(p,x)	ENTRY(__CONCAT(p,x),0)
41 #define	__EXIT(p,x)	EXIT(__CONCAT(p,x))
42 
43 
44 #define	__SYSCALL(p,x)				!\
45 	.import	errno, data			!\
46 	stw	rp, HPPA_FRAME_ERP(sr0,sp)	!\
47 	ldil	L%SYSCALLGATE, r1		!\
48 	ble	4(sr7, r1)			!\
49 	ldi	__CONCAT(SYS_,x), t1		!\
50 	ldw	HPPA_FRAME_ERP(sr0,sp), rp	!\
51 	comb,=,n r0, t1, __CONCAT(x,$noerr)	!\
52 	ldil	L%errno, r1			!\
53 	stw	t1, R%errno(r1)			!\
54 	ldi	-1, ret0			!\
55 	bv	r0(rp)				!\
56 	ldi	-1, ret1			!\
57 	.label	__CONCAT(x,$noerr)
58 
59 #define	__RSYSCALL(p,x)			!\
60 __ENTRY(p,x)				!\
61 	__SYSCALL(p,x)			!\
62 	bv	r0(rp)			!\
63 	nop				!\
64 __EXIT(p,x)
65 
66 #define	__PSEUDO(p,x,y)			!\
67 __ENTRY(p,x)				!\
68 	__SYSCALL(p,y)			!\
69 	bv	r0(rp)			!\
70 	nop				!\
71 __EXIT(p,x)
72 
73 /* XXX - actually sets errnor */
74 #define	__PSEUDO_NOERROR(p,x,y)		!\
75 __ENTRY(p,x)				!\
76 	__SYSCALL(p,y)			!\
77 	bv	r0(rp)			!\
78 	nop				!\
79 __EXIT(p,x)
80 
81 /*
82  * Design note:
83  *
84  * When the syscalls need to be renamed so they can be handled
85  * specially by the threaded library, these macros insert `_thread_sys_'
86  * in front of their name. This avoids the need to #ifdef _THREAD_SAFE
87  * everywhere that the renamed function needs to be called.
88  */
89 #ifdef _THREAD_SAFE
90 /*
91  * For the thread_safe versions, we prepend _thread_sys_ to the function
92  * name so that the 'C' wrapper can go around the real name.
93  */
94 # define SYSCALL(x)		__SYSCALL(_thread_sys_,x)
95 # define RSYSCALL(x)		__RSYSCALL(_thread_sys_,x)
96 # define PSEUDO(x,y)		__PSEUDO(_thread_sys_,x,y)
97 # define PSEUDO_NOERROR(x,y)	__PSEUDO_NOERROR(_thread_sys_,x,y)
98 /*# define SYSENTRY(x)		__ENTRY(_thread_sys_,x)*/
99 #else /* _THREAD_SAFE */
100 /*
101  * The non-threaded library defaults to traditional syscalls where
102  * the function name matches the syscall name.
103  */
104 # define SYSCALL(x)		__SYSCALL(,x)
105 # define RSYSCALL(x)		__RSYSCALL(,x)
106 # define PSEUDO(x,y)		__PSEUDO(,x,y)
107 # define PSEUDO_NOERROR(x,y)	__PSEUDO_NOERROR(_thread_sys_,x,y)
108 /*# define SYSENTRY(x)		__ENTRY(,x)*/
109 #endif /* _THREAD_SAFE */
110