xref: /openbsd-src/sys/arch/powerpc/include/asm.h (revision 78fec973f57e9fc9edd564490c79661460ad807b)
1 /*	$OpenBSD: asm.h,v 1.17 2022/06/10 01:56:02 guenther Exp $	*/
2 /*	$NetBSD: asm.h,v 1.1 1996/09/30 16:34:20 ws Exp $	*/
3 
4 /*
5  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
6  * Copyright (C) 1995, 1996 TooLs GmbH.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed by TooLs GmbH.
20  * 4. The name of TooLs GmbH may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef _POWERPC_ASM_H_
36 #define _POWERPC_ASM_H_
37 
38 /* XXX */
39 #define TARGET_ELF
40 
41 #ifdef __PIC__
42 #define PIC_PROLOGUE	XXX
43 #define PIC_EPILOGUE	XXX
44 #ifdef	__STDC__
45 #define PIC_PLT(x)	x ## @plt
46 #define PIC_GOT(x)	XXX
47 #define PIC_GOTOFF(x)	XXX
48 #else	/* not __STDC__ */
49 #define PIC_PLT(x)	x/**/@plt
50 #define PIC_GOT(x)	XXX
51 #define PIC_GOTOFF(x)	XXX
52 #endif	/* __STDC__ */
53 #else
54 #define PIC_PROLOGUE
55 #define PIC_EPILOGUE
56 #define PIC_PLT(x)	x
57 #define PIC_GOT(x)	x
58 #define PIC_GOTOFF(x)	x
59 #endif
60 
61 #ifdef TARGET_ELF
62 # define _C_LABEL(x)	x
63 #endif
64 #define	_ASM_LABEL(x)	x
65 
66 #ifdef __STDC__
67 # define _TMP_LABEL(x)	.L_ ## x
68 #else
69 # define _TMP_LABEL(x)	.L_/**/x
70 #endif
71 
72 #define _ENTRY_NB(x) \
73 	.text; .align 2; .type x,@function; x:
74 #define _ENTRY(x)	.globl x; _ENTRY_NB(x)
75 
76 #if defined(PROF) || defined(GPROF)
77 # define _PROF_PROLOGUE(y)	\
78 	.section ".data"; \
79 	.align 2; \
80 _TMP_LABEL(y):; \
81 	.long 0; \
82 	.section ".text"; \
83 	mflr 0; \
84 	addis 11, 11, _TMP_LABEL(y)@ha; \
85 	stw 0, 4(1); \
86 	addi 0, 11,_TMP_LABEL(y)@l; \
87 	bl _mcount;
88 #else
89 # define _PROF_PROLOGUE(y)
90 #endif
91 
92 #define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE(y)
93 #define	ENTRY_NB(y)	_ENTRY_NB(y); _PROF_PROLOGUE(y)
94 #define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE(y)
95 #define	END(y)		.size y, . - y
96 
97 #define STRONG_ALIAS(alias,sym) \
98 	.global alias; .set alias,sym
99 #define WEAK_ALIAS(alias,sym) \
100 	.weak alias; .set alias,sym
101 
102 #if defined(_RET_PROTECTOR)
103 # if defined(__PIC__)
104 #  define RETGUARD_LOAD_RANDOM(x, reg)					\
105 	bcl	20, 31, 66f;						\
106 66:	mflr	reg;							\
107 	addis	reg, reg, (__retguard_ ## x - 66b)@ha;			\
108 	lwz	reg, ((__retguard_ ## x - 66b)@l)(reg)
109 # else
110 #  define RETGUARD_LOAD_RANDOM(x, reg)					\
111 	lis	reg, (__retguard_ ## x)@ha;				\
112 	lwz	reg, ((__retguard_ ## x)@l)(reg)
113 # endif
114 # define RETGUARD_SETUP(x, reg, retreg)					\
115 	mflr	retreg;							\
116 	RETGUARD_SETUP_LATE(x, reg, retreg)
117 # define RETGUARD_SETUP_LATE(x, reg, retreg)				\
118 	RETGUARD_SYMBOL(x);						\
119 	RETGUARD_LOAD_RANDOM(x, reg);					\
120 	xor	reg, reg, retreg
121 # define RETGUARD_CHECK(x, reg, retreg)					\
122 	xor	reg, reg, retreg;					\
123 	RETGUARD_LOAD_RANDOM(x, %r10);					\
124 	mtlr	retreg;							\
125 	twne	reg, %r10
126 # define RETGUARD_SAVE(reg, loc)					\
127 	stw reg, loc
128 # define RETGUARD_LOAD(reg, loc)					\
129 	lwz reg, loc
130 # define RETGUARD_SYMBOL(x)						\
131 	.ifndef __retguard_ ## x;					\
132 	.hidden __retguard_ ## x;					\
133 	.type   __retguard_ ## x,@object;				\
134 	.pushsection .openbsd.randomdata.retguard,"aw",@progbits; 	\
135 	.weak   __retguard_ ## x;					\
136 	.p2align 2;							\
137 	__retguard_ ## x: ;						\
138 	.long 0;							\
139 	.size __retguard_ ## x, 4;					\
140 	.popsection;							\
141 	.endif
142 #else
143 # define RETGUARD_LOAD_RANDOM(x, reg)
144 # define RETGUARD_SETUP(x, reg, retreg)
145 # define RETGUARD_SETUP_LATE(x, reg, retreg)
146 # define RETGUARD_CHECK(x, reg, retreg)
147 # define RETGUARD_SAVE(reg, loc)
148 # define RETGUARD_LOAD(reg, loc)
149 # define RETGUARD_SYMBOL(x)
150 #endif
151 
152 #endif /* !_POWERPC_ASM_H_ */
153