xref: /openbsd-src/lib/libc/arch/powerpc64/SYS.h (revision 83762a71f74848f4d09174ce350838b4204957c5)
1*83762a71Sderaadt /*	$OpenBSD: SYS.h,v 1.6 2023/12/10 16:45:52 deraadt Exp $	*/
2b074422eSdrahn /*-
3b074422eSdrahn  * Copyright (c) 1994
4b074422eSdrahn  *	Andrew Cagney.  All rights reserved.
5b074422eSdrahn  *
6b074422eSdrahn  * This code is derived from software contributed to Berkeley by
7b074422eSdrahn  * Ralph Campbell.
8b074422eSdrahn  *
9b074422eSdrahn  * Redistribution and use in source and binary forms, with or without
10b074422eSdrahn  * modification, are permitted provided that the following conditions
11b074422eSdrahn  * are met:
12b074422eSdrahn  * 1. Redistributions of source code must retain the above copyright
13b074422eSdrahn  *    notice, this list of conditions and the following disclaimer.
14b074422eSdrahn  * 2. Redistributions in binary form must reproduce the above copyright
15b074422eSdrahn  *    notice, this list of conditions and the following disclaimer in the
16b074422eSdrahn  *    documentation and/or other materials provided with the distribution.
17b074422eSdrahn  * 3. All advertising materials mentioning features or use of this software
18b074422eSdrahn  *    must display the following acknowledgement:
19b074422eSdrahn  *	This product includes software developed by the University of
20b074422eSdrahn  *	California, Berkeley and its contributors.
21b074422eSdrahn  * 4. Neither the name of the University nor the names of its contributors
22b074422eSdrahn  *    may be used to endorse or promote products derived from this software
23b074422eSdrahn  *    without specific prior written permission.
24b074422eSdrahn  *
25b074422eSdrahn  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26b074422eSdrahn  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27b074422eSdrahn  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28b074422eSdrahn  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29b074422eSdrahn  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30b074422eSdrahn  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31b074422eSdrahn  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32b074422eSdrahn  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33b074422eSdrahn  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34b074422eSdrahn  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35b074422eSdrahn  * SUCH DAMAGE.
36b074422eSdrahn  *
37b074422eSdrahn  *	from: @(#)SYS.h	8.1 (Berkeley) 6/4/93
38b074422eSdrahn  */
39b074422eSdrahn 
40b074422eSdrahn #include "DEFS.h"
41b074422eSdrahn #include <sys/syscall.h>
42b074422eSdrahn 
43b074422eSdrahn /* r0 will be a non zero errno if there was an error, while r3/r4 will
44b074422eSdrahn    contain the return value */
45b074422eSdrahn 
46b074422eSdrahn #include "machine/asm.h"
47b074422eSdrahn 
48b074422eSdrahn 
49b074422eSdrahn /* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */
50874055c7Skettenis #define TCB_OFFSET_ERRNO	(-20)
51bfccc37dSkettenis /* from <powerpc64/tcb.h>: TCB address == %r13 - TCB_OFFSET */
52874055c7Skettenis #define TCB_OFFSET		0x7008
53b074422eSdrahn 
54bfccc37dSkettenis /* offset of errno from %r13 */
55b074422eSdrahn #define R13_OFFSET_ERRNO		(-TCB_OFFSET + TCB_OFFSET_ERRNO)
56b074422eSdrahn 
576a684a04Sguenther #define SYSENTRY(x)		.weak x; \
586a684a04Sguenther 				x = _thread_sys_ ## x; \
591a8dbaacSderaadt 				ENTRY(_thread_sys_ ## x)
601a8dbaacSderaadt #define SYSENTRY_HIDDEN(x) 	ENTRY(_thread_sys_ ## x)
61b074422eSdrahn #define __END_HIDDEN(p,x)	END(p##x);			\
62b074422eSdrahn 				_HIDDEN_FALIAS(x,p##x);		\
63b074422eSdrahn 				END(_HIDDEN(x))
64b074422eSdrahn #define __END(p,x)		__END_HIDDEN(p,x); END(x)
65b074422eSdrahn 
661a8dbaacSderaadt #define ALIAS(x,y)		WEAK_ALIAS(y, x ## y);
67b074422eSdrahn 
68b074422eSdrahn #define PSEUDO_NOERROR(x,y)	ALIAS(_thread_sys_,x) \
691a8dbaacSderaadt 				ENTRY(_thread_sys_ ## x) \
701a8dbaacSderaadt 				RETGUARD_SETUP(_thread_sys_ ## x, %r11); \
711a8dbaacSderaadt 				li %r0, SYS_ ## y ; \
72*83762a71Sderaadt 			97:	sc ; \
73*83762a71Sderaadt 				PINSYSCALL(SYS_ ## y, 97b); \
741a8dbaacSderaadt 				RETGUARD_CHECK(_thread_sys_ ## x, %r11); \
751a8dbaacSderaadt 				blr; \
76b074422eSdrahn 				__END(_thread_sys_,x)
77b074422eSdrahn 
781a8dbaacSderaadt #define PSEUDO_HIDDEN(x,y) 	ENTRY(_thread_sys_ ## x) \
791a8dbaacSderaadt 				RETGUARD_SETUP(_thread_sys_ ## x, %r11); \
801a8dbaacSderaadt 				li %r0, SYS_ ## y ; \
81*83762a71Sderaadt 			97:	sc ; \
82*83762a71Sderaadt 				PINSYSCALL(SYS_ ## y, 97b); \
831a8dbaacSderaadt 				cmpwi %r0, 0 ; \
841a8dbaacSderaadt 				beq .L_ret ; \
851a8dbaacSderaadt 				stw	%r0, R13_OFFSET_ERRNO(%r13); \
861a8dbaacSderaadt 				li	%r3, -1; \
871a8dbaacSderaadt 			.L_ret: \
881a8dbaacSderaadt 				RETGUARD_CHECK(_thread_sys_ ## x, %r11); \
891a8dbaacSderaadt 				blr; \
90b074422eSdrahn 				__END_HIDDEN(_thread_sys_,x)
911a8dbaacSderaadt 
92b074422eSdrahn #define PSEUDO(x,y)		ALIAS(_thread_sys_,x) \
93b074422eSdrahn 				PSEUDO_HIDDEN(x,y); \
94b074422eSdrahn 				END(x)
95b074422eSdrahn 
96b074422eSdrahn #define RSYSCALL(x)		PSEUDO(x,x)
97b074422eSdrahn #define RSYSCALL_HIDDEN(x)	PSEUDO_HIDDEN(x,x)
98b074422eSdrahn #define SYSCALL_END_HIDDEN(x)	__END_HIDDEN(_thread_sys_,x)
99b074422eSdrahn #define SYSCALL_END(x)		__END(_thread_sys_,x)
100b074422eSdrahn 
101