asm.h revision 1.12.12.1 1 /* $NetBSD: asm.h,v 1.12.12.1 2014/02/15 16:18:36 matt 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 * from: @(#)asm.h 5.5 (Berkeley) 5/7/91
35 */
36
37 #ifndef _ARM32_ASM_H_
38 #define _ARM32_ASM_H_
39
40 #include <arm/cdefs.h>
41
42 /* .syntax unified */
43
44 #ifdef __thumb__
45 #define THUMB_INSN(n) n
46 #else
47 #define THUMB_INSN(n)
48 #endif
49
50 #define UPPER16(n) (((n) >> 16) & 0xffff)
51 #define LOWER16(n) ((n) & 0xffff)
52
53 #define __BIT(n) (1 << (n))
54 #define __BITS(hi,lo) ((~((~0)<<((hi)+1)))&((~0)<<(lo)))
55
56 #define _C_LABEL(x) x
57 #define _ASM_LABEL(x) x
58
59 #ifdef __STDC__
60 # define __CONCAT(x,y) x ## y
61 # define __STRING(x) #x
62 #else
63 # define __CONCAT(x,y) x/**/y
64 # define __STRING(x) "x"
65 #endif
66
67 #ifndef _ALIGN_TEXT
68 # define _ALIGN_TEXT .align 2
69 #endif
70
71 #ifndef _TEXT_SECTION
72 #define _TEXT_SECTION .text
73 #endif
74 /*
75 * gas/arm uses @ as a single comment character and thus cannot be used here
76 * Instead it recognised the # instead of an @ symbols in .type directives
77 * We define a couple of macros so that assembly code will not be dependent
78 * on one or the other.
79 */
80 #define _ASM_TYPE_FUNCTION %function
81 #define _ASM_TYPE_OBJECT %object
82 #define _THUMB_ENTRY(x) \
83 _TEXT_SECTION; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; \
84 .thumb_func; .code 16; x:
85 #define _ARM_ENTRY(x) \
86 _TEXT_SECTION; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; \
87 .code 32; x:
88 #ifdef __thumb__
89 #define _ENTRY(x) _THUMB_ENTRY(x)
90 #else
91 #define _ENTRY(x) _ARM_ENTRY(x)
92 #endif
93 #define _END(x) .size x,.-x
94
95 #ifdef GPROF
96 # define _PROF_PROLOGUE \
97 mov ip, lr; bl __mcount
98 #else
99 # define _PROF_PROLOGUE
100 #endif
101
102 #define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
103 #define ENTRY_NP(y) _ENTRY(_C_LABEL(y))
104 #define END(y) _END(_C_LABEL(y))
105 #define ARM_ENTRY(y) _ARM_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
106 #define ARM_ENTRY_NP(y) _ARM_ENTRY(_C_LABEL(y))
107 #define THUMB_ENTRY(y) _THUMB_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
108 #define THUMB_ENTRY_NP(y) _THUMB_ENTRY(_C_LABEL(y))
109 #define END(y) _END(_C_LABEL(y))
110 #define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
111 #define ASENTRY_NP(y) _ENTRY(_ASM_LABEL(y))
112 #define ASEND(y) _END(_ASM_LABEL(y))
113 #define ARM_ASENTRY(y) _ARM_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
114 #define ARM_ASENTRY_NP(y) _ARM_ENTRY(_ASM_LABEL(y))
115 #define THUMB_ASENTRY(y) _THUMB_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
116 #define THUMB_ASENTRY_NP(y) _THUMB_ENTRY(_ASM_LABEL(y))
117
118 #define ASMSTR .asciz
119
120 #ifdef __PIC__
121 #define REL_SYM(a, b) ((a) - (b))
122 #define PLT_SYM(x) x
123 #define GOT_SYM(x) PIC_SYM(x, GOT)
124 #define GOT_GET(x,got,sym) \
125 ldr x, sym; \
126 ldr x, [x, got]
127 #define GOT_INIT(got,gotsym,pclabel) \
128 ldr got, gotsym; \
129 pclabel: add got, got, pc
130 #ifdef __thumb__
131 #define GOT_INITSYM(gotsym,pclabel) \
132 .align 0; \
133 gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+4)
134 #else
135 #define GOT_INITSYM(gotsym,pclabel) \
136 .align 0; \
137 gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+8)
138 #endif
139
140 #ifdef __STDC__
141 #define PIC_SYM(x,y) x ## ( ## y ## )
142 #else
143 #define PIC_SYM(x,y) x/**/(/**/y/**/)
144 #endif
145
146 #else
147 #define REL_SYM(a, b) (a)
148 #define PLT_SYM(x) x
149 #define GOT_SYM(x) x
150 #define GOT_GET(x,got,sym) \
151 ldr x, sym;
152 #define GOT_INIT(got,gotsym,pclabel)
153 #define GOT_INITSYM(gotsym,pclabel)
154 #define PIC_SYM(x,y) x
155 #endif /* __PIC__ */
156
157 #define RCSID(x) .pushsection ".ident"; .asciz x; .popsection
158
159 #define WEAK_ALIAS(alias,sym) \
160 .weak alias; \
161 alias = sym
162
163 /*
164 * STRONG_ALIAS: create a strong alias.
165 */
166 #define STRONG_ALIAS(alias,sym) \
167 .globl alias; \
168 alias = sym
169
170 #ifdef __STDC__
171 #define WARN_REFERENCES(sym,msg) \
172 .pushsection .gnu.warning. ## sym; \
173 .ascii msg; \
174 .popsection
175 #else
176 #define WARN_REFERENCES(sym,msg) \
177 .pushsection .gnu.warning./**/sym; \
178 .ascii msg; \
179 .popsection
180 #endif /* __STDC__ */
181
182 #ifdef __thumb__
183 # define XPUSH push
184 # define XPOP pop
185 # define XPOPRET pop {pc}
186 #else
187 # define XPUSH stmfd sp!,
188 # define XPOP ldmfd sp!,
189 # ifdef _ARM_ARCH_5
190 # define XPOPRET ldmfd sp!, {pc}
191 # else
192 # define XPOPRET ldmfd sp!, {lr}; mov pc, lr
193 # endif
194 #endif
195
196 #if defined (_ARM_ARCH_4T)
197 # define RET bx lr
198 # define RETr(r) bx r
199 # if defined(__thumb__)
200 # if defined(_ARM_ARCH_7)
201 # define RETc(c) it c; __CONCAT(bx,c) lr
202 # endif
203 # else
204 # define RETc(c) __CONCAT(bx,c) lr
205 # endif
206 #else
207 # define RET mov pc, lr
208 # define RETr(r) mov pc, r
209 # define RETc(c) __CONCAT(mov,c) pc, lr
210 #endif
211
212 #ifdef _ARM_ARCH_7
213 #define KMODTRAMPOLINE(n) \
214 _ENTRY(__wrap_ ## n) \
215 movw ip, #:lower16:n; \
216 movt ip, #:upper16:n; \
217 bx ip
218 #elif defined(_ARM_ARCH_4T)
219 #define KMODTRAMPOLINE(n) \
220 _ENTRY(__wrap_ ## n) \
221 ldr ip, [pc]; \
222 bx ip; \
223 .word n
224 #else
225 #define KMODTRAMPOLINE(n) \
226 _ENTRY(__wrap_ ## n) \
227 ldr pc, [pc, #-4]; \
228 .word n
229 #endif
230
231 .macro lsls a,b,c
232 movs \a, \b, lsl \c
233 .endm
234 .macro lsl a,b,c
235 mov \a, \b, lsl \c
236 .endm
237 .macro lsrs a,b,c
238 movs \a, \b, lsr \c
239 .endm
240 .macro lsr a,b,c
241 mov \a, \b, lsr \c
242 .endm
243 .macro negs a,b
244 rsbs \a, \b, #0
245 .endm
246 .macro neg a,b
247 rsb \a, \b, #0
248 .endm
249 .macro ldrd a,b,c,d
250 ldrald \a, \c, \d
251 .endm
252 .macro strd a,b,c,d
253 strald \a, \c, \d
254 .endm
255 #define strbge strgeb
256 #define strbgt strgtb
257 #define ldrbge ldrgeb
258 #define ldrbgt ldrgtb
259 #define ldmdbeq ldmeqdb
260 #define ldrtne ldrnet
261 #define ldrtge ldrget
262 #define ldrtgt ldrgtt
263 #define ldrbtge ldrgebt
264 #define ldrbtgt ldrgtbt
265 #define strtge strget
266 #define strtne strnet
267 #define strbtge strgebt
268 #define strbtgt strgtbt
269
270 #endif /* !_ARM_ASM_H_ */
271