xref: /netbsd-src/sys/arch/m68k/include/asm.h (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: asm.h,v 1.23 2001/05/27 01:01:08 chs Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the NetBSD
21  *	Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Copyright (c) 1994 Allen Briggs
41  * All rights reserved.
42  *
43  * Gleaned from locore.s and sun3 asm.h which had the following copyrights:
44  * locore.s:
45  * Copyright (c) 1988 University of Utah.
46  * Copyright (c) 1982, 1990 The Regents of the University of California.
47  * sun3/include/asm.h:
48  * Copyright (c) 1993 Adam Glass
49  * Copyright (c) 1990 The Regents of the University of California.
50  *
51  * Redistribution and use in source and binary forms, with or without
52  * modification, are permitted provided that the following conditions
53  * are met:
54  * 1. Redistributions of source code must retain the above copyright
55  *    notice, this list of conditions and the following disclaimer.
56  * 2. Redistributions in binary form must reproduce the above copyright
57  *    notice, this list of conditions and the following disclaimer in the
58  *    documentation and/or other materials provided with the distribution.
59  * 3. All advertising materials mentioning features or use of this software
60  *    must display the following acknowledgement:
61  *	This product includes software developed by the University of
62  *	California, Berkeley and its contributors.
63  * 4. Neither the name of the University nor the names of its contributors
64  *    may be used to endorse or promote products derived from this software
65  *    without specific prior written permission.
66  *
67  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
68  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
69  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
70  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
71  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
72  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
73  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
74  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
75  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
76  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
77  * SUCH DAMAGE.
78  */
79 
80 #ifndef _M68K_ASM_H_
81 #define _M68K_ASM_H_
82 
83 #if defined(__ELF__) && defined(PIC)
84 #define PIC_PLT(name)	name@PLTPC
85 #else
86 #define PIC_PLT(name)	name
87 #endif
88 
89 #ifdef __ELF__
90 # if __STDC__
91 #  define _C_LABEL(name)	name
92 # else
93 #  define _C_LABEL(name)	name
94 #endif /* __STDC__ */
95 #else /* __ELF__ */
96 # if __STDC__
97 #  define _C_LABEL(name)	_ ## name
98 # else
99 #  define _C_LABEL(name)	_/**/name
100 # endif /* __STDC__ */
101 #endif /* __ELF__ */
102 
103 #define	_ASM_LABEL(name)	name
104 
105 #define	_ENTRY(name) \
106 	.text; .even; .globl name; .type name,@function; name:
107 
108 #ifdef __ELF__
109 #define	MCOUNT_ENTRY	__mcount
110 #else
111 #define	MCOUNT_ENTRY	mcount
112 #endif
113 
114 #ifdef GPROF
115 #define _PROF_PROLOG	link %a6,#0; jbsr MCOUNT_ENTRY; unlk %a6
116 #else
117 #define _PROF_PROLOG
118 #endif
119 
120 #define ENTRY(name)		_ENTRY(_C_LABEL(name)) _PROF_PROLOG
121 #define	ASENTRY(name)		_ENTRY(_ASM_LABEL(name)) _PROF_PROLOG
122 
123 #define	ENTRY_NOPROFILE(name)	_ENTRY(_C_LABEL(name))
124 #define	ASENTRY_NOPROFILE(name)	_ENTRY(_ASM_LABEL(name))
125 
126 /*
127  * The m68k ALTENTRY macro is very different than the traditional
128  * implementation used by other NetBSD ports.  Usually ALTENTRY
129  * simply provides an alternate function entry point.  The m68k
130  * definition takes a second argument and jumps inside the second
131  * function when profiling is enabled.
132  *
133  * The m68k behavior is similar to the ENTRY2 macro found in
134  * solaris' asm_linkage.h.
135  *
136  * Providing ENTRY2 and changing all the code that uses ALTENTRY
137  * to use it would be a desirable change.
138  */
139 #ifdef PROF
140 #define ALTENTRY(name, rname)	ENTRY(name); jra rname+12
141 #else
142 #define ALTENTRY(name, rname)	_ENTRY(_C_LABEL(name))
143 #endif
144 
145 #define RCSID(x)	.text			;	\
146 			.asciz x		;	\
147 			.even
148 
149 /*
150  * Global variables of whatever sort.
151  */
152 #define	GLOBAL(x)					\
153 		.globl	_C_LABEL(x)		;	\
154 	_C_LABEL(x):
155 
156 #define	ASGLOBAL(x)					\
157 		.globl	_ASM_LABEL(x)		;	\
158 	_ASM_LABEL(x):
159 
160 /*
161  * ...and local variables.
162  */
163 #define	LOCAL(x)					\
164 	_C_LABEL(x):
165 
166 #define	ASLOCAL(x)					\
167 	_ASM_LABEL(x):
168 
169 /*
170  * Items in the BSS segment.
171  */
172 #define	BSS(name, size)					\
173 	.comm	_C_LABEL(name),size
174 
175 #define	ASBSS(name, size)				\
176 	.comm	_ASM_LABEL(name),size
177 
178 #ifdef _KERNEL
179 /*
180  * Shorthand for calling panic().
181  * Note the side-effect: it uses up the 9: label, so be careful!
182  */
183 #define	PANIC(x)					\
184 		pea	9f			;	\
185 		jbsr	_C_LABEL(panic)		;	\
186 	9:	.asciz	x			;	\
187 		.even
188 
189 #endif /* _KERNEL */
190 
191 /*
192  * Shorthand for defining vectors for the vector table.
193  */
194 #define	VECTOR(x)					\
195 	.long	_C_LABEL(x)
196 
197 #define	ASVECTOR(x)					\
198 	.long	_ASM_LABEL(x)
199 
200 #define	VECTOR_UNUSED					\
201 	.long	0
202 
203 #ifdef __ELF__
204 #define	WEAK_ALIAS(alias,sym)						\
205 	.weak alias;							\
206 	alias = sym
207 #endif
208 
209 #ifdef __STDC__
210 #define	__STRING(x)			#x
211 #define	WARN_REFERENCES(sym,msg)					\
212 	.stabs msg ## ,30,0,0,0 ;					\
213 	.stabs __STRING(_ ## sym) ## ,1,0,0,0
214 #else
215 #define	__STRING(x)			"x"
216 #define	WARN_REFERENCES(sym,msg)					\
217 	.stabs msg,30,0,0,0 ;						\
218 	.stabs __STRING(_/**/sym),1,0,0,0
219 #endif /* __STDC__ */
220 
221 /*
222  * Macros to hide shortcomings in the 68010.
223  */
224 #ifndef __mc68010__
225 #define	EXTBL(reg)					\
226 	extbl	reg
227 #else	/* __mc68010__ */
228 #define	EXTBL(reg)					\
229 	extw	reg		;			\
230 	extl	reg
231 #endif	/* __mc68010__ */
232 
233 #endif /* _M68K_ASM_H_ */
234