xref: /openbsd-src/sys/arch/powerpc/include/asm.h (revision a0747c9f67a4ae71ccb71e62a28d1ea19e06a63c)
1 /*	$OpenBSD: asm.h,v 1.16 2020/11/28 19:49:30 gkoehler 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(x) \
73 	.text; .align 2; .globl x; .type x,@function; x:
74 
75 #if defined(PROF) || defined(GPROF)
76 # define _PROF_PROLOGUE(y)	\
77 	.section ".data"; \
78 	.align 2; \
79 _TMP_LABEL(y):; \
80 	.long 0; \
81 	.section ".text"; \
82 	mflr 0; \
83 	addis 11, 11, _TMP_LABEL(y)@ha; \
84 	stw 0, 4(1); \
85 	addi 0, 11,_TMP_LABEL(y)@l; \
86 	bl _mcount;
87 #else
88 # define _PROF_PROLOGUE(y)
89 #endif
90 
91 #define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE(y)
92 #define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE(y)
93 #define	END(y)		.size y, . - y
94 
95 #define STRONG_ALIAS(alias,sym) \
96 	.global alias; .set alias,sym
97 #define WEAK_ALIAS(alias,sym) \
98 	.weak alias; .set alias,sym
99 
100 #if defined(_RET_PROTECTOR)
101 # if defined(__PIC__)
102 #  define RETGUARD_LOAD_RANDOM(x, reg)					\
103 	bcl	20, 31, 66f;						\
104 66:	mflr	reg;							\
105 	addis	reg, reg, (__retguard_ ## x - 66b)@ha;			\
106 	lwz	reg, ((__retguard_ ## x - 66b)@l)(reg)
107 # else
108 #  define RETGUARD_LOAD_RANDOM(x, reg)					\
109 	lis	reg, (__retguard_ ## x)@ha;				\
110 	lwz	reg, ((__retguard_ ## x)@l)(reg)
111 # endif
112 # define RETGUARD_SETUP(x, reg, retreg)					\
113 	mflr	retreg;							\
114 	RETGUARD_SETUP_LATE(x, reg, retreg)
115 # define RETGUARD_SETUP_LATE(x, reg, retreg)				\
116 	RETGUARD_SYMBOL(x);						\
117 	RETGUARD_LOAD_RANDOM(x, reg);					\
118 	xor	reg, reg, retreg
119 # define RETGUARD_CHECK(x, reg, retreg)					\
120 	xor	reg, reg, retreg;					\
121 	RETGUARD_LOAD_RANDOM(x, %r10);					\
122 	mtlr	retreg;							\
123 	twne	reg, %r10
124 # define RETGUARD_SAVE(reg, loc)					\
125 	stw reg, loc
126 # define RETGUARD_LOAD(reg, loc)					\
127 	lwz reg, loc
128 # define RETGUARD_SYMBOL(x)						\
129 	.ifndef __retguard_ ## x;					\
130 	.hidden __retguard_ ## x;					\
131 	.type   __retguard_ ## x,@object;				\
132 	.pushsection .openbsd.randomdata.retguard,"aw",@progbits; 	\
133 	.weak   __retguard_ ## x;					\
134 	.p2align 2;							\
135 	__retguard_ ## x: ;						\
136 	.long 0;							\
137 	.size __retguard_ ## x, 4;					\
138 	.popsection;							\
139 	.endif
140 #else
141 # define RETGUARD_LOAD_RANDOM(x, reg)
142 # define RETGUARD_SETUP(x, reg, retreg)
143 # define RETGUARD_SETUP_LATE(x, reg, retreg)
144 # define RETGUARD_CHECK(x, reg, retreg)
145 # define RETGUARD_SAVE(reg, loc)
146 # define RETGUARD_LOAD(reg, loc)
147 # define RETGUARD_SYMBOL(x)
148 #endif
149 
150 #endif /* !_POWERPC_ASM_H_ */
151