xref: /openbsd-src/lib/libc/arch/alpha/SYS.h (revision 5bcead818ba71dc1c4fad02a24986a5b47ae1c58)
1*5bcead81Skettenis /*	$OpenBSD: SYS.h,v 1.18 2023/12/11 22:24:15 kettenis Exp $	*/
241768452Sniklas /*	$NetBSD: SYS.h,v 1.4 1996/10/17 03:03:53 cgd Exp $	*/
3df930be7Sderaadt 
4df930be7Sderaadt /*
5df930be7Sderaadt  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
6df930be7Sderaadt  * All rights reserved.
7df930be7Sderaadt  *
8df930be7Sderaadt  * Author: Chris G. Demetriou
9df930be7Sderaadt  *
10df930be7Sderaadt  * Permission to use, copy, modify and distribute this software and
11df930be7Sderaadt  * its documentation is hereby granted, provided that both the copyright
12df930be7Sderaadt  * notice and this permission notice appear in all copies of the
13df930be7Sderaadt  * software, derivative works or modified versions, and any portions
14df930be7Sderaadt  * thereof, and that both notices appear in supporting documentation.
15df930be7Sderaadt  *
16df930be7Sderaadt  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17df930be7Sderaadt  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18df930be7Sderaadt  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19df930be7Sderaadt  *
20df930be7Sderaadt  * Carnegie Mellon requests users of this software to return to
21df930be7Sderaadt  *
22df930be7Sderaadt  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
23df930be7Sderaadt  *  School of Computer Science
24df930be7Sderaadt  *  Carnegie Mellon University
25df930be7Sderaadt  *  Pittsburgh PA 15213-3890
26df930be7Sderaadt  *
27df930be7Sderaadt  * any improvements or extensions that they make and grant Carnegie the
28df930be7Sderaadt  * rights to redistribute these changes.
29df930be7Sderaadt  */
30df930be7Sderaadt 
31df930be7Sderaadt #include <machine/asm.h>
32adca6c91Sguenther #include <machine/pal.h>		/* for PAL_rdunique */
33df930be7Sderaadt #include <sys/syscall.h>
34df930be7Sderaadt 
35adca6c91Sguenther 
36adca6c91Sguenther /* offsetof(struct tib, tib_errno) - offsetof(struct tib, __tib_tcb) */
37adca6c91Sguenther #define	TCB_OFFSET_ERRNO	(-12)
38adca6c91Sguenther 
399b9d2a55Sguenther /*
409b9d2a55Sguenther  * We define a hidden alias with the prefix "_libc_" for each global symbol
419b9d2a55Sguenther  * that may be used internally.  By referencing _libc_x instead of x, other
429b9d2a55Sguenther  * parts of libc prevent overriding by the application and avoid unnecessary
439b9d2a55Sguenther  * relocations.
449b9d2a55Sguenther  */
459b9d2a55Sguenther #define _HIDDEN(x)		_libc_##x
469b9d2a55Sguenther #define _HIDDEN_ALIAS(x,y)			\
479b9d2a55Sguenther 	STRONG_ALIAS(_HIDDEN(x),y);		\
489b9d2a55Sguenther 	.hidden _HIDDEN(x)
499b9d2a55Sguenther #define _HIDDEN_FALIAS(x,y)			\
509b9d2a55Sguenther 	_HIDDEN_ALIAS(x,y);			\
519b9d2a55Sguenther 	.type _HIDDEN(x),@function
529b9d2a55Sguenther 
539b9d2a55Sguenther /*
543f373d41Sguenther  * END() uses the alpha .end pseudo-op which requires a matching .ent,
553f373d41Sguenther  * so here's a short hand for just doing .size
563f373d41Sguenther  */
573f373d41Sguenther #define _END(x)		.size x, . - x
583f373d41Sguenther 
5983762a71Sderaadt #define PINSYSCALL(sysno, label)					\
6083762a71Sderaadt 	.pushsection .openbsd.syscalls,"",@progbits;			\
61*5bcead81Skettenis 	.p2align 2;							\
6283762a71Sderaadt 	.long label;							\
6383762a71Sderaadt 	.long sysno;							\
6483762a71Sderaadt 	.popsection;
6583762a71Sderaadt 
663f373d41Sguenther /*
679b9d2a55Sguenther  * For functions implemented in ASM that aren't syscalls.
689b9d2a55Sguenther  *   END_STRONG(x)	Like DEF_STRONG() in C; for standard/reserved C names
699b9d2a55Sguenther  *   END_WEAK(x)	Like DEF_WEAK() in C; for non-ISO C names
709b9d2a55Sguenther  */
719b9d2a55Sguenther #define	END_STRONG(x)	END(x); _HIDDEN_FALIAS(x,x);		\
723f373d41Sguenther 			_END(_HIDDEN(x))
739b9d2a55Sguenther #define	END_WEAK(x)	END_STRONG(x); .weak x
749b9d2a55Sguenther 
756750a6d9Smiod #define	CALLSYS_NOERROR(name)					\
766750a6d9Smiod 	ldiq	v0, ___CONCAT(SYS_,name);			\
7783762a71Sderaadt 97:	call_pal PAL_OSF1_callsys;				\
7883762a71Sderaadt 	PINSYSCALL(___CONCAT(SYS_,name), 97b)
79df930be7Sderaadt 
8041768452Sniklas #define	CALLSYS_ERROR(name)					\
8141768452Sniklas 	CALLSYS_NOERROR(name);					\
8241768452Sniklas 	beq	a3, LLABEL(name,1);				\
83adca6c91Sguenther 	mov	v0, t0;						\
84adca6c91Sguenther 	call_pal PAL_rdunique;					\
85adca6c91Sguenther 	stl	t0, TCB_OFFSET_ERRNO(v0);			\
86adca6c91Sguenther 	ldiq	v0, -1;						\
87adca6c91Sguenther 	RET;							\
8841768452Sniklas LLABEL(name,1):
89df930be7Sderaadt 
90322509f8Sd #define __LEAF(p,n,e)						\
91322509f8Sd 	LEAF(___CONCAT(p,n),e)
92322509f8Sd #define __END(p,n)						\
933f373d41Sguenther 	END(___CONCAT(p,n));					\
943f373d41Sguenther 	_HIDDEN_FALIAS(n,___CONCAT(p,n));			\
953f373d41Sguenther 	_END(_HIDDEN(n))
96df930be7Sderaadt 
97322509f8Sd #define	__SYSCALL(p,name)					\
98322509f8Sd __LEAF(p,name,0);			/* XXX # of args? */	\
9941768452Sniklas 	CALLSYS_ERROR(name)
10041768452Sniklas 
101322509f8Sd #define	__SYSCALL_NOERROR(p,name)				\
102322509f8Sd __LEAF(p,name,0);			/* XXX # of args? */	\
10341768452Sniklas 	CALLSYS_NOERROR(name)
10441768452Sniklas 
10541768452Sniklas 
106322509f8Sd #define __RSYSCALL(p,name)					\
107322509f8Sd 	__SYSCALL(p,name);					\
108df930be7Sderaadt 	RET;							\
109322509f8Sd __END(p,name)
11041768452Sniklas 
111322509f8Sd #define __RSYSCALL_NOERROR(p,name)				\
112322509f8Sd 	__SYSCALL_NOERROR(p,name);				\
11341768452Sniklas 	RET;							\
114322509f8Sd __END(p,name)
11541768452Sniklas 
11641768452Sniklas 
117322509f8Sd #define	__PSEUDO(p,label,name)					\
118322509f8Sd __LEAF(p,label,0);			/* XXX # of args? */	\
119ba8732b6Smillert 	CALLSYS_ERROR(name);					\
120ba8732b6Smillert 	RET;							\
121ba8732b6Smillert __END(p,label);
122ba8732b6Smillert 
123ba8732b6Smillert #define	__PSEUDO_NOERROR(p,label,name)				\
124ba8732b6Smillert __LEAF(p,label,0);			/* XXX # of args? */	\
12541768452Sniklas 	CALLSYS_NOERROR(name);					\
12641768452Sniklas 	RET;							\
127322509f8Sd __END(p,label);
128322509f8Sd 
12901751614Sdrahn #define ALIAS(prefix,name) WEAK_ALIAS(name, ___CONCAT(prefix,name));
130322509f8Sd 
131322509f8Sd /*
132322509f8Sd  * For the thread_safe versions, we prepend _thread_sys_ to the function
133322509f8Sd  * name so that the 'C' wrapper can go around the real name.
134322509f8Sd  */
13501751614Sdrahn # define SYSCALL(x)		ALIAS(_thread_sys_,x) \
13601751614Sdrahn 				__SYSCALL(_thread_sys_,x)
13701751614Sdrahn # define SYSCALL_NOERROR(x)	ALIAS(_thread_sys_,x) \
13801751614Sdrahn 				__SYSCALL_NOERROR(_thread_sys_,x)
13901751614Sdrahn # define RSYSCALL(x)		ALIAS(_thread_sys_,x) \
1403f373d41Sguenther 				__RSYSCALL(_thread_sys_,x); \
1413f373d41Sguenther 				_END(x)
142514a545fSguenther # define RSYSCALL_HIDDEN(x)	__RSYSCALL(_thread_sys_,x)
14301751614Sdrahn # define RSYSCALL_NOERROR(x)	ALIAS(_thread_sys_,x) \
1443f373d41Sguenther 				__RSYSCALL_NOERROR(_thread_sys_,x); \
1453f373d41Sguenther 				_END(x)
14601751614Sdrahn # define PSEUDO(x,y)		ALIAS(_thread_sys_,x) \
1473f373d41Sguenther 				__PSEUDO(_thread_sys_,x,y); \
1483f373d41Sguenther 				_END(x)
14901751614Sdrahn # define PSEUDO_NOERROR(x,y)	ALIAS(_thread_sys_,x) \
1503f373d41Sguenther 				__PSEUDO_NOERROR(_thread_sys_,x,y); \
1513f373d41Sguenther 				_END(x)
1525aed4d28Sguenther # define SYSLEAF_HIDDEN(x,e)	__LEAF(_thread_sys_,x,e)
15301751614Sdrahn # define SYSLEAF(x,e)		ALIAS(_thread_sys_,x) \
1545aed4d28Sguenther 				SYSLEAF_HIDDEN(x,e)
1555aed4d28Sguenther # define SYSCALL_END_HIDDEN(x)	__END(_thread_sys_,x)
1565aed4d28Sguenther # define SYSCALL_END(x)		SYSCALL_END_HIDDEN(x); \
1573f373d41Sguenther 				_END(x)
158