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