xref: /minix3/lib/libc/arch/powerpc64/SYS.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: SYS.h,v 1.4 2015/01/12 02:48:20 dennis Exp $	*/
22fe8fb19SBen Gras 
32fe8fb19SBen Gras #include <machine/asm.h>
42fe8fb19SBen Gras #include <sys/syscall.h>
52fe8fb19SBen Gras 
6*0a6a1f1dSLionel Sambuc /*
7*0a6a1f1dSLionel Sambuc  * Inline what __cerror() is generally used to do since branching
8*0a6a1f1dSLionel Sambuc  * to __cerror() can't be done reliably with the powerpc64 ABI.
9*0a6a1f1dSLionel Sambuc  */
10*0a6a1f1dSLionel Sambuc #ifdef _REENTRANT
11*0a6a1f1dSLionel Sambuc #define	_DO_CERROR_SF_SZ	(SF_SZ + SF_ALIGN(8))
12*0a6a1f1dSLionel Sambuc #define	_DO_CERROR()		mflr	%r0				;\
13*0a6a1f1dSLionel Sambuc 				streg	%r31,-8(%r1)			;\
14*0a6a1f1dSLionel Sambuc 				streg	%r0,SF_LR(%r1)			;\
15*0a6a1f1dSLionel Sambuc 				stptru	%r1,-_DO_CERROR_SF_SZ(%r1)	;\
16*0a6a1f1dSLionel Sambuc 				mr	%r31,%r3			;\
17*0a6a1f1dSLionel Sambuc 				bl	PIC_PLT(_C_LABEL(__errno))	;\
18*0a6a1f1dSLionel Sambuc 				nop					;\
19*0a6a1f1dSLionel Sambuc 				stint	%r31,0(%r3)			;\
20*0a6a1f1dSLionel Sambuc 				addi	%r1,%r1,_DO_CERROR_SF_SZ	;\
21*0a6a1f1dSLionel Sambuc 				ldreg	%r0,SF_LR(%r1)			;\
22*0a6a1f1dSLionel Sambuc 				ldreg	%r31,-8(%r1)			;\
23*0a6a1f1dSLionel Sambuc 				mtlr	%r0				;\
24*0a6a1f1dSLionel Sambuc 				li	%r3,-1				;\
25*0a6a1f1dSLionel Sambuc 				li	%r4,-1				;\
26*0a6a1f1dSLionel Sambuc 				blr
27*0a6a1f1dSLionel Sambuc #else	/* !_REENTRANT */
28*0a6a1f1dSLionel Sambuc #define	_DO_CERROR()		lwz	%r4,_C_LABEL(errno)@got(%r2)	;\
29*0a6a1f1dSLionel Sambuc 				stw	%r3,0(%r4)			;\
30*0a6a1f1dSLionel Sambuc 				li	%r3,-1				;\
31*0a6a1f1dSLionel Sambuc 				li	%r4,-1				;\
32*0a6a1f1dSLionel Sambuc 				blr
33*0a6a1f1dSLionel Sambuc #endif	/* _REENTRANT */
34*0a6a1f1dSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc /* Clearly BRANCH_TO_CERROR() no longer does that... */
36*0a6a1f1dSLionel Sambuc #define	BRANCH_TO_CERROR()	_DO_CERROR()
37*0a6a1f1dSLionel Sambuc 
382fe8fb19SBen Gras #define	_DOSYSCALL(x)		li	%r0,(SYS_ ## x)		;\
392fe8fb19SBen Gras 				sc
402fe8fb19SBen Gras 
412fe8fb19SBen Gras #define	_SYSCALL_NOERROR(x,y)	.text				;\
42*0a6a1f1dSLionel Sambuc 				.p2align 2			;\
432fe8fb19SBen Gras 			ENTRY(x)				;\
442fe8fb19SBen Gras 				_DOSYSCALL(y)
452fe8fb19SBen Gras 
462fe8fb19SBen Gras #define _SYSCALL(x,y)		.text				;\
47*0a6a1f1dSLionel Sambuc 				.p2align 2			;\
48*0a6a1f1dSLionel Sambuc 			2:	_DO_CERROR()			;\
492fe8fb19SBen Gras 				_SYSCALL_NOERROR(x,y)		;\
502fe8fb19SBen Gras 				bso	2b
512fe8fb19SBen Gras 
522fe8fb19SBen Gras #define SYSCALL_NOERROR(x)	_SYSCALL_NOERROR(x,x)
532fe8fb19SBen Gras 
542fe8fb19SBen Gras #define SYSCALL(x)		_SYSCALL(x,x)
552fe8fb19SBen Gras 
562fe8fb19SBen Gras #define PSEUDO_NOERROR(x,y)	_SYSCALL_NOERROR(x,y)		;\
57*0a6a1f1dSLionel Sambuc 				blr				;\
58*0a6a1f1dSLionel Sambuc 				END(x)
592fe8fb19SBen Gras 
602fe8fb19SBen Gras #define PSEUDO(x,y)		_SYSCALL_NOERROR(x,y)		;\
612fe8fb19SBen Gras 				bnslr				;\
62*0a6a1f1dSLionel Sambuc 				_DO_CERROR()			;\
63*0a6a1f1dSLionel Sambuc 				END(x)
642fe8fb19SBen Gras 
652fe8fb19SBen Gras #define RSYSCALL_NOERROR(x)	PSEUDO_NOERROR(x,x)
662fe8fb19SBen Gras 
672fe8fb19SBen Gras #define RSYSCALL(x)		PSEUDO(x,x)
682fe8fb19SBen Gras 
692fe8fb19SBen Gras #define	WSYSCALL(weak,strong)	WEAK_ALIAS(weak,strong)		;\
702fe8fb19SBen Gras 				PSEUDO(strong,weak)
71