asm.h revision 1.20 1 /* $NetBSD: asm.h,v 1.20 2005/12/31 05:06:33 uwe Exp $ */
2
3 /*-
4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * William Jolitz.
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)asm.h 5.5 (Berkeley) 5/7/91
35 */
36
37 #ifndef _SH3_ASM_H_
38 #define _SH3_ASM_H_
39
40 /*
41 * The old NetBSD/sh3 ELF toolchain used underscores. The new
42 * NetBSD/sh3 ELF toolchain does not. The C pre-processor
43 * defines __NO_LEADING_UNDERSCORES__ for the new ELF toolchain.
44 */
45
46 #if defined(__ELF__) && defined(__NO_LEADING_UNDERSCORES__)
47 # define _C_LABEL(x) x
48 #else
49 #ifdef __STDC__
50 # define _C_LABEL(x) _ ## x
51 #else
52 # define _C_LABEL(x) _/**/x
53 #endif
54 #endif
55 #define _ASM_LABEL(x) x
56
57 /* let kernels and others override entrypoint alignment */
58 #ifndef _ALIGN_TEXT
59 # define _ALIGN_TEXT .align 2
60 #endif
61
62 #ifdef __ELF__
63 #define _ENTRY(x) \
64 .text ;\
65 _ALIGN_TEXT ;\
66 .globl x ;\
67 .type x,@function ;\
68 x:
69 #else /* !__ELF__ */
70 #define _ENTRY(x) \
71 .text ;\
72 _ALIGN_TEXT ;\
73 .globl x ;\
74 x:
75 #endif /* !__ELF__ */
76
77 #ifdef GPROF
78 #define _PROF_PROLOGUE \
79 mov.l 1f,r1 ; \
80 mova 2f,r0 ; \
81 jmp @r1 ; \
82 nop ; \
83 .align 2 ; \
84 1: .long __mcount ; \
85 2:
86 #else /* !GPROF */
87 #define _PROF_PROLOGUE
88 #endif /* !GPROF */
89
90 #define ENTRY(y) _ENTRY(_C_LABEL(y)) _PROF_PROLOGUE
91 #define NENTRY(y) _ENTRY(_C_LABEL(y))
92 #define ASENTRY(y) _ENTRY(_ASM_LABEL(y)) _PROF_PROLOGUE
93
94 #ifdef __ELF__
95 #define ALTENTRY(name) \
96 .globl _C_LABEL(name) ;\
97 .type _C_LABEL(name),@function ;\
98 _C_LABEL(name):
99 #else
100 #define ALTENTRY(name) \
101 .globl _C_LABEL(name) ;\
102 _C_LABEL(name):
103 #endif
104
105
106 /*
107 * Hide the gory details of PIC calls vs. normal calls. Use as in the
108 * following example:
109 *
110 * sts.l pr, @-sp
111 * PIC_PROLOGUE(.L_got, r0) ! saves old r12 on stack
112 * ...
113 * mov.l .L_function_1, r0
114 * 1: CALL r0 ! each call site needs a label
115 * nop
116 * ...
117 * mov.l .L_function_2, r0
118 * 2: CALL r0
119 * nop
120 * ...
121 * PIC_EPILOGUE ! restores r12 from stack
122 * lds.l @sp+, pr ! so call in right order
123 * rts
124 * nop
125 *
126 * .align 2
127 * .L_got:
128 * PIC_GOT_DATUM
129 * .L_function_1: ! if you call the same function twice
130 * CALL_DATUM(function, 1b) ! provide call datum for each call
131 * .L_function_2:
132 * CALL_DATUM(function, 2b)
133 */
134
135 #ifdef PIC
136
137 #define PIC_PLT(x) x@PLT
138 #define PIC_GOT(x) x@GOT
139 #define PIC_GOTOFF(x) x@GOTOFF
140
141 #define PIC_PROLOGUE(got, temp) \
142 mov.l r12, @-sp; \
143 mov.l got, r12; \
144 mova got, temp; \
145 add temp, r12
146
147 #define PIC_EPILOGUE \
148 mov.l @sp+, r12
149
150 #define PIC_GOT_DATUM \
151 .long _GLOBAL_OFFSET_TABLE_
152
153 #define CALL bsrf
154 #define JUMP braf
155
156 #define CALL_DATUM(function, lpcs) \
157 .long PIC_PLT(function) - ((lpcs) + 4 - (.))
158
159 /*
160 * This will result in text relocations in the shared library,
161 * unless the function is local or has hidden or protected visibility.
162 * Does not require PIC prologue.
163 */
164 #define CALL_DATUM_LOCAL(function, lpcs) \
165 .long function - ((lpcs) + 4)
166
167 #else /* !PIC */
168
169 #define PIC_PROLOGUE(label, temp)
170 #define PIC_EPILOGUE
171 #define PIC_GOT_DATUM
172
173 #define CALL jsr @
174 #define JUMP jmp @
175
176 #define CALL_DATUM(function, lpcs) \
177 .long function
178
179 #define CALL_DATUM_LOCAL(function, lpcs) \
180 .long function
181
182 #endif /* !PIC */
183
184
185 #define ASMSTR .asciz
186
187 #ifdef __ELF__
188 #define RCSID(x) .section .ident; .asciz x; .previous
189 #else
190 #define RCSID(x) .text; .asciz x
191 #endif
192
193 #ifdef NO_KERNEL_RCSIDS
194 #define __KERNEL_RCSID(_n, _s) /* nothing */
195 #else
196 #define __KERNEL_RCSID(_n, _s) RCSID(_s)
197 #endif
198
199 #ifdef __ELF__
200 #define WEAK_ALIAS(alias,sym) \
201 .weak _C_LABEL(alias); \
202 _C_LABEL(alias) = _C_LABEL(sym)
203 #endif
204
205 #define WARN_REFERENCES(_sym,_msg) \
206 .section .gnu.warning._sym; .ascii _msg; .previous
207
208 #endif /* !_SH3_ASM_H_ */
209