asm.h revision 1.20 1 1.20 matt /* $NetBSD: asm.h,v 1.20 2013/08/13 00:18:15 matt Exp $ */
2 1.1 bjh21
3 1.1 bjh21 /*
4 1.1 bjh21 * Copyright (c) 1990 The Regents of the University of California.
5 1.1 bjh21 * All rights reserved.
6 1.1 bjh21 *
7 1.1 bjh21 * This code is derived from software contributed to Berkeley by
8 1.1 bjh21 * William Jolitz.
9 1.1 bjh21 *
10 1.1 bjh21 * Redistribution and use in source and binary forms, with or without
11 1.1 bjh21 * modification, are permitted provided that the following conditions
12 1.1 bjh21 * are met:
13 1.1 bjh21 * 1. Redistributions of source code must retain the above copyright
14 1.1 bjh21 * notice, this list of conditions and the following disclaimer.
15 1.1 bjh21 * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 bjh21 * notice, this list of conditions and the following disclaimer in the
17 1.1 bjh21 * documentation and/or other materials provided with the distribution.
18 1.5 agc * 3. Neither the name of the University nor the names of its contributors
19 1.1 bjh21 * may be used to endorse or promote products derived from this software
20 1.1 bjh21 * without specific prior written permission.
21 1.1 bjh21 *
22 1.1 bjh21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1 bjh21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 bjh21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 bjh21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1 bjh21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 bjh21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 bjh21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 bjh21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 bjh21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 bjh21 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 bjh21 * SUCH DAMAGE.
33 1.1 bjh21 *
34 1.1 bjh21 * from: @(#)asm.h 5.5 (Berkeley) 5/7/91
35 1.1 bjh21 */
36 1.1 bjh21
37 1.1 bjh21 #ifndef _ARM32_ASM_H_
38 1.1 bjh21 #define _ARM32_ASM_H_
39 1.1 bjh21
40 1.9 matt #include <arm/cdefs.h>
41 1.9 matt
42 1.19 matt .syntax unified
43 1.19 matt
44 1.20 matt #ifdef __thumb__
45 1.20 matt #define THUMB_INSN(n) n
46 1.20 matt #else
47 1.20 matt #define THUMB_INSN(n)
48 1.20 matt #endif
49 1.20 matt
50 1.15 matt #define __BIT(n) (1 << (n))
51 1.16 matt #define __BITS(hi,lo) ((~((~0)<<((hi)+1)))&((~0)<<(lo)))
52 1.15 matt
53 1.12 matt #define _C_LABEL(x) x
54 1.1 bjh21 #define _ASM_LABEL(x) x
55 1.1 bjh21
56 1.1 bjh21 #ifdef __STDC__
57 1.1 bjh21 # define __CONCAT(x,y) x ## y
58 1.1 bjh21 # define __STRING(x) #x
59 1.1 bjh21 #else
60 1.1 bjh21 # define __CONCAT(x,y) x/**/y
61 1.1 bjh21 # define __STRING(x) "x"
62 1.1 bjh21 #endif
63 1.1 bjh21
64 1.1 bjh21 #ifndef _ALIGN_TEXT
65 1.19 matt # define _ALIGN_TEXT .align 2
66 1.1 bjh21 #endif
67 1.1 bjh21
68 1.1 bjh21 /*
69 1.1 bjh21 * gas/arm uses @ as a single comment character and thus cannot be used here
70 1.1 bjh21 * Instead it recognised the # instead of an @ symbols in .type directives
71 1.14 wiz * We define a couple of macros so that assembly code will not be dependent
72 1.1 bjh21 * on one or the other.
73 1.1 bjh21 */
74 1.9 matt #define _ASM_TYPE_FUNCTION %function
75 1.9 matt #define _ASM_TYPE_OBJECT %object
76 1.20 matt #define _THUMB_ENTRY(x) \
77 1.20 matt .text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; \
78 1.20 matt .thumb_func; .code 16; x:
79 1.20 matt #define _ARM_ENTRY(x) \
80 1.20 matt .text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; \
81 1.20 matt .code 32; x:
82 1.11 matt #ifdef __thumb__
83 1.20 matt #define _ENTRY(x) _THUMB_ENTRY(x)
84 1.11 matt #else
85 1.20 matt #define _ENTRY(x) _ARM_ENTRY(x)
86 1.11 matt #endif
87 1.9 matt #define _END(x) .size x,.-x
88 1.1 bjh21
89 1.1 bjh21 #ifdef GPROF
90 1.12 matt # define _PROF_PROLOGUE \
91 1.2 bjh21 mov ip, lr; bl __mcount
92 1.1 bjh21 #else
93 1.1 bjh21 # define _PROF_PROLOGUE
94 1.1 bjh21 #endif
95 1.1 bjh21
96 1.1 bjh21 #define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
97 1.1 bjh21 #define ENTRY_NP(y) _ENTRY(_C_LABEL(y))
98 1.11 matt #define END(y) _END(_C_LABEL(y))
99 1.1 bjh21 #define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
100 1.1 bjh21 #define ASENTRY_NP(y) _ENTRY(_ASM_LABEL(y))
101 1.9 matt #define ASEND(y) _END(_ASM_LABEL(y))
102 1.1 bjh21
103 1.1 bjh21 #define ASMSTR .asciz
104 1.3 matt
105 1.12 matt #if defined(PIC)
106 1.11 matt #ifdef __thumb__
107 1.11 matt #define PLT_SYM(x) x
108 1.11 matt #define GOT_SYM(x) PIC_SYM(x, GOTOFF)
109 1.11 matt #define GOT_GET(x,got,sym) \
110 1.11 matt ldr x, sym; \
111 1.11 matt add x, got; \
112 1.11 matt ldr x, [x]
113 1.11 matt #else
114 1.11 matt #define PLT_SYM(x) PIC_SYM(x, PLT)
115 1.11 matt #define GOT_SYM(x) PIC_SYM(x, GOT)
116 1.11 matt #define GOT_GET(x,got,sym) \
117 1.11 matt ldr x, sym; \
118 1.11 matt ldr x, [x, got]
119 1.11 matt #endif /* __thumb__ */
120 1.11 matt
121 1.11 matt #define GOT_INIT(got,gotsym,pclabel) \
122 1.11 matt ldr got, gotsym; \
123 1.11 matt add got, got, pc; \
124 1.11 matt pclabel:
125 1.11 matt #define GOT_INITSYM(gotsym,pclabel) \
126 1.11 matt gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) + (. - (pclabel+4))
127 1.11 matt
128 1.4 matt #ifdef __STDC__
129 1.4 matt #define PIC_SYM(x,y) x ## ( ## y ## )
130 1.4 matt #else
131 1.4 matt #define PIC_SYM(x,y) x/**/(/**/y/**/)
132 1.4 matt #endif
133 1.11 matt
134 1.3 matt #else
135 1.11 matt #define PLT_SYM(x) x
136 1.11 matt #define GOT_SYM(x) x
137 1.11 matt #define GOT_GET(x,got,sym) \
138 1.11 matt ldr x, sym;
139 1.11 matt #define GOT_INIT(got,gotsym,pclabel)
140 1.11 matt #define GOT_INITSYM(gotsym,pclabel)
141 1.4 matt #define PIC_SYM(x,y) x
142 1.12 matt #endif /* PIC */
143 1.1 bjh21
144 1.12 matt #define RCSID(x) .pushsection ".ident"; .asciz x; .popsection
145 1.1 bjh21
146 1.1 bjh21 #define WEAK_ALIAS(alias,sym) \
147 1.1 bjh21 .weak alias; \
148 1.1 bjh21 alias = sym
149 1.1 bjh21
150 1.8 christos /*
151 1.8 christos * STRONG_ALIAS: create a strong alias.
152 1.8 christos */
153 1.8 christos #define STRONG_ALIAS(alias,sym) \
154 1.8 christos .globl alias; \
155 1.8 christos alias = sym
156 1.8 christos
157 1.13 joerg #ifdef __STDC__
158 1.13 joerg #define WARN_REFERENCES(sym,msg) \
159 1.13 joerg .pushsection .gnu.warning. ## sym; \
160 1.13 joerg .ascii msg; \
161 1.13 joerg .popsection
162 1.13 joerg #else
163 1.1 bjh21 #define WARN_REFERENCES(sym,msg) \
164 1.13 joerg .pushsection .gnu.warning./**/sym; \
165 1.13 joerg .ascii msg; \
166 1.13 joerg .popsection
167 1.13 joerg #endif /* __STDC__ */
168 1.1 bjh21
169 1.11 matt #ifdef __thumb__
170 1.11 matt # define XPUSH push
171 1.11 matt # define XPOP pop
172 1.11 matt # define XPOPRET pop {pc}
173 1.11 matt #else
174 1.11 matt # define XPUSH stmfd sp!,
175 1.11 matt # define XPOP ldmfd sp!,
176 1.11 matt # ifdef _ARM_ARCH_5
177 1.11 matt # define XPOPRET ldmfd sp!, {pc}
178 1.11 matt # else
179 1.11 matt # define XPOPRET ldmfd sp!, {lr}; mov pc, lr
180 1.11 matt # endif
181 1.6 rearnsha #endif
182 1.11 matt
183 1.6 rearnsha #if defined (_ARM_ARCH_4T)
184 1.11 matt # define RET bx lr
185 1.17 matt # define RETr(r) bx r
186 1.19 matt # if defined(__thumb__)
187 1.19 matt # define RETc(c) it c; __CONCAT(bx,c) lr
188 1.19 matt # else
189 1.19 matt # define RETc(c) __CONCAT(bx,c) lr
190 1.19 matt # endif
191 1.6 rearnsha #else
192 1.11 matt # define RET mov pc, lr
193 1.17 matt # define RETr(r) mov pc, r
194 1.11 matt # define RETc(c) __CONCAT(mov,c) pc, lr
195 1.6 rearnsha #endif
196 1.6 rearnsha
197 1.18 matt #ifdef _ARM_ARCH_7
198 1.18 matt #define KMODTRAMPOLINE(n) \
199 1.18 matt _ENTRY(__wrap_ ## n) \
200 1.18 matt movw ip, #:lower16:n; \
201 1.18 matt movt ip, #:upper16:n; \
202 1.18 matt bx ip
203 1.18 matt #elif defined(_ARM_ARCH_4T)
204 1.18 matt #define KMODTRAMPOLINE(n) \
205 1.18 matt _ENTRY(__wrap_ ## n) \
206 1.18 matt ldr ip, [pc]; \
207 1.18 matt bx ip; \
208 1.18 matt .word n
209 1.18 matt #else
210 1.18 matt #define KMODTRAMPOLINE(n) \
211 1.18 matt _ENTRY(__wrap_ ## n) \
212 1.18 matt ldr pc, [pc, #-4]; \
213 1.18 matt .word n
214 1.18 matt #endif
215 1.18 matt
216 1.1 bjh21 #endif /* !_ARM_ASM_H_ */
217