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