xref: /freebsd/sys/powerpc/include/asm.h (revision 4928135658a9d0eaee37003df6137ab363fcb0b4)
1 /*-
2  * SPDX-License-Identifier: BSD-4-Clause
3  *
4  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5  * Copyright (C) 1995, 1996 TooLs GmbH.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by TooLs GmbH.
19  * 4. The name of TooLs GmbH may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *	$NetBSD: asm.h,v 1.6.18.1 2000/07/25 08:37:14 kleink Exp $
34  * $FreeBSD$
35  */
36 
37 #ifndef _MACHINE_ASM_H_
38 #define	_MACHINE_ASM_H_
39 
40 #include <sys/cdefs.h>
41 
42 #if defined(PIC) && !defined(__powerpc64__)
43 #define	PIC_PROLOGUE	XXX
44 #define	PIC_EPILOGUE	XXX
45 #define	PIC_PLT(x)	x@plt
46 #ifdef	__STDC__
47 #define	PIC_GOT(x)	XXX
48 #else	/* not __STDC__ */
49 #define	PIC_GOT(x)	XXX
50 #endif	/* __STDC__ */
51 #else
52 #define	PIC_PROLOGUE
53 #define	PIC_EPILOGUE
54 #define	PIC_PLT(x)	x
55 #define PIC_GOT(x)	x
56 #endif
57 
58 #define	CNAME(csym)		csym
59 #define	ASMNAME(asmsym)		asmsym
60 #ifdef __powerpc64__
61 #define	HIDENAME(asmsym)	__CONCAT(_,asmsym)
62 #else
63 #define	HIDENAME(asmsym)	__CONCAT(.,asmsym)
64 #endif
65 
66 #if !defined(_CALL_ELF) || _CALL_ELF == 1
67 #ifdef _KERNEL
68 /* ELFv1 kernel uses global dot symbols */
69 #define	DOT_LABEL(name)		__CONCAT(.,name)
70 #define	TYPE_ENTRY(name)	.size	name,24; \
71 				.type	DOT_LABEL(name),@function; \
72 				.globl	DOT_LABEL(name);
73 #define	END_SIZE(name)		.size	DOT_LABEL(name),.-DOT_LABEL(name);
74 #else /* !_KERNEL */
75 /* ELFv1 user code uses local function entry points */
76 #define	DOT_LABEL(name)		__CONCAT(.L.,name)
77 #define	TYPE_ENTRY(name)	.type	name,@function;
78 #define	END_SIZE(name)		.size	name,.-DOT_LABEL(name);
79 #endif /* _KERNEL */
80 #else
81 /* ELFv2 doesn't have any of this complication */
82 #define	DOT_LABEL(name)		name
83 #define	TYPE_ENTRY(name)	.type	name,@function;
84 #define	END_SIZE(name)		.size	name,.-DOT_LABEL(name);
85 #endif
86 
87 #define	_GLOBAL(name) \
88 	.data; \
89 	.p2align 2; \
90 	.globl	name; \
91 	name:
92 
93 #ifdef __powerpc64__
94 #define TOC_NAME_FOR_REF(name)	__CONCAT(.L,name)
95 #define	TOC_REF(name)	TOC_NAME_FOR_REF(name)@toc
96 #define TOC_ENTRY(name) \
97 	.section ".toc","aw"; \
98 	TOC_NAME_FOR_REF(name): \
99         .tc name[TC],name
100 #endif
101 
102 #ifdef __powerpc64__
103 
104 #if !defined(_CALL_ELF) || _CALL_ELF == 1
105 #define	_ENTRY(name) \
106 	.section ".text"; \
107 	.p2align 2; \
108 	.globl	name; \
109 	.section ".opd","aw"; \
110 	.p2align 3; \
111 	name: \
112 	.quad	DOT_LABEL(name),.TOC.@tocbase,0; \
113 	.previous; \
114 	.p2align 4; \
115 	TYPE_ENTRY(name) \
116 DOT_LABEL(name):
117 #else
118 #define	_ENTRY(name) \
119 	.text; \
120 	.p2align 4; \
121 	.globl	name; \
122 	.type	name,@function; \
123 name: \
124 	addis	%r2, %r12, (.TOC.-name)@ha; \
125 	addi	%r2, %r2, (.TOC.-name)@l; \
126 	.localentry name, .-name;
127 #endif
128 
129 #define	_END(name) \
130 	.long	0; \
131 	.byte	0,0,0,0,0,0,0,0; \
132 	END_SIZE(name)
133 
134 #define	LOAD_ADDR(reg, var) \
135 	lis	reg, var@highest; \
136 	ori	reg, reg, var@higher; \
137 	rldicr	reg, reg, 32, 31; \
138 	oris	reg, reg, var@h; \
139 	ori	reg, reg, var@l;
140 #else /* !__powerpc64__ */
141 #define	_ENTRY(name) \
142 	.text; \
143 	.p2align 4; \
144 	.globl	name; \
145 	.type	name,@function; \
146 	name:
147 #define	_END(name)
148 
149 #define	LOAD_ADDR(reg, var) \
150 	lis	reg, var@ha; \
151 	ori	reg, reg, var@l;
152 #endif /* __powerpc64__ */
153 
154 #if defined(PROF) || (defined(_KERNEL) && defined(GPROF))
155 # ifdef __powerpc64__
156 #   define	_PROF_PROLOGUE	mflr 0;					\
157 				std 3,48(1);				\
158 				std 4,56(1);				\
159 				std 5,64(1);				\
160 				std 0,16(1);				\
161 				stdu 1,-112(1);				\
162 				bl _mcount;				\
163 				nop;					\
164 				ld 0,112+16(1);				\
165 				ld 3,112+48(1);				\
166 				ld 4,112+56(1);				\
167 				ld 5,112+64(1);				\
168 				mtlr 0;					\
169 				addi 1,1,112
170 # else
171 #   define	_PROF_PROLOGUE	mflr 0; stw 0,4(1); bl _mcount
172 # endif
173 #else
174 # define	_PROF_PROLOGUE
175 #endif
176 
177 #define	ASENTRY(y)	_ENTRY(ASMNAME(y)); _PROF_PROLOGUE
178 #define	END(y)		_END(CNAME(y))
179 #define	ENTRY(y)	_ENTRY(CNAME(y)); _PROF_PROLOGUE
180 #define	GLOBAL(y)	_GLOBAL(CNAME(y))
181 
182 #define	ASENTRY_NOPROF(y)	_ENTRY(ASMNAME(y))
183 #define	ENTRY_NOPROF(y)		_ENTRY(CNAME(y))
184 
185 #define	ASMSTR		.asciz
186 
187 #define	RCSID(x)	.text; .asciz x
188 
189 #undef __FBSDID
190 #if !defined(lint) && !defined(STRIP_FBSDID)
191 #define __FBSDID(s)	.ident s
192 #else
193 #define __FBSDID(s)	/* nothing */
194 #endif /* not lint and not STRIP_FBSDID */
195 
196 #define	WEAK_REFERENCE(sym, alias)				\
197 	.weak alias;						\
198 	.equ alias,sym
199 
200 #ifdef __STDC__
201 #define	WARN_REFERENCES(_sym,_msg)				\
202 	.section .gnu.warning. ## _sym ; .ascii _msg ; .text
203 #else
204 #define	WARN_REFERENCES(_sym,_msg)				\
205 	.section .gnu.warning./**/_sym ; .ascii _msg ; .text
206 #endif /* __STDC__ */
207 
208 #endif /* !_MACHINE_ASM_H_ */
209