asm.h revision 1.19 1 /* $NetBSD: asm.h,v 1.19 2013/08/11 04:39:18 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 #define __BIT(n) (1 << (n))
45 #define __BITS(hi,lo) ((~((~0)<<((hi)+1)))&((~0)<<(lo)))
46
47 #define _C_LABEL(x) x
48 #define _ASM_LABEL(x) x
49
50 #ifdef __STDC__
51 # define __CONCAT(x,y) x ## y
52 # define __STRING(x) #x
53 #else
54 # define __CONCAT(x,y) x/**/y
55 # define __STRING(x) "x"
56 #endif
57
58 #ifndef _ALIGN_TEXT
59 # define _ALIGN_TEXT .align 2
60 #endif
61
62 /*
63 * gas/arm uses @ as a single comment character and thus cannot be used here
64 * Instead it recognised the # instead of an @ symbols in .type directives
65 * We define a couple of macros so that assembly code will not be dependent
66 * on one or the other.
67 */
68 #define _ASM_TYPE_FUNCTION %function
69 #define _ASM_TYPE_OBJECT %object
70 #ifdef __thumb__
71 #define _ENTRY(x) \
72 .text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; .thumb_func; x:
73 #else
74 #define _ENTRY(x) \
75 .text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; x:
76 #endif
77 #define _END(x) .size x,.-x
78
79 #ifdef GPROF
80 # define _PROF_PROLOGUE \
81 mov ip, lr; bl __mcount
82 #else
83 # define _PROF_PROLOGUE
84 #endif
85
86 #define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
87 #define ENTRY_NP(y) _ENTRY(_C_LABEL(y))
88 #define END(y) _END(_C_LABEL(y))
89 #define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
90 #define ASENTRY_NP(y) _ENTRY(_ASM_LABEL(y))
91 #define ASEND(y) _END(_ASM_LABEL(y))
92
93 #define ASMSTR .asciz
94
95 #if defined(PIC)
96 #ifdef __thumb__
97 #define PLT_SYM(x) x
98 #define GOT_SYM(x) PIC_SYM(x, GOTOFF)
99 #define GOT_GET(x,got,sym) \
100 ldr x, sym; \
101 add x, got; \
102 ldr x, [x]
103 #else
104 #define PLT_SYM(x) PIC_SYM(x, PLT)
105 #define GOT_SYM(x) PIC_SYM(x, GOT)
106 #define GOT_GET(x,got,sym) \
107 ldr x, sym; \
108 ldr x, [x, got]
109 #endif /* __thumb__ */
110
111 #define GOT_INIT(got,gotsym,pclabel) \
112 ldr got, gotsym; \
113 add got, got, pc; \
114 pclabel:
115 #define GOT_INITSYM(gotsym,pclabel) \
116 gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) + (. - (pclabel+4))
117
118 #ifdef __STDC__
119 #define PIC_SYM(x,y) x ## ( ## y ## )
120 #else
121 #define PIC_SYM(x,y) x/**/(/**/y/**/)
122 #endif
123
124 #else
125 #define PLT_SYM(x) x
126 #define GOT_SYM(x) x
127 #define GOT_GET(x,got,sym) \
128 ldr x, sym;
129 #define GOT_INIT(got,gotsym,pclabel)
130 #define GOT_INITSYM(gotsym,pclabel)
131 #define PIC_SYM(x,y) x
132 #endif /* PIC */
133
134 #define RCSID(x) .pushsection ".ident"; .asciz x; .popsection
135
136 #define WEAK_ALIAS(alias,sym) \
137 .weak alias; \
138 alias = sym
139
140 /*
141 * STRONG_ALIAS: create a strong alias.
142 */
143 #define STRONG_ALIAS(alias,sym) \
144 .globl alias; \
145 alias = sym
146
147 #ifdef __STDC__
148 #define WARN_REFERENCES(sym,msg) \
149 .pushsection .gnu.warning. ## sym; \
150 .ascii msg; \
151 .popsection
152 #else
153 #define WARN_REFERENCES(sym,msg) \
154 .pushsection .gnu.warning./**/sym; \
155 .ascii msg; \
156 .popsection
157 #endif /* __STDC__ */
158
159 #ifdef __thumb__
160 # define XPUSH push
161 # define XPOP pop
162 # define XPOPRET pop {pc}
163 #else
164 # define XPUSH stmfd sp!,
165 # define XPOP ldmfd sp!,
166 # ifdef _ARM_ARCH_5
167 # define XPOPRET ldmfd sp!, {pc}
168 # else
169 # define XPOPRET ldmfd sp!, {lr}; mov pc, lr
170 # endif
171 #endif
172
173 #if defined (_ARM_ARCH_4T)
174 # define RET bx lr
175 # define RETr(r) bx r
176 # if defined(__thumb__)
177 # define RETc(c) it c; __CONCAT(bx,c) lr
178 # else
179 # define RETc(c) __CONCAT(bx,c) lr
180 # endif
181 #else
182 # define RET mov pc, lr
183 # define RETr(r) mov pc, r
184 # define RETc(c) __CONCAT(mov,c) pc, lr
185 #endif
186
187 #ifdef _ARM_ARCH_7
188 #define KMODTRAMPOLINE(n) \
189 _ENTRY(__wrap_ ## n) \
190 movw ip, #:lower16:n; \
191 movt ip, #:upper16:n; \
192 bx ip
193 #elif defined(_ARM_ARCH_4T)
194 #define KMODTRAMPOLINE(n) \
195 _ENTRY(__wrap_ ## n) \
196 ldr ip, [pc]; \
197 bx ip; \
198 .word n
199 #else
200 #define KMODTRAMPOLINE(n) \
201 _ENTRY(__wrap_ ## n) \
202 ldr pc, [pc, #-4]; \
203 .word n
204 #endif
205
206 #endif /* !_ARM_ASM_H_ */
207