Commit | Line | Data |
---|---|---|
b99bd4ef | 1 | /* tc-arm.c -- Assemble for the ARM |
82704155 | 2 | Copyright (C) 1994-2019 Free Software Foundation, Inc. |
b99bd4ef NC |
3 | Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org) |
4 | Modified by David Taylor (dtaylor@armltd.co.uk) | |
22d9c8c5 | 5 | Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com) |
34920d91 NC |
6 | Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com) |
7 | Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com) | |
b99bd4ef NC |
8 | |
9 | This file is part of GAS, the GNU Assembler. | |
10 | ||
11 | GAS is free software; you can redistribute it and/or modify | |
12 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 13 | the Free Software Foundation; either version 3, or (at your option) |
b99bd4ef NC |
14 | any later version. |
15 | ||
16 | GAS is distributed in the hope that it will be useful, | |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
c19d1205 | 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b99bd4ef NC |
19 | GNU General Public License for more details. |
20 | ||
21 | You should have received a copy of the GNU General Public License | |
22 | along with GAS; see the file COPYING. If not, write to the Free | |
699d2810 NC |
23 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
24 | 02110-1301, USA. */ | |
b99bd4ef | 25 | |
42a68e18 | 26 | #include "as.h" |
5287ad62 | 27 | #include <limits.h> |
037e8744 | 28 | #include <stdarg.h> |
c19d1205 | 29 | #define NO_RELOC 0 |
3882b010 | 30 | #include "safe-ctype.h" |
b99bd4ef NC |
31 | #include "subsegs.h" |
32 | #include "obstack.h" | |
3da1d841 | 33 | #include "libiberty.h" |
f263249b RE |
34 | #include "opcode/arm.h" |
35 | ||
b99bd4ef NC |
36 | #ifdef OBJ_ELF |
37 | #include "elf/arm.h" | |
a394c00f | 38 | #include "dw2gencfi.h" |
b99bd4ef NC |
39 | #endif |
40 | ||
f0927246 NC |
41 | #include "dwarf2dbg.h" |
42 | ||
7ed4c4c5 NC |
43 | #ifdef OBJ_ELF |
44 | /* Must be at least the size of the largest unwind opcode (currently two). */ | |
45 | #define ARM_OPCODE_CHUNK_SIZE 8 | |
46 | ||
47 | /* This structure holds the unwinding state. */ | |
48 | ||
49 | static struct | |
50 | { | |
c19d1205 ZW |
51 | symbolS * proc_start; |
52 | symbolS * table_entry; | |
53 | symbolS * personality_routine; | |
54 | int personality_index; | |
7ed4c4c5 | 55 | /* The segment containing the function. */ |
c19d1205 ZW |
56 | segT saved_seg; |
57 | subsegT saved_subseg; | |
7ed4c4c5 NC |
58 | /* Opcodes generated from this function. */ |
59 | unsigned char * opcodes; | |
c19d1205 ZW |
60 | int opcode_count; |
61 | int opcode_alloc; | |
7ed4c4c5 | 62 | /* The number of bytes pushed to the stack. */ |
c19d1205 | 63 | offsetT frame_size; |
7ed4c4c5 NC |
64 | /* We don't add stack adjustment opcodes immediately so that we can merge |
65 | multiple adjustments. We can also omit the final adjustment | |
66 | when using a frame pointer. */ | |
c19d1205 | 67 | offsetT pending_offset; |
7ed4c4c5 | 68 | /* These two fields are set by both unwind_movsp and unwind_setfp. They |
c19d1205 ZW |
69 | hold the reg+offset to use when restoring sp from a frame pointer. */ |
70 | offsetT fp_offset; | |
71 | int fp_reg; | |
7ed4c4c5 | 72 | /* Nonzero if an unwind_setfp directive has been seen. */ |
c19d1205 | 73 | unsigned fp_used:1; |
7ed4c4c5 | 74 | /* Nonzero if the last opcode restores sp from fp_reg. */ |
c19d1205 | 75 | unsigned sp_restored:1; |
7ed4c4c5 NC |
76 | } unwind; |
77 | ||
18a20338 CL |
78 | /* Whether --fdpic was given. */ |
79 | static int arm_fdpic; | |
80 | ||
8b1ad454 NC |
81 | #endif /* OBJ_ELF */ |
82 | ||
4962c51a MS |
83 | /* Results from operand parsing worker functions. */ |
84 | ||
85 | typedef enum | |
86 | { | |
87 | PARSE_OPERAND_SUCCESS, | |
88 | PARSE_OPERAND_FAIL, | |
89 | PARSE_OPERAND_FAIL_NO_BACKTRACK | |
90 | } parse_operand_result; | |
91 | ||
33a392fb PB |
92 | enum arm_float_abi |
93 | { | |
94 | ARM_FLOAT_ABI_HARD, | |
95 | ARM_FLOAT_ABI_SOFTFP, | |
96 | ARM_FLOAT_ABI_SOFT | |
97 | }; | |
98 | ||
c19d1205 | 99 | /* Types of processor to assemble for. */ |
b99bd4ef | 100 | #ifndef CPU_DEFAULT |
8a59fff3 | 101 | /* The code that was here used to select a default CPU depending on compiler |
fa94de6b | 102 | pre-defines which were only present when doing native builds, thus |
8a59fff3 MGD |
103 | changing gas' default behaviour depending upon the build host. |
104 | ||
105 | If you have a target that requires a default CPU option then the you | |
106 | should define CPU_DEFAULT here. */ | |
b99bd4ef NC |
107 | #endif |
108 | ||
109 | #ifndef FPU_DEFAULT | |
c820d418 MM |
110 | # ifdef TE_LINUX |
111 | # define FPU_DEFAULT FPU_ARCH_FPA | |
112 | # elif defined (TE_NetBSD) | |
113 | # ifdef OBJ_ELF | |
114 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */ | |
115 | # else | |
116 | /* Legacy a.out format. */ | |
117 | # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */ | |
118 | # endif | |
4e7fd91e PB |
119 | # elif defined (TE_VXWORKS) |
120 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */ | |
c820d418 MM |
121 | # else |
122 | /* For backwards compatibility, default to FPA. */ | |
123 | # define FPU_DEFAULT FPU_ARCH_FPA | |
124 | # endif | |
125 | #endif /* ifndef FPU_DEFAULT */ | |
b99bd4ef | 126 | |
c19d1205 | 127 | #define streq(a, b) (strcmp (a, b) == 0) |
b99bd4ef | 128 | |
4d354d8b TP |
129 | /* Current set of feature bits available (CPU+FPU). Different from |
130 | selected_cpu + selected_fpu in case of autodetection since the CPU | |
131 | feature bits are then all set. */ | |
e74cfd16 | 132 | static arm_feature_set cpu_variant; |
4d354d8b TP |
133 | /* Feature bits used in each execution state. Used to set build attribute |
134 | (in particular Tag_*_ISA_use) in CPU autodetection mode. */ | |
e74cfd16 PB |
135 | static arm_feature_set arm_arch_used; |
136 | static arm_feature_set thumb_arch_used; | |
b99bd4ef | 137 | |
b99bd4ef | 138 | /* Flags stored in private area of BFD structure. */ |
c19d1205 ZW |
139 | static int uses_apcs_26 = FALSE; |
140 | static int atpcs = FALSE; | |
b34976b6 AM |
141 | static int support_interwork = FALSE; |
142 | static int uses_apcs_float = FALSE; | |
c19d1205 | 143 | static int pic_code = FALSE; |
845b51d6 | 144 | static int fix_v4bx = FALSE; |
278df34e NS |
145 | /* Warn on using deprecated features. */ |
146 | static int warn_on_deprecated = TRUE; | |
147 | ||
2e6976a8 DG |
148 | /* Understand CodeComposer Studio assembly syntax. */ |
149 | bfd_boolean codecomposer_syntax = FALSE; | |
03b1477f RE |
150 | |
151 | /* Variables that we set while parsing command-line options. Once all | |
152 | options have been read we re-process these values to set the real | |
153 | assembly flags. */ | |
4d354d8b TP |
154 | |
155 | /* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1 | |
156 | instead of -mcpu=arm1). */ | |
157 | static const arm_feature_set *legacy_cpu = NULL; | |
158 | static const arm_feature_set *legacy_fpu = NULL; | |
159 | ||
160 | /* CPU, extension and FPU feature bits selected by -mcpu. */ | |
161 | static const arm_feature_set *mcpu_cpu_opt = NULL; | |
162 | static arm_feature_set *mcpu_ext_opt = NULL; | |
163 | static const arm_feature_set *mcpu_fpu_opt = NULL; | |
164 | ||
165 | /* CPU, extension and FPU feature bits selected by -march. */ | |
166 | static const arm_feature_set *march_cpu_opt = NULL; | |
167 | static arm_feature_set *march_ext_opt = NULL; | |
168 | static const arm_feature_set *march_fpu_opt = NULL; | |
169 | ||
170 | /* Feature bits selected by -mfpu. */ | |
171 | static const arm_feature_set *mfpu_opt = NULL; | |
e74cfd16 PB |
172 | |
173 | /* Constants for known architecture features. */ | |
174 | static const arm_feature_set fpu_default = FPU_DEFAULT; | |
f85d59c3 | 175 | static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1; |
e74cfd16 | 176 | static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2; |
f85d59c3 KT |
177 | static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3; |
178 | static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1; | |
e74cfd16 PB |
179 | static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA; |
180 | static const arm_feature_set fpu_any_hard = FPU_ANY_HARD; | |
69c9e028 | 181 | #ifdef OBJ_ELF |
e74cfd16 | 182 | static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK; |
69c9e028 | 183 | #endif |
e74cfd16 PB |
184 | static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE; |
185 | ||
186 | #ifdef CPU_DEFAULT | |
187 | static const arm_feature_set cpu_default = CPU_DEFAULT; | |
188 | #endif | |
189 | ||
823d2571 | 190 | static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1); |
4070243b | 191 | static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2); |
823d2571 TG |
192 | static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S); |
193 | static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3); | |
194 | static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M); | |
195 | static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4); | |
196 | static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T); | |
197 | static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5); | |
e74cfd16 | 198 | static const arm_feature_set arm_ext_v4t_5 = |
823d2571 TG |
199 | ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5); |
200 | static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T); | |
201 | static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E); | |
202 | static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP); | |
203 | static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J); | |
204 | static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6); | |
205 | static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K); | |
206 | static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2); | |
55e8aae7 SP |
207 | /* Only for compatability of hint instructions. */ |
208 | static const arm_feature_set arm_ext_v6k_v6t2 = | |
209 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2); | |
823d2571 TG |
210 | static const arm_feature_set arm_ext_v6_notm = |
211 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM); | |
212 | static const arm_feature_set arm_ext_v6_dsp = | |
213 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP); | |
214 | static const arm_feature_set arm_ext_barrier = | |
215 | ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER); | |
216 | static const arm_feature_set arm_ext_msr = | |
217 | ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR); | |
218 | static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV); | |
219 | static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7); | |
220 | static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A); | |
221 | static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R); | |
69c9e028 | 222 | #ifdef OBJ_ELF |
e7d39ed3 | 223 | static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M); |
69c9e028 | 224 | #endif |
823d2571 | 225 | static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8); |
7e806470 | 226 | static const arm_feature_set arm_ext_m = |
173205ca | 227 | ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M, |
16a1fa25 | 228 | ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN); |
823d2571 TG |
229 | static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP); |
230 | static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC); | |
231 | static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS); | |
232 | static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV); | |
233 | static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT); | |
ddfded2f | 234 | static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN); |
4ed7ed8d | 235 | static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M); |
16a1fa25 TP |
236 | static const arm_feature_set arm_ext_v8m_main = |
237 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN); | |
e12437dc AV |
238 | static const arm_feature_set arm_ext_v8_1m_main = |
239 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN); | |
16a1fa25 TP |
240 | /* Instructions in ARMv8-M only found in M profile architectures. */ |
241 | static const arm_feature_set arm_ext_v8m_m_only = | |
242 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN); | |
ff8646ee TP |
243 | static const arm_feature_set arm_ext_v6t2_v8m = |
244 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M); | |
4ed7ed8d TP |
245 | /* Instructions shared between ARMv8-A and ARMv8-M. */ |
246 | static const arm_feature_set arm_ext_atomics = | |
247 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS); | |
69c9e028 | 248 | #ifdef OBJ_ELF |
15afaa63 TP |
249 | /* DSP instructions Tag_DSP_extension refers to. */ |
250 | static const arm_feature_set arm_ext_dsp = | |
251 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP); | |
69c9e028 | 252 | #endif |
4d1464f2 MW |
253 | static const arm_feature_set arm_ext_ras = |
254 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS); | |
b8ec4e87 JW |
255 | /* FP16 instructions. */ |
256 | static const arm_feature_set arm_ext_fp16 = | |
257 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST); | |
01f48020 TC |
258 | static const arm_feature_set arm_ext_fp16_fml = |
259 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML); | |
dec41383 JW |
260 | static const arm_feature_set arm_ext_v8_2 = |
261 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A); | |
49e8a725 SN |
262 | static const arm_feature_set arm_ext_v8_3 = |
263 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A); | |
7fadb25d SD |
264 | static const arm_feature_set arm_ext_sb = |
265 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB); | |
dad0c3bf SD |
266 | static const arm_feature_set arm_ext_predres = |
267 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES); | |
e74cfd16 PB |
268 | |
269 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
49fa50ef | 270 | #ifdef OBJ_ELF |
2c6b98ea | 271 | static const arm_feature_set fpu_any = FPU_ANY; |
49fa50ef | 272 | #endif |
f85d59c3 | 273 | static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1); |
e74cfd16 PB |
274 | static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2; |
275 | static const arm_feature_set arm_arch_none = ARM_ARCH_NONE; | |
276 | ||
2d447fca | 277 | static const arm_feature_set arm_cext_iwmmxt2 = |
823d2571 | 278 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2); |
e74cfd16 | 279 | static const arm_feature_set arm_cext_iwmmxt = |
823d2571 | 280 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT); |
e74cfd16 | 281 | static const arm_feature_set arm_cext_xscale = |
823d2571 | 282 | ARM_FEATURE_COPROC (ARM_CEXT_XSCALE); |
e74cfd16 | 283 | static const arm_feature_set arm_cext_maverick = |
823d2571 TG |
284 | ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK); |
285 | static const arm_feature_set fpu_fpa_ext_v1 = | |
286 | ARM_FEATURE_COPROC (FPU_FPA_EXT_V1); | |
287 | static const arm_feature_set fpu_fpa_ext_v2 = | |
288 | ARM_FEATURE_COPROC (FPU_FPA_EXT_V2); | |
e74cfd16 | 289 | static const arm_feature_set fpu_vfp_ext_v1xd = |
823d2571 TG |
290 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD); |
291 | static const arm_feature_set fpu_vfp_ext_v1 = | |
292 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V1); | |
293 | static const arm_feature_set fpu_vfp_ext_v2 = | |
294 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V2); | |
295 | static const arm_feature_set fpu_vfp_ext_v3xd = | |
296 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD); | |
297 | static const arm_feature_set fpu_vfp_ext_v3 = | |
298 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V3); | |
b1cc4aeb | 299 | static const arm_feature_set fpu_vfp_ext_d32 = |
823d2571 TG |
300 | ARM_FEATURE_COPROC (FPU_VFP_EXT_D32); |
301 | static const arm_feature_set fpu_neon_ext_v1 = | |
302 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1); | |
5287ad62 | 303 | static const arm_feature_set fpu_vfp_v3_or_neon_ext = |
823d2571 | 304 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3); |
69c9e028 | 305 | #ifdef OBJ_ELF |
823d2571 TG |
306 | static const arm_feature_set fpu_vfp_fp16 = |
307 | ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16); | |
308 | static const arm_feature_set fpu_neon_ext_fma = | |
309 | ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA); | |
69c9e028 | 310 | #endif |
823d2571 TG |
311 | static const arm_feature_set fpu_vfp_ext_fma = |
312 | ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA); | |
bca38921 | 313 | static const arm_feature_set fpu_vfp_ext_armv8 = |
823d2571 | 314 | ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8); |
a715796b | 315 | static const arm_feature_set fpu_vfp_ext_armv8xd = |
823d2571 | 316 | ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD); |
bca38921 | 317 | static const arm_feature_set fpu_neon_ext_armv8 = |
823d2571 | 318 | ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8); |
bca38921 | 319 | static const arm_feature_set fpu_crypto_ext_armv8 = |
823d2571 | 320 | ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8); |
dd5181d5 | 321 | static const arm_feature_set crc_ext_armv8 = |
823d2571 | 322 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8); |
d6b4b13e | 323 | static const arm_feature_set fpu_neon_ext_v8_1 = |
643afb90 | 324 | ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA); |
c604a79a JW |
325 | static const arm_feature_set fpu_neon_ext_dotprod = |
326 | ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD); | |
e74cfd16 | 327 | |
33a392fb | 328 | static int mfloat_abi_opt = -1; |
4d354d8b TP |
329 | /* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch |
330 | directive. */ | |
331 | static arm_feature_set selected_arch = ARM_ARCH_NONE; | |
332 | /* Extension feature bits selected by the last -mcpu/-march or .arch_extension | |
333 | directive. */ | |
334 | static arm_feature_set selected_ext = ARM_ARCH_NONE; | |
335 | /* Feature bits selected by the last -mcpu/-march or by the combination of the | |
336 | last .cpu/.arch directive .arch_extension directives since that | |
337 | directive. */ | |
e74cfd16 | 338 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; |
4d354d8b TP |
339 | /* FPU feature bits selected by the last -mfpu or .fpu directive. */ |
340 | static arm_feature_set selected_fpu = FPU_NONE; | |
341 | /* Feature bits selected by the last .object_arch directive. */ | |
342 | static arm_feature_set selected_object_arch = ARM_ARCH_NONE; | |
ee065d83 | 343 | /* Must be long enough to hold any of the names in arm_cpus. */ |
ef8e6722 | 344 | static char selected_cpu_name[20]; |
8d67f500 | 345 | |
aacf0b33 KT |
346 | extern FLONUM_TYPE generic_floating_point_number; |
347 | ||
8d67f500 NC |
348 | /* Return if no cpu was selected on command-line. */ |
349 | static bfd_boolean | |
350 | no_cpu_selected (void) | |
351 | { | |
823d2571 | 352 | return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none); |
8d67f500 NC |
353 | } |
354 | ||
7cc69913 | 355 | #ifdef OBJ_ELF |
deeaaff8 DJ |
356 | # ifdef EABI_DEFAULT |
357 | static int meabi_flags = EABI_DEFAULT; | |
358 | # else | |
d507cf36 | 359 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 360 | # endif |
e1da3f5b | 361 | |
ee3c0378 AS |
362 | static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES]; |
363 | ||
e1da3f5b | 364 | bfd_boolean |
5f4273c7 | 365 | arm_is_eabi (void) |
e1da3f5b PB |
366 | { |
367 | return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4); | |
368 | } | |
7cc69913 | 369 | #endif |
b99bd4ef | 370 | |
b99bd4ef | 371 | #ifdef OBJ_ELF |
c19d1205 | 372 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
373 | symbolS * GOT_symbol; |
374 | #endif | |
375 | ||
b99bd4ef NC |
376 | /* 0: assemble for ARM, |
377 | 1: assemble for Thumb, | |
378 | 2: assemble for Thumb even though target CPU does not support thumb | |
379 | instructions. */ | |
380 | static int thumb_mode = 0; | |
8dc2430f NC |
381 | /* A value distinct from the possible values for thumb_mode that we |
382 | can use to record whether thumb_mode has been copied into the | |
383 | tc_frag_data field of a frag. */ | |
384 | #define MODE_RECORDED (1 << 4) | |
b99bd4ef | 385 | |
e07e6e58 NC |
386 | /* Specifies the intrinsic IT insn behavior mode. */ |
387 | enum implicit_it_mode | |
388 | { | |
389 | IMPLICIT_IT_MODE_NEVER = 0x00, | |
390 | IMPLICIT_IT_MODE_ARM = 0x01, | |
391 | IMPLICIT_IT_MODE_THUMB = 0x02, | |
392 | IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB) | |
393 | }; | |
394 | static int implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
395 | ||
c19d1205 ZW |
396 | /* If unified_syntax is true, we are processing the new unified |
397 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
398 | ||
399 | - Immediate operands do not require a # prefix. | |
400 | - Conditional affixes always appear at the end of the | |
401 | instruction. (For backward compatibility, those instructions | |
402 | that formerly had them in the middle, continue to accept them | |
403 | there.) | |
404 | - The IT instruction may appear, and if it does is validated | |
405 | against subsequent conditional affixes. It does not generate | |
406 | machine code. | |
407 | ||
408 | Important differences from the old Thumb mode: | |
409 | ||
410 | - Immediate operands do not require a # prefix. | |
411 | - Most of the V6T2 instructions are only available in unified mode. | |
412 | - The .N and .W suffixes are recognized and honored (it is an error | |
413 | if they cannot be honored). | |
414 | - All instructions set the flags if and only if they have an 's' affix. | |
415 | - Conditional affixes may be used. They are validated against | |
416 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
417 | conditional affix except in the scope of an IT instruction. */ | |
418 | ||
419 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef | 420 | |
bacebabc RM |
421 | /* An immediate operand can start with #, and ld*, st*, pld operands |
422 | can contain [ and ]. We need to tell APP not to elide whitespace | |
477330fc RM |
423 | before a [, which can appear as the first operand for pld. |
424 | Likewise, a { can appear as the first operand for push, pop, vld*, etc. */ | |
425 | const char arm_symbol_chars[] = "#[]{}"; | |
bacebabc | 426 | |
5287ad62 JB |
427 | enum neon_el_type |
428 | { | |
dcbf9037 | 429 | NT_invtype, |
5287ad62 JB |
430 | NT_untyped, |
431 | NT_integer, | |
432 | NT_float, | |
433 | NT_poly, | |
434 | NT_signed, | |
dcbf9037 | 435 | NT_unsigned |
5287ad62 JB |
436 | }; |
437 | ||
438 | struct neon_type_el | |
439 | { | |
440 | enum neon_el_type type; | |
441 | unsigned size; | |
442 | }; | |
443 | ||
444 | #define NEON_MAX_TYPE_ELS 4 | |
445 | ||
446 | struct neon_type | |
447 | { | |
448 | struct neon_type_el el[NEON_MAX_TYPE_ELS]; | |
449 | unsigned elems; | |
450 | }; | |
451 | ||
e07e6e58 NC |
452 | enum it_instruction_type |
453 | { | |
454 | OUTSIDE_IT_INSN, | |
455 | INSIDE_IT_INSN, | |
456 | INSIDE_IT_LAST_INSN, | |
457 | IF_INSIDE_IT_LAST_INSN, /* Either outside or inside; | |
477330fc | 458 | if inside, should be the last one. */ |
e07e6e58 | 459 | NEUTRAL_IT_INSN, /* This could be either inside or outside, |
477330fc | 460 | i.e. BKPT and NOP. */ |
e07e6e58 NC |
461 | IT_INSN /* The IT insn has been parsed. */ |
462 | }; | |
463 | ||
ad6cec43 MGD |
464 | /* The maximum number of operands we need. */ |
465 | #define ARM_IT_MAX_OPERANDS 6 | |
e2b0ab59 | 466 | #define ARM_IT_MAX_RELOCS 3 |
ad6cec43 | 467 | |
b99bd4ef NC |
468 | struct arm_it |
469 | { | |
c19d1205 | 470 | const char * error; |
b99bd4ef | 471 | unsigned long instruction; |
c19d1205 ZW |
472 | int size; |
473 | int size_req; | |
474 | int cond; | |
037e8744 JB |
475 | /* "uncond_value" is set to the value in place of the conditional field in |
476 | unconditional versions of the instruction, or -1 if nothing is | |
477 | appropriate. */ | |
478 | int uncond_value; | |
5287ad62 | 479 | struct neon_type vectype; |
88714cb8 DG |
480 | /* This does not indicate an actual NEON instruction, only that |
481 | the mnemonic accepts neon-style type suffixes. */ | |
482 | int is_neon; | |
0110f2b8 PB |
483 | /* Set to the opcode if the instruction needs relaxation. |
484 | Zero if the instruction is not relaxed. */ | |
485 | unsigned long relax; | |
b99bd4ef NC |
486 | struct |
487 | { | |
488 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
489 | expressionS exp; |
490 | int pc_rel; | |
e2b0ab59 | 491 | } relocs[ARM_IT_MAX_RELOCS]; |
b99bd4ef | 492 | |
e07e6e58 NC |
493 | enum it_instruction_type it_insn_type; |
494 | ||
c19d1205 ZW |
495 | struct |
496 | { | |
497 | unsigned reg; | |
ca3f61f7 | 498 | signed int imm; |
dcbf9037 | 499 | struct neon_type_el vectype; |
ca3f61f7 NC |
500 | unsigned present : 1; /* Operand present. */ |
501 | unsigned isreg : 1; /* Operand was a register. */ | |
502 | unsigned immisreg : 1; /* .imm field is a second register. */ | |
5287ad62 JB |
503 | unsigned isscalar : 1; /* Operand is a (Neon) scalar. */ |
504 | unsigned immisalign : 1; /* Immediate is an alignment specifier. */ | |
c96612cc | 505 | unsigned immisfloat : 1; /* Immediate was parsed as a float. */ |
5287ad62 JB |
506 | /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV |
507 | instructions. This allows us to disambiguate ARM <-> vector insns. */ | |
508 | unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */ | |
037e8744 | 509 | unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */ |
5287ad62 | 510 | unsigned isquad : 1; /* Operand is Neon quad-precision register. */ |
037e8744 | 511 | unsigned issingle : 1; /* Operand is VFP single-precision register. */ |
ca3f61f7 NC |
512 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ |
513 | unsigned writeback : 1; /* Operand has trailing ! */ | |
514 | unsigned preind : 1; /* Preindexed address. */ | |
515 | unsigned postind : 1; /* Postindexed address. */ | |
516 | unsigned negative : 1; /* Index register was negated. */ | |
517 | unsigned shifted : 1; /* Shift applied to operation. */ | |
518 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
ad6cec43 | 519 | } operands[ARM_IT_MAX_OPERANDS]; |
b99bd4ef NC |
520 | }; |
521 | ||
c19d1205 | 522 | static struct arm_it inst; |
b99bd4ef NC |
523 | |
524 | #define NUM_FLOAT_VALS 8 | |
525 | ||
05d2d07e | 526 | const char * fp_const[] = |
b99bd4ef NC |
527 | { |
528 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
529 | }; | |
530 | ||
b99bd4ef NC |
531 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; |
532 | ||
533 | #define FAIL (-1) | |
534 | #define SUCCESS (0) | |
535 | ||
536 | #define SUFF_S 1 | |
537 | #define SUFF_D 2 | |
538 | #define SUFF_E 3 | |
539 | #define SUFF_P 4 | |
540 | ||
c19d1205 ZW |
541 | #define CP_T_X 0x00008000 |
542 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 543 | |
c19d1205 ZW |
544 | #define CONDS_BIT 0x00100000 |
545 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
546 | |
547 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
548 | ||
549 | struct asm_cond | |
550 | { | |
d3ce72d0 | 551 | const char * template_name; |
c921be7d | 552 | unsigned long value; |
b99bd4ef NC |
553 | }; |
554 | ||
c19d1205 | 555 | #define COND_ALWAYS 0xE |
b99bd4ef | 556 | |
b99bd4ef NC |
557 | struct asm_psr |
558 | { | |
d3ce72d0 | 559 | const char * template_name; |
c921be7d | 560 | unsigned long field; |
b99bd4ef NC |
561 | }; |
562 | ||
62b3e311 PB |
563 | struct asm_barrier_opt |
564 | { | |
e797f7e0 MGD |
565 | const char * template_name; |
566 | unsigned long value; | |
567 | const arm_feature_set arch; | |
62b3e311 PB |
568 | }; |
569 | ||
2d2255b5 | 570 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
571 | #define SPSR_BIT (1 << 22) |
572 | ||
c19d1205 ZW |
573 | /* The individual PSR flag bits. */ |
574 | #define PSR_c (1 << 16) | |
575 | #define PSR_x (1 << 17) | |
576 | #define PSR_s (1 << 18) | |
577 | #define PSR_f (1 << 19) | |
b99bd4ef | 578 | |
c19d1205 | 579 | struct reloc_entry |
bfae80f2 | 580 | { |
0198d5e6 | 581 | const char * name; |
c921be7d | 582 | bfd_reloc_code_real_type reloc; |
bfae80f2 RE |
583 | }; |
584 | ||
5287ad62 | 585 | enum vfp_reg_pos |
bfae80f2 | 586 | { |
5287ad62 JB |
587 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn, |
588 | VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn | |
bfae80f2 RE |
589 | }; |
590 | ||
591 | enum vfp_ldstm_type | |
592 | { | |
593 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
594 | }; | |
595 | ||
dcbf9037 JB |
596 | /* Bits for DEFINED field in neon_typed_alias. */ |
597 | #define NTA_HASTYPE 1 | |
598 | #define NTA_HASINDEX 2 | |
599 | ||
600 | struct neon_typed_alias | |
601 | { | |
c921be7d NC |
602 | unsigned char defined; |
603 | unsigned char index; | |
604 | struct neon_type_el eltype; | |
dcbf9037 JB |
605 | }; |
606 | ||
c19d1205 | 607 | /* ARM register categories. This includes coprocessor numbers and various |
5aa75429 TP |
608 | architecture extensions' registers. Each entry should have an error message |
609 | in reg_expected_msgs below. */ | |
c19d1205 | 610 | enum arm_reg_type |
bfae80f2 | 611 | { |
c19d1205 ZW |
612 | REG_TYPE_RN, |
613 | REG_TYPE_CP, | |
614 | REG_TYPE_CN, | |
615 | REG_TYPE_FN, | |
616 | REG_TYPE_VFS, | |
617 | REG_TYPE_VFD, | |
5287ad62 | 618 | REG_TYPE_NQ, |
037e8744 | 619 | REG_TYPE_VFSD, |
5287ad62 | 620 | REG_TYPE_NDQ, |
dec41383 | 621 | REG_TYPE_NSD, |
037e8744 | 622 | REG_TYPE_NSDQ, |
c19d1205 ZW |
623 | REG_TYPE_VFC, |
624 | REG_TYPE_MVF, | |
625 | REG_TYPE_MVD, | |
626 | REG_TYPE_MVFX, | |
627 | REG_TYPE_MVDX, | |
628 | REG_TYPE_MVAX, | |
629 | REG_TYPE_DSPSC, | |
630 | REG_TYPE_MMXWR, | |
631 | REG_TYPE_MMXWC, | |
632 | REG_TYPE_MMXWCG, | |
633 | REG_TYPE_XSCALE, | |
90ec0d68 | 634 | REG_TYPE_RNB |
bfae80f2 RE |
635 | }; |
636 | ||
dcbf9037 JB |
637 | /* Structure for a hash table entry for a register. |
638 | If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra | |
639 | information which states whether a vector type or index is specified (for a | |
640 | register alias created with .dn or .qn). Otherwise NEON should be NULL. */ | |
6c43fab6 RE |
641 | struct reg_entry |
642 | { | |
c921be7d | 643 | const char * name; |
90ec0d68 | 644 | unsigned int number; |
c921be7d NC |
645 | unsigned char type; |
646 | unsigned char builtin; | |
647 | struct neon_typed_alias * neon; | |
6c43fab6 RE |
648 | }; |
649 | ||
c19d1205 | 650 | /* Diagnostics used when we don't get a register of the expected type. */ |
c921be7d | 651 | const char * const reg_expected_msgs[] = |
c19d1205 | 652 | { |
5aa75429 TP |
653 | [REG_TYPE_RN] = N_("ARM register expected"), |
654 | [REG_TYPE_CP] = N_("bad or missing co-processor number"), | |
655 | [REG_TYPE_CN] = N_("co-processor register expected"), | |
656 | [REG_TYPE_FN] = N_("FPA register expected"), | |
657 | [REG_TYPE_VFS] = N_("VFP single precision register expected"), | |
658 | [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"), | |
659 | [REG_TYPE_NQ] = N_("Neon quad precision register expected"), | |
660 | [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"), | |
661 | [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"), | |
662 | [REG_TYPE_NSD] = N_("Neon single or double precision register expected"), | |
663 | [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register" | |
664 | " expected"), | |
665 | [REG_TYPE_VFC] = N_("VFP system register expected"), | |
666 | [REG_TYPE_MVF] = N_("Maverick MVF register expected"), | |
667 | [REG_TYPE_MVD] = N_("Maverick MVD register expected"), | |
668 | [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"), | |
669 | [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"), | |
670 | [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"), | |
671 | [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"), | |
672 | [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"), | |
673 | [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"), | |
674 | [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"), | |
675 | [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"), | |
676 | [REG_TYPE_RNB] = N_("") | |
6c43fab6 RE |
677 | }; |
678 | ||
c19d1205 | 679 | /* Some well known registers that we refer to directly elsewhere. */ |
bd340a04 | 680 | #define REG_R12 12 |
c19d1205 ZW |
681 | #define REG_SP 13 |
682 | #define REG_LR 14 | |
683 | #define REG_PC 15 | |
404ff6b5 | 684 | |
b99bd4ef NC |
685 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
686 | take 2: */ | |
c19d1205 | 687 | #define INSN_SIZE 4 |
b99bd4ef NC |
688 | |
689 | struct asm_opcode | |
690 | { | |
691 | /* Basic string to match. */ | |
d3ce72d0 | 692 | const char * template_name; |
c19d1205 ZW |
693 | |
694 | /* Parameters to instruction. */ | |
5be8be5d | 695 | unsigned int operands[8]; |
c19d1205 ZW |
696 | |
697 | /* Conditional tag - see opcode_lookup. */ | |
698 | unsigned int tag : 4; | |
b99bd4ef NC |
699 | |
700 | /* Basic instruction code. */ | |
c19d1205 | 701 | unsigned int avalue : 28; |
b99bd4ef | 702 | |
c19d1205 ZW |
703 | /* Thumb-format instruction code. */ |
704 | unsigned int tvalue; | |
b99bd4ef | 705 | |
90e4755a | 706 | /* Which architecture variant provides this instruction. */ |
c921be7d NC |
707 | const arm_feature_set * avariant; |
708 | const arm_feature_set * tvariant; | |
c19d1205 ZW |
709 | |
710 | /* Function to call to encode instruction in ARM format. */ | |
711 | void (* aencode) (void); | |
b99bd4ef | 712 | |
c19d1205 ZW |
713 | /* Function to call to encode instruction in Thumb format. */ |
714 | void (* tencode) (void); | |
b99bd4ef NC |
715 | }; |
716 | ||
a737bd4d NC |
717 | /* Defines for various bits that we will want to toggle. */ |
718 | #define INST_IMMEDIATE 0x02000000 | |
719 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 720 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
721 | #define SHIFT_BY_REG 0x00000010 |
722 | #define PRE_INDEX 0x01000000 | |
723 | #define INDEX_UP 0x00800000 | |
724 | #define WRITE_BACK 0x00200000 | |
725 | #define LDM_TYPE_2_OR_3 0x00400000 | |
a028a6f5 | 726 | #define CPSI_MMOD 0x00020000 |
90e4755a | 727 | |
a737bd4d NC |
728 | #define LITERAL_MASK 0xf000f000 |
729 | #define OPCODE_MASK 0xfe1fffff | |
730 | #define V4_STR_BIT 0x00000020 | |
8335d6aa | 731 | #define VLDR_VMOV_SAME 0x0040f000 |
90e4755a | 732 | |
efd81785 PB |
733 | #define T2_SUBS_PC_LR 0xf3de8f00 |
734 | ||
a737bd4d | 735 | #define DATA_OP_SHIFT 21 |
bada4342 | 736 | #define SBIT_SHIFT 20 |
90e4755a | 737 | |
ef8d22e6 PB |
738 | #define T2_OPCODE_MASK 0xfe1fffff |
739 | #define T2_DATA_OP_SHIFT 21 | |
bada4342 | 740 | #define T2_SBIT_SHIFT 20 |
ef8d22e6 | 741 | |
6530b175 NC |
742 | #define A_COND_MASK 0xf0000000 |
743 | #define A_PUSH_POP_OP_MASK 0x0fff0000 | |
744 | ||
745 | /* Opcodes for pushing/poping registers to/from the stack. */ | |
746 | #define A1_OPCODE_PUSH 0x092d0000 | |
747 | #define A2_OPCODE_PUSH 0x052d0004 | |
748 | #define A2_OPCODE_POP 0x049d0004 | |
749 | ||
a737bd4d NC |
750 | /* Codes to distinguish the arithmetic instructions. */ |
751 | #define OPCODE_AND 0 | |
752 | #define OPCODE_EOR 1 | |
753 | #define OPCODE_SUB 2 | |
754 | #define OPCODE_RSB 3 | |
755 | #define OPCODE_ADD 4 | |
756 | #define OPCODE_ADC 5 | |
757 | #define OPCODE_SBC 6 | |
758 | #define OPCODE_RSC 7 | |
759 | #define OPCODE_TST 8 | |
760 | #define OPCODE_TEQ 9 | |
761 | #define OPCODE_CMP 10 | |
762 | #define OPCODE_CMN 11 | |
763 | #define OPCODE_ORR 12 | |
764 | #define OPCODE_MOV 13 | |
765 | #define OPCODE_BIC 14 | |
766 | #define OPCODE_MVN 15 | |
90e4755a | 767 | |
ef8d22e6 PB |
768 | #define T2_OPCODE_AND 0 |
769 | #define T2_OPCODE_BIC 1 | |
770 | #define T2_OPCODE_ORR 2 | |
771 | #define T2_OPCODE_ORN 3 | |
772 | #define T2_OPCODE_EOR 4 | |
773 | #define T2_OPCODE_ADD 8 | |
774 | #define T2_OPCODE_ADC 10 | |
775 | #define T2_OPCODE_SBC 11 | |
776 | #define T2_OPCODE_SUB 13 | |
777 | #define T2_OPCODE_RSB 14 | |
778 | ||
a737bd4d NC |
779 | #define T_OPCODE_MUL 0x4340 |
780 | #define T_OPCODE_TST 0x4200 | |
781 | #define T_OPCODE_CMN 0x42c0 | |
782 | #define T_OPCODE_NEG 0x4240 | |
783 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 784 | |
a737bd4d NC |
785 | #define T_OPCODE_ADD_R3 0x1800 |
786 | #define T_OPCODE_SUB_R3 0x1a00 | |
787 | #define T_OPCODE_ADD_HI 0x4400 | |
788 | #define T_OPCODE_ADD_ST 0xb000 | |
789 | #define T_OPCODE_SUB_ST 0xb080 | |
790 | #define T_OPCODE_ADD_SP 0xa800 | |
791 | #define T_OPCODE_ADD_PC 0xa000 | |
792 | #define T_OPCODE_ADD_I8 0x3000 | |
793 | #define T_OPCODE_SUB_I8 0x3800 | |
794 | #define T_OPCODE_ADD_I3 0x1c00 | |
795 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 796 | |
a737bd4d NC |
797 | #define T_OPCODE_ASR_R 0x4100 |
798 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
799 | #define T_OPCODE_LSR_R 0x40c0 |
800 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
801 | #define T_OPCODE_ASR_I 0x1000 |
802 | #define T_OPCODE_LSL_I 0x0000 | |
803 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 804 | |
a737bd4d NC |
805 | #define T_OPCODE_MOV_I8 0x2000 |
806 | #define T_OPCODE_CMP_I8 0x2800 | |
807 | #define T_OPCODE_CMP_LR 0x4280 | |
808 | #define T_OPCODE_MOV_HR 0x4600 | |
809 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 810 | |
a737bd4d NC |
811 | #define T_OPCODE_LDR_PC 0x4800 |
812 | #define T_OPCODE_LDR_SP 0x9800 | |
813 | #define T_OPCODE_STR_SP 0x9000 | |
814 | #define T_OPCODE_LDR_IW 0x6800 | |
815 | #define T_OPCODE_STR_IW 0x6000 | |
816 | #define T_OPCODE_LDR_IH 0x8800 | |
817 | #define T_OPCODE_STR_IH 0x8000 | |
818 | #define T_OPCODE_LDR_IB 0x7800 | |
819 | #define T_OPCODE_STR_IB 0x7000 | |
820 | #define T_OPCODE_LDR_RW 0x5800 | |
821 | #define T_OPCODE_STR_RW 0x5000 | |
822 | #define T_OPCODE_LDR_RH 0x5a00 | |
823 | #define T_OPCODE_STR_RH 0x5200 | |
824 | #define T_OPCODE_LDR_RB 0x5c00 | |
825 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 826 | |
a737bd4d NC |
827 | #define T_OPCODE_PUSH 0xb400 |
828 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 829 | |
2fc8bdac | 830 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 831 | |
a737bd4d | 832 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 833 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 834 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 835 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 ZW |
836 | |
837 | #define BAD_ARGS _("bad arguments to instruction") | |
fdfde340 | 838 | #define BAD_SP _("r13 not allowed here") |
c19d1205 ZW |
839 | #define BAD_PC _("r15 not allowed here") |
840 | #define BAD_COND _("instruction cannot be conditional") | |
841 | #define BAD_OVERLAP _("registers may not be the same") | |
842 | #define BAD_HIREG _("lo register required") | |
843 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
01cfc07f | 844 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode"); |
dfa9f0d5 | 845 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
e12437dc | 846 | #define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2") |
dfa9f0d5 | 847 | #define BAD_NOT_IT _("instruction not allowed in IT block") |
037e8744 | 848 | #define BAD_FPU _("selected FPU does not support instruction") |
e07e6e58 NC |
849 | #define BAD_OUT_IT _("thumb conditional instruction should be in IT block") |
850 | #define BAD_IT_COND _("incorrect condition in IT block") | |
851 | #define BAD_IT_IT _("IT falling in the range of a previous IT block") | |
921e5f0a | 852 | #define MISSING_FNSTART _("missing .fnstart before unwinding directive") |
5be8be5d DG |
853 | #define BAD_PC_ADDRESSING \ |
854 | _("cannot use register index with PC-relative addressing") | |
855 | #define BAD_PC_WRITEBACK \ | |
856 | _("cannot use writeback with PC-relative addressing") | |
9db2f6b4 RL |
857 | #define BAD_RANGE _("branch out of range") |
858 | #define BAD_FP16 _("selected processor does not support fp16 instruction") | |
dd5181d5 | 859 | #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour") |
a9f02af8 | 860 | #define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only") |
c19d1205 | 861 | |
c921be7d NC |
862 | static struct hash_control * arm_ops_hsh; |
863 | static struct hash_control * arm_cond_hsh; | |
864 | static struct hash_control * arm_shift_hsh; | |
865 | static struct hash_control * arm_psr_hsh; | |
866 | static struct hash_control * arm_v7m_psr_hsh; | |
867 | static struct hash_control * arm_reg_hsh; | |
868 | static struct hash_control * arm_reloc_hsh; | |
869 | static struct hash_control * arm_barrier_opt_hsh; | |
b99bd4ef | 870 | |
b99bd4ef NC |
871 | /* Stuff needed to resolve the label ambiguity |
872 | As: | |
873 | ... | |
874 | label: <insn> | |
875 | may differ from: | |
876 | ... | |
877 | label: | |
5f4273c7 | 878 | <insn> */ |
b99bd4ef NC |
879 | |
880 | symbolS * last_label_seen; | |
b34976b6 | 881 | static int label_is_thumb_function_name = FALSE; |
e07e6e58 | 882 | |
3d0c9500 NC |
883 | /* Literal pool structure. Held on a per-section |
884 | and per-sub-section basis. */ | |
a737bd4d | 885 | |
c19d1205 | 886 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 887 | typedef struct literal_pool |
b99bd4ef | 888 | { |
c921be7d NC |
889 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
890 | unsigned int next_free_entry; | |
891 | unsigned int id; | |
892 | symbolS * symbol; | |
893 | segT section; | |
894 | subsegT sub_section; | |
a8040cf2 NC |
895 | #ifdef OBJ_ELF |
896 | struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE]; | |
897 | #endif | |
c921be7d | 898 | struct literal_pool * next; |
8335d6aa | 899 | unsigned int alignment; |
3d0c9500 | 900 | } literal_pool; |
b99bd4ef | 901 | |
3d0c9500 NC |
902 | /* Pointer to a linked list of literal pools. */ |
903 | literal_pool * list_of_pools = NULL; | |
e27ec89e | 904 | |
2e6976a8 DG |
905 | typedef enum asmfunc_states |
906 | { | |
907 | OUTSIDE_ASMFUNC, | |
908 | WAITING_ASMFUNC_NAME, | |
909 | WAITING_ENDASMFUNC | |
910 | } asmfunc_states; | |
911 | ||
912 | static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC; | |
913 | ||
e07e6e58 NC |
914 | #ifdef OBJ_ELF |
915 | # define now_it seg_info (now_seg)->tc_segment_info_data.current_it | |
916 | #else | |
917 | static struct current_it now_it; | |
918 | #endif | |
919 | ||
920 | static inline int | |
921 | now_it_compatible (int cond) | |
922 | { | |
923 | return (cond & ~1) == (now_it.cc & ~1); | |
924 | } | |
925 | ||
926 | static inline int | |
927 | conditional_insn (void) | |
928 | { | |
929 | return inst.cond != COND_ALWAYS; | |
930 | } | |
931 | ||
932 | static int in_it_block (void); | |
933 | ||
934 | static int handle_it_state (void); | |
935 | ||
936 | static void force_automatic_it_block_close (void); | |
937 | ||
c921be7d NC |
938 | static void it_fsm_post_encode (void); |
939 | ||
e07e6e58 NC |
940 | #define set_it_insn_type(type) \ |
941 | do \ | |
942 | { \ | |
943 | inst.it_insn_type = type; \ | |
944 | if (handle_it_state () == FAIL) \ | |
477330fc | 945 | return; \ |
e07e6e58 NC |
946 | } \ |
947 | while (0) | |
948 | ||
c921be7d NC |
949 | #define set_it_insn_type_nonvoid(type, failret) \ |
950 | do \ | |
951 | { \ | |
952 | inst.it_insn_type = type; \ | |
953 | if (handle_it_state () == FAIL) \ | |
477330fc | 954 | return failret; \ |
c921be7d NC |
955 | } \ |
956 | while(0) | |
957 | ||
e07e6e58 NC |
958 | #define set_it_insn_type_last() \ |
959 | do \ | |
960 | { \ | |
961 | if (inst.cond == COND_ALWAYS) \ | |
477330fc | 962 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \ |
e07e6e58 | 963 | else \ |
477330fc | 964 | set_it_insn_type (INSIDE_IT_LAST_INSN); \ |
e07e6e58 NC |
965 | } \ |
966 | while (0) | |
967 | ||
c19d1205 | 968 | /* Pure syntax. */ |
b99bd4ef | 969 | |
c19d1205 ZW |
970 | /* This array holds the chars that always start a comment. If the |
971 | pre-processor is disabled, these aren't very useful. */ | |
2e6976a8 | 972 | char arm_comment_chars[] = "@"; |
3d0c9500 | 973 | |
c19d1205 ZW |
974 | /* This array holds the chars that only start a comment at the beginning of |
975 | a line. If the line seems to have the form '# 123 filename' | |
976 | .line and .file directives will appear in the pre-processed output. */ | |
977 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
978 | first line of the input file. This is because the compiler outputs | |
979 | #NO_APP at the beginning of its output. */ | |
980 | /* Also note that comments like this one will always work. */ | |
981 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 982 | |
2e6976a8 | 983 | char arm_line_separator_chars[] = ";"; |
b99bd4ef | 984 | |
c19d1205 ZW |
985 | /* Chars that can be used to separate mant |
986 | from exp in floating point numbers. */ | |
987 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 988 | |
c19d1205 ZW |
989 | /* Chars that mean this number is a floating point constant. */ |
990 | /* As in 0f12.456 */ | |
991 | /* or 0d1.2345e12 */ | |
b99bd4ef | 992 | |
c19d1205 | 993 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
3d0c9500 | 994 | |
c19d1205 ZW |
995 | /* Prefix characters that indicate the start of an immediate |
996 | value. */ | |
997 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 998 | |
c19d1205 ZW |
999 | /* Separator character handling. */ |
1000 | ||
1001 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
1002 | ||
1003 | static inline int | |
1004 | skip_past_char (char ** str, char c) | |
1005 | { | |
8ab8155f NC |
1006 | /* PR gas/14987: Allow for whitespace before the expected character. */ |
1007 | skip_whitespace (*str); | |
427d0db6 | 1008 | |
c19d1205 ZW |
1009 | if (**str == c) |
1010 | { | |
1011 | (*str)++; | |
1012 | return SUCCESS; | |
3d0c9500 | 1013 | } |
c19d1205 ZW |
1014 | else |
1015 | return FAIL; | |
1016 | } | |
c921be7d | 1017 | |
c19d1205 | 1018 | #define skip_past_comma(str) skip_past_char (str, ',') |
3d0c9500 | 1019 | |
c19d1205 ZW |
1020 | /* Arithmetic expressions (possibly involving symbols). */ |
1021 | ||
1022 | /* Return TRUE if anything in the expression is a bignum. */ | |
1023 | ||
0198d5e6 | 1024 | static bfd_boolean |
c19d1205 ZW |
1025 | walk_no_bignums (symbolS * sp) |
1026 | { | |
1027 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
0198d5e6 | 1028 | return TRUE; |
c19d1205 ZW |
1029 | |
1030 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 1031 | { |
c19d1205 ZW |
1032 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
1033 | || (symbol_get_value_expression (sp)->X_op_symbol | |
1034 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
1035 | } |
1036 | ||
0198d5e6 | 1037 | return FALSE; |
3d0c9500 NC |
1038 | } |
1039 | ||
0198d5e6 | 1040 | static bfd_boolean in_my_get_expression = FALSE; |
c19d1205 ZW |
1041 | |
1042 | /* Third argument to my_get_expression. */ | |
1043 | #define GE_NO_PREFIX 0 | |
1044 | #define GE_IMM_PREFIX 1 | |
1045 | #define GE_OPT_PREFIX 2 | |
5287ad62 JB |
1046 | /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit) |
1047 | immediates, as can be used in Neon VMVN and VMOV immediate instructions. */ | |
1048 | #define GE_OPT_PREFIX_BIG 3 | |
a737bd4d | 1049 | |
b99bd4ef | 1050 | static int |
c19d1205 | 1051 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 1052 | { |
c19d1205 | 1053 | char * save_in; |
b99bd4ef | 1054 | |
c19d1205 ZW |
1055 | /* In unified syntax, all prefixes are optional. */ |
1056 | if (unified_syntax) | |
5287ad62 | 1057 | prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode |
477330fc | 1058 | : GE_OPT_PREFIX; |
b99bd4ef | 1059 | |
c19d1205 | 1060 | switch (prefix_mode) |
b99bd4ef | 1061 | { |
c19d1205 ZW |
1062 | case GE_NO_PREFIX: break; |
1063 | case GE_IMM_PREFIX: | |
1064 | if (!is_immediate_prefix (**str)) | |
1065 | { | |
1066 | inst.error = _("immediate expression requires a # prefix"); | |
1067 | return FAIL; | |
1068 | } | |
1069 | (*str)++; | |
1070 | break; | |
1071 | case GE_OPT_PREFIX: | |
5287ad62 | 1072 | case GE_OPT_PREFIX_BIG: |
c19d1205 ZW |
1073 | if (is_immediate_prefix (**str)) |
1074 | (*str)++; | |
1075 | break; | |
0198d5e6 TC |
1076 | default: |
1077 | abort (); | |
c19d1205 | 1078 | } |
b99bd4ef | 1079 | |
c19d1205 | 1080 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 1081 | |
c19d1205 ZW |
1082 | save_in = input_line_pointer; |
1083 | input_line_pointer = *str; | |
0198d5e6 | 1084 | in_my_get_expression = TRUE; |
2ac93be7 | 1085 | expression (ep); |
0198d5e6 | 1086 | in_my_get_expression = FALSE; |
c19d1205 | 1087 | |
f86adc07 | 1088 | if (ep->X_op == O_illegal || ep->X_op == O_absent) |
b99bd4ef | 1089 | { |
f86adc07 | 1090 | /* We found a bad or missing expression in md_operand(). */ |
c19d1205 ZW |
1091 | *str = input_line_pointer; |
1092 | input_line_pointer = save_in; | |
1093 | if (inst.error == NULL) | |
f86adc07 NS |
1094 | inst.error = (ep->X_op == O_absent |
1095 | ? _("missing expression") :_("bad expression")); | |
c19d1205 ZW |
1096 | return 1; |
1097 | } | |
b99bd4ef | 1098 | |
c19d1205 ZW |
1099 | /* Get rid of any bignums now, so that we don't generate an error for which |
1100 | we can't establish a line number later on. Big numbers are never valid | |
1101 | in instructions, which is where this routine is always called. */ | |
5287ad62 JB |
1102 | if (prefix_mode != GE_OPT_PREFIX_BIG |
1103 | && (ep->X_op == O_big | |
477330fc | 1104 | || (ep->X_add_symbol |
5287ad62 | 1105 | && (walk_no_bignums (ep->X_add_symbol) |
477330fc | 1106 | || (ep->X_op_symbol |
5287ad62 | 1107 | && walk_no_bignums (ep->X_op_symbol)))))) |
c19d1205 ZW |
1108 | { |
1109 | inst.error = _("invalid constant"); | |
1110 | *str = input_line_pointer; | |
1111 | input_line_pointer = save_in; | |
1112 | return 1; | |
1113 | } | |
b99bd4ef | 1114 | |
c19d1205 ZW |
1115 | *str = input_line_pointer; |
1116 | input_line_pointer = save_in; | |
0198d5e6 | 1117 | return SUCCESS; |
b99bd4ef NC |
1118 | } |
1119 | ||
c19d1205 ZW |
1120 | /* Turn a string in input_line_pointer into a floating point constant |
1121 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
1122 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
1123 | returned, or NULL on OK. | |
b99bd4ef | 1124 | |
c19d1205 ZW |
1125 | Note that fp constants aren't represent in the normal way on the ARM. |
1126 | In big endian mode, things are as expected. However, in little endian | |
1127 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
1128 | within the words. For example, (double) 1.1 in big endian mode is | |
1129 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
1130 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 1131 | |
c19d1205 | 1132 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 1133 | |
6d4af3c2 | 1134 | const char * |
c19d1205 ZW |
1135 | md_atof (int type, char * litP, int * sizeP) |
1136 | { | |
1137 | int prec; | |
1138 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
1139 | char *t; | |
1140 | int i; | |
b99bd4ef | 1141 | |
c19d1205 ZW |
1142 | switch (type) |
1143 | { | |
1144 | case 'f': | |
1145 | case 'F': | |
1146 | case 's': | |
1147 | case 'S': | |
1148 | prec = 2; | |
1149 | break; | |
b99bd4ef | 1150 | |
c19d1205 ZW |
1151 | case 'd': |
1152 | case 'D': | |
1153 | case 'r': | |
1154 | case 'R': | |
1155 | prec = 4; | |
1156 | break; | |
b99bd4ef | 1157 | |
c19d1205 ZW |
1158 | case 'x': |
1159 | case 'X': | |
499ac353 | 1160 | prec = 5; |
c19d1205 | 1161 | break; |
b99bd4ef | 1162 | |
c19d1205 ZW |
1163 | case 'p': |
1164 | case 'P': | |
499ac353 | 1165 | prec = 5; |
c19d1205 | 1166 | break; |
a737bd4d | 1167 | |
c19d1205 ZW |
1168 | default: |
1169 | *sizeP = 0; | |
499ac353 | 1170 | return _("Unrecognized or unsupported floating point constant"); |
c19d1205 | 1171 | } |
b99bd4ef | 1172 | |
c19d1205 ZW |
1173 | t = atof_ieee (input_line_pointer, type, words); |
1174 | if (t) | |
1175 | input_line_pointer = t; | |
499ac353 | 1176 | *sizeP = prec * sizeof (LITTLENUM_TYPE); |
b99bd4ef | 1177 | |
c19d1205 ZW |
1178 | if (target_big_endian) |
1179 | { | |
1180 | for (i = 0; i < prec; i++) | |
1181 | { | |
499ac353 NC |
1182 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1183 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1184 | } |
1185 | } | |
1186 | else | |
1187 | { | |
e74cfd16 | 1188 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) |
c19d1205 ZW |
1189 | for (i = prec - 1; i >= 0; i--) |
1190 | { | |
499ac353 NC |
1191 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1192 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1193 | } |
1194 | else | |
1195 | /* For a 4 byte float the order of elements in `words' is 1 0. | |
1196 | For an 8 byte float the order is 1 0 3 2. */ | |
1197 | for (i = 0; i < prec; i += 2) | |
1198 | { | |
499ac353 NC |
1199 | md_number_to_chars (litP, (valueT) words[i + 1], |
1200 | sizeof (LITTLENUM_TYPE)); | |
1201 | md_number_to_chars (litP + sizeof (LITTLENUM_TYPE), | |
1202 | (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
1203 | litP += 2 * sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1204 | } |
1205 | } | |
b99bd4ef | 1206 | |
499ac353 | 1207 | return NULL; |
c19d1205 | 1208 | } |
b99bd4ef | 1209 | |
c19d1205 ZW |
1210 | /* We handle all bad expressions here, so that we can report the faulty |
1211 | instruction in the error message. */ | |
0198d5e6 | 1212 | |
c19d1205 | 1213 | void |
91d6fa6a | 1214 | md_operand (expressionS * exp) |
c19d1205 ZW |
1215 | { |
1216 | if (in_my_get_expression) | |
91d6fa6a | 1217 | exp->X_op = O_illegal; |
b99bd4ef NC |
1218 | } |
1219 | ||
c19d1205 | 1220 | /* Immediate values. */ |
b99bd4ef | 1221 | |
0198d5e6 | 1222 | #ifdef OBJ_ELF |
c19d1205 ZW |
1223 | /* Generic immediate-value read function for use in directives. |
1224 | Accepts anything that 'expression' can fold to a constant. | |
1225 | *val receives the number. */ | |
0198d5e6 | 1226 | |
c19d1205 ZW |
1227 | static int |
1228 | immediate_for_directive (int *val) | |
b99bd4ef | 1229 | { |
c19d1205 ZW |
1230 | expressionS exp; |
1231 | exp.X_op = O_illegal; | |
b99bd4ef | 1232 | |
c19d1205 ZW |
1233 | if (is_immediate_prefix (*input_line_pointer)) |
1234 | { | |
1235 | input_line_pointer++; | |
1236 | expression (&exp); | |
1237 | } | |
b99bd4ef | 1238 | |
c19d1205 ZW |
1239 | if (exp.X_op != O_constant) |
1240 | { | |
1241 | as_bad (_("expected #constant")); | |
1242 | ignore_rest_of_line (); | |
1243 | return FAIL; | |
1244 | } | |
1245 | *val = exp.X_add_number; | |
1246 | return SUCCESS; | |
b99bd4ef | 1247 | } |
c19d1205 | 1248 | #endif |
b99bd4ef | 1249 | |
c19d1205 | 1250 | /* Register parsing. */ |
b99bd4ef | 1251 | |
c19d1205 ZW |
1252 | /* Generic register parser. CCP points to what should be the |
1253 | beginning of a register name. If it is indeed a valid register | |
1254 | name, advance CCP over it and return the reg_entry structure; | |
1255 | otherwise return NULL. Does not issue diagnostics. */ | |
1256 | ||
1257 | static struct reg_entry * | |
1258 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 1259 | { |
c19d1205 ZW |
1260 | char *start = *ccp; |
1261 | char *p; | |
1262 | struct reg_entry *reg; | |
b99bd4ef | 1263 | |
477330fc RM |
1264 | skip_whitespace (start); |
1265 | ||
c19d1205 ZW |
1266 | #ifdef REGISTER_PREFIX |
1267 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 1268 | return NULL; |
c19d1205 ZW |
1269 | start++; |
1270 | #endif | |
1271 | #ifdef OPTIONAL_REGISTER_PREFIX | |
1272 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
1273 | start++; | |
1274 | #endif | |
b99bd4ef | 1275 | |
c19d1205 ZW |
1276 | p = start; |
1277 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
1278 | return NULL; | |
b99bd4ef | 1279 | |
c19d1205 ZW |
1280 | do |
1281 | p++; | |
1282 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
1283 | ||
1284 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
1285 | ||
1286 | if (!reg) | |
1287 | return NULL; | |
1288 | ||
1289 | *ccp = p; | |
1290 | return reg; | |
b99bd4ef NC |
1291 | } |
1292 | ||
1293 | static int | |
dcbf9037 | 1294 | arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg, |
477330fc | 1295 | enum arm_reg_type type) |
b99bd4ef | 1296 | { |
c19d1205 ZW |
1297 | /* Alternative syntaxes are accepted for a few register classes. */ |
1298 | switch (type) | |
1299 | { | |
1300 | case REG_TYPE_MVF: | |
1301 | case REG_TYPE_MVD: | |
1302 | case REG_TYPE_MVFX: | |
1303 | case REG_TYPE_MVDX: | |
1304 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 1305 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
1306 | return reg->number; |
1307 | break; | |
69b97547 | 1308 | |
c19d1205 ZW |
1309 | case REG_TYPE_CP: |
1310 | /* For backward compatibility, a bare number is valid here. */ | |
1311 | { | |
1312 | unsigned long processor = strtoul (start, ccp, 10); | |
1313 | if (*ccp != start && processor <= 15) | |
1314 | return processor; | |
1315 | } | |
1a0670f3 | 1316 | /* Fall through. */ |
6057a28f | 1317 | |
c19d1205 ZW |
1318 | case REG_TYPE_MMXWC: |
1319 | /* WC includes WCG. ??? I'm not sure this is true for all | |
1320 | instructions that take WC registers. */ | |
79134647 | 1321 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 1322 | return reg->number; |
6057a28f | 1323 | break; |
c19d1205 | 1324 | |
6057a28f | 1325 | default: |
c19d1205 | 1326 | break; |
6057a28f NC |
1327 | } |
1328 | ||
dcbf9037 JB |
1329 | return FAIL; |
1330 | } | |
1331 | ||
1332 | /* As arm_reg_parse_multi, but the register must be of type TYPE, and the | |
1333 | return value is the register number or FAIL. */ | |
1334 | ||
1335 | static int | |
1336 | arm_reg_parse (char **ccp, enum arm_reg_type type) | |
1337 | { | |
1338 | char *start = *ccp; | |
1339 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
1340 | int ret; | |
1341 | ||
1342 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1343 | if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX)) | |
1344 | return FAIL; | |
1345 | ||
1346 | if (reg && reg->type == type) | |
1347 | return reg->number; | |
1348 | ||
1349 | if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL) | |
1350 | return ret; | |
1351 | ||
c19d1205 ZW |
1352 | *ccp = start; |
1353 | return FAIL; | |
1354 | } | |
69b97547 | 1355 | |
dcbf9037 JB |
1356 | /* Parse a Neon type specifier. *STR should point at the leading '.' |
1357 | character. Does no verification at this stage that the type fits the opcode | |
1358 | properly. E.g., | |
1359 | ||
1360 | .i32.i32.s16 | |
1361 | .s32.f32 | |
1362 | .u16 | |
1363 | ||
1364 | Can all be legally parsed by this function. | |
1365 | ||
1366 | Fills in neon_type struct pointer with parsed information, and updates STR | |
1367 | to point after the parsed type specifier. Returns SUCCESS if this was a legal | |
1368 | type, FAIL if not. */ | |
1369 | ||
1370 | static int | |
1371 | parse_neon_type (struct neon_type *type, char **str) | |
1372 | { | |
1373 | char *ptr = *str; | |
1374 | ||
1375 | if (type) | |
1376 | type->elems = 0; | |
1377 | ||
1378 | while (type->elems < NEON_MAX_TYPE_ELS) | |
1379 | { | |
1380 | enum neon_el_type thistype = NT_untyped; | |
1381 | unsigned thissize = -1u; | |
1382 | ||
1383 | if (*ptr != '.') | |
1384 | break; | |
1385 | ||
1386 | ptr++; | |
1387 | ||
1388 | /* Just a size without an explicit type. */ | |
1389 | if (ISDIGIT (*ptr)) | |
1390 | goto parsesize; | |
1391 | ||
1392 | switch (TOLOWER (*ptr)) | |
1393 | { | |
1394 | case 'i': thistype = NT_integer; break; | |
1395 | case 'f': thistype = NT_float; break; | |
1396 | case 'p': thistype = NT_poly; break; | |
1397 | case 's': thistype = NT_signed; break; | |
1398 | case 'u': thistype = NT_unsigned; break; | |
477330fc RM |
1399 | case 'd': |
1400 | thistype = NT_float; | |
1401 | thissize = 64; | |
1402 | ptr++; | |
1403 | goto done; | |
dcbf9037 JB |
1404 | default: |
1405 | as_bad (_("unexpected character `%c' in type specifier"), *ptr); | |
1406 | return FAIL; | |
1407 | } | |
1408 | ||
1409 | ptr++; | |
1410 | ||
1411 | /* .f is an abbreviation for .f32. */ | |
1412 | if (thistype == NT_float && !ISDIGIT (*ptr)) | |
1413 | thissize = 32; | |
1414 | else | |
1415 | { | |
1416 | parsesize: | |
1417 | thissize = strtoul (ptr, &ptr, 10); | |
1418 | ||
1419 | if (thissize != 8 && thissize != 16 && thissize != 32 | |
477330fc RM |
1420 | && thissize != 64) |
1421 | { | |
1422 | as_bad (_("bad size %d in type specifier"), thissize); | |
dcbf9037 JB |
1423 | return FAIL; |
1424 | } | |
1425 | } | |
1426 | ||
037e8744 | 1427 | done: |
dcbf9037 | 1428 | if (type) |
477330fc RM |
1429 | { |
1430 | type->el[type->elems].type = thistype; | |
dcbf9037 JB |
1431 | type->el[type->elems].size = thissize; |
1432 | type->elems++; | |
1433 | } | |
1434 | } | |
1435 | ||
1436 | /* Empty/missing type is not a successful parse. */ | |
1437 | if (type->elems == 0) | |
1438 | return FAIL; | |
1439 | ||
1440 | *str = ptr; | |
1441 | ||
1442 | return SUCCESS; | |
1443 | } | |
1444 | ||
1445 | /* Errors may be set multiple times during parsing or bit encoding | |
1446 | (particularly in the Neon bits), but usually the earliest error which is set | |
1447 | will be the most meaningful. Avoid overwriting it with later (cascading) | |
1448 | errors by calling this function. */ | |
1449 | ||
1450 | static void | |
1451 | first_error (const char *err) | |
1452 | { | |
1453 | if (!inst.error) | |
1454 | inst.error = err; | |
1455 | } | |
1456 | ||
1457 | /* Parse a single type, e.g. ".s32", leading period included. */ | |
1458 | static int | |
1459 | parse_neon_operand_type (struct neon_type_el *vectype, char **ccp) | |
1460 | { | |
1461 | char *str = *ccp; | |
1462 | struct neon_type optype; | |
1463 | ||
1464 | if (*str == '.') | |
1465 | { | |
1466 | if (parse_neon_type (&optype, &str) == SUCCESS) | |
477330fc RM |
1467 | { |
1468 | if (optype.elems == 1) | |
1469 | *vectype = optype.el[0]; | |
1470 | else | |
1471 | { | |
1472 | first_error (_("only one type should be specified for operand")); | |
1473 | return FAIL; | |
1474 | } | |
1475 | } | |
dcbf9037 | 1476 | else |
477330fc RM |
1477 | { |
1478 | first_error (_("vector type expected")); | |
1479 | return FAIL; | |
1480 | } | |
dcbf9037 JB |
1481 | } |
1482 | else | |
1483 | return FAIL; | |
5f4273c7 | 1484 | |
dcbf9037 | 1485 | *ccp = str; |
5f4273c7 | 1486 | |
dcbf9037 JB |
1487 | return SUCCESS; |
1488 | } | |
1489 | ||
1490 | /* Special meanings for indices (which have a range of 0-7), which will fit into | |
1491 | a 4-bit integer. */ | |
1492 | ||
1493 | #define NEON_ALL_LANES 15 | |
1494 | #define NEON_INTERLEAVE_LANES 14 | |
1495 | ||
1496 | /* Parse either a register or a scalar, with an optional type. Return the | |
1497 | register number, and optionally fill in the actual type of the register | |
1498 | when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and | |
1499 | type/index information in *TYPEINFO. */ | |
1500 | ||
1501 | static int | |
1502 | parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type, | |
477330fc RM |
1503 | enum arm_reg_type *rtype, |
1504 | struct neon_typed_alias *typeinfo) | |
dcbf9037 JB |
1505 | { |
1506 | char *str = *ccp; | |
1507 | struct reg_entry *reg = arm_reg_parse_multi (&str); | |
1508 | struct neon_typed_alias atype; | |
1509 | struct neon_type_el parsetype; | |
1510 | ||
1511 | atype.defined = 0; | |
1512 | atype.index = -1; | |
1513 | atype.eltype.type = NT_invtype; | |
1514 | atype.eltype.size = -1; | |
1515 | ||
1516 | /* Try alternate syntax for some types of register. Note these are mutually | |
1517 | exclusive with the Neon syntax extensions. */ | |
1518 | if (reg == NULL) | |
1519 | { | |
1520 | int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type); | |
1521 | if (altreg != FAIL) | |
477330fc | 1522 | *ccp = str; |
dcbf9037 | 1523 | if (typeinfo) |
477330fc | 1524 | *typeinfo = atype; |
dcbf9037 JB |
1525 | return altreg; |
1526 | } | |
1527 | ||
037e8744 JB |
1528 | /* Undo polymorphism when a set of register types may be accepted. */ |
1529 | if ((type == REG_TYPE_NDQ | |
1530 | && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD)) | |
1531 | || (type == REG_TYPE_VFSD | |
477330fc | 1532 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) |
037e8744 | 1533 | || (type == REG_TYPE_NSDQ |
477330fc RM |
1534 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD |
1535 | || reg->type == REG_TYPE_NQ)) | |
dec41383 JW |
1536 | || (type == REG_TYPE_NSD |
1537 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) | |
f512f76f NC |
1538 | || (type == REG_TYPE_MMXWC |
1539 | && (reg->type == REG_TYPE_MMXWCG))) | |
21d799b5 | 1540 | type = (enum arm_reg_type) reg->type; |
dcbf9037 JB |
1541 | |
1542 | if (type != reg->type) | |
1543 | return FAIL; | |
1544 | ||
1545 | if (reg->neon) | |
1546 | atype = *reg->neon; | |
5f4273c7 | 1547 | |
dcbf9037 JB |
1548 | if (parse_neon_operand_type (&parsetype, &str) == SUCCESS) |
1549 | { | |
1550 | if ((atype.defined & NTA_HASTYPE) != 0) | |
477330fc RM |
1551 | { |
1552 | first_error (_("can't redefine type for operand")); | |
1553 | return FAIL; | |
1554 | } | |
dcbf9037 JB |
1555 | atype.defined |= NTA_HASTYPE; |
1556 | atype.eltype = parsetype; | |
1557 | } | |
5f4273c7 | 1558 | |
dcbf9037 JB |
1559 | if (skip_past_char (&str, '[') == SUCCESS) |
1560 | { | |
dec41383 JW |
1561 | if (type != REG_TYPE_VFD |
1562 | && !(type == REG_TYPE_VFS | |
1563 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))) | |
477330fc RM |
1564 | { |
1565 | first_error (_("only D registers may be indexed")); | |
1566 | return FAIL; | |
1567 | } | |
5f4273c7 | 1568 | |
dcbf9037 | 1569 | if ((atype.defined & NTA_HASINDEX) != 0) |
477330fc RM |
1570 | { |
1571 | first_error (_("can't change index for operand")); | |
1572 | return FAIL; | |
1573 | } | |
dcbf9037 JB |
1574 | |
1575 | atype.defined |= NTA_HASINDEX; | |
1576 | ||
1577 | if (skip_past_char (&str, ']') == SUCCESS) | |
477330fc | 1578 | atype.index = NEON_ALL_LANES; |
dcbf9037 | 1579 | else |
477330fc RM |
1580 | { |
1581 | expressionS exp; | |
dcbf9037 | 1582 | |
477330fc | 1583 | my_get_expression (&exp, &str, GE_NO_PREFIX); |
dcbf9037 | 1584 | |
477330fc RM |
1585 | if (exp.X_op != O_constant) |
1586 | { | |
1587 | first_error (_("constant expression required")); | |
1588 | return FAIL; | |
1589 | } | |
dcbf9037 | 1590 | |
477330fc RM |
1591 | if (skip_past_char (&str, ']') == FAIL) |
1592 | return FAIL; | |
dcbf9037 | 1593 | |
477330fc RM |
1594 | atype.index = exp.X_add_number; |
1595 | } | |
dcbf9037 | 1596 | } |
5f4273c7 | 1597 | |
dcbf9037 JB |
1598 | if (typeinfo) |
1599 | *typeinfo = atype; | |
5f4273c7 | 1600 | |
dcbf9037 JB |
1601 | if (rtype) |
1602 | *rtype = type; | |
5f4273c7 | 1603 | |
dcbf9037 | 1604 | *ccp = str; |
5f4273c7 | 1605 | |
dcbf9037 JB |
1606 | return reg->number; |
1607 | } | |
1608 | ||
efd6b359 | 1609 | /* Like arm_reg_parse, but also allow the following extra features: |
dcbf9037 JB |
1610 | - If RTYPE is non-zero, return the (possibly restricted) type of the |
1611 | register (e.g. Neon double or quad reg when either has been requested). | |
1612 | - If this is a Neon vector type with additional type information, fill | |
1613 | in the struct pointed to by VECTYPE (if non-NULL). | |
5f4273c7 | 1614 | This function will fault on encountering a scalar. */ |
dcbf9037 JB |
1615 | |
1616 | static int | |
1617 | arm_typed_reg_parse (char **ccp, enum arm_reg_type type, | |
477330fc | 1618 | enum arm_reg_type *rtype, struct neon_type_el *vectype) |
dcbf9037 JB |
1619 | { |
1620 | struct neon_typed_alias atype; | |
1621 | char *str = *ccp; | |
1622 | int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype); | |
1623 | ||
1624 | if (reg == FAIL) | |
1625 | return FAIL; | |
1626 | ||
0855e32b NS |
1627 | /* Do not allow regname(... to parse as a register. */ |
1628 | if (*str == '(') | |
1629 | return FAIL; | |
1630 | ||
dcbf9037 JB |
1631 | /* Do not allow a scalar (reg+index) to parse as a register. */ |
1632 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1633 | { | |
1634 | first_error (_("register operand expected, but got scalar")); | |
1635 | return FAIL; | |
1636 | } | |
1637 | ||
1638 | if (vectype) | |
1639 | *vectype = atype.eltype; | |
1640 | ||
1641 | *ccp = str; | |
1642 | ||
1643 | return reg; | |
1644 | } | |
1645 | ||
1646 | #define NEON_SCALAR_REG(X) ((X) >> 4) | |
1647 | #define NEON_SCALAR_INDEX(X) ((X) & 15) | |
1648 | ||
5287ad62 JB |
1649 | /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't |
1650 | have enough information to be able to do a good job bounds-checking. So, we | |
1651 | just do easy checks here, and do further checks later. */ | |
1652 | ||
1653 | static int | |
dcbf9037 | 1654 | parse_scalar (char **ccp, int elsize, struct neon_type_el *type) |
5287ad62 | 1655 | { |
dcbf9037 | 1656 | int reg; |
5287ad62 | 1657 | char *str = *ccp; |
dcbf9037 | 1658 | struct neon_typed_alias atype; |
dec41383 JW |
1659 | enum arm_reg_type reg_type = REG_TYPE_VFD; |
1660 | ||
1661 | if (elsize == 4) | |
1662 | reg_type = REG_TYPE_VFS; | |
5f4273c7 | 1663 | |
dec41383 | 1664 | reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype); |
5f4273c7 | 1665 | |
dcbf9037 | 1666 | if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0) |
5287ad62 | 1667 | return FAIL; |
5f4273c7 | 1668 | |
dcbf9037 | 1669 | if (atype.index == NEON_ALL_LANES) |
5287ad62 | 1670 | { |
dcbf9037 | 1671 | first_error (_("scalar must have an index")); |
5287ad62 JB |
1672 | return FAIL; |
1673 | } | |
dcbf9037 | 1674 | else if (atype.index >= 64 / elsize) |
5287ad62 | 1675 | { |
dcbf9037 | 1676 | first_error (_("scalar index out of range")); |
5287ad62 JB |
1677 | return FAIL; |
1678 | } | |
5f4273c7 | 1679 | |
dcbf9037 JB |
1680 | if (type) |
1681 | *type = atype.eltype; | |
5f4273c7 | 1682 | |
5287ad62 | 1683 | *ccp = str; |
5f4273c7 | 1684 | |
dcbf9037 | 1685 | return reg * 16 + atype.index; |
5287ad62 JB |
1686 | } |
1687 | ||
4b5a202f AV |
1688 | /* Types of registers in a list. */ |
1689 | ||
1690 | enum reg_list_els | |
1691 | { | |
1692 | REGLIST_RN, | |
1693 | REGLIST_CLRM, | |
1694 | REGLIST_VFP_S, | |
efd6b359 | 1695 | REGLIST_VFP_S_VPR, |
4b5a202f | 1696 | REGLIST_VFP_D, |
efd6b359 | 1697 | REGLIST_VFP_D_VPR, |
4b5a202f AV |
1698 | REGLIST_NEON_D |
1699 | }; | |
1700 | ||
c19d1205 | 1701 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
e07e6e58 | 1702 | |
c19d1205 | 1703 | static long |
4b5a202f | 1704 | parse_reg_list (char ** strp, enum reg_list_els etype) |
c19d1205 | 1705 | { |
4b5a202f AV |
1706 | char *str = *strp; |
1707 | long range = 0; | |
1708 | int another_range; | |
1709 | ||
1710 | gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM); | |
a737bd4d | 1711 | |
c19d1205 ZW |
1712 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
1713 | do | |
6057a28f | 1714 | { |
477330fc RM |
1715 | skip_whitespace (str); |
1716 | ||
c19d1205 | 1717 | another_range = 0; |
a737bd4d | 1718 | |
c19d1205 ZW |
1719 | if (*str == '{') |
1720 | { | |
1721 | int in_range = 0; | |
1722 | int cur_reg = -1; | |
a737bd4d | 1723 | |
c19d1205 ZW |
1724 | str++; |
1725 | do | |
1726 | { | |
1727 | int reg; | |
4b5a202f AV |
1728 | const char apsr_str[] = "apsr"; |
1729 | int apsr_str_len = strlen (apsr_str); | |
6057a28f | 1730 | |
4b5a202f AV |
1731 | reg = arm_reg_parse (&str, REGLIST_RN); |
1732 | if (etype == REGLIST_CLRM) | |
c19d1205 | 1733 | { |
4b5a202f AV |
1734 | if (reg == REG_SP || reg == REG_PC) |
1735 | reg = FAIL; | |
1736 | else if (reg == FAIL | |
1737 | && !strncasecmp (str, apsr_str, apsr_str_len) | |
1738 | && !ISALPHA (*(str + apsr_str_len))) | |
1739 | { | |
1740 | reg = 15; | |
1741 | str += apsr_str_len; | |
1742 | } | |
1743 | ||
1744 | if (reg == FAIL) | |
1745 | { | |
1746 | first_error (_("r0-r12, lr or APSR expected")); | |
1747 | return FAIL; | |
1748 | } | |
1749 | } | |
1750 | else /* etype == REGLIST_RN. */ | |
1751 | { | |
1752 | if (reg == FAIL) | |
1753 | { | |
1754 | first_error (_(reg_expected_msgs[REGLIST_RN])); | |
1755 | return FAIL; | |
1756 | } | |
c19d1205 | 1757 | } |
a737bd4d | 1758 | |
c19d1205 ZW |
1759 | if (in_range) |
1760 | { | |
1761 | int i; | |
a737bd4d | 1762 | |
c19d1205 ZW |
1763 | if (reg <= cur_reg) |
1764 | { | |
dcbf9037 | 1765 | first_error (_("bad range in register list")); |
c19d1205 ZW |
1766 | return FAIL; |
1767 | } | |
40a18ebd | 1768 | |
c19d1205 ZW |
1769 | for (i = cur_reg + 1; i < reg; i++) |
1770 | { | |
1771 | if (range & (1 << i)) | |
1772 | as_tsktsk | |
1773 | (_("Warning: duplicated register (r%d) in register list"), | |
1774 | i); | |
1775 | else | |
1776 | range |= 1 << i; | |
1777 | } | |
1778 | in_range = 0; | |
1779 | } | |
a737bd4d | 1780 | |
c19d1205 ZW |
1781 | if (range & (1 << reg)) |
1782 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1783 | reg); | |
1784 | else if (reg <= cur_reg) | |
1785 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1786 | |
c19d1205 ZW |
1787 | range |= 1 << reg; |
1788 | cur_reg = reg; | |
1789 | } | |
1790 | while (skip_past_comma (&str) != FAIL | |
1791 | || (in_range = 1, *str++ == '-')); | |
1792 | str--; | |
a737bd4d | 1793 | |
d996d970 | 1794 | if (skip_past_char (&str, '}') == FAIL) |
c19d1205 | 1795 | { |
dcbf9037 | 1796 | first_error (_("missing `}'")); |
c19d1205 ZW |
1797 | return FAIL; |
1798 | } | |
1799 | } | |
4b5a202f | 1800 | else if (etype == REGLIST_RN) |
c19d1205 | 1801 | { |
91d6fa6a | 1802 | expressionS exp; |
40a18ebd | 1803 | |
91d6fa6a | 1804 | if (my_get_expression (&exp, &str, GE_NO_PREFIX)) |
c19d1205 | 1805 | return FAIL; |
40a18ebd | 1806 | |
91d6fa6a | 1807 | if (exp.X_op == O_constant) |
c19d1205 | 1808 | { |
91d6fa6a NC |
1809 | if (exp.X_add_number |
1810 | != (exp.X_add_number & 0x0000ffff)) | |
c19d1205 ZW |
1811 | { |
1812 | inst.error = _("invalid register mask"); | |
1813 | return FAIL; | |
1814 | } | |
a737bd4d | 1815 | |
91d6fa6a | 1816 | if ((range & exp.X_add_number) != 0) |
c19d1205 | 1817 | { |
91d6fa6a | 1818 | int regno = range & exp.X_add_number; |
a737bd4d | 1819 | |
c19d1205 ZW |
1820 | regno &= -regno; |
1821 | regno = (1 << regno) - 1; | |
1822 | as_tsktsk | |
1823 | (_("Warning: duplicated register (r%d) in register list"), | |
1824 | regno); | |
1825 | } | |
a737bd4d | 1826 | |
91d6fa6a | 1827 | range |= exp.X_add_number; |
c19d1205 ZW |
1828 | } |
1829 | else | |
1830 | { | |
e2b0ab59 | 1831 | if (inst.relocs[0].type != 0) |
c19d1205 ZW |
1832 | { |
1833 | inst.error = _("expression too complex"); | |
1834 | return FAIL; | |
1835 | } | |
a737bd4d | 1836 | |
e2b0ab59 AV |
1837 | memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS)); |
1838 | inst.relocs[0].type = BFD_RELOC_ARM_MULTI; | |
1839 | inst.relocs[0].pc_rel = 0; | |
c19d1205 ZW |
1840 | } |
1841 | } | |
a737bd4d | 1842 | |
c19d1205 ZW |
1843 | if (*str == '|' || *str == '+') |
1844 | { | |
1845 | str++; | |
1846 | another_range = 1; | |
1847 | } | |
a737bd4d | 1848 | } |
c19d1205 | 1849 | while (another_range); |
a737bd4d | 1850 | |
c19d1205 ZW |
1851 | *strp = str; |
1852 | return range; | |
a737bd4d NC |
1853 | } |
1854 | ||
c19d1205 ZW |
1855 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1856 | Otherwise return the number of registers, and set PBASE to the first | |
5287ad62 JB |
1857 | register. Parses registers of type ETYPE. |
1858 | If REGLIST_NEON_D is used, several syntax enhancements are enabled: | |
1859 | - Q registers can be used to specify pairs of D registers | |
1860 | - { } can be omitted from around a singleton register list | |
477330fc RM |
1861 | FIXME: This is not implemented, as it would require backtracking in |
1862 | some cases, e.g.: | |
1863 | vtbl.8 d3,d4,d5 | |
1864 | This could be done (the meaning isn't really ambiguous), but doesn't | |
1865 | fit in well with the current parsing framework. | |
dcbf9037 JB |
1866 | - 32 D registers may be used (also true for VFPv3). |
1867 | FIXME: Types are ignored in these register lists, which is probably a | |
1868 | bug. */ | |
6057a28f | 1869 | |
c19d1205 | 1870 | static int |
efd6b359 AV |
1871 | parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype, |
1872 | bfd_boolean *partial_match) | |
6057a28f | 1873 | { |
037e8744 | 1874 | char *str = *ccp; |
c19d1205 ZW |
1875 | int base_reg; |
1876 | int new_base; | |
21d799b5 | 1877 | enum arm_reg_type regtype = (enum arm_reg_type) 0; |
5287ad62 | 1878 | int max_regs = 0; |
c19d1205 ZW |
1879 | int count = 0; |
1880 | int warned = 0; | |
1881 | unsigned long mask = 0; | |
a737bd4d | 1882 | int i; |
efd6b359 AV |
1883 | bfd_boolean vpr_seen = FALSE; |
1884 | bfd_boolean expect_vpr = | |
1885 | (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR); | |
6057a28f | 1886 | |
477330fc | 1887 | if (skip_past_char (&str, '{') == FAIL) |
5287ad62 JB |
1888 | { |
1889 | inst.error = _("expecting {"); | |
1890 | return FAIL; | |
1891 | } | |
6057a28f | 1892 | |
5287ad62 | 1893 | switch (etype) |
c19d1205 | 1894 | { |
5287ad62 | 1895 | case REGLIST_VFP_S: |
efd6b359 | 1896 | case REGLIST_VFP_S_VPR: |
c19d1205 ZW |
1897 | regtype = REG_TYPE_VFS; |
1898 | max_regs = 32; | |
5287ad62 | 1899 | break; |
5f4273c7 | 1900 | |
5287ad62 | 1901 | case REGLIST_VFP_D: |
efd6b359 | 1902 | case REGLIST_VFP_D_VPR: |
5287ad62 | 1903 | regtype = REG_TYPE_VFD; |
b7fc2769 | 1904 | break; |
5f4273c7 | 1905 | |
b7fc2769 JB |
1906 | case REGLIST_NEON_D: |
1907 | regtype = REG_TYPE_NDQ; | |
1908 | break; | |
4b5a202f AV |
1909 | |
1910 | default: | |
1911 | gas_assert (0); | |
b7fc2769 JB |
1912 | } |
1913 | ||
efd6b359 | 1914 | if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR) |
b7fc2769 | 1915 | { |
b1cc4aeb PB |
1916 | /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */ |
1917 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) | |
477330fc RM |
1918 | { |
1919 | max_regs = 32; | |
1920 | if (thumb_mode) | |
1921 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
1922 | fpu_vfp_ext_d32); | |
1923 | else | |
1924 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
1925 | fpu_vfp_ext_d32); | |
1926 | } | |
5287ad62 | 1927 | else |
477330fc | 1928 | max_regs = 16; |
c19d1205 | 1929 | } |
6057a28f | 1930 | |
c19d1205 | 1931 | base_reg = max_regs; |
efd6b359 | 1932 | *partial_match = FALSE; |
a737bd4d | 1933 | |
c19d1205 ZW |
1934 | do |
1935 | { | |
5287ad62 | 1936 | int setmask = 1, addregs = 1; |
efd6b359 AV |
1937 | const char vpr_str[] = "vpr"; |
1938 | int vpr_str_len = strlen (vpr_str); | |
dcbf9037 | 1939 | |
037e8744 | 1940 | new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL); |
dcbf9037 | 1941 | |
efd6b359 AV |
1942 | if (expect_vpr) |
1943 | { | |
1944 | if (new_base == FAIL | |
1945 | && !strncasecmp (str, vpr_str, vpr_str_len) | |
1946 | && !ISALPHA (*(str + vpr_str_len)) | |
1947 | && !vpr_seen) | |
1948 | { | |
1949 | vpr_seen = TRUE; | |
1950 | str += vpr_str_len; | |
1951 | if (count == 0) | |
1952 | base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */ | |
1953 | } | |
1954 | else if (vpr_seen) | |
1955 | { | |
1956 | first_error (_("VPR expected last")); | |
1957 | return FAIL; | |
1958 | } | |
1959 | else if (new_base == FAIL) | |
1960 | { | |
1961 | if (regtype == REG_TYPE_VFS) | |
1962 | first_error (_("VFP single precision register or VPR " | |
1963 | "expected")); | |
1964 | else /* regtype == REG_TYPE_VFD. */ | |
1965 | first_error (_("VFP/Neon double precision register or VPR " | |
1966 | "expected")); | |
1967 | return FAIL; | |
1968 | } | |
1969 | } | |
1970 | else if (new_base == FAIL) | |
a737bd4d | 1971 | { |
dcbf9037 | 1972 | first_error (_(reg_expected_msgs[regtype])); |
c19d1205 ZW |
1973 | return FAIL; |
1974 | } | |
5f4273c7 | 1975 | |
efd6b359 AV |
1976 | *partial_match = TRUE; |
1977 | if (vpr_seen) | |
1978 | continue; | |
1979 | ||
b7fc2769 | 1980 | if (new_base >= max_regs) |
477330fc RM |
1981 | { |
1982 | first_error (_("register out of range in list")); | |
1983 | return FAIL; | |
1984 | } | |
5f4273c7 | 1985 | |
5287ad62 JB |
1986 | /* Note: a value of 2 * n is returned for the register Q<n>. */ |
1987 | if (regtype == REG_TYPE_NQ) | |
477330fc RM |
1988 | { |
1989 | setmask = 3; | |
1990 | addregs = 2; | |
1991 | } | |
5287ad62 | 1992 | |
c19d1205 ZW |
1993 | if (new_base < base_reg) |
1994 | base_reg = new_base; | |
a737bd4d | 1995 | |
5287ad62 | 1996 | if (mask & (setmask << new_base)) |
c19d1205 | 1997 | { |
dcbf9037 | 1998 | first_error (_("invalid register list")); |
c19d1205 | 1999 | return FAIL; |
a737bd4d | 2000 | } |
a737bd4d | 2001 | |
efd6b359 | 2002 | if ((mask >> new_base) != 0 && ! warned && !vpr_seen) |
c19d1205 ZW |
2003 | { |
2004 | as_tsktsk (_("register list not in ascending order")); | |
2005 | warned = 1; | |
2006 | } | |
0bbf2aa4 | 2007 | |
5287ad62 JB |
2008 | mask |= setmask << new_base; |
2009 | count += addregs; | |
0bbf2aa4 | 2010 | |
037e8744 | 2011 | if (*str == '-') /* We have the start of a range expression */ |
c19d1205 ZW |
2012 | { |
2013 | int high_range; | |
0bbf2aa4 | 2014 | |
037e8744 | 2015 | str++; |
0bbf2aa4 | 2016 | |
037e8744 | 2017 | if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL)) |
477330fc | 2018 | == FAIL) |
c19d1205 ZW |
2019 | { |
2020 | inst.error = gettext (reg_expected_msgs[regtype]); | |
2021 | return FAIL; | |
2022 | } | |
0bbf2aa4 | 2023 | |
477330fc RM |
2024 | if (high_range >= max_regs) |
2025 | { | |
2026 | first_error (_("register out of range in list")); | |
2027 | return FAIL; | |
2028 | } | |
b7fc2769 | 2029 | |
477330fc RM |
2030 | if (regtype == REG_TYPE_NQ) |
2031 | high_range = high_range + 1; | |
5287ad62 | 2032 | |
c19d1205 ZW |
2033 | if (high_range <= new_base) |
2034 | { | |
2035 | inst.error = _("register range not in ascending order"); | |
2036 | return FAIL; | |
2037 | } | |
0bbf2aa4 | 2038 | |
5287ad62 | 2039 | for (new_base += addregs; new_base <= high_range; new_base += addregs) |
0bbf2aa4 | 2040 | { |
5287ad62 | 2041 | if (mask & (setmask << new_base)) |
0bbf2aa4 | 2042 | { |
c19d1205 ZW |
2043 | inst.error = _("invalid register list"); |
2044 | return FAIL; | |
0bbf2aa4 | 2045 | } |
c19d1205 | 2046 | |
5287ad62 JB |
2047 | mask |= setmask << new_base; |
2048 | count += addregs; | |
0bbf2aa4 | 2049 | } |
0bbf2aa4 | 2050 | } |
0bbf2aa4 | 2051 | } |
037e8744 | 2052 | while (skip_past_comma (&str) != FAIL); |
0bbf2aa4 | 2053 | |
037e8744 | 2054 | str++; |
0bbf2aa4 | 2055 | |
c19d1205 | 2056 | /* Sanity check -- should have raised a parse error above. */ |
efd6b359 | 2057 | if ((!vpr_seen && count == 0) || count > max_regs) |
c19d1205 ZW |
2058 | abort (); |
2059 | ||
2060 | *pbase = base_reg; | |
2061 | ||
efd6b359 AV |
2062 | if (expect_vpr && !vpr_seen) |
2063 | { | |
2064 | first_error (_("VPR expected last")); | |
2065 | return FAIL; | |
2066 | } | |
2067 | ||
c19d1205 ZW |
2068 | /* Final test -- the registers must be consecutive. */ |
2069 | mask >>= base_reg; | |
2070 | for (i = 0; i < count; i++) | |
2071 | { | |
2072 | if ((mask & (1u << i)) == 0) | |
2073 | { | |
2074 | inst.error = _("non-contiguous register range"); | |
2075 | return FAIL; | |
2076 | } | |
2077 | } | |
2078 | ||
037e8744 JB |
2079 | *ccp = str; |
2080 | ||
c19d1205 | 2081 | return count; |
b99bd4ef NC |
2082 | } |
2083 | ||
dcbf9037 JB |
2084 | /* True if two alias types are the same. */ |
2085 | ||
c921be7d | 2086 | static bfd_boolean |
dcbf9037 JB |
2087 | neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b) |
2088 | { | |
2089 | if (!a && !b) | |
c921be7d | 2090 | return TRUE; |
5f4273c7 | 2091 | |
dcbf9037 | 2092 | if (!a || !b) |
c921be7d | 2093 | return FALSE; |
dcbf9037 JB |
2094 | |
2095 | if (a->defined != b->defined) | |
c921be7d | 2096 | return FALSE; |
5f4273c7 | 2097 | |
dcbf9037 JB |
2098 | if ((a->defined & NTA_HASTYPE) != 0 |
2099 | && (a->eltype.type != b->eltype.type | |
477330fc | 2100 | || a->eltype.size != b->eltype.size)) |
c921be7d | 2101 | return FALSE; |
dcbf9037 JB |
2102 | |
2103 | if ((a->defined & NTA_HASINDEX) != 0 | |
2104 | && (a->index != b->index)) | |
c921be7d | 2105 | return FALSE; |
5f4273c7 | 2106 | |
c921be7d | 2107 | return TRUE; |
dcbf9037 JB |
2108 | } |
2109 | ||
5287ad62 JB |
2110 | /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions. |
2111 | The base register is put in *PBASE. | |
dcbf9037 | 2112 | The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of |
5287ad62 JB |
2113 | the return value. |
2114 | The register stride (minus one) is put in bit 4 of the return value. | |
dcbf9037 JB |
2115 | Bits [6:5] encode the list length (minus one). |
2116 | The type of the list elements is put in *ELTYPE, if non-NULL. */ | |
5287ad62 | 2117 | |
5287ad62 | 2118 | #define NEON_LANE(X) ((X) & 0xf) |
dcbf9037 | 2119 | #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1) |
5287ad62 JB |
2120 | #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1) |
2121 | ||
2122 | static int | |
dcbf9037 | 2123 | parse_neon_el_struct_list (char **str, unsigned *pbase, |
477330fc | 2124 | struct neon_type_el *eltype) |
5287ad62 JB |
2125 | { |
2126 | char *ptr = *str; | |
2127 | int base_reg = -1; | |
2128 | int reg_incr = -1; | |
2129 | int count = 0; | |
2130 | int lane = -1; | |
2131 | int leading_brace = 0; | |
2132 | enum arm_reg_type rtype = REG_TYPE_NDQ; | |
20203fb9 NC |
2133 | const char *const incr_error = _("register stride must be 1 or 2"); |
2134 | const char *const type_error = _("mismatched element/structure types in list"); | |
dcbf9037 | 2135 | struct neon_typed_alias firsttype; |
f85d59c3 KT |
2136 | firsttype.defined = 0; |
2137 | firsttype.eltype.type = NT_invtype; | |
2138 | firsttype.eltype.size = -1; | |
2139 | firsttype.index = -1; | |
5f4273c7 | 2140 | |
5287ad62 JB |
2141 | if (skip_past_char (&ptr, '{') == SUCCESS) |
2142 | leading_brace = 1; | |
5f4273c7 | 2143 | |
5287ad62 JB |
2144 | do |
2145 | { | |
dcbf9037 JB |
2146 | struct neon_typed_alias atype; |
2147 | int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype); | |
2148 | ||
5287ad62 | 2149 | if (getreg == FAIL) |
477330fc RM |
2150 | { |
2151 | first_error (_(reg_expected_msgs[rtype])); | |
2152 | return FAIL; | |
2153 | } | |
5f4273c7 | 2154 | |
5287ad62 | 2155 | if (base_reg == -1) |
477330fc RM |
2156 | { |
2157 | base_reg = getreg; | |
2158 | if (rtype == REG_TYPE_NQ) | |
2159 | { | |
2160 | reg_incr = 1; | |
2161 | } | |
2162 | firsttype = atype; | |
2163 | } | |
5287ad62 | 2164 | else if (reg_incr == -1) |
477330fc RM |
2165 | { |
2166 | reg_incr = getreg - base_reg; | |
2167 | if (reg_incr < 1 || reg_incr > 2) | |
2168 | { | |
2169 | first_error (_(incr_error)); | |
2170 | return FAIL; | |
2171 | } | |
2172 | } | |
5287ad62 | 2173 | else if (getreg != base_reg + reg_incr * count) |
477330fc RM |
2174 | { |
2175 | first_error (_(incr_error)); | |
2176 | return FAIL; | |
2177 | } | |
dcbf9037 | 2178 | |
c921be7d | 2179 | if (! neon_alias_types_same (&atype, &firsttype)) |
477330fc RM |
2180 | { |
2181 | first_error (_(type_error)); | |
2182 | return FAIL; | |
2183 | } | |
5f4273c7 | 2184 | |
5287ad62 | 2185 | /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list |
477330fc | 2186 | modes. */ |
5287ad62 | 2187 | if (ptr[0] == '-') |
477330fc RM |
2188 | { |
2189 | struct neon_typed_alias htype; | |
2190 | int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1; | |
2191 | if (lane == -1) | |
2192 | lane = NEON_INTERLEAVE_LANES; | |
2193 | else if (lane != NEON_INTERLEAVE_LANES) | |
2194 | { | |
2195 | first_error (_(type_error)); | |
2196 | return FAIL; | |
2197 | } | |
2198 | if (reg_incr == -1) | |
2199 | reg_incr = 1; | |
2200 | else if (reg_incr != 1) | |
2201 | { | |
2202 | first_error (_("don't use Rn-Rm syntax with non-unit stride")); | |
2203 | return FAIL; | |
2204 | } | |
2205 | ptr++; | |
2206 | hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype); | |
2207 | if (hireg == FAIL) | |
2208 | { | |
2209 | first_error (_(reg_expected_msgs[rtype])); | |
2210 | return FAIL; | |
2211 | } | |
2212 | if (! neon_alias_types_same (&htype, &firsttype)) | |
2213 | { | |
2214 | first_error (_(type_error)); | |
2215 | return FAIL; | |
2216 | } | |
2217 | count += hireg + dregs - getreg; | |
2218 | continue; | |
2219 | } | |
5f4273c7 | 2220 | |
5287ad62 JB |
2221 | /* If we're using Q registers, we can't use [] or [n] syntax. */ |
2222 | if (rtype == REG_TYPE_NQ) | |
477330fc RM |
2223 | { |
2224 | count += 2; | |
2225 | continue; | |
2226 | } | |
5f4273c7 | 2227 | |
dcbf9037 | 2228 | if ((atype.defined & NTA_HASINDEX) != 0) |
477330fc RM |
2229 | { |
2230 | if (lane == -1) | |
2231 | lane = atype.index; | |
2232 | else if (lane != atype.index) | |
2233 | { | |
2234 | first_error (_(type_error)); | |
2235 | return FAIL; | |
2236 | } | |
2237 | } | |
5287ad62 | 2238 | else if (lane == -1) |
477330fc | 2239 | lane = NEON_INTERLEAVE_LANES; |
5287ad62 | 2240 | else if (lane != NEON_INTERLEAVE_LANES) |
477330fc RM |
2241 | { |
2242 | first_error (_(type_error)); | |
2243 | return FAIL; | |
2244 | } | |
5287ad62 JB |
2245 | count++; |
2246 | } | |
2247 | while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL); | |
5f4273c7 | 2248 | |
5287ad62 JB |
2249 | /* No lane set by [x]. We must be interleaving structures. */ |
2250 | if (lane == -1) | |
2251 | lane = NEON_INTERLEAVE_LANES; | |
5f4273c7 | 2252 | |
5287ad62 JB |
2253 | /* Sanity check. */ |
2254 | if (lane == -1 || base_reg == -1 || count < 1 || count > 4 | |
2255 | || (count > 1 && reg_incr == -1)) | |
2256 | { | |
dcbf9037 | 2257 | first_error (_("error parsing element/structure list")); |
5287ad62 JB |
2258 | return FAIL; |
2259 | } | |
2260 | ||
2261 | if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL) | |
2262 | { | |
dcbf9037 | 2263 | first_error (_("expected }")); |
5287ad62 JB |
2264 | return FAIL; |
2265 | } | |
5f4273c7 | 2266 | |
5287ad62 JB |
2267 | if (reg_incr == -1) |
2268 | reg_incr = 1; | |
2269 | ||
dcbf9037 JB |
2270 | if (eltype) |
2271 | *eltype = firsttype.eltype; | |
2272 | ||
5287ad62 JB |
2273 | *pbase = base_reg; |
2274 | *str = ptr; | |
5f4273c7 | 2275 | |
5287ad62 JB |
2276 | return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5); |
2277 | } | |
2278 | ||
c19d1205 ZW |
2279 | /* Parse an explicit relocation suffix on an expression. This is |
2280 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
2281 | arm_reloc_hsh contains no entries, so this function can only | |
2282 | succeed if there is no () after the word. Returns -1 on error, | |
2283 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
3da1d841 | 2284 | |
c19d1205 ZW |
2285 | static int |
2286 | parse_reloc (char **str) | |
b99bd4ef | 2287 | { |
c19d1205 ZW |
2288 | struct reloc_entry *r; |
2289 | char *p, *q; | |
b99bd4ef | 2290 | |
c19d1205 ZW |
2291 | if (**str != '(') |
2292 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 2293 | |
c19d1205 ZW |
2294 | p = *str + 1; |
2295 | q = p; | |
2296 | ||
2297 | while (*q && *q != ')' && *q != ',') | |
2298 | q++; | |
2299 | if (*q != ')') | |
2300 | return -1; | |
2301 | ||
21d799b5 NC |
2302 | if ((r = (struct reloc_entry *) |
2303 | hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
c19d1205 ZW |
2304 | return -1; |
2305 | ||
2306 | *str = q + 1; | |
2307 | return r->reloc; | |
b99bd4ef NC |
2308 | } |
2309 | ||
c19d1205 ZW |
2310 | /* Directives: register aliases. */ |
2311 | ||
dcbf9037 | 2312 | static struct reg_entry * |
90ec0d68 | 2313 | insert_reg_alias (char *str, unsigned number, int type) |
b99bd4ef | 2314 | { |
d3ce72d0 | 2315 | struct reg_entry *new_reg; |
c19d1205 | 2316 | const char *name; |
b99bd4ef | 2317 | |
d3ce72d0 | 2318 | if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0) |
c19d1205 | 2319 | { |
d3ce72d0 | 2320 | if (new_reg->builtin) |
c19d1205 | 2321 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); |
b99bd4ef | 2322 | |
c19d1205 ZW |
2323 | /* Only warn about a redefinition if it's not defined as the |
2324 | same register. */ | |
d3ce72d0 | 2325 | else if (new_reg->number != number || new_reg->type != type) |
c19d1205 | 2326 | as_warn (_("ignoring redefinition of register alias '%s'"), str); |
69b97547 | 2327 | |
d929913e | 2328 | return NULL; |
c19d1205 | 2329 | } |
b99bd4ef | 2330 | |
c19d1205 | 2331 | name = xstrdup (str); |
325801bd | 2332 | new_reg = XNEW (struct reg_entry); |
b99bd4ef | 2333 | |
d3ce72d0 NC |
2334 | new_reg->name = name; |
2335 | new_reg->number = number; | |
2336 | new_reg->type = type; | |
2337 | new_reg->builtin = FALSE; | |
2338 | new_reg->neon = NULL; | |
b99bd4ef | 2339 | |
d3ce72d0 | 2340 | if (hash_insert (arm_reg_hsh, name, (void *) new_reg)) |
c19d1205 | 2341 | abort (); |
5f4273c7 | 2342 | |
d3ce72d0 | 2343 | return new_reg; |
dcbf9037 JB |
2344 | } |
2345 | ||
2346 | static void | |
2347 | insert_neon_reg_alias (char *str, int number, int type, | |
477330fc | 2348 | struct neon_typed_alias *atype) |
dcbf9037 JB |
2349 | { |
2350 | struct reg_entry *reg = insert_reg_alias (str, number, type); | |
5f4273c7 | 2351 | |
dcbf9037 JB |
2352 | if (!reg) |
2353 | { | |
2354 | first_error (_("attempt to redefine typed alias")); | |
2355 | return; | |
2356 | } | |
5f4273c7 | 2357 | |
dcbf9037 JB |
2358 | if (atype) |
2359 | { | |
325801bd | 2360 | reg->neon = XNEW (struct neon_typed_alias); |
dcbf9037 JB |
2361 | *reg->neon = *atype; |
2362 | } | |
c19d1205 | 2363 | } |
b99bd4ef | 2364 | |
c19d1205 | 2365 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 2366 | |
c19d1205 | 2367 | new_register_name .req existing_register_name |
b99bd4ef | 2368 | |
c19d1205 | 2369 | If we find one, or if it looks sufficiently like one that we want to |
d929913e | 2370 | handle any error here, return TRUE. Otherwise return FALSE. */ |
b99bd4ef | 2371 | |
d929913e | 2372 | static bfd_boolean |
c19d1205 ZW |
2373 | create_register_alias (char * newname, char *p) |
2374 | { | |
2375 | struct reg_entry *old; | |
2376 | char *oldname, *nbuf; | |
2377 | size_t nlen; | |
b99bd4ef | 2378 | |
c19d1205 ZW |
2379 | /* The input scrubber ensures that whitespace after the mnemonic is |
2380 | collapsed to single spaces. */ | |
2381 | oldname = p; | |
2382 | if (strncmp (oldname, " .req ", 6) != 0) | |
d929913e | 2383 | return FALSE; |
b99bd4ef | 2384 | |
c19d1205 ZW |
2385 | oldname += 6; |
2386 | if (*oldname == '\0') | |
d929913e | 2387 | return FALSE; |
b99bd4ef | 2388 | |
21d799b5 | 2389 | old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname); |
c19d1205 | 2390 | if (!old) |
b99bd4ef | 2391 | { |
c19d1205 | 2392 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
d929913e | 2393 | return TRUE; |
b99bd4ef NC |
2394 | } |
2395 | ||
c19d1205 ZW |
2396 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2397 | the desired alias name, and p points to its end. If not, then | |
2398 | the desired alias name is in the global original_case_string. */ | |
2399 | #ifdef TC_CASE_SENSITIVE | |
2400 | nlen = p - newname; | |
2401 | #else | |
2402 | newname = original_case_string; | |
2403 | nlen = strlen (newname); | |
2404 | #endif | |
b99bd4ef | 2405 | |
29a2809e | 2406 | nbuf = xmemdup0 (newname, nlen); |
b99bd4ef | 2407 | |
c19d1205 ZW |
2408 | /* Create aliases under the new name as stated; an all-lowercase |
2409 | version of the new name; and an all-uppercase version of the new | |
2410 | name. */ | |
d929913e NC |
2411 | if (insert_reg_alias (nbuf, old->number, old->type) != NULL) |
2412 | { | |
2413 | for (p = nbuf; *p; p++) | |
2414 | *p = TOUPPER (*p); | |
c19d1205 | 2415 | |
d929913e NC |
2416 | if (strncmp (nbuf, newname, nlen)) |
2417 | { | |
2418 | /* If this attempt to create an additional alias fails, do not bother | |
2419 | trying to create the all-lower case alias. We will fail and issue | |
2420 | a second, duplicate error message. This situation arises when the | |
2421 | programmer does something like: | |
2422 | foo .req r0 | |
2423 | Foo .req r1 | |
2424 | The second .req creates the "Foo" alias but then fails to create | |
5f4273c7 | 2425 | the artificial FOO alias because it has already been created by the |
d929913e NC |
2426 | first .req. */ |
2427 | if (insert_reg_alias (nbuf, old->number, old->type) == NULL) | |
e1fa0163 NC |
2428 | { |
2429 | free (nbuf); | |
2430 | return TRUE; | |
2431 | } | |
d929913e | 2432 | } |
c19d1205 | 2433 | |
d929913e NC |
2434 | for (p = nbuf; *p; p++) |
2435 | *p = TOLOWER (*p); | |
c19d1205 | 2436 | |
d929913e NC |
2437 | if (strncmp (nbuf, newname, nlen)) |
2438 | insert_reg_alias (nbuf, old->number, old->type); | |
2439 | } | |
c19d1205 | 2440 | |
e1fa0163 | 2441 | free (nbuf); |
d929913e | 2442 | return TRUE; |
b99bd4ef NC |
2443 | } |
2444 | ||
dcbf9037 JB |
2445 | /* Create a Neon typed/indexed register alias using directives, e.g.: |
2446 | X .dn d5.s32[1] | |
2447 | Y .qn 6.s16 | |
2448 | Z .dn d7 | |
2449 | T .dn Z[0] | |
2450 | These typed registers can be used instead of the types specified after the | |
2451 | Neon mnemonic, so long as all operands given have types. Types can also be | |
2452 | specified directly, e.g.: | |
5f4273c7 | 2453 | vadd d0.s32, d1.s32, d2.s32 */ |
dcbf9037 | 2454 | |
c921be7d | 2455 | static bfd_boolean |
dcbf9037 JB |
2456 | create_neon_reg_alias (char *newname, char *p) |
2457 | { | |
2458 | enum arm_reg_type basetype; | |
2459 | struct reg_entry *basereg; | |
2460 | struct reg_entry mybasereg; | |
2461 | struct neon_type ntype; | |
2462 | struct neon_typed_alias typeinfo; | |
12d6b0b7 | 2463 | char *namebuf, *nameend ATTRIBUTE_UNUSED; |
dcbf9037 | 2464 | int namelen; |
5f4273c7 | 2465 | |
dcbf9037 JB |
2466 | typeinfo.defined = 0; |
2467 | typeinfo.eltype.type = NT_invtype; | |
2468 | typeinfo.eltype.size = -1; | |
2469 | typeinfo.index = -1; | |
5f4273c7 | 2470 | |
dcbf9037 | 2471 | nameend = p; |
5f4273c7 | 2472 | |
dcbf9037 JB |
2473 | if (strncmp (p, " .dn ", 5) == 0) |
2474 | basetype = REG_TYPE_VFD; | |
2475 | else if (strncmp (p, " .qn ", 5) == 0) | |
2476 | basetype = REG_TYPE_NQ; | |
2477 | else | |
c921be7d | 2478 | return FALSE; |
5f4273c7 | 2479 | |
dcbf9037 | 2480 | p += 5; |
5f4273c7 | 2481 | |
dcbf9037 | 2482 | if (*p == '\0') |
c921be7d | 2483 | return FALSE; |
5f4273c7 | 2484 | |
dcbf9037 JB |
2485 | basereg = arm_reg_parse_multi (&p); |
2486 | ||
2487 | if (basereg && basereg->type != basetype) | |
2488 | { | |
2489 | as_bad (_("bad type for register")); | |
c921be7d | 2490 | return FALSE; |
dcbf9037 JB |
2491 | } |
2492 | ||
2493 | if (basereg == NULL) | |
2494 | { | |
2495 | expressionS exp; | |
2496 | /* Try parsing as an integer. */ | |
2497 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2498 | if (exp.X_op != O_constant) | |
477330fc RM |
2499 | { |
2500 | as_bad (_("expression must be constant")); | |
2501 | return FALSE; | |
2502 | } | |
dcbf9037 JB |
2503 | basereg = &mybasereg; |
2504 | basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2 | |
477330fc | 2505 | : exp.X_add_number; |
dcbf9037 JB |
2506 | basereg->neon = 0; |
2507 | } | |
2508 | ||
2509 | if (basereg->neon) | |
2510 | typeinfo = *basereg->neon; | |
2511 | ||
2512 | if (parse_neon_type (&ntype, &p) == SUCCESS) | |
2513 | { | |
2514 | /* We got a type. */ | |
2515 | if (typeinfo.defined & NTA_HASTYPE) | |
477330fc RM |
2516 | { |
2517 | as_bad (_("can't redefine the type of a register alias")); | |
2518 | return FALSE; | |
2519 | } | |
5f4273c7 | 2520 | |
dcbf9037 JB |
2521 | typeinfo.defined |= NTA_HASTYPE; |
2522 | if (ntype.elems != 1) | |
477330fc RM |
2523 | { |
2524 | as_bad (_("you must specify a single type only")); | |
2525 | return FALSE; | |
2526 | } | |
dcbf9037 JB |
2527 | typeinfo.eltype = ntype.el[0]; |
2528 | } | |
5f4273c7 | 2529 | |
dcbf9037 JB |
2530 | if (skip_past_char (&p, '[') == SUCCESS) |
2531 | { | |
2532 | expressionS exp; | |
2533 | /* We got a scalar index. */ | |
5f4273c7 | 2534 | |
dcbf9037 | 2535 | if (typeinfo.defined & NTA_HASINDEX) |
477330fc RM |
2536 | { |
2537 | as_bad (_("can't redefine the index of a scalar alias")); | |
2538 | return FALSE; | |
2539 | } | |
5f4273c7 | 2540 | |
dcbf9037 | 2541 | my_get_expression (&exp, &p, GE_NO_PREFIX); |
5f4273c7 | 2542 | |
dcbf9037 | 2543 | if (exp.X_op != O_constant) |
477330fc RM |
2544 | { |
2545 | as_bad (_("scalar index must be constant")); | |
2546 | return FALSE; | |
2547 | } | |
5f4273c7 | 2548 | |
dcbf9037 JB |
2549 | typeinfo.defined |= NTA_HASINDEX; |
2550 | typeinfo.index = exp.X_add_number; | |
5f4273c7 | 2551 | |
dcbf9037 | 2552 | if (skip_past_char (&p, ']') == FAIL) |
477330fc RM |
2553 | { |
2554 | as_bad (_("expecting ]")); | |
2555 | return FALSE; | |
2556 | } | |
dcbf9037 JB |
2557 | } |
2558 | ||
15735687 NS |
2559 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2560 | the desired alias name, and p points to its end. If not, then | |
2561 | the desired alias name is in the global original_case_string. */ | |
2562 | #ifdef TC_CASE_SENSITIVE | |
dcbf9037 | 2563 | namelen = nameend - newname; |
15735687 NS |
2564 | #else |
2565 | newname = original_case_string; | |
2566 | namelen = strlen (newname); | |
2567 | #endif | |
2568 | ||
29a2809e | 2569 | namebuf = xmemdup0 (newname, namelen); |
5f4273c7 | 2570 | |
dcbf9037 | 2571 | insert_neon_reg_alias (namebuf, basereg->number, basetype, |
477330fc | 2572 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2573 | |
dcbf9037 JB |
2574 | /* Insert name in all uppercase. */ |
2575 | for (p = namebuf; *p; p++) | |
2576 | *p = TOUPPER (*p); | |
5f4273c7 | 2577 | |
dcbf9037 JB |
2578 | if (strncmp (namebuf, newname, namelen)) |
2579 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
477330fc | 2580 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2581 | |
dcbf9037 JB |
2582 | /* Insert name in all lowercase. */ |
2583 | for (p = namebuf; *p; p++) | |
2584 | *p = TOLOWER (*p); | |
5f4273c7 | 2585 | |
dcbf9037 JB |
2586 | if (strncmp (namebuf, newname, namelen)) |
2587 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
477330fc | 2588 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2589 | |
e1fa0163 | 2590 | free (namebuf); |
c921be7d | 2591 | return TRUE; |
dcbf9037 JB |
2592 | } |
2593 | ||
c19d1205 ZW |
2594 | /* Should never be called, as .req goes between the alias and the |
2595 | register name, not at the beginning of the line. */ | |
c921be7d | 2596 | |
b99bd4ef | 2597 | static void |
c19d1205 | 2598 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2599 | { |
c19d1205 ZW |
2600 | as_bad (_("invalid syntax for .req directive")); |
2601 | } | |
b99bd4ef | 2602 | |
dcbf9037 JB |
2603 | static void |
2604 | s_dn (int a ATTRIBUTE_UNUSED) | |
2605 | { | |
2606 | as_bad (_("invalid syntax for .dn directive")); | |
2607 | } | |
2608 | ||
2609 | static void | |
2610 | s_qn (int a ATTRIBUTE_UNUSED) | |
2611 | { | |
2612 | as_bad (_("invalid syntax for .qn directive")); | |
2613 | } | |
2614 | ||
c19d1205 ZW |
2615 | /* The .unreq directive deletes an alias which was previously defined |
2616 | by .req. For example: | |
b99bd4ef | 2617 | |
c19d1205 ZW |
2618 | my_alias .req r11 |
2619 | .unreq my_alias */ | |
b99bd4ef NC |
2620 | |
2621 | static void | |
c19d1205 | 2622 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2623 | { |
c19d1205 ZW |
2624 | char * name; |
2625 | char saved_char; | |
b99bd4ef | 2626 | |
c19d1205 ZW |
2627 | name = input_line_pointer; |
2628 | ||
2629 | while (*input_line_pointer != 0 | |
2630 | && *input_line_pointer != ' ' | |
2631 | && *input_line_pointer != '\n') | |
2632 | ++input_line_pointer; | |
2633 | ||
2634 | saved_char = *input_line_pointer; | |
2635 | *input_line_pointer = 0; | |
2636 | ||
2637 | if (!*name) | |
2638 | as_bad (_("invalid syntax for .unreq directive")); | |
2639 | else | |
2640 | { | |
21d799b5 | 2641 | struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh, |
477330fc | 2642 | name); |
c19d1205 ZW |
2643 | |
2644 | if (!reg) | |
2645 | as_bad (_("unknown register alias '%s'"), name); | |
2646 | else if (reg->builtin) | |
a1727c1a | 2647 | as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"), |
c19d1205 ZW |
2648 | name); |
2649 | else | |
2650 | { | |
d929913e NC |
2651 | char * p; |
2652 | char * nbuf; | |
2653 | ||
db0bc284 | 2654 | hash_delete (arm_reg_hsh, name, FALSE); |
c19d1205 | 2655 | free ((char *) reg->name); |
477330fc RM |
2656 | if (reg->neon) |
2657 | free (reg->neon); | |
c19d1205 | 2658 | free (reg); |
d929913e NC |
2659 | |
2660 | /* Also locate the all upper case and all lower case versions. | |
2661 | Do not complain if we cannot find one or the other as it | |
2662 | was probably deleted above. */ | |
5f4273c7 | 2663 | |
d929913e NC |
2664 | nbuf = strdup (name); |
2665 | for (p = nbuf; *p; p++) | |
2666 | *p = TOUPPER (*p); | |
21d799b5 | 2667 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2668 | if (reg) |
2669 | { | |
db0bc284 | 2670 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2671 | free ((char *) reg->name); |
2672 | if (reg->neon) | |
2673 | free (reg->neon); | |
2674 | free (reg); | |
2675 | } | |
2676 | ||
2677 | for (p = nbuf; *p; p++) | |
2678 | *p = TOLOWER (*p); | |
21d799b5 | 2679 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2680 | if (reg) |
2681 | { | |
db0bc284 | 2682 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2683 | free ((char *) reg->name); |
2684 | if (reg->neon) | |
2685 | free (reg->neon); | |
2686 | free (reg); | |
2687 | } | |
2688 | ||
2689 | free (nbuf); | |
c19d1205 ZW |
2690 | } |
2691 | } | |
b99bd4ef | 2692 | |
c19d1205 | 2693 | *input_line_pointer = saved_char; |
b99bd4ef NC |
2694 | demand_empty_rest_of_line (); |
2695 | } | |
2696 | ||
c19d1205 ZW |
2697 | /* Directives: Instruction set selection. */ |
2698 | ||
2699 | #ifdef OBJ_ELF | |
2700 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
2701 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
2702 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
2703 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
2704 | ||
cd000bff DJ |
2705 | /* Create a new mapping symbol for the transition to STATE. */ |
2706 | ||
2707 | static void | |
2708 | make_mapping_symbol (enum mstate state, valueT value, fragS *frag) | |
b99bd4ef | 2709 | { |
a737bd4d | 2710 | symbolS * symbolP; |
c19d1205 ZW |
2711 | const char * symname; |
2712 | int type; | |
b99bd4ef | 2713 | |
c19d1205 | 2714 | switch (state) |
b99bd4ef | 2715 | { |
c19d1205 ZW |
2716 | case MAP_DATA: |
2717 | symname = "$d"; | |
2718 | type = BSF_NO_FLAGS; | |
2719 | break; | |
2720 | case MAP_ARM: | |
2721 | symname = "$a"; | |
2722 | type = BSF_NO_FLAGS; | |
2723 | break; | |
2724 | case MAP_THUMB: | |
2725 | symname = "$t"; | |
2726 | type = BSF_NO_FLAGS; | |
2727 | break; | |
c19d1205 ZW |
2728 | default: |
2729 | abort (); | |
2730 | } | |
2731 | ||
cd000bff | 2732 | symbolP = symbol_new (symname, now_seg, value, frag); |
c19d1205 ZW |
2733 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; |
2734 | ||
2735 | switch (state) | |
2736 | { | |
2737 | case MAP_ARM: | |
2738 | THUMB_SET_FUNC (symbolP, 0); | |
2739 | ARM_SET_THUMB (symbolP, 0); | |
2740 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2741 | break; | |
2742 | ||
2743 | case MAP_THUMB: | |
2744 | THUMB_SET_FUNC (symbolP, 1); | |
2745 | ARM_SET_THUMB (symbolP, 1); | |
2746 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2747 | break; | |
2748 | ||
2749 | case MAP_DATA: | |
2750 | default: | |
cd000bff DJ |
2751 | break; |
2752 | } | |
2753 | ||
2754 | /* Save the mapping symbols for future reference. Also check that | |
2755 | we do not place two mapping symbols at the same offset within a | |
2756 | frag. We'll handle overlap between frags in | |
2de7820f JZ |
2757 | check_mapping_symbols. |
2758 | ||
2759 | If .fill or other data filling directive generates zero sized data, | |
2760 | the mapping symbol for the following code will have the same value | |
2761 | as the one generated for the data filling directive. In this case, | |
2762 | we replace the old symbol with the new one at the same address. */ | |
cd000bff DJ |
2763 | if (value == 0) |
2764 | { | |
2de7820f JZ |
2765 | if (frag->tc_frag_data.first_map != NULL) |
2766 | { | |
2767 | know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0); | |
2768 | symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP); | |
2769 | } | |
cd000bff DJ |
2770 | frag->tc_frag_data.first_map = symbolP; |
2771 | } | |
2772 | if (frag->tc_frag_data.last_map != NULL) | |
0f020cef JZ |
2773 | { |
2774 | know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP)); | |
0f020cef JZ |
2775 | if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP)) |
2776 | symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP); | |
2777 | } | |
cd000bff DJ |
2778 | frag->tc_frag_data.last_map = symbolP; |
2779 | } | |
2780 | ||
2781 | /* We must sometimes convert a region marked as code to data during | |
2782 | code alignment, if an odd number of bytes have to be padded. The | |
2783 | code mapping symbol is pushed to an aligned address. */ | |
2784 | ||
2785 | static void | |
2786 | insert_data_mapping_symbol (enum mstate state, | |
2787 | valueT value, fragS *frag, offsetT bytes) | |
2788 | { | |
2789 | /* If there was already a mapping symbol, remove it. */ | |
2790 | if (frag->tc_frag_data.last_map != NULL | |
2791 | && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value) | |
2792 | { | |
2793 | symbolS *symp = frag->tc_frag_data.last_map; | |
2794 | ||
2795 | if (value == 0) | |
2796 | { | |
2797 | know (frag->tc_frag_data.first_map == symp); | |
2798 | frag->tc_frag_data.first_map = NULL; | |
2799 | } | |
2800 | frag->tc_frag_data.last_map = NULL; | |
2801 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
c19d1205 | 2802 | } |
cd000bff DJ |
2803 | |
2804 | make_mapping_symbol (MAP_DATA, value, frag); | |
2805 | make_mapping_symbol (state, value + bytes, frag); | |
2806 | } | |
2807 | ||
2808 | static void mapping_state_2 (enum mstate state, int max_chars); | |
2809 | ||
2810 | /* Set the mapping state to STATE. Only call this when about to | |
2811 | emit some STATE bytes to the file. */ | |
2812 | ||
4e9aaefb | 2813 | #define TRANSITION(from, to) (mapstate == (from) && state == (to)) |
cd000bff DJ |
2814 | void |
2815 | mapping_state (enum mstate state) | |
2816 | { | |
940b5ce0 DJ |
2817 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2818 | ||
cd000bff DJ |
2819 | if (mapstate == state) |
2820 | /* The mapping symbol has already been emitted. | |
2821 | There is nothing else to do. */ | |
2822 | return; | |
49c62a33 NC |
2823 | |
2824 | if (state == MAP_ARM || state == MAP_THUMB) | |
2825 | /* PR gas/12931 | |
2826 | All ARM instructions require 4-byte alignment. | |
2827 | (Almost) all Thumb instructions require 2-byte alignment. | |
2828 | ||
2829 | When emitting instructions into any section, mark the section | |
2830 | appropriately. | |
2831 | ||
2832 | Some Thumb instructions are alignment-sensitive modulo 4 bytes, | |
2833 | but themselves require 2-byte alignment; this applies to some | |
33eaf5de | 2834 | PC- relative forms. However, these cases will involve implicit |
49c62a33 NC |
2835 | literal pool generation or an explicit .align >=2, both of |
2836 | which will cause the section to me marked with sufficient | |
2837 | alignment. Thus, we don't handle those cases here. */ | |
2838 | record_alignment (now_seg, state == MAP_ARM ? 2 : 1); | |
2839 | ||
2840 | if (TRANSITION (MAP_UNDEFINED, MAP_DATA)) | |
4e9aaefb | 2841 | /* This case will be evaluated later. */ |
cd000bff | 2842 | return; |
cd000bff DJ |
2843 | |
2844 | mapping_state_2 (state, 0); | |
cd000bff DJ |
2845 | } |
2846 | ||
2847 | /* Same as mapping_state, but MAX_CHARS bytes have already been | |
2848 | allocated. Put the mapping symbol that far back. */ | |
2849 | ||
2850 | static void | |
2851 | mapping_state_2 (enum mstate state, int max_chars) | |
2852 | { | |
940b5ce0 DJ |
2853 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2854 | ||
2855 | if (!SEG_NORMAL (now_seg)) | |
2856 | return; | |
2857 | ||
cd000bff DJ |
2858 | if (mapstate == state) |
2859 | /* The mapping symbol has already been emitted. | |
2860 | There is nothing else to do. */ | |
2861 | return; | |
2862 | ||
4e9aaefb SA |
2863 | if (TRANSITION (MAP_UNDEFINED, MAP_ARM) |
2864 | || TRANSITION (MAP_UNDEFINED, MAP_THUMB)) | |
2865 | { | |
2866 | struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root; | |
2867 | const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0); | |
2868 | ||
2869 | if (add_symbol) | |
2870 | make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first); | |
2871 | } | |
2872 | ||
cd000bff DJ |
2873 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; |
2874 | make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now); | |
c19d1205 | 2875 | } |
4e9aaefb | 2876 | #undef TRANSITION |
c19d1205 | 2877 | #else |
d3106081 NS |
2878 | #define mapping_state(x) ((void)0) |
2879 | #define mapping_state_2(x, y) ((void)0) | |
c19d1205 ZW |
2880 | #endif |
2881 | ||
2882 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
2883 | ||
4343666d | 2884 | #ifdef OBJ_COFF |
c19d1205 ZW |
2885 | static symbolS * |
2886 | find_real_start (symbolS * symbolP) | |
2887 | { | |
2888 | char * real_start; | |
2889 | const char * name = S_GET_NAME (symbolP); | |
2890 | symbolS * new_target; | |
2891 | ||
2892 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
2893 | #define STUB_NAME ".real_start_of" | |
2894 | ||
2895 | if (name == NULL) | |
2896 | abort (); | |
2897 | ||
37f6032b ZW |
2898 | /* The compiler may generate BL instructions to local labels because |
2899 | it needs to perform a branch to a far away location. These labels | |
2900 | do not have a corresponding ".real_start_of" label. We check | |
2901 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
2902 | the ".real_start_of" convention for nonlocal branches. */ | |
2903 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
2904 | return symbolP; |
2905 | ||
e1fa0163 | 2906 | real_start = concat (STUB_NAME, name, NULL); |
c19d1205 | 2907 | new_target = symbol_find (real_start); |
e1fa0163 | 2908 | free (real_start); |
c19d1205 ZW |
2909 | |
2910 | if (new_target == NULL) | |
2911 | { | |
bd3ba5d1 | 2912 | as_warn (_("Failed to find real start of function: %s\n"), name); |
c19d1205 ZW |
2913 | new_target = symbolP; |
2914 | } | |
2915 | ||
c19d1205 ZW |
2916 | return new_target; |
2917 | } | |
4343666d | 2918 | #endif |
c19d1205 ZW |
2919 | |
2920 | static void | |
2921 | opcode_select (int width) | |
2922 | { | |
2923 | switch (width) | |
2924 | { | |
2925 | case 16: | |
2926 | if (! thumb_mode) | |
2927 | { | |
e74cfd16 | 2928 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
2929 | as_bad (_("selected processor does not support THUMB opcodes")); |
2930 | ||
2931 | thumb_mode = 1; | |
2932 | /* No need to force the alignment, since we will have been | |
2933 | coming from ARM mode, which is word-aligned. */ | |
2934 | record_alignment (now_seg, 1); | |
2935 | } | |
c19d1205 ZW |
2936 | break; |
2937 | ||
2938 | case 32: | |
2939 | if (thumb_mode) | |
2940 | { | |
e74cfd16 | 2941 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
2942 | as_bad (_("selected processor does not support ARM opcodes")); |
2943 | ||
2944 | thumb_mode = 0; | |
2945 | ||
2946 | if (!need_pass_2) | |
2947 | frag_align (2, 0, 0); | |
2948 | ||
2949 | record_alignment (now_seg, 1); | |
2950 | } | |
c19d1205 ZW |
2951 | break; |
2952 | ||
2953 | default: | |
2954 | as_bad (_("invalid instruction size selected (%d)"), width); | |
2955 | } | |
2956 | } | |
2957 | ||
2958 | static void | |
2959 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
2960 | { | |
2961 | opcode_select (32); | |
2962 | demand_empty_rest_of_line (); | |
2963 | } | |
2964 | ||
2965 | static void | |
2966 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
2967 | { | |
2968 | opcode_select (16); | |
2969 | demand_empty_rest_of_line (); | |
2970 | } | |
2971 | ||
2972 | static void | |
2973 | s_code (int unused ATTRIBUTE_UNUSED) | |
2974 | { | |
2975 | int temp; | |
2976 | ||
2977 | temp = get_absolute_expression (); | |
2978 | switch (temp) | |
2979 | { | |
2980 | case 16: | |
2981 | case 32: | |
2982 | opcode_select (temp); | |
2983 | break; | |
2984 | ||
2985 | default: | |
2986 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
2987 | } | |
2988 | } | |
2989 | ||
2990 | static void | |
2991 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
2992 | { | |
2993 | /* If we are not already in thumb mode go into it, EVEN if | |
2994 | the target processor does not support thumb instructions. | |
2995 | This is used by gcc/config/arm/lib1funcs.asm for example | |
2996 | to compile interworking support functions even if the | |
2997 | target processor should not support interworking. */ | |
2998 | if (! thumb_mode) | |
2999 | { | |
3000 | thumb_mode = 2; | |
3001 | record_alignment (now_seg, 1); | |
3002 | } | |
3003 | ||
3004 | demand_empty_rest_of_line (); | |
3005 | } | |
3006 | ||
3007 | static void | |
3008 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
3009 | { | |
3010 | s_thumb (0); | |
3011 | ||
3012 | /* The following label is the name/address of the start of a Thumb function. | |
3013 | We need to know this for the interworking support. */ | |
3014 | label_is_thumb_function_name = TRUE; | |
3015 | } | |
3016 | ||
3017 | /* Perform a .set directive, but also mark the alias as | |
3018 | being a thumb function. */ | |
3019 | ||
3020 | static void | |
3021 | s_thumb_set (int equiv) | |
3022 | { | |
3023 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
3024 | We cannot just call that code as we need to get at the symbol that | |
3025 | is created. */ | |
3026 | char * name; | |
3027 | char delim; | |
3028 | char * end_name; | |
3029 | symbolS * symbolP; | |
3030 | ||
3031 | /* Especial apologies for the random logic: | |
3032 | This just grew, and could be parsed much more simply! | |
3033 | Dean - in haste. */ | |
d02603dc | 3034 | delim = get_symbol_name (& name); |
c19d1205 | 3035 | end_name = input_line_pointer; |
d02603dc | 3036 | (void) restore_line_pointer (delim); |
c19d1205 ZW |
3037 | |
3038 | if (*input_line_pointer != ',') | |
3039 | { | |
3040 | *end_name = 0; | |
3041 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
3042 | *end_name = delim; |
3043 | ignore_rest_of_line (); | |
3044 | return; | |
3045 | } | |
3046 | ||
3047 | input_line_pointer++; | |
3048 | *end_name = 0; | |
3049 | ||
3050 | if (name[0] == '.' && name[1] == '\0') | |
3051 | { | |
3052 | /* XXX - this should not happen to .thumb_set. */ | |
3053 | abort (); | |
3054 | } | |
3055 | ||
3056 | if ((symbolP = symbol_find (name)) == NULL | |
3057 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
3058 | { | |
3059 | #ifndef NO_LISTING | |
3060 | /* When doing symbol listings, play games with dummy fragments living | |
3061 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 3062 | for this symbol. */ |
b99bd4ef NC |
3063 | if (listing & LISTING_SYMBOLS) |
3064 | { | |
3065 | extern struct list_info_struct * listing_tail; | |
21d799b5 | 3066 | fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS)); |
b99bd4ef NC |
3067 | |
3068 | memset (dummy_frag, 0, sizeof (fragS)); | |
3069 | dummy_frag->fr_type = rs_fill; | |
3070 | dummy_frag->line = listing_tail; | |
3071 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
3072 | dummy_frag->fr_symbol = symbolP; | |
3073 | } | |
3074 | else | |
3075 | #endif | |
3076 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
3077 | ||
3078 | #ifdef OBJ_COFF | |
3079 | /* "set" symbols are local unless otherwise specified. */ | |
3080 | SF_SET_LOCAL (symbolP); | |
3081 | #endif /* OBJ_COFF */ | |
3082 | } /* Make a new symbol. */ | |
3083 | ||
3084 | symbol_table_insert (symbolP); | |
3085 | ||
3086 | * end_name = delim; | |
3087 | ||
3088 | if (equiv | |
3089 | && S_IS_DEFINED (symbolP) | |
3090 | && S_GET_SEGMENT (symbolP) != reg_section) | |
3091 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
3092 | ||
3093 | pseudo_set (symbolP); | |
3094 | ||
3095 | demand_empty_rest_of_line (); | |
3096 | ||
c19d1205 | 3097 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
3098 | |
3099 | THUMB_SET_FUNC (symbolP, 1); | |
3100 | ARM_SET_THUMB (symbolP, 1); | |
3101 | #if defined OBJ_ELF || defined OBJ_COFF | |
3102 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
3103 | #endif | |
3104 | } | |
3105 | ||
c19d1205 | 3106 | /* Directives: Mode selection. */ |
b99bd4ef | 3107 | |
c19d1205 ZW |
3108 | /* .syntax [unified|divided] - choose the new unified syntax |
3109 | (same for Arm and Thumb encoding, modulo slight differences in what | |
3110 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 3111 | static void |
c19d1205 | 3112 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 3113 | { |
c19d1205 ZW |
3114 | char *name, delim; |
3115 | ||
d02603dc | 3116 | delim = get_symbol_name (& name); |
c19d1205 ZW |
3117 | |
3118 | if (!strcasecmp (name, "unified")) | |
3119 | unified_syntax = TRUE; | |
3120 | else if (!strcasecmp (name, "divided")) | |
3121 | unified_syntax = FALSE; | |
3122 | else | |
3123 | { | |
3124 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
3125 | return; | |
3126 | } | |
d02603dc | 3127 | (void) restore_line_pointer (delim); |
b99bd4ef NC |
3128 | demand_empty_rest_of_line (); |
3129 | } | |
3130 | ||
c19d1205 ZW |
3131 | /* Directives: sectioning and alignment. */ |
3132 | ||
c19d1205 ZW |
3133 | static void |
3134 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 3135 | { |
c19d1205 ZW |
3136 | /* We don't support putting frags in the BSS segment, we fake it by |
3137 | marking in_bss, then looking at s_skip for clues. */ | |
3138 | subseg_set (bss_section, 0); | |
3139 | demand_empty_rest_of_line (); | |
cd000bff DJ |
3140 | |
3141 | #ifdef md_elf_section_change_hook | |
3142 | md_elf_section_change_hook (); | |
3143 | #endif | |
c19d1205 | 3144 | } |
b99bd4ef | 3145 | |
c19d1205 ZW |
3146 | static void |
3147 | s_even (int ignore ATTRIBUTE_UNUSED) | |
3148 | { | |
3149 | /* Never make frag if expect extra pass. */ | |
3150 | if (!need_pass_2) | |
3151 | frag_align (1, 0, 0); | |
b99bd4ef | 3152 | |
c19d1205 | 3153 | record_alignment (now_seg, 1); |
b99bd4ef | 3154 | |
c19d1205 | 3155 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3156 | } |
3157 | ||
2e6976a8 DG |
3158 | /* Directives: CodeComposer Studio. */ |
3159 | ||
3160 | /* .ref (for CodeComposer Studio syntax only). */ | |
3161 | static void | |
3162 | s_ccs_ref (int unused ATTRIBUTE_UNUSED) | |
3163 | { | |
3164 | if (codecomposer_syntax) | |
3165 | ignore_rest_of_line (); | |
3166 | else | |
3167 | as_bad (_(".ref pseudo-op only available with -mccs flag.")); | |
3168 | } | |
3169 | ||
3170 | /* If name is not NULL, then it is used for marking the beginning of a | |
2b0f3761 | 3171 | function, whereas if it is NULL then it means the function end. */ |
2e6976a8 DG |
3172 | static void |
3173 | asmfunc_debug (const char * name) | |
3174 | { | |
3175 | static const char * last_name = NULL; | |
3176 | ||
3177 | if (name != NULL) | |
3178 | { | |
3179 | gas_assert (last_name == NULL); | |
3180 | last_name = name; | |
3181 | ||
3182 | if (debug_type == DEBUG_STABS) | |
3183 | stabs_generate_asm_func (name, name); | |
3184 | } | |
3185 | else | |
3186 | { | |
3187 | gas_assert (last_name != NULL); | |
3188 | ||
3189 | if (debug_type == DEBUG_STABS) | |
3190 | stabs_generate_asm_endfunc (last_name, last_name); | |
3191 | ||
3192 | last_name = NULL; | |
3193 | } | |
3194 | } | |
3195 | ||
3196 | static void | |
3197 | s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED) | |
3198 | { | |
3199 | if (codecomposer_syntax) | |
3200 | { | |
3201 | switch (asmfunc_state) | |
3202 | { | |
3203 | case OUTSIDE_ASMFUNC: | |
3204 | asmfunc_state = WAITING_ASMFUNC_NAME; | |
3205 | break; | |
3206 | ||
3207 | case WAITING_ASMFUNC_NAME: | |
3208 | as_bad (_(".asmfunc repeated.")); | |
3209 | break; | |
3210 | ||
3211 | case WAITING_ENDASMFUNC: | |
3212 | as_bad (_(".asmfunc without function.")); | |
3213 | break; | |
3214 | } | |
3215 | demand_empty_rest_of_line (); | |
3216 | } | |
3217 | else | |
3218 | as_bad (_(".asmfunc pseudo-op only available with -mccs flag.")); | |
3219 | } | |
3220 | ||
3221 | static void | |
3222 | s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED) | |
3223 | { | |
3224 | if (codecomposer_syntax) | |
3225 | { | |
3226 | switch (asmfunc_state) | |
3227 | { | |
3228 | case OUTSIDE_ASMFUNC: | |
3229 | as_bad (_(".endasmfunc without a .asmfunc.")); | |
3230 | break; | |
3231 | ||
3232 | case WAITING_ASMFUNC_NAME: | |
3233 | as_bad (_(".endasmfunc without function.")); | |
3234 | break; | |
3235 | ||
3236 | case WAITING_ENDASMFUNC: | |
3237 | asmfunc_state = OUTSIDE_ASMFUNC; | |
3238 | asmfunc_debug (NULL); | |
3239 | break; | |
3240 | } | |
3241 | demand_empty_rest_of_line (); | |
3242 | } | |
3243 | else | |
3244 | as_bad (_(".endasmfunc pseudo-op only available with -mccs flag.")); | |
3245 | } | |
3246 | ||
3247 | static void | |
3248 | s_ccs_def (int name) | |
3249 | { | |
3250 | if (codecomposer_syntax) | |
3251 | s_globl (name); | |
3252 | else | |
3253 | as_bad (_(".def pseudo-op only available with -mccs flag.")); | |
3254 | } | |
3255 | ||
c19d1205 | 3256 | /* Directives: Literal pools. */ |
a737bd4d | 3257 | |
c19d1205 ZW |
3258 | static literal_pool * |
3259 | find_literal_pool (void) | |
a737bd4d | 3260 | { |
c19d1205 | 3261 | literal_pool * pool; |
a737bd4d | 3262 | |
c19d1205 | 3263 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 3264 | { |
c19d1205 ZW |
3265 | if (pool->section == now_seg |
3266 | && pool->sub_section == now_subseg) | |
3267 | break; | |
a737bd4d NC |
3268 | } |
3269 | ||
c19d1205 | 3270 | return pool; |
a737bd4d NC |
3271 | } |
3272 | ||
c19d1205 ZW |
3273 | static literal_pool * |
3274 | find_or_make_literal_pool (void) | |
a737bd4d | 3275 | { |
c19d1205 ZW |
3276 | /* Next literal pool ID number. */ |
3277 | static unsigned int latest_pool_num = 1; | |
3278 | literal_pool * pool; | |
a737bd4d | 3279 | |
c19d1205 | 3280 | pool = find_literal_pool (); |
a737bd4d | 3281 | |
c19d1205 | 3282 | if (pool == NULL) |
a737bd4d | 3283 | { |
c19d1205 | 3284 | /* Create a new pool. */ |
325801bd | 3285 | pool = XNEW (literal_pool); |
c19d1205 ZW |
3286 | if (! pool) |
3287 | return NULL; | |
a737bd4d | 3288 | |
c19d1205 ZW |
3289 | pool->next_free_entry = 0; |
3290 | pool->section = now_seg; | |
3291 | pool->sub_section = now_subseg; | |
3292 | pool->next = list_of_pools; | |
3293 | pool->symbol = NULL; | |
8335d6aa | 3294 | pool->alignment = 2; |
c19d1205 ZW |
3295 | |
3296 | /* Add it to the list. */ | |
3297 | list_of_pools = pool; | |
a737bd4d | 3298 | } |
a737bd4d | 3299 | |
c19d1205 ZW |
3300 | /* New pools, and emptied pools, will have a NULL symbol. */ |
3301 | if (pool->symbol == NULL) | |
a737bd4d | 3302 | { |
c19d1205 ZW |
3303 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
3304 | (valueT) 0, &zero_address_frag); | |
3305 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
3306 | } |
3307 | ||
c19d1205 ZW |
3308 | /* Done. */ |
3309 | return pool; | |
a737bd4d NC |
3310 | } |
3311 | ||
c19d1205 | 3312 | /* Add the literal in the global 'inst' |
5f4273c7 | 3313 | structure to the relevant literal pool. */ |
b99bd4ef NC |
3314 | |
3315 | static int | |
8335d6aa | 3316 | add_to_lit_pool (unsigned int nbytes) |
b99bd4ef | 3317 | { |
8335d6aa JW |
3318 | #define PADDING_SLOT 0x1 |
3319 | #define LIT_ENTRY_SIZE_MASK 0xFF | |
c19d1205 | 3320 | literal_pool * pool; |
8335d6aa JW |
3321 | unsigned int entry, pool_size = 0; |
3322 | bfd_boolean padding_slot_p = FALSE; | |
e56c722b | 3323 | unsigned imm1 = 0; |
8335d6aa JW |
3324 | unsigned imm2 = 0; |
3325 | ||
3326 | if (nbytes == 8) | |
3327 | { | |
3328 | imm1 = inst.operands[1].imm; | |
3329 | imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg | |
e2b0ab59 | 3330 | : inst.relocs[0].exp.X_unsigned ? 0 |
2569ceb0 | 3331 | : ((bfd_int64_t) inst.operands[1].imm) >> 32); |
8335d6aa JW |
3332 | if (target_big_endian) |
3333 | { | |
3334 | imm1 = imm2; | |
3335 | imm2 = inst.operands[1].imm; | |
3336 | } | |
3337 | } | |
b99bd4ef | 3338 | |
c19d1205 ZW |
3339 | pool = find_or_make_literal_pool (); |
3340 | ||
3341 | /* Check if this literal value is already in the pool. */ | |
3342 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 3343 | { |
8335d6aa JW |
3344 | if (nbytes == 4) |
3345 | { | |
e2b0ab59 AV |
3346 | if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op) |
3347 | && (inst.relocs[0].exp.X_op == O_constant) | |
8335d6aa | 3348 | && (pool->literals[entry].X_add_number |
e2b0ab59 | 3349 | == inst.relocs[0].exp.X_add_number) |
8335d6aa JW |
3350 | && (pool->literals[entry].X_md == nbytes) |
3351 | && (pool->literals[entry].X_unsigned | |
e2b0ab59 | 3352 | == inst.relocs[0].exp.X_unsigned)) |
8335d6aa JW |
3353 | break; |
3354 | ||
e2b0ab59 AV |
3355 | if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op) |
3356 | && (inst.relocs[0].exp.X_op == O_symbol) | |
8335d6aa | 3357 | && (pool->literals[entry].X_add_number |
e2b0ab59 | 3358 | == inst.relocs[0].exp.X_add_number) |
8335d6aa | 3359 | && (pool->literals[entry].X_add_symbol |
e2b0ab59 | 3360 | == inst.relocs[0].exp.X_add_symbol) |
8335d6aa | 3361 | && (pool->literals[entry].X_op_symbol |
e2b0ab59 | 3362 | == inst.relocs[0].exp.X_op_symbol) |
8335d6aa JW |
3363 | && (pool->literals[entry].X_md == nbytes)) |
3364 | break; | |
3365 | } | |
3366 | else if ((nbytes == 8) | |
3367 | && !(pool_size & 0x7) | |
3368 | && ((entry + 1) != pool->next_free_entry) | |
3369 | && (pool->literals[entry].X_op == O_constant) | |
19f2f6a9 | 3370 | && (pool->literals[entry].X_add_number == (offsetT) imm1) |
8335d6aa | 3371 | && (pool->literals[entry].X_unsigned |
e2b0ab59 | 3372 | == inst.relocs[0].exp.X_unsigned) |
8335d6aa | 3373 | && (pool->literals[entry + 1].X_op == O_constant) |
19f2f6a9 | 3374 | && (pool->literals[entry + 1].X_add_number == (offsetT) imm2) |
8335d6aa | 3375 | && (pool->literals[entry + 1].X_unsigned |
e2b0ab59 | 3376 | == inst.relocs[0].exp.X_unsigned)) |
c19d1205 ZW |
3377 | break; |
3378 | ||
8335d6aa JW |
3379 | padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT); |
3380 | if (padding_slot_p && (nbytes == 4)) | |
c19d1205 | 3381 | break; |
8335d6aa JW |
3382 | |
3383 | pool_size += 4; | |
b99bd4ef NC |
3384 | } |
3385 | ||
c19d1205 ZW |
3386 | /* Do we need to create a new entry? */ |
3387 | if (entry == pool->next_free_entry) | |
3388 | { | |
3389 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
3390 | { | |
3391 | inst.error = _("literal pool overflow"); | |
3392 | return FAIL; | |
3393 | } | |
3394 | ||
8335d6aa JW |
3395 | if (nbytes == 8) |
3396 | { | |
3397 | /* For 8-byte entries, we align to an 8-byte boundary, | |
3398 | and split it into two 4-byte entries, because on 32-bit | |
3399 | host, 8-byte constants are treated as big num, thus | |
3400 | saved in "generic_bignum" which will be overwritten | |
3401 | by later assignments. | |
3402 | ||
3403 | We also need to make sure there is enough space for | |
3404 | the split. | |
3405 | ||
3406 | We also check to make sure the literal operand is a | |
3407 | constant number. */ | |
e2b0ab59 AV |
3408 | if (!(inst.relocs[0].exp.X_op == O_constant |
3409 | || inst.relocs[0].exp.X_op == O_big)) | |
8335d6aa JW |
3410 | { |
3411 | inst.error = _("invalid type for literal pool"); | |
3412 | return FAIL; | |
3413 | } | |
3414 | else if (pool_size & 0x7) | |
3415 | { | |
3416 | if ((entry + 2) >= MAX_LITERAL_POOL_SIZE) | |
3417 | { | |
3418 | inst.error = _("literal pool overflow"); | |
3419 | return FAIL; | |
3420 | } | |
3421 | ||
e2b0ab59 | 3422 | pool->literals[entry] = inst.relocs[0].exp; |
a6684f0d | 3423 | pool->literals[entry].X_op = O_constant; |
8335d6aa JW |
3424 | pool->literals[entry].X_add_number = 0; |
3425 | pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4; | |
3426 | pool->next_free_entry += 1; | |
3427 | pool_size += 4; | |
3428 | } | |
3429 | else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE) | |
3430 | { | |
3431 | inst.error = _("literal pool overflow"); | |
3432 | return FAIL; | |
3433 | } | |
3434 | ||
e2b0ab59 | 3435 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3436 | pool->literals[entry].X_op = O_constant; |
3437 | pool->literals[entry].X_add_number = imm1; | |
e2b0ab59 | 3438 | pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned; |
8335d6aa | 3439 | pool->literals[entry++].X_md = 4; |
e2b0ab59 | 3440 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3441 | pool->literals[entry].X_op = O_constant; |
3442 | pool->literals[entry].X_add_number = imm2; | |
e2b0ab59 | 3443 | pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned; |
8335d6aa JW |
3444 | pool->literals[entry].X_md = 4; |
3445 | pool->alignment = 3; | |
3446 | pool->next_free_entry += 1; | |
3447 | } | |
3448 | else | |
3449 | { | |
e2b0ab59 | 3450 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3451 | pool->literals[entry].X_md = 4; |
3452 | } | |
3453 | ||
a8040cf2 NC |
3454 | #ifdef OBJ_ELF |
3455 | /* PR ld/12974: Record the location of the first source line to reference | |
3456 | this entry in the literal pool. If it turns out during linking that the | |
3457 | symbol does not exist we will be able to give an accurate line number for | |
3458 | the (first use of the) missing reference. */ | |
3459 | if (debug_type == DEBUG_DWARF2) | |
3460 | dwarf2_where (pool->locs + entry); | |
3461 | #endif | |
c19d1205 ZW |
3462 | pool->next_free_entry += 1; |
3463 | } | |
8335d6aa JW |
3464 | else if (padding_slot_p) |
3465 | { | |
e2b0ab59 | 3466 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3467 | pool->literals[entry].X_md = nbytes; |
3468 | } | |
b99bd4ef | 3469 | |
e2b0ab59 AV |
3470 | inst.relocs[0].exp.X_op = O_symbol; |
3471 | inst.relocs[0].exp.X_add_number = pool_size; | |
3472 | inst.relocs[0].exp.X_add_symbol = pool->symbol; | |
b99bd4ef | 3473 | |
c19d1205 | 3474 | return SUCCESS; |
b99bd4ef NC |
3475 | } |
3476 | ||
2e6976a8 | 3477 | bfd_boolean |
2e57ce7b | 3478 | tc_start_label_without_colon (void) |
2e6976a8 DG |
3479 | { |
3480 | bfd_boolean ret = TRUE; | |
3481 | ||
3482 | if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME) | |
3483 | { | |
2e57ce7b | 3484 | const char *label = input_line_pointer; |
2e6976a8 DG |
3485 | |
3486 | while (!is_end_of_line[(int) label[-1]]) | |
3487 | --label; | |
3488 | ||
3489 | if (*label == '.') | |
3490 | { | |
3491 | as_bad (_("Invalid label '%s'"), label); | |
3492 | ret = FALSE; | |
3493 | } | |
3494 | ||
3495 | asmfunc_debug (label); | |
3496 | ||
3497 | asmfunc_state = WAITING_ENDASMFUNC; | |
3498 | } | |
3499 | ||
3500 | return ret; | |
3501 | } | |
3502 | ||
c19d1205 | 3503 | /* Can't use symbol_new here, so have to create a symbol and then at |
33eaf5de | 3504 | a later date assign it a value. That's what these functions do. */ |
e16bb312 | 3505 | |
c19d1205 ZW |
3506 | static void |
3507 | symbol_locate (symbolS * symbolP, | |
3508 | const char * name, /* It is copied, the caller can modify. */ | |
3509 | segT segment, /* Segment identifier (SEG_<something>). */ | |
3510 | valueT valu, /* Symbol value. */ | |
3511 | fragS * frag) /* Associated fragment. */ | |
3512 | { | |
e57e6ddc | 3513 | size_t name_length; |
c19d1205 | 3514 | char * preserved_copy_of_name; |
e16bb312 | 3515 | |
c19d1205 ZW |
3516 | name_length = strlen (name) + 1; /* +1 for \0. */ |
3517 | obstack_grow (¬es, name, name_length); | |
21d799b5 | 3518 | preserved_copy_of_name = (char *) obstack_finish (¬es); |
e16bb312 | 3519 | |
c19d1205 ZW |
3520 | #ifdef tc_canonicalize_symbol_name |
3521 | preserved_copy_of_name = | |
3522 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
3523 | #endif | |
b99bd4ef | 3524 | |
c19d1205 | 3525 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 3526 | |
c19d1205 ZW |
3527 | S_SET_SEGMENT (symbolP, segment); |
3528 | S_SET_VALUE (symbolP, valu); | |
3529 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 3530 | |
c19d1205 | 3531 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 3532 | |
c19d1205 ZW |
3533 | /* Link to end of symbol chain. */ |
3534 | { | |
3535 | extern int symbol_table_frozen; | |
b99bd4ef | 3536 | |
c19d1205 ZW |
3537 | if (symbol_table_frozen) |
3538 | abort (); | |
3539 | } | |
b99bd4ef | 3540 | |
c19d1205 | 3541 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 3542 | |
c19d1205 | 3543 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 3544 | |
c19d1205 ZW |
3545 | #ifdef tc_symbol_new_hook |
3546 | tc_symbol_new_hook (symbolP); | |
3547 | #endif | |
3548 | ||
3549 | #ifdef DEBUG_SYMS | |
3550 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
3551 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
3552 | } |
3553 | ||
c19d1205 ZW |
3554 | static void |
3555 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 3556 | { |
c19d1205 ZW |
3557 | unsigned int entry; |
3558 | literal_pool * pool; | |
3559 | char sym_name[20]; | |
b99bd4ef | 3560 | |
c19d1205 ZW |
3561 | pool = find_literal_pool (); |
3562 | if (pool == NULL | |
3563 | || pool->symbol == NULL | |
3564 | || pool->next_free_entry == 0) | |
3565 | return; | |
b99bd4ef | 3566 | |
c19d1205 ZW |
3567 | /* Align pool as you have word accesses. |
3568 | Only make a frag if we have to. */ | |
3569 | if (!need_pass_2) | |
8335d6aa | 3570 | frag_align (pool->alignment, 0, 0); |
b99bd4ef | 3571 | |
c19d1205 | 3572 | record_alignment (now_seg, 2); |
b99bd4ef | 3573 | |
aaca88ef | 3574 | #ifdef OBJ_ELF |
47fc6e36 WN |
3575 | seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA; |
3576 | make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now); | |
aaca88ef | 3577 | #endif |
c19d1205 | 3578 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 3579 | |
c19d1205 ZW |
3580 | symbol_locate (pool->symbol, sym_name, now_seg, |
3581 | (valueT) frag_now_fix (), frag_now); | |
3582 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 3583 | |
c19d1205 | 3584 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 3585 | |
c19d1205 ZW |
3586 | #if defined OBJ_COFF || defined OBJ_ELF |
3587 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
3588 | #endif | |
6c43fab6 | 3589 | |
c19d1205 | 3590 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
a8040cf2 NC |
3591 | { |
3592 | #ifdef OBJ_ELF | |
3593 | if (debug_type == DEBUG_DWARF2) | |
3594 | dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry); | |
3595 | #endif | |
3596 | /* First output the expression in the instruction to the pool. */ | |
8335d6aa JW |
3597 | emit_expr (&(pool->literals[entry]), |
3598 | pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK); | |
a8040cf2 | 3599 | } |
b99bd4ef | 3600 | |
c19d1205 ZW |
3601 | /* Mark the pool as empty. */ |
3602 | pool->next_free_entry = 0; | |
3603 | pool->symbol = NULL; | |
b99bd4ef NC |
3604 | } |
3605 | ||
c19d1205 ZW |
3606 | #ifdef OBJ_ELF |
3607 | /* Forward declarations for functions below, in the MD interface | |
3608 | section. */ | |
3609 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
3610 | static valueT create_unwind_entry (int); | |
3611 | static void start_unwind_section (const segT, int); | |
3612 | static void add_unwind_opcode (valueT, int); | |
3613 | static void flush_pending_unwind (void); | |
b99bd4ef | 3614 | |
c19d1205 | 3615 | /* Directives: Data. */ |
b99bd4ef | 3616 | |
c19d1205 ZW |
3617 | static void |
3618 | s_arm_elf_cons (int nbytes) | |
3619 | { | |
3620 | expressionS exp; | |
b99bd4ef | 3621 | |
c19d1205 ZW |
3622 | #ifdef md_flush_pending_output |
3623 | md_flush_pending_output (); | |
3624 | #endif | |
b99bd4ef | 3625 | |
c19d1205 | 3626 | if (is_it_end_of_statement ()) |
b99bd4ef | 3627 | { |
c19d1205 ZW |
3628 | demand_empty_rest_of_line (); |
3629 | return; | |
b99bd4ef NC |
3630 | } |
3631 | ||
c19d1205 ZW |
3632 | #ifdef md_cons_align |
3633 | md_cons_align (nbytes); | |
3634 | #endif | |
b99bd4ef | 3635 | |
c19d1205 ZW |
3636 | mapping_state (MAP_DATA); |
3637 | do | |
b99bd4ef | 3638 | { |
c19d1205 ZW |
3639 | int reloc; |
3640 | char *base = input_line_pointer; | |
b99bd4ef | 3641 | |
c19d1205 | 3642 | expression (& exp); |
b99bd4ef | 3643 | |
c19d1205 ZW |
3644 | if (exp.X_op != O_symbol) |
3645 | emit_expr (&exp, (unsigned int) nbytes); | |
3646 | else | |
3647 | { | |
3648 | char *before_reloc = input_line_pointer; | |
3649 | reloc = parse_reloc (&input_line_pointer); | |
3650 | if (reloc == -1) | |
3651 | { | |
3652 | as_bad (_("unrecognized relocation suffix")); | |
3653 | ignore_rest_of_line (); | |
3654 | return; | |
3655 | } | |
3656 | else if (reloc == BFD_RELOC_UNUSED) | |
3657 | emit_expr (&exp, (unsigned int) nbytes); | |
3658 | else | |
3659 | { | |
21d799b5 | 3660 | reloc_howto_type *howto = (reloc_howto_type *) |
477330fc RM |
3661 | bfd_reloc_type_lookup (stdoutput, |
3662 | (bfd_reloc_code_real_type) reloc); | |
c19d1205 | 3663 | int size = bfd_get_reloc_size (howto); |
b99bd4ef | 3664 | |
2fc8bdac ZW |
3665 | if (reloc == BFD_RELOC_ARM_PLT32) |
3666 | { | |
3667 | as_bad (_("(plt) is only valid on branch targets")); | |
3668 | reloc = BFD_RELOC_UNUSED; | |
3669 | size = 0; | |
3670 | } | |
3671 | ||
c19d1205 | 3672 | if (size > nbytes) |
992a06ee AM |
3673 | as_bad (ngettext ("%s relocations do not fit in %d byte", |
3674 | "%s relocations do not fit in %d bytes", | |
3675 | nbytes), | |
c19d1205 ZW |
3676 | howto->name, nbytes); |
3677 | else | |
3678 | { | |
3679 | /* We've parsed an expression stopping at O_symbol. | |
3680 | But there may be more expression left now that we | |
3681 | have parsed the relocation marker. Parse it again. | |
3682 | XXX Surely there is a cleaner way to do this. */ | |
3683 | char *p = input_line_pointer; | |
3684 | int offset; | |
325801bd | 3685 | char *save_buf = XNEWVEC (char, input_line_pointer - base); |
e1fa0163 | 3686 | |
c19d1205 ZW |
3687 | memcpy (save_buf, base, input_line_pointer - base); |
3688 | memmove (base + (input_line_pointer - before_reloc), | |
3689 | base, before_reloc - base); | |
3690 | ||
3691 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
3692 | expression (&exp); | |
3693 | memcpy (base, save_buf, p - base); | |
3694 | ||
3695 | offset = nbytes - size; | |
4b1a927e AM |
3696 | p = frag_more (nbytes); |
3697 | memset (p, 0, nbytes); | |
c19d1205 | 3698 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, |
21d799b5 | 3699 | size, &exp, 0, (enum bfd_reloc_code_real) reloc); |
e1fa0163 | 3700 | free (save_buf); |
c19d1205 ZW |
3701 | } |
3702 | } | |
3703 | } | |
b99bd4ef | 3704 | } |
c19d1205 | 3705 | while (*input_line_pointer++ == ','); |
b99bd4ef | 3706 | |
c19d1205 ZW |
3707 | /* Put terminator back into stream. */ |
3708 | input_line_pointer --; | |
3709 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
3710 | } |
3711 | ||
c921be7d NC |
3712 | /* Emit an expression containing a 32-bit thumb instruction. |
3713 | Implementation based on put_thumb32_insn. */ | |
3714 | ||
3715 | static void | |
3716 | emit_thumb32_expr (expressionS * exp) | |
3717 | { | |
3718 | expressionS exp_high = *exp; | |
3719 | ||
3720 | exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16; | |
3721 | emit_expr (& exp_high, (unsigned int) THUMB_SIZE); | |
3722 | exp->X_add_number &= 0xffff; | |
3723 | emit_expr (exp, (unsigned int) THUMB_SIZE); | |
3724 | } | |
3725 | ||
3726 | /* Guess the instruction size based on the opcode. */ | |
3727 | ||
3728 | static int | |
3729 | thumb_insn_size (int opcode) | |
3730 | { | |
3731 | if ((unsigned int) opcode < 0xe800u) | |
3732 | return 2; | |
3733 | else if ((unsigned int) opcode >= 0xe8000000u) | |
3734 | return 4; | |
3735 | else | |
3736 | return 0; | |
3737 | } | |
3738 | ||
3739 | static bfd_boolean | |
3740 | emit_insn (expressionS *exp, int nbytes) | |
3741 | { | |
3742 | int size = 0; | |
3743 | ||
3744 | if (exp->X_op == O_constant) | |
3745 | { | |
3746 | size = nbytes; | |
3747 | ||
3748 | if (size == 0) | |
3749 | size = thumb_insn_size (exp->X_add_number); | |
3750 | ||
3751 | if (size != 0) | |
3752 | { | |
3753 | if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu) | |
3754 | { | |
3755 | as_bad (_(".inst.n operand too big. "\ | |
3756 | "Use .inst.w instead")); | |
3757 | size = 0; | |
3758 | } | |
3759 | else | |
3760 | { | |
3761 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
3762 | set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0); | |
3763 | else | |
3764 | set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0); | |
3765 | ||
3766 | if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian) | |
3767 | emit_thumb32_expr (exp); | |
3768 | else | |
3769 | emit_expr (exp, (unsigned int) size); | |
3770 | ||
3771 | it_fsm_post_encode (); | |
3772 | } | |
3773 | } | |
3774 | else | |
3775 | as_bad (_("cannot determine Thumb instruction size. " \ | |
3776 | "Use .inst.n/.inst.w instead")); | |
3777 | } | |
3778 | else | |
3779 | as_bad (_("constant expression required")); | |
3780 | ||
3781 | return (size != 0); | |
3782 | } | |
3783 | ||
3784 | /* Like s_arm_elf_cons but do not use md_cons_align and | |
3785 | set the mapping state to MAP_ARM/MAP_THUMB. */ | |
3786 | ||
3787 | static void | |
3788 | s_arm_elf_inst (int nbytes) | |
3789 | { | |
3790 | if (is_it_end_of_statement ()) | |
3791 | { | |
3792 | demand_empty_rest_of_line (); | |
3793 | return; | |
3794 | } | |
3795 | ||
3796 | /* Calling mapping_state () here will not change ARM/THUMB, | |
3797 | but will ensure not to be in DATA state. */ | |
3798 | ||
3799 | if (thumb_mode) | |
3800 | mapping_state (MAP_THUMB); | |
3801 | else | |
3802 | { | |
3803 | if (nbytes != 0) | |
3804 | { | |
3805 | as_bad (_("width suffixes are invalid in ARM mode")); | |
3806 | ignore_rest_of_line (); | |
3807 | return; | |
3808 | } | |
3809 | ||
3810 | nbytes = 4; | |
3811 | ||
3812 | mapping_state (MAP_ARM); | |
3813 | } | |
3814 | ||
3815 | do | |
3816 | { | |
3817 | expressionS exp; | |
3818 | ||
3819 | expression (& exp); | |
3820 | ||
3821 | if (! emit_insn (& exp, nbytes)) | |
3822 | { | |
3823 | ignore_rest_of_line (); | |
3824 | return; | |
3825 | } | |
3826 | } | |
3827 | while (*input_line_pointer++ == ','); | |
3828 | ||
3829 | /* Put terminator back into stream. */ | |
3830 | input_line_pointer --; | |
3831 | demand_empty_rest_of_line (); | |
3832 | } | |
b99bd4ef | 3833 | |
c19d1205 | 3834 | /* Parse a .rel31 directive. */ |
b99bd4ef | 3835 | |
c19d1205 ZW |
3836 | static void |
3837 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
3838 | { | |
3839 | expressionS exp; | |
3840 | char *p; | |
3841 | valueT highbit; | |
b99bd4ef | 3842 | |
c19d1205 ZW |
3843 | highbit = 0; |
3844 | if (*input_line_pointer == '1') | |
3845 | highbit = 0x80000000; | |
3846 | else if (*input_line_pointer != '0') | |
3847 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 3848 | |
c19d1205 ZW |
3849 | input_line_pointer++; |
3850 | if (*input_line_pointer != ',') | |
3851 | as_bad (_("missing comma")); | |
3852 | input_line_pointer++; | |
b99bd4ef | 3853 | |
c19d1205 ZW |
3854 | #ifdef md_flush_pending_output |
3855 | md_flush_pending_output (); | |
3856 | #endif | |
b99bd4ef | 3857 | |
c19d1205 ZW |
3858 | #ifdef md_cons_align |
3859 | md_cons_align (4); | |
3860 | #endif | |
b99bd4ef | 3861 | |
c19d1205 | 3862 | mapping_state (MAP_DATA); |
b99bd4ef | 3863 | |
c19d1205 | 3864 | expression (&exp); |
b99bd4ef | 3865 | |
c19d1205 ZW |
3866 | p = frag_more (4); |
3867 | md_number_to_chars (p, highbit, 4); | |
3868 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
3869 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 3870 | |
c19d1205 | 3871 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3872 | } |
3873 | ||
c19d1205 | 3874 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 3875 | |
c19d1205 | 3876 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 3877 | |
c19d1205 ZW |
3878 | static void |
3879 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
3880 | { | |
3881 | demand_empty_rest_of_line (); | |
921e5f0a PB |
3882 | if (unwind.proc_start) |
3883 | { | |
c921be7d | 3884 | as_bad (_("duplicate .fnstart directive")); |
921e5f0a PB |
3885 | return; |
3886 | } | |
3887 | ||
c19d1205 ZW |
3888 | /* Mark the start of the function. */ |
3889 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 3890 | |
c19d1205 ZW |
3891 | /* Reset the rest of the unwind info. */ |
3892 | unwind.opcode_count = 0; | |
3893 | unwind.table_entry = NULL; | |
3894 | unwind.personality_routine = NULL; | |
3895 | unwind.personality_index = -1; | |
3896 | unwind.frame_size = 0; | |
3897 | unwind.fp_offset = 0; | |
fdfde340 | 3898 | unwind.fp_reg = REG_SP; |
c19d1205 ZW |
3899 | unwind.fp_used = 0; |
3900 | unwind.sp_restored = 0; | |
3901 | } | |
b99bd4ef | 3902 | |
b99bd4ef | 3903 | |
c19d1205 ZW |
3904 | /* Parse a handlerdata directive. Creates the exception handling table entry |
3905 | for the function. */ | |
b99bd4ef | 3906 | |
c19d1205 ZW |
3907 | static void |
3908 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
3909 | { | |
3910 | demand_empty_rest_of_line (); | |
921e5f0a | 3911 | if (!unwind.proc_start) |
c921be7d | 3912 | as_bad (MISSING_FNSTART); |
921e5f0a | 3913 | |
c19d1205 | 3914 | if (unwind.table_entry) |
6decc662 | 3915 | as_bad (_("duplicate .handlerdata directive")); |
f02232aa | 3916 | |
c19d1205 ZW |
3917 | create_unwind_entry (1); |
3918 | } | |
a737bd4d | 3919 | |
c19d1205 | 3920 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 3921 | |
c19d1205 ZW |
3922 | static void |
3923 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
3924 | { | |
3925 | long where; | |
3926 | char *ptr; | |
3927 | valueT val; | |
940b5ce0 | 3928 | unsigned int marked_pr_dependency; |
f02232aa | 3929 | |
c19d1205 | 3930 | demand_empty_rest_of_line (); |
f02232aa | 3931 | |
921e5f0a PB |
3932 | if (!unwind.proc_start) |
3933 | { | |
c921be7d | 3934 | as_bad (_(".fnend directive without .fnstart")); |
921e5f0a PB |
3935 | return; |
3936 | } | |
3937 | ||
c19d1205 ZW |
3938 | /* Add eh table entry. */ |
3939 | if (unwind.table_entry == NULL) | |
3940 | val = create_unwind_entry (0); | |
3941 | else | |
3942 | val = 0; | |
f02232aa | 3943 | |
c19d1205 ZW |
3944 | /* Add index table entry. This is two words. */ |
3945 | start_unwind_section (unwind.saved_seg, 1); | |
3946 | frag_align (2, 0, 0); | |
3947 | record_alignment (now_seg, 2); | |
b99bd4ef | 3948 | |
c19d1205 | 3949 | ptr = frag_more (8); |
5011093d | 3950 | memset (ptr, 0, 8); |
c19d1205 | 3951 | where = frag_now_fix () - 8; |
f02232aa | 3952 | |
c19d1205 ZW |
3953 | /* Self relative offset of the function start. */ |
3954 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
3955 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3956 | |
c19d1205 ZW |
3957 | /* Indicate dependency on EHABI-defined personality routines to the |
3958 | linker, if it hasn't been done already. */ | |
940b5ce0 DJ |
3959 | marked_pr_dependency |
3960 | = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency; | |
c19d1205 ZW |
3961 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 |
3962 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
3963 | { | |
5f4273c7 NC |
3964 | static const char *const name[] = |
3965 | { | |
3966 | "__aeabi_unwind_cpp_pr0", | |
3967 | "__aeabi_unwind_cpp_pr1", | |
3968 | "__aeabi_unwind_cpp_pr2" | |
3969 | }; | |
c19d1205 ZW |
3970 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); |
3971 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
c19d1205 | 3972 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency |
940b5ce0 | 3973 | |= 1 << unwind.personality_index; |
c19d1205 | 3974 | } |
f02232aa | 3975 | |
c19d1205 ZW |
3976 | if (val) |
3977 | /* Inline exception table entry. */ | |
3978 | md_number_to_chars (ptr + 4, val, 4); | |
3979 | else | |
3980 | /* Self relative offset of the table entry. */ | |
3981 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
3982 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3983 | |
c19d1205 ZW |
3984 | /* Restore the original section. */ |
3985 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
921e5f0a PB |
3986 | |
3987 | unwind.proc_start = NULL; | |
c19d1205 | 3988 | } |
f02232aa | 3989 | |
f02232aa | 3990 | |
c19d1205 | 3991 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 3992 | |
c19d1205 ZW |
3993 | static void |
3994 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
3995 | { | |
3996 | demand_empty_rest_of_line (); | |
921e5f0a | 3997 | if (!unwind.proc_start) |
c921be7d | 3998 | as_bad (MISSING_FNSTART); |
921e5f0a | 3999 | |
c19d1205 ZW |
4000 | if (unwind.personality_routine || unwind.personality_index != -1) |
4001 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 4002 | |
c19d1205 ZW |
4003 | unwind.personality_index = -2; |
4004 | } | |
b99bd4ef | 4005 | |
b99bd4ef | 4006 | |
c19d1205 | 4007 | /* Parse a personalityindex directive. */ |
b99bd4ef | 4008 | |
c19d1205 ZW |
4009 | static void |
4010 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
4011 | { | |
4012 | expressionS exp; | |
b99bd4ef | 4013 | |
921e5f0a | 4014 | if (!unwind.proc_start) |
c921be7d | 4015 | as_bad (MISSING_FNSTART); |
921e5f0a | 4016 | |
c19d1205 ZW |
4017 | if (unwind.personality_routine || unwind.personality_index != -1) |
4018 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 4019 | |
c19d1205 | 4020 | expression (&exp); |
b99bd4ef | 4021 | |
c19d1205 ZW |
4022 | if (exp.X_op != O_constant |
4023 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 4024 | { |
c19d1205 ZW |
4025 | as_bad (_("bad personality routine number")); |
4026 | ignore_rest_of_line (); | |
4027 | return; | |
b99bd4ef NC |
4028 | } |
4029 | ||
c19d1205 | 4030 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 4031 | |
c19d1205 ZW |
4032 | demand_empty_rest_of_line (); |
4033 | } | |
e16bb312 | 4034 | |
e16bb312 | 4035 | |
c19d1205 | 4036 | /* Parse a personality directive. */ |
e16bb312 | 4037 | |
c19d1205 ZW |
4038 | static void |
4039 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
4040 | { | |
4041 | char *name, *p, c; | |
a737bd4d | 4042 | |
921e5f0a | 4043 | if (!unwind.proc_start) |
c921be7d | 4044 | as_bad (MISSING_FNSTART); |
921e5f0a | 4045 | |
c19d1205 ZW |
4046 | if (unwind.personality_routine || unwind.personality_index != -1) |
4047 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 4048 | |
d02603dc | 4049 | c = get_symbol_name (& name); |
c19d1205 | 4050 | p = input_line_pointer; |
d02603dc NC |
4051 | if (c == '"') |
4052 | ++ input_line_pointer; | |
c19d1205 ZW |
4053 | unwind.personality_routine = symbol_find_or_make (name); |
4054 | *p = c; | |
4055 | demand_empty_rest_of_line (); | |
4056 | } | |
e16bb312 | 4057 | |
e16bb312 | 4058 | |
c19d1205 | 4059 | /* Parse a directive saving core registers. */ |
e16bb312 | 4060 | |
c19d1205 ZW |
4061 | static void |
4062 | s_arm_unwind_save_core (void) | |
e16bb312 | 4063 | { |
c19d1205 ZW |
4064 | valueT op; |
4065 | long range; | |
4066 | int n; | |
e16bb312 | 4067 | |
4b5a202f | 4068 | range = parse_reg_list (&input_line_pointer, REGLIST_RN); |
c19d1205 | 4069 | if (range == FAIL) |
e16bb312 | 4070 | { |
c19d1205 ZW |
4071 | as_bad (_("expected register list")); |
4072 | ignore_rest_of_line (); | |
4073 | return; | |
4074 | } | |
e16bb312 | 4075 | |
c19d1205 | 4076 | demand_empty_rest_of_line (); |
e16bb312 | 4077 | |
c19d1205 ZW |
4078 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
4079 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
4080 | ip because it is clobbered by calls. */ | |
4081 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
4082 | && (range & 0x3000) == 0x1000) | |
4083 | { | |
4084 | unwind.opcode_count--; | |
4085 | unwind.sp_restored = 0; | |
4086 | range = (range | 0x2000) & ~0x1000; | |
4087 | unwind.pending_offset = 0; | |
4088 | } | |
e16bb312 | 4089 | |
01ae4198 DJ |
4090 | /* Pop r4-r15. */ |
4091 | if (range & 0xfff0) | |
c19d1205 | 4092 | { |
01ae4198 DJ |
4093 | /* See if we can use the short opcodes. These pop a block of up to 8 |
4094 | registers starting with r4, plus maybe r14. */ | |
4095 | for (n = 0; n < 8; n++) | |
4096 | { | |
4097 | /* Break at the first non-saved register. */ | |
4098 | if ((range & (1 << (n + 4))) == 0) | |
4099 | break; | |
4100 | } | |
4101 | /* See if there are any other bits set. */ | |
4102 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
4103 | { | |
4104 | /* Use the long form. */ | |
4105 | op = 0x8000 | ((range >> 4) & 0xfff); | |
4106 | add_unwind_opcode (op, 2); | |
4107 | } | |
0dd132b6 | 4108 | else |
01ae4198 DJ |
4109 | { |
4110 | /* Use the short form. */ | |
4111 | if (range & 0x4000) | |
4112 | op = 0xa8; /* Pop r14. */ | |
4113 | else | |
4114 | op = 0xa0; /* Do not pop r14. */ | |
4115 | op |= (n - 1); | |
4116 | add_unwind_opcode (op, 1); | |
4117 | } | |
c19d1205 | 4118 | } |
0dd132b6 | 4119 | |
c19d1205 ZW |
4120 | /* Pop r0-r3. */ |
4121 | if (range & 0xf) | |
4122 | { | |
4123 | op = 0xb100 | (range & 0xf); | |
4124 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
4125 | } |
4126 | ||
c19d1205 ZW |
4127 | /* Record the number of bytes pushed. */ |
4128 | for (n = 0; n < 16; n++) | |
4129 | { | |
4130 | if (range & (1 << n)) | |
4131 | unwind.frame_size += 4; | |
4132 | } | |
0dd132b6 NC |
4133 | } |
4134 | ||
c19d1205 ZW |
4135 | |
4136 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
4137 | |
4138 | static void | |
c19d1205 | 4139 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 4140 | { |
c19d1205 ZW |
4141 | expressionS exp; |
4142 | int num_regs; | |
4143 | valueT op; | |
b99bd4ef | 4144 | |
c19d1205 ZW |
4145 | /* Get Number of registers to transfer. */ |
4146 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4147 | expression (&exp); | |
4148 | else | |
4149 | exp.X_op = O_illegal; | |
b99bd4ef | 4150 | |
c19d1205 | 4151 | if (exp.X_op != O_constant) |
b99bd4ef | 4152 | { |
c19d1205 ZW |
4153 | as_bad (_("expected , <constant>")); |
4154 | ignore_rest_of_line (); | |
b99bd4ef NC |
4155 | return; |
4156 | } | |
4157 | ||
c19d1205 ZW |
4158 | num_regs = exp.X_add_number; |
4159 | ||
4160 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 4161 | { |
c19d1205 ZW |
4162 | as_bad (_("number of registers must be in the range [1:4]")); |
4163 | ignore_rest_of_line (); | |
b99bd4ef NC |
4164 | return; |
4165 | } | |
4166 | ||
c19d1205 | 4167 | demand_empty_rest_of_line (); |
b99bd4ef | 4168 | |
c19d1205 ZW |
4169 | if (reg == 4) |
4170 | { | |
4171 | /* Short form. */ | |
4172 | op = 0xb4 | (num_regs - 1); | |
4173 | add_unwind_opcode (op, 1); | |
4174 | } | |
b99bd4ef NC |
4175 | else |
4176 | { | |
c19d1205 ZW |
4177 | /* Long form. */ |
4178 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
4179 | add_unwind_opcode (op, 2); | |
b99bd4ef | 4180 | } |
c19d1205 | 4181 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
4182 | } |
4183 | ||
c19d1205 | 4184 | |
fa073d69 MS |
4185 | /* Parse a directive saving VFP registers for ARMv6 and above. */ |
4186 | ||
4187 | static void | |
4188 | s_arm_unwind_save_vfp_armv6 (void) | |
4189 | { | |
4190 | int count; | |
4191 | unsigned int start; | |
4192 | valueT op; | |
4193 | int num_vfpv3_regs = 0; | |
4194 | int num_regs_below_16; | |
efd6b359 | 4195 | bfd_boolean partial_match; |
fa073d69 | 4196 | |
efd6b359 AV |
4197 | count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D, |
4198 | &partial_match); | |
fa073d69 MS |
4199 | if (count == FAIL) |
4200 | { | |
4201 | as_bad (_("expected register list")); | |
4202 | ignore_rest_of_line (); | |
4203 | return; | |
4204 | } | |
4205 | ||
4206 | demand_empty_rest_of_line (); | |
4207 | ||
4208 | /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather | |
4209 | than FSTMX/FLDMX-style ones). */ | |
4210 | ||
4211 | /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */ | |
4212 | if (start >= 16) | |
4213 | num_vfpv3_regs = count; | |
4214 | else if (start + count > 16) | |
4215 | num_vfpv3_regs = start + count - 16; | |
4216 | ||
4217 | if (num_vfpv3_regs > 0) | |
4218 | { | |
4219 | int start_offset = start > 16 ? start - 16 : 0; | |
4220 | op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1); | |
4221 | add_unwind_opcode (op, 2); | |
4222 | } | |
4223 | ||
4224 | /* Generate opcode for registers numbered in the range 0 .. 15. */ | |
4225 | num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count; | |
9c2799c2 | 4226 | gas_assert (num_regs_below_16 + num_vfpv3_regs == count); |
fa073d69 MS |
4227 | if (num_regs_below_16 > 0) |
4228 | { | |
4229 | op = 0xc900 | (start << 4) | (num_regs_below_16 - 1); | |
4230 | add_unwind_opcode (op, 2); | |
4231 | } | |
4232 | ||
4233 | unwind.frame_size += count * 8; | |
4234 | } | |
4235 | ||
4236 | ||
4237 | /* Parse a directive saving VFP registers for pre-ARMv6. */ | |
b99bd4ef NC |
4238 | |
4239 | static void | |
c19d1205 | 4240 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 4241 | { |
c19d1205 | 4242 | int count; |
ca3f61f7 | 4243 | unsigned int reg; |
c19d1205 | 4244 | valueT op; |
efd6b359 | 4245 | bfd_boolean partial_match; |
b99bd4ef | 4246 | |
efd6b359 AV |
4247 | count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D, |
4248 | &partial_match); | |
c19d1205 | 4249 | if (count == FAIL) |
b99bd4ef | 4250 | { |
c19d1205 ZW |
4251 | as_bad (_("expected register list")); |
4252 | ignore_rest_of_line (); | |
b99bd4ef NC |
4253 | return; |
4254 | } | |
4255 | ||
c19d1205 | 4256 | demand_empty_rest_of_line (); |
b99bd4ef | 4257 | |
c19d1205 | 4258 | if (reg == 8) |
b99bd4ef | 4259 | { |
c19d1205 ZW |
4260 | /* Short form. */ |
4261 | op = 0xb8 | (count - 1); | |
4262 | add_unwind_opcode (op, 1); | |
b99bd4ef | 4263 | } |
c19d1205 | 4264 | else |
b99bd4ef | 4265 | { |
c19d1205 ZW |
4266 | /* Long form. */ |
4267 | op = 0xb300 | (reg << 4) | (count - 1); | |
4268 | add_unwind_opcode (op, 2); | |
b99bd4ef | 4269 | } |
c19d1205 ZW |
4270 | unwind.frame_size += count * 8 + 4; |
4271 | } | |
b99bd4ef | 4272 | |
b99bd4ef | 4273 | |
c19d1205 ZW |
4274 | /* Parse a directive saving iWMMXt data registers. */ |
4275 | ||
4276 | static void | |
4277 | s_arm_unwind_save_mmxwr (void) | |
4278 | { | |
4279 | int reg; | |
4280 | int hi_reg; | |
4281 | int i; | |
4282 | unsigned mask = 0; | |
4283 | valueT op; | |
b99bd4ef | 4284 | |
c19d1205 ZW |
4285 | if (*input_line_pointer == '{') |
4286 | input_line_pointer++; | |
b99bd4ef | 4287 | |
c19d1205 | 4288 | do |
b99bd4ef | 4289 | { |
dcbf9037 | 4290 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 4291 | |
c19d1205 | 4292 | if (reg == FAIL) |
b99bd4ef | 4293 | { |
9b7132d3 | 4294 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 | 4295 | goto error; |
b99bd4ef NC |
4296 | } |
4297 | ||
c19d1205 ZW |
4298 | if (mask >> reg) |
4299 | as_tsktsk (_("register list not in ascending order")); | |
4300 | mask |= 1 << reg; | |
b99bd4ef | 4301 | |
c19d1205 ZW |
4302 | if (*input_line_pointer == '-') |
4303 | { | |
4304 | input_line_pointer++; | |
dcbf9037 | 4305 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
c19d1205 ZW |
4306 | if (hi_reg == FAIL) |
4307 | { | |
9b7132d3 | 4308 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 ZW |
4309 | goto error; |
4310 | } | |
4311 | else if (reg >= hi_reg) | |
4312 | { | |
4313 | as_bad (_("bad register range")); | |
4314 | goto error; | |
4315 | } | |
4316 | for (; reg < hi_reg; reg++) | |
4317 | mask |= 1 << reg; | |
4318 | } | |
4319 | } | |
4320 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 4321 | |
d996d970 | 4322 | skip_past_char (&input_line_pointer, '}'); |
b99bd4ef | 4323 | |
c19d1205 | 4324 | demand_empty_rest_of_line (); |
b99bd4ef | 4325 | |
708587a4 | 4326 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
4327 | the list. */ |
4328 | flush_pending_unwind (); | |
b99bd4ef | 4329 | |
c19d1205 | 4330 | for (i = 0; i < 16; i++) |
b99bd4ef | 4331 | { |
c19d1205 ZW |
4332 | if (mask & (1 << i)) |
4333 | unwind.frame_size += 8; | |
b99bd4ef NC |
4334 | } |
4335 | ||
c19d1205 ZW |
4336 | /* Attempt to combine with a previous opcode. We do this because gcc |
4337 | likes to output separate unwind directives for a single block of | |
4338 | registers. */ | |
4339 | if (unwind.opcode_count > 0) | |
b99bd4ef | 4340 | { |
c19d1205 ZW |
4341 | i = unwind.opcodes[unwind.opcode_count - 1]; |
4342 | if ((i & 0xf8) == 0xc0) | |
4343 | { | |
4344 | i &= 7; | |
4345 | /* Only merge if the blocks are contiguous. */ | |
4346 | if (i < 6) | |
4347 | { | |
4348 | if ((mask & 0xfe00) == (1 << 9)) | |
4349 | { | |
4350 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
4351 | unwind.opcode_count--; | |
4352 | } | |
4353 | } | |
4354 | else if (i == 6 && unwind.opcode_count >= 2) | |
4355 | { | |
4356 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
4357 | reg = i >> 4; | |
4358 | i &= 0xf; | |
b99bd4ef | 4359 | |
c19d1205 ZW |
4360 | op = 0xffff << (reg - 1); |
4361 | if (reg > 0 | |
87a1fd79 | 4362 | && ((mask & op) == (1u << (reg - 1)))) |
c19d1205 ZW |
4363 | { |
4364 | op = (1 << (reg + i + 1)) - 1; | |
4365 | op &= ~((1 << reg) - 1); | |
4366 | mask |= op; | |
4367 | unwind.opcode_count -= 2; | |
4368 | } | |
4369 | } | |
4370 | } | |
b99bd4ef NC |
4371 | } |
4372 | ||
c19d1205 ZW |
4373 | hi_reg = 15; |
4374 | /* We want to generate opcodes in the order the registers have been | |
4375 | saved, ie. descending order. */ | |
4376 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 4377 | { |
c19d1205 ZW |
4378 | /* Save registers in blocks. */ |
4379 | if (reg < 0 | |
4380 | || !(mask & (1 << reg))) | |
4381 | { | |
4382 | /* We found an unsaved reg. Generate opcodes to save the | |
5f4273c7 | 4383 | preceding block. */ |
c19d1205 ZW |
4384 | if (reg != hi_reg) |
4385 | { | |
4386 | if (reg == 9) | |
4387 | { | |
4388 | /* Short form. */ | |
4389 | op = 0xc0 | (hi_reg - 10); | |
4390 | add_unwind_opcode (op, 1); | |
4391 | } | |
4392 | else | |
4393 | { | |
4394 | /* Long form. */ | |
4395 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
4396 | add_unwind_opcode (op, 2); | |
4397 | } | |
4398 | } | |
4399 | hi_reg = reg - 1; | |
4400 | } | |
b99bd4ef NC |
4401 | } |
4402 | ||
c19d1205 ZW |
4403 | return; |
4404 | error: | |
4405 | ignore_rest_of_line (); | |
b99bd4ef NC |
4406 | } |
4407 | ||
4408 | static void | |
c19d1205 | 4409 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 4410 | { |
c19d1205 ZW |
4411 | int reg; |
4412 | int hi_reg; | |
4413 | unsigned mask = 0; | |
4414 | valueT op; | |
b99bd4ef | 4415 | |
c19d1205 ZW |
4416 | if (*input_line_pointer == '{') |
4417 | input_line_pointer++; | |
b99bd4ef | 4418 | |
477330fc RM |
4419 | skip_whitespace (input_line_pointer); |
4420 | ||
c19d1205 | 4421 | do |
b99bd4ef | 4422 | { |
dcbf9037 | 4423 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 4424 | |
c19d1205 ZW |
4425 | if (reg == FAIL) |
4426 | { | |
9b7132d3 | 4427 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
4428 | goto error; |
4429 | } | |
b99bd4ef | 4430 | |
c19d1205 ZW |
4431 | reg -= 8; |
4432 | if (mask >> reg) | |
4433 | as_tsktsk (_("register list not in ascending order")); | |
4434 | mask |= 1 << reg; | |
b99bd4ef | 4435 | |
c19d1205 ZW |
4436 | if (*input_line_pointer == '-') |
4437 | { | |
4438 | input_line_pointer++; | |
dcbf9037 | 4439 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
c19d1205 ZW |
4440 | if (hi_reg == FAIL) |
4441 | { | |
9b7132d3 | 4442 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
4443 | goto error; |
4444 | } | |
4445 | else if (reg >= hi_reg) | |
4446 | { | |
4447 | as_bad (_("bad register range")); | |
4448 | goto error; | |
4449 | } | |
4450 | for (; reg < hi_reg; reg++) | |
4451 | mask |= 1 << reg; | |
4452 | } | |
b99bd4ef | 4453 | } |
c19d1205 | 4454 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 4455 | |
d996d970 | 4456 | skip_past_char (&input_line_pointer, '}'); |
b99bd4ef | 4457 | |
c19d1205 ZW |
4458 | demand_empty_rest_of_line (); |
4459 | ||
708587a4 | 4460 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
4461 | the list. */ |
4462 | flush_pending_unwind (); | |
b99bd4ef | 4463 | |
c19d1205 | 4464 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 4465 | { |
c19d1205 ZW |
4466 | if (mask & (1 << reg)) |
4467 | unwind.frame_size += 4; | |
b99bd4ef | 4468 | } |
c19d1205 ZW |
4469 | op = 0xc700 | mask; |
4470 | add_unwind_opcode (op, 2); | |
4471 | return; | |
4472 | error: | |
4473 | ignore_rest_of_line (); | |
b99bd4ef NC |
4474 | } |
4475 | ||
c19d1205 | 4476 | |
fa073d69 MS |
4477 | /* Parse an unwind_save directive. |
4478 | If the argument is non-zero, this is a .vsave directive. */ | |
c19d1205 | 4479 | |
b99bd4ef | 4480 | static void |
fa073d69 | 4481 | s_arm_unwind_save (int arch_v6) |
b99bd4ef | 4482 | { |
c19d1205 ZW |
4483 | char *peek; |
4484 | struct reg_entry *reg; | |
4485 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 4486 | |
921e5f0a | 4487 | if (!unwind.proc_start) |
c921be7d | 4488 | as_bad (MISSING_FNSTART); |
921e5f0a | 4489 | |
c19d1205 ZW |
4490 | /* Figure out what sort of save we have. */ |
4491 | peek = input_line_pointer; | |
b99bd4ef | 4492 | |
c19d1205 | 4493 | if (*peek == '{') |
b99bd4ef | 4494 | { |
c19d1205 ZW |
4495 | had_brace = TRUE; |
4496 | peek++; | |
b99bd4ef NC |
4497 | } |
4498 | ||
c19d1205 | 4499 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 4500 | |
c19d1205 | 4501 | if (!reg) |
b99bd4ef | 4502 | { |
c19d1205 ZW |
4503 | as_bad (_("register expected")); |
4504 | ignore_rest_of_line (); | |
b99bd4ef NC |
4505 | return; |
4506 | } | |
4507 | ||
c19d1205 | 4508 | switch (reg->type) |
b99bd4ef | 4509 | { |
c19d1205 ZW |
4510 | case REG_TYPE_FN: |
4511 | if (had_brace) | |
4512 | { | |
4513 | as_bad (_("FPA .unwind_save does not take a register list")); | |
4514 | ignore_rest_of_line (); | |
4515 | return; | |
4516 | } | |
93ac2687 | 4517 | input_line_pointer = peek; |
c19d1205 | 4518 | s_arm_unwind_save_fpa (reg->number); |
b99bd4ef | 4519 | return; |
c19d1205 | 4520 | |
1f5afe1c NC |
4521 | case REG_TYPE_RN: |
4522 | s_arm_unwind_save_core (); | |
4523 | return; | |
4524 | ||
fa073d69 MS |
4525 | case REG_TYPE_VFD: |
4526 | if (arch_v6) | |
477330fc | 4527 | s_arm_unwind_save_vfp_armv6 (); |
fa073d69 | 4528 | else |
477330fc | 4529 | s_arm_unwind_save_vfp (); |
fa073d69 | 4530 | return; |
1f5afe1c NC |
4531 | |
4532 | case REG_TYPE_MMXWR: | |
4533 | s_arm_unwind_save_mmxwr (); | |
4534 | return; | |
4535 | ||
4536 | case REG_TYPE_MMXWCG: | |
4537 | s_arm_unwind_save_mmxwcg (); | |
4538 | return; | |
c19d1205 ZW |
4539 | |
4540 | default: | |
4541 | as_bad (_(".unwind_save does not support this kind of register")); | |
4542 | ignore_rest_of_line (); | |
b99bd4ef | 4543 | } |
c19d1205 | 4544 | } |
b99bd4ef | 4545 | |
b99bd4ef | 4546 | |
c19d1205 ZW |
4547 | /* Parse an unwind_movsp directive. */ |
4548 | ||
4549 | static void | |
4550 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
4551 | { | |
4552 | int reg; | |
4553 | valueT op; | |
4fa3602b | 4554 | int offset; |
c19d1205 | 4555 | |
921e5f0a | 4556 | if (!unwind.proc_start) |
c921be7d | 4557 | as_bad (MISSING_FNSTART); |
921e5f0a | 4558 | |
dcbf9037 | 4559 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 | 4560 | if (reg == FAIL) |
b99bd4ef | 4561 | { |
9b7132d3 | 4562 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 | 4563 | ignore_rest_of_line (); |
b99bd4ef NC |
4564 | return; |
4565 | } | |
4fa3602b PB |
4566 | |
4567 | /* Optional constant. */ | |
4568 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4569 | { | |
4570 | if (immediate_for_directive (&offset) == FAIL) | |
4571 | return; | |
4572 | } | |
4573 | else | |
4574 | offset = 0; | |
4575 | ||
c19d1205 | 4576 | demand_empty_rest_of_line (); |
b99bd4ef | 4577 | |
c19d1205 | 4578 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 4579 | { |
c19d1205 | 4580 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
4581 | return; |
4582 | } | |
4583 | ||
c19d1205 ZW |
4584 | if (unwind.fp_reg != REG_SP) |
4585 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 4586 | |
c19d1205 ZW |
4587 | /* Generate opcode to restore the value. */ |
4588 | op = 0x90 | reg; | |
4589 | add_unwind_opcode (op, 1); | |
4590 | ||
4591 | /* Record the information for later. */ | |
4592 | unwind.fp_reg = reg; | |
4fa3602b | 4593 | unwind.fp_offset = unwind.frame_size - offset; |
c19d1205 | 4594 | unwind.sp_restored = 1; |
b05fe5cf ZW |
4595 | } |
4596 | ||
c19d1205 ZW |
4597 | /* Parse an unwind_pad directive. */ |
4598 | ||
b05fe5cf | 4599 | static void |
c19d1205 | 4600 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 4601 | { |
c19d1205 | 4602 | int offset; |
b05fe5cf | 4603 | |
921e5f0a | 4604 | if (!unwind.proc_start) |
c921be7d | 4605 | as_bad (MISSING_FNSTART); |
921e5f0a | 4606 | |
c19d1205 ZW |
4607 | if (immediate_for_directive (&offset) == FAIL) |
4608 | return; | |
b99bd4ef | 4609 | |
c19d1205 ZW |
4610 | if (offset & 3) |
4611 | { | |
4612 | as_bad (_("stack increment must be multiple of 4")); | |
4613 | ignore_rest_of_line (); | |
4614 | return; | |
4615 | } | |
b99bd4ef | 4616 | |
c19d1205 ZW |
4617 | /* Don't generate any opcodes, just record the details for later. */ |
4618 | unwind.frame_size += offset; | |
4619 | unwind.pending_offset += offset; | |
4620 | ||
4621 | demand_empty_rest_of_line (); | |
4622 | } | |
4623 | ||
4624 | /* Parse an unwind_setfp directive. */ | |
4625 | ||
4626 | static void | |
4627 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 4628 | { |
c19d1205 ZW |
4629 | int sp_reg; |
4630 | int fp_reg; | |
4631 | int offset; | |
4632 | ||
921e5f0a | 4633 | if (!unwind.proc_start) |
c921be7d | 4634 | as_bad (MISSING_FNSTART); |
921e5f0a | 4635 | |
dcbf9037 | 4636 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 ZW |
4637 | if (skip_past_comma (&input_line_pointer) == FAIL) |
4638 | sp_reg = FAIL; | |
4639 | else | |
dcbf9037 | 4640 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
b99bd4ef | 4641 | |
c19d1205 ZW |
4642 | if (fp_reg == FAIL || sp_reg == FAIL) |
4643 | { | |
4644 | as_bad (_("expected <reg>, <reg>")); | |
4645 | ignore_rest_of_line (); | |
4646 | return; | |
4647 | } | |
b99bd4ef | 4648 | |
c19d1205 ZW |
4649 | /* Optional constant. */ |
4650 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4651 | { | |
4652 | if (immediate_for_directive (&offset) == FAIL) | |
4653 | return; | |
4654 | } | |
4655 | else | |
4656 | offset = 0; | |
a737bd4d | 4657 | |
c19d1205 | 4658 | demand_empty_rest_of_line (); |
a737bd4d | 4659 | |
fdfde340 | 4660 | if (sp_reg != REG_SP && sp_reg != unwind.fp_reg) |
a737bd4d | 4661 | { |
c19d1205 ZW |
4662 | as_bad (_("register must be either sp or set by a previous" |
4663 | "unwind_movsp directive")); | |
4664 | return; | |
a737bd4d NC |
4665 | } |
4666 | ||
c19d1205 ZW |
4667 | /* Don't generate any opcodes, just record the information for later. */ |
4668 | unwind.fp_reg = fp_reg; | |
4669 | unwind.fp_used = 1; | |
fdfde340 | 4670 | if (sp_reg == REG_SP) |
c19d1205 ZW |
4671 | unwind.fp_offset = unwind.frame_size - offset; |
4672 | else | |
4673 | unwind.fp_offset -= offset; | |
a737bd4d NC |
4674 | } |
4675 | ||
c19d1205 ZW |
4676 | /* Parse an unwind_raw directive. */ |
4677 | ||
4678 | static void | |
4679 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 4680 | { |
c19d1205 | 4681 | expressionS exp; |
708587a4 | 4682 | /* This is an arbitrary limit. */ |
c19d1205 ZW |
4683 | unsigned char op[16]; |
4684 | int count; | |
a737bd4d | 4685 | |
921e5f0a | 4686 | if (!unwind.proc_start) |
c921be7d | 4687 | as_bad (MISSING_FNSTART); |
921e5f0a | 4688 | |
c19d1205 ZW |
4689 | expression (&exp); |
4690 | if (exp.X_op == O_constant | |
4691 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 4692 | { |
c19d1205 ZW |
4693 | unwind.frame_size += exp.X_add_number; |
4694 | expression (&exp); | |
4695 | } | |
4696 | else | |
4697 | exp.X_op = O_illegal; | |
a737bd4d | 4698 | |
c19d1205 ZW |
4699 | if (exp.X_op != O_constant) |
4700 | { | |
4701 | as_bad (_("expected <offset>, <opcode>")); | |
4702 | ignore_rest_of_line (); | |
4703 | return; | |
4704 | } | |
a737bd4d | 4705 | |
c19d1205 | 4706 | count = 0; |
a737bd4d | 4707 | |
c19d1205 ZW |
4708 | /* Parse the opcode. */ |
4709 | for (;;) | |
4710 | { | |
4711 | if (count >= 16) | |
4712 | { | |
4713 | as_bad (_("unwind opcode too long")); | |
4714 | ignore_rest_of_line (); | |
a737bd4d | 4715 | } |
c19d1205 | 4716 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 4717 | { |
c19d1205 ZW |
4718 | as_bad (_("invalid unwind opcode")); |
4719 | ignore_rest_of_line (); | |
4720 | return; | |
a737bd4d | 4721 | } |
c19d1205 | 4722 | op[count++] = exp.X_add_number; |
a737bd4d | 4723 | |
c19d1205 ZW |
4724 | /* Parse the next byte. */ |
4725 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
4726 | break; | |
a737bd4d | 4727 | |
c19d1205 ZW |
4728 | expression (&exp); |
4729 | } | |
b99bd4ef | 4730 | |
c19d1205 ZW |
4731 | /* Add the opcode bytes in reverse order. */ |
4732 | while (count--) | |
4733 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 4734 | |
c19d1205 | 4735 | demand_empty_rest_of_line (); |
b99bd4ef | 4736 | } |
ee065d83 PB |
4737 | |
4738 | ||
4739 | /* Parse a .eabi_attribute directive. */ | |
4740 | ||
4741 | static void | |
4742 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
4743 | { | |
0420f52b | 4744 | int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC); |
ee3c0378 | 4745 | |
3076e594 | 4746 | if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES) |
ee3c0378 | 4747 | attributes_set_explicitly[tag] = 1; |
ee065d83 PB |
4748 | } |
4749 | ||
0855e32b NS |
4750 | /* Emit a tls fix for the symbol. */ |
4751 | ||
4752 | static void | |
4753 | s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED) | |
4754 | { | |
4755 | char *p; | |
4756 | expressionS exp; | |
4757 | #ifdef md_flush_pending_output | |
4758 | md_flush_pending_output (); | |
4759 | #endif | |
4760 | ||
4761 | #ifdef md_cons_align | |
4762 | md_cons_align (4); | |
4763 | #endif | |
4764 | ||
4765 | /* Since we're just labelling the code, there's no need to define a | |
4766 | mapping symbol. */ | |
4767 | expression (&exp); | |
4768 | p = obstack_next_free (&frchain_now->frch_obstack); | |
4769 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0, | |
4770 | thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ | |
4771 | : BFD_RELOC_ARM_TLS_DESCSEQ); | |
4772 | } | |
cdf9ccec | 4773 | #endif /* OBJ_ELF */ |
0855e32b | 4774 | |
ee065d83 | 4775 | static void s_arm_arch (int); |
7a1d4c38 | 4776 | static void s_arm_object_arch (int); |
ee065d83 PB |
4777 | static void s_arm_cpu (int); |
4778 | static void s_arm_fpu (int); | |
69133863 | 4779 | static void s_arm_arch_extension (int); |
b99bd4ef | 4780 | |
f0927246 NC |
4781 | #ifdef TE_PE |
4782 | ||
4783 | static void | |
5f4273c7 | 4784 | pe_directive_secrel (int dummy ATTRIBUTE_UNUSED) |
f0927246 NC |
4785 | { |
4786 | expressionS exp; | |
4787 | ||
4788 | do | |
4789 | { | |
4790 | expression (&exp); | |
4791 | if (exp.X_op == O_symbol) | |
4792 | exp.X_op = O_secrel; | |
4793 | ||
4794 | emit_expr (&exp, 4); | |
4795 | } | |
4796 | while (*input_line_pointer++ == ','); | |
4797 | ||
4798 | input_line_pointer--; | |
4799 | demand_empty_rest_of_line (); | |
4800 | } | |
4801 | #endif /* TE_PE */ | |
4802 | ||
c19d1205 ZW |
4803 | /* This table describes all the machine specific pseudo-ops the assembler |
4804 | has to support. The fields are: | |
4805 | pseudo-op name without dot | |
4806 | function to call to execute this pseudo-op | |
4807 | Integer arg to pass to the function. */ | |
b99bd4ef | 4808 | |
c19d1205 | 4809 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 4810 | { |
c19d1205 ZW |
4811 | /* Never called because '.req' does not start a line. */ |
4812 | { "req", s_req, 0 }, | |
dcbf9037 JB |
4813 | /* Following two are likewise never called. */ |
4814 | { "dn", s_dn, 0 }, | |
4815 | { "qn", s_qn, 0 }, | |
c19d1205 ZW |
4816 | { "unreq", s_unreq, 0 }, |
4817 | { "bss", s_bss, 0 }, | |
db2ed2e0 | 4818 | { "align", s_align_ptwo, 2 }, |
c19d1205 ZW |
4819 | { "arm", s_arm, 0 }, |
4820 | { "thumb", s_thumb, 0 }, | |
4821 | { "code", s_code, 0 }, | |
4822 | { "force_thumb", s_force_thumb, 0 }, | |
4823 | { "thumb_func", s_thumb_func, 0 }, | |
4824 | { "thumb_set", s_thumb_set, 0 }, | |
4825 | { "even", s_even, 0 }, | |
4826 | { "ltorg", s_ltorg, 0 }, | |
4827 | { "pool", s_ltorg, 0 }, | |
4828 | { "syntax", s_syntax, 0 }, | |
8463be01 PB |
4829 | { "cpu", s_arm_cpu, 0 }, |
4830 | { "arch", s_arm_arch, 0 }, | |
7a1d4c38 | 4831 | { "object_arch", s_arm_object_arch, 0 }, |
8463be01 | 4832 | { "fpu", s_arm_fpu, 0 }, |
69133863 | 4833 | { "arch_extension", s_arm_arch_extension, 0 }, |
c19d1205 | 4834 | #ifdef OBJ_ELF |
c921be7d NC |
4835 | { "word", s_arm_elf_cons, 4 }, |
4836 | { "long", s_arm_elf_cons, 4 }, | |
4837 | { "inst.n", s_arm_elf_inst, 2 }, | |
4838 | { "inst.w", s_arm_elf_inst, 4 }, | |
4839 | { "inst", s_arm_elf_inst, 0 }, | |
4840 | { "rel31", s_arm_rel31, 0 }, | |
c19d1205 ZW |
4841 | { "fnstart", s_arm_unwind_fnstart, 0 }, |
4842 | { "fnend", s_arm_unwind_fnend, 0 }, | |
4843 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
4844 | { "personality", s_arm_unwind_personality, 0 }, | |
4845 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
4846 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
4847 | { "save", s_arm_unwind_save, 0 }, | |
fa073d69 | 4848 | { "vsave", s_arm_unwind_save, 1 }, |
c19d1205 ZW |
4849 | { "movsp", s_arm_unwind_movsp, 0 }, |
4850 | { "pad", s_arm_unwind_pad, 0 }, | |
4851 | { "setfp", s_arm_unwind_setfp, 0 }, | |
4852 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 | 4853 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
0855e32b | 4854 | { "tlsdescseq", s_arm_tls_descseq, 0 }, |
c19d1205 ZW |
4855 | #else |
4856 | { "word", cons, 4}, | |
f0927246 NC |
4857 | |
4858 | /* These are used for dwarf. */ | |
4859 | {"2byte", cons, 2}, | |
4860 | {"4byte", cons, 4}, | |
4861 | {"8byte", cons, 8}, | |
4862 | /* These are used for dwarf2. */ | |
68d20676 | 4863 | { "file", dwarf2_directive_file, 0 }, |
f0927246 NC |
4864 | { "loc", dwarf2_directive_loc, 0 }, |
4865 | { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 }, | |
c19d1205 ZW |
4866 | #endif |
4867 | { "extend", float_cons, 'x' }, | |
4868 | { "ldouble", float_cons, 'x' }, | |
4869 | { "packed", float_cons, 'p' }, | |
f0927246 NC |
4870 | #ifdef TE_PE |
4871 | {"secrel32", pe_directive_secrel, 0}, | |
4872 | #endif | |
2e6976a8 DG |
4873 | |
4874 | /* These are for compatibility with CodeComposer Studio. */ | |
4875 | {"ref", s_ccs_ref, 0}, | |
4876 | {"def", s_ccs_def, 0}, | |
4877 | {"asmfunc", s_ccs_asmfunc, 0}, | |
4878 | {"endasmfunc", s_ccs_endasmfunc, 0}, | |
4879 | ||
c19d1205 ZW |
4880 | { 0, 0, 0 } |
4881 | }; | |
4882 | \f | |
4883 | /* Parser functions used exclusively in instruction operands. */ | |
b99bd4ef | 4884 | |
c19d1205 ZW |
4885 | /* Generic immediate-value read function for use in insn parsing. |
4886 | STR points to the beginning of the immediate (the leading #); | |
4887 | VAL receives the value; if the value is outside [MIN, MAX] | |
4888 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
4889 | optional. */ | |
b99bd4ef | 4890 | |
c19d1205 ZW |
4891 | static int |
4892 | parse_immediate (char **str, int *val, int min, int max, | |
4893 | bfd_boolean prefix_opt) | |
4894 | { | |
4895 | expressionS exp; | |
0198d5e6 | 4896 | |
c19d1205 ZW |
4897 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); |
4898 | if (exp.X_op != O_constant) | |
b99bd4ef | 4899 | { |
c19d1205 ZW |
4900 | inst.error = _("constant expression required"); |
4901 | return FAIL; | |
4902 | } | |
b99bd4ef | 4903 | |
c19d1205 ZW |
4904 | if (exp.X_add_number < min || exp.X_add_number > max) |
4905 | { | |
4906 | inst.error = _("immediate value out of range"); | |
4907 | return FAIL; | |
4908 | } | |
b99bd4ef | 4909 | |
c19d1205 ZW |
4910 | *val = exp.X_add_number; |
4911 | return SUCCESS; | |
4912 | } | |
b99bd4ef | 4913 | |
5287ad62 | 4914 | /* Less-generic immediate-value read function with the possibility of loading a |
036dc3f7 | 4915 | big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate |
5287ad62 JB |
4916 | instructions. Puts the result directly in inst.operands[i]. */ |
4917 | ||
4918 | static int | |
8335d6aa JW |
4919 | parse_big_immediate (char **str, int i, expressionS *in_exp, |
4920 | bfd_boolean allow_symbol_p) | |
5287ad62 JB |
4921 | { |
4922 | expressionS exp; | |
8335d6aa | 4923 | expressionS *exp_p = in_exp ? in_exp : &exp; |
5287ad62 JB |
4924 | char *ptr = *str; |
4925 | ||
8335d6aa | 4926 | my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG); |
5287ad62 | 4927 | |
8335d6aa | 4928 | if (exp_p->X_op == O_constant) |
036dc3f7 | 4929 | { |
8335d6aa | 4930 | inst.operands[i].imm = exp_p->X_add_number & 0xffffffff; |
036dc3f7 PB |
4931 | /* If we're on a 64-bit host, then a 64-bit number can be returned using |
4932 | O_constant. We have to be careful not to break compilation for | |
4933 | 32-bit X_add_number, though. */ | |
8335d6aa | 4934 | if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0) |
036dc3f7 | 4935 | { |
8335d6aa JW |
4936 | /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */ |
4937 | inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16) | |
4938 | & 0xffffffff); | |
036dc3f7 PB |
4939 | inst.operands[i].regisimm = 1; |
4940 | } | |
4941 | } | |
8335d6aa JW |
4942 | else if (exp_p->X_op == O_big |
4943 | && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32) | |
5287ad62 JB |
4944 | { |
4945 | unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0; | |
95b75c01 | 4946 | |
5287ad62 | 4947 | /* Bignums have their least significant bits in |
477330fc RM |
4948 | generic_bignum[0]. Make sure we put 32 bits in imm and |
4949 | 32 bits in reg, in a (hopefully) portable way. */ | |
9c2799c2 | 4950 | gas_assert (parts != 0); |
95b75c01 NC |
4951 | |
4952 | /* Make sure that the number is not too big. | |
4953 | PR 11972: Bignums can now be sign-extended to the | |
4954 | size of a .octa so check that the out of range bits | |
4955 | are all zero or all one. */ | |
8335d6aa | 4956 | if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64) |
95b75c01 NC |
4957 | { |
4958 | LITTLENUM_TYPE m = -1; | |
4959 | ||
4960 | if (generic_bignum[parts * 2] != 0 | |
4961 | && generic_bignum[parts * 2] != m) | |
4962 | return FAIL; | |
4963 | ||
8335d6aa | 4964 | for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++) |
95b75c01 NC |
4965 | if (generic_bignum[j] != generic_bignum[j-1]) |
4966 | return FAIL; | |
4967 | } | |
4968 | ||
5287ad62 JB |
4969 | inst.operands[i].imm = 0; |
4970 | for (j = 0; j < parts; j++, idx++) | |
477330fc RM |
4971 | inst.operands[i].imm |= generic_bignum[idx] |
4972 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
5287ad62 JB |
4973 | inst.operands[i].reg = 0; |
4974 | for (j = 0; j < parts; j++, idx++) | |
477330fc RM |
4975 | inst.operands[i].reg |= generic_bignum[idx] |
4976 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
5287ad62 JB |
4977 | inst.operands[i].regisimm = 1; |
4978 | } | |
8335d6aa | 4979 | else if (!(exp_p->X_op == O_symbol && allow_symbol_p)) |
5287ad62 | 4980 | return FAIL; |
5f4273c7 | 4981 | |
5287ad62 JB |
4982 | *str = ptr; |
4983 | ||
4984 | return SUCCESS; | |
4985 | } | |
4986 | ||
c19d1205 ZW |
4987 | /* Returns the pseudo-register number of an FPA immediate constant, |
4988 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 4989 | |
c19d1205 ZW |
4990 | static int |
4991 | parse_fpa_immediate (char ** str) | |
4992 | { | |
4993 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
4994 | char * save_in; | |
4995 | expressionS exp; | |
4996 | int i; | |
4997 | int j; | |
b99bd4ef | 4998 | |
c19d1205 ZW |
4999 | /* First try and match exact strings, this is to guarantee |
5000 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 5001 | |
c19d1205 ZW |
5002 | for (i = 0; fp_const[i]; i++) |
5003 | { | |
5004 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 5005 | { |
c19d1205 | 5006 | char *start = *str; |
b99bd4ef | 5007 | |
c19d1205 ZW |
5008 | *str += strlen (fp_const[i]); |
5009 | if (is_end_of_line[(unsigned char) **str]) | |
5010 | return i + 8; | |
5011 | *str = start; | |
5012 | } | |
5013 | } | |
b99bd4ef | 5014 | |
c19d1205 ZW |
5015 | /* Just because we didn't get a match doesn't mean that the constant |
5016 | isn't valid, just that it is in a format that we don't | |
5017 | automatically recognize. Try parsing it with the standard | |
5018 | expression routines. */ | |
b99bd4ef | 5019 | |
c19d1205 | 5020 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 5021 | |
c19d1205 ZW |
5022 | /* Look for a raw floating point number. */ |
5023 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
5024 | && is_end_of_line[(unsigned char) *save_in]) | |
5025 | { | |
5026 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
5027 | { | |
5028 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 5029 | { |
c19d1205 ZW |
5030 | if (words[j] != fp_values[i][j]) |
5031 | break; | |
b99bd4ef NC |
5032 | } |
5033 | ||
c19d1205 | 5034 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 5035 | { |
c19d1205 ZW |
5036 | *str = save_in; |
5037 | return i + 8; | |
b99bd4ef NC |
5038 | } |
5039 | } | |
5040 | } | |
b99bd4ef | 5041 | |
c19d1205 ZW |
5042 | /* Try and parse a more complex expression, this will probably fail |
5043 | unless the code uses a floating point prefix (eg "0f"). */ | |
5044 | save_in = input_line_pointer; | |
5045 | input_line_pointer = *str; | |
5046 | if (expression (&exp) == absolute_section | |
5047 | && exp.X_op == O_big | |
5048 | && exp.X_add_number < 0) | |
5049 | { | |
5050 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
5051 | Ditto for 15. */ | |
ba592044 AM |
5052 | #define X_PRECISION 5 |
5053 | #define E_PRECISION 15L | |
5054 | if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0) | |
c19d1205 ZW |
5055 | { |
5056 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
5057 | { | |
5058 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
5059 | { | |
5060 | if (words[j] != fp_values[i][j]) | |
5061 | break; | |
5062 | } | |
b99bd4ef | 5063 | |
c19d1205 ZW |
5064 | if (j == MAX_LITTLENUMS) |
5065 | { | |
5066 | *str = input_line_pointer; | |
5067 | input_line_pointer = save_in; | |
5068 | return i + 8; | |
5069 | } | |
5070 | } | |
5071 | } | |
b99bd4ef NC |
5072 | } |
5073 | ||
c19d1205 ZW |
5074 | *str = input_line_pointer; |
5075 | input_line_pointer = save_in; | |
5076 | inst.error = _("invalid FPA immediate expression"); | |
5077 | return FAIL; | |
b99bd4ef NC |
5078 | } |
5079 | ||
136da414 JB |
5080 | /* Returns 1 if a number has "quarter-precision" float format |
5081 | 0baBbbbbbc defgh000 00000000 00000000. */ | |
5082 | ||
5083 | static int | |
5084 | is_quarter_float (unsigned imm) | |
5085 | { | |
5086 | int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000; | |
5087 | return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0; | |
5088 | } | |
5089 | ||
aacf0b33 KT |
5090 | |
5091 | /* Detect the presence of a floating point or integer zero constant, | |
5092 | i.e. #0.0 or #0. */ | |
5093 | ||
5094 | static bfd_boolean | |
5095 | parse_ifimm_zero (char **in) | |
5096 | { | |
5097 | int error_code; | |
5098 | ||
5099 | if (!is_immediate_prefix (**in)) | |
3c6452ae TP |
5100 | { |
5101 | /* In unified syntax, all prefixes are optional. */ | |
5102 | if (!unified_syntax) | |
5103 | return FALSE; | |
5104 | } | |
5105 | else | |
5106 | ++*in; | |
0900a05b JW |
5107 | |
5108 | /* Accept #0x0 as a synonym for #0. */ | |
5109 | if (strncmp (*in, "0x", 2) == 0) | |
5110 | { | |
5111 | int val; | |
5112 | if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL) | |
5113 | return FALSE; | |
5114 | return TRUE; | |
5115 | } | |
5116 | ||
aacf0b33 KT |
5117 | error_code = atof_generic (in, ".", EXP_CHARS, |
5118 | &generic_floating_point_number); | |
5119 | ||
5120 | if (!error_code | |
5121 | && generic_floating_point_number.sign == '+' | |
5122 | && (generic_floating_point_number.low | |
5123 | > generic_floating_point_number.leader)) | |
5124 | return TRUE; | |
5125 | ||
5126 | return FALSE; | |
5127 | } | |
5128 | ||
136da414 JB |
5129 | /* Parse an 8-bit "quarter-precision" floating point number of the form: |
5130 | 0baBbbbbbc defgh000 00000000 00000000. | |
c96612cc JB |
5131 | The zero and minus-zero cases need special handling, since they can't be |
5132 | encoded in the "quarter-precision" float format, but can nonetheless be | |
5133 | loaded as integer constants. */ | |
136da414 JB |
5134 | |
5135 | static unsigned | |
5136 | parse_qfloat_immediate (char **ccp, int *immed) | |
5137 | { | |
5138 | char *str = *ccp; | |
c96612cc | 5139 | char *fpnum; |
136da414 | 5140 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; |
c96612cc | 5141 | int found_fpchar = 0; |
5f4273c7 | 5142 | |
136da414 | 5143 | skip_past_char (&str, '#'); |
5f4273c7 | 5144 | |
c96612cc JB |
5145 | /* We must not accidentally parse an integer as a floating-point number. Make |
5146 | sure that the value we parse is not an integer by checking for special | |
5147 | characters '.' or 'e'. | |
5148 | FIXME: This is a horrible hack, but doing better is tricky because type | |
5149 | information isn't in a very usable state at parse time. */ | |
5150 | fpnum = str; | |
5151 | skip_whitespace (fpnum); | |
5152 | ||
5153 | if (strncmp (fpnum, "0x", 2) == 0) | |
5154 | return FAIL; | |
5155 | else | |
5156 | { | |
5157 | for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++) | |
477330fc RM |
5158 | if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E') |
5159 | { | |
5160 | found_fpchar = 1; | |
5161 | break; | |
5162 | } | |
c96612cc JB |
5163 | |
5164 | if (!found_fpchar) | |
477330fc | 5165 | return FAIL; |
c96612cc | 5166 | } |
5f4273c7 | 5167 | |
136da414 JB |
5168 | if ((str = atof_ieee (str, 's', words)) != NULL) |
5169 | { | |
5170 | unsigned fpword = 0; | |
5171 | int i; | |
5f4273c7 | 5172 | |
136da414 JB |
5173 | /* Our FP word must be 32 bits (single-precision FP). */ |
5174 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
477330fc RM |
5175 | { |
5176 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
5177 | fpword |= words[i]; | |
5178 | } | |
5f4273c7 | 5179 | |
c96612cc | 5180 | if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0) |
477330fc | 5181 | *immed = fpword; |
136da414 | 5182 | else |
477330fc | 5183 | return FAIL; |
136da414 JB |
5184 | |
5185 | *ccp = str; | |
5f4273c7 | 5186 | |
136da414 JB |
5187 | return SUCCESS; |
5188 | } | |
5f4273c7 | 5189 | |
136da414 JB |
5190 | return FAIL; |
5191 | } | |
5192 | ||
c19d1205 ZW |
5193 | /* Shift operands. */ |
5194 | enum shift_kind | |
b99bd4ef | 5195 | { |
c19d1205 ZW |
5196 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX |
5197 | }; | |
b99bd4ef | 5198 | |
c19d1205 ZW |
5199 | struct asm_shift_name |
5200 | { | |
5201 | const char *name; | |
5202 | enum shift_kind kind; | |
5203 | }; | |
b99bd4ef | 5204 | |
c19d1205 ZW |
5205 | /* Third argument to parse_shift. */ |
5206 | enum parse_shift_mode | |
5207 | { | |
5208 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
5209 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
5210 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
5211 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
5212 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
5213 | }; | |
b99bd4ef | 5214 | |
c19d1205 ZW |
5215 | /* Parse a <shift> specifier on an ARM data processing instruction. |
5216 | This has three forms: | |
b99bd4ef | 5217 | |
c19d1205 ZW |
5218 | (LSL|LSR|ASL|ASR|ROR) Rs |
5219 | (LSL|LSR|ASL|ASR|ROR) #imm | |
5220 | RRX | |
b99bd4ef | 5221 | |
c19d1205 ZW |
5222 | Note that ASL is assimilated to LSL in the instruction encoding, and |
5223 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 5224 | |
c19d1205 ZW |
5225 | static int |
5226 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 5227 | { |
c19d1205 ZW |
5228 | const struct asm_shift_name *shift_name; |
5229 | enum shift_kind shift; | |
5230 | char *s = *str; | |
5231 | char *p = s; | |
5232 | int reg; | |
b99bd4ef | 5233 | |
c19d1205 ZW |
5234 | for (p = *str; ISALPHA (*p); p++) |
5235 | ; | |
b99bd4ef | 5236 | |
c19d1205 | 5237 | if (p == *str) |
b99bd4ef | 5238 | { |
c19d1205 ZW |
5239 | inst.error = _("shift expression expected"); |
5240 | return FAIL; | |
b99bd4ef NC |
5241 | } |
5242 | ||
21d799b5 | 5243 | shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str, |
477330fc | 5244 | p - *str); |
c19d1205 ZW |
5245 | |
5246 | if (shift_name == NULL) | |
b99bd4ef | 5247 | { |
c19d1205 ZW |
5248 | inst.error = _("shift expression expected"); |
5249 | return FAIL; | |
b99bd4ef NC |
5250 | } |
5251 | ||
c19d1205 | 5252 | shift = shift_name->kind; |
b99bd4ef | 5253 | |
c19d1205 ZW |
5254 | switch (mode) |
5255 | { | |
5256 | case NO_SHIFT_RESTRICT: | |
5257 | case SHIFT_IMMEDIATE: break; | |
b99bd4ef | 5258 | |
c19d1205 ZW |
5259 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
5260 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
5261 | { | |
5262 | inst.error = _("'LSL' or 'ASR' required"); | |
5263 | return FAIL; | |
5264 | } | |
5265 | break; | |
b99bd4ef | 5266 | |
c19d1205 ZW |
5267 | case SHIFT_LSL_IMMEDIATE: |
5268 | if (shift != SHIFT_LSL) | |
5269 | { | |
5270 | inst.error = _("'LSL' required"); | |
5271 | return FAIL; | |
5272 | } | |
5273 | break; | |
b99bd4ef | 5274 | |
c19d1205 ZW |
5275 | case SHIFT_ASR_IMMEDIATE: |
5276 | if (shift != SHIFT_ASR) | |
5277 | { | |
5278 | inst.error = _("'ASR' required"); | |
5279 | return FAIL; | |
5280 | } | |
5281 | break; | |
b99bd4ef | 5282 | |
c19d1205 ZW |
5283 | default: abort (); |
5284 | } | |
b99bd4ef | 5285 | |
c19d1205 ZW |
5286 | if (shift != SHIFT_RRX) |
5287 | { | |
5288 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
5289 | skip_whitespace (p); | |
b99bd4ef | 5290 | |
c19d1205 | 5291 | if (mode == NO_SHIFT_RESTRICT |
dcbf9037 | 5292 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
5293 | { |
5294 | inst.operands[i].imm = reg; | |
5295 | inst.operands[i].immisreg = 1; | |
5296 | } | |
e2b0ab59 | 5297 | else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX)) |
c19d1205 ZW |
5298 | return FAIL; |
5299 | } | |
5300 | inst.operands[i].shift_kind = shift; | |
5301 | inst.operands[i].shifted = 1; | |
5302 | *str = p; | |
5303 | return SUCCESS; | |
b99bd4ef NC |
5304 | } |
5305 | ||
c19d1205 | 5306 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 5307 | |
c19d1205 ZW |
5308 | #<immediate> |
5309 | #<immediate>, <rotate> | |
5310 | <Rm> | |
5311 | <Rm>, <shift> | |
b99bd4ef | 5312 | |
c19d1205 ZW |
5313 | where <shift> is defined by parse_shift above, and <rotate> is a |
5314 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 5315 | is deferred to md_apply_fix. */ |
b99bd4ef | 5316 | |
c19d1205 ZW |
5317 | static int |
5318 | parse_shifter_operand (char **str, int i) | |
5319 | { | |
5320 | int value; | |
91d6fa6a | 5321 | expressionS exp; |
b99bd4ef | 5322 | |
dcbf9037 | 5323 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
5324 | { |
5325 | inst.operands[i].reg = value; | |
5326 | inst.operands[i].isreg = 1; | |
b99bd4ef | 5327 | |
c19d1205 | 5328 | /* parse_shift will override this if appropriate */ |
e2b0ab59 AV |
5329 | inst.relocs[0].exp.X_op = O_constant; |
5330 | inst.relocs[0].exp.X_add_number = 0; | |
b99bd4ef | 5331 | |
c19d1205 ZW |
5332 | if (skip_past_comma (str) == FAIL) |
5333 | return SUCCESS; | |
b99bd4ef | 5334 | |
c19d1205 ZW |
5335 | /* Shift operation on register. */ |
5336 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
5337 | } |
5338 | ||
e2b0ab59 | 5339 | if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX)) |
c19d1205 | 5340 | return FAIL; |
b99bd4ef | 5341 | |
c19d1205 | 5342 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 5343 | { |
c19d1205 | 5344 | /* #x, y -- ie explicit rotation by Y. */ |
91d6fa6a | 5345 | if (my_get_expression (&exp, str, GE_NO_PREFIX)) |
c19d1205 | 5346 | return FAIL; |
b99bd4ef | 5347 | |
e2b0ab59 | 5348 | if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant) |
c19d1205 ZW |
5349 | { |
5350 | inst.error = _("constant expression expected"); | |
5351 | return FAIL; | |
5352 | } | |
b99bd4ef | 5353 | |
91d6fa6a | 5354 | value = exp.X_add_number; |
c19d1205 ZW |
5355 | if (value < 0 || value > 30 || value % 2 != 0) |
5356 | { | |
5357 | inst.error = _("invalid rotation"); | |
5358 | return FAIL; | |
5359 | } | |
e2b0ab59 AV |
5360 | if (inst.relocs[0].exp.X_add_number < 0 |
5361 | || inst.relocs[0].exp.X_add_number > 255) | |
c19d1205 ZW |
5362 | { |
5363 | inst.error = _("invalid constant"); | |
5364 | return FAIL; | |
5365 | } | |
09d92015 | 5366 | |
a415b1cd | 5367 | /* Encode as specified. */ |
e2b0ab59 | 5368 | inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7; |
a415b1cd | 5369 | return SUCCESS; |
09d92015 MM |
5370 | } |
5371 | ||
e2b0ab59 AV |
5372 | inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE; |
5373 | inst.relocs[0].pc_rel = 0; | |
c19d1205 | 5374 | return SUCCESS; |
09d92015 MM |
5375 | } |
5376 | ||
4962c51a MS |
5377 | /* Group relocation information. Each entry in the table contains the |
5378 | textual name of the relocation as may appear in assembler source | |
5379 | and must end with a colon. | |
5380 | Along with this textual name are the relocation codes to be used if | |
5381 | the corresponding instruction is an ALU instruction (ADD or SUB only), | |
5382 | an LDR, an LDRS, or an LDC. */ | |
5383 | ||
5384 | struct group_reloc_table_entry | |
5385 | { | |
5386 | const char *name; | |
5387 | int alu_code; | |
5388 | int ldr_code; | |
5389 | int ldrs_code; | |
5390 | int ldc_code; | |
5391 | }; | |
5392 | ||
5393 | typedef enum | |
5394 | { | |
5395 | /* Varieties of non-ALU group relocation. */ | |
5396 | ||
5397 | GROUP_LDR, | |
5398 | GROUP_LDRS, | |
5399 | GROUP_LDC | |
5400 | } group_reloc_type; | |
5401 | ||
5402 | static struct group_reloc_table_entry group_reloc_table[] = | |
5403 | { /* Program counter relative: */ | |
5404 | { "pc_g0_nc", | |
5405 | BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */ | |
5406 | 0, /* LDR */ | |
5407 | 0, /* LDRS */ | |
5408 | 0 }, /* LDC */ | |
5409 | { "pc_g0", | |
5410 | BFD_RELOC_ARM_ALU_PC_G0, /* ALU */ | |
5411 | BFD_RELOC_ARM_LDR_PC_G0, /* LDR */ | |
5412 | BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */ | |
5413 | BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */ | |
5414 | { "pc_g1_nc", | |
5415 | BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */ | |
5416 | 0, /* LDR */ | |
5417 | 0, /* LDRS */ | |
5418 | 0 }, /* LDC */ | |
5419 | { "pc_g1", | |
5420 | BFD_RELOC_ARM_ALU_PC_G1, /* ALU */ | |
5421 | BFD_RELOC_ARM_LDR_PC_G1, /* LDR */ | |
5422 | BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */ | |
5423 | BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */ | |
5424 | { "pc_g2", | |
5425 | BFD_RELOC_ARM_ALU_PC_G2, /* ALU */ | |
5426 | BFD_RELOC_ARM_LDR_PC_G2, /* LDR */ | |
5427 | BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */ | |
5428 | BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */ | |
5429 | /* Section base relative */ | |
5430 | { "sb_g0_nc", | |
5431 | BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */ | |
5432 | 0, /* LDR */ | |
5433 | 0, /* LDRS */ | |
5434 | 0 }, /* LDC */ | |
5435 | { "sb_g0", | |
5436 | BFD_RELOC_ARM_ALU_SB_G0, /* ALU */ | |
5437 | BFD_RELOC_ARM_LDR_SB_G0, /* LDR */ | |
5438 | BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */ | |
5439 | BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */ | |
5440 | { "sb_g1_nc", | |
5441 | BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */ | |
5442 | 0, /* LDR */ | |
5443 | 0, /* LDRS */ | |
5444 | 0 }, /* LDC */ | |
5445 | { "sb_g1", | |
5446 | BFD_RELOC_ARM_ALU_SB_G1, /* ALU */ | |
5447 | BFD_RELOC_ARM_LDR_SB_G1, /* LDR */ | |
5448 | BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */ | |
5449 | BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */ | |
5450 | { "sb_g2", | |
5451 | BFD_RELOC_ARM_ALU_SB_G2, /* ALU */ | |
5452 | BFD_RELOC_ARM_LDR_SB_G2, /* LDR */ | |
5453 | BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */ | |
72d98d16 MG |
5454 | BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */ |
5455 | /* Absolute thumb alu relocations. */ | |
5456 | { "lower0_7", | |
5457 | BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */ | |
5458 | 0, /* LDR. */ | |
5459 | 0, /* LDRS. */ | |
5460 | 0 }, /* LDC. */ | |
5461 | { "lower8_15", | |
5462 | BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */ | |
5463 | 0, /* LDR. */ | |
5464 | 0, /* LDRS. */ | |
5465 | 0 }, /* LDC. */ | |
5466 | { "upper0_7", | |
5467 | BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */ | |
5468 | 0, /* LDR. */ | |
5469 | 0, /* LDRS. */ | |
5470 | 0 }, /* LDC. */ | |
5471 | { "upper8_15", | |
5472 | BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */ | |
5473 | 0, /* LDR. */ | |
5474 | 0, /* LDRS. */ | |
5475 | 0 } }; /* LDC. */ | |
4962c51a MS |
5476 | |
5477 | /* Given the address of a pointer pointing to the textual name of a group | |
5478 | relocation as may appear in assembler source, attempt to find its details | |
5479 | in group_reloc_table. The pointer will be updated to the character after | |
5480 | the trailing colon. On failure, FAIL will be returned; SUCCESS | |
5481 | otherwise. On success, *entry will be updated to point at the relevant | |
5482 | group_reloc_table entry. */ | |
5483 | ||
5484 | static int | |
5485 | find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out) | |
5486 | { | |
5487 | unsigned int i; | |
5488 | for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++) | |
5489 | { | |
5490 | int length = strlen (group_reloc_table[i].name); | |
5491 | ||
5f4273c7 NC |
5492 | if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 |
5493 | && (*str)[length] == ':') | |
477330fc RM |
5494 | { |
5495 | *out = &group_reloc_table[i]; | |
5496 | *str += (length + 1); | |
5497 | return SUCCESS; | |
5498 | } | |
4962c51a MS |
5499 | } |
5500 | ||
5501 | return FAIL; | |
5502 | } | |
5503 | ||
5504 | /* Parse a <shifter_operand> for an ARM data processing instruction | |
5505 | (as for parse_shifter_operand) where group relocations are allowed: | |
5506 | ||
5507 | #<immediate> | |
5508 | #<immediate>, <rotate> | |
5509 | #:<group_reloc>:<expression> | |
5510 | <Rm> | |
5511 | <Rm>, <shift> | |
5512 | ||
5513 | where <group_reloc> is one of the strings defined in group_reloc_table. | |
5514 | The hashes are optional. | |
5515 | ||
5516 | Everything else is as for parse_shifter_operand. */ | |
5517 | ||
5518 | static parse_operand_result | |
5519 | parse_shifter_operand_group_reloc (char **str, int i) | |
5520 | { | |
5521 | /* Determine if we have the sequence of characters #: or just : | |
5522 | coming next. If we do, then we check for a group relocation. | |
5523 | If we don't, punt the whole lot to parse_shifter_operand. */ | |
5524 | ||
5525 | if (((*str)[0] == '#' && (*str)[1] == ':') | |
5526 | || (*str)[0] == ':') | |
5527 | { | |
5528 | struct group_reloc_table_entry *entry; | |
5529 | ||
5530 | if ((*str)[0] == '#') | |
477330fc | 5531 | (*str) += 2; |
4962c51a | 5532 | else |
477330fc | 5533 | (*str)++; |
4962c51a MS |
5534 | |
5535 | /* Try to parse a group relocation. Anything else is an error. */ | |
5536 | if (find_group_reloc_table_entry (str, &entry) == FAIL) | |
477330fc RM |
5537 | { |
5538 | inst.error = _("unknown group relocation"); | |
5539 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5540 | } | |
4962c51a MS |
5541 | |
5542 | /* We now have the group relocation table entry corresponding to | |
477330fc | 5543 | the name in the assembler source. Next, we parse the expression. */ |
e2b0ab59 | 5544 | if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX)) |
477330fc | 5545 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; |
4962c51a MS |
5546 | |
5547 | /* Record the relocation type (always the ALU variant here). */ | |
e2b0ab59 AV |
5548 | inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code; |
5549 | gas_assert (inst.relocs[0].type != 0); | |
4962c51a MS |
5550 | |
5551 | return PARSE_OPERAND_SUCCESS; | |
5552 | } | |
5553 | else | |
5554 | return parse_shifter_operand (str, i) == SUCCESS | |
477330fc | 5555 | ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL; |
4962c51a MS |
5556 | |
5557 | /* Never reached. */ | |
5558 | } | |
5559 | ||
8e560766 MGD |
5560 | /* Parse a Neon alignment expression. Information is written to |
5561 | inst.operands[i]. We assume the initial ':' has been skipped. | |
fa94de6b | 5562 | |
8e560766 MGD |
5563 | align .imm = align << 8, .immisalign=1, .preind=0 */ |
5564 | static parse_operand_result | |
5565 | parse_neon_alignment (char **str, int i) | |
5566 | { | |
5567 | char *p = *str; | |
5568 | expressionS exp; | |
5569 | ||
5570 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
5571 | ||
5572 | if (exp.X_op != O_constant) | |
5573 | { | |
5574 | inst.error = _("alignment must be constant"); | |
5575 | return PARSE_OPERAND_FAIL; | |
5576 | } | |
5577 | ||
5578 | inst.operands[i].imm = exp.X_add_number << 8; | |
5579 | inst.operands[i].immisalign = 1; | |
5580 | /* Alignments are not pre-indexes. */ | |
5581 | inst.operands[i].preind = 0; | |
5582 | ||
5583 | *str = p; | |
5584 | return PARSE_OPERAND_SUCCESS; | |
5585 | } | |
5586 | ||
c19d1205 | 5587 | /* Parse all forms of an ARM address expression. Information is written |
e2b0ab59 | 5588 | to inst.operands[i] and/or inst.relocs[0]. |
09d92015 | 5589 | |
c19d1205 | 5590 | Preindexed addressing (.preind=1): |
09d92015 | 5591 | |
e2b0ab59 | 5592 | [Rn, #offset] .reg=Rn .relocs[0].exp=offset |
c19d1205 ZW |
5593 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 |
5594 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
e2b0ab59 | 5595 | .shift_kind=shift .relocs[0].exp=shift_imm |
09d92015 | 5596 | |
c19d1205 | 5597 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 5598 | |
c19d1205 | 5599 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 5600 | |
e2b0ab59 | 5601 | [Rn], #offset .reg=Rn .relocs[0].exp=offset |
c19d1205 ZW |
5602 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 |
5603 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
e2b0ab59 | 5604 | .shift_kind=shift .relocs[0].exp=shift_imm |
09d92015 | 5605 | |
c19d1205 | 5606 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 5607 | |
c19d1205 | 5608 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 5609 | |
c19d1205 | 5610 | Other: |
09d92015 | 5611 | |
c19d1205 | 5612 | [Rn]{!} shorthand for [Rn,#0]{!} |
e2b0ab59 AV |
5613 | =immediate .isreg=0 .relocs[0].exp=immediate |
5614 | label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label | |
09d92015 | 5615 | |
c19d1205 | 5616 | It is the caller's responsibility to check for addressing modes not |
e2b0ab59 | 5617 | supported by the instruction, and to set inst.relocs[0].type. */ |
c19d1205 | 5618 | |
4962c51a MS |
5619 | static parse_operand_result |
5620 | parse_address_main (char **str, int i, int group_relocations, | |
477330fc | 5621 | group_reloc_type group_type) |
09d92015 | 5622 | { |
c19d1205 ZW |
5623 | char *p = *str; |
5624 | int reg; | |
09d92015 | 5625 | |
c19d1205 | 5626 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 5627 | { |
c19d1205 ZW |
5628 | if (skip_past_char (&p, '=') == FAIL) |
5629 | { | |
974da60d | 5630 | /* Bare address - translate to PC-relative offset. */ |
e2b0ab59 | 5631 | inst.relocs[0].pc_rel = 1; |
c19d1205 ZW |
5632 | inst.operands[i].reg = REG_PC; |
5633 | inst.operands[i].isreg = 1; | |
5634 | inst.operands[i].preind = 1; | |
09d92015 | 5635 | |
e2b0ab59 | 5636 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG)) |
8335d6aa JW |
5637 | return PARSE_OPERAND_FAIL; |
5638 | } | |
e2b0ab59 | 5639 | else if (parse_big_immediate (&p, i, &inst.relocs[0].exp, |
8335d6aa | 5640 | /*allow_symbol_p=*/TRUE)) |
4962c51a | 5641 | return PARSE_OPERAND_FAIL; |
09d92015 | 5642 | |
c19d1205 | 5643 | *str = p; |
4962c51a | 5644 | return PARSE_OPERAND_SUCCESS; |
09d92015 MM |
5645 | } |
5646 | ||
8ab8155f NC |
5647 | /* PR gas/14887: Allow for whitespace after the opening bracket. */ |
5648 | skip_whitespace (p); | |
5649 | ||
dcbf9037 | 5650 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
09d92015 | 5651 | { |
c19d1205 | 5652 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); |
4962c51a | 5653 | return PARSE_OPERAND_FAIL; |
09d92015 | 5654 | } |
c19d1205 ZW |
5655 | inst.operands[i].reg = reg; |
5656 | inst.operands[i].isreg = 1; | |
09d92015 | 5657 | |
c19d1205 | 5658 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5659 | { |
c19d1205 | 5660 | inst.operands[i].preind = 1; |
09d92015 | 5661 | |
c19d1205 ZW |
5662 | if (*p == '+') p++; |
5663 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
5664 | ||
dcbf9037 | 5665 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
09d92015 | 5666 | { |
c19d1205 ZW |
5667 | inst.operands[i].imm = reg; |
5668 | inst.operands[i].immisreg = 1; | |
5669 | ||
5670 | if (skip_past_comma (&p) == SUCCESS) | |
5671 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5672 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5673 | } |
5287ad62 | 5674 | else if (skip_past_char (&p, ':') == SUCCESS) |
8e560766 MGD |
5675 | { |
5676 | /* FIXME: '@' should be used here, but it's filtered out by generic | |
5677 | code before we get to see it here. This may be subject to | |
5678 | change. */ | |
5679 | parse_operand_result result = parse_neon_alignment (&p, i); | |
fa94de6b | 5680 | |
8e560766 MGD |
5681 | if (result != PARSE_OPERAND_SUCCESS) |
5682 | return result; | |
5683 | } | |
c19d1205 ZW |
5684 | else |
5685 | { | |
5686 | if (inst.operands[i].negative) | |
5687 | { | |
5688 | inst.operands[i].negative = 0; | |
5689 | p--; | |
5690 | } | |
4962c51a | 5691 | |
5f4273c7 NC |
5692 | if (group_relocations |
5693 | && ((*p == '#' && *(p + 1) == ':') || *p == ':')) | |
4962c51a MS |
5694 | { |
5695 | struct group_reloc_table_entry *entry; | |
5696 | ||
477330fc RM |
5697 | /* Skip over the #: or : sequence. */ |
5698 | if (*p == '#') | |
5699 | p += 2; | |
5700 | else | |
5701 | p++; | |
4962c51a MS |
5702 | |
5703 | /* Try to parse a group relocation. Anything else is an | |
477330fc | 5704 | error. */ |
4962c51a MS |
5705 | if (find_group_reloc_table_entry (&p, &entry) == FAIL) |
5706 | { | |
5707 | inst.error = _("unknown group relocation"); | |
5708 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5709 | } | |
5710 | ||
5711 | /* We now have the group relocation table entry corresponding to | |
5712 | the name in the assembler source. Next, we parse the | |
477330fc | 5713 | expression. */ |
e2b0ab59 | 5714 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX)) |
4962c51a MS |
5715 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; |
5716 | ||
5717 | /* Record the relocation type. */ | |
477330fc RM |
5718 | switch (group_type) |
5719 | { | |
5720 | case GROUP_LDR: | |
e2b0ab59 AV |
5721 | inst.relocs[0].type |
5722 | = (bfd_reloc_code_real_type) entry->ldr_code; | |
477330fc | 5723 | break; |
4962c51a | 5724 | |
477330fc | 5725 | case GROUP_LDRS: |
e2b0ab59 AV |
5726 | inst.relocs[0].type |
5727 | = (bfd_reloc_code_real_type) entry->ldrs_code; | |
477330fc | 5728 | break; |
4962c51a | 5729 | |
477330fc | 5730 | case GROUP_LDC: |
e2b0ab59 AV |
5731 | inst.relocs[0].type |
5732 | = (bfd_reloc_code_real_type) entry->ldc_code; | |
477330fc | 5733 | break; |
4962c51a | 5734 | |
477330fc RM |
5735 | default: |
5736 | gas_assert (0); | |
5737 | } | |
4962c51a | 5738 | |
e2b0ab59 | 5739 | if (inst.relocs[0].type == 0) |
4962c51a MS |
5740 | { |
5741 | inst.error = _("this group relocation is not allowed on this instruction"); | |
5742 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5743 | } | |
477330fc RM |
5744 | } |
5745 | else | |
26d97720 NS |
5746 | { |
5747 | char *q = p; | |
0198d5e6 | 5748 | |
e2b0ab59 | 5749 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX)) |
26d97720 NS |
5750 | return PARSE_OPERAND_FAIL; |
5751 | /* If the offset is 0, find out if it's a +0 or -0. */ | |
e2b0ab59 AV |
5752 | if (inst.relocs[0].exp.X_op == O_constant |
5753 | && inst.relocs[0].exp.X_add_number == 0) | |
26d97720 NS |
5754 | { |
5755 | skip_whitespace (q); | |
5756 | if (*q == '#') | |
5757 | { | |
5758 | q++; | |
5759 | skip_whitespace (q); | |
5760 | } | |
5761 | if (*q == '-') | |
5762 | inst.operands[i].negative = 1; | |
5763 | } | |
5764 | } | |
09d92015 MM |
5765 | } |
5766 | } | |
8e560766 MGD |
5767 | else if (skip_past_char (&p, ':') == SUCCESS) |
5768 | { | |
5769 | /* FIXME: '@' should be used here, but it's filtered out by generic code | |
5770 | before we get to see it here. This may be subject to change. */ | |
5771 | parse_operand_result result = parse_neon_alignment (&p, i); | |
fa94de6b | 5772 | |
8e560766 MGD |
5773 | if (result != PARSE_OPERAND_SUCCESS) |
5774 | return result; | |
5775 | } | |
09d92015 | 5776 | |
c19d1205 | 5777 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 5778 | { |
c19d1205 | 5779 | inst.error = _("']' expected"); |
4962c51a | 5780 | return PARSE_OPERAND_FAIL; |
09d92015 MM |
5781 | } |
5782 | ||
c19d1205 ZW |
5783 | if (skip_past_char (&p, '!') == SUCCESS) |
5784 | inst.operands[i].writeback = 1; | |
09d92015 | 5785 | |
c19d1205 | 5786 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5787 | { |
c19d1205 ZW |
5788 | if (skip_past_char (&p, '{') == SUCCESS) |
5789 | { | |
5790 | /* [Rn], {expr} - unindexed, with option */ | |
5791 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 5792 | 0, 255, TRUE) == FAIL) |
4962c51a | 5793 | return PARSE_OPERAND_FAIL; |
09d92015 | 5794 | |
c19d1205 ZW |
5795 | if (skip_past_char (&p, '}') == FAIL) |
5796 | { | |
5797 | inst.error = _("'}' expected at end of 'option' field"); | |
4962c51a | 5798 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5799 | } |
5800 | if (inst.operands[i].preind) | |
5801 | { | |
5802 | inst.error = _("cannot combine index with option"); | |
4962c51a | 5803 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5804 | } |
5805 | *str = p; | |
4962c51a | 5806 | return PARSE_OPERAND_SUCCESS; |
09d92015 | 5807 | } |
c19d1205 ZW |
5808 | else |
5809 | { | |
5810 | inst.operands[i].postind = 1; | |
5811 | inst.operands[i].writeback = 1; | |
09d92015 | 5812 | |
c19d1205 ZW |
5813 | if (inst.operands[i].preind) |
5814 | { | |
5815 | inst.error = _("cannot combine pre- and post-indexing"); | |
4962c51a | 5816 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5817 | } |
09d92015 | 5818 | |
c19d1205 ZW |
5819 | if (*p == '+') p++; |
5820 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 5821 | |
dcbf9037 | 5822 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 | 5823 | { |
477330fc RM |
5824 | /* We might be using the immediate for alignment already. If we |
5825 | are, OR the register number into the low-order bits. */ | |
5826 | if (inst.operands[i].immisalign) | |
5827 | inst.operands[i].imm |= reg; | |
5828 | else | |
5829 | inst.operands[i].imm = reg; | |
c19d1205 | 5830 | inst.operands[i].immisreg = 1; |
a737bd4d | 5831 | |
c19d1205 ZW |
5832 | if (skip_past_comma (&p) == SUCCESS) |
5833 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5834 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5835 | } |
5836 | else | |
5837 | { | |
26d97720 | 5838 | char *q = p; |
0198d5e6 | 5839 | |
c19d1205 ZW |
5840 | if (inst.operands[i].negative) |
5841 | { | |
5842 | inst.operands[i].negative = 0; | |
5843 | p--; | |
5844 | } | |
e2b0ab59 | 5845 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX)) |
4962c51a | 5846 | return PARSE_OPERAND_FAIL; |
26d97720 | 5847 | /* If the offset is 0, find out if it's a +0 or -0. */ |
e2b0ab59 AV |
5848 | if (inst.relocs[0].exp.X_op == O_constant |
5849 | && inst.relocs[0].exp.X_add_number == 0) | |
26d97720 NS |
5850 | { |
5851 | skip_whitespace (q); | |
5852 | if (*q == '#') | |
5853 | { | |
5854 | q++; | |
5855 | skip_whitespace (q); | |
5856 | } | |
5857 | if (*q == '-') | |
5858 | inst.operands[i].negative = 1; | |
5859 | } | |
c19d1205 ZW |
5860 | } |
5861 | } | |
a737bd4d NC |
5862 | } |
5863 | ||
c19d1205 ZW |
5864 | /* If at this point neither .preind nor .postind is set, we have a |
5865 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
5866 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
5867 | { | |
5868 | inst.operands[i].preind = 1; | |
e2b0ab59 AV |
5869 | inst.relocs[0].exp.X_op = O_constant; |
5870 | inst.relocs[0].exp.X_add_number = 0; | |
c19d1205 ZW |
5871 | } |
5872 | *str = p; | |
4962c51a MS |
5873 | return PARSE_OPERAND_SUCCESS; |
5874 | } | |
5875 | ||
5876 | static int | |
5877 | parse_address (char **str, int i) | |
5878 | { | |
21d799b5 | 5879 | return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS |
477330fc | 5880 | ? SUCCESS : FAIL; |
4962c51a MS |
5881 | } |
5882 | ||
5883 | static parse_operand_result | |
5884 | parse_address_group_reloc (char **str, int i, group_reloc_type type) | |
5885 | { | |
5886 | return parse_address_main (str, i, 1, type); | |
a737bd4d NC |
5887 | } |
5888 | ||
b6895b4f PB |
5889 | /* Parse an operand for a MOVW or MOVT instruction. */ |
5890 | static int | |
5891 | parse_half (char **str) | |
5892 | { | |
5893 | char * p; | |
5f4273c7 | 5894 | |
b6895b4f PB |
5895 | p = *str; |
5896 | skip_past_char (&p, '#'); | |
5f4273c7 | 5897 | if (strncasecmp (p, ":lower16:", 9) == 0) |
e2b0ab59 | 5898 | inst.relocs[0].type = BFD_RELOC_ARM_MOVW; |
b6895b4f | 5899 | else if (strncasecmp (p, ":upper16:", 9) == 0) |
e2b0ab59 | 5900 | inst.relocs[0].type = BFD_RELOC_ARM_MOVT; |
b6895b4f | 5901 | |
e2b0ab59 | 5902 | if (inst.relocs[0].type != BFD_RELOC_UNUSED) |
b6895b4f PB |
5903 | { |
5904 | p += 9; | |
5f4273c7 | 5905 | skip_whitespace (p); |
b6895b4f PB |
5906 | } |
5907 | ||
e2b0ab59 | 5908 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX)) |
b6895b4f PB |
5909 | return FAIL; |
5910 | ||
e2b0ab59 | 5911 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
b6895b4f | 5912 | { |
e2b0ab59 | 5913 | if (inst.relocs[0].exp.X_op != O_constant) |
b6895b4f PB |
5914 | { |
5915 | inst.error = _("constant expression expected"); | |
5916 | return FAIL; | |
5917 | } | |
e2b0ab59 AV |
5918 | if (inst.relocs[0].exp.X_add_number < 0 |
5919 | || inst.relocs[0].exp.X_add_number > 0xffff) | |
b6895b4f PB |
5920 | { |
5921 | inst.error = _("immediate value out of range"); | |
5922 | return FAIL; | |
5923 | } | |
5924 | } | |
5925 | *str = p; | |
5926 | return SUCCESS; | |
5927 | } | |
5928 | ||
c19d1205 | 5929 | /* Miscellaneous. */ |
a737bd4d | 5930 | |
c19d1205 ZW |
5931 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
5932 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
5933 | static int | |
d2cd1205 | 5934 | parse_psr (char **str, bfd_boolean lhs) |
09d92015 | 5935 | { |
c19d1205 ZW |
5936 | char *p; |
5937 | unsigned long psr_field; | |
62b3e311 PB |
5938 | const struct asm_psr *psr; |
5939 | char *start; | |
d2cd1205 | 5940 | bfd_boolean is_apsr = FALSE; |
ac7f631b | 5941 | bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m); |
09d92015 | 5942 | |
a4482bb6 NC |
5943 | /* PR gas/12698: If the user has specified -march=all then m_profile will |
5944 | be TRUE, but we want to ignore it in this case as we are building for any | |
5945 | CPU type, including non-m variants. */ | |
823d2571 | 5946 | if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any)) |
a4482bb6 NC |
5947 | m_profile = FALSE; |
5948 | ||
c19d1205 ZW |
5949 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
5950 | feature for ease of use and backwards compatibility. */ | |
5951 | p = *str; | |
62b3e311 | 5952 | if (strncasecmp (p, "SPSR", 4) == 0) |
d2cd1205 JB |
5953 | { |
5954 | if (m_profile) | |
5955 | goto unsupported_psr; | |
fa94de6b | 5956 | |
d2cd1205 JB |
5957 | psr_field = SPSR_BIT; |
5958 | } | |
5959 | else if (strncasecmp (p, "CPSR", 4) == 0) | |
5960 | { | |
5961 | if (m_profile) | |
5962 | goto unsupported_psr; | |
5963 | ||
5964 | psr_field = 0; | |
5965 | } | |
5966 | else if (strncasecmp (p, "APSR", 4) == 0) | |
5967 | { | |
5968 | /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A | |
5969 | and ARMv7-R architecture CPUs. */ | |
5970 | is_apsr = TRUE; | |
5971 | psr_field = 0; | |
5972 | } | |
5973 | else if (m_profile) | |
62b3e311 PB |
5974 | { |
5975 | start = p; | |
5976 | do | |
5977 | p++; | |
5978 | while (ISALNUM (*p) || *p == '_'); | |
5979 | ||
d2cd1205 JB |
5980 | if (strncasecmp (start, "iapsr", 5) == 0 |
5981 | || strncasecmp (start, "eapsr", 5) == 0 | |
5982 | || strncasecmp (start, "xpsr", 4) == 0 | |
5983 | || strncasecmp (start, "psr", 3) == 0) | |
5984 | p = start + strcspn (start, "rR") + 1; | |
5985 | ||
21d799b5 | 5986 | psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start, |
477330fc | 5987 | p - start); |
d2cd1205 | 5988 | |
62b3e311 PB |
5989 | if (!psr) |
5990 | return FAIL; | |
09d92015 | 5991 | |
d2cd1205 JB |
5992 | /* If APSR is being written, a bitfield may be specified. Note that |
5993 | APSR itself is handled above. */ | |
5994 | if (psr->field <= 3) | |
5995 | { | |
5996 | psr_field = psr->field; | |
5997 | is_apsr = TRUE; | |
5998 | goto check_suffix; | |
5999 | } | |
6000 | ||
62b3e311 | 6001 | *str = p; |
d2cd1205 JB |
6002 | /* M-profile MSR instructions have the mask field set to "10", except |
6003 | *PSR variants which modify APSR, which may use a different mask (and | |
6004 | have been handled already). Do that by setting the PSR_f field | |
6005 | here. */ | |
6006 | return psr->field | (lhs ? PSR_f : 0); | |
62b3e311 | 6007 | } |
d2cd1205 JB |
6008 | else |
6009 | goto unsupported_psr; | |
09d92015 | 6010 | |
62b3e311 | 6011 | p += 4; |
d2cd1205 | 6012 | check_suffix: |
c19d1205 ZW |
6013 | if (*p == '_') |
6014 | { | |
6015 | /* A suffix follows. */ | |
c19d1205 ZW |
6016 | p++; |
6017 | start = p; | |
a737bd4d | 6018 | |
c19d1205 ZW |
6019 | do |
6020 | p++; | |
6021 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 6022 | |
d2cd1205 JB |
6023 | if (is_apsr) |
6024 | { | |
6025 | /* APSR uses a notation for bits, rather than fields. */ | |
6026 | unsigned int nzcvq_bits = 0; | |
6027 | unsigned int g_bit = 0; | |
6028 | char *bit; | |
fa94de6b | 6029 | |
d2cd1205 JB |
6030 | for (bit = start; bit != p; bit++) |
6031 | { | |
6032 | switch (TOLOWER (*bit)) | |
477330fc | 6033 | { |
d2cd1205 JB |
6034 | case 'n': |
6035 | nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01; | |
6036 | break; | |
6037 | ||
6038 | case 'z': | |
6039 | nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02; | |
6040 | break; | |
6041 | ||
6042 | case 'c': | |
6043 | nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04; | |
6044 | break; | |
6045 | ||
6046 | case 'v': | |
6047 | nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08; | |
6048 | break; | |
fa94de6b | 6049 | |
d2cd1205 JB |
6050 | case 'q': |
6051 | nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10; | |
6052 | break; | |
fa94de6b | 6053 | |
d2cd1205 JB |
6054 | case 'g': |
6055 | g_bit |= (g_bit & 0x1) ? 0x2 : 0x1; | |
6056 | break; | |
fa94de6b | 6057 | |
d2cd1205 JB |
6058 | default: |
6059 | inst.error = _("unexpected bit specified after APSR"); | |
6060 | return FAIL; | |
6061 | } | |
6062 | } | |
fa94de6b | 6063 | |
d2cd1205 JB |
6064 | if (nzcvq_bits == 0x1f) |
6065 | psr_field |= PSR_f; | |
fa94de6b | 6066 | |
d2cd1205 JB |
6067 | if (g_bit == 0x1) |
6068 | { | |
6069 | if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)) | |
477330fc | 6070 | { |
d2cd1205 JB |
6071 | inst.error = _("selected processor does not " |
6072 | "support DSP extension"); | |
6073 | return FAIL; | |
6074 | } | |
6075 | ||
6076 | psr_field |= PSR_s; | |
6077 | } | |
fa94de6b | 6078 | |
d2cd1205 JB |
6079 | if ((nzcvq_bits & 0x20) != 0 |
6080 | || (nzcvq_bits != 0x1f && nzcvq_bits != 0) | |
6081 | || (g_bit & 0x2) != 0) | |
6082 | { | |
6083 | inst.error = _("bad bitmask specified after APSR"); | |
6084 | return FAIL; | |
6085 | } | |
6086 | } | |
6087 | else | |
477330fc | 6088 | { |
d2cd1205 | 6089 | psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start, |
477330fc | 6090 | p - start); |
d2cd1205 | 6091 | if (!psr) |
477330fc | 6092 | goto error; |
a737bd4d | 6093 | |
d2cd1205 JB |
6094 | psr_field |= psr->field; |
6095 | } | |
a737bd4d | 6096 | } |
c19d1205 | 6097 | else |
a737bd4d | 6098 | { |
c19d1205 ZW |
6099 | if (ISALNUM (*p)) |
6100 | goto error; /* Garbage after "[CS]PSR". */ | |
6101 | ||
d2cd1205 | 6102 | /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This |
477330fc | 6103 | is deprecated, but allow it anyway. */ |
d2cd1205 JB |
6104 | if (is_apsr && lhs) |
6105 | { | |
6106 | psr_field |= PSR_f; | |
6107 | as_tsktsk (_("writing to APSR without specifying a bitmask is " | |
6108 | "deprecated")); | |
6109 | } | |
6110 | else if (!m_profile) | |
6111 | /* These bits are never right for M-profile devices: don't set them | |
6112 | (only code paths which read/write APSR reach here). */ | |
6113 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 6114 | } |
c19d1205 ZW |
6115 | *str = p; |
6116 | return psr_field; | |
a737bd4d | 6117 | |
d2cd1205 JB |
6118 | unsupported_psr: |
6119 | inst.error = _("selected processor does not support requested special " | |
6120 | "purpose register"); | |
6121 | return FAIL; | |
6122 | ||
c19d1205 ZW |
6123 | error: |
6124 | inst.error = _("flag for {c}psr instruction expected"); | |
6125 | return FAIL; | |
a737bd4d NC |
6126 | } |
6127 | ||
32c36c3c AV |
6128 | static int |
6129 | parse_sys_vldr_vstr (char **str) | |
6130 | { | |
6131 | unsigned i; | |
6132 | int val = FAIL; | |
6133 | struct { | |
6134 | const char *name; | |
6135 | int regl; | |
6136 | int regh; | |
6137 | } sysregs[] = { | |
6138 | {"FPSCR", 0x1, 0x0}, | |
6139 | {"FPSCR_nzcvqc", 0x2, 0x0}, | |
6140 | {"VPR", 0x4, 0x1}, | |
6141 | {"P0", 0x5, 0x1}, | |
6142 | {"FPCXTNS", 0x6, 0x1}, | |
6143 | {"FPCXTS", 0x7, 0x1} | |
6144 | }; | |
6145 | char *op_end = strchr (*str, ','); | |
6146 | size_t op_strlen = op_end - *str; | |
6147 | ||
6148 | for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++) | |
6149 | { | |
6150 | if (!strncmp (*str, sysregs[i].name, op_strlen)) | |
6151 | { | |
6152 | val = sysregs[i].regl | (sysregs[i].regh << 3); | |
6153 | *str = op_end; | |
6154 | break; | |
6155 | } | |
6156 | } | |
6157 | ||
6158 | return val; | |
6159 | } | |
6160 | ||
c19d1205 ZW |
6161 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
6162 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 6163 | |
c19d1205 ZW |
6164 | static int |
6165 | parse_cps_flags (char **str) | |
a737bd4d | 6166 | { |
c19d1205 ZW |
6167 | int val = 0; |
6168 | int saw_a_flag = 0; | |
6169 | char *s = *str; | |
a737bd4d | 6170 | |
c19d1205 ZW |
6171 | for (;;) |
6172 | switch (*s++) | |
6173 | { | |
6174 | case '\0': case ',': | |
6175 | goto done; | |
a737bd4d | 6176 | |
c19d1205 ZW |
6177 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
6178 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
6179 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 6180 | |
c19d1205 ZW |
6181 | default: |
6182 | inst.error = _("unrecognized CPS flag"); | |
6183 | return FAIL; | |
6184 | } | |
a737bd4d | 6185 | |
c19d1205 ZW |
6186 | done: |
6187 | if (saw_a_flag == 0) | |
a737bd4d | 6188 | { |
c19d1205 ZW |
6189 | inst.error = _("missing CPS flags"); |
6190 | return FAIL; | |
a737bd4d | 6191 | } |
a737bd4d | 6192 | |
c19d1205 ZW |
6193 | *str = s - 1; |
6194 | return val; | |
a737bd4d NC |
6195 | } |
6196 | ||
c19d1205 ZW |
6197 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
6198 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
6199 | |
6200 | static int | |
c19d1205 | 6201 | parse_endian_specifier (char **str) |
a737bd4d | 6202 | { |
c19d1205 ZW |
6203 | int little_endian; |
6204 | char *s = *str; | |
a737bd4d | 6205 | |
c19d1205 ZW |
6206 | if (strncasecmp (s, "BE", 2)) |
6207 | little_endian = 0; | |
6208 | else if (strncasecmp (s, "LE", 2)) | |
6209 | little_endian = 1; | |
6210 | else | |
a737bd4d | 6211 | { |
c19d1205 | 6212 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
6213 | return FAIL; |
6214 | } | |
6215 | ||
c19d1205 | 6216 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 6217 | { |
c19d1205 | 6218 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
6219 | return FAIL; |
6220 | } | |
6221 | ||
c19d1205 ZW |
6222 | *str = s + 2; |
6223 | return little_endian; | |
6224 | } | |
a737bd4d | 6225 | |
c19d1205 ZW |
6226 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
6227 | value suitable for poking into the rotate field of an sxt or sxta | |
6228 | instruction, or FAIL on error. */ | |
6229 | ||
6230 | static int | |
6231 | parse_ror (char **str) | |
6232 | { | |
6233 | int rot; | |
6234 | char *s = *str; | |
6235 | ||
6236 | if (strncasecmp (s, "ROR", 3) == 0) | |
6237 | s += 3; | |
6238 | else | |
a737bd4d | 6239 | { |
c19d1205 | 6240 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
6241 | return FAIL; |
6242 | } | |
c19d1205 ZW |
6243 | |
6244 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
6245 | return FAIL; | |
6246 | ||
6247 | switch (rot) | |
a737bd4d | 6248 | { |
c19d1205 ZW |
6249 | case 0: *str = s; return 0x0; |
6250 | case 8: *str = s; return 0x1; | |
6251 | case 16: *str = s; return 0x2; | |
6252 | case 24: *str = s; return 0x3; | |
6253 | ||
6254 | default: | |
6255 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
6256 | return FAIL; |
6257 | } | |
c19d1205 | 6258 | } |
a737bd4d | 6259 | |
c19d1205 ZW |
6260 | /* Parse a conditional code (from conds[] below). The value returned is in the |
6261 | range 0 .. 14, or FAIL. */ | |
6262 | static int | |
6263 | parse_cond (char **str) | |
6264 | { | |
c462b453 | 6265 | char *q; |
c19d1205 | 6266 | const struct asm_cond *c; |
c462b453 PB |
6267 | int n; |
6268 | /* Condition codes are always 2 characters, so matching up to | |
6269 | 3 characters is sufficient. */ | |
6270 | char cond[3]; | |
a737bd4d | 6271 | |
c462b453 PB |
6272 | q = *str; |
6273 | n = 0; | |
6274 | while (ISALPHA (*q) && n < 3) | |
6275 | { | |
e07e6e58 | 6276 | cond[n] = TOLOWER (*q); |
c462b453 PB |
6277 | q++; |
6278 | n++; | |
6279 | } | |
a737bd4d | 6280 | |
21d799b5 | 6281 | c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n); |
c19d1205 | 6282 | if (!c) |
a737bd4d | 6283 | { |
c19d1205 | 6284 | inst.error = _("condition required"); |
a737bd4d NC |
6285 | return FAIL; |
6286 | } | |
6287 | ||
c19d1205 ZW |
6288 | *str = q; |
6289 | return c->value; | |
6290 | } | |
6291 | ||
643afb90 MW |
6292 | /* Record a use of the given feature. */ |
6293 | static void | |
6294 | record_feature_use (const arm_feature_set *feature) | |
6295 | { | |
6296 | if (thumb_mode) | |
6297 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature); | |
6298 | else | |
6299 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature); | |
6300 | } | |
6301 | ||
4d354d8b TP |
6302 | /* If the given feature is currently allowed, mark it as used and return TRUE. |
6303 | Return FALSE otherwise. */ | |
e797f7e0 MGD |
6304 | static bfd_boolean |
6305 | mark_feature_used (const arm_feature_set *feature) | |
6306 | { | |
4d354d8b | 6307 | /* Ensure the option is currently allowed. */ |
e797f7e0 MGD |
6308 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) |
6309 | return FALSE; | |
6310 | ||
4d354d8b | 6311 | /* Add the appropriate architecture feature for the barrier option used. */ |
643afb90 | 6312 | record_feature_use (feature); |
e797f7e0 MGD |
6313 | |
6314 | return TRUE; | |
6315 | } | |
6316 | ||
62b3e311 PB |
6317 | /* Parse an option for a barrier instruction. Returns the encoding for the |
6318 | option, or FAIL. */ | |
6319 | static int | |
6320 | parse_barrier (char **str) | |
6321 | { | |
6322 | char *p, *q; | |
6323 | const struct asm_barrier_opt *o; | |
6324 | ||
6325 | p = q = *str; | |
6326 | while (ISALPHA (*q)) | |
6327 | q++; | |
6328 | ||
21d799b5 | 6329 | o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p, |
477330fc | 6330 | q - p); |
62b3e311 PB |
6331 | if (!o) |
6332 | return FAIL; | |
6333 | ||
e797f7e0 MGD |
6334 | if (!mark_feature_used (&o->arch)) |
6335 | return FAIL; | |
6336 | ||
62b3e311 PB |
6337 | *str = q; |
6338 | return o->value; | |
6339 | } | |
6340 | ||
92e90b6e PB |
6341 | /* Parse the operands of a table branch instruction. Similar to a memory |
6342 | operand. */ | |
6343 | static int | |
6344 | parse_tb (char **str) | |
6345 | { | |
6346 | char * p = *str; | |
6347 | int reg; | |
6348 | ||
6349 | if (skip_past_char (&p, '[') == FAIL) | |
ab1eb5fe PB |
6350 | { |
6351 | inst.error = _("'[' expected"); | |
6352 | return FAIL; | |
6353 | } | |
92e90b6e | 6354 | |
dcbf9037 | 6355 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
6356 | { |
6357 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
6358 | return FAIL; | |
6359 | } | |
6360 | inst.operands[0].reg = reg; | |
6361 | ||
6362 | if (skip_past_comma (&p) == FAIL) | |
ab1eb5fe PB |
6363 | { |
6364 | inst.error = _("',' expected"); | |
6365 | return FAIL; | |
6366 | } | |
5f4273c7 | 6367 | |
dcbf9037 | 6368 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
6369 | { |
6370 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
6371 | return FAIL; | |
6372 | } | |
6373 | inst.operands[0].imm = reg; | |
6374 | ||
6375 | if (skip_past_comma (&p) == SUCCESS) | |
6376 | { | |
6377 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
6378 | return FAIL; | |
e2b0ab59 | 6379 | if (inst.relocs[0].exp.X_add_number != 1) |
92e90b6e PB |
6380 | { |
6381 | inst.error = _("invalid shift"); | |
6382 | return FAIL; | |
6383 | } | |
6384 | inst.operands[0].shifted = 1; | |
6385 | } | |
6386 | ||
6387 | if (skip_past_char (&p, ']') == FAIL) | |
6388 | { | |
6389 | inst.error = _("']' expected"); | |
6390 | return FAIL; | |
6391 | } | |
6392 | *str = p; | |
6393 | return SUCCESS; | |
6394 | } | |
6395 | ||
5287ad62 JB |
6396 | /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more |
6397 | information on the types the operands can take and how they are encoded. | |
037e8744 JB |
6398 | Up to four operands may be read; this function handles setting the |
6399 | ".present" field for each read operand itself. | |
5287ad62 JB |
6400 | Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS, |
6401 | else returns FAIL. */ | |
6402 | ||
6403 | static int | |
6404 | parse_neon_mov (char **str, int *which_operand) | |
6405 | { | |
6406 | int i = *which_operand, val; | |
6407 | enum arm_reg_type rtype; | |
6408 | char *ptr = *str; | |
dcbf9037 | 6409 | struct neon_type_el optype; |
5f4273c7 | 6410 | |
dcbf9037 | 6411 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
6412 | { |
6413 | /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */ | |
6414 | inst.operands[i].reg = val; | |
6415 | inst.operands[i].isscalar = 1; | |
dcbf9037 | 6416 | inst.operands[i].vectype = optype; |
5287ad62 JB |
6417 | inst.operands[i++].present = 1; |
6418 | ||
6419 | if (skip_past_comma (&ptr) == FAIL) | |
477330fc | 6420 | goto wanted_comma; |
5f4273c7 | 6421 | |
dcbf9037 | 6422 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
477330fc | 6423 | goto wanted_arm; |
5f4273c7 | 6424 | |
5287ad62 JB |
6425 | inst.operands[i].reg = val; |
6426 | inst.operands[i].isreg = 1; | |
6427 | inst.operands[i].present = 1; | |
6428 | } | |
037e8744 | 6429 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype)) |
477330fc | 6430 | != FAIL) |
5287ad62 JB |
6431 | { |
6432 | /* Cases 0, 1, 2, 3, 5 (D only). */ | |
6433 | if (skip_past_comma (&ptr) == FAIL) | |
477330fc | 6434 | goto wanted_comma; |
5f4273c7 | 6435 | |
5287ad62 JB |
6436 | inst.operands[i].reg = val; |
6437 | inst.operands[i].isreg = 1; | |
6438 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
6439 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
6440 | inst.operands[i].isvec = 1; | |
dcbf9037 | 6441 | inst.operands[i].vectype = optype; |
5287ad62 JB |
6442 | inst.operands[i++].present = 1; |
6443 | ||
dcbf9037 | 6444 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
477330fc RM |
6445 | { |
6446 | /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>. | |
6447 | Case 13: VMOV <Sd>, <Rm> */ | |
6448 | inst.operands[i].reg = val; | |
6449 | inst.operands[i].isreg = 1; | |
6450 | inst.operands[i].present = 1; | |
6451 | ||
6452 | if (rtype == REG_TYPE_NQ) | |
6453 | { | |
6454 | first_error (_("can't use Neon quad register here")); | |
6455 | return FAIL; | |
6456 | } | |
6457 | else if (rtype != REG_TYPE_VFS) | |
6458 | { | |
6459 | i++; | |
6460 | if (skip_past_comma (&ptr) == FAIL) | |
6461 | goto wanted_comma; | |
6462 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6463 | goto wanted_arm; | |
6464 | inst.operands[i].reg = val; | |
6465 | inst.operands[i].isreg = 1; | |
6466 | inst.operands[i].present = 1; | |
6467 | } | |
6468 | } | |
037e8744 | 6469 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, |
477330fc RM |
6470 | &optype)) != FAIL) |
6471 | { | |
6472 | /* Case 0: VMOV<c><q> <Qd>, <Qm> | |
6473 | Case 1: VMOV<c><q> <Dd>, <Dm> | |
6474 | Case 8: VMOV.F32 <Sd>, <Sm> | |
6475 | Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */ | |
6476 | ||
6477 | inst.operands[i].reg = val; | |
6478 | inst.operands[i].isreg = 1; | |
6479 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
6480 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
6481 | inst.operands[i].isvec = 1; | |
6482 | inst.operands[i].vectype = optype; | |
6483 | inst.operands[i].present = 1; | |
6484 | ||
6485 | if (skip_past_comma (&ptr) == SUCCESS) | |
6486 | { | |
6487 | /* Case 15. */ | |
6488 | i++; | |
6489 | ||
6490 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6491 | goto wanted_arm; | |
6492 | ||
6493 | inst.operands[i].reg = val; | |
6494 | inst.operands[i].isreg = 1; | |
6495 | inst.operands[i++].present = 1; | |
6496 | ||
6497 | if (skip_past_comma (&ptr) == FAIL) | |
6498 | goto wanted_comma; | |
6499 | ||
6500 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6501 | goto wanted_arm; | |
6502 | ||
6503 | inst.operands[i].reg = val; | |
6504 | inst.operands[i].isreg = 1; | |
6505 | inst.operands[i].present = 1; | |
6506 | } | |
6507 | } | |
4641781c | 6508 | else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS) |
477330fc RM |
6509 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm> |
6510 | Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm> | |
6511 | Case 10: VMOV.F32 <Sd>, #<imm> | |
6512 | Case 11: VMOV.F64 <Dd>, #<imm> */ | |
6513 | inst.operands[i].immisfloat = 1; | |
8335d6aa JW |
6514 | else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE) |
6515 | == SUCCESS) | |
477330fc RM |
6516 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm> |
6517 | Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */ | |
6518 | ; | |
5287ad62 | 6519 | else |
477330fc RM |
6520 | { |
6521 | first_error (_("expected <Rm> or <Dm> or <Qm> operand")); | |
6522 | return FAIL; | |
6523 | } | |
5287ad62 | 6524 | } |
dcbf9037 | 6525 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
6526 | { |
6527 | /* Cases 6, 7. */ | |
6528 | inst.operands[i].reg = val; | |
6529 | inst.operands[i].isreg = 1; | |
6530 | inst.operands[i++].present = 1; | |
5f4273c7 | 6531 | |
5287ad62 | 6532 | if (skip_past_comma (&ptr) == FAIL) |
477330fc | 6533 | goto wanted_comma; |
5f4273c7 | 6534 | |
dcbf9037 | 6535 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
477330fc RM |
6536 | { |
6537 | /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */ | |
6538 | inst.operands[i].reg = val; | |
6539 | inst.operands[i].isscalar = 1; | |
6540 | inst.operands[i].present = 1; | |
6541 | inst.operands[i].vectype = optype; | |
6542 | } | |
dcbf9037 | 6543 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
477330fc RM |
6544 | { |
6545 | /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */ | |
6546 | inst.operands[i].reg = val; | |
6547 | inst.operands[i].isreg = 1; | |
6548 | inst.operands[i++].present = 1; | |
6549 | ||
6550 | if (skip_past_comma (&ptr) == FAIL) | |
6551 | goto wanted_comma; | |
6552 | ||
6553 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype)) | |
6554 | == FAIL) | |
6555 | { | |
6556 | first_error (_(reg_expected_msgs[REG_TYPE_VFSD])); | |
6557 | return FAIL; | |
6558 | } | |
6559 | ||
6560 | inst.operands[i].reg = val; | |
6561 | inst.operands[i].isreg = 1; | |
6562 | inst.operands[i].isvec = 1; | |
6563 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
6564 | inst.operands[i].vectype = optype; | |
6565 | inst.operands[i].present = 1; | |
6566 | ||
6567 | if (rtype == REG_TYPE_VFS) | |
6568 | { | |
6569 | /* Case 14. */ | |
6570 | i++; | |
6571 | if (skip_past_comma (&ptr) == FAIL) | |
6572 | goto wanted_comma; | |
6573 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, | |
6574 | &optype)) == FAIL) | |
6575 | { | |
6576 | first_error (_(reg_expected_msgs[REG_TYPE_VFS])); | |
6577 | return FAIL; | |
6578 | } | |
6579 | inst.operands[i].reg = val; | |
6580 | inst.operands[i].isreg = 1; | |
6581 | inst.operands[i].isvec = 1; | |
6582 | inst.operands[i].issingle = 1; | |
6583 | inst.operands[i].vectype = optype; | |
6584 | inst.operands[i].present = 1; | |
6585 | } | |
6586 | } | |
037e8744 | 6587 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype)) |
477330fc RM |
6588 | != FAIL) |
6589 | { | |
6590 | /* Case 13. */ | |
6591 | inst.operands[i].reg = val; | |
6592 | inst.operands[i].isreg = 1; | |
6593 | inst.operands[i].isvec = 1; | |
6594 | inst.operands[i].issingle = 1; | |
6595 | inst.operands[i].vectype = optype; | |
6596 | inst.operands[i].present = 1; | |
6597 | } | |
5287ad62 JB |
6598 | } |
6599 | else | |
6600 | { | |
dcbf9037 | 6601 | first_error (_("parse error")); |
5287ad62 JB |
6602 | return FAIL; |
6603 | } | |
6604 | ||
6605 | /* Successfully parsed the operands. Update args. */ | |
6606 | *which_operand = i; | |
6607 | *str = ptr; | |
6608 | return SUCCESS; | |
6609 | ||
5f4273c7 | 6610 | wanted_comma: |
dcbf9037 | 6611 | first_error (_("expected comma")); |
5287ad62 | 6612 | return FAIL; |
5f4273c7 NC |
6613 | |
6614 | wanted_arm: | |
dcbf9037 | 6615 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
5287ad62 | 6616 | return FAIL; |
5287ad62 JB |
6617 | } |
6618 | ||
5be8be5d DG |
6619 | /* Use this macro when the operand constraints are different |
6620 | for ARM and THUMB (e.g. ldrd). */ | |
6621 | #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \ | |
6622 | ((arm_operand) | ((thumb_operand) << 16)) | |
6623 | ||
c19d1205 ZW |
6624 | /* Matcher codes for parse_operands. */ |
6625 | enum operand_parse_code | |
6626 | { | |
6627 | OP_stop, /* end of line */ | |
6628 | ||
6629 | OP_RR, /* ARM register */ | |
6630 | OP_RRnpc, /* ARM register, not r15 */ | |
5be8be5d | 6631 | OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */ |
c19d1205 | 6632 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ |
fa94de6b | 6633 | OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback, |
55881a11 | 6634 | optional trailing ! */ |
c19d1205 ZW |
6635 | OP_RRw, /* ARM register, not r15, optional trailing ! */ |
6636 | OP_RCP, /* Coprocessor number */ | |
6637 | OP_RCN, /* Coprocessor register */ | |
6638 | OP_RF, /* FPA register */ | |
6639 | OP_RVS, /* VFP single precision register */ | |
5287ad62 JB |
6640 | OP_RVD, /* VFP double precision register (0..15) */ |
6641 | OP_RND, /* Neon double precision register (0..31) */ | |
6642 | OP_RNQ, /* Neon quad precision register */ | |
037e8744 | 6643 | OP_RVSD, /* VFP single or double precision register */ |
dec41383 | 6644 | OP_RNSD, /* Neon single or double precision register */ |
5287ad62 | 6645 | OP_RNDQ, /* Neon double or quad precision register */ |
037e8744 | 6646 | OP_RNSDQ, /* Neon single, double or quad precision register */ |
5287ad62 | 6647 | OP_RNSC, /* Neon scalar D[X] */ |
c19d1205 ZW |
6648 | OP_RVC, /* VFP control register */ |
6649 | OP_RMF, /* Maverick F register */ | |
6650 | OP_RMD, /* Maverick D register */ | |
6651 | OP_RMFX, /* Maverick FX register */ | |
6652 | OP_RMDX, /* Maverick DX register */ | |
6653 | OP_RMAX, /* Maverick AX register */ | |
6654 | OP_RMDS, /* Maverick DSPSC register */ | |
6655 | OP_RIWR, /* iWMMXt wR register */ | |
6656 | OP_RIWC, /* iWMMXt wC register */ | |
6657 | OP_RIWG, /* iWMMXt wCG register */ | |
6658 | OP_RXA, /* XScale accumulator register */ | |
6659 | ||
60f993ce AV |
6660 | /* New operands for Armv8.1-M Mainline. */ |
6661 | OP_LR, /* ARM LR register */ | |
6662 | OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */ | |
6663 | ||
c19d1205 | 6664 | OP_REGLST, /* ARM register list */ |
4b5a202f | 6665 | OP_CLRMLST, /* CLRM register list */ |
c19d1205 ZW |
6666 | OP_VRSLST, /* VFP single-precision register list */ |
6667 | OP_VRDLST, /* VFP double-precision register list */ | |
037e8744 | 6668 | OP_VRSDLST, /* VFP single or double-precision register list (& quad) */ |
5287ad62 JB |
6669 | OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */ |
6670 | OP_NSTRLST, /* Neon element/structure list */ | |
efd6b359 | 6671 | OP_VRSDVLST, /* VFP single or double-precision register list and VPR */ |
5287ad62 | 6672 | |
5287ad62 | 6673 | OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */ |
037e8744 | 6674 | OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */ |
aacf0b33 | 6675 | OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */ |
5287ad62 | 6676 | OP_RR_RNSC, /* ARM reg or Neon scalar. */ |
dec41383 | 6677 | OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */ |
037e8744 | 6678 | OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */ |
5287ad62 JB |
6679 | OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */ |
6680 | OP_RND_RNSC, /* Neon D reg, or Neon scalar. */ | |
6681 | OP_VMOV, /* Neon VMOV operands. */ | |
4316f0d2 | 6682 | OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */ |
5287ad62 | 6683 | OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */ |
2d447fca | 6684 | OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */ |
32c36c3c | 6685 | OP_VLDR, /* VLDR operand. */ |
5287ad62 JB |
6686 | |
6687 | OP_I0, /* immediate zero */ | |
c19d1205 ZW |
6688 | OP_I7, /* immediate value 0 .. 7 */ |
6689 | OP_I15, /* 0 .. 15 */ | |
6690 | OP_I16, /* 1 .. 16 */ | |
5287ad62 | 6691 | OP_I16z, /* 0 .. 16 */ |
c19d1205 ZW |
6692 | OP_I31, /* 0 .. 31 */ |
6693 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
6694 | OP_I32, /* 1 .. 32 */ | |
5287ad62 JB |
6695 | OP_I32z, /* 0 .. 32 */ |
6696 | OP_I63, /* 0 .. 63 */ | |
c19d1205 | 6697 | OP_I63s, /* -64 .. 63 */ |
5287ad62 JB |
6698 | OP_I64, /* 1 .. 64 */ |
6699 | OP_I64z, /* 0 .. 64 */ | |
c19d1205 | 6700 | OP_I255, /* 0 .. 255 */ |
c19d1205 ZW |
6701 | |
6702 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
6703 | OP_I7b, /* 0 .. 7 */ | |
6704 | OP_I15b, /* 0 .. 15 */ | |
6705 | OP_I31b, /* 0 .. 31 */ | |
6706 | ||
6707 | OP_SH, /* shifter operand */ | |
4962c51a | 6708 | OP_SHG, /* shifter operand with possible group relocation */ |
c19d1205 | 6709 | OP_ADDR, /* Memory address expression (any mode) */ |
4962c51a MS |
6710 | OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */ |
6711 | OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */ | |
6712 | OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */ | |
c19d1205 ZW |
6713 | OP_EXP, /* arbitrary expression */ |
6714 | OP_EXPi, /* same, with optional immediate prefix */ | |
6715 | OP_EXPr, /* same, with optional relocation suffix */ | |
e2b0ab59 | 6716 | OP_EXPs, /* same, with optional non-first operand relocation suffix */ |
b6895b4f | 6717 | OP_HALF, /* 0 .. 65535 or low/high reloc. */ |
c28eeff2 SN |
6718 | OP_IROT1, /* VCADD rotate immediate: 90, 270. */ |
6719 | OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */ | |
c19d1205 ZW |
6720 | |
6721 | OP_CPSF, /* CPS flags */ | |
6722 | OP_ENDI, /* Endianness specifier */ | |
d2cd1205 JB |
6723 | OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */ |
6724 | OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */ | |
c19d1205 | 6725 | OP_COND, /* conditional code */ |
92e90b6e | 6726 | OP_TB, /* Table branch. */ |
c19d1205 | 6727 | |
037e8744 JB |
6728 | OP_APSR_RR, /* ARM register or "APSR_nzcv". */ |
6729 | ||
c19d1205 | 6730 | OP_RRnpc_I0, /* ARM register or literal 0 */ |
33eaf5de | 6731 | OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */ |
c19d1205 ZW |
6732 | OP_RR_EXi, /* ARM register or expression with imm prefix */ |
6733 | OP_RF_IF, /* FPA register or immediate */ | |
6734 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
41adaa5c | 6735 | OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */ |
c19d1205 ZW |
6736 | |
6737 | /* Optional operands. */ | |
6738 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
6739 | OP_oI31b, /* 0 .. 31 */ | |
5287ad62 | 6740 | OP_oI32b, /* 1 .. 32 */ |
5f1af56b | 6741 | OP_oI32z, /* 0 .. 32 */ |
c19d1205 ZW |
6742 | OP_oIffffb, /* 0 .. 65535 */ |
6743 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
6744 | ||
6745 | OP_oRR, /* ARM register */ | |
60f993ce | 6746 | OP_oLR, /* ARM LR register */ |
c19d1205 | 6747 | OP_oRRnpc, /* ARM register, not the PC */ |
5be8be5d | 6748 | OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */ |
b6702015 | 6749 | OP_oRRw, /* ARM register, not r15, optional trailing ! */ |
5287ad62 JB |
6750 | OP_oRND, /* Optional Neon double precision register */ |
6751 | OP_oRNQ, /* Optional Neon quad precision register */ | |
6752 | OP_oRNDQ, /* Optional Neon double or quad precision register */ | |
037e8744 | 6753 | OP_oRNSDQ, /* Optional single, double or quad precision vector register */ |
c19d1205 ZW |
6754 | OP_oSHll, /* LSL immediate */ |
6755 | OP_oSHar, /* ASR immediate */ | |
6756 | OP_oSHllar, /* LSL or ASR immediate */ | |
6757 | OP_oROR, /* ROR 0/8/16/24 */ | |
52e7f43d | 6758 | OP_oBARRIER_I15, /* Option argument for a barrier instruction. */ |
c19d1205 | 6759 | |
5be8be5d DG |
6760 | /* Some pre-defined mixed (ARM/THUMB) operands. */ |
6761 | OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp), | |
6762 | OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp), | |
6763 | OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp), | |
6764 | ||
c19d1205 ZW |
6765 | OP_FIRST_OPTIONAL = OP_oI7b |
6766 | }; | |
a737bd4d | 6767 | |
c19d1205 ZW |
6768 | /* Generic instruction operand parser. This does no encoding and no |
6769 | semantic validation; it merely squirrels values away in the inst | |
6770 | structure. Returns SUCCESS or FAIL depending on whether the | |
6771 | specified grammar matched. */ | |
6772 | static int | |
5be8be5d | 6773 | parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb) |
c19d1205 | 6774 | { |
5be8be5d | 6775 | unsigned const int *upat = pattern; |
c19d1205 ZW |
6776 | char *backtrack_pos = 0; |
6777 | const char *backtrack_error = 0; | |
99aad254 | 6778 | int i, val = 0, backtrack_index = 0; |
5287ad62 | 6779 | enum arm_reg_type rtype; |
4962c51a | 6780 | parse_operand_result result; |
5be8be5d | 6781 | unsigned int op_parse_code; |
efd6b359 | 6782 | bfd_boolean partial_match; |
c19d1205 | 6783 | |
e07e6e58 NC |
6784 | #define po_char_or_fail(chr) \ |
6785 | do \ | |
6786 | { \ | |
6787 | if (skip_past_char (&str, chr) == FAIL) \ | |
477330fc | 6788 | goto bad_args; \ |
e07e6e58 NC |
6789 | } \ |
6790 | while (0) | |
c19d1205 | 6791 | |
e07e6e58 NC |
6792 | #define po_reg_or_fail(regtype) \ |
6793 | do \ | |
dcbf9037 | 6794 | { \ |
e07e6e58 | 6795 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ |
477330fc | 6796 | & inst.operands[i].vectype); \ |
e07e6e58 | 6797 | if (val == FAIL) \ |
477330fc RM |
6798 | { \ |
6799 | first_error (_(reg_expected_msgs[regtype])); \ | |
6800 | goto failure; \ | |
6801 | } \ | |
e07e6e58 NC |
6802 | inst.operands[i].reg = val; \ |
6803 | inst.operands[i].isreg = 1; \ | |
6804 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
6805 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
6806 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
477330fc RM |
6807 | || rtype == REG_TYPE_VFD \ |
6808 | || rtype == REG_TYPE_NQ); \ | |
dcbf9037 | 6809 | } \ |
e07e6e58 NC |
6810 | while (0) |
6811 | ||
6812 | #define po_reg_or_goto(regtype, label) \ | |
6813 | do \ | |
6814 | { \ | |
6815 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ | |
6816 | & inst.operands[i].vectype); \ | |
6817 | if (val == FAIL) \ | |
6818 | goto label; \ | |
dcbf9037 | 6819 | \ |
e07e6e58 NC |
6820 | inst.operands[i].reg = val; \ |
6821 | inst.operands[i].isreg = 1; \ | |
6822 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
6823 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
6824 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
477330fc | 6825 | || rtype == REG_TYPE_VFD \ |
e07e6e58 NC |
6826 | || rtype == REG_TYPE_NQ); \ |
6827 | } \ | |
6828 | while (0) | |
6829 | ||
6830 | #define po_imm_or_fail(min, max, popt) \ | |
6831 | do \ | |
6832 | { \ | |
6833 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
6834 | goto failure; \ | |
6835 | inst.operands[i].imm = val; \ | |
6836 | } \ | |
6837 | while (0) | |
6838 | ||
6839 | #define po_scalar_or_goto(elsz, label) \ | |
6840 | do \ | |
6841 | { \ | |
6842 | val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \ | |
6843 | if (val == FAIL) \ | |
6844 | goto label; \ | |
6845 | inst.operands[i].reg = val; \ | |
6846 | inst.operands[i].isscalar = 1; \ | |
6847 | } \ | |
6848 | while (0) | |
6849 | ||
6850 | #define po_misc_or_fail(expr) \ | |
6851 | do \ | |
6852 | { \ | |
6853 | if (expr) \ | |
6854 | goto failure; \ | |
6855 | } \ | |
6856 | while (0) | |
6857 | ||
6858 | #define po_misc_or_fail_no_backtrack(expr) \ | |
6859 | do \ | |
6860 | { \ | |
6861 | result = expr; \ | |
6862 | if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \ | |
6863 | backtrack_pos = 0; \ | |
6864 | if (result != PARSE_OPERAND_SUCCESS) \ | |
6865 | goto failure; \ | |
6866 | } \ | |
6867 | while (0) | |
4962c51a | 6868 | |
52e7f43d RE |
6869 | #define po_barrier_or_imm(str) \ |
6870 | do \ | |
6871 | { \ | |
6872 | val = parse_barrier (&str); \ | |
ccb84d65 JB |
6873 | if (val == FAIL && ! ISALPHA (*str)) \ |
6874 | goto immediate; \ | |
6875 | if (val == FAIL \ | |
6876 | /* ISB can only take SY as an option. */ \ | |
6877 | || ((inst.instruction & 0xf0) == 0x60 \ | |
6878 | && val != 0xf)) \ | |
52e7f43d | 6879 | { \ |
ccb84d65 JB |
6880 | inst.error = _("invalid barrier type"); \ |
6881 | backtrack_pos = 0; \ | |
6882 | goto failure; \ | |
52e7f43d RE |
6883 | } \ |
6884 | } \ | |
6885 | while (0) | |
6886 | ||
c19d1205 ZW |
6887 | skip_whitespace (str); |
6888 | ||
6889 | for (i = 0; upat[i] != OP_stop; i++) | |
6890 | { | |
5be8be5d DG |
6891 | op_parse_code = upat[i]; |
6892 | if (op_parse_code >= 1<<16) | |
6893 | op_parse_code = thumb ? (op_parse_code >> 16) | |
6894 | : (op_parse_code & ((1<<16)-1)); | |
6895 | ||
6896 | if (op_parse_code >= OP_FIRST_OPTIONAL) | |
c19d1205 ZW |
6897 | { |
6898 | /* Remember where we are in case we need to backtrack. */ | |
9c2799c2 | 6899 | gas_assert (!backtrack_pos); |
c19d1205 ZW |
6900 | backtrack_pos = str; |
6901 | backtrack_error = inst.error; | |
6902 | backtrack_index = i; | |
6903 | } | |
6904 | ||
b6702015 | 6905 | if (i > 0 && (i > 1 || inst.operands[0].present)) |
c19d1205 ZW |
6906 | po_char_or_fail (','); |
6907 | ||
5be8be5d | 6908 | switch (op_parse_code) |
c19d1205 ZW |
6909 | { |
6910 | /* Registers */ | |
6911 | case OP_oRRnpc: | |
5be8be5d | 6912 | case OP_oRRnpcsp: |
c19d1205 | 6913 | case OP_RRnpc: |
5be8be5d | 6914 | case OP_RRnpcsp: |
c19d1205 | 6915 | case OP_oRR: |
60f993ce AV |
6916 | case OP_LR: |
6917 | case OP_oLR: | |
c19d1205 ZW |
6918 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; |
6919 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
6920 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
6921 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
6922 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
6923 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
477330fc | 6924 | case OP_oRND: |
5287ad62 | 6925 | case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break; |
cd2cf30b PB |
6926 | case OP_RVC: |
6927 | po_reg_or_goto (REG_TYPE_VFC, coproc_reg); | |
6928 | break; | |
6929 | /* Also accept generic coprocessor regs for unknown registers. */ | |
6930 | coproc_reg: | |
6931 | po_reg_or_fail (REG_TYPE_CN); | |
6932 | break; | |
c19d1205 ZW |
6933 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; |
6934 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
6935 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
6936 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
6937 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
6938 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
6939 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
6940 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
6941 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
6942 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
477330fc | 6943 | case OP_oRNQ: |
5287ad62 | 6944 | case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break; |
dec41383 | 6945 | case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break; |
477330fc | 6946 | case OP_oRNDQ: |
5287ad62 | 6947 | case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break; |
477330fc RM |
6948 | case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break; |
6949 | case OP_oRNSDQ: | |
6950 | case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break; | |
6951 | ||
6952 | /* Neon scalar. Using an element size of 8 means that some invalid | |
6953 | scalars are accepted here, so deal with those in later code. */ | |
6954 | case OP_RNSC: po_scalar_or_goto (8, failure); break; | |
6955 | ||
6956 | case OP_RNDQ_I0: | |
6957 | { | |
6958 | po_reg_or_goto (REG_TYPE_NDQ, try_imm0); | |
6959 | break; | |
6960 | try_imm0: | |
6961 | po_imm_or_fail (0, 0, TRUE); | |
6962 | } | |
6963 | break; | |
6964 | ||
6965 | case OP_RVSD_I0: | |
6966 | po_reg_or_goto (REG_TYPE_VFSD, try_imm0); | |
6967 | break; | |
6968 | ||
aacf0b33 KT |
6969 | case OP_RSVD_FI0: |
6970 | { | |
6971 | po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0); | |
6972 | break; | |
6973 | try_ifimm0: | |
6974 | if (parse_ifimm_zero (&str)) | |
6975 | inst.operands[i].imm = 0; | |
6976 | else | |
6977 | { | |
6978 | inst.error | |
6979 | = _("only floating point zero is allowed as immediate value"); | |
6980 | goto failure; | |
6981 | } | |
6982 | } | |
6983 | break; | |
6984 | ||
477330fc RM |
6985 | case OP_RR_RNSC: |
6986 | { | |
6987 | po_scalar_or_goto (8, try_rr); | |
6988 | break; | |
6989 | try_rr: | |
6990 | po_reg_or_fail (REG_TYPE_RN); | |
6991 | } | |
6992 | break; | |
6993 | ||
6994 | case OP_RNSDQ_RNSC: | |
6995 | { | |
6996 | po_scalar_or_goto (8, try_nsdq); | |
6997 | break; | |
6998 | try_nsdq: | |
6999 | po_reg_or_fail (REG_TYPE_NSDQ); | |
7000 | } | |
7001 | break; | |
7002 | ||
dec41383 JW |
7003 | case OP_RNSD_RNSC: |
7004 | { | |
7005 | po_scalar_or_goto (8, try_s_scalar); | |
7006 | break; | |
7007 | try_s_scalar: | |
7008 | po_scalar_or_goto (4, try_nsd); | |
7009 | break; | |
7010 | try_nsd: | |
7011 | po_reg_or_fail (REG_TYPE_NSD); | |
7012 | } | |
7013 | break; | |
7014 | ||
477330fc RM |
7015 | case OP_RNDQ_RNSC: |
7016 | { | |
7017 | po_scalar_or_goto (8, try_ndq); | |
7018 | break; | |
7019 | try_ndq: | |
7020 | po_reg_or_fail (REG_TYPE_NDQ); | |
7021 | } | |
7022 | break; | |
7023 | ||
7024 | case OP_RND_RNSC: | |
7025 | { | |
7026 | po_scalar_or_goto (8, try_vfd); | |
7027 | break; | |
7028 | try_vfd: | |
7029 | po_reg_or_fail (REG_TYPE_VFD); | |
7030 | } | |
7031 | break; | |
7032 | ||
7033 | case OP_VMOV: | |
7034 | /* WARNING: parse_neon_mov can move the operand counter, i. If we're | |
7035 | not careful then bad things might happen. */ | |
7036 | po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL); | |
7037 | break; | |
7038 | ||
7039 | case OP_RNDQ_Ibig: | |
7040 | { | |
7041 | po_reg_or_goto (REG_TYPE_NDQ, try_immbig); | |
7042 | break; | |
7043 | try_immbig: | |
7044 | /* There's a possibility of getting a 64-bit immediate here, so | |
7045 | we need special handling. */ | |
8335d6aa JW |
7046 | if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE) |
7047 | == FAIL) | |
477330fc RM |
7048 | { |
7049 | inst.error = _("immediate value is out of range"); | |
7050 | goto failure; | |
7051 | } | |
7052 | } | |
7053 | break; | |
7054 | ||
7055 | case OP_RNDQ_I63b: | |
7056 | { | |
7057 | po_reg_or_goto (REG_TYPE_NDQ, try_shimm); | |
7058 | break; | |
7059 | try_shimm: | |
7060 | po_imm_or_fail (0, 63, TRUE); | |
7061 | } | |
7062 | break; | |
c19d1205 ZW |
7063 | |
7064 | case OP_RRnpcb: | |
7065 | po_char_or_fail ('['); | |
7066 | po_reg_or_fail (REG_TYPE_RN); | |
7067 | po_char_or_fail (']'); | |
7068 | break; | |
a737bd4d | 7069 | |
55881a11 | 7070 | case OP_RRnpctw: |
c19d1205 | 7071 | case OP_RRw: |
b6702015 | 7072 | case OP_oRRw: |
c19d1205 ZW |
7073 | po_reg_or_fail (REG_TYPE_RN); |
7074 | if (skip_past_char (&str, '!') == SUCCESS) | |
7075 | inst.operands[i].writeback = 1; | |
7076 | break; | |
7077 | ||
7078 | /* Immediates */ | |
7079 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
7080 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
7081 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
477330fc | 7082 | case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break; |
c19d1205 ZW |
7083 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; |
7084 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
477330fc | 7085 | case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break; |
c19d1205 | 7086 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; |
477330fc RM |
7087 | case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break; |
7088 | case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break; | |
7089 | case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break; | |
c19d1205 | 7090 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; |
c19d1205 ZW |
7091 | |
7092 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
7093 | case OP_oI7b: | |
7094 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
7095 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
7096 | case OP_oI31b: | |
7097 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
477330fc RM |
7098 | case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break; |
7099 | case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break; | |
c19d1205 ZW |
7100 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; |
7101 | ||
7102 | /* Immediate variants */ | |
7103 | case OP_oI255c: | |
7104 | po_char_or_fail ('{'); | |
7105 | po_imm_or_fail (0, 255, TRUE); | |
7106 | po_char_or_fail ('}'); | |
7107 | break; | |
7108 | ||
7109 | case OP_I31w: | |
7110 | /* The expression parser chokes on a trailing !, so we have | |
7111 | to find it first and zap it. */ | |
7112 | { | |
7113 | char *s = str; | |
7114 | while (*s && *s != ',') | |
7115 | s++; | |
7116 | if (s[-1] == '!') | |
7117 | { | |
7118 | s[-1] = '\0'; | |
7119 | inst.operands[i].writeback = 1; | |
7120 | } | |
7121 | po_imm_or_fail (0, 31, TRUE); | |
7122 | if (str == s - 1) | |
7123 | str = s; | |
7124 | } | |
7125 | break; | |
7126 | ||
7127 | /* Expressions */ | |
7128 | case OP_EXPi: EXPi: | |
e2b0ab59 | 7129 | po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str, |
c19d1205 ZW |
7130 | GE_OPT_PREFIX)); |
7131 | break; | |
7132 | ||
7133 | case OP_EXP: | |
e2b0ab59 | 7134 | po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str, |
c19d1205 ZW |
7135 | GE_NO_PREFIX)); |
7136 | break; | |
7137 | ||
7138 | case OP_EXPr: EXPr: | |
e2b0ab59 | 7139 | po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str, |
c19d1205 | 7140 | GE_NO_PREFIX)); |
e2b0ab59 | 7141 | if (inst.relocs[0].exp.X_op == O_symbol) |
a737bd4d | 7142 | { |
c19d1205 ZW |
7143 | val = parse_reloc (&str); |
7144 | if (val == -1) | |
7145 | { | |
7146 | inst.error = _("unrecognized relocation suffix"); | |
7147 | goto failure; | |
7148 | } | |
7149 | else if (val != BFD_RELOC_UNUSED) | |
7150 | { | |
7151 | inst.operands[i].imm = val; | |
7152 | inst.operands[i].hasreloc = 1; | |
7153 | } | |
a737bd4d | 7154 | } |
c19d1205 | 7155 | break; |
a737bd4d | 7156 | |
e2b0ab59 AV |
7157 | case OP_EXPs: |
7158 | po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str, | |
7159 | GE_NO_PREFIX)); | |
7160 | if (inst.relocs[i].exp.X_op == O_symbol) | |
7161 | { | |
7162 | inst.operands[i].hasreloc = 1; | |
7163 | } | |
7164 | else if (inst.relocs[i].exp.X_op == O_constant) | |
7165 | { | |
7166 | inst.operands[i].imm = inst.relocs[i].exp.X_add_number; | |
7167 | inst.operands[i].hasreloc = 0; | |
7168 | } | |
7169 | break; | |
7170 | ||
b6895b4f PB |
7171 | /* Operand for MOVW or MOVT. */ |
7172 | case OP_HALF: | |
7173 | po_misc_or_fail (parse_half (&str)); | |
7174 | break; | |
7175 | ||
e07e6e58 | 7176 | /* Register or expression. */ |
c19d1205 ZW |
7177 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; |
7178 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 7179 | |
e07e6e58 | 7180 | /* Register or immediate. */ |
c19d1205 ZW |
7181 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; |
7182 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 7183 | |
c19d1205 ZW |
7184 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
7185 | IF: | |
7186 | if (!is_immediate_prefix (*str)) | |
7187 | goto bad_args; | |
7188 | str++; | |
7189 | val = parse_fpa_immediate (&str); | |
7190 | if (val == FAIL) | |
7191 | goto failure; | |
7192 | /* FPA immediates are encoded as registers 8-15. | |
7193 | parse_fpa_immediate has already applied the offset. */ | |
7194 | inst.operands[i].reg = val; | |
7195 | inst.operands[i].isreg = 1; | |
7196 | break; | |
09d92015 | 7197 | |
2d447fca JM |
7198 | case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break; |
7199 | I32z: po_imm_or_fail (0, 32, FALSE); break; | |
7200 | ||
e07e6e58 | 7201 | /* Two kinds of register. */ |
c19d1205 ZW |
7202 | case OP_RIWR_RIWC: |
7203 | { | |
7204 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
97f87066 JM |
7205 | if (!rege |
7206 | || (rege->type != REG_TYPE_MMXWR | |
7207 | && rege->type != REG_TYPE_MMXWC | |
7208 | && rege->type != REG_TYPE_MMXWCG)) | |
c19d1205 ZW |
7209 | { |
7210 | inst.error = _("iWMMXt data or control register expected"); | |
7211 | goto failure; | |
7212 | } | |
7213 | inst.operands[i].reg = rege->number; | |
7214 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
7215 | } | |
7216 | break; | |
09d92015 | 7217 | |
41adaa5c JM |
7218 | case OP_RIWC_RIWG: |
7219 | { | |
7220 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
7221 | if (!rege | |
7222 | || (rege->type != REG_TYPE_MMXWC | |
7223 | && rege->type != REG_TYPE_MMXWCG)) | |
7224 | { | |
7225 | inst.error = _("iWMMXt control register expected"); | |
7226 | goto failure; | |
7227 | } | |
7228 | inst.operands[i].reg = rege->number; | |
7229 | inst.operands[i].isreg = 1; | |
7230 | } | |
7231 | break; | |
7232 | ||
c19d1205 ZW |
7233 | /* Misc */ |
7234 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
7235 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
7236 | case OP_oROR: val = parse_ror (&str); break; | |
c19d1205 | 7237 | case OP_COND: val = parse_cond (&str); break; |
52e7f43d RE |
7238 | case OP_oBARRIER_I15: |
7239 | po_barrier_or_imm (str); break; | |
7240 | immediate: | |
7241 | if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL) | |
477330fc | 7242 | goto failure; |
52e7f43d | 7243 | break; |
c19d1205 | 7244 | |
fa94de6b | 7245 | case OP_wPSR: |
d2cd1205 | 7246 | case OP_rPSR: |
90ec0d68 MGD |
7247 | po_reg_or_goto (REG_TYPE_RNB, try_psr); |
7248 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt)) | |
7249 | { | |
7250 | inst.error = _("Banked registers are not available with this " | |
7251 | "architecture."); | |
7252 | goto failure; | |
7253 | } | |
7254 | break; | |
d2cd1205 JB |
7255 | try_psr: |
7256 | val = parse_psr (&str, op_parse_code == OP_wPSR); | |
7257 | break; | |
037e8744 | 7258 | |
32c36c3c AV |
7259 | case OP_VLDR: |
7260 | po_reg_or_goto (REG_TYPE_VFSD, try_sysreg); | |
7261 | break; | |
7262 | try_sysreg: | |
7263 | val = parse_sys_vldr_vstr (&str); | |
7264 | break; | |
7265 | ||
477330fc RM |
7266 | case OP_APSR_RR: |
7267 | po_reg_or_goto (REG_TYPE_RN, try_apsr); | |
7268 | break; | |
7269 | try_apsr: | |
7270 | /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS | |
7271 | instruction). */ | |
7272 | if (strncasecmp (str, "APSR_", 5) == 0) | |
7273 | { | |
7274 | unsigned found = 0; | |
7275 | str += 5; | |
7276 | while (found < 15) | |
7277 | switch (*str++) | |
7278 | { | |
7279 | case 'c': found = (found & 1) ? 16 : found | 1; break; | |
7280 | case 'n': found = (found & 2) ? 16 : found | 2; break; | |
7281 | case 'z': found = (found & 4) ? 16 : found | 4; break; | |
7282 | case 'v': found = (found & 8) ? 16 : found | 8; break; | |
7283 | default: found = 16; | |
7284 | } | |
7285 | if (found != 15) | |
7286 | goto failure; | |
7287 | inst.operands[i].isvec = 1; | |
f7c21dc7 NC |
7288 | /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */ |
7289 | inst.operands[i].reg = REG_PC; | |
477330fc RM |
7290 | } |
7291 | else | |
7292 | goto failure; | |
7293 | break; | |
037e8744 | 7294 | |
92e90b6e PB |
7295 | case OP_TB: |
7296 | po_misc_or_fail (parse_tb (&str)); | |
7297 | break; | |
7298 | ||
e07e6e58 | 7299 | /* Register lists. */ |
c19d1205 | 7300 | case OP_REGLST: |
4b5a202f | 7301 | val = parse_reg_list (&str, REGLIST_RN); |
c19d1205 ZW |
7302 | if (*str == '^') |
7303 | { | |
5e0d7f77 | 7304 | inst.operands[i].writeback = 1; |
c19d1205 ZW |
7305 | str++; |
7306 | } | |
7307 | break; | |
09d92015 | 7308 | |
4b5a202f AV |
7309 | case OP_CLRMLST: |
7310 | val = parse_reg_list (&str, REGLIST_CLRM); | |
7311 | break; | |
7312 | ||
c19d1205 | 7313 | case OP_VRSLST: |
efd6b359 AV |
7314 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S, |
7315 | &partial_match); | |
c19d1205 | 7316 | break; |
09d92015 | 7317 | |
c19d1205 | 7318 | case OP_VRDLST: |
efd6b359 AV |
7319 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D, |
7320 | &partial_match); | |
c19d1205 | 7321 | break; |
a737bd4d | 7322 | |
477330fc RM |
7323 | case OP_VRSDLST: |
7324 | /* Allow Q registers too. */ | |
7325 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
efd6b359 | 7326 | REGLIST_NEON_D, &partial_match); |
477330fc RM |
7327 | if (val == FAIL) |
7328 | { | |
7329 | inst.error = NULL; | |
7330 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
efd6b359 AV |
7331 | REGLIST_VFP_S, &partial_match); |
7332 | inst.operands[i].issingle = 1; | |
7333 | } | |
7334 | break; | |
7335 | ||
7336 | case OP_VRSDVLST: | |
7337 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
7338 | REGLIST_VFP_D_VPR, &partial_match); | |
7339 | if (val == FAIL && !partial_match) | |
7340 | { | |
7341 | inst.error = NULL; | |
7342 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
7343 | REGLIST_VFP_S_VPR, &partial_match); | |
477330fc RM |
7344 | inst.operands[i].issingle = 1; |
7345 | } | |
7346 | break; | |
7347 | ||
7348 | case OP_NRDLST: | |
7349 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
efd6b359 | 7350 | REGLIST_NEON_D, &partial_match); |
477330fc | 7351 | break; |
5287ad62 JB |
7352 | |
7353 | case OP_NSTRLST: | |
477330fc RM |
7354 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, |
7355 | &inst.operands[i].vectype); | |
7356 | break; | |
5287ad62 | 7357 | |
c19d1205 ZW |
7358 | /* Addressing modes */ |
7359 | case OP_ADDR: | |
7360 | po_misc_or_fail (parse_address (&str, i)); | |
7361 | break; | |
09d92015 | 7362 | |
4962c51a MS |
7363 | case OP_ADDRGLDR: |
7364 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7365 | parse_address_group_reloc (&str, i, GROUP_LDR)); |
4962c51a MS |
7366 | break; |
7367 | ||
7368 | case OP_ADDRGLDRS: | |
7369 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7370 | parse_address_group_reloc (&str, i, GROUP_LDRS)); |
4962c51a MS |
7371 | break; |
7372 | ||
7373 | case OP_ADDRGLDC: | |
7374 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7375 | parse_address_group_reloc (&str, i, GROUP_LDC)); |
4962c51a MS |
7376 | break; |
7377 | ||
c19d1205 ZW |
7378 | case OP_SH: |
7379 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
7380 | break; | |
09d92015 | 7381 | |
4962c51a MS |
7382 | case OP_SHG: |
7383 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7384 | parse_shifter_operand_group_reloc (&str, i)); |
4962c51a MS |
7385 | break; |
7386 | ||
c19d1205 ZW |
7387 | case OP_oSHll: |
7388 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
7389 | break; | |
09d92015 | 7390 | |
c19d1205 ZW |
7391 | case OP_oSHar: |
7392 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
7393 | break; | |
09d92015 | 7394 | |
c19d1205 ZW |
7395 | case OP_oSHllar: |
7396 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
7397 | break; | |
09d92015 | 7398 | |
c19d1205 | 7399 | default: |
5be8be5d | 7400 | as_fatal (_("unhandled operand code %d"), op_parse_code); |
c19d1205 | 7401 | } |
09d92015 | 7402 | |
c19d1205 ZW |
7403 | /* Various value-based sanity checks and shared operations. We |
7404 | do not signal immediate failures for the register constraints; | |
7405 | this allows a syntax error to take precedence. */ | |
5be8be5d | 7406 | switch (op_parse_code) |
c19d1205 ZW |
7407 | { |
7408 | case OP_oRRnpc: | |
7409 | case OP_RRnpc: | |
7410 | case OP_RRnpcb: | |
7411 | case OP_RRw: | |
b6702015 | 7412 | case OP_oRRw: |
c19d1205 ZW |
7413 | case OP_RRnpc_I0: |
7414 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
7415 | inst.error = BAD_PC; | |
7416 | break; | |
09d92015 | 7417 | |
5be8be5d DG |
7418 | case OP_oRRnpcsp: |
7419 | case OP_RRnpcsp: | |
7420 | if (inst.operands[i].isreg) | |
7421 | { | |
7422 | if (inst.operands[i].reg == REG_PC) | |
7423 | inst.error = BAD_PC; | |
5c8ed6a4 JW |
7424 | else if (inst.operands[i].reg == REG_SP |
7425 | /* The restriction on Rd/Rt/Rt2 on Thumb mode has been | |
7426 | relaxed since ARMv8-A. */ | |
7427 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
7428 | { | |
7429 | gas_assert (thumb); | |
7430 | inst.error = BAD_SP; | |
7431 | } | |
5be8be5d DG |
7432 | } |
7433 | break; | |
7434 | ||
55881a11 | 7435 | case OP_RRnpctw: |
fa94de6b RM |
7436 | if (inst.operands[i].isreg |
7437 | && inst.operands[i].reg == REG_PC | |
55881a11 MGD |
7438 | && (inst.operands[i].writeback || thumb)) |
7439 | inst.error = BAD_PC; | |
7440 | break; | |
7441 | ||
32c36c3c AV |
7442 | case OP_VLDR: |
7443 | if (inst.operands[i].isreg) | |
7444 | break; | |
7445 | /* fall through. */ | |
c19d1205 ZW |
7446 | case OP_CPSF: |
7447 | case OP_ENDI: | |
7448 | case OP_oROR: | |
d2cd1205 JB |
7449 | case OP_wPSR: |
7450 | case OP_rPSR: | |
c19d1205 | 7451 | case OP_COND: |
52e7f43d | 7452 | case OP_oBARRIER_I15: |
c19d1205 | 7453 | case OP_REGLST: |
4b5a202f | 7454 | case OP_CLRMLST: |
c19d1205 ZW |
7455 | case OP_VRSLST: |
7456 | case OP_VRDLST: | |
477330fc | 7457 | case OP_VRSDLST: |
efd6b359 | 7458 | case OP_VRSDVLST: |
477330fc RM |
7459 | case OP_NRDLST: |
7460 | case OP_NSTRLST: | |
c19d1205 ZW |
7461 | if (val == FAIL) |
7462 | goto failure; | |
7463 | inst.operands[i].imm = val; | |
7464 | break; | |
a737bd4d | 7465 | |
60f993ce AV |
7466 | case OP_LR: |
7467 | case OP_oLR: | |
7468 | if (inst.operands[i].reg != REG_LR) | |
7469 | inst.error = _("operand must be LR register"); | |
7470 | break; | |
7471 | ||
c19d1205 ZW |
7472 | default: |
7473 | break; | |
7474 | } | |
09d92015 | 7475 | |
c19d1205 ZW |
7476 | /* If we get here, this operand was successfully parsed. */ |
7477 | inst.operands[i].present = 1; | |
7478 | continue; | |
09d92015 | 7479 | |
c19d1205 | 7480 | bad_args: |
09d92015 | 7481 | inst.error = BAD_ARGS; |
c19d1205 ZW |
7482 | |
7483 | failure: | |
7484 | if (!backtrack_pos) | |
d252fdde PB |
7485 | { |
7486 | /* The parse routine should already have set inst.error, but set a | |
5f4273c7 | 7487 | default here just in case. */ |
d252fdde PB |
7488 | if (!inst.error) |
7489 | inst.error = _("syntax error"); | |
7490 | return FAIL; | |
7491 | } | |
c19d1205 ZW |
7492 | |
7493 | /* Do not backtrack over a trailing optional argument that | |
7494 | absorbed some text. We will only fail again, with the | |
7495 | 'garbage following instruction' error message, which is | |
7496 | probably less helpful than the current one. */ | |
7497 | if (backtrack_index == i && backtrack_pos != str | |
7498 | && upat[i+1] == OP_stop) | |
d252fdde PB |
7499 | { |
7500 | if (!inst.error) | |
7501 | inst.error = _("syntax error"); | |
7502 | return FAIL; | |
7503 | } | |
c19d1205 ZW |
7504 | |
7505 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
7506 | str = backtrack_pos; | |
7507 | inst.error = backtrack_error; | |
7508 | inst.operands[backtrack_index].present = 0; | |
7509 | i = backtrack_index; | |
7510 | backtrack_pos = 0; | |
09d92015 | 7511 | } |
09d92015 | 7512 | |
c19d1205 ZW |
7513 | /* Check that we have parsed all the arguments. */ |
7514 | if (*str != '\0' && !inst.error) | |
7515 | inst.error = _("garbage following instruction"); | |
09d92015 | 7516 | |
c19d1205 | 7517 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
7518 | } |
7519 | ||
c19d1205 ZW |
7520 | #undef po_char_or_fail |
7521 | #undef po_reg_or_fail | |
7522 | #undef po_reg_or_goto | |
7523 | #undef po_imm_or_fail | |
5287ad62 | 7524 | #undef po_scalar_or_fail |
52e7f43d | 7525 | #undef po_barrier_or_imm |
e07e6e58 | 7526 | |
c19d1205 | 7527 | /* Shorthand macro for instruction encoding functions issuing errors. */ |
e07e6e58 NC |
7528 | #define constraint(expr, err) \ |
7529 | do \ | |
c19d1205 | 7530 | { \ |
e07e6e58 NC |
7531 | if (expr) \ |
7532 | { \ | |
7533 | inst.error = err; \ | |
7534 | return; \ | |
7535 | } \ | |
c19d1205 | 7536 | } \ |
e07e6e58 | 7537 | while (0) |
c19d1205 | 7538 | |
fdfde340 JM |
7539 | /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2 |
7540 | instructions are unpredictable if these registers are used. This | |
5c8ed6a4 JW |
7541 | is the BadReg predicate in ARM's Thumb-2 documentation. |
7542 | ||
7543 | Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few | |
7544 | places, while the restriction on REG_SP was relaxed since ARMv8-A. */ | |
7545 | #define reject_bad_reg(reg) \ | |
7546 | do \ | |
7547 | if (reg == REG_PC) \ | |
7548 | { \ | |
7549 | inst.error = BAD_PC; \ | |
7550 | return; \ | |
7551 | } \ | |
7552 | else if (reg == REG_SP \ | |
7553 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \ | |
7554 | { \ | |
7555 | inst.error = BAD_SP; \ | |
7556 | return; \ | |
7557 | } \ | |
fdfde340 JM |
7558 | while (0) |
7559 | ||
94206790 MM |
7560 | /* If REG is R13 (the stack pointer), warn that its use is |
7561 | deprecated. */ | |
7562 | #define warn_deprecated_sp(reg) \ | |
7563 | do \ | |
7564 | if (warn_on_deprecated && reg == REG_SP) \ | |
5c3696f8 | 7565 | as_tsktsk (_("use of r13 is deprecated")); \ |
94206790 MM |
7566 | while (0) |
7567 | ||
c19d1205 ZW |
7568 | /* Functions for operand encoding. ARM, then Thumb. */ |
7569 | ||
d840c081 | 7570 | #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31)) |
c19d1205 | 7571 | |
9db2f6b4 RL |
7572 | /* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding. |
7573 | ||
7574 | The only binary encoding difference is the Coprocessor number. Coprocessor | |
7575 | 9 is used for half-precision calculations or conversions. The format of the | |
2b0f3761 | 7576 | instruction is the same as the equivalent Coprocessor 10 instruction that |
9db2f6b4 RL |
7577 | exists for Single-Precision operation. */ |
7578 | ||
7579 | static void | |
7580 | do_scalar_fp16_v82_encode (void) | |
7581 | { | |
7582 | if (inst.cond != COND_ALWAYS) | |
7583 | as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional," | |
7584 | " the behaviour is UNPREDICTABLE")); | |
7585 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16), | |
7586 | _(BAD_FP16)); | |
7587 | ||
7588 | inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900; | |
7589 | mark_feature_used (&arm_ext_fp16); | |
7590 | } | |
7591 | ||
c19d1205 ZW |
7592 | /* If VAL can be encoded in the immediate field of an ARM instruction, |
7593 | return the encoded form. Otherwise, return FAIL. */ | |
7594 | ||
7595 | static unsigned int | |
7596 | encode_arm_immediate (unsigned int val) | |
09d92015 | 7597 | { |
c19d1205 ZW |
7598 | unsigned int a, i; |
7599 | ||
4f1d6205 L |
7600 | if (val <= 0xff) |
7601 | return val; | |
7602 | ||
7603 | for (i = 2; i < 32; i += 2) | |
c19d1205 ZW |
7604 | if ((a = rotate_left (val, i)) <= 0xff) |
7605 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
7606 | ||
7607 | return FAIL; | |
09d92015 MM |
7608 | } |
7609 | ||
c19d1205 ZW |
7610 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
7611 | return the encoded form. Otherwise, return FAIL. */ | |
7612 | static unsigned int | |
7613 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 7614 | { |
c19d1205 | 7615 | unsigned int a, i; |
09d92015 | 7616 | |
9c3c69f2 | 7617 | if (val <= 0xff) |
c19d1205 | 7618 | return val; |
a737bd4d | 7619 | |
9c3c69f2 | 7620 | for (i = 1; i <= 24; i++) |
09d92015 | 7621 | { |
9c3c69f2 PB |
7622 | a = val >> i; |
7623 | if ((val & ~(0xff << i)) == 0) | |
7624 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 7625 | } |
a737bd4d | 7626 | |
c19d1205 ZW |
7627 | a = val & 0xff; |
7628 | if (val == ((a << 16) | a)) | |
7629 | return 0x100 | a; | |
7630 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
7631 | return 0x300 | a; | |
09d92015 | 7632 | |
c19d1205 ZW |
7633 | a = val & 0xff00; |
7634 | if (val == ((a << 16) | a)) | |
7635 | return 0x200 | (a >> 8); | |
a737bd4d | 7636 | |
c19d1205 | 7637 | return FAIL; |
09d92015 | 7638 | } |
5287ad62 | 7639 | /* Encode a VFP SP or DP register number into inst.instruction. */ |
09d92015 MM |
7640 | |
7641 | static void | |
5287ad62 JB |
7642 | encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos) |
7643 | { | |
7644 | if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm) | |
7645 | && reg > 15) | |
7646 | { | |
b1cc4aeb | 7647 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) |
477330fc RM |
7648 | { |
7649 | if (thumb_mode) | |
7650 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
7651 | fpu_vfp_ext_d32); | |
7652 | else | |
7653 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
7654 | fpu_vfp_ext_d32); | |
7655 | } | |
5287ad62 | 7656 | else |
477330fc RM |
7657 | { |
7658 | first_error (_("D register out of range for selected VFP version")); | |
7659 | return; | |
7660 | } | |
5287ad62 JB |
7661 | } |
7662 | ||
c19d1205 | 7663 | switch (pos) |
09d92015 | 7664 | { |
c19d1205 ZW |
7665 | case VFP_REG_Sd: |
7666 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
7667 | break; | |
7668 | ||
7669 | case VFP_REG_Sn: | |
7670 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
7671 | break; | |
7672 | ||
7673 | case VFP_REG_Sm: | |
7674 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
7675 | break; | |
7676 | ||
5287ad62 JB |
7677 | case VFP_REG_Dd: |
7678 | inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22); | |
7679 | break; | |
5f4273c7 | 7680 | |
5287ad62 JB |
7681 | case VFP_REG_Dn: |
7682 | inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7); | |
7683 | break; | |
5f4273c7 | 7684 | |
5287ad62 JB |
7685 | case VFP_REG_Dm: |
7686 | inst.instruction |= (reg & 15) | ((reg >> 4) << 5); | |
7687 | break; | |
7688 | ||
c19d1205 ZW |
7689 | default: |
7690 | abort (); | |
09d92015 | 7691 | } |
09d92015 MM |
7692 | } |
7693 | ||
c19d1205 | 7694 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 7695 | if any, is handled by md_apply_fix. */ |
09d92015 | 7696 | static void |
c19d1205 | 7697 | encode_arm_shift (int i) |
09d92015 | 7698 | { |
008a97ef RL |
7699 | /* register-shifted register. */ |
7700 | if (inst.operands[i].immisreg) | |
7701 | { | |
bf355b69 MR |
7702 | int op_index; |
7703 | for (op_index = 0; op_index <= i; ++op_index) | |
008a97ef | 7704 | { |
5689c942 RL |
7705 | /* Check the operand only when it's presented. In pre-UAL syntax, |
7706 | if the destination register is the same as the first operand, two | |
7707 | register form of the instruction can be used. */ | |
bf355b69 MR |
7708 | if (inst.operands[op_index].present && inst.operands[op_index].isreg |
7709 | && inst.operands[op_index].reg == REG_PC) | |
008a97ef RL |
7710 | as_warn (UNPRED_REG ("r15")); |
7711 | } | |
7712 | ||
7713 | if (inst.operands[i].imm == REG_PC) | |
7714 | as_warn (UNPRED_REG ("r15")); | |
7715 | } | |
7716 | ||
c19d1205 ZW |
7717 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
7718 | inst.instruction |= SHIFT_ROR << 5; | |
7719 | else | |
09d92015 | 7720 | { |
c19d1205 ZW |
7721 | inst.instruction |= inst.operands[i].shift_kind << 5; |
7722 | if (inst.operands[i].immisreg) | |
7723 | { | |
7724 | inst.instruction |= SHIFT_BY_REG; | |
7725 | inst.instruction |= inst.operands[i].imm << 8; | |
7726 | } | |
7727 | else | |
e2b0ab59 | 7728 | inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM; |
09d92015 | 7729 | } |
c19d1205 | 7730 | } |
09d92015 | 7731 | |
c19d1205 ZW |
7732 | static void |
7733 | encode_arm_shifter_operand (int i) | |
7734 | { | |
7735 | if (inst.operands[i].isreg) | |
09d92015 | 7736 | { |
c19d1205 ZW |
7737 | inst.instruction |= inst.operands[i].reg; |
7738 | encode_arm_shift (i); | |
09d92015 | 7739 | } |
c19d1205 | 7740 | else |
a415b1cd JB |
7741 | { |
7742 | inst.instruction |= INST_IMMEDIATE; | |
e2b0ab59 | 7743 | if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE) |
a415b1cd JB |
7744 | inst.instruction |= inst.operands[i].imm; |
7745 | } | |
09d92015 MM |
7746 | } |
7747 | ||
c19d1205 | 7748 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 7749 | static void |
c19d1205 | 7750 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 7751 | { |
2b2f5df9 NC |
7752 | /* PR 14260: |
7753 | Generate an error if the operand is not a register. */ | |
7754 | constraint (!inst.operands[i].isreg, | |
7755 | _("Instruction does not support =N addresses")); | |
7756 | ||
c19d1205 | 7757 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 7758 | |
c19d1205 | 7759 | if (inst.operands[i].preind) |
09d92015 | 7760 | { |
c19d1205 ZW |
7761 | if (is_t) |
7762 | { | |
7763 | inst.error = _("instruction does not accept preindexed addressing"); | |
7764 | return; | |
7765 | } | |
7766 | inst.instruction |= PRE_INDEX; | |
7767 | if (inst.operands[i].writeback) | |
7768 | inst.instruction |= WRITE_BACK; | |
09d92015 | 7769 | |
c19d1205 ZW |
7770 | } |
7771 | else if (inst.operands[i].postind) | |
7772 | { | |
9c2799c2 | 7773 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
7774 | if (is_t) |
7775 | inst.instruction |= WRITE_BACK; | |
7776 | } | |
7777 | else /* unindexed - only for coprocessor */ | |
09d92015 | 7778 | { |
c19d1205 | 7779 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
7780 | return; |
7781 | } | |
7782 | ||
c19d1205 ZW |
7783 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
7784 | && (((inst.instruction & 0x000f0000) >> 16) | |
7785 | == ((inst.instruction & 0x0000f000) >> 12))) | |
7786 | as_warn ((inst.instruction & LOAD_BIT) | |
7787 | ? _("destination register same as write-back base") | |
7788 | : _("source register same as write-back base")); | |
09d92015 MM |
7789 | } |
7790 | ||
c19d1205 ZW |
7791 | /* inst.operands[i] was set up by parse_address. Encode it into an |
7792 | ARM-format mode 2 load or store instruction. If is_t is true, | |
7793 | reject forms that cannot be used with a T instruction (i.e. not | |
7794 | post-indexed). */ | |
a737bd4d | 7795 | static void |
c19d1205 | 7796 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 7797 | { |
5be8be5d DG |
7798 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
7799 | ||
c19d1205 | 7800 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 7801 | |
c19d1205 | 7802 | if (inst.operands[i].immisreg) |
09d92015 | 7803 | { |
5be8be5d DG |
7804 | constraint ((inst.operands[i].imm == REG_PC |
7805 | || (is_pc && inst.operands[i].writeback)), | |
7806 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
7807 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
7808 | inst.instruction |= inst.operands[i].imm; | |
7809 | if (!inst.operands[i].negative) | |
7810 | inst.instruction |= INDEX_UP; | |
7811 | if (inst.operands[i].shifted) | |
7812 | { | |
7813 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
7814 | inst.instruction |= SHIFT_ROR << 5; | |
7815 | else | |
7816 | { | |
7817 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
e2b0ab59 | 7818 | inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM; |
c19d1205 ZW |
7819 | } |
7820 | } | |
09d92015 | 7821 | } |
e2b0ab59 | 7822 | else /* immediate offset in inst.relocs[0] */ |
09d92015 | 7823 | { |
e2b0ab59 | 7824 | if (is_pc && !inst.relocs[0].pc_rel) |
5be8be5d DG |
7825 | { |
7826 | const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0); | |
23a10334 JZ |
7827 | |
7828 | /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt | |
7829 | cannot use PC in addressing. | |
7830 | PC cannot be used in writeback addressing, either. */ | |
7831 | constraint ((is_t || inst.operands[i].writeback), | |
5be8be5d | 7832 | BAD_PC_ADDRESSING); |
23a10334 | 7833 | |
dc5ec521 | 7834 | /* Use of PC in str is deprecated for ARMv7. */ |
23a10334 JZ |
7835 | if (warn_on_deprecated |
7836 | && !is_load | |
7837 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7)) | |
5c3696f8 | 7838 | as_tsktsk (_("use of PC in this instruction is deprecated")); |
5be8be5d DG |
7839 | } |
7840 | ||
e2b0ab59 | 7841 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
26d97720 NS |
7842 | { |
7843 | /* Prefer + for zero encoded value. */ | |
7844 | if (!inst.operands[i].negative) | |
7845 | inst.instruction |= INDEX_UP; | |
e2b0ab59 | 7846 | inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM; |
26d97720 | 7847 | } |
09d92015 | 7848 | } |
09d92015 MM |
7849 | } |
7850 | ||
c19d1205 ZW |
7851 | /* inst.operands[i] was set up by parse_address. Encode it into an |
7852 | ARM-format mode 3 load or store instruction. Reject forms that | |
7853 | cannot be used with such instructions. If is_t is true, reject | |
7854 | forms that cannot be used with a T instruction (i.e. not | |
7855 | post-indexed). */ | |
7856 | static void | |
7857 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 7858 | { |
c19d1205 | 7859 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 7860 | { |
c19d1205 ZW |
7861 | inst.error = _("instruction does not accept scaled register index"); |
7862 | return; | |
09d92015 | 7863 | } |
a737bd4d | 7864 | |
c19d1205 | 7865 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 7866 | |
c19d1205 ZW |
7867 | if (inst.operands[i].immisreg) |
7868 | { | |
5be8be5d | 7869 | constraint ((inst.operands[i].imm == REG_PC |
eb9f3f00 | 7870 | || (is_t && inst.operands[i].reg == REG_PC)), |
5be8be5d | 7871 | BAD_PC_ADDRESSING); |
eb9f3f00 JB |
7872 | constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback, |
7873 | BAD_PC_WRITEBACK); | |
c19d1205 ZW |
7874 | inst.instruction |= inst.operands[i].imm; |
7875 | if (!inst.operands[i].negative) | |
7876 | inst.instruction |= INDEX_UP; | |
7877 | } | |
e2b0ab59 | 7878 | else /* immediate offset in inst.relocs[0] */ |
c19d1205 | 7879 | { |
e2b0ab59 | 7880 | constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel |
5be8be5d DG |
7881 | && inst.operands[i].writeback), |
7882 | BAD_PC_WRITEBACK); | |
c19d1205 | 7883 | inst.instruction |= HWOFFSET_IMM; |
e2b0ab59 | 7884 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
26d97720 NS |
7885 | { |
7886 | /* Prefer + for zero encoded value. */ | |
7887 | if (!inst.operands[i].negative) | |
7888 | inst.instruction |= INDEX_UP; | |
7889 | ||
e2b0ab59 | 7890 | inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8; |
26d97720 | 7891 | } |
c19d1205 | 7892 | } |
a737bd4d NC |
7893 | } |
7894 | ||
8335d6aa JW |
7895 | /* Write immediate bits [7:0] to the following locations: |
7896 | ||
7897 | |28/24|23 19|18 16|15 4|3 0| | |
7898 | | a |x x x x x|b c d|x x x x x x x x x x x x|e f g h| | |
7899 | ||
7900 | This function is used by VMOV/VMVN/VORR/VBIC. */ | |
7901 | ||
7902 | static void | |
7903 | neon_write_immbits (unsigned immbits) | |
7904 | { | |
7905 | inst.instruction |= immbits & 0xf; | |
7906 | inst.instruction |= ((immbits >> 4) & 0x7) << 16; | |
7907 | inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24); | |
7908 | } | |
7909 | ||
7910 | /* Invert low-order SIZE bits of XHI:XLO. */ | |
7911 | ||
7912 | static void | |
7913 | neon_invert_size (unsigned *xlo, unsigned *xhi, int size) | |
7914 | { | |
7915 | unsigned immlo = xlo ? *xlo : 0; | |
7916 | unsigned immhi = xhi ? *xhi : 0; | |
7917 | ||
7918 | switch (size) | |
7919 | { | |
7920 | case 8: | |
7921 | immlo = (~immlo) & 0xff; | |
7922 | break; | |
7923 | ||
7924 | case 16: | |
7925 | immlo = (~immlo) & 0xffff; | |
7926 | break; | |
7927 | ||
7928 | case 64: | |
7929 | immhi = (~immhi) & 0xffffffff; | |
7930 | /* fall through. */ | |
7931 | ||
7932 | case 32: | |
7933 | immlo = (~immlo) & 0xffffffff; | |
7934 | break; | |
7935 | ||
7936 | default: | |
7937 | abort (); | |
7938 | } | |
7939 | ||
7940 | if (xlo) | |
7941 | *xlo = immlo; | |
7942 | ||
7943 | if (xhi) | |
7944 | *xhi = immhi; | |
7945 | } | |
7946 | ||
7947 | /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits | |
7948 | A, B, C, D. */ | |
09d92015 | 7949 | |
c19d1205 | 7950 | static int |
8335d6aa | 7951 | neon_bits_same_in_bytes (unsigned imm) |
09d92015 | 7952 | { |
8335d6aa JW |
7953 | return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff) |
7954 | && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00) | |
7955 | && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000) | |
7956 | && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000); | |
7957 | } | |
a737bd4d | 7958 | |
8335d6aa | 7959 | /* For immediate of above form, return 0bABCD. */ |
09d92015 | 7960 | |
8335d6aa JW |
7961 | static unsigned |
7962 | neon_squash_bits (unsigned imm) | |
7963 | { | |
7964 | return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14) | |
7965 | | ((imm & 0x01000000) >> 21); | |
7966 | } | |
7967 | ||
7968 | /* Compress quarter-float representation to 0b...000 abcdefgh. */ | |
7969 | ||
7970 | static unsigned | |
7971 | neon_qfloat_bits (unsigned imm) | |
7972 | { | |
7973 | return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80); | |
7974 | } | |
7975 | ||
7976 | /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into | |
7977 | the instruction. *OP is passed as the initial value of the op field, and | |
7978 | may be set to a different value depending on the constant (i.e. | |
7979 | "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not | |
7980 | MVN). If the immediate looks like a repeated pattern then also | |
7981 | try smaller element sizes. */ | |
7982 | ||
7983 | static int | |
7984 | neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p, | |
7985 | unsigned *immbits, int *op, int size, | |
7986 | enum neon_el_type type) | |
7987 | { | |
7988 | /* Only permit float immediates (including 0.0/-0.0) if the operand type is | |
7989 | float. */ | |
7990 | if (type == NT_float && !float_p) | |
7991 | return FAIL; | |
7992 | ||
7993 | if (type == NT_float && is_quarter_float (immlo) && immhi == 0) | |
09d92015 | 7994 | { |
8335d6aa JW |
7995 | if (size != 32 || *op == 1) |
7996 | return FAIL; | |
7997 | *immbits = neon_qfloat_bits (immlo); | |
7998 | return 0xf; | |
7999 | } | |
8000 | ||
8001 | if (size == 64) | |
8002 | { | |
8003 | if (neon_bits_same_in_bytes (immhi) | |
8004 | && neon_bits_same_in_bytes (immlo)) | |
c19d1205 | 8005 | { |
8335d6aa JW |
8006 | if (*op == 1) |
8007 | return FAIL; | |
8008 | *immbits = (neon_squash_bits (immhi) << 4) | |
8009 | | neon_squash_bits (immlo); | |
8010 | *op = 1; | |
8011 | return 0xe; | |
c19d1205 | 8012 | } |
a737bd4d | 8013 | |
8335d6aa JW |
8014 | if (immhi != immlo) |
8015 | return FAIL; | |
8016 | } | |
a737bd4d | 8017 | |
8335d6aa | 8018 | if (size >= 32) |
09d92015 | 8019 | { |
8335d6aa | 8020 | if (immlo == (immlo & 0x000000ff)) |
c19d1205 | 8021 | { |
8335d6aa JW |
8022 | *immbits = immlo; |
8023 | return 0x0; | |
c19d1205 | 8024 | } |
8335d6aa | 8025 | else if (immlo == (immlo & 0x0000ff00)) |
c19d1205 | 8026 | { |
8335d6aa JW |
8027 | *immbits = immlo >> 8; |
8028 | return 0x2; | |
c19d1205 | 8029 | } |
8335d6aa JW |
8030 | else if (immlo == (immlo & 0x00ff0000)) |
8031 | { | |
8032 | *immbits = immlo >> 16; | |
8033 | return 0x4; | |
8034 | } | |
8035 | else if (immlo == (immlo & 0xff000000)) | |
8036 | { | |
8037 | *immbits = immlo >> 24; | |
8038 | return 0x6; | |
8039 | } | |
8040 | else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff)) | |
8041 | { | |
8042 | *immbits = (immlo >> 8) & 0xff; | |
8043 | return 0xc; | |
8044 | } | |
8045 | else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff)) | |
8046 | { | |
8047 | *immbits = (immlo >> 16) & 0xff; | |
8048 | return 0xd; | |
8049 | } | |
8050 | ||
8051 | if ((immlo & 0xffff) != (immlo >> 16)) | |
8052 | return FAIL; | |
8053 | immlo &= 0xffff; | |
09d92015 | 8054 | } |
a737bd4d | 8055 | |
8335d6aa | 8056 | if (size >= 16) |
4962c51a | 8057 | { |
8335d6aa JW |
8058 | if (immlo == (immlo & 0x000000ff)) |
8059 | { | |
8060 | *immbits = immlo; | |
8061 | return 0x8; | |
8062 | } | |
8063 | else if (immlo == (immlo & 0x0000ff00)) | |
8064 | { | |
8065 | *immbits = immlo >> 8; | |
8066 | return 0xa; | |
8067 | } | |
8068 | ||
8069 | if ((immlo & 0xff) != (immlo >> 8)) | |
8070 | return FAIL; | |
8071 | immlo &= 0xff; | |
4962c51a MS |
8072 | } |
8073 | ||
8335d6aa JW |
8074 | if (immlo == (immlo & 0x000000ff)) |
8075 | { | |
8076 | /* Don't allow MVN with 8-bit immediate. */ | |
8077 | if (*op == 1) | |
8078 | return FAIL; | |
8079 | *immbits = immlo; | |
8080 | return 0xe; | |
8081 | } | |
26d97720 | 8082 | |
8335d6aa | 8083 | return FAIL; |
c19d1205 | 8084 | } |
a737bd4d | 8085 | |
5fc177c8 | 8086 | #if defined BFD_HOST_64_BIT |
ba592044 AM |
8087 | /* Returns TRUE if double precision value V may be cast |
8088 | to single precision without loss of accuracy. */ | |
8089 | ||
8090 | static bfd_boolean | |
5fc177c8 | 8091 | is_double_a_single (bfd_int64_t v) |
ba592044 | 8092 | { |
5fc177c8 | 8093 | int exp = (int)((v >> 52) & 0x7FF); |
8fe3f3d6 | 8094 | bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL); |
ba592044 AM |
8095 | |
8096 | return (exp == 0 || exp == 0x7FF | |
8097 | || (exp >= 1023 - 126 && exp <= 1023 + 127)) | |
8098 | && (mantissa & 0x1FFFFFFFl) == 0; | |
8099 | } | |
8100 | ||
3739860c | 8101 | /* Returns a double precision value casted to single precision |
ba592044 AM |
8102 | (ignoring the least significant bits in exponent and mantissa). */ |
8103 | ||
8104 | static int | |
5fc177c8 | 8105 | double_to_single (bfd_int64_t v) |
ba592044 AM |
8106 | { |
8107 | int sign = (int) ((v >> 63) & 1l); | |
5fc177c8 | 8108 | int exp = (int) ((v >> 52) & 0x7FF); |
8fe3f3d6 | 8109 | bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL); |
ba592044 AM |
8110 | |
8111 | if (exp == 0x7FF) | |
8112 | exp = 0xFF; | |
8113 | else | |
8114 | { | |
8115 | exp = exp - 1023 + 127; | |
8116 | if (exp >= 0xFF) | |
8117 | { | |
8118 | /* Infinity. */ | |
8119 | exp = 0x7F; | |
8120 | mantissa = 0; | |
8121 | } | |
8122 | else if (exp < 0) | |
8123 | { | |
8124 | /* No denormalized numbers. */ | |
8125 | exp = 0; | |
8126 | mantissa = 0; | |
8127 | } | |
8128 | } | |
8129 | mantissa >>= 29; | |
8130 | return (sign << 31) | (exp << 23) | mantissa; | |
8131 | } | |
5fc177c8 | 8132 | #endif /* BFD_HOST_64_BIT */ |
ba592044 | 8133 | |
8335d6aa JW |
8134 | enum lit_type |
8135 | { | |
8136 | CONST_THUMB, | |
8137 | CONST_ARM, | |
8138 | CONST_VEC | |
8139 | }; | |
8140 | ||
ba592044 AM |
8141 | static void do_vfp_nsyn_opcode (const char *); |
8142 | ||
e2b0ab59 | 8143 | /* inst.relocs[0].exp describes an "=expr" load pseudo-operation. |
c19d1205 ZW |
8144 | Determine whether it can be performed with a move instruction; if |
8145 | it can, convert inst.instruction to that move instruction and | |
c921be7d NC |
8146 | return TRUE; if it can't, convert inst.instruction to a literal-pool |
8147 | load and return FALSE. If this is not a valid thing to do in the | |
8148 | current context, set inst.error and return TRUE. | |
a737bd4d | 8149 | |
c19d1205 ZW |
8150 | inst.operands[i] describes the destination register. */ |
8151 | ||
c921be7d | 8152 | static bfd_boolean |
8335d6aa | 8153 | move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3) |
c19d1205 | 8154 | { |
53365c0d | 8155 | unsigned long tbit; |
8335d6aa JW |
8156 | bfd_boolean thumb_p = (t == CONST_THUMB); |
8157 | bfd_boolean arm_p = (t == CONST_ARM); | |
53365c0d PB |
8158 | |
8159 | if (thumb_p) | |
8160 | tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT; | |
8161 | else | |
8162 | tbit = LOAD_BIT; | |
8163 | ||
8164 | if ((inst.instruction & tbit) == 0) | |
09d92015 | 8165 | { |
c19d1205 | 8166 | inst.error = _("invalid pseudo operation"); |
c921be7d | 8167 | return TRUE; |
09d92015 | 8168 | } |
ba592044 | 8169 | |
e2b0ab59 AV |
8170 | if (inst.relocs[0].exp.X_op != O_constant |
8171 | && inst.relocs[0].exp.X_op != O_symbol | |
8172 | && inst.relocs[0].exp.X_op != O_big) | |
09d92015 MM |
8173 | { |
8174 | inst.error = _("constant expression expected"); | |
c921be7d | 8175 | return TRUE; |
09d92015 | 8176 | } |
ba592044 | 8177 | |
e2b0ab59 AV |
8178 | if (inst.relocs[0].exp.X_op == O_constant |
8179 | || inst.relocs[0].exp.X_op == O_big) | |
8335d6aa | 8180 | { |
5fc177c8 NC |
8181 | #if defined BFD_HOST_64_BIT |
8182 | bfd_int64_t v; | |
8183 | #else | |
ba592044 | 8184 | offsetT v; |
5fc177c8 | 8185 | #endif |
e2b0ab59 | 8186 | if (inst.relocs[0].exp.X_op == O_big) |
8335d6aa | 8187 | { |
ba592044 AM |
8188 | LITTLENUM_TYPE w[X_PRECISION]; |
8189 | LITTLENUM_TYPE * l; | |
8190 | ||
e2b0ab59 | 8191 | if (inst.relocs[0].exp.X_add_number == -1) |
8335d6aa | 8192 | { |
ba592044 AM |
8193 | gen_to_words (w, X_PRECISION, E_PRECISION); |
8194 | l = w; | |
8195 | /* FIXME: Should we check words w[2..5] ? */ | |
8335d6aa | 8196 | } |
ba592044 AM |
8197 | else |
8198 | l = generic_bignum; | |
3739860c | 8199 | |
5fc177c8 NC |
8200 | #if defined BFD_HOST_64_BIT |
8201 | v = | |
8202 | ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK) | |
8203 | << LITTLENUM_NUMBER_OF_BITS) | |
8204 | | ((bfd_int64_t) l[2] & LITTLENUM_MASK)) | |
8205 | << LITTLENUM_NUMBER_OF_BITS) | |
8206 | | ((bfd_int64_t) l[1] & LITTLENUM_MASK)) | |
8207 | << LITTLENUM_NUMBER_OF_BITS) | |
8208 | | ((bfd_int64_t) l[0] & LITTLENUM_MASK)); | |
8209 | #else | |
ba592044 AM |
8210 | v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS) |
8211 | | (l[0] & LITTLENUM_MASK); | |
5fc177c8 | 8212 | #endif |
8335d6aa | 8213 | } |
ba592044 | 8214 | else |
e2b0ab59 | 8215 | v = inst.relocs[0].exp.X_add_number; |
ba592044 AM |
8216 | |
8217 | if (!inst.operands[i].issingle) | |
8335d6aa | 8218 | { |
12569877 | 8219 | if (thumb_p) |
8335d6aa | 8220 | { |
53445554 TP |
8221 | /* LDR should not use lead in a flag-setting instruction being |
8222 | chosen so we do not check whether movs can be used. */ | |
12569877 | 8223 | |
53445554 | 8224 | if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2) |
ff8646ee | 8225 | || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)) |
53445554 TP |
8226 | && inst.operands[i].reg != 13 |
8227 | && inst.operands[i].reg != 15) | |
12569877 | 8228 | { |
fc289b0a TP |
8229 | /* Check if on thumb2 it can be done with a mov.w, mvn or |
8230 | movw instruction. */ | |
12569877 AM |
8231 | unsigned int newimm; |
8232 | bfd_boolean isNegated; | |
8233 | ||
8234 | newimm = encode_thumb32_immediate (v); | |
8235 | if (newimm != (unsigned int) FAIL) | |
8236 | isNegated = FALSE; | |
8237 | else | |
8238 | { | |
582cfe03 | 8239 | newimm = encode_thumb32_immediate (~v); |
12569877 AM |
8240 | if (newimm != (unsigned int) FAIL) |
8241 | isNegated = TRUE; | |
8242 | } | |
8243 | ||
fc289b0a TP |
8244 | /* The number can be loaded with a mov.w or mvn |
8245 | instruction. */ | |
ff8646ee TP |
8246 | if (newimm != (unsigned int) FAIL |
8247 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) | |
12569877 | 8248 | { |
fc289b0a | 8249 | inst.instruction = (0xf04f0000 /* MOV.W. */ |
582cfe03 | 8250 | | (inst.operands[i].reg << 8)); |
fc289b0a | 8251 | /* Change to MOVN. */ |
582cfe03 | 8252 | inst.instruction |= (isNegated ? 0x200000 : 0); |
12569877 AM |
8253 | inst.instruction |= (newimm & 0x800) << 15; |
8254 | inst.instruction |= (newimm & 0x700) << 4; | |
8255 | inst.instruction |= (newimm & 0x0ff); | |
8256 | return TRUE; | |
8257 | } | |
fc289b0a | 8258 | /* The number can be loaded with a movw instruction. */ |
ff8646ee TP |
8259 | else if ((v & ~0xFFFF) == 0 |
8260 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)) | |
3739860c | 8261 | { |
582cfe03 | 8262 | int imm = v & 0xFFFF; |
12569877 | 8263 | |
582cfe03 | 8264 | inst.instruction = 0xf2400000; /* MOVW. */ |
12569877 AM |
8265 | inst.instruction |= (inst.operands[i].reg << 8); |
8266 | inst.instruction |= (imm & 0xf000) << 4; | |
8267 | inst.instruction |= (imm & 0x0800) << 15; | |
8268 | inst.instruction |= (imm & 0x0700) << 4; | |
8269 | inst.instruction |= (imm & 0x00ff); | |
8270 | return TRUE; | |
8271 | } | |
8272 | } | |
8335d6aa | 8273 | } |
12569877 | 8274 | else if (arm_p) |
ba592044 AM |
8275 | { |
8276 | int value = encode_arm_immediate (v); | |
12569877 | 8277 | |
ba592044 AM |
8278 | if (value != FAIL) |
8279 | { | |
8280 | /* This can be done with a mov instruction. */ | |
8281 | inst.instruction &= LITERAL_MASK; | |
8282 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
8283 | inst.instruction |= value & 0xfff; | |
8284 | return TRUE; | |
8285 | } | |
8335d6aa | 8286 | |
ba592044 AM |
8287 | value = encode_arm_immediate (~ v); |
8288 | if (value != FAIL) | |
8289 | { | |
8290 | /* This can be done with a mvn instruction. */ | |
8291 | inst.instruction &= LITERAL_MASK; | |
8292 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
8293 | inst.instruction |= value & 0xfff; | |
8294 | return TRUE; | |
8295 | } | |
8296 | } | |
934c2632 | 8297 | else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)) |
8335d6aa | 8298 | { |
ba592044 AM |
8299 | int op = 0; |
8300 | unsigned immbits = 0; | |
8301 | unsigned immlo = inst.operands[1].imm; | |
8302 | unsigned immhi = inst.operands[1].regisimm | |
8303 | ? inst.operands[1].reg | |
e2b0ab59 | 8304 | : inst.relocs[0].exp.X_unsigned |
ba592044 AM |
8305 | ? 0 |
8306 | : ((bfd_int64_t)((int) immlo)) >> 32; | |
8307 | int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits, | |
8308 | &op, 64, NT_invtype); | |
8309 | ||
8310 | if (cmode == FAIL) | |
8311 | { | |
8312 | neon_invert_size (&immlo, &immhi, 64); | |
8313 | op = !op; | |
8314 | cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits, | |
8315 | &op, 64, NT_invtype); | |
8316 | } | |
8317 | ||
8318 | if (cmode != FAIL) | |
8319 | { | |
8320 | inst.instruction = (inst.instruction & VLDR_VMOV_SAME) | |
8321 | | (1 << 23) | |
8322 | | (cmode << 8) | |
8323 | | (op << 5) | |
8324 | | (1 << 4); | |
8325 | ||
8326 | /* Fill other bits in vmov encoding for both thumb and arm. */ | |
8327 | if (thumb_mode) | |
eff0bc54 | 8328 | inst.instruction |= (0x7U << 29) | (0xF << 24); |
ba592044 | 8329 | else |
eff0bc54 | 8330 | inst.instruction |= (0xFU << 28) | (0x1 << 25); |
ba592044 AM |
8331 | neon_write_immbits (immbits); |
8332 | return TRUE; | |
8333 | } | |
8335d6aa JW |
8334 | } |
8335 | } | |
8335d6aa | 8336 | |
ba592044 AM |
8337 | if (t == CONST_VEC) |
8338 | { | |
8339 | /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */ | |
8340 | if (inst.operands[i].issingle | |
8341 | && is_quarter_float (inst.operands[1].imm) | |
8342 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd)) | |
8335d6aa | 8343 | { |
ba592044 AM |
8344 | inst.operands[1].imm = |
8345 | neon_qfloat_bits (v); | |
8346 | do_vfp_nsyn_opcode ("fconsts"); | |
8347 | return TRUE; | |
8335d6aa | 8348 | } |
5fc177c8 NC |
8349 | |
8350 | /* If our host does not support a 64-bit type then we cannot perform | |
8351 | the following optimization. This mean that there will be a | |
8352 | discrepancy between the output produced by an assembler built for | |
8353 | a 32-bit-only host and the output produced from a 64-bit host, but | |
8354 | this cannot be helped. */ | |
8355 | #if defined BFD_HOST_64_BIT | |
ba592044 AM |
8356 | else if (!inst.operands[1].issingle |
8357 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3)) | |
8335d6aa | 8358 | { |
ba592044 AM |
8359 | if (is_double_a_single (v) |
8360 | && is_quarter_float (double_to_single (v))) | |
8361 | { | |
8362 | inst.operands[1].imm = | |
8363 | neon_qfloat_bits (double_to_single (v)); | |
8364 | do_vfp_nsyn_opcode ("fconstd"); | |
8365 | return TRUE; | |
8366 | } | |
8335d6aa | 8367 | } |
5fc177c8 | 8368 | #endif |
8335d6aa JW |
8369 | } |
8370 | } | |
8371 | ||
8372 | if (add_to_lit_pool ((!inst.operands[i].isvec | |
8373 | || inst.operands[i].issingle) ? 4 : 8) == FAIL) | |
8374 | return TRUE; | |
8375 | ||
8376 | inst.operands[1].reg = REG_PC; | |
8377 | inst.operands[1].isreg = 1; | |
8378 | inst.operands[1].preind = 1; | |
e2b0ab59 AV |
8379 | inst.relocs[0].pc_rel = 1; |
8380 | inst.relocs[0].type = (thumb_p | |
8335d6aa JW |
8381 | ? BFD_RELOC_ARM_THUMB_OFFSET |
8382 | : (mode_3 | |
8383 | ? BFD_RELOC_ARM_HWLITERAL | |
8384 | : BFD_RELOC_ARM_LITERAL)); | |
8385 | return FALSE; | |
8386 | } | |
8387 | ||
8388 | /* inst.operands[i] was set up by parse_address. Encode it into an | |
8389 | ARM-format instruction. Reject all forms which cannot be encoded | |
8390 | into a coprocessor load/store instruction. If wb_ok is false, | |
8391 | reject use of writeback; if unind_ok is false, reject use of | |
8392 | unindexed addressing. If reloc_override is not 0, use it instead | |
8393 | of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one | |
8394 | (in which case it is preserved). */ | |
8395 | ||
8396 | static int | |
8397 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
8398 | { | |
8399 | if (!inst.operands[i].isreg) | |
8400 | { | |
99b2a2dd NC |
8401 | /* PR 18256 */ |
8402 | if (! inst.operands[0].isvec) | |
8403 | { | |
8404 | inst.error = _("invalid co-processor operand"); | |
8405 | return FAIL; | |
8406 | } | |
8335d6aa JW |
8407 | if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE)) |
8408 | return SUCCESS; | |
8409 | } | |
8410 | ||
8411 | inst.instruction |= inst.operands[i].reg << 16; | |
8412 | ||
8413 | gas_assert (!(inst.operands[i].preind && inst.operands[i].postind)); | |
8414 | ||
8415 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ | |
8416 | { | |
8417 | gas_assert (!inst.operands[i].writeback); | |
8418 | if (!unind_ok) | |
8419 | { | |
8420 | inst.error = _("instruction does not support unindexed addressing"); | |
8421 | return FAIL; | |
8422 | } | |
8423 | inst.instruction |= inst.operands[i].imm; | |
8424 | inst.instruction |= INDEX_UP; | |
8425 | return SUCCESS; | |
8426 | } | |
8427 | ||
8428 | if (inst.operands[i].preind) | |
8429 | inst.instruction |= PRE_INDEX; | |
8430 | ||
8431 | if (inst.operands[i].writeback) | |
09d92015 | 8432 | { |
8335d6aa | 8433 | if (inst.operands[i].reg == REG_PC) |
c19d1205 | 8434 | { |
8335d6aa JW |
8435 | inst.error = _("pc may not be used with write-back"); |
8436 | return FAIL; | |
c19d1205 | 8437 | } |
8335d6aa | 8438 | if (!wb_ok) |
c19d1205 | 8439 | { |
8335d6aa JW |
8440 | inst.error = _("instruction does not support writeback"); |
8441 | return FAIL; | |
c19d1205 | 8442 | } |
8335d6aa | 8443 | inst.instruction |= WRITE_BACK; |
09d92015 MM |
8444 | } |
8445 | ||
8335d6aa | 8446 | if (reloc_override) |
e2b0ab59 AV |
8447 | inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override; |
8448 | else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC | |
8449 | || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2) | |
8450 | && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0) | |
c19d1205 | 8451 | { |
8335d6aa | 8452 | if (thumb_mode) |
e2b0ab59 | 8453 | inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM; |
8335d6aa | 8454 | else |
e2b0ab59 | 8455 | inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM; |
c19d1205 | 8456 | } |
8335d6aa JW |
8457 | |
8458 | /* Prefer + for zero encoded value. */ | |
8459 | if (!inst.operands[i].negative) | |
8460 | inst.instruction |= INDEX_UP; | |
8461 | ||
8462 | return SUCCESS; | |
09d92015 MM |
8463 | } |
8464 | ||
5f4273c7 | 8465 | /* Functions for instruction encoding, sorted by sub-architecture. |
c19d1205 ZW |
8466 | First some generics; their names are taken from the conventional |
8467 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 8468 | |
a737bd4d | 8469 | static void |
c19d1205 | 8470 | do_noargs (void) |
09d92015 | 8471 | { |
c19d1205 | 8472 | } |
a737bd4d | 8473 | |
c19d1205 ZW |
8474 | static void |
8475 | do_rd (void) | |
8476 | { | |
8477 | inst.instruction |= inst.operands[0].reg << 12; | |
8478 | } | |
a737bd4d | 8479 | |
16a1fa25 TP |
8480 | static void |
8481 | do_rn (void) | |
8482 | { | |
8483 | inst.instruction |= inst.operands[0].reg << 16; | |
8484 | } | |
8485 | ||
c19d1205 ZW |
8486 | static void |
8487 | do_rd_rm (void) | |
8488 | { | |
8489 | inst.instruction |= inst.operands[0].reg << 12; | |
8490 | inst.instruction |= inst.operands[1].reg; | |
8491 | } | |
09d92015 | 8492 | |
9eb6c0f1 MGD |
8493 | static void |
8494 | do_rm_rn (void) | |
8495 | { | |
8496 | inst.instruction |= inst.operands[0].reg; | |
8497 | inst.instruction |= inst.operands[1].reg << 16; | |
8498 | } | |
8499 | ||
c19d1205 ZW |
8500 | static void |
8501 | do_rd_rn (void) | |
8502 | { | |
8503 | inst.instruction |= inst.operands[0].reg << 12; | |
8504 | inst.instruction |= inst.operands[1].reg << 16; | |
8505 | } | |
a737bd4d | 8506 | |
c19d1205 ZW |
8507 | static void |
8508 | do_rn_rd (void) | |
8509 | { | |
8510 | inst.instruction |= inst.operands[0].reg << 16; | |
8511 | inst.instruction |= inst.operands[1].reg << 12; | |
8512 | } | |
09d92015 | 8513 | |
4ed7ed8d TP |
8514 | static void |
8515 | do_tt (void) | |
8516 | { | |
8517 | inst.instruction |= inst.operands[0].reg << 8; | |
8518 | inst.instruction |= inst.operands[1].reg << 16; | |
8519 | } | |
8520 | ||
59d09be6 MGD |
8521 | static bfd_boolean |
8522 | check_obsolete (const arm_feature_set *feature, const char *msg) | |
8523 | { | |
8524 | if (ARM_CPU_IS_ANY (cpu_variant)) | |
8525 | { | |
5c3696f8 | 8526 | as_tsktsk ("%s", msg); |
59d09be6 MGD |
8527 | return TRUE; |
8528 | } | |
8529 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) | |
8530 | { | |
8531 | as_bad ("%s", msg); | |
8532 | return TRUE; | |
8533 | } | |
8534 | ||
8535 | return FALSE; | |
8536 | } | |
8537 | ||
c19d1205 ZW |
8538 | static void |
8539 | do_rd_rm_rn (void) | |
8540 | { | |
9a64e435 | 8541 | unsigned Rn = inst.operands[2].reg; |
708587a4 | 8542 | /* Enforce restrictions on SWP instruction. */ |
9a64e435 | 8543 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) |
56adecf4 DG |
8544 | { |
8545 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
8546 | _("Rn must not overlap other operands")); | |
8547 | ||
59d09be6 MGD |
8548 | /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7. |
8549 | */ | |
8550 | if (!check_obsolete (&arm_ext_v8, | |
8551 | _("swp{b} use is obsoleted for ARMv8 and later")) | |
8552 | && warn_on_deprecated | |
8553 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6)) | |
5c3696f8 | 8554 | as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7")); |
56adecf4 | 8555 | } |
59d09be6 | 8556 | |
c19d1205 ZW |
8557 | inst.instruction |= inst.operands[0].reg << 12; |
8558 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 8559 | inst.instruction |= Rn << 16; |
c19d1205 | 8560 | } |
09d92015 | 8561 | |
c19d1205 ZW |
8562 | static void |
8563 | do_rd_rn_rm (void) | |
8564 | { | |
8565 | inst.instruction |= inst.operands[0].reg << 12; | |
8566 | inst.instruction |= inst.operands[1].reg << 16; | |
8567 | inst.instruction |= inst.operands[2].reg; | |
8568 | } | |
a737bd4d | 8569 | |
c19d1205 ZW |
8570 | static void |
8571 | do_rm_rd_rn (void) | |
8572 | { | |
5be8be5d | 8573 | constraint ((inst.operands[2].reg == REG_PC), BAD_PC); |
e2b0ab59 AV |
8574 | constraint (((inst.relocs[0].exp.X_op != O_constant |
8575 | && inst.relocs[0].exp.X_op != O_illegal) | |
8576 | || inst.relocs[0].exp.X_add_number != 0), | |
5be8be5d | 8577 | BAD_ADDR_MODE); |
c19d1205 ZW |
8578 | inst.instruction |= inst.operands[0].reg; |
8579 | inst.instruction |= inst.operands[1].reg << 12; | |
8580 | inst.instruction |= inst.operands[2].reg << 16; | |
8581 | } | |
09d92015 | 8582 | |
c19d1205 ZW |
8583 | static void |
8584 | do_imm0 (void) | |
8585 | { | |
8586 | inst.instruction |= inst.operands[0].imm; | |
8587 | } | |
09d92015 | 8588 | |
c19d1205 ZW |
8589 | static void |
8590 | do_rd_cpaddr (void) | |
8591 | { | |
8592 | inst.instruction |= inst.operands[0].reg << 12; | |
8593 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 8594 | } |
a737bd4d | 8595 | |
c19d1205 ZW |
8596 | /* ARM instructions, in alphabetical order by function name (except |
8597 | that wrapper functions appear immediately after the function they | |
8598 | wrap). */ | |
09d92015 | 8599 | |
c19d1205 ZW |
8600 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
8601 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
8602 | |
8603 | static void | |
c19d1205 | 8604 | do_adr (void) |
09d92015 | 8605 | { |
c19d1205 | 8606 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 8607 | |
c19d1205 ZW |
8608 | /* Frag hacking will turn this into a sub instruction if the offset turns |
8609 | out to be negative. */ | |
e2b0ab59 AV |
8610 | inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE; |
8611 | inst.relocs[0].pc_rel = 1; | |
8612 | inst.relocs[0].exp.X_add_number -= 8; | |
52a86f84 | 8613 | |
fc6141f0 | 8614 | if (support_interwork |
e2b0ab59 AV |
8615 | && inst.relocs[0].exp.X_op == O_symbol |
8616 | && inst.relocs[0].exp.X_add_symbol != NULL | |
8617 | && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol) | |
8618 | && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol)) | |
8619 | inst.relocs[0].exp.X_add_number |= 1; | |
c19d1205 | 8620 | } |
b99bd4ef | 8621 | |
c19d1205 ZW |
8622 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
8623 | into a relative address of the form: | |
8624 | add rd, pc, #low(label-.-8)" | |
8625 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 8626 | |
c19d1205 ZW |
8627 | static void |
8628 | do_adrl (void) | |
8629 | { | |
8630 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 8631 | |
c19d1205 ZW |
8632 | /* Frag hacking will turn this into a sub instruction if the offset turns |
8633 | out to be negative. */ | |
e2b0ab59 AV |
8634 | inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE; |
8635 | inst.relocs[0].pc_rel = 1; | |
c19d1205 | 8636 | inst.size = INSN_SIZE * 2; |
e2b0ab59 | 8637 | inst.relocs[0].exp.X_add_number -= 8; |
52a86f84 | 8638 | |
fc6141f0 | 8639 | if (support_interwork |
e2b0ab59 AV |
8640 | && inst.relocs[0].exp.X_op == O_symbol |
8641 | && inst.relocs[0].exp.X_add_symbol != NULL | |
8642 | && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol) | |
8643 | && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol)) | |
8644 | inst.relocs[0].exp.X_add_number |= 1; | |
b99bd4ef NC |
8645 | } |
8646 | ||
b99bd4ef | 8647 | static void |
c19d1205 | 8648 | do_arit (void) |
b99bd4ef | 8649 | { |
e2b0ab59 AV |
8650 | constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
8651 | && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC , | |
a9f02af8 | 8652 | THUMB1_RELOC_ONLY); |
c19d1205 ZW |
8653 | if (!inst.operands[1].present) |
8654 | inst.operands[1].reg = inst.operands[0].reg; | |
8655 | inst.instruction |= inst.operands[0].reg << 12; | |
8656 | inst.instruction |= inst.operands[1].reg << 16; | |
8657 | encode_arm_shifter_operand (2); | |
8658 | } | |
b99bd4ef | 8659 | |
62b3e311 PB |
8660 | static void |
8661 | do_barrier (void) | |
8662 | { | |
8663 | if (inst.operands[0].present) | |
ccb84d65 | 8664 | inst.instruction |= inst.operands[0].imm; |
62b3e311 PB |
8665 | else |
8666 | inst.instruction |= 0xf; | |
8667 | } | |
8668 | ||
c19d1205 ZW |
8669 | static void |
8670 | do_bfc (void) | |
8671 | { | |
8672 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
8673 | constraint (msb > 32, _("bit-field extends past end of register")); | |
8674 | /* The instruction encoding stores the LSB and MSB, | |
8675 | not the LSB and width. */ | |
8676 | inst.instruction |= inst.operands[0].reg << 12; | |
8677 | inst.instruction |= inst.operands[1].imm << 7; | |
8678 | inst.instruction |= (msb - 1) << 16; | |
8679 | } | |
b99bd4ef | 8680 | |
c19d1205 ZW |
8681 | static void |
8682 | do_bfi (void) | |
8683 | { | |
8684 | unsigned int msb; | |
b99bd4ef | 8685 | |
c19d1205 ZW |
8686 | /* #0 in second position is alternative syntax for bfc, which is |
8687 | the same instruction but with REG_PC in the Rm field. */ | |
8688 | if (!inst.operands[1].isreg) | |
8689 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 8690 | |
c19d1205 ZW |
8691 | msb = inst.operands[2].imm + inst.operands[3].imm; |
8692 | constraint (msb > 32, _("bit-field extends past end of register")); | |
8693 | /* The instruction encoding stores the LSB and MSB, | |
8694 | not the LSB and width. */ | |
8695 | inst.instruction |= inst.operands[0].reg << 12; | |
8696 | inst.instruction |= inst.operands[1].reg; | |
8697 | inst.instruction |= inst.operands[2].imm << 7; | |
8698 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
8699 | } |
8700 | ||
b99bd4ef | 8701 | static void |
c19d1205 | 8702 | do_bfx (void) |
b99bd4ef | 8703 | { |
c19d1205 ZW |
8704 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
8705 | _("bit-field extends past end of register")); | |
8706 | inst.instruction |= inst.operands[0].reg << 12; | |
8707 | inst.instruction |= inst.operands[1].reg; | |
8708 | inst.instruction |= inst.operands[2].imm << 7; | |
8709 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
8710 | } | |
09d92015 | 8711 | |
c19d1205 ZW |
8712 | /* ARM V5 breakpoint instruction (argument parse) |
8713 | BKPT <16 bit unsigned immediate> | |
8714 | Instruction is not conditional. | |
8715 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
8716 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 8717 | |
c19d1205 ZW |
8718 | static void |
8719 | do_bkpt (void) | |
8720 | { | |
8721 | /* Top 12 of 16 bits to bits 19:8. */ | |
8722 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 8723 | |
c19d1205 ZW |
8724 | /* Bottom 4 of 16 bits to bits 3:0. */ |
8725 | inst.instruction |= inst.operands[0].imm & 0xf; | |
8726 | } | |
09d92015 | 8727 | |
c19d1205 ZW |
8728 | static void |
8729 | encode_branch (int default_reloc) | |
8730 | { | |
8731 | if (inst.operands[0].hasreloc) | |
8732 | { | |
0855e32b NS |
8733 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32 |
8734 | && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL, | |
8735 | _("the only valid suffixes here are '(plt)' and '(tlscall)'")); | |
e2b0ab59 | 8736 | inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32 |
0855e32b NS |
8737 | ? BFD_RELOC_ARM_PLT32 |
8738 | : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL; | |
c19d1205 | 8739 | } |
b99bd4ef | 8740 | else |
e2b0ab59 AV |
8741 | inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc; |
8742 | inst.relocs[0].pc_rel = 1; | |
b99bd4ef NC |
8743 | } |
8744 | ||
b99bd4ef | 8745 | static void |
c19d1205 | 8746 | do_branch (void) |
b99bd4ef | 8747 | { |
39b41c9c PB |
8748 | #ifdef OBJ_ELF |
8749 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
8750 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
8751 | else | |
8752 | #endif | |
8753 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
8754 | } | |
8755 | ||
8756 | static void | |
8757 | do_bl (void) | |
8758 | { | |
8759 | #ifdef OBJ_ELF | |
8760 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
8761 | { | |
8762 | if (inst.cond == COND_ALWAYS) | |
8763 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
8764 | else | |
8765 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
8766 | } | |
8767 | else | |
8768 | #endif | |
8769 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 8770 | } |
b99bd4ef | 8771 | |
c19d1205 ZW |
8772 | /* ARM V5 branch-link-exchange instruction (argument parse) |
8773 | BLX <target_addr> ie BLX(1) | |
8774 | BLX{<condition>} <Rm> ie BLX(2) | |
8775 | Unfortunately, there are two different opcodes for this mnemonic. | |
8776 | So, the insns[].value is not used, and the code here zaps values | |
8777 | into inst.instruction. | |
8778 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 8779 | |
c19d1205 ZW |
8780 | static void |
8781 | do_blx (void) | |
8782 | { | |
8783 | if (inst.operands[0].isreg) | |
b99bd4ef | 8784 | { |
c19d1205 ZW |
8785 | /* Arg is a register; the opcode provided by insns[] is correct. |
8786 | It is not illegal to do "blx pc", just useless. */ | |
8787 | if (inst.operands[0].reg == REG_PC) | |
8788 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 8789 | |
c19d1205 ZW |
8790 | inst.instruction |= inst.operands[0].reg; |
8791 | } | |
8792 | else | |
b99bd4ef | 8793 | { |
c19d1205 | 8794 | /* Arg is an address; this instruction cannot be executed |
267bf995 RR |
8795 | conditionally, and the opcode must be adjusted. |
8796 | We retain the BFD_RELOC_ARM_PCREL_BLX till the very end | |
8797 | where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */ | |
c19d1205 | 8798 | constraint (inst.cond != COND_ALWAYS, BAD_COND); |
2fc8bdac | 8799 | inst.instruction = 0xfa000000; |
267bf995 | 8800 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); |
b99bd4ef | 8801 | } |
c19d1205 ZW |
8802 | } |
8803 | ||
8804 | static void | |
8805 | do_bx (void) | |
8806 | { | |
845b51d6 PB |
8807 | bfd_boolean want_reloc; |
8808 | ||
c19d1205 ZW |
8809 | if (inst.operands[0].reg == REG_PC) |
8810 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 8811 | |
c19d1205 | 8812 | inst.instruction |= inst.operands[0].reg; |
845b51d6 PB |
8813 | /* Output R_ARM_V4BX relocations if is an EABI object that looks like |
8814 | it is for ARMv4t or earlier. */ | |
8815 | want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5); | |
4d354d8b TP |
8816 | if (!ARM_FEATURE_ZERO (selected_object_arch) |
8817 | && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5)) | |
845b51d6 PB |
8818 | want_reloc = TRUE; |
8819 | ||
5ad34203 | 8820 | #ifdef OBJ_ELF |
845b51d6 | 8821 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
5ad34203 | 8822 | #endif |
584206db | 8823 | want_reloc = FALSE; |
845b51d6 PB |
8824 | |
8825 | if (want_reloc) | |
e2b0ab59 | 8826 | inst.relocs[0].type = BFD_RELOC_ARM_V4BX; |
09d92015 MM |
8827 | } |
8828 | ||
c19d1205 ZW |
8829 | |
8830 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
8831 | |
8832 | static void | |
c19d1205 | 8833 | do_bxj (void) |
a737bd4d | 8834 | { |
c19d1205 ZW |
8835 | if (inst.operands[0].reg == REG_PC) |
8836 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
8837 | ||
8838 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
8839 | } |
8840 | ||
c19d1205 ZW |
8841 | /* Co-processor data operation: |
8842 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
8843 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
8844 | static void | |
8845 | do_cdp (void) | |
8846 | { | |
8847 | inst.instruction |= inst.operands[0].reg << 8; | |
8848 | inst.instruction |= inst.operands[1].imm << 20; | |
8849 | inst.instruction |= inst.operands[2].reg << 12; | |
8850 | inst.instruction |= inst.operands[3].reg << 16; | |
8851 | inst.instruction |= inst.operands[4].reg; | |
8852 | inst.instruction |= inst.operands[5].imm << 5; | |
8853 | } | |
a737bd4d NC |
8854 | |
8855 | static void | |
c19d1205 | 8856 | do_cmp (void) |
a737bd4d | 8857 | { |
c19d1205 ZW |
8858 | inst.instruction |= inst.operands[0].reg << 16; |
8859 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
8860 | } |
8861 | ||
c19d1205 ZW |
8862 | /* Transfer between coprocessor and ARM registers. |
8863 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
8864 | MRC2 | |
8865 | MCR{cond} | |
8866 | MCR2 | |
8867 | ||
8868 | No special properties. */ | |
09d92015 | 8869 | |
dcbd0d71 MGD |
8870 | struct deprecated_coproc_regs_s |
8871 | { | |
8872 | unsigned cp; | |
8873 | int opc1; | |
8874 | unsigned crn; | |
8875 | unsigned crm; | |
8876 | int opc2; | |
8877 | arm_feature_set deprecated; | |
8878 | arm_feature_set obsoleted; | |
8879 | const char *dep_msg; | |
8880 | const char *obs_msg; | |
8881 | }; | |
8882 | ||
8883 | #define DEPR_ACCESS_V8 \ | |
8884 | N_("This coprocessor register access is deprecated in ARMv8") | |
8885 | ||
8886 | /* Table of all deprecated coprocessor registers. */ | |
8887 | static struct deprecated_coproc_regs_s deprecated_coproc_regs[] = | |
8888 | { | |
8889 | {15, 0, 7, 10, 5, /* CP15DMB. */ | |
823d2571 | 8890 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8891 | DEPR_ACCESS_V8, NULL}, |
8892 | {15, 0, 7, 10, 4, /* CP15DSB. */ | |
823d2571 | 8893 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8894 | DEPR_ACCESS_V8, NULL}, |
8895 | {15, 0, 7, 5, 4, /* CP15ISB. */ | |
823d2571 | 8896 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8897 | DEPR_ACCESS_V8, NULL}, |
8898 | {14, 6, 1, 0, 0, /* TEEHBR. */ | |
823d2571 | 8899 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8900 | DEPR_ACCESS_V8, NULL}, |
8901 | {14, 6, 0, 0, 0, /* TEECR. */ | |
823d2571 | 8902 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8903 | DEPR_ACCESS_V8, NULL}, |
8904 | }; | |
8905 | ||
8906 | #undef DEPR_ACCESS_V8 | |
8907 | ||
8908 | static const size_t deprecated_coproc_reg_count = | |
8909 | sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]); | |
8910 | ||
09d92015 | 8911 | static void |
c19d1205 | 8912 | do_co_reg (void) |
09d92015 | 8913 | { |
fdfde340 | 8914 | unsigned Rd; |
dcbd0d71 | 8915 | size_t i; |
fdfde340 JM |
8916 | |
8917 | Rd = inst.operands[2].reg; | |
8918 | if (thumb_mode) | |
8919 | { | |
8920 | if (inst.instruction == 0xee000010 | |
8921 | || inst.instruction == 0xfe000010) | |
8922 | /* MCR, MCR2 */ | |
8923 | reject_bad_reg (Rd); | |
5c8ed6a4 | 8924 | else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
fdfde340 JM |
8925 | /* MRC, MRC2 */ |
8926 | constraint (Rd == REG_SP, BAD_SP); | |
8927 | } | |
8928 | else | |
8929 | { | |
8930 | /* MCR */ | |
8931 | if (inst.instruction == 0xe000010) | |
8932 | constraint (Rd == REG_PC, BAD_PC); | |
8933 | } | |
8934 | ||
dcbd0d71 MGD |
8935 | for (i = 0; i < deprecated_coproc_reg_count; ++i) |
8936 | { | |
8937 | const struct deprecated_coproc_regs_s *r = | |
8938 | deprecated_coproc_regs + i; | |
8939 | ||
8940 | if (inst.operands[0].reg == r->cp | |
8941 | && inst.operands[1].imm == r->opc1 | |
8942 | && inst.operands[3].reg == r->crn | |
8943 | && inst.operands[4].reg == r->crm | |
8944 | && inst.operands[5].imm == r->opc2) | |
8945 | { | |
b10bf8c5 | 8946 | if (! ARM_CPU_IS_ANY (cpu_variant) |
477330fc | 8947 | && warn_on_deprecated |
dcbd0d71 | 8948 | && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated)) |
5c3696f8 | 8949 | as_tsktsk ("%s", r->dep_msg); |
dcbd0d71 MGD |
8950 | } |
8951 | } | |
fdfde340 | 8952 | |
c19d1205 ZW |
8953 | inst.instruction |= inst.operands[0].reg << 8; |
8954 | inst.instruction |= inst.operands[1].imm << 21; | |
fdfde340 | 8955 | inst.instruction |= Rd << 12; |
c19d1205 ZW |
8956 | inst.instruction |= inst.operands[3].reg << 16; |
8957 | inst.instruction |= inst.operands[4].reg; | |
8958 | inst.instruction |= inst.operands[5].imm << 5; | |
8959 | } | |
09d92015 | 8960 | |
c19d1205 ZW |
8961 | /* Transfer between coprocessor register and pair of ARM registers. |
8962 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
8963 | MCRR2 | |
8964 | MRRC{cond} | |
8965 | MRRC2 | |
b99bd4ef | 8966 | |
c19d1205 | 8967 | Two XScale instructions are special cases of these: |
09d92015 | 8968 | |
c19d1205 ZW |
8969 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
8970 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 8971 | |
5f4273c7 | 8972 | Result unpredictable if Rd or Rn is R15. */ |
a737bd4d | 8973 | |
c19d1205 ZW |
8974 | static void |
8975 | do_co_reg2c (void) | |
8976 | { | |
fdfde340 JM |
8977 | unsigned Rd, Rn; |
8978 | ||
8979 | Rd = inst.operands[2].reg; | |
8980 | Rn = inst.operands[3].reg; | |
8981 | ||
8982 | if (thumb_mode) | |
8983 | { | |
8984 | reject_bad_reg (Rd); | |
8985 | reject_bad_reg (Rn); | |
8986 | } | |
8987 | else | |
8988 | { | |
8989 | constraint (Rd == REG_PC, BAD_PC); | |
8990 | constraint (Rn == REG_PC, BAD_PC); | |
8991 | } | |
8992 | ||
873f10f0 TC |
8993 | /* Only check the MRRC{2} variants. */ |
8994 | if ((inst.instruction & 0x0FF00000) == 0x0C500000) | |
8995 | { | |
8996 | /* If Rd == Rn, error that the operation is | |
8997 | unpredictable (example MRRC p3,#1,r1,r1,c4). */ | |
8998 | constraint (Rd == Rn, BAD_OVERLAP); | |
8999 | } | |
9000 | ||
c19d1205 ZW |
9001 | inst.instruction |= inst.operands[0].reg << 8; |
9002 | inst.instruction |= inst.operands[1].imm << 4; | |
fdfde340 JM |
9003 | inst.instruction |= Rd << 12; |
9004 | inst.instruction |= Rn << 16; | |
c19d1205 | 9005 | inst.instruction |= inst.operands[4].reg; |
b99bd4ef NC |
9006 | } |
9007 | ||
c19d1205 ZW |
9008 | static void |
9009 | do_cpsi (void) | |
9010 | { | |
9011 | inst.instruction |= inst.operands[0].imm << 6; | |
a028a6f5 PB |
9012 | if (inst.operands[1].present) |
9013 | { | |
9014 | inst.instruction |= CPSI_MMOD; | |
9015 | inst.instruction |= inst.operands[1].imm; | |
9016 | } | |
c19d1205 | 9017 | } |
b99bd4ef | 9018 | |
62b3e311 PB |
9019 | static void |
9020 | do_dbg (void) | |
9021 | { | |
9022 | inst.instruction |= inst.operands[0].imm; | |
9023 | } | |
9024 | ||
eea54501 MGD |
9025 | static void |
9026 | do_div (void) | |
9027 | { | |
9028 | unsigned Rd, Rn, Rm; | |
9029 | ||
9030 | Rd = inst.operands[0].reg; | |
9031 | Rn = (inst.operands[1].present | |
9032 | ? inst.operands[1].reg : Rd); | |
9033 | Rm = inst.operands[2].reg; | |
9034 | ||
9035 | constraint ((Rd == REG_PC), BAD_PC); | |
9036 | constraint ((Rn == REG_PC), BAD_PC); | |
9037 | constraint ((Rm == REG_PC), BAD_PC); | |
9038 | ||
9039 | inst.instruction |= Rd << 16; | |
9040 | inst.instruction |= Rn << 0; | |
9041 | inst.instruction |= Rm << 8; | |
9042 | } | |
9043 | ||
b99bd4ef | 9044 | static void |
c19d1205 | 9045 | do_it (void) |
b99bd4ef | 9046 | { |
c19d1205 | 9047 | /* There is no IT instruction in ARM mode. We |
e07e6e58 NC |
9048 | process it to do the validation as if in |
9049 | thumb mode, just in case the code gets | |
9050 | assembled for thumb using the unified syntax. */ | |
9051 | ||
c19d1205 | 9052 | inst.size = 0; |
e07e6e58 NC |
9053 | if (unified_syntax) |
9054 | { | |
9055 | set_it_insn_type (IT_INSN); | |
9056 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
9057 | now_it.cc = inst.operands[0].imm; | |
9058 | } | |
09d92015 | 9059 | } |
b99bd4ef | 9060 | |
6530b175 NC |
9061 | /* If there is only one register in the register list, |
9062 | then return its register number. Otherwise return -1. */ | |
9063 | static int | |
9064 | only_one_reg_in_list (int range) | |
9065 | { | |
9066 | int i = ffs (range) - 1; | |
9067 | return (i > 15 || range != (1 << i)) ? -1 : i; | |
9068 | } | |
9069 | ||
09d92015 | 9070 | static void |
6530b175 | 9071 | encode_ldmstm(int from_push_pop_mnem) |
ea6ef066 | 9072 | { |
c19d1205 ZW |
9073 | int base_reg = inst.operands[0].reg; |
9074 | int range = inst.operands[1].imm; | |
6530b175 | 9075 | int one_reg; |
ea6ef066 | 9076 | |
c19d1205 ZW |
9077 | inst.instruction |= base_reg << 16; |
9078 | inst.instruction |= range; | |
ea6ef066 | 9079 | |
c19d1205 ZW |
9080 | if (inst.operands[1].writeback) |
9081 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 9082 | |
c19d1205 | 9083 | if (inst.operands[0].writeback) |
ea6ef066 | 9084 | { |
c19d1205 ZW |
9085 | inst.instruction |= WRITE_BACK; |
9086 | /* Check for unpredictable uses of writeback. */ | |
9087 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 9088 | { |
c19d1205 ZW |
9089 | /* Not allowed in LDM type 2. */ |
9090 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
9091 | && ((range & (1 << REG_PC)) == 0)) | |
9092 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
9093 | /* Only allowed if base reg not in list for other types. */ | |
9094 | else if (range & (1 << base_reg)) | |
9095 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
9096 | } | |
9097 | else /* STM. */ | |
9098 | { | |
9099 | /* Not allowed for type 2. */ | |
9100 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
9101 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
9102 | /* Only allowed if base reg not in list, or first in list. */ | |
9103 | else if ((range & (1 << base_reg)) | |
9104 | && (range & ((1 << base_reg) - 1))) | |
9105 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 9106 | } |
ea6ef066 | 9107 | } |
6530b175 NC |
9108 | |
9109 | /* If PUSH/POP has only one register, then use the A2 encoding. */ | |
9110 | one_reg = only_one_reg_in_list (range); | |
9111 | if (from_push_pop_mnem && one_reg >= 0) | |
9112 | { | |
9113 | int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH; | |
9114 | ||
4f588891 NC |
9115 | if (is_push && one_reg == 13 /* SP */) |
9116 | /* PR 22483: The A2 encoding cannot be used when | |
9117 | pushing the stack pointer as this is UNPREDICTABLE. */ | |
9118 | return; | |
9119 | ||
6530b175 NC |
9120 | inst.instruction &= A_COND_MASK; |
9121 | inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP; | |
9122 | inst.instruction |= one_reg << 12; | |
9123 | } | |
9124 | } | |
9125 | ||
9126 | static void | |
9127 | do_ldmstm (void) | |
9128 | { | |
9129 | encode_ldmstm (/*from_push_pop_mnem=*/FALSE); | |
a737bd4d NC |
9130 | } |
9131 | ||
c19d1205 ZW |
9132 | /* ARMv5TE load-consecutive (argument parse) |
9133 | Mode is like LDRH. | |
9134 | ||
9135 | LDRccD R, mode | |
9136 | STRccD R, mode. */ | |
9137 | ||
a737bd4d | 9138 | static void |
c19d1205 | 9139 | do_ldrd (void) |
a737bd4d | 9140 | { |
c19d1205 | 9141 | constraint (inst.operands[0].reg % 2 != 0, |
c56791bb | 9142 | _("first transfer register must be even")); |
c19d1205 ZW |
9143 | constraint (inst.operands[1].present |
9144 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
c56791bb | 9145 | _("can only transfer two consecutive registers")); |
c19d1205 ZW |
9146 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); |
9147 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 9148 | |
c19d1205 ZW |
9149 | if (!inst.operands[1].present) |
9150 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
5f4273c7 | 9151 | |
c56791bb RE |
9152 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
9153 | register and the first register written; we have to diagnose | |
9154 | overlap between the base and the second register written here. */ | |
ea6ef066 | 9155 | |
c56791bb RE |
9156 | if (inst.operands[2].reg == inst.operands[1].reg |
9157 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
9158 | as_warn (_("base register written back, and overlaps " | |
9159 | "second transfer register")); | |
b05fe5cf | 9160 | |
c56791bb RE |
9161 | if (!(inst.instruction & V4_STR_BIT)) |
9162 | { | |
c19d1205 | 9163 | /* For an index-register load, the index register must not overlap the |
c56791bb RE |
9164 | destination (even if not write-back). */ |
9165 | if (inst.operands[2].immisreg | |
9166 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg | |
9167 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
9168 | as_warn (_("index register overlaps transfer register")); | |
b05fe5cf | 9169 | } |
c19d1205 ZW |
9170 | inst.instruction |= inst.operands[0].reg << 12; |
9171 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
9172 | } |
9173 | ||
9174 | static void | |
c19d1205 | 9175 | do_ldrex (void) |
b05fe5cf | 9176 | { |
c19d1205 ZW |
9177 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
9178 | || inst.operands[1].postind || inst.operands[1].writeback | |
9179 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
9180 | || inst.operands[1].negative |
9181 | /* This can arise if the programmer has written | |
9182 | strex rN, rM, foo | |
9183 | or if they have mistakenly used a register name as the last | |
9184 | operand, eg: | |
9185 | strex rN, rM, rX | |
9186 | It is very difficult to distinguish between these two cases | |
9187 | because "rX" might actually be a label. ie the register | |
9188 | name has been occluded by a symbol of the same name. So we | |
9189 | just generate a general 'bad addressing mode' type error | |
9190 | message and leave it up to the programmer to discover the | |
9191 | true cause and fix their mistake. */ | |
9192 | || (inst.operands[1].reg == REG_PC), | |
9193 | BAD_ADDR_MODE); | |
b05fe5cf | 9194 | |
e2b0ab59 AV |
9195 | constraint (inst.relocs[0].exp.X_op != O_constant |
9196 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9197 | _("offset must be zero in ARM encoding")); |
b05fe5cf | 9198 | |
5be8be5d DG |
9199 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
9200 | ||
c19d1205 ZW |
9201 | inst.instruction |= inst.operands[0].reg << 12; |
9202 | inst.instruction |= inst.operands[1].reg << 16; | |
e2b0ab59 | 9203 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
b05fe5cf ZW |
9204 | } |
9205 | ||
9206 | static void | |
c19d1205 | 9207 | do_ldrexd (void) |
b05fe5cf | 9208 | { |
c19d1205 ZW |
9209 | constraint (inst.operands[0].reg % 2 != 0, |
9210 | _("even register required")); | |
9211 | constraint (inst.operands[1].present | |
9212 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
9213 | _("can only load two consecutive registers")); | |
9214 | /* If op 1 were present and equal to PC, this function wouldn't | |
9215 | have been called in the first place. */ | |
9216 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 9217 | |
c19d1205 ZW |
9218 | inst.instruction |= inst.operands[0].reg << 12; |
9219 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
9220 | } |
9221 | ||
1be5fd2e NC |
9222 | /* In both ARM and thumb state 'ldr pc, #imm' with an immediate |
9223 | which is not a multiple of four is UNPREDICTABLE. */ | |
9224 | static void | |
9225 | check_ldr_r15_aligned (void) | |
9226 | { | |
9227 | constraint (!(inst.operands[1].immisreg) | |
9228 | && (inst.operands[0].reg == REG_PC | |
9229 | && inst.operands[1].reg == REG_PC | |
e2b0ab59 | 9230 | && (inst.relocs[0].exp.X_add_number & 0x3)), |
de194d85 | 9231 | _("ldr to register 15 must be 4-byte aligned")); |
1be5fd2e NC |
9232 | } |
9233 | ||
b05fe5cf | 9234 | static void |
c19d1205 | 9235 | do_ldst (void) |
b05fe5cf | 9236 | { |
c19d1205 ZW |
9237 | inst.instruction |= inst.operands[0].reg << 12; |
9238 | if (!inst.operands[1].isreg) | |
8335d6aa | 9239 | if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE)) |
b05fe5cf | 9240 | return; |
c19d1205 | 9241 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
1be5fd2e | 9242 | check_ldr_r15_aligned (); |
b05fe5cf ZW |
9243 | } |
9244 | ||
9245 | static void | |
c19d1205 | 9246 | do_ldstt (void) |
b05fe5cf | 9247 | { |
c19d1205 ZW |
9248 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
9249 | reject [Rn,...]. */ | |
9250 | if (inst.operands[1].preind) | |
b05fe5cf | 9251 | { |
e2b0ab59 AV |
9252 | constraint (inst.relocs[0].exp.X_op != O_constant |
9253 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9254 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 9255 | |
c19d1205 ZW |
9256 | inst.operands[1].preind = 0; |
9257 | inst.operands[1].postind = 1; | |
9258 | inst.operands[1].writeback = 1; | |
b05fe5cf | 9259 | } |
c19d1205 ZW |
9260 | inst.instruction |= inst.operands[0].reg << 12; |
9261 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
9262 | } | |
b05fe5cf | 9263 | |
c19d1205 | 9264 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 9265 | |
c19d1205 ZW |
9266 | static void |
9267 | do_ldstv4 (void) | |
9268 | { | |
ff4a8d2b | 9269 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 ZW |
9270 | inst.instruction |= inst.operands[0].reg << 12; |
9271 | if (!inst.operands[1].isreg) | |
8335d6aa | 9272 | if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE)) |
b05fe5cf | 9273 | return; |
c19d1205 | 9274 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
9275 | } |
9276 | ||
9277 | static void | |
c19d1205 | 9278 | do_ldsttv4 (void) |
b05fe5cf | 9279 | { |
c19d1205 ZW |
9280 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
9281 | reject [Rn,...]. */ | |
9282 | if (inst.operands[1].preind) | |
b05fe5cf | 9283 | { |
e2b0ab59 AV |
9284 | constraint (inst.relocs[0].exp.X_op != O_constant |
9285 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9286 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 9287 | |
c19d1205 ZW |
9288 | inst.operands[1].preind = 0; |
9289 | inst.operands[1].postind = 1; | |
9290 | inst.operands[1].writeback = 1; | |
b05fe5cf | 9291 | } |
c19d1205 ZW |
9292 | inst.instruction |= inst.operands[0].reg << 12; |
9293 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
9294 | } | |
b05fe5cf | 9295 | |
c19d1205 ZW |
9296 | /* Co-processor register load/store. |
9297 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
9298 | static void | |
9299 | do_lstc (void) | |
9300 | { | |
9301 | inst.instruction |= inst.operands[0].reg << 8; | |
9302 | inst.instruction |= inst.operands[1].reg << 12; | |
9303 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
9304 | } |
9305 | ||
b05fe5cf | 9306 | static void |
c19d1205 | 9307 | do_mlas (void) |
b05fe5cf | 9308 | { |
8fb9d7b9 | 9309 | /* This restriction does not apply to mls (nor to mla in v6 or later). */ |
c19d1205 | 9310 | if (inst.operands[0].reg == inst.operands[1].reg |
8fb9d7b9 | 9311 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6) |
c19d1205 | 9312 | && !(inst.instruction & 0x00400000)) |
8fb9d7b9 | 9313 | as_tsktsk (_("Rd and Rm should be different in mla")); |
b05fe5cf | 9314 | |
c19d1205 ZW |
9315 | inst.instruction |= inst.operands[0].reg << 16; |
9316 | inst.instruction |= inst.operands[1].reg; | |
9317 | inst.instruction |= inst.operands[2].reg << 8; | |
9318 | inst.instruction |= inst.operands[3].reg << 12; | |
c19d1205 | 9319 | } |
b05fe5cf | 9320 | |
c19d1205 ZW |
9321 | static void |
9322 | do_mov (void) | |
9323 | { | |
e2b0ab59 AV |
9324 | constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
9325 | && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC , | |
a9f02af8 | 9326 | THUMB1_RELOC_ONLY); |
c19d1205 ZW |
9327 | inst.instruction |= inst.operands[0].reg << 12; |
9328 | encode_arm_shifter_operand (1); | |
9329 | } | |
b05fe5cf | 9330 | |
c19d1205 ZW |
9331 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
9332 | static void | |
9333 | do_mov16 (void) | |
9334 | { | |
b6895b4f PB |
9335 | bfd_vma imm; |
9336 | bfd_boolean top; | |
9337 | ||
9338 | top = (inst.instruction & 0x00400000) != 0; | |
e2b0ab59 | 9339 | constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW, |
33eaf5de | 9340 | _(":lower16: not allowed in this instruction")); |
e2b0ab59 | 9341 | constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT, |
33eaf5de | 9342 | _(":upper16: not allowed in this instruction")); |
c19d1205 | 9343 | inst.instruction |= inst.operands[0].reg << 12; |
e2b0ab59 | 9344 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
b6895b4f | 9345 | { |
e2b0ab59 | 9346 | imm = inst.relocs[0].exp.X_add_number; |
b6895b4f PB |
9347 | /* The value is in two pieces: 0:11, 16:19. */ |
9348 | inst.instruction |= (imm & 0x00000fff); | |
9349 | inst.instruction |= (imm & 0x0000f000) << 4; | |
9350 | } | |
b05fe5cf | 9351 | } |
b99bd4ef | 9352 | |
037e8744 JB |
9353 | static int |
9354 | do_vfp_nsyn_mrs (void) | |
9355 | { | |
9356 | if (inst.operands[0].isvec) | |
9357 | { | |
9358 | if (inst.operands[1].reg != 1) | |
477330fc | 9359 | first_error (_("operand 1 must be FPSCR")); |
037e8744 JB |
9360 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); |
9361 | memset (&inst.operands[1], '\0', sizeof (inst.operands[1])); | |
9362 | do_vfp_nsyn_opcode ("fmstat"); | |
9363 | } | |
9364 | else if (inst.operands[1].isvec) | |
9365 | do_vfp_nsyn_opcode ("fmrx"); | |
9366 | else | |
9367 | return FAIL; | |
5f4273c7 | 9368 | |
037e8744 JB |
9369 | return SUCCESS; |
9370 | } | |
9371 | ||
9372 | static int | |
9373 | do_vfp_nsyn_msr (void) | |
9374 | { | |
9375 | if (inst.operands[0].isvec) | |
9376 | do_vfp_nsyn_opcode ("fmxr"); | |
9377 | else | |
9378 | return FAIL; | |
9379 | ||
9380 | return SUCCESS; | |
9381 | } | |
9382 | ||
f7c21dc7 NC |
9383 | static void |
9384 | do_vmrs (void) | |
9385 | { | |
9386 | unsigned Rt = inst.operands[0].reg; | |
fa94de6b | 9387 | |
16d02dc9 | 9388 | if (thumb_mode && Rt == REG_SP) |
f7c21dc7 NC |
9389 | { |
9390 | inst.error = BAD_SP; | |
9391 | return; | |
9392 | } | |
9393 | ||
40c7d507 RR |
9394 | /* MVFR2 is only valid at ARMv8-A. */ |
9395 | if (inst.operands[1].reg == 5) | |
9396 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
9397 | _(BAD_FPU)); | |
9398 | ||
f7c21dc7 | 9399 | /* APSR_ sets isvec. All other refs to PC are illegal. */ |
16d02dc9 | 9400 | if (!inst.operands[0].isvec && Rt == REG_PC) |
f7c21dc7 NC |
9401 | { |
9402 | inst.error = BAD_PC; | |
9403 | return; | |
9404 | } | |
9405 | ||
16d02dc9 JB |
9406 | /* If we get through parsing the register name, we just insert the number |
9407 | generated into the instruction without further validation. */ | |
9408 | inst.instruction |= (inst.operands[1].reg << 16); | |
f7c21dc7 NC |
9409 | inst.instruction |= (Rt << 12); |
9410 | } | |
9411 | ||
9412 | static void | |
9413 | do_vmsr (void) | |
9414 | { | |
9415 | unsigned Rt = inst.operands[1].reg; | |
fa94de6b | 9416 | |
f7c21dc7 NC |
9417 | if (thumb_mode) |
9418 | reject_bad_reg (Rt); | |
9419 | else if (Rt == REG_PC) | |
9420 | { | |
9421 | inst.error = BAD_PC; | |
9422 | return; | |
9423 | } | |
9424 | ||
40c7d507 RR |
9425 | /* MVFR2 is only valid for ARMv8-A. */ |
9426 | if (inst.operands[0].reg == 5) | |
9427 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
9428 | _(BAD_FPU)); | |
9429 | ||
16d02dc9 JB |
9430 | /* If we get through parsing the register name, we just insert the number |
9431 | generated into the instruction without further validation. */ | |
9432 | inst.instruction |= (inst.operands[0].reg << 16); | |
f7c21dc7 NC |
9433 | inst.instruction |= (Rt << 12); |
9434 | } | |
9435 | ||
b99bd4ef | 9436 | static void |
c19d1205 | 9437 | do_mrs (void) |
b99bd4ef | 9438 | { |
90ec0d68 MGD |
9439 | unsigned br; |
9440 | ||
037e8744 JB |
9441 | if (do_vfp_nsyn_mrs () == SUCCESS) |
9442 | return; | |
9443 | ||
ff4a8d2b | 9444 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 | 9445 | inst.instruction |= inst.operands[0].reg << 12; |
90ec0d68 MGD |
9446 | |
9447 | if (inst.operands[1].isreg) | |
9448 | { | |
9449 | br = inst.operands[1].reg; | |
806ab1c0 | 9450 | if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000)) |
90ec0d68 MGD |
9451 | as_bad (_("bad register for mrs")); |
9452 | } | |
9453 | else | |
9454 | { | |
9455 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ | |
9456 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
9457 | != (PSR_c|PSR_f), | |
d2cd1205 | 9458 | _("'APSR', 'CPSR' or 'SPSR' expected")); |
90ec0d68 MGD |
9459 | br = (15<<16) | (inst.operands[1].imm & SPSR_BIT); |
9460 | } | |
9461 | ||
9462 | inst.instruction |= br; | |
c19d1205 | 9463 | } |
b99bd4ef | 9464 | |
c19d1205 ZW |
9465 | /* Two possible forms: |
9466 | "{C|S}PSR_<field>, Rm", | |
9467 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 9468 | |
c19d1205 ZW |
9469 | static void |
9470 | do_msr (void) | |
9471 | { | |
037e8744 JB |
9472 | if (do_vfp_nsyn_msr () == SUCCESS) |
9473 | return; | |
9474 | ||
c19d1205 ZW |
9475 | inst.instruction |= inst.operands[0].imm; |
9476 | if (inst.operands[1].isreg) | |
9477 | inst.instruction |= inst.operands[1].reg; | |
9478 | else | |
b99bd4ef | 9479 | { |
c19d1205 | 9480 | inst.instruction |= INST_IMMEDIATE; |
e2b0ab59 AV |
9481 | inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE; |
9482 | inst.relocs[0].pc_rel = 0; | |
b99bd4ef | 9483 | } |
b99bd4ef NC |
9484 | } |
9485 | ||
c19d1205 ZW |
9486 | static void |
9487 | do_mul (void) | |
a737bd4d | 9488 | { |
ff4a8d2b NC |
9489 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
9490 | ||
c19d1205 ZW |
9491 | if (!inst.operands[2].present) |
9492 | inst.operands[2].reg = inst.operands[0].reg; | |
9493 | inst.instruction |= inst.operands[0].reg << 16; | |
9494 | inst.instruction |= inst.operands[1].reg; | |
9495 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 9496 | |
8fb9d7b9 MS |
9497 | if (inst.operands[0].reg == inst.operands[1].reg |
9498 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) | |
9499 | as_tsktsk (_("Rd and Rm should be different in mul")); | |
a737bd4d NC |
9500 | } |
9501 | ||
c19d1205 ZW |
9502 | /* Long Multiply Parser |
9503 | UMULL RdLo, RdHi, Rm, Rs | |
9504 | SMULL RdLo, RdHi, Rm, Rs | |
9505 | UMLAL RdLo, RdHi, Rm, Rs | |
9506 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
9507 | |
9508 | static void | |
c19d1205 | 9509 | do_mull (void) |
b99bd4ef | 9510 | { |
c19d1205 ZW |
9511 | inst.instruction |= inst.operands[0].reg << 12; |
9512 | inst.instruction |= inst.operands[1].reg << 16; | |
9513 | inst.instruction |= inst.operands[2].reg; | |
9514 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 9515 | |
682b27ad PB |
9516 | /* rdhi and rdlo must be different. */ |
9517 | if (inst.operands[0].reg == inst.operands[1].reg) | |
9518 | as_tsktsk (_("rdhi and rdlo must be different")); | |
9519 | ||
9520 | /* rdhi, rdlo and rm must all be different before armv6. */ | |
9521 | if ((inst.operands[0].reg == inst.operands[2].reg | |
c19d1205 | 9522 | || inst.operands[1].reg == inst.operands[2].reg) |
682b27ad | 9523 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) |
c19d1205 ZW |
9524 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); |
9525 | } | |
b99bd4ef | 9526 | |
c19d1205 ZW |
9527 | static void |
9528 | do_nop (void) | |
9529 | { | |
e7495e45 NS |
9530 | if (inst.operands[0].present |
9531 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k)) | |
c19d1205 ZW |
9532 | { |
9533 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
9534 | inst.instruction &= 0xf0000000; | |
e7495e45 NS |
9535 | inst.instruction |= 0x0320f000; |
9536 | if (inst.operands[0].present) | |
9537 | inst.instruction |= inst.operands[0].imm; | |
c19d1205 | 9538 | } |
b99bd4ef NC |
9539 | } |
9540 | ||
c19d1205 ZW |
9541 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
9542 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
9543 | Condition defaults to COND_ALWAYS. | |
9544 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
9545 | |
9546 | static void | |
c19d1205 | 9547 | do_pkhbt (void) |
b99bd4ef | 9548 | { |
c19d1205 ZW |
9549 | inst.instruction |= inst.operands[0].reg << 12; |
9550 | inst.instruction |= inst.operands[1].reg << 16; | |
9551 | inst.instruction |= inst.operands[2].reg; | |
9552 | if (inst.operands[3].present) | |
9553 | encode_arm_shift (3); | |
9554 | } | |
b99bd4ef | 9555 | |
c19d1205 | 9556 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 9557 | |
c19d1205 ZW |
9558 | static void |
9559 | do_pkhtb (void) | |
9560 | { | |
9561 | if (!inst.operands[3].present) | |
b99bd4ef | 9562 | { |
c19d1205 ZW |
9563 | /* If the shift specifier is omitted, turn the instruction |
9564 | into pkhbt rd, rm, rn. */ | |
9565 | inst.instruction &= 0xfff00010; | |
9566 | inst.instruction |= inst.operands[0].reg << 12; | |
9567 | inst.instruction |= inst.operands[1].reg; | |
9568 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
9569 | } |
9570 | else | |
9571 | { | |
c19d1205 ZW |
9572 | inst.instruction |= inst.operands[0].reg << 12; |
9573 | inst.instruction |= inst.operands[1].reg << 16; | |
9574 | inst.instruction |= inst.operands[2].reg; | |
9575 | encode_arm_shift (3); | |
b99bd4ef NC |
9576 | } |
9577 | } | |
9578 | ||
c19d1205 | 9579 | /* ARMv5TE: Preload-Cache |
60e5ef9f | 9580 | MP Extensions: Preload for write |
c19d1205 | 9581 | |
60e5ef9f | 9582 | PLD(W) <addr_mode> |
c19d1205 ZW |
9583 | |
9584 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
9585 | |
9586 | static void | |
c19d1205 | 9587 | do_pld (void) |
b99bd4ef | 9588 | { |
c19d1205 ZW |
9589 | constraint (!inst.operands[0].isreg, |
9590 | _("'[' expected after PLD mnemonic")); | |
9591 | constraint (inst.operands[0].postind, | |
9592 | _("post-indexed expression used in preload instruction")); | |
9593 | constraint (inst.operands[0].writeback, | |
9594 | _("writeback used in preload instruction")); | |
9595 | constraint (!inst.operands[0].preind, | |
9596 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
9597 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
9598 | } | |
b99bd4ef | 9599 | |
62b3e311 PB |
9600 | /* ARMv7: PLI <addr_mode> */ |
9601 | static void | |
9602 | do_pli (void) | |
9603 | { | |
9604 | constraint (!inst.operands[0].isreg, | |
9605 | _("'[' expected after PLI mnemonic")); | |
9606 | constraint (inst.operands[0].postind, | |
9607 | _("post-indexed expression used in preload instruction")); | |
9608 | constraint (inst.operands[0].writeback, | |
9609 | _("writeback used in preload instruction")); | |
9610 | constraint (!inst.operands[0].preind, | |
9611 | _("unindexed addressing used in preload instruction")); | |
9612 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); | |
9613 | inst.instruction &= ~PRE_INDEX; | |
9614 | } | |
9615 | ||
c19d1205 ZW |
9616 | static void |
9617 | do_push_pop (void) | |
9618 | { | |
5e0d7f77 MP |
9619 | constraint (inst.operands[0].writeback, |
9620 | _("push/pop do not support {reglist}^")); | |
c19d1205 ZW |
9621 | inst.operands[1] = inst.operands[0]; |
9622 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
9623 | inst.operands[0].isreg = 1; | |
9624 | inst.operands[0].writeback = 1; | |
9625 | inst.operands[0].reg = REG_SP; | |
6530b175 | 9626 | encode_ldmstm (/*from_push_pop_mnem=*/TRUE); |
c19d1205 | 9627 | } |
b99bd4ef | 9628 | |
c19d1205 ZW |
9629 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
9630 | word at the specified address and the following word | |
9631 | respectively. | |
9632 | Unconditionally executed. | |
9633 | Error if Rn is R15. */ | |
b99bd4ef | 9634 | |
c19d1205 ZW |
9635 | static void |
9636 | do_rfe (void) | |
9637 | { | |
9638 | inst.instruction |= inst.operands[0].reg << 16; | |
9639 | if (inst.operands[0].writeback) | |
9640 | inst.instruction |= WRITE_BACK; | |
9641 | } | |
b99bd4ef | 9642 | |
c19d1205 | 9643 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 9644 | |
c19d1205 ZW |
9645 | static void |
9646 | do_ssat (void) | |
9647 | { | |
9648 | inst.instruction |= inst.operands[0].reg << 12; | |
9649 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
9650 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 9651 | |
c19d1205 ZW |
9652 | if (inst.operands[3].present) |
9653 | encode_arm_shift (3); | |
b99bd4ef NC |
9654 | } |
9655 | ||
c19d1205 | 9656 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
9657 | |
9658 | static void | |
c19d1205 | 9659 | do_usat (void) |
b99bd4ef | 9660 | { |
c19d1205 ZW |
9661 | inst.instruction |= inst.operands[0].reg << 12; |
9662 | inst.instruction |= inst.operands[1].imm << 16; | |
9663 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 9664 | |
c19d1205 ZW |
9665 | if (inst.operands[3].present) |
9666 | encode_arm_shift (3); | |
b99bd4ef NC |
9667 | } |
9668 | ||
c19d1205 | 9669 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
9670 | |
9671 | static void | |
c19d1205 | 9672 | do_ssat16 (void) |
09d92015 | 9673 | { |
c19d1205 ZW |
9674 | inst.instruction |= inst.operands[0].reg << 12; |
9675 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
9676 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
9677 | } |
9678 | ||
c19d1205 ZW |
9679 | static void |
9680 | do_usat16 (void) | |
a737bd4d | 9681 | { |
c19d1205 ZW |
9682 | inst.instruction |= inst.operands[0].reg << 12; |
9683 | inst.instruction |= inst.operands[1].imm << 16; | |
9684 | inst.instruction |= inst.operands[2].reg; | |
9685 | } | |
a737bd4d | 9686 | |
c19d1205 ZW |
9687 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
9688 | preserving the other bits. | |
a737bd4d | 9689 | |
c19d1205 ZW |
9690 | setend <endian_specifier>, where <endian_specifier> is either |
9691 | BE or LE. */ | |
a737bd4d | 9692 | |
c19d1205 ZW |
9693 | static void |
9694 | do_setend (void) | |
9695 | { | |
12e37cbc MGD |
9696 | if (warn_on_deprecated |
9697 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
5c3696f8 | 9698 | as_tsktsk (_("setend use is deprecated for ARMv8")); |
12e37cbc | 9699 | |
c19d1205 ZW |
9700 | if (inst.operands[0].imm) |
9701 | inst.instruction |= 0x200; | |
a737bd4d NC |
9702 | } |
9703 | ||
9704 | static void | |
c19d1205 | 9705 | do_shift (void) |
a737bd4d | 9706 | { |
c19d1205 ZW |
9707 | unsigned int Rm = (inst.operands[1].present |
9708 | ? inst.operands[1].reg | |
9709 | : inst.operands[0].reg); | |
a737bd4d | 9710 | |
c19d1205 ZW |
9711 | inst.instruction |= inst.operands[0].reg << 12; |
9712 | inst.instruction |= Rm; | |
9713 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 9714 | { |
c19d1205 ZW |
9715 | inst.instruction |= inst.operands[2].reg << 8; |
9716 | inst.instruction |= SHIFT_BY_REG; | |
94342ec3 NC |
9717 | /* PR 12854: Error on extraneous shifts. */ |
9718 | constraint (inst.operands[2].shifted, | |
9719 | _("extraneous shift as part of operand to shift insn")); | |
a737bd4d NC |
9720 | } |
9721 | else | |
e2b0ab59 | 9722 | inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
9723 | } |
9724 | ||
09d92015 | 9725 | static void |
3eb17e6b | 9726 | do_smc (void) |
09d92015 | 9727 | { |
e2b0ab59 AV |
9728 | inst.relocs[0].type = BFD_RELOC_ARM_SMC; |
9729 | inst.relocs[0].pc_rel = 0; | |
09d92015 MM |
9730 | } |
9731 | ||
90ec0d68 MGD |
9732 | static void |
9733 | do_hvc (void) | |
9734 | { | |
e2b0ab59 AV |
9735 | inst.relocs[0].type = BFD_RELOC_ARM_HVC; |
9736 | inst.relocs[0].pc_rel = 0; | |
90ec0d68 MGD |
9737 | } |
9738 | ||
09d92015 | 9739 | static void |
c19d1205 | 9740 | do_swi (void) |
09d92015 | 9741 | { |
e2b0ab59 AV |
9742 | inst.relocs[0].type = BFD_RELOC_ARM_SWI; |
9743 | inst.relocs[0].pc_rel = 0; | |
09d92015 MM |
9744 | } |
9745 | ||
ddfded2f MW |
9746 | static void |
9747 | do_setpan (void) | |
9748 | { | |
9749 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan), | |
9750 | _("selected processor does not support SETPAN instruction")); | |
9751 | ||
9752 | inst.instruction |= ((inst.operands[0].imm & 1) << 9); | |
9753 | } | |
9754 | ||
9755 | static void | |
9756 | do_t_setpan (void) | |
9757 | { | |
9758 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan), | |
9759 | _("selected processor does not support SETPAN instruction")); | |
9760 | ||
9761 | inst.instruction |= (inst.operands[0].imm << 3); | |
9762 | } | |
9763 | ||
c19d1205 ZW |
9764 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
9765 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
9766 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
9767 | Error if any register is R15. */ | |
e16bb312 | 9768 | |
c19d1205 ZW |
9769 | static void |
9770 | do_smla (void) | |
e16bb312 | 9771 | { |
c19d1205 ZW |
9772 | inst.instruction |= inst.operands[0].reg << 16; |
9773 | inst.instruction |= inst.operands[1].reg; | |
9774 | inst.instruction |= inst.operands[2].reg << 8; | |
9775 | inst.instruction |= inst.operands[3].reg << 12; | |
9776 | } | |
a737bd4d | 9777 | |
c19d1205 ZW |
9778 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
9779 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
9780 | Error if any register is R15. | |
9781 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 9782 | |
c19d1205 ZW |
9783 | static void |
9784 | do_smlal (void) | |
9785 | { | |
9786 | inst.instruction |= inst.operands[0].reg << 12; | |
9787 | inst.instruction |= inst.operands[1].reg << 16; | |
9788 | inst.instruction |= inst.operands[2].reg; | |
9789 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 9790 | |
c19d1205 ZW |
9791 | if (inst.operands[0].reg == inst.operands[1].reg) |
9792 | as_tsktsk (_("rdhi and rdlo must be different")); | |
9793 | } | |
a737bd4d | 9794 | |
c19d1205 ZW |
9795 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
9796 | SMULxy{cond} Rd,Rm,Rs | |
9797 | Error if any register is R15. */ | |
a737bd4d | 9798 | |
c19d1205 ZW |
9799 | static void |
9800 | do_smul (void) | |
9801 | { | |
9802 | inst.instruction |= inst.operands[0].reg << 16; | |
9803 | inst.instruction |= inst.operands[1].reg; | |
9804 | inst.instruction |= inst.operands[2].reg << 8; | |
9805 | } | |
a737bd4d | 9806 | |
b6702015 PB |
9807 | /* ARM V6 srs (argument parse). The variable fields in the encoding are |
9808 | the same for both ARM and Thumb-2. */ | |
a737bd4d | 9809 | |
c19d1205 ZW |
9810 | static void |
9811 | do_srs (void) | |
9812 | { | |
b6702015 PB |
9813 | int reg; |
9814 | ||
9815 | if (inst.operands[0].present) | |
9816 | { | |
9817 | reg = inst.operands[0].reg; | |
fdfde340 | 9818 | constraint (reg != REG_SP, _("SRS base register must be r13")); |
b6702015 PB |
9819 | } |
9820 | else | |
fdfde340 | 9821 | reg = REG_SP; |
b6702015 PB |
9822 | |
9823 | inst.instruction |= reg << 16; | |
9824 | inst.instruction |= inst.operands[1].imm; | |
9825 | if (inst.operands[0].writeback || inst.operands[1].writeback) | |
c19d1205 ZW |
9826 | inst.instruction |= WRITE_BACK; |
9827 | } | |
a737bd4d | 9828 | |
c19d1205 | 9829 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 9830 | |
c19d1205 ZW |
9831 | static void |
9832 | do_strex (void) | |
9833 | { | |
9834 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
9835 | || inst.operands[2].postind || inst.operands[2].writeback | |
9836 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
9837 | || inst.operands[2].negative |
9838 | /* See comment in do_ldrex(). */ | |
9839 | || (inst.operands[2].reg == REG_PC), | |
9840 | BAD_ADDR_MODE); | |
a737bd4d | 9841 | |
c19d1205 ZW |
9842 | constraint (inst.operands[0].reg == inst.operands[1].reg |
9843 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 9844 | |
e2b0ab59 AV |
9845 | constraint (inst.relocs[0].exp.X_op != O_constant |
9846 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9847 | _("offset must be zero in ARM encoding")); |
a737bd4d | 9848 | |
c19d1205 ZW |
9849 | inst.instruction |= inst.operands[0].reg << 12; |
9850 | inst.instruction |= inst.operands[1].reg; | |
9851 | inst.instruction |= inst.operands[2].reg << 16; | |
e2b0ab59 | 9852 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
e16bb312 NC |
9853 | } |
9854 | ||
877807f8 NC |
9855 | static void |
9856 | do_t_strexbh (void) | |
9857 | { | |
9858 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
9859 | || inst.operands[2].postind || inst.operands[2].writeback | |
9860 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
9861 | || inst.operands[2].negative, | |
9862 | BAD_ADDR_MODE); | |
9863 | ||
9864 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
9865 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
9866 | ||
9867 | do_rm_rd_rn (); | |
9868 | } | |
9869 | ||
e16bb312 | 9870 | static void |
c19d1205 | 9871 | do_strexd (void) |
e16bb312 | 9872 | { |
c19d1205 ZW |
9873 | constraint (inst.operands[1].reg % 2 != 0, |
9874 | _("even register required")); | |
9875 | constraint (inst.operands[2].present | |
9876 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
9877 | _("can only store two consecutive registers")); | |
9878 | /* If op 2 were present and equal to PC, this function wouldn't | |
9879 | have been called in the first place. */ | |
9880 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 9881 | |
c19d1205 ZW |
9882 | constraint (inst.operands[0].reg == inst.operands[1].reg |
9883 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
9884 | || inst.operands[0].reg == inst.operands[3].reg, | |
9885 | BAD_OVERLAP); | |
e16bb312 | 9886 | |
c19d1205 ZW |
9887 | inst.instruction |= inst.operands[0].reg << 12; |
9888 | inst.instruction |= inst.operands[1].reg; | |
9889 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
9890 | } |
9891 | ||
9eb6c0f1 MGD |
9892 | /* ARM V8 STRL. */ |
9893 | static void | |
4b8c8c02 | 9894 | do_stlex (void) |
9eb6c0f1 MGD |
9895 | { |
9896 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
9897 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
9898 | ||
9899 | do_rd_rm_rn (); | |
9900 | } | |
9901 | ||
9902 | static void | |
4b8c8c02 | 9903 | do_t_stlex (void) |
9eb6c0f1 MGD |
9904 | { |
9905 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
9906 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
9907 | ||
9908 | do_rm_rd_rn (); | |
9909 | } | |
9910 | ||
c19d1205 ZW |
9911 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
9912 | extends it to 32-bits, and adds the result to a value in another | |
9913 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
9914 | before extracting the 16-bit value. | |
9915 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
9916 | Condition defaults to COND_ALWAYS. | |
9917 | Error if any register uses R15. */ | |
9918 | ||
e16bb312 | 9919 | static void |
c19d1205 | 9920 | do_sxtah (void) |
e16bb312 | 9921 | { |
c19d1205 ZW |
9922 | inst.instruction |= inst.operands[0].reg << 12; |
9923 | inst.instruction |= inst.operands[1].reg << 16; | |
9924 | inst.instruction |= inst.operands[2].reg; | |
9925 | inst.instruction |= inst.operands[3].imm << 10; | |
9926 | } | |
e16bb312 | 9927 | |
c19d1205 | 9928 | /* ARM V6 SXTH. |
e16bb312 | 9929 | |
c19d1205 ZW |
9930 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
9931 | Condition defaults to COND_ALWAYS. | |
9932 | Error if any register uses R15. */ | |
e16bb312 NC |
9933 | |
9934 | static void | |
c19d1205 | 9935 | do_sxth (void) |
e16bb312 | 9936 | { |
c19d1205 ZW |
9937 | inst.instruction |= inst.operands[0].reg << 12; |
9938 | inst.instruction |= inst.operands[1].reg; | |
9939 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 9940 | } |
c19d1205 ZW |
9941 | \f |
9942 | /* VFP instructions. In a logical order: SP variant first, monad | |
9943 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
9944 | |
9945 | static void | |
c19d1205 | 9946 | do_vfp_sp_monadic (void) |
e16bb312 | 9947 | { |
5287ad62 JB |
9948 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
9949 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
9950 | } |
9951 | ||
9952 | static void | |
c19d1205 | 9953 | do_vfp_sp_dyadic (void) |
e16bb312 | 9954 | { |
5287ad62 JB |
9955 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
9956 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
9957 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
9958 | } |
9959 | ||
9960 | static void | |
c19d1205 | 9961 | do_vfp_sp_compare_z (void) |
e16bb312 | 9962 | { |
5287ad62 | 9963 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
9964 | } |
9965 | ||
9966 | static void | |
c19d1205 | 9967 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 9968 | { |
5287ad62 JB |
9969 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
9970 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
9971 | } |
9972 | ||
9973 | static void | |
c19d1205 | 9974 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 9975 | { |
5287ad62 JB |
9976 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
9977 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
e16bb312 NC |
9978 | } |
9979 | ||
9980 | static void | |
c19d1205 | 9981 | do_vfp_reg_from_sp (void) |
e16bb312 | 9982 | { |
c19d1205 | 9983 | inst.instruction |= inst.operands[0].reg << 12; |
5287ad62 | 9984 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); |
e16bb312 NC |
9985 | } |
9986 | ||
9987 | static void | |
c19d1205 | 9988 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 9989 | { |
c19d1205 ZW |
9990 | constraint (inst.operands[2].imm != 2, |
9991 | _("only two consecutive VFP SP registers allowed here")); | |
9992 | inst.instruction |= inst.operands[0].reg << 12; | |
9993 | inst.instruction |= inst.operands[1].reg << 16; | |
5287ad62 | 9994 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); |
e16bb312 NC |
9995 | } |
9996 | ||
9997 | static void | |
c19d1205 | 9998 | do_vfp_sp_from_reg (void) |
e16bb312 | 9999 | { |
5287ad62 | 10000 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn); |
c19d1205 | 10001 | inst.instruction |= inst.operands[1].reg << 12; |
e16bb312 NC |
10002 | } |
10003 | ||
10004 | static void | |
c19d1205 | 10005 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 10006 | { |
c19d1205 ZW |
10007 | constraint (inst.operands[0].imm != 2, |
10008 | _("only two consecutive VFP SP registers allowed here")); | |
5287ad62 | 10009 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm); |
c19d1205 ZW |
10010 | inst.instruction |= inst.operands[1].reg << 12; |
10011 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
10012 | } |
10013 | ||
10014 | static void | |
c19d1205 | 10015 | do_vfp_sp_ldst (void) |
e16bb312 | 10016 | { |
5287ad62 | 10017 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
c19d1205 | 10018 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
10019 | } |
10020 | ||
10021 | static void | |
c19d1205 | 10022 | do_vfp_dp_ldst (void) |
e16bb312 | 10023 | { |
5287ad62 | 10024 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
c19d1205 | 10025 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
10026 | } |
10027 | ||
c19d1205 | 10028 | |
e16bb312 | 10029 | static void |
c19d1205 | 10030 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 10031 | { |
c19d1205 ZW |
10032 | if (inst.operands[0].writeback) |
10033 | inst.instruction |= WRITE_BACK; | |
10034 | else | |
10035 | constraint (ldstm_type != VFP_LDSTMIA, | |
10036 | _("this addressing mode requires base-register writeback")); | |
10037 | inst.instruction |= inst.operands[0].reg << 16; | |
5287ad62 | 10038 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd); |
c19d1205 | 10039 | inst.instruction |= inst.operands[1].imm; |
e16bb312 NC |
10040 | } |
10041 | ||
10042 | static void | |
c19d1205 | 10043 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 10044 | { |
c19d1205 | 10045 | int count; |
e16bb312 | 10046 | |
c19d1205 ZW |
10047 | if (inst.operands[0].writeback) |
10048 | inst.instruction |= WRITE_BACK; | |
10049 | else | |
10050 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
10051 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 10052 | |
c19d1205 | 10053 | inst.instruction |= inst.operands[0].reg << 16; |
5287ad62 | 10054 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); |
e16bb312 | 10055 | |
c19d1205 ZW |
10056 | count = inst.operands[1].imm << 1; |
10057 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
10058 | count += 1; | |
e16bb312 | 10059 | |
c19d1205 | 10060 | inst.instruction |= count; |
e16bb312 NC |
10061 | } |
10062 | ||
10063 | static void | |
c19d1205 | 10064 | do_vfp_sp_ldstmia (void) |
e16bb312 | 10065 | { |
c19d1205 | 10066 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
10067 | } |
10068 | ||
10069 | static void | |
c19d1205 | 10070 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 10071 | { |
c19d1205 | 10072 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
10073 | } |
10074 | ||
10075 | static void | |
c19d1205 | 10076 | do_vfp_dp_ldstmia (void) |
e16bb312 | 10077 | { |
c19d1205 | 10078 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
10079 | } |
10080 | ||
10081 | static void | |
c19d1205 | 10082 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 10083 | { |
c19d1205 | 10084 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
10085 | } |
10086 | ||
10087 | static void | |
c19d1205 | 10088 | do_vfp_xp_ldstmia (void) |
e16bb312 | 10089 | { |
c19d1205 ZW |
10090 | vfp_dp_ldstm (VFP_LDSTMIAX); |
10091 | } | |
e16bb312 | 10092 | |
c19d1205 ZW |
10093 | static void |
10094 | do_vfp_xp_ldstmdb (void) | |
10095 | { | |
10096 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 10097 | } |
5287ad62 JB |
10098 | |
10099 | static void | |
10100 | do_vfp_dp_rd_rm (void) | |
10101 | { | |
10102 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
10103 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
10104 | } | |
10105 | ||
10106 | static void | |
10107 | do_vfp_dp_rn_rd (void) | |
10108 | { | |
10109 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn); | |
10110 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
10111 | } | |
10112 | ||
10113 | static void | |
10114 | do_vfp_dp_rd_rn (void) | |
10115 | { | |
10116 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
10117 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
10118 | } | |
10119 | ||
10120 | static void | |
10121 | do_vfp_dp_rd_rn_rm (void) | |
10122 | { | |
10123 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
10124 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
10125 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm); | |
10126 | } | |
10127 | ||
10128 | static void | |
10129 | do_vfp_dp_rd (void) | |
10130 | { | |
10131 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
10132 | } | |
10133 | ||
10134 | static void | |
10135 | do_vfp_dp_rm_rd_rn (void) | |
10136 | { | |
10137 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm); | |
10138 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
10139 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn); | |
10140 | } | |
10141 | ||
10142 | /* VFPv3 instructions. */ | |
10143 | static void | |
10144 | do_vfp_sp_const (void) | |
10145 | { | |
10146 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
00249aaa PB |
10147 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
10148 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
10149 | } |
10150 | ||
10151 | static void | |
10152 | do_vfp_dp_const (void) | |
10153 | { | |
10154 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
00249aaa PB |
10155 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
10156 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
10157 | } |
10158 | ||
10159 | static void | |
10160 | vfp_conv (int srcsize) | |
10161 | { | |
5f1af56b MGD |
10162 | int immbits = srcsize - inst.operands[1].imm; |
10163 | ||
fa94de6b RM |
10164 | if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize)) |
10165 | { | |
5f1af56b | 10166 | /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16. |
477330fc | 10167 | i.e. immbits must be in range 0 - 16. */ |
5f1af56b MGD |
10168 | inst.error = _("immediate value out of range, expected range [0, 16]"); |
10169 | return; | |
10170 | } | |
fa94de6b | 10171 | else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize)) |
5f1af56b MGD |
10172 | { |
10173 | /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32. | |
477330fc | 10174 | i.e. immbits must be in range 0 - 31. */ |
5f1af56b MGD |
10175 | inst.error = _("immediate value out of range, expected range [1, 32]"); |
10176 | return; | |
10177 | } | |
10178 | ||
5287ad62 JB |
10179 | inst.instruction |= (immbits & 1) << 5; |
10180 | inst.instruction |= (immbits >> 1); | |
10181 | } | |
10182 | ||
10183 | static void | |
10184 | do_vfp_sp_conv_16 (void) | |
10185 | { | |
10186 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
10187 | vfp_conv (16); | |
10188 | } | |
10189 | ||
10190 | static void | |
10191 | do_vfp_dp_conv_16 (void) | |
10192 | { | |
10193 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
10194 | vfp_conv (16); | |
10195 | } | |
10196 | ||
10197 | static void | |
10198 | do_vfp_sp_conv_32 (void) | |
10199 | { | |
10200 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
10201 | vfp_conv (32); | |
10202 | } | |
10203 | ||
10204 | static void | |
10205 | do_vfp_dp_conv_32 (void) | |
10206 | { | |
10207 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
10208 | vfp_conv (32); | |
10209 | } | |
c19d1205 ZW |
10210 | \f |
10211 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 10212 | |
c19d1205 ZW |
10213 | static void |
10214 | do_fpa_cmp (void) | |
10215 | { | |
10216 | inst.instruction |= inst.operands[0].reg << 16; | |
10217 | inst.instruction |= inst.operands[1].reg; | |
10218 | } | |
b99bd4ef NC |
10219 | |
10220 | static void | |
c19d1205 | 10221 | do_fpa_ldmstm (void) |
b99bd4ef | 10222 | { |
c19d1205 ZW |
10223 | inst.instruction |= inst.operands[0].reg << 12; |
10224 | switch (inst.operands[1].imm) | |
10225 | { | |
10226 | case 1: inst.instruction |= CP_T_X; break; | |
10227 | case 2: inst.instruction |= CP_T_Y; break; | |
10228 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
10229 | case 4: break; | |
10230 | default: abort (); | |
10231 | } | |
b99bd4ef | 10232 | |
c19d1205 ZW |
10233 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
10234 | { | |
10235 | /* The instruction specified "ea" or "fd", so we can only accept | |
10236 | [Rn]{!}. The instruction does not really support stacking or | |
10237 | unstacking, so we have to emulate these by setting appropriate | |
10238 | bits and offsets. */ | |
e2b0ab59 AV |
10239 | constraint (inst.relocs[0].exp.X_op != O_constant |
10240 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 10241 | _("this instruction does not support indexing")); |
b99bd4ef | 10242 | |
c19d1205 | 10243 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
e2b0ab59 | 10244 | inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm; |
b99bd4ef | 10245 | |
c19d1205 | 10246 | if (!(inst.instruction & INDEX_UP)) |
e2b0ab59 | 10247 | inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number; |
b99bd4ef | 10248 | |
c19d1205 ZW |
10249 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
10250 | { | |
10251 | inst.operands[2].preind = 0; | |
10252 | inst.operands[2].postind = 1; | |
10253 | } | |
10254 | } | |
b99bd4ef | 10255 | |
c19d1205 | 10256 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 10257 | } |
c19d1205 ZW |
10258 | \f |
10259 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 10260 | |
c19d1205 ZW |
10261 | static void |
10262 | do_iwmmxt_tandorc (void) | |
10263 | { | |
10264 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
10265 | } | |
b99bd4ef | 10266 | |
c19d1205 ZW |
10267 | static void |
10268 | do_iwmmxt_textrc (void) | |
10269 | { | |
10270 | inst.instruction |= inst.operands[0].reg << 12; | |
10271 | inst.instruction |= inst.operands[1].imm; | |
10272 | } | |
b99bd4ef NC |
10273 | |
10274 | static void | |
c19d1205 | 10275 | do_iwmmxt_textrm (void) |
b99bd4ef | 10276 | { |
c19d1205 ZW |
10277 | inst.instruction |= inst.operands[0].reg << 12; |
10278 | inst.instruction |= inst.operands[1].reg << 16; | |
10279 | inst.instruction |= inst.operands[2].imm; | |
10280 | } | |
b99bd4ef | 10281 | |
c19d1205 ZW |
10282 | static void |
10283 | do_iwmmxt_tinsr (void) | |
10284 | { | |
10285 | inst.instruction |= inst.operands[0].reg << 16; | |
10286 | inst.instruction |= inst.operands[1].reg << 12; | |
10287 | inst.instruction |= inst.operands[2].imm; | |
10288 | } | |
b99bd4ef | 10289 | |
c19d1205 ZW |
10290 | static void |
10291 | do_iwmmxt_tmia (void) | |
10292 | { | |
10293 | inst.instruction |= inst.operands[0].reg << 5; | |
10294 | inst.instruction |= inst.operands[1].reg; | |
10295 | inst.instruction |= inst.operands[2].reg << 12; | |
10296 | } | |
b99bd4ef | 10297 | |
c19d1205 ZW |
10298 | static void |
10299 | do_iwmmxt_waligni (void) | |
10300 | { | |
10301 | inst.instruction |= inst.operands[0].reg << 12; | |
10302 | inst.instruction |= inst.operands[1].reg << 16; | |
10303 | inst.instruction |= inst.operands[2].reg; | |
10304 | inst.instruction |= inst.operands[3].imm << 20; | |
10305 | } | |
b99bd4ef | 10306 | |
2d447fca JM |
10307 | static void |
10308 | do_iwmmxt_wmerge (void) | |
10309 | { | |
10310 | inst.instruction |= inst.operands[0].reg << 12; | |
10311 | inst.instruction |= inst.operands[1].reg << 16; | |
10312 | inst.instruction |= inst.operands[2].reg; | |
10313 | inst.instruction |= inst.operands[3].imm << 21; | |
10314 | } | |
10315 | ||
c19d1205 ZW |
10316 | static void |
10317 | do_iwmmxt_wmov (void) | |
10318 | { | |
10319 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
10320 | inst.instruction |= inst.operands[0].reg << 12; | |
10321 | inst.instruction |= inst.operands[1].reg << 16; | |
10322 | inst.instruction |= inst.operands[1].reg; | |
10323 | } | |
b99bd4ef | 10324 | |
c19d1205 ZW |
10325 | static void |
10326 | do_iwmmxt_wldstbh (void) | |
10327 | { | |
8f06b2d8 | 10328 | int reloc; |
c19d1205 | 10329 | inst.instruction |= inst.operands[0].reg << 12; |
8f06b2d8 PB |
10330 | if (thumb_mode) |
10331 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
10332 | else | |
10333 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
10334 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
10335 | } |
10336 | ||
c19d1205 ZW |
10337 | static void |
10338 | do_iwmmxt_wldstw (void) | |
10339 | { | |
10340 | /* RIWR_RIWC clears .isreg for a control register. */ | |
10341 | if (!inst.operands[0].isreg) | |
10342 | { | |
10343 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
10344 | inst.instruction |= 0xf0000000; | |
10345 | } | |
b99bd4ef | 10346 | |
c19d1205 ZW |
10347 | inst.instruction |= inst.operands[0].reg << 12; |
10348 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
10349 | } | |
b99bd4ef NC |
10350 | |
10351 | static void | |
c19d1205 | 10352 | do_iwmmxt_wldstd (void) |
b99bd4ef | 10353 | { |
c19d1205 | 10354 | inst.instruction |= inst.operands[0].reg << 12; |
2d447fca JM |
10355 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2) |
10356 | && inst.operands[1].immisreg) | |
10357 | { | |
10358 | inst.instruction &= ~0x1a000ff; | |
eff0bc54 | 10359 | inst.instruction |= (0xfU << 28); |
2d447fca JM |
10360 | if (inst.operands[1].preind) |
10361 | inst.instruction |= PRE_INDEX; | |
10362 | if (!inst.operands[1].negative) | |
10363 | inst.instruction |= INDEX_UP; | |
10364 | if (inst.operands[1].writeback) | |
10365 | inst.instruction |= WRITE_BACK; | |
10366 | inst.instruction |= inst.operands[1].reg << 16; | |
e2b0ab59 | 10367 | inst.instruction |= inst.relocs[0].exp.X_add_number << 4; |
2d447fca JM |
10368 | inst.instruction |= inst.operands[1].imm; |
10369 | } | |
10370 | else | |
10371 | encode_arm_cp_address (1, TRUE, FALSE, 0); | |
c19d1205 | 10372 | } |
b99bd4ef | 10373 | |
c19d1205 ZW |
10374 | static void |
10375 | do_iwmmxt_wshufh (void) | |
10376 | { | |
10377 | inst.instruction |= inst.operands[0].reg << 12; | |
10378 | inst.instruction |= inst.operands[1].reg << 16; | |
10379 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
10380 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
10381 | } | |
b99bd4ef | 10382 | |
c19d1205 ZW |
10383 | static void |
10384 | do_iwmmxt_wzero (void) | |
10385 | { | |
10386 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
10387 | inst.instruction |= inst.operands[0].reg; | |
10388 | inst.instruction |= inst.operands[0].reg << 12; | |
10389 | inst.instruction |= inst.operands[0].reg << 16; | |
10390 | } | |
2d447fca JM |
10391 | |
10392 | static void | |
10393 | do_iwmmxt_wrwrwr_or_imm5 (void) | |
10394 | { | |
10395 | if (inst.operands[2].isreg) | |
10396 | do_rd_rn_rm (); | |
10397 | else { | |
10398 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2), | |
10399 | _("immediate operand requires iWMMXt2")); | |
10400 | do_rd_rn (); | |
10401 | if (inst.operands[2].imm == 0) | |
10402 | { | |
10403 | switch ((inst.instruction >> 20) & 0xf) | |
10404 | { | |
10405 | case 4: | |
10406 | case 5: | |
10407 | case 6: | |
5f4273c7 | 10408 | case 7: |
2d447fca JM |
10409 | /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */ |
10410 | inst.operands[2].imm = 16; | |
10411 | inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20); | |
10412 | break; | |
10413 | case 8: | |
10414 | case 9: | |
10415 | case 10: | |
10416 | case 11: | |
10417 | /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */ | |
10418 | inst.operands[2].imm = 32; | |
10419 | inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20); | |
10420 | break; | |
10421 | case 12: | |
10422 | case 13: | |
10423 | case 14: | |
10424 | case 15: | |
10425 | { | |
10426 | /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */ | |
10427 | unsigned long wrn; | |
10428 | wrn = (inst.instruction >> 16) & 0xf; | |
10429 | inst.instruction &= 0xff0fff0f; | |
10430 | inst.instruction |= wrn; | |
10431 | /* Bail out here; the instruction is now assembled. */ | |
10432 | return; | |
10433 | } | |
10434 | } | |
10435 | } | |
10436 | /* Map 32 -> 0, etc. */ | |
10437 | inst.operands[2].imm &= 0x1f; | |
eff0bc54 | 10438 | inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf); |
2d447fca JM |
10439 | } |
10440 | } | |
c19d1205 ZW |
10441 | \f |
10442 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
10443 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 10444 | |
c19d1205 | 10445 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 10446 | |
c19d1205 ZW |
10447 | static void |
10448 | do_mav_triple (void) | |
10449 | { | |
10450 | inst.instruction |= inst.operands[0].reg << 16; | |
10451 | inst.instruction |= inst.operands[1].reg; | |
10452 | inst.instruction |= inst.operands[2].reg << 12; | |
10453 | } | |
b99bd4ef | 10454 | |
c19d1205 ZW |
10455 | /* Insns like "foo W,X,Y,Z". |
10456 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 10457 | |
c19d1205 ZW |
10458 | static void |
10459 | do_mav_quad (void) | |
10460 | { | |
10461 | inst.instruction |= inst.operands[0].reg << 5; | |
10462 | inst.instruction |= inst.operands[1].reg << 12; | |
10463 | inst.instruction |= inst.operands[2].reg << 16; | |
10464 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
10465 | } |
10466 | ||
c19d1205 ZW |
10467 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
10468 | static void | |
10469 | do_mav_dspsc (void) | |
a737bd4d | 10470 | { |
c19d1205 ZW |
10471 | inst.instruction |= inst.operands[1].reg << 12; |
10472 | } | |
a737bd4d | 10473 | |
c19d1205 ZW |
10474 | /* Maverick shift immediate instructions. |
10475 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
10476 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 10477 | |
c19d1205 ZW |
10478 | static void |
10479 | do_mav_shift (void) | |
10480 | { | |
10481 | int imm = inst.operands[2].imm; | |
a737bd4d | 10482 | |
c19d1205 ZW |
10483 | inst.instruction |= inst.operands[0].reg << 12; |
10484 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 10485 | |
c19d1205 ZW |
10486 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
10487 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
10488 | Bit 4 should be 0. */ | |
10489 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 10490 | |
c19d1205 ZW |
10491 | inst.instruction |= imm; |
10492 | } | |
10493 | \f | |
10494 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 10495 | |
c19d1205 ZW |
10496 | /* Xscale multiply-accumulate (argument parse) |
10497 | MIAcc acc0,Rm,Rs | |
10498 | MIAPHcc acc0,Rm,Rs | |
10499 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 10500 | |
c19d1205 ZW |
10501 | static void |
10502 | do_xsc_mia (void) | |
10503 | { | |
10504 | inst.instruction |= inst.operands[1].reg; | |
10505 | inst.instruction |= inst.operands[2].reg << 12; | |
10506 | } | |
a737bd4d | 10507 | |
c19d1205 | 10508 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 10509 | |
c19d1205 | 10510 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 10511 | |
c19d1205 ZW |
10512 | static void |
10513 | do_xsc_mar (void) | |
10514 | { | |
10515 | inst.instruction |= inst.operands[1].reg << 12; | |
10516 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
10517 | } |
10518 | ||
c19d1205 | 10519 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 10520 | |
c19d1205 | 10521 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
10522 | |
10523 | static void | |
c19d1205 | 10524 | do_xsc_mra (void) |
b99bd4ef | 10525 | { |
c19d1205 ZW |
10526 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
10527 | inst.instruction |= inst.operands[0].reg << 12; | |
10528 | inst.instruction |= inst.operands[1].reg << 16; | |
10529 | } | |
10530 | \f | |
10531 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 10532 | |
c19d1205 ZW |
10533 | /* inst.operands[i] is a shifted-register operand; encode |
10534 | it into inst.instruction in the format used by Thumb32. */ | |
10535 | ||
10536 | static void | |
10537 | encode_thumb32_shifted_operand (int i) | |
10538 | { | |
e2b0ab59 | 10539 | unsigned int value = inst.relocs[0].exp.X_add_number; |
c19d1205 | 10540 | unsigned int shift = inst.operands[i].shift_kind; |
b99bd4ef | 10541 | |
9c3c69f2 PB |
10542 | constraint (inst.operands[i].immisreg, |
10543 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
10544 | inst.instruction |= inst.operands[i].reg; |
10545 | if (shift == SHIFT_RRX) | |
10546 | inst.instruction |= SHIFT_ROR << 4; | |
10547 | else | |
b99bd4ef | 10548 | { |
e2b0ab59 | 10549 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 ZW |
10550 | _("expression too complex")); |
10551 | ||
10552 | constraint (value > 32 | |
10553 | || (value == 32 && (shift == SHIFT_LSL | |
10554 | || shift == SHIFT_ROR)), | |
10555 | _("shift expression is too large")); | |
10556 | ||
10557 | if (value == 0) | |
10558 | shift = SHIFT_LSL; | |
10559 | else if (value == 32) | |
10560 | value = 0; | |
10561 | ||
10562 | inst.instruction |= shift << 4; | |
10563 | inst.instruction |= (value & 0x1c) << 10; | |
10564 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 10565 | } |
c19d1205 | 10566 | } |
b99bd4ef | 10567 | |
b99bd4ef | 10568 | |
c19d1205 ZW |
10569 | /* inst.operands[i] was set up by parse_address. Encode it into a |
10570 | Thumb32 format load or store instruction. Reject forms that cannot | |
10571 | be used with such instructions. If is_t is true, reject forms that | |
10572 | cannot be used with a T instruction; if is_d is true, reject forms | |
5be8be5d DG |
10573 | that cannot be used with a D instruction. If it is a store insn, |
10574 | reject PC in Rn. */ | |
b99bd4ef | 10575 | |
c19d1205 ZW |
10576 | static void |
10577 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
10578 | { | |
5be8be5d | 10579 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
c19d1205 ZW |
10580 | |
10581 | constraint (!inst.operands[i].isreg, | |
53365c0d | 10582 | _("Instruction does not support =N addresses")); |
b99bd4ef | 10583 | |
c19d1205 ZW |
10584 | inst.instruction |= inst.operands[i].reg << 16; |
10585 | if (inst.operands[i].immisreg) | |
b99bd4ef | 10586 | { |
5be8be5d | 10587 | constraint (is_pc, BAD_PC_ADDRESSING); |
c19d1205 ZW |
10588 | constraint (is_t || is_d, _("cannot use register index with this instruction")); |
10589 | constraint (inst.operands[i].negative, | |
10590 | _("Thumb does not support negative register indexing")); | |
10591 | constraint (inst.operands[i].postind, | |
10592 | _("Thumb does not support register post-indexing")); | |
10593 | constraint (inst.operands[i].writeback, | |
10594 | _("Thumb does not support register indexing with writeback")); | |
10595 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
10596 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 10597 | |
f40d1643 | 10598 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 10599 | if (inst.operands[i].shifted) |
b99bd4ef | 10600 | { |
e2b0ab59 | 10601 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 | 10602 | _("expression too complex")); |
e2b0ab59 AV |
10603 | constraint (inst.relocs[0].exp.X_add_number < 0 |
10604 | || inst.relocs[0].exp.X_add_number > 3, | |
c19d1205 | 10605 | _("shift out of range")); |
e2b0ab59 | 10606 | inst.instruction |= inst.relocs[0].exp.X_add_number << 4; |
c19d1205 | 10607 | } |
e2b0ab59 | 10608 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
c19d1205 ZW |
10609 | } |
10610 | else if (inst.operands[i].preind) | |
10611 | { | |
5be8be5d | 10612 | constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK); |
f40d1643 | 10613 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 | 10614 | _("cannot use writeback with this instruction")); |
4755303e WN |
10615 | constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0), |
10616 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
10617 | |
10618 | if (is_d) | |
10619 | { | |
10620 | inst.instruction |= 0x01000000; | |
10621 | if (inst.operands[i].writeback) | |
10622 | inst.instruction |= 0x00200000; | |
b99bd4ef | 10623 | } |
c19d1205 | 10624 | else |
b99bd4ef | 10625 | { |
c19d1205 ZW |
10626 | inst.instruction |= 0x00000c00; |
10627 | if (inst.operands[i].writeback) | |
10628 | inst.instruction |= 0x00000100; | |
b99bd4ef | 10629 | } |
e2b0ab59 | 10630 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 10631 | } |
c19d1205 | 10632 | else if (inst.operands[i].postind) |
b99bd4ef | 10633 | { |
9c2799c2 | 10634 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
10635 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); |
10636 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
10637 | ||
10638 | if (is_d) | |
10639 | inst.instruction |= 0x00200000; | |
10640 | else | |
10641 | inst.instruction |= 0x00000900; | |
e2b0ab59 | 10642 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
c19d1205 ZW |
10643 | } |
10644 | else /* unindexed - only for coprocessor */ | |
10645 | inst.error = _("instruction does not accept unindexed addressing"); | |
10646 | } | |
10647 | ||
10648 | /* Table of Thumb instructions which exist in both 16- and 32-bit | |
10649 | encodings (the latter only in post-V6T2 cores). The index is the | |
10650 | value used in the insns table below. When there is more than one | |
10651 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
10652 | holds variant (1). |
10653 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 | 10654 | #define T16_32_TAB \ |
21d799b5 NC |
10655 | X(_adc, 4140, eb400000), \ |
10656 | X(_adcs, 4140, eb500000), \ | |
10657 | X(_add, 1c00, eb000000), \ | |
10658 | X(_adds, 1c00, eb100000), \ | |
10659 | X(_addi, 0000, f1000000), \ | |
10660 | X(_addis, 0000, f1100000), \ | |
10661 | X(_add_pc,000f, f20f0000), \ | |
10662 | X(_add_sp,000d, f10d0000), \ | |
10663 | X(_adr, 000f, f20f0000), \ | |
10664 | X(_and, 4000, ea000000), \ | |
10665 | X(_ands, 4000, ea100000), \ | |
10666 | X(_asr, 1000, fa40f000), \ | |
10667 | X(_asrs, 1000, fa50f000), \ | |
10668 | X(_b, e000, f000b000), \ | |
10669 | X(_bcond, d000, f0008000), \ | |
4389b29a | 10670 | X(_bf, 0000, f040e001), \ |
f6b2b12d | 10671 | X(_bfcsel,0000, f000e001), \ |
f1c7f421 | 10672 | X(_bfx, 0000, f060e001), \ |
65d1bc05 | 10673 | X(_bfl, 0000, f000c001), \ |
f1c7f421 | 10674 | X(_bflx, 0000, f070e001), \ |
21d799b5 NC |
10675 | X(_bic, 4380, ea200000), \ |
10676 | X(_bics, 4380, ea300000), \ | |
10677 | X(_cmn, 42c0, eb100f00), \ | |
10678 | X(_cmp, 2800, ebb00f00), \ | |
10679 | X(_cpsie, b660, f3af8400), \ | |
10680 | X(_cpsid, b670, f3af8600), \ | |
10681 | X(_cpy, 4600, ea4f0000), \ | |
10682 | X(_dec_sp,80dd, f1ad0d00), \ | |
60f993ce | 10683 | X(_dls, 0000, f040e001), \ |
21d799b5 NC |
10684 | X(_eor, 4040, ea800000), \ |
10685 | X(_eors, 4040, ea900000), \ | |
10686 | X(_inc_sp,00dd, f10d0d00), \ | |
10687 | X(_ldmia, c800, e8900000), \ | |
10688 | X(_ldr, 6800, f8500000), \ | |
10689 | X(_ldrb, 7800, f8100000), \ | |
10690 | X(_ldrh, 8800, f8300000), \ | |
10691 | X(_ldrsb, 5600, f9100000), \ | |
10692 | X(_ldrsh, 5e00, f9300000), \ | |
10693 | X(_ldr_pc,4800, f85f0000), \ | |
10694 | X(_ldr_pc2,4800, f85f0000), \ | |
10695 | X(_ldr_sp,9800, f85d0000), \ | |
60f993ce | 10696 | X(_le, 0000, f00fc001), \ |
21d799b5 NC |
10697 | X(_lsl, 0000, fa00f000), \ |
10698 | X(_lsls, 0000, fa10f000), \ | |
10699 | X(_lsr, 0800, fa20f000), \ | |
10700 | X(_lsrs, 0800, fa30f000), \ | |
10701 | X(_mov, 2000, ea4f0000), \ | |
10702 | X(_movs, 2000, ea5f0000), \ | |
10703 | X(_mul, 4340, fb00f000), \ | |
10704 | X(_muls, 4340, ffffffff), /* no 32b muls */ \ | |
10705 | X(_mvn, 43c0, ea6f0000), \ | |
10706 | X(_mvns, 43c0, ea7f0000), \ | |
10707 | X(_neg, 4240, f1c00000), /* rsb #0 */ \ | |
10708 | X(_negs, 4240, f1d00000), /* rsbs #0 */ \ | |
10709 | X(_orr, 4300, ea400000), \ | |
10710 | X(_orrs, 4300, ea500000), \ | |
10711 | X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \ | |
10712 | X(_push, b400, e92d0000), /* stmdb sp!,... */ \ | |
10713 | X(_rev, ba00, fa90f080), \ | |
10714 | X(_rev16, ba40, fa90f090), \ | |
10715 | X(_revsh, bac0, fa90f0b0), \ | |
10716 | X(_ror, 41c0, fa60f000), \ | |
10717 | X(_rors, 41c0, fa70f000), \ | |
10718 | X(_sbc, 4180, eb600000), \ | |
10719 | X(_sbcs, 4180, eb700000), \ | |
10720 | X(_stmia, c000, e8800000), \ | |
10721 | X(_str, 6000, f8400000), \ | |
10722 | X(_strb, 7000, f8000000), \ | |
10723 | X(_strh, 8000, f8200000), \ | |
10724 | X(_str_sp,9000, f84d0000), \ | |
10725 | X(_sub, 1e00, eba00000), \ | |
10726 | X(_subs, 1e00, ebb00000), \ | |
10727 | X(_subi, 8000, f1a00000), \ | |
10728 | X(_subis, 8000, f1b00000), \ | |
10729 | X(_sxtb, b240, fa4ff080), \ | |
10730 | X(_sxth, b200, fa0ff080), \ | |
10731 | X(_tst, 4200, ea100f00), \ | |
10732 | X(_uxtb, b2c0, fa5ff080), \ | |
10733 | X(_uxth, b280, fa1ff080), \ | |
10734 | X(_nop, bf00, f3af8000), \ | |
10735 | X(_yield, bf10, f3af8001), \ | |
10736 | X(_wfe, bf20, f3af8002), \ | |
10737 | X(_wfi, bf30, f3af8003), \ | |
60f993ce | 10738 | X(_wls, 0000, f040c001), \ |
53c4b28b | 10739 | X(_sev, bf40, f3af8004), \ |
74db7efb NC |
10740 | X(_sevl, bf50, f3af8005), \ |
10741 | X(_udf, de00, f7f0a000) | |
c19d1205 ZW |
10742 | |
10743 | /* To catch errors in encoding functions, the codes are all offset by | |
10744 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
10745 | as 16-bit instructions. */ | |
21d799b5 | 10746 | #define X(a,b,c) T_MNEM##a |
c19d1205 ZW |
10747 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; |
10748 | #undef X | |
10749 | ||
10750 | #define X(a,b,c) 0x##b | |
10751 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
10752 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
10753 | #undef X | |
10754 | ||
10755 | #define X(a,b,c) 0x##c | |
10756 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
c921be7d NC |
10757 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) |
10758 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
c19d1205 ZW |
10759 | #undef X |
10760 | #undef T16_32_TAB | |
10761 | ||
10762 | /* Thumb instruction encoders, in alphabetical order. */ | |
10763 | ||
92e90b6e | 10764 | /* ADDW or SUBW. */ |
c921be7d | 10765 | |
92e90b6e PB |
10766 | static void |
10767 | do_t_add_sub_w (void) | |
10768 | { | |
10769 | int Rd, Rn; | |
10770 | ||
10771 | Rd = inst.operands[0].reg; | |
10772 | Rn = inst.operands[1].reg; | |
10773 | ||
539d4391 NC |
10774 | /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this |
10775 | is the SP-{plus,minus}-immediate form of the instruction. */ | |
10776 | if (Rn == REG_SP) | |
10777 | constraint (Rd == REG_PC, BAD_PC); | |
10778 | else | |
10779 | reject_bad_reg (Rd); | |
fdfde340 | 10780 | |
92e90b6e | 10781 | inst.instruction |= (Rn << 16) | (Rd << 8); |
e2b0ab59 | 10782 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12; |
92e90b6e PB |
10783 | } |
10784 | ||
c19d1205 | 10785 | /* Parse an add or subtract instruction. We get here with inst.instruction |
33eaf5de | 10786 | equaling any of THUMB_OPCODE_add, adds, sub, or subs. */ |
c19d1205 ZW |
10787 | |
10788 | static void | |
10789 | do_t_add_sub (void) | |
10790 | { | |
10791 | int Rd, Rs, Rn; | |
10792 | ||
10793 | Rd = inst.operands[0].reg; | |
10794 | Rs = (inst.operands[1].present | |
10795 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
10796 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
10797 | ||
e07e6e58 NC |
10798 | if (Rd == REG_PC) |
10799 | set_it_insn_type_last (); | |
10800 | ||
c19d1205 ZW |
10801 | if (unified_syntax) |
10802 | { | |
0110f2b8 PB |
10803 | bfd_boolean flags; |
10804 | bfd_boolean narrow; | |
10805 | int opcode; | |
10806 | ||
10807 | flags = (inst.instruction == T_MNEM_adds | |
10808 | || inst.instruction == T_MNEM_subs); | |
10809 | if (flags) | |
e07e6e58 | 10810 | narrow = !in_it_block (); |
0110f2b8 | 10811 | else |
e07e6e58 | 10812 | narrow = in_it_block (); |
c19d1205 | 10813 | if (!inst.operands[2].isreg) |
b99bd4ef | 10814 | { |
16805f35 PB |
10815 | int add; |
10816 | ||
5c8ed6a4 JW |
10817 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
10818 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
fdfde340 | 10819 | |
16805f35 PB |
10820 | add = (inst.instruction == T_MNEM_add |
10821 | || inst.instruction == T_MNEM_adds); | |
0110f2b8 PB |
10822 | opcode = 0; |
10823 | if (inst.size_req != 4) | |
10824 | { | |
0110f2b8 | 10825 | /* Attempt to use a narrow opcode, with relaxation if |
477330fc | 10826 | appropriate. */ |
0110f2b8 PB |
10827 | if (Rd == REG_SP && Rs == REG_SP && !flags) |
10828 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
10829 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
10830 | opcode = T_MNEM_add_sp; | |
10831 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
10832 | opcode = T_MNEM_add_pc; | |
10833 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
10834 | { | |
10835 | if (flags) | |
10836 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
10837 | else | |
10838 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
10839 | } | |
10840 | if (opcode) | |
10841 | { | |
10842 | inst.instruction = THUMB_OP16(opcode); | |
10843 | inst.instruction |= (Rd << 4) | Rs; | |
e2b0ab59 AV |
10844 | if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
10845 | || (inst.relocs[0].type | |
10846 | > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)) | |
a9f02af8 MG |
10847 | { |
10848 | if (inst.size_req == 2) | |
e2b0ab59 | 10849 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD; |
a9f02af8 MG |
10850 | else |
10851 | inst.relax = opcode; | |
10852 | } | |
0110f2b8 PB |
10853 | } |
10854 | else | |
10855 | constraint (inst.size_req == 2, BAD_HIREG); | |
10856 | } | |
10857 | if (inst.size_req == 4 | |
10858 | || (inst.size_req != 2 && !opcode)) | |
10859 | { | |
e2b0ab59 AV |
10860 | constraint ((inst.relocs[0].type |
10861 | >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC) | |
10862 | && (inst.relocs[0].type | |
10863 | <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) , | |
a9f02af8 | 10864 | THUMB1_RELOC_ONLY); |
efd81785 PB |
10865 | if (Rd == REG_PC) |
10866 | { | |
fdfde340 | 10867 | constraint (add, BAD_PC); |
efd81785 PB |
10868 | constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs, |
10869 | _("only SUBS PC, LR, #const allowed")); | |
e2b0ab59 | 10870 | constraint (inst.relocs[0].exp.X_op != O_constant, |
efd81785 | 10871 | _("expression too complex")); |
e2b0ab59 AV |
10872 | constraint (inst.relocs[0].exp.X_add_number < 0 |
10873 | || inst.relocs[0].exp.X_add_number > 0xff, | |
efd81785 PB |
10874 | _("immediate value out of range")); |
10875 | inst.instruction = T2_SUBS_PC_LR | |
e2b0ab59 AV |
10876 | | inst.relocs[0].exp.X_add_number; |
10877 | inst.relocs[0].type = BFD_RELOC_UNUSED; | |
efd81785 PB |
10878 | return; |
10879 | } | |
10880 | else if (Rs == REG_PC) | |
16805f35 PB |
10881 | { |
10882 | /* Always use addw/subw. */ | |
10883 | inst.instruction = add ? 0xf20f0000 : 0xf2af0000; | |
e2b0ab59 | 10884 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12; |
16805f35 PB |
10885 | } |
10886 | else | |
10887 | { | |
10888 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10889 | inst.instruction = (inst.instruction & 0xe1ffffff) | |
10890 | | 0x10000000; | |
10891 | if (flags) | |
e2b0ab59 | 10892 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
16805f35 | 10893 | else |
e2b0ab59 | 10894 | inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM; |
16805f35 | 10895 | } |
dc4503c6 PB |
10896 | inst.instruction |= Rd << 8; |
10897 | inst.instruction |= Rs << 16; | |
0110f2b8 | 10898 | } |
b99bd4ef | 10899 | } |
c19d1205 ZW |
10900 | else |
10901 | { | |
e2b0ab59 | 10902 | unsigned int value = inst.relocs[0].exp.X_add_number; |
5f4cb198 NC |
10903 | unsigned int shift = inst.operands[2].shift_kind; |
10904 | ||
c19d1205 ZW |
10905 | Rn = inst.operands[2].reg; |
10906 | /* See if we can do this with a 16-bit instruction. */ | |
10907 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
10908 | { | |
e27ec89e PB |
10909 | if (Rd > 7 || Rs > 7 || Rn > 7) |
10910 | narrow = FALSE; | |
10911 | ||
10912 | if (narrow) | |
c19d1205 | 10913 | { |
e27ec89e PB |
10914 | inst.instruction = ((inst.instruction == T_MNEM_adds |
10915 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
10916 | ? T_OPCODE_ADD_R3 |
10917 | : T_OPCODE_SUB_R3); | |
10918 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
10919 | return; | |
10920 | } | |
b99bd4ef | 10921 | |
7e806470 | 10922 | if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn)) |
c19d1205 | 10923 | { |
7e806470 PB |
10924 | /* Thumb-1 cores (except v6-M) require at least one high |
10925 | register in a narrow non flag setting add. */ | |
10926 | if (Rd > 7 || Rn > 7 | |
10927 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2) | |
10928 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr)) | |
c19d1205 | 10929 | { |
7e806470 PB |
10930 | if (Rd == Rn) |
10931 | { | |
10932 | Rn = Rs; | |
10933 | Rs = Rd; | |
10934 | } | |
c19d1205 ZW |
10935 | inst.instruction = T_OPCODE_ADD_HI; |
10936 | inst.instruction |= (Rd & 8) << 4; | |
10937 | inst.instruction |= (Rd & 7); | |
10938 | inst.instruction |= Rn << 3; | |
10939 | return; | |
10940 | } | |
c19d1205 ZW |
10941 | } |
10942 | } | |
c921be7d | 10943 | |
fdfde340 | 10944 | constraint (Rd == REG_PC, BAD_PC); |
5c8ed6a4 JW |
10945 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
10946 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
fdfde340 JM |
10947 | constraint (Rs == REG_PC, BAD_PC); |
10948 | reject_bad_reg (Rn); | |
10949 | ||
c19d1205 ZW |
10950 | /* If we get here, it can't be done in 16 bits. */ |
10951 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
10952 | _("shift must be constant")); | |
10953 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10954 | inst.instruction |= Rd << 8; | |
10955 | inst.instruction |= Rs << 16; | |
5f4cb198 NC |
10956 | constraint (Rd == REG_SP && Rs == REG_SP && value > 3, |
10957 | _("shift value over 3 not allowed in thumb mode")); | |
10958 | constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL, | |
10959 | _("only LSL shift allowed in thumb mode")); | |
c19d1205 ZW |
10960 | encode_thumb32_shifted_operand (2); |
10961 | } | |
10962 | } | |
10963 | else | |
10964 | { | |
10965 | constraint (inst.instruction == T_MNEM_adds | |
10966 | || inst.instruction == T_MNEM_subs, | |
10967 | BAD_THUMB32); | |
b99bd4ef | 10968 | |
c19d1205 | 10969 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 10970 | { |
c19d1205 ZW |
10971 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
10972 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
10973 | BAD_HIREG); | |
10974 | ||
10975 | inst.instruction = (inst.instruction == T_MNEM_add | |
10976 | ? 0x0000 : 0x8000); | |
10977 | inst.instruction |= (Rd << 4) | Rs; | |
e2b0ab59 | 10978 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD; |
b99bd4ef NC |
10979 | return; |
10980 | } | |
10981 | ||
c19d1205 ZW |
10982 | Rn = inst.operands[2].reg; |
10983 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 10984 | |
c19d1205 ZW |
10985 | /* We now have Rd, Rs, and Rn set to registers. */ |
10986 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 10987 | { |
c19d1205 ZW |
10988 | /* Can't do this for SUB. */ |
10989 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
10990 | inst.instruction = T_OPCODE_ADD_HI; | |
10991 | inst.instruction |= (Rd & 8) << 4; | |
10992 | inst.instruction |= (Rd & 7); | |
10993 | if (Rs == Rd) | |
10994 | inst.instruction |= Rn << 3; | |
10995 | else if (Rn == Rd) | |
10996 | inst.instruction |= Rs << 3; | |
10997 | else | |
10998 | constraint (1, _("dest must overlap one source register")); | |
10999 | } | |
11000 | else | |
11001 | { | |
11002 | inst.instruction = (inst.instruction == T_MNEM_add | |
11003 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
11004 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 11005 | } |
b99bd4ef | 11006 | } |
b99bd4ef NC |
11007 | } |
11008 | ||
c19d1205 ZW |
11009 | static void |
11010 | do_t_adr (void) | |
11011 | { | |
fdfde340 JM |
11012 | unsigned Rd; |
11013 | ||
11014 | Rd = inst.operands[0].reg; | |
11015 | reject_bad_reg (Rd); | |
11016 | ||
11017 | if (unified_syntax && inst.size_req == 0 && Rd <= 7) | |
0110f2b8 PB |
11018 | { |
11019 | /* Defer to section relaxation. */ | |
11020 | inst.relax = inst.instruction; | |
11021 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 | 11022 | inst.instruction |= Rd << 4; |
0110f2b8 PB |
11023 | } |
11024 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 11025 | { |
0110f2b8 | 11026 | /* Generate a 32-bit opcode. */ |
e9f89963 | 11027 | inst.instruction = THUMB_OP32 (inst.instruction); |
fdfde340 | 11028 | inst.instruction |= Rd << 8; |
e2b0ab59 AV |
11029 | inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12; |
11030 | inst.relocs[0].pc_rel = 1; | |
e9f89963 PB |
11031 | } |
11032 | else | |
11033 | { | |
0110f2b8 | 11034 | /* Generate a 16-bit opcode. */ |
e9f89963 | 11035 | inst.instruction = THUMB_OP16 (inst.instruction); |
e2b0ab59 AV |
11036 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD; |
11037 | inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */ | |
11038 | inst.relocs[0].pc_rel = 1; | |
fdfde340 | 11039 | inst.instruction |= Rd << 4; |
e9f89963 | 11040 | } |
52a86f84 | 11041 | |
e2b0ab59 AV |
11042 | if (inst.relocs[0].exp.X_op == O_symbol |
11043 | && inst.relocs[0].exp.X_add_symbol != NULL | |
11044 | && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol) | |
11045 | && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol)) | |
11046 | inst.relocs[0].exp.X_add_number += 1; | |
c19d1205 | 11047 | } |
b99bd4ef | 11048 | |
c19d1205 ZW |
11049 | /* Arithmetic instructions for which there is just one 16-bit |
11050 | instruction encoding, and it allows only two low registers. | |
11051 | For maximal compatibility with ARM syntax, we allow three register | |
11052 | operands even when Thumb-32 instructions are not available, as long | |
11053 | as the first two are identical. For instance, both "sbc r0,r1" and | |
11054 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 11055 | static void |
c19d1205 | 11056 | do_t_arit3 (void) |
b99bd4ef | 11057 | { |
c19d1205 | 11058 | int Rd, Rs, Rn; |
b99bd4ef | 11059 | |
c19d1205 ZW |
11060 | Rd = inst.operands[0].reg; |
11061 | Rs = (inst.operands[1].present | |
11062 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
11063 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
11064 | Rn = inst.operands[2].reg; | |
b99bd4ef | 11065 | |
fdfde340 JM |
11066 | reject_bad_reg (Rd); |
11067 | reject_bad_reg (Rs); | |
11068 | if (inst.operands[2].isreg) | |
11069 | reject_bad_reg (Rn); | |
11070 | ||
c19d1205 | 11071 | if (unified_syntax) |
b99bd4ef | 11072 | { |
c19d1205 ZW |
11073 | if (!inst.operands[2].isreg) |
11074 | { | |
11075 | /* For an immediate, we always generate a 32-bit opcode; | |
11076 | section relaxation will shrink it later if possible. */ | |
11077 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11078 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
11079 | inst.instruction |= Rd << 8; | |
11080 | inst.instruction |= Rs << 16; | |
e2b0ab59 | 11081 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
c19d1205 ZW |
11082 | } |
11083 | else | |
11084 | { | |
e27ec89e PB |
11085 | bfd_boolean narrow; |
11086 | ||
c19d1205 | 11087 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 11088 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 11089 | narrow = !in_it_block (); |
e27ec89e | 11090 | else |
e07e6e58 | 11091 | narrow = in_it_block (); |
e27ec89e PB |
11092 | |
11093 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
11094 | narrow = FALSE; | |
11095 | if (inst.operands[2].shifted) | |
11096 | narrow = FALSE; | |
11097 | if (inst.size_req == 4) | |
11098 | narrow = FALSE; | |
11099 | ||
11100 | if (narrow | |
c19d1205 ZW |
11101 | && Rd == Rs) |
11102 | { | |
11103 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11104 | inst.instruction |= Rd; | |
11105 | inst.instruction |= Rn << 3; | |
11106 | return; | |
11107 | } | |
b99bd4ef | 11108 | |
c19d1205 ZW |
11109 | /* If we get here, it can't be done in 16 bits. */ |
11110 | constraint (inst.operands[2].shifted | |
11111 | && inst.operands[2].immisreg, | |
11112 | _("shift must be constant")); | |
11113 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11114 | inst.instruction |= Rd << 8; | |
11115 | inst.instruction |= Rs << 16; | |
11116 | encode_thumb32_shifted_operand (2); | |
11117 | } | |
a737bd4d | 11118 | } |
c19d1205 | 11119 | else |
b99bd4ef | 11120 | { |
c19d1205 ZW |
11121 | /* On its face this is a lie - the instruction does set the |
11122 | flags. However, the only supported mnemonic in this mode | |
11123 | says it doesn't. */ | |
11124 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 11125 | |
c19d1205 ZW |
11126 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
11127 | _("unshifted register required")); | |
11128 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
11129 | constraint (Rd != Rs, | |
11130 | _("dest and source1 must be the same register")); | |
a737bd4d | 11131 | |
c19d1205 ZW |
11132 | inst.instruction = THUMB_OP16 (inst.instruction); |
11133 | inst.instruction |= Rd; | |
11134 | inst.instruction |= Rn << 3; | |
b99bd4ef | 11135 | } |
a737bd4d | 11136 | } |
b99bd4ef | 11137 | |
c19d1205 ZW |
11138 | /* Similarly, but for instructions where the arithmetic operation is |
11139 | commutative, so we can allow either of them to be different from | |
11140 | the destination operand in a 16-bit instruction. For instance, all | |
11141 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
11142 | accepted. */ | |
11143 | static void | |
11144 | do_t_arit3c (void) | |
a737bd4d | 11145 | { |
c19d1205 | 11146 | int Rd, Rs, Rn; |
b99bd4ef | 11147 | |
c19d1205 ZW |
11148 | Rd = inst.operands[0].reg; |
11149 | Rs = (inst.operands[1].present | |
11150 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
11151 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
11152 | Rn = inst.operands[2].reg; | |
c921be7d | 11153 | |
fdfde340 JM |
11154 | reject_bad_reg (Rd); |
11155 | reject_bad_reg (Rs); | |
11156 | if (inst.operands[2].isreg) | |
11157 | reject_bad_reg (Rn); | |
a737bd4d | 11158 | |
c19d1205 | 11159 | if (unified_syntax) |
a737bd4d | 11160 | { |
c19d1205 | 11161 | if (!inst.operands[2].isreg) |
b99bd4ef | 11162 | { |
c19d1205 ZW |
11163 | /* For an immediate, we always generate a 32-bit opcode; |
11164 | section relaxation will shrink it later if possible. */ | |
11165 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11166 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
11167 | inst.instruction |= Rd << 8; | |
11168 | inst.instruction |= Rs << 16; | |
e2b0ab59 | 11169 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 11170 | } |
c19d1205 | 11171 | else |
a737bd4d | 11172 | { |
e27ec89e PB |
11173 | bfd_boolean narrow; |
11174 | ||
c19d1205 | 11175 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 11176 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 11177 | narrow = !in_it_block (); |
e27ec89e | 11178 | else |
e07e6e58 | 11179 | narrow = in_it_block (); |
e27ec89e PB |
11180 | |
11181 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
11182 | narrow = FALSE; | |
11183 | if (inst.operands[2].shifted) | |
11184 | narrow = FALSE; | |
11185 | if (inst.size_req == 4) | |
11186 | narrow = FALSE; | |
11187 | ||
11188 | if (narrow) | |
a737bd4d | 11189 | { |
c19d1205 | 11190 | if (Rd == Rs) |
a737bd4d | 11191 | { |
c19d1205 ZW |
11192 | inst.instruction = THUMB_OP16 (inst.instruction); |
11193 | inst.instruction |= Rd; | |
11194 | inst.instruction |= Rn << 3; | |
11195 | return; | |
a737bd4d | 11196 | } |
c19d1205 | 11197 | if (Rd == Rn) |
a737bd4d | 11198 | { |
c19d1205 ZW |
11199 | inst.instruction = THUMB_OP16 (inst.instruction); |
11200 | inst.instruction |= Rd; | |
11201 | inst.instruction |= Rs << 3; | |
11202 | return; | |
a737bd4d NC |
11203 | } |
11204 | } | |
c19d1205 ZW |
11205 | |
11206 | /* If we get here, it can't be done in 16 bits. */ | |
11207 | constraint (inst.operands[2].shifted | |
11208 | && inst.operands[2].immisreg, | |
11209 | _("shift must be constant")); | |
11210 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11211 | inst.instruction |= Rd << 8; | |
11212 | inst.instruction |= Rs << 16; | |
11213 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 11214 | } |
b99bd4ef | 11215 | } |
c19d1205 ZW |
11216 | else |
11217 | { | |
11218 | /* On its face this is a lie - the instruction does set the | |
11219 | flags. However, the only supported mnemonic in this mode | |
11220 | says it doesn't. */ | |
11221 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 11222 | |
c19d1205 ZW |
11223 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
11224 | _("unshifted register required")); | |
11225 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
11226 | ||
11227 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11228 | inst.instruction |= Rd; | |
11229 | ||
11230 | if (Rd == Rs) | |
11231 | inst.instruction |= Rn << 3; | |
11232 | else if (Rd == Rn) | |
11233 | inst.instruction |= Rs << 3; | |
11234 | else | |
11235 | constraint (1, _("dest must overlap one source register")); | |
11236 | } | |
a737bd4d NC |
11237 | } |
11238 | ||
c19d1205 ZW |
11239 | static void |
11240 | do_t_bfc (void) | |
a737bd4d | 11241 | { |
fdfde340 | 11242 | unsigned Rd; |
c19d1205 ZW |
11243 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
11244 | constraint (msb > 32, _("bit-field extends past end of register")); | |
11245 | /* The instruction encoding stores the LSB and MSB, | |
11246 | not the LSB and width. */ | |
fdfde340 JM |
11247 | Rd = inst.operands[0].reg; |
11248 | reject_bad_reg (Rd); | |
11249 | inst.instruction |= Rd << 8; | |
c19d1205 ZW |
11250 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; |
11251 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
11252 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
11253 | } |
11254 | ||
c19d1205 ZW |
11255 | static void |
11256 | do_t_bfi (void) | |
b99bd4ef | 11257 | { |
fdfde340 | 11258 | int Rd, Rn; |
c19d1205 | 11259 | unsigned int msb; |
b99bd4ef | 11260 | |
fdfde340 JM |
11261 | Rd = inst.operands[0].reg; |
11262 | reject_bad_reg (Rd); | |
11263 | ||
c19d1205 ZW |
11264 | /* #0 in second position is alternative syntax for bfc, which is |
11265 | the same instruction but with REG_PC in the Rm field. */ | |
11266 | if (!inst.operands[1].isreg) | |
fdfde340 JM |
11267 | Rn = REG_PC; |
11268 | else | |
11269 | { | |
11270 | Rn = inst.operands[1].reg; | |
11271 | reject_bad_reg (Rn); | |
11272 | } | |
b99bd4ef | 11273 | |
c19d1205 ZW |
11274 | msb = inst.operands[2].imm + inst.operands[3].imm; |
11275 | constraint (msb > 32, _("bit-field extends past end of register")); | |
11276 | /* The instruction encoding stores the LSB and MSB, | |
11277 | not the LSB and width. */ | |
fdfde340 JM |
11278 | inst.instruction |= Rd << 8; |
11279 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
11280 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
11281 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
11282 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
11283 | } |
11284 | ||
c19d1205 ZW |
11285 | static void |
11286 | do_t_bfx (void) | |
b99bd4ef | 11287 | { |
fdfde340 JM |
11288 | unsigned Rd, Rn; |
11289 | ||
11290 | Rd = inst.operands[0].reg; | |
11291 | Rn = inst.operands[1].reg; | |
11292 | ||
11293 | reject_bad_reg (Rd); | |
11294 | reject_bad_reg (Rn); | |
11295 | ||
c19d1205 ZW |
11296 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
11297 | _("bit-field extends past end of register")); | |
fdfde340 JM |
11298 | inst.instruction |= Rd << 8; |
11299 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
11300 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
11301 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
11302 | inst.instruction |= inst.operands[3].imm - 1; | |
11303 | } | |
b99bd4ef | 11304 | |
c19d1205 ZW |
11305 | /* ARM V5 Thumb BLX (argument parse) |
11306 | BLX <target_addr> which is BLX(1) | |
11307 | BLX <Rm> which is BLX(2) | |
11308 | Unfortunately, there are two different opcodes for this mnemonic. | |
11309 | So, the insns[].value is not used, and the code here zaps values | |
11310 | into inst.instruction. | |
b99bd4ef | 11311 | |
c19d1205 ZW |
11312 | ??? How to take advantage of the additional two bits of displacement |
11313 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 11314 | |
c19d1205 ZW |
11315 | static void |
11316 | do_t_blx (void) | |
11317 | { | |
e07e6e58 NC |
11318 | set_it_insn_type_last (); |
11319 | ||
c19d1205 | 11320 | if (inst.operands[0].isreg) |
fdfde340 JM |
11321 | { |
11322 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); | |
11323 | /* We have a register, so this is BLX(2). */ | |
11324 | inst.instruction |= inst.operands[0].reg << 3; | |
11325 | } | |
b99bd4ef NC |
11326 | else |
11327 | { | |
c19d1205 | 11328 | /* No register. This must be BLX(1). */ |
2fc8bdac | 11329 | inst.instruction = 0xf000e800; |
0855e32b | 11330 | encode_branch (BFD_RELOC_THUMB_PCREL_BLX); |
b99bd4ef NC |
11331 | } |
11332 | } | |
11333 | ||
c19d1205 ZW |
11334 | static void |
11335 | do_t_branch (void) | |
b99bd4ef | 11336 | { |
0110f2b8 | 11337 | int opcode; |
dfa9f0d5 | 11338 | int cond; |
2fe88214 | 11339 | bfd_reloc_code_real_type reloc; |
dfa9f0d5 | 11340 | |
e07e6e58 NC |
11341 | cond = inst.cond; |
11342 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); | |
11343 | ||
11344 | if (in_it_block ()) | |
dfa9f0d5 PB |
11345 | { |
11346 | /* Conditional branches inside IT blocks are encoded as unconditional | |
477330fc | 11347 | branches. */ |
dfa9f0d5 | 11348 | cond = COND_ALWAYS; |
dfa9f0d5 PB |
11349 | } |
11350 | else | |
11351 | cond = inst.cond; | |
11352 | ||
11353 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
11354 | opcode = T_MNEM_bcond; |
11355 | else | |
11356 | opcode = inst.instruction; | |
11357 | ||
12d6b0b7 RS |
11358 | if (unified_syntax |
11359 | && (inst.size_req == 4 | |
10960bfb PB |
11360 | || (inst.size_req != 2 |
11361 | && (inst.operands[0].hasreloc | |
e2b0ab59 | 11362 | || inst.relocs[0].exp.X_op == O_constant)))) |
c19d1205 | 11363 | { |
0110f2b8 | 11364 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 11365 | if (cond == COND_ALWAYS) |
9ae92b05 | 11366 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
11367 | else |
11368 | { | |
ff8646ee TP |
11369 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2), |
11370 | _("selected architecture does not support " | |
11371 | "wide conditional branch instruction")); | |
11372 | ||
9c2799c2 | 11373 | gas_assert (cond != 0xF); |
dfa9f0d5 | 11374 | inst.instruction |= cond << 22; |
9ae92b05 | 11375 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH20; |
c19d1205 ZW |
11376 | } |
11377 | } | |
b99bd4ef NC |
11378 | else |
11379 | { | |
0110f2b8 | 11380 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 11381 | if (cond == COND_ALWAYS) |
9ae92b05 | 11382 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH12; |
c19d1205 | 11383 | else |
b99bd4ef | 11384 | { |
dfa9f0d5 | 11385 | inst.instruction |= cond << 8; |
9ae92b05 | 11386 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 11387 | } |
0110f2b8 PB |
11388 | /* Allow section relaxation. */ |
11389 | if (unified_syntax && inst.size_req != 2) | |
11390 | inst.relax = opcode; | |
b99bd4ef | 11391 | } |
e2b0ab59 AV |
11392 | inst.relocs[0].type = reloc; |
11393 | inst.relocs[0].pc_rel = 1; | |
b99bd4ef NC |
11394 | } |
11395 | ||
8884b720 | 11396 | /* Actually do the work for Thumb state bkpt and hlt. The only difference |
bacebabc | 11397 | between the two is the maximum immediate allowed - which is passed in |
8884b720 | 11398 | RANGE. */ |
b99bd4ef | 11399 | static void |
8884b720 | 11400 | do_t_bkpt_hlt1 (int range) |
b99bd4ef | 11401 | { |
dfa9f0d5 PB |
11402 | constraint (inst.cond != COND_ALWAYS, |
11403 | _("instruction is always unconditional")); | |
c19d1205 | 11404 | if (inst.operands[0].present) |
b99bd4ef | 11405 | { |
8884b720 | 11406 | constraint (inst.operands[0].imm > range, |
c19d1205 ZW |
11407 | _("immediate value out of range")); |
11408 | inst.instruction |= inst.operands[0].imm; | |
b99bd4ef | 11409 | } |
8884b720 MGD |
11410 | |
11411 | set_it_insn_type (NEUTRAL_IT_INSN); | |
11412 | } | |
11413 | ||
11414 | static void | |
11415 | do_t_hlt (void) | |
11416 | { | |
11417 | do_t_bkpt_hlt1 (63); | |
11418 | } | |
11419 | ||
11420 | static void | |
11421 | do_t_bkpt (void) | |
11422 | { | |
11423 | do_t_bkpt_hlt1 (255); | |
b99bd4ef NC |
11424 | } |
11425 | ||
11426 | static void | |
c19d1205 | 11427 | do_t_branch23 (void) |
b99bd4ef | 11428 | { |
e07e6e58 | 11429 | set_it_insn_type_last (); |
0855e32b | 11430 | encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23); |
fa94de6b | 11431 | |
0855e32b NS |
11432 | /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in |
11433 | this file. We used to simply ignore the PLT reloc type here -- | |
11434 | the branch encoding is now needed to deal with TLSCALL relocs. | |
11435 | So if we see a PLT reloc now, put it back to how it used to be to | |
11436 | keep the preexisting behaviour. */ | |
e2b0ab59 AV |
11437 | if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32) |
11438 | inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
90e4755a | 11439 | |
4343666d | 11440 | #if defined(OBJ_COFF) |
c19d1205 ZW |
11441 | /* If the destination of the branch is a defined symbol which does not have |
11442 | the THUMB_FUNC attribute, then we must be calling a function which has | |
11443 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
11444 | function and change the branch to refer to that function instead. */ | |
e2b0ab59 AV |
11445 | if ( inst.relocs[0].exp.X_op == O_symbol |
11446 | && inst.relocs[0].exp.X_add_symbol != NULL | |
11447 | && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol) | |
11448 | && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol)) | |
11449 | inst.relocs[0].exp.X_add_symbol | |
11450 | = find_real_start (inst.relocs[0].exp.X_add_symbol); | |
4343666d | 11451 | #endif |
90e4755a RE |
11452 | } |
11453 | ||
11454 | static void | |
c19d1205 | 11455 | do_t_bx (void) |
90e4755a | 11456 | { |
e07e6e58 | 11457 | set_it_insn_type_last (); |
c19d1205 ZW |
11458 | inst.instruction |= inst.operands[0].reg << 3; |
11459 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
11460 | should cause the alignment to be checked once it is known. This is | |
11461 | because BX PC only works if the instruction is word aligned. */ | |
11462 | } | |
90e4755a | 11463 | |
c19d1205 ZW |
11464 | static void |
11465 | do_t_bxj (void) | |
11466 | { | |
fdfde340 | 11467 | int Rm; |
90e4755a | 11468 | |
e07e6e58 | 11469 | set_it_insn_type_last (); |
fdfde340 JM |
11470 | Rm = inst.operands[0].reg; |
11471 | reject_bad_reg (Rm); | |
11472 | inst.instruction |= Rm << 16; | |
90e4755a RE |
11473 | } |
11474 | ||
11475 | static void | |
c19d1205 | 11476 | do_t_clz (void) |
90e4755a | 11477 | { |
fdfde340 JM |
11478 | unsigned Rd; |
11479 | unsigned Rm; | |
11480 | ||
11481 | Rd = inst.operands[0].reg; | |
11482 | Rm = inst.operands[1].reg; | |
11483 | ||
11484 | reject_bad_reg (Rd); | |
11485 | reject_bad_reg (Rm); | |
11486 | ||
11487 | inst.instruction |= Rd << 8; | |
11488 | inst.instruction |= Rm << 16; | |
11489 | inst.instruction |= Rm; | |
c19d1205 | 11490 | } |
90e4755a | 11491 | |
91d8b670 JG |
11492 | static void |
11493 | do_t_csdb (void) | |
11494 | { | |
11495 | set_it_insn_type (OUTSIDE_IT_INSN); | |
11496 | } | |
11497 | ||
dfa9f0d5 PB |
11498 | static void |
11499 | do_t_cps (void) | |
11500 | { | |
e07e6e58 | 11501 | set_it_insn_type (OUTSIDE_IT_INSN); |
dfa9f0d5 PB |
11502 | inst.instruction |= inst.operands[0].imm; |
11503 | } | |
11504 | ||
c19d1205 ZW |
11505 | static void |
11506 | do_t_cpsi (void) | |
11507 | { | |
e07e6e58 | 11508 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 | 11509 | if (unified_syntax |
62b3e311 PB |
11510 | && (inst.operands[1].present || inst.size_req == 4) |
11511 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 11512 | { |
c19d1205 ZW |
11513 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
11514 | inst.instruction = 0xf3af8000; | |
11515 | inst.instruction |= imod << 9; | |
11516 | inst.instruction |= inst.operands[0].imm << 5; | |
11517 | if (inst.operands[1].present) | |
11518 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 11519 | } |
c19d1205 | 11520 | else |
90e4755a | 11521 | { |
62b3e311 PB |
11522 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1) |
11523 | && (inst.operands[0].imm & 4), | |
11524 | _("selected processor does not support 'A' form " | |
11525 | "of this instruction")); | |
11526 | constraint (inst.operands[1].present || inst.size_req == 4, | |
c19d1205 ZW |
11527 | _("Thumb does not support the 2-argument " |
11528 | "form of this instruction")); | |
11529 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 11530 | } |
90e4755a RE |
11531 | } |
11532 | ||
c19d1205 ZW |
11533 | /* THUMB CPY instruction (argument parse). */ |
11534 | ||
90e4755a | 11535 | static void |
c19d1205 | 11536 | do_t_cpy (void) |
90e4755a | 11537 | { |
c19d1205 | 11538 | if (inst.size_req == 4) |
90e4755a | 11539 | { |
c19d1205 ZW |
11540 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
11541 | inst.instruction |= inst.operands[0].reg << 8; | |
11542 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 11543 | } |
c19d1205 | 11544 | else |
90e4755a | 11545 | { |
c19d1205 ZW |
11546 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
11547 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
11548 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 11549 | } |
90e4755a RE |
11550 | } |
11551 | ||
90e4755a | 11552 | static void |
25fe350b | 11553 | do_t_cbz (void) |
90e4755a | 11554 | { |
e07e6e58 | 11555 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
11556 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
11557 | inst.instruction |= inst.operands[0].reg; | |
e2b0ab59 AV |
11558 | inst.relocs[0].pc_rel = 1; |
11559 | inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
c19d1205 | 11560 | } |
90e4755a | 11561 | |
62b3e311 PB |
11562 | static void |
11563 | do_t_dbg (void) | |
11564 | { | |
11565 | inst.instruction |= inst.operands[0].imm; | |
11566 | } | |
11567 | ||
11568 | static void | |
11569 | do_t_div (void) | |
11570 | { | |
fdfde340 JM |
11571 | unsigned Rd, Rn, Rm; |
11572 | ||
11573 | Rd = inst.operands[0].reg; | |
11574 | Rn = (inst.operands[1].present | |
11575 | ? inst.operands[1].reg : Rd); | |
11576 | Rm = inst.operands[2].reg; | |
11577 | ||
11578 | reject_bad_reg (Rd); | |
11579 | reject_bad_reg (Rn); | |
11580 | reject_bad_reg (Rm); | |
11581 | ||
11582 | inst.instruction |= Rd << 8; | |
11583 | inst.instruction |= Rn << 16; | |
11584 | inst.instruction |= Rm; | |
62b3e311 PB |
11585 | } |
11586 | ||
c19d1205 ZW |
11587 | static void |
11588 | do_t_hint (void) | |
11589 | { | |
11590 | if (unified_syntax && inst.size_req == 4) | |
11591 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11592 | else | |
11593 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11594 | } | |
90e4755a | 11595 | |
c19d1205 ZW |
11596 | static void |
11597 | do_t_it (void) | |
11598 | { | |
11599 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 11600 | |
e07e6e58 NC |
11601 | set_it_insn_type (IT_INSN); |
11602 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
11603 | now_it.cc = cond; | |
5a01bb1d | 11604 | now_it.warn_deprecated = FALSE; |
e27ec89e PB |
11605 | |
11606 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 11607 | if ((cond & 0x1) == 0x0) |
90e4755a | 11608 | { |
c19d1205 | 11609 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 11610 | |
c19d1205 | 11611 | if ((mask & 0x7) == 0) |
5a01bb1d MGD |
11612 | { |
11613 | /* No conversion needed. */ | |
11614 | now_it.block_length = 1; | |
11615 | } | |
c19d1205 | 11616 | else if ((mask & 0x3) == 0) |
5a01bb1d MGD |
11617 | { |
11618 | mask ^= 0x8; | |
11619 | now_it.block_length = 2; | |
11620 | } | |
e27ec89e | 11621 | else if ((mask & 0x1) == 0) |
5a01bb1d MGD |
11622 | { |
11623 | mask ^= 0xC; | |
11624 | now_it.block_length = 3; | |
11625 | } | |
c19d1205 | 11626 | else |
5a01bb1d MGD |
11627 | { |
11628 | mask ^= 0xE; | |
11629 | now_it.block_length = 4; | |
11630 | } | |
90e4755a | 11631 | |
e27ec89e PB |
11632 | inst.instruction &= 0xfff0; |
11633 | inst.instruction |= mask; | |
c19d1205 | 11634 | } |
90e4755a | 11635 | |
c19d1205 ZW |
11636 | inst.instruction |= cond << 4; |
11637 | } | |
90e4755a | 11638 | |
3c707909 PB |
11639 | /* Helper function used for both push/pop and ldm/stm. */ |
11640 | static void | |
4b5a202f AV |
11641 | encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask, |
11642 | bfd_boolean writeback) | |
3c707909 | 11643 | { |
4b5a202f | 11644 | bfd_boolean load, store; |
3c707909 | 11645 | |
4b5a202f AV |
11646 | gas_assert (base != -1 || !do_io); |
11647 | load = do_io && ((inst.instruction & (1 << 20)) != 0); | |
11648 | store = do_io && !load; | |
3c707909 PB |
11649 | |
11650 | if (mask & (1 << 13)) | |
11651 | inst.error = _("SP not allowed in register list"); | |
1e5b0379 | 11652 | |
4b5a202f | 11653 | if (do_io && (mask & (1 << base)) != 0 |
1e5b0379 NC |
11654 | && writeback) |
11655 | inst.error = _("having the base register in the register list when " | |
11656 | "using write back is UNPREDICTABLE"); | |
11657 | ||
3c707909 PB |
11658 | if (load) |
11659 | { | |
e07e6e58 | 11660 | if (mask & (1 << 15)) |
477330fc RM |
11661 | { |
11662 | if (mask & (1 << 14)) | |
11663 | inst.error = _("LR and PC should not both be in register list"); | |
11664 | else | |
11665 | set_it_insn_type_last (); | |
11666 | } | |
3c707909 | 11667 | } |
4b5a202f | 11668 | else if (store) |
3c707909 PB |
11669 | { |
11670 | if (mask & (1 << 15)) | |
11671 | inst.error = _("PC not allowed in register list"); | |
3c707909 PB |
11672 | } |
11673 | ||
4b5a202f | 11674 | if (do_io && ((mask & (mask - 1)) == 0)) |
3c707909 PB |
11675 | { |
11676 | /* Single register transfers implemented as str/ldr. */ | |
11677 | if (writeback) | |
11678 | { | |
11679 | if (inst.instruction & (1 << 23)) | |
11680 | inst.instruction = 0x00000b04; /* ia! -> [base], #4 */ | |
11681 | else | |
11682 | inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */ | |
11683 | } | |
11684 | else | |
11685 | { | |
11686 | if (inst.instruction & (1 << 23)) | |
11687 | inst.instruction = 0x00800000; /* ia -> [base] */ | |
11688 | else | |
11689 | inst.instruction = 0x00000c04; /* db -> [base, #-4] */ | |
11690 | } | |
11691 | ||
11692 | inst.instruction |= 0xf8400000; | |
11693 | if (load) | |
11694 | inst.instruction |= 0x00100000; | |
11695 | ||
5f4273c7 | 11696 | mask = ffs (mask) - 1; |
3c707909 PB |
11697 | mask <<= 12; |
11698 | } | |
11699 | else if (writeback) | |
11700 | inst.instruction |= WRITE_BACK; | |
11701 | ||
11702 | inst.instruction |= mask; | |
4b5a202f AV |
11703 | if (do_io) |
11704 | inst.instruction |= base << 16; | |
3c707909 PB |
11705 | } |
11706 | ||
c19d1205 ZW |
11707 | static void |
11708 | do_t_ldmstm (void) | |
11709 | { | |
11710 | /* This really doesn't seem worth it. */ | |
e2b0ab59 | 11711 | constraint (inst.relocs[0].type != BFD_RELOC_UNUSED, |
c19d1205 ZW |
11712 | _("expression too complex")); |
11713 | constraint (inst.operands[1].writeback, | |
11714 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 11715 | |
c19d1205 ZW |
11716 | if (unified_syntax) |
11717 | { | |
3c707909 PB |
11718 | bfd_boolean narrow; |
11719 | unsigned mask; | |
11720 | ||
11721 | narrow = FALSE; | |
c19d1205 ZW |
11722 | /* See if we can use a 16-bit instruction. */ |
11723 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
11724 | && inst.size_req != 4 | |
3c707909 | 11725 | && !(inst.operands[1].imm & ~0xff)) |
90e4755a | 11726 | { |
3c707909 | 11727 | mask = 1 << inst.operands[0].reg; |
90e4755a | 11728 | |
eab4f823 | 11729 | if (inst.operands[0].reg <= 7) |
90e4755a | 11730 | { |
3c707909 | 11731 | if (inst.instruction == T_MNEM_stmia |
eab4f823 MGD |
11732 | ? inst.operands[0].writeback |
11733 | : (inst.operands[0].writeback | |
11734 | == !(inst.operands[1].imm & mask))) | |
477330fc | 11735 | { |
eab4f823 MGD |
11736 | if (inst.instruction == T_MNEM_stmia |
11737 | && (inst.operands[1].imm & mask) | |
11738 | && (inst.operands[1].imm & (mask - 1))) | |
11739 | as_warn (_("value stored for r%d is UNKNOWN"), | |
11740 | inst.operands[0].reg); | |
3c707909 | 11741 | |
eab4f823 MGD |
11742 | inst.instruction = THUMB_OP16 (inst.instruction); |
11743 | inst.instruction |= inst.operands[0].reg << 8; | |
11744 | inst.instruction |= inst.operands[1].imm; | |
11745 | narrow = TRUE; | |
11746 | } | |
11747 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
11748 | { | |
11749 | /* This means 1 register in reg list one of 3 situations: | |
11750 | 1. Instruction is stmia, but without writeback. | |
11751 | 2. lmdia without writeback, but with Rn not in | |
477330fc | 11752 | reglist. |
eab4f823 MGD |
11753 | 3. ldmia with writeback, but with Rn in reglist. |
11754 | Case 3 is UNPREDICTABLE behaviour, so we handle | |
11755 | case 1 and 2 which can be converted into a 16-bit | |
11756 | str or ldr. The SP cases are handled below. */ | |
11757 | unsigned long opcode; | |
11758 | /* First, record an error for Case 3. */ | |
11759 | if (inst.operands[1].imm & mask | |
11760 | && inst.operands[0].writeback) | |
fa94de6b | 11761 | inst.error = |
eab4f823 MGD |
11762 | _("having the base register in the register list when " |
11763 | "using write back is UNPREDICTABLE"); | |
fa94de6b RM |
11764 | |
11765 | opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str | |
eab4f823 MGD |
11766 | : T_MNEM_ldr); |
11767 | inst.instruction = THUMB_OP16 (opcode); | |
11768 | inst.instruction |= inst.operands[0].reg << 3; | |
11769 | inst.instruction |= (ffs (inst.operands[1].imm)-1); | |
11770 | narrow = TRUE; | |
11771 | } | |
90e4755a | 11772 | } |
eab4f823 | 11773 | else if (inst.operands[0] .reg == REG_SP) |
90e4755a | 11774 | { |
eab4f823 MGD |
11775 | if (inst.operands[0].writeback) |
11776 | { | |
fa94de6b | 11777 | inst.instruction = |
eab4f823 | 11778 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
477330fc | 11779 | ? T_MNEM_push : T_MNEM_pop); |
eab4f823 | 11780 | inst.instruction |= inst.operands[1].imm; |
477330fc | 11781 | narrow = TRUE; |
eab4f823 MGD |
11782 | } |
11783 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
11784 | { | |
fa94de6b | 11785 | inst.instruction = |
eab4f823 | 11786 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
477330fc | 11787 | ? T_MNEM_str_sp : T_MNEM_ldr_sp); |
eab4f823 | 11788 | inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8); |
477330fc | 11789 | narrow = TRUE; |
eab4f823 | 11790 | } |
90e4755a | 11791 | } |
3c707909 PB |
11792 | } |
11793 | ||
11794 | if (!narrow) | |
11795 | { | |
c19d1205 ZW |
11796 | if (inst.instruction < 0xffff) |
11797 | inst.instruction = THUMB_OP32 (inst.instruction); | |
3c707909 | 11798 | |
4b5a202f AV |
11799 | encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg, |
11800 | inst.operands[1].imm, | |
11801 | inst.operands[0].writeback); | |
90e4755a RE |
11802 | } |
11803 | } | |
c19d1205 | 11804 | else |
90e4755a | 11805 | { |
c19d1205 ZW |
11806 | constraint (inst.operands[0].reg > 7 |
11807 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
1198ca51 PB |
11808 | constraint (inst.instruction != T_MNEM_ldmia |
11809 | && inst.instruction != T_MNEM_stmia, | |
11810 | _("Thumb-2 instruction only valid in unified syntax")); | |
c19d1205 | 11811 | if (inst.instruction == T_MNEM_stmia) |
f03698e6 | 11812 | { |
c19d1205 ZW |
11813 | if (!inst.operands[0].writeback) |
11814 | as_warn (_("this instruction will write back the base register")); | |
11815 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
11816 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
1e5b0379 | 11817 | as_warn (_("value stored for r%d is UNKNOWN"), |
c19d1205 | 11818 | inst.operands[0].reg); |
f03698e6 | 11819 | } |
c19d1205 | 11820 | else |
90e4755a | 11821 | { |
c19d1205 ZW |
11822 | if (!inst.operands[0].writeback |
11823 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
11824 | as_warn (_("this instruction will write back the base register")); | |
11825 | else if (inst.operands[0].writeback | |
11826 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
11827 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
11828 | } |
11829 | ||
c19d1205 ZW |
11830 | inst.instruction = THUMB_OP16 (inst.instruction); |
11831 | inst.instruction |= inst.operands[0].reg << 8; | |
11832 | inst.instruction |= inst.operands[1].imm; | |
11833 | } | |
11834 | } | |
e28cd48c | 11835 | |
c19d1205 ZW |
11836 | static void |
11837 | do_t_ldrex (void) | |
11838 | { | |
11839 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
11840 | || inst.operands[1].postind || inst.operands[1].writeback | |
11841 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
11842 | || inst.operands[1].negative, | |
01cfc07f | 11843 | BAD_ADDR_MODE); |
e28cd48c | 11844 | |
5be8be5d DG |
11845 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
11846 | ||
c19d1205 ZW |
11847 | inst.instruction |= inst.operands[0].reg << 12; |
11848 | inst.instruction |= inst.operands[1].reg << 16; | |
e2b0ab59 | 11849 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8; |
c19d1205 | 11850 | } |
e28cd48c | 11851 | |
c19d1205 ZW |
11852 | static void |
11853 | do_t_ldrexd (void) | |
11854 | { | |
11855 | if (!inst.operands[1].present) | |
1cac9012 | 11856 | { |
c19d1205 ZW |
11857 | constraint (inst.operands[0].reg == REG_LR, |
11858 | _("r14 not allowed as first register " | |
11859 | "when second register is omitted")); | |
11860 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 11861 | } |
c19d1205 ZW |
11862 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
11863 | BAD_OVERLAP); | |
b99bd4ef | 11864 | |
c19d1205 ZW |
11865 | inst.instruction |= inst.operands[0].reg << 12; |
11866 | inst.instruction |= inst.operands[1].reg << 8; | |
11867 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
11868 | } |
11869 | ||
11870 | static void | |
c19d1205 | 11871 | do_t_ldst (void) |
b99bd4ef | 11872 | { |
0110f2b8 PB |
11873 | unsigned long opcode; |
11874 | int Rn; | |
11875 | ||
e07e6e58 NC |
11876 | if (inst.operands[0].isreg |
11877 | && !inst.operands[0].preind | |
11878 | && inst.operands[0].reg == REG_PC) | |
11879 | set_it_insn_type_last (); | |
11880 | ||
0110f2b8 | 11881 | opcode = inst.instruction; |
c19d1205 | 11882 | if (unified_syntax) |
b99bd4ef | 11883 | { |
53365c0d PB |
11884 | if (!inst.operands[1].isreg) |
11885 | { | |
11886 | if (opcode <= 0xffff) | |
11887 | inst.instruction = THUMB_OP32 (opcode); | |
8335d6aa | 11888 | if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE)) |
53365c0d PB |
11889 | return; |
11890 | } | |
0110f2b8 PB |
11891 | if (inst.operands[1].isreg |
11892 | && !inst.operands[1].writeback | |
c19d1205 ZW |
11893 | && !inst.operands[1].shifted && !inst.operands[1].postind |
11894 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
11895 | && opcode <= 0xffff |
11896 | && inst.size_req != 4) | |
c19d1205 | 11897 | { |
0110f2b8 PB |
11898 | /* Insn may have a 16-bit form. */ |
11899 | Rn = inst.operands[1].reg; | |
11900 | if (inst.operands[1].immisreg) | |
11901 | { | |
11902 | inst.instruction = THUMB_OP16 (opcode); | |
5f4273c7 | 11903 | /* [Rn, Rik] */ |
0110f2b8 PB |
11904 | if (Rn <= 7 && inst.operands[1].imm <= 7) |
11905 | goto op16; | |
5be8be5d DG |
11906 | else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str) |
11907 | reject_bad_reg (inst.operands[1].imm); | |
0110f2b8 PB |
11908 | } |
11909 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
11910 | && opcode != T_MNEM_ldrsb) | |
11911 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
11912 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
11913 | { | |
11914 | /* [Rn, #const] */ | |
11915 | if (Rn > 7) | |
11916 | { | |
11917 | if (Rn == REG_PC) | |
11918 | { | |
e2b0ab59 | 11919 | if (inst.relocs[0].pc_rel) |
0110f2b8 PB |
11920 | opcode = T_MNEM_ldr_pc2; |
11921 | else | |
11922 | opcode = T_MNEM_ldr_pc; | |
11923 | } | |
11924 | else | |
11925 | { | |
11926 | if (opcode == T_MNEM_ldr) | |
11927 | opcode = T_MNEM_ldr_sp; | |
11928 | else | |
11929 | opcode = T_MNEM_str_sp; | |
11930 | } | |
11931 | inst.instruction = inst.operands[0].reg << 8; | |
11932 | } | |
11933 | else | |
11934 | { | |
11935 | inst.instruction = inst.operands[0].reg; | |
11936 | inst.instruction |= inst.operands[1].reg << 3; | |
11937 | } | |
11938 | inst.instruction |= THUMB_OP16 (opcode); | |
11939 | if (inst.size_req == 2) | |
e2b0ab59 | 11940 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET; |
0110f2b8 PB |
11941 | else |
11942 | inst.relax = opcode; | |
11943 | return; | |
11944 | } | |
c19d1205 | 11945 | } |
0110f2b8 | 11946 | /* Definitely a 32-bit variant. */ |
5be8be5d | 11947 | |
8d67f500 NC |
11948 | /* Warning for Erratum 752419. */ |
11949 | if (opcode == T_MNEM_ldr | |
11950 | && inst.operands[0].reg == REG_SP | |
11951 | && inst.operands[1].writeback == 1 | |
11952 | && !inst.operands[1].immisreg) | |
11953 | { | |
11954 | if (no_cpu_selected () | |
11955 | || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7) | |
477330fc RM |
11956 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a) |
11957 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r))) | |
8d67f500 NC |
11958 | as_warn (_("This instruction may be unpredictable " |
11959 | "if executed on M-profile cores " | |
11960 | "with interrupts enabled.")); | |
11961 | } | |
11962 | ||
5be8be5d | 11963 | /* Do some validations regarding addressing modes. */ |
1be5fd2e | 11964 | if (inst.operands[1].immisreg) |
5be8be5d DG |
11965 | reject_bad_reg (inst.operands[1].imm); |
11966 | ||
1be5fd2e NC |
11967 | constraint (inst.operands[1].writeback == 1 |
11968 | && inst.operands[0].reg == inst.operands[1].reg, | |
11969 | BAD_OVERLAP); | |
11970 | ||
0110f2b8 | 11971 | inst.instruction = THUMB_OP32 (opcode); |
c19d1205 ZW |
11972 | inst.instruction |= inst.operands[0].reg << 12; |
11973 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
1be5fd2e | 11974 | check_ldr_r15_aligned (); |
b99bd4ef NC |
11975 | return; |
11976 | } | |
11977 | ||
c19d1205 ZW |
11978 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
11979 | ||
11980 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 11981 | { |
c19d1205 ZW |
11982 | /* Only [Rn,Rm] is acceptable. */ |
11983 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
11984 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
11985 | || inst.operands[1].postind || inst.operands[1].shifted | |
11986 | || inst.operands[1].negative, | |
11987 | _("Thumb does not support this addressing mode")); | |
11988 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11989 | goto op16; | |
b99bd4ef | 11990 | } |
5f4273c7 | 11991 | |
c19d1205 ZW |
11992 | inst.instruction = THUMB_OP16 (inst.instruction); |
11993 | if (!inst.operands[1].isreg) | |
8335d6aa | 11994 | if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE)) |
c19d1205 | 11995 | return; |
b99bd4ef | 11996 | |
c19d1205 ZW |
11997 | constraint (!inst.operands[1].preind |
11998 | || inst.operands[1].shifted | |
11999 | || inst.operands[1].writeback, | |
12000 | _("Thumb does not support this addressing mode")); | |
12001 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 12002 | { |
c19d1205 ZW |
12003 | constraint (inst.instruction & 0x0600, |
12004 | _("byte or halfword not valid for base register")); | |
12005 | constraint (inst.operands[1].reg == REG_PC | |
12006 | && !(inst.instruction & THUMB_LOAD_BIT), | |
12007 | _("r15 based store not allowed")); | |
12008 | constraint (inst.operands[1].immisreg, | |
12009 | _("invalid base register for register offset")); | |
b99bd4ef | 12010 | |
c19d1205 ZW |
12011 | if (inst.operands[1].reg == REG_PC) |
12012 | inst.instruction = T_OPCODE_LDR_PC; | |
12013 | else if (inst.instruction & THUMB_LOAD_BIT) | |
12014 | inst.instruction = T_OPCODE_LDR_SP; | |
12015 | else | |
12016 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 12017 | |
c19d1205 | 12018 | inst.instruction |= inst.operands[0].reg << 8; |
e2b0ab59 | 12019 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET; |
c19d1205 ZW |
12020 | return; |
12021 | } | |
90e4755a | 12022 | |
c19d1205 ZW |
12023 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
12024 | if (!inst.operands[1].immisreg) | |
12025 | { | |
12026 | /* Immediate offset. */ | |
12027 | inst.instruction |= inst.operands[0].reg; | |
12028 | inst.instruction |= inst.operands[1].reg << 3; | |
e2b0ab59 | 12029 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET; |
c19d1205 ZW |
12030 | return; |
12031 | } | |
90e4755a | 12032 | |
c19d1205 ZW |
12033 | /* Register offset. */ |
12034 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
12035 | constraint (inst.operands[1].negative, | |
12036 | _("Thumb does not support this addressing mode")); | |
90e4755a | 12037 | |
c19d1205 ZW |
12038 | op16: |
12039 | switch (inst.instruction) | |
12040 | { | |
12041 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
12042 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
12043 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
12044 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
12045 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
12046 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
12047 | case 0x5600 /* ldrsb */: | |
12048 | case 0x5e00 /* ldrsh */: break; | |
12049 | default: abort (); | |
12050 | } | |
90e4755a | 12051 | |
c19d1205 ZW |
12052 | inst.instruction |= inst.operands[0].reg; |
12053 | inst.instruction |= inst.operands[1].reg << 3; | |
12054 | inst.instruction |= inst.operands[1].imm << 6; | |
12055 | } | |
90e4755a | 12056 | |
c19d1205 ZW |
12057 | static void |
12058 | do_t_ldstd (void) | |
12059 | { | |
12060 | if (!inst.operands[1].present) | |
b99bd4ef | 12061 | { |
c19d1205 ZW |
12062 | inst.operands[1].reg = inst.operands[0].reg + 1; |
12063 | constraint (inst.operands[0].reg == REG_LR, | |
12064 | _("r14 not allowed here")); | |
bd340a04 | 12065 | constraint (inst.operands[0].reg == REG_R12, |
477330fc | 12066 | _("r12 not allowed here")); |
b99bd4ef | 12067 | } |
bd340a04 MGD |
12068 | |
12069 | if (inst.operands[2].writeback | |
12070 | && (inst.operands[0].reg == inst.operands[2].reg | |
12071 | || inst.operands[1].reg == inst.operands[2].reg)) | |
12072 | as_warn (_("base register written back, and overlaps " | |
477330fc | 12073 | "one of transfer registers")); |
bd340a04 | 12074 | |
c19d1205 ZW |
12075 | inst.instruction |= inst.operands[0].reg << 12; |
12076 | inst.instruction |= inst.operands[1].reg << 8; | |
12077 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
b99bd4ef NC |
12078 | } |
12079 | ||
c19d1205 ZW |
12080 | static void |
12081 | do_t_ldstt (void) | |
12082 | { | |
12083 | inst.instruction |= inst.operands[0].reg << 12; | |
12084 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
12085 | } | |
a737bd4d | 12086 | |
b99bd4ef | 12087 | static void |
c19d1205 | 12088 | do_t_mla (void) |
b99bd4ef | 12089 | { |
fdfde340 | 12090 | unsigned Rd, Rn, Rm, Ra; |
c921be7d | 12091 | |
fdfde340 JM |
12092 | Rd = inst.operands[0].reg; |
12093 | Rn = inst.operands[1].reg; | |
12094 | Rm = inst.operands[2].reg; | |
12095 | Ra = inst.operands[3].reg; | |
12096 | ||
12097 | reject_bad_reg (Rd); | |
12098 | reject_bad_reg (Rn); | |
12099 | reject_bad_reg (Rm); | |
12100 | reject_bad_reg (Ra); | |
12101 | ||
12102 | inst.instruction |= Rd << 8; | |
12103 | inst.instruction |= Rn << 16; | |
12104 | inst.instruction |= Rm; | |
12105 | inst.instruction |= Ra << 12; | |
c19d1205 | 12106 | } |
b99bd4ef | 12107 | |
c19d1205 ZW |
12108 | static void |
12109 | do_t_mlal (void) | |
12110 | { | |
fdfde340 JM |
12111 | unsigned RdLo, RdHi, Rn, Rm; |
12112 | ||
12113 | RdLo = inst.operands[0].reg; | |
12114 | RdHi = inst.operands[1].reg; | |
12115 | Rn = inst.operands[2].reg; | |
12116 | Rm = inst.operands[3].reg; | |
12117 | ||
12118 | reject_bad_reg (RdLo); | |
12119 | reject_bad_reg (RdHi); | |
12120 | reject_bad_reg (Rn); | |
12121 | reject_bad_reg (Rm); | |
12122 | ||
12123 | inst.instruction |= RdLo << 12; | |
12124 | inst.instruction |= RdHi << 8; | |
12125 | inst.instruction |= Rn << 16; | |
12126 | inst.instruction |= Rm; | |
c19d1205 | 12127 | } |
b99bd4ef | 12128 | |
c19d1205 ZW |
12129 | static void |
12130 | do_t_mov_cmp (void) | |
12131 | { | |
fdfde340 JM |
12132 | unsigned Rn, Rm; |
12133 | ||
12134 | Rn = inst.operands[0].reg; | |
12135 | Rm = inst.operands[1].reg; | |
12136 | ||
e07e6e58 NC |
12137 | if (Rn == REG_PC) |
12138 | set_it_insn_type_last (); | |
12139 | ||
c19d1205 | 12140 | if (unified_syntax) |
b99bd4ef | 12141 | { |
c19d1205 ZW |
12142 | int r0off = (inst.instruction == T_MNEM_mov |
12143 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 12144 | unsigned long opcode; |
3d388997 PB |
12145 | bfd_boolean narrow; |
12146 | bfd_boolean low_regs; | |
12147 | ||
fdfde340 | 12148 | low_regs = (Rn <= 7 && Rm <= 7); |
0110f2b8 | 12149 | opcode = inst.instruction; |
e07e6e58 | 12150 | if (in_it_block ()) |
0110f2b8 | 12151 | narrow = opcode != T_MNEM_movs; |
3d388997 | 12152 | else |
0110f2b8 | 12153 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
12154 | if (inst.size_req == 4 |
12155 | || inst.operands[1].shifted) | |
12156 | narrow = FALSE; | |
12157 | ||
efd81785 PB |
12158 | /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */ |
12159 | if (opcode == T_MNEM_movs && inst.operands[1].isreg | |
12160 | && !inst.operands[1].shifted | |
fdfde340 JM |
12161 | && Rn == REG_PC |
12162 | && Rm == REG_LR) | |
efd81785 PB |
12163 | { |
12164 | inst.instruction = T2_SUBS_PC_LR; | |
12165 | return; | |
12166 | } | |
12167 | ||
fdfde340 JM |
12168 | if (opcode == T_MNEM_cmp) |
12169 | { | |
12170 | constraint (Rn == REG_PC, BAD_PC); | |
94206790 MM |
12171 | if (narrow) |
12172 | { | |
12173 | /* In the Thumb-2 ISA, use of R13 as Rm is deprecated, | |
12174 | but valid. */ | |
12175 | warn_deprecated_sp (Rm); | |
12176 | /* R15 was documented as a valid choice for Rm in ARMv6, | |
12177 | but as UNPREDICTABLE in ARMv7. ARM's proprietary | |
12178 | tools reject R15, so we do too. */ | |
12179 | constraint (Rm == REG_PC, BAD_PC); | |
12180 | } | |
12181 | else | |
12182 | reject_bad_reg (Rm); | |
fdfde340 JM |
12183 | } |
12184 | else if (opcode == T_MNEM_mov | |
12185 | || opcode == T_MNEM_movs) | |
12186 | { | |
12187 | if (inst.operands[1].isreg) | |
12188 | { | |
12189 | if (opcode == T_MNEM_movs) | |
12190 | { | |
12191 | reject_bad_reg (Rn); | |
12192 | reject_bad_reg (Rm); | |
12193 | } | |
76fa04a4 MGD |
12194 | else if (narrow) |
12195 | { | |
12196 | /* This is mov.n. */ | |
12197 | if ((Rn == REG_SP || Rn == REG_PC) | |
12198 | && (Rm == REG_SP || Rm == REG_PC)) | |
12199 | { | |
5c3696f8 | 12200 | as_tsktsk (_("Use of r%u as a source register is " |
76fa04a4 MGD |
12201 | "deprecated when r%u is the destination " |
12202 | "register."), Rm, Rn); | |
12203 | } | |
12204 | } | |
12205 | else | |
12206 | { | |
12207 | /* This is mov.w. */ | |
12208 | constraint (Rn == REG_PC, BAD_PC); | |
12209 | constraint (Rm == REG_PC, BAD_PC); | |
5c8ed6a4 JW |
12210 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
12211 | constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP); | |
76fa04a4 | 12212 | } |
fdfde340 JM |
12213 | } |
12214 | else | |
12215 | reject_bad_reg (Rn); | |
12216 | } | |
12217 | ||
c19d1205 ZW |
12218 | if (!inst.operands[1].isreg) |
12219 | { | |
0110f2b8 | 12220 | /* Immediate operand. */ |
e07e6e58 | 12221 | if (!in_it_block () && opcode == T_MNEM_mov) |
0110f2b8 PB |
12222 | narrow = 0; |
12223 | if (low_regs && narrow) | |
12224 | { | |
12225 | inst.instruction = THUMB_OP16 (opcode); | |
fdfde340 | 12226 | inst.instruction |= Rn << 8; |
e2b0ab59 AV |
12227 | if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
12228 | || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) | |
72d98d16 | 12229 | { |
a9f02af8 | 12230 | if (inst.size_req == 2) |
e2b0ab59 | 12231 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM; |
a9f02af8 MG |
12232 | else |
12233 | inst.relax = opcode; | |
72d98d16 | 12234 | } |
0110f2b8 PB |
12235 | } |
12236 | else | |
12237 | { | |
e2b0ab59 AV |
12238 | constraint ((inst.relocs[0].type |
12239 | >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC) | |
12240 | && (inst.relocs[0].type | |
12241 | <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) , | |
a9f02af8 MG |
12242 | THUMB1_RELOC_ONLY); |
12243 | ||
0110f2b8 PB |
12244 | inst.instruction = THUMB_OP32 (inst.instruction); |
12245 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 12246 | inst.instruction |= Rn << r0off; |
e2b0ab59 | 12247 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
0110f2b8 | 12248 | } |
c19d1205 | 12249 | } |
728ca7c9 PB |
12250 | else if (inst.operands[1].shifted && inst.operands[1].immisreg |
12251 | && (inst.instruction == T_MNEM_mov | |
12252 | || inst.instruction == T_MNEM_movs)) | |
12253 | { | |
12254 | /* Register shifts are encoded as separate shift instructions. */ | |
12255 | bfd_boolean flags = (inst.instruction == T_MNEM_movs); | |
12256 | ||
e07e6e58 | 12257 | if (in_it_block ()) |
728ca7c9 PB |
12258 | narrow = !flags; |
12259 | else | |
12260 | narrow = flags; | |
12261 | ||
12262 | if (inst.size_req == 4) | |
12263 | narrow = FALSE; | |
12264 | ||
12265 | if (!low_regs || inst.operands[1].imm > 7) | |
12266 | narrow = FALSE; | |
12267 | ||
fdfde340 | 12268 | if (Rn != Rm) |
728ca7c9 PB |
12269 | narrow = FALSE; |
12270 | ||
12271 | switch (inst.operands[1].shift_kind) | |
12272 | { | |
12273 | case SHIFT_LSL: | |
12274 | opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl); | |
12275 | break; | |
12276 | case SHIFT_ASR: | |
12277 | opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr); | |
12278 | break; | |
12279 | case SHIFT_LSR: | |
12280 | opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr); | |
12281 | break; | |
12282 | case SHIFT_ROR: | |
12283 | opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror); | |
12284 | break; | |
12285 | default: | |
5f4273c7 | 12286 | abort (); |
728ca7c9 PB |
12287 | } |
12288 | ||
12289 | inst.instruction = opcode; | |
12290 | if (narrow) | |
12291 | { | |
fdfde340 | 12292 | inst.instruction |= Rn; |
728ca7c9 PB |
12293 | inst.instruction |= inst.operands[1].imm << 3; |
12294 | } | |
12295 | else | |
12296 | { | |
12297 | if (flags) | |
12298 | inst.instruction |= CONDS_BIT; | |
12299 | ||
fdfde340 JM |
12300 | inst.instruction |= Rn << 8; |
12301 | inst.instruction |= Rm << 16; | |
728ca7c9 PB |
12302 | inst.instruction |= inst.operands[1].imm; |
12303 | } | |
12304 | } | |
3d388997 | 12305 | else if (!narrow) |
c19d1205 | 12306 | { |
728ca7c9 PB |
12307 | /* Some mov with immediate shift have narrow variants. |
12308 | Register shifts are handled above. */ | |
12309 | if (low_regs && inst.operands[1].shifted | |
12310 | && (inst.instruction == T_MNEM_mov | |
12311 | || inst.instruction == T_MNEM_movs)) | |
12312 | { | |
e07e6e58 | 12313 | if (in_it_block ()) |
728ca7c9 PB |
12314 | narrow = (inst.instruction == T_MNEM_mov); |
12315 | else | |
12316 | narrow = (inst.instruction == T_MNEM_movs); | |
12317 | } | |
12318 | ||
12319 | if (narrow) | |
12320 | { | |
12321 | switch (inst.operands[1].shift_kind) | |
12322 | { | |
12323 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
12324 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
12325 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; | |
12326 | default: narrow = FALSE; break; | |
12327 | } | |
12328 | } | |
12329 | ||
12330 | if (narrow) | |
12331 | { | |
fdfde340 JM |
12332 | inst.instruction |= Rn; |
12333 | inst.instruction |= Rm << 3; | |
e2b0ab59 | 12334 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT; |
728ca7c9 PB |
12335 | } |
12336 | else | |
12337 | { | |
12338 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 12339 | inst.instruction |= Rn << r0off; |
728ca7c9 PB |
12340 | encode_thumb32_shifted_operand (1); |
12341 | } | |
c19d1205 ZW |
12342 | } |
12343 | else | |
12344 | switch (inst.instruction) | |
12345 | { | |
12346 | case T_MNEM_mov: | |
837b3435 | 12347 | /* In v4t or v5t a move of two lowregs produces unpredictable |
c6400f8a MGD |
12348 | results. Don't allow this. */ |
12349 | if (low_regs) | |
12350 | { | |
12351 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6), | |
12352 | "MOV Rd, Rs with two low registers is not " | |
12353 | "permitted on this architecture"); | |
fa94de6b | 12354 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
c6400f8a MGD |
12355 | arm_ext_v6); |
12356 | } | |
12357 | ||
c19d1205 | 12358 | inst.instruction = T_OPCODE_MOV_HR; |
fdfde340 JM |
12359 | inst.instruction |= (Rn & 0x8) << 4; |
12360 | inst.instruction |= (Rn & 0x7); | |
12361 | inst.instruction |= Rm << 3; | |
c19d1205 | 12362 | break; |
b99bd4ef | 12363 | |
c19d1205 ZW |
12364 | case T_MNEM_movs: |
12365 | /* We know we have low registers at this point. | |
941a8a52 MGD |
12366 | Generate LSLS Rd, Rs, #0. */ |
12367 | inst.instruction = T_OPCODE_LSL_I; | |
fdfde340 JM |
12368 | inst.instruction |= Rn; |
12369 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
12370 | break; |
12371 | ||
12372 | case T_MNEM_cmp: | |
3d388997 | 12373 | if (low_regs) |
c19d1205 ZW |
12374 | { |
12375 | inst.instruction = T_OPCODE_CMP_LR; | |
fdfde340 JM |
12376 | inst.instruction |= Rn; |
12377 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
12378 | } |
12379 | else | |
12380 | { | |
12381 | inst.instruction = T_OPCODE_CMP_HR; | |
fdfde340 JM |
12382 | inst.instruction |= (Rn & 0x8) << 4; |
12383 | inst.instruction |= (Rn & 0x7); | |
12384 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
12385 | } |
12386 | break; | |
12387 | } | |
b99bd4ef NC |
12388 | return; |
12389 | } | |
12390 | ||
c19d1205 | 12391 | inst.instruction = THUMB_OP16 (inst.instruction); |
539d4391 NC |
12392 | |
12393 | /* PR 10443: Do not silently ignore shifted operands. */ | |
12394 | constraint (inst.operands[1].shifted, | |
12395 | _("shifts in CMP/MOV instructions are only supported in unified syntax")); | |
12396 | ||
c19d1205 | 12397 | if (inst.operands[1].isreg) |
b99bd4ef | 12398 | { |
fdfde340 | 12399 | if (Rn < 8 && Rm < 8) |
b99bd4ef | 12400 | { |
c19d1205 ZW |
12401 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
12402 | since a MOV instruction produces unpredictable results. */ | |
12403 | if (inst.instruction == T_OPCODE_MOV_I8) | |
12404 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 12405 | else |
c19d1205 | 12406 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 12407 | |
fdfde340 JM |
12408 | inst.instruction |= Rn; |
12409 | inst.instruction |= Rm << 3; | |
b99bd4ef NC |
12410 | } |
12411 | else | |
12412 | { | |
c19d1205 ZW |
12413 | if (inst.instruction == T_OPCODE_MOV_I8) |
12414 | inst.instruction = T_OPCODE_MOV_HR; | |
12415 | else | |
12416 | inst.instruction = T_OPCODE_CMP_HR; | |
12417 | do_t_cpy (); | |
b99bd4ef NC |
12418 | } |
12419 | } | |
c19d1205 | 12420 | else |
b99bd4ef | 12421 | { |
fdfde340 | 12422 | constraint (Rn > 7, |
c19d1205 | 12423 | _("only lo regs allowed with immediate")); |
fdfde340 | 12424 | inst.instruction |= Rn << 8; |
e2b0ab59 | 12425 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM; |
c19d1205 ZW |
12426 | } |
12427 | } | |
b99bd4ef | 12428 | |
c19d1205 ZW |
12429 | static void |
12430 | do_t_mov16 (void) | |
12431 | { | |
fdfde340 | 12432 | unsigned Rd; |
b6895b4f PB |
12433 | bfd_vma imm; |
12434 | bfd_boolean top; | |
12435 | ||
12436 | top = (inst.instruction & 0x00800000) != 0; | |
e2b0ab59 | 12437 | if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW) |
b6895b4f | 12438 | { |
33eaf5de | 12439 | constraint (top, _(":lower16: not allowed in this instruction")); |
e2b0ab59 | 12440 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW; |
b6895b4f | 12441 | } |
e2b0ab59 | 12442 | else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT) |
b6895b4f | 12443 | { |
33eaf5de | 12444 | constraint (!top, _(":upper16: not allowed in this instruction")); |
e2b0ab59 | 12445 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT; |
b6895b4f PB |
12446 | } |
12447 | ||
fdfde340 JM |
12448 | Rd = inst.operands[0].reg; |
12449 | reject_bad_reg (Rd); | |
12450 | ||
12451 | inst.instruction |= Rd << 8; | |
e2b0ab59 | 12452 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
b6895b4f | 12453 | { |
e2b0ab59 | 12454 | imm = inst.relocs[0].exp.X_add_number; |
b6895b4f PB |
12455 | inst.instruction |= (imm & 0xf000) << 4; |
12456 | inst.instruction |= (imm & 0x0800) << 15; | |
12457 | inst.instruction |= (imm & 0x0700) << 4; | |
12458 | inst.instruction |= (imm & 0x00ff); | |
12459 | } | |
c19d1205 | 12460 | } |
b99bd4ef | 12461 | |
c19d1205 ZW |
12462 | static void |
12463 | do_t_mvn_tst (void) | |
12464 | { | |
fdfde340 | 12465 | unsigned Rn, Rm; |
c921be7d | 12466 | |
fdfde340 JM |
12467 | Rn = inst.operands[0].reg; |
12468 | Rm = inst.operands[1].reg; | |
12469 | ||
12470 | if (inst.instruction == T_MNEM_cmp | |
12471 | || inst.instruction == T_MNEM_cmn) | |
12472 | constraint (Rn == REG_PC, BAD_PC); | |
12473 | else | |
12474 | reject_bad_reg (Rn); | |
12475 | reject_bad_reg (Rm); | |
12476 | ||
c19d1205 ZW |
12477 | if (unified_syntax) |
12478 | { | |
12479 | int r0off = (inst.instruction == T_MNEM_mvn | |
12480 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
12481 | bfd_boolean narrow; |
12482 | ||
12483 | if (inst.size_req == 4 | |
12484 | || inst.instruction > 0xffff | |
12485 | || inst.operands[1].shifted | |
fdfde340 | 12486 | || Rn > 7 || Rm > 7) |
3d388997 | 12487 | narrow = FALSE; |
fe8b4cc3 KT |
12488 | else if (inst.instruction == T_MNEM_cmn |
12489 | || inst.instruction == T_MNEM_tst) | |
3d388997 PB |
12490 | narrow = TRUE; |
12491 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 12492 | narrow = !in_it_block (); |
3d388997 | 12493 | else |
e07e6e58 | 12494 | narrow = in_it_block (); |
3d388997 | 12495 | |
c19d1205 | 12496 | if (!inst.operands[1].isreg) |
b99bd4ef | 12497 | { |
c19d1205 ZW |
12498 | /* For an immediate, we always generate a 32-bit opcode; |
12499 | section relaxation will shrink it later if possible. */ | |
12500 | if (inst.instruction < 0xffff) | |
12501 | inst.instruction = THUMB_OP32 (inst.instruction); | |
12502 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 12503 | inst.instruction |= Rn << r0off; |
e2b0ab59 | 12504 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 12505 | } |
c19d1205 | 12506 | else |
b99bd4ef | 12507 | { |
c19d1205 | 12508 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 12509 | if (narrow) |
b99bd4ef | 12510 | { |
c19d1205 | 12511 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
12512 | inst.instruction |= Rn; |
12513 | inst.instruction |= Rm << 3; | |
b99bd4ef | 12514 | } |
c19d1205 | 12515 | else |
b99bd4ef | 12516 | { |
c19d1205 ZW |
12517 | constraint (inst.operands[1].shifted |
12518 | && inst.operands[1].immisreg, | |
12519 | _("shift must be constant")); | |
12520 | if (inst.instruction < 0xffff) | |
12521 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 12522 | inst.instruction |= Rn << r0off; |
c19d1205 | 12523 | encode_thumb32_shifted_operand (1); |
b99bd4ef | 12524 | } |
b99bd4ef NC |
12525 | } |
12526 | } | |
12527 | else | |
12528 | { | |
c19d1205 ZW |
12529 | constraint (inst.instruction > 0xffff |
12530 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
12531 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
12532 | _("unshifted register required")); | |
fdfde340 | 12533 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 12534 | BAD_HIREG); |
b99bd4ef | 12535 | |
c19d1205 | 12536 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
12537 | inst.instruction |= Rn; |
12538 | inst.instruction |= Rm << 3; | |
b99bd4ef | 12539 | } |
b99bd4ef NC |
12540 | } |
12541 | ||
b05fe5cf | 12542 | static void |
c19d1205 | 12543 | do_t_mrs (void) |
b05fe5cf | 12544 | { |
fdfde340 | 12545 | unsigned Rd; |
037e8744 JB |
12546 | |
12547 | if (do_vfp_nsyn_mrs () == SUCCESS) | |
12548 | return; | |
12549 | ||
90ec0d68 MGD |
12550 | Rd = inst.operands[0].reg; |
12551 | reject_bad_reg (Rd); | |
12552 | inst.instruction |= Rd << 8; | |
12553 | ||
12554 | if (inst.operands[1].isreg) | |
62b3e311 | 12555 | { |
90ec0d68 MGD |
12556 | unsigned br = inst.operands[1].reg; |
12557 | if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000)) | |
12558 | as_bad (_("bad register for mrs")); | |
12559 | ||
12560 | inst.instruction |= br & (0xf << 16); | |
12561 | inst.instruction |= (br & 0x300) >> 4; | |
12562 | inst.instruction |= (br & SPSR_BIT) >> 2; | |
62b3e311 PB |
12563 | } |
12564 | else | |
12565 | { | |
90ec0d68 | 12566 | int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
5f4273c7 | 12567 | |
d2cd1205 | 12568 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
1a43faaf NC |
12569 | { |
12570 | /* PR gas/12698: The constraint is only applied for m_profile. | |
12571 | If the user has specified -march=all, we want to ignore it as | |
12572 | we are building for any CPU type, including non-m variants. */ | |
823d2571 TG |
12573 | bfd_boolean m_profile = |
12574 | !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any); | |
1a43faaf NC |
12575 | constraint ((flags != 0) && m_profile, _("selected processor does " |
12576 | "not support requested special purpose register")); | |
12577 | } | |
90ec0d68 | 12578 | else |
d2cd1205 JB |
12579 | /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile |
12580 | devices). */ | |
12581 | constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f), | |
12582 | _("'APSR', 'CPSR' or 'SPSR' expected")); | |
fdfde340 | 12583 | |
90ec0d68 MGD |
12584 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
12585 | inst.instruction |= inst.operands[1].imm & 0xff; | |
12586 | inst.instruction |= 0xf0000; | |
12587 | } | |
c19d1205 | 12588 | } |
b05fe5cf | 12589 | |
c19d1205 ZW |
12590 | static void |
12591 | do_t_msr (void) | |
12592 | { | |
62b3e311 | 12593 | int flags; |
fdfde340 | 12594 | unsigned Rn; |
62b3e311 | 12595 | |
037e8744 JB |
12596 | if (do_vfp_nsyn_msr () == SUCCESS) |
12597 | return; | |
12598 | ||
c19d1205 ZW |
12599 | constraint (!inst.operands[1].isreg, |
12600 | _("Thumb encoding does not support an immediate here")); | |
90ec0d68 MGD |
12601 | |
12602 | if (inst.operands[0].isreg) | |
12603 | flags = (int)(inst.operands[0].reg); | |
12604 | else | |
12605 | flags = inst.operands[0].imm; | |
12606 | ||
d2cd1205 | 12607 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
62b3e311 | 12608 | { |
d2cd1205 JB |
12609 | int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
12610 | ||
1a43faaf | 12611 | /* PR gas/12698: The constraint is only applied for m_profile. |
477330fc RM |
12612 | If the user has specified -march=all, we want to ignore it as |
12613 | we are building for any CPU type, including non-m variants. */ | |
823d2571 TG |
12614 | bfd_boolean m_profile = |
12615 | !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any); | |
1a43faaf | 12616 | constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp) |
477330fc RM |
12617 | && (bits & ~(PSR_s | PSR_f)) != 0) |
12618 | || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp) | |
12619 | && bits != PSR_f)) && m_profile, | |
12620 | _("selected processor does not support requested special " | |
12621 | "purpose register")); | |
62b3e311 PB |
12622 | } |
12623 | else | |
d2cd1205 JB |
12624 | constraint ((flags & 0xff) != 0, _("selected processor does not support " |
12625 | "requested special purpose register")); | |
c921be7d | 12626 | |
fdfde340 JM |
12627 | Rn = inst.operands[1].reg; |
12628 | reject_bad_reg (Rn); | |
12629 | ||
62b3e311 | 12630 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
90ec0d68 MGD |
12631 | inst.instruction |= (flags & 0xf0000) >> 8; |
12632 | inst.instruction |= (flags & 0x300) >> 4; | |
62b3e311 | 12633 | inst.instruction |= (flags & 0xff); |
fdfde340 | 12634 | inst.instruction |= Rn << 16; |
c19d1205 | 12635 | } |
b05fe5cf | 12636 | |
c19d1205 ZW |
12637 | static void |
12638 | do_t_mul (void) | |
12639 | { | |
17828f45 | 12640 | bfd_boolean narrow; |
fdfde340 | 12641 | unsigned Rd, Rn, Rm; |
17828f45 | 12642 | |
c19d1205 ZW |
12643 | if (!inst.operands[2].present) |
12644 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 12645 | |
fdfde340 JM |
12646 | Rd = inst.operands[0].reg; |
12647 | Rn = inst.operands[1].reg; | |
12648 | Rm = inst.operands[2].reg; | |
12649 | ||
17828f45 | 12650 | if (unified_syntax) |
b05fe5cf | 12651 | { |
17828f45 | 12652 | if (inst.size_req == 4 |
fdfde340 JM |
12653 | || (Rd != Rn |
12654 | && Rd != Rm) | |
12655 | || Rn > 7 | |
12656 | || Rm > 7) | |
17828f45 JM |
12657 | narrow = FALSE; |
12658 | else if (inst.instruction == T_MNEM_muls) | |
e07e6e58 | 12659 | narrow = !in_it_block (); |
17828f45 | 12660 | else |
e07e6e58 | 12661 | narrow = in_it_block (); |
b05fe5cf | 12662 | } |
c19d1205 | 12663 | else |
b05fe5cf | 12664 | { |
17828f45 | 12665 | constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32); |
fdfde340 | 12666 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 12667 | BAD_HIREG); |
17828f45 JM |
12668 | narrow = TRUE; |
12669 | } | |
b05fe5cf | 12670 | |
17828f45 JM |
12671 | if (narrow) |
12672 | { | |
12673 | /* 16-bit MULS/Conditional MUL. */ | |
c19d1205 | 12674 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 | 12675 | inst.instruction |= Rd; |
b05fe5cf | 12676 | |
fdfde340 JM |
12677 | if (Rd == Rn) |
12678 | inst.instruction |= Rm << 3; | |
12679 | else if (Rd == Rm) | |
12680 | inst.instruction |= Rn << 3; | |
c19d1205 ZW |
12681 | else |
12682 | constraint (1, _("dest must overlap one source register")); | |
12683 | } | |
17828f45 JM |
12684 | else |
12685 | { | |
e07e6e58 NC |
12686 | constraint (inst.instruction != T_MNEM_mul, |
12687 | _("Thumb-2 MUL must not set flags")); | |
17828f45 JM |
12688 | /* 32-bit MUL. */ |
12689 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
12690 | inst.instruction |= Rd << 8; |
12691 | inst.instruction |= Rn << 16; | |
12692 | inst.instruction |= Rm << 0; | |
12693 | ||
12694 | reject_bad_reg (Rd); | |
12695 | reject_bad_reg (Rn); | |
12696 | reject_bad_reg (Rm); | |
17828f45 | 12697 | } |
c19d1205 | 12698 | } |
b05fe5cf | 12699 | |
c19d1205 ZW |
12700 | static void |
12701 | do_t_mull (void) | |
12702 | { | |
fdfde340 | 12703 | unsigned RdLo, RdHi, Rn, Rm; |
b05fe5cf | 12704 | |
fdfde340 JM |
12705 | RdLo = inst.operands[0].reg; |
12706 | RdHi = inst.operands[1].reg; | |
12707 | Rn = inst.operands[2].reg; | |
12708 | Rm = inst.operands[3].reg; | |
12709 | ||
12710 | reject_bad_reg (RdLo); | |
12711 | reject_bad_reg (RdHi); | |
12712 | reject_bad_reg (Rn); | |
12713 | reject_bad_reg (Rm); | |
12714 | ||
12715 | inst.instruction |= RdLo << 12; | |
12716 | inst.instruction |= RdHi << 8; | |
12717 | inst.instruction |= Rn << 16; | |
12718 | inst.instruction |= Rm; | |
12719 | ||
12720 | if (RdLo == RdHi) | |
c19d1205 ZW |
12721 | as_tsktsk (_("rdhi and rdlo must be different")); |
12722 | } | |
b05fe5cf | 12723 | |
c19d1205 ZW |
12724 | static void |
12725 | do_t_nop (void) | |
12726 | { | |
e07e6e58 NC |
12727 | set_it_insn_type (NEUTRAL_IT_INSN); |
12728 | ||
c19d1205 ZW |
12729 | if (unified_syntax) |
12730 | { | |
12731 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 12732 | { |
c19d1205 ZW |
12733 | inst.instruction = THUMB_OP32 (inst.instruction); |
12734 | inst.instruction |= inst.operands[0].imm; | |
12735 | } | |
12736 | else | |
12737 | { | |
bc2d1808 NC |
12738 | /* PR9722: Check for Thumb2 availability before |
12739 | generating a thumb2 nop instruction. */ | |
afa62d5e | 12740 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
bc2d1808 NC |
12741 | { |
12742 | inst.instruction = THUMB_OP16 (inst.instruction); | |
12743 | inst.instruction |= inst.operands[0].imm << 4; | |
12744 | } | |
12745 | else | |
12746 | inst.instruction = 0x46c0; | |
c19d1205 ZW |
12747 | } |
12748 | } | |
12749 | else | |
12750 | { | |
12751 | constraint (inst.operands[0].present, | |
12752 | _("Thumb does not support NOP with hints")); | |
12753 | inst.instruction = 0x46c0; | |
12754 | } | |
12755 | } | |
b05fe5cf | 12756 | |
c19d1205 ZW |
12757 | static void |
12758 | do_t_neg (void) | |
12759 | { | |
12760 | if (unified_syntax) | |
12761 | { | |
3d388997 PB |
12762 | bfd_boolean narrow; |
12763 | ||
12764 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 12765 | narrow = !in_it_block (); |
3d388997 | 12766 | else |
e07e6e58 | 12767 | narrow = in_it_block (); |
3d388997 PB |
12768 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
12769 | narrow = FALSE; | |
12770 | if (inst.size_req == 4) | |
12771 | narrow = FALSE; | |
12772 | ||
12773 | if (!narrow) | |
c19d1205 ZW |
12774 | { |
12775 | inst.instruction = THUMB_OP32 (inst.instruction); | |
12776 | inst.instruction |= inst.operands[0].reg << 8; | |
12777 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
12778 | } |
12779 | else | |
12780 | { | |
c19d1205 ZW |
12781 | inst.instruction = THUMB_OP16 (inst.instruction); |
12782 | inst.instruction |= inst.operands[0].reg; | |
12783 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
12784 | } |
12785 | } | |
12786 | else | |
12787 | { | |
c19d1205 ZW |
12788 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
12789 | BAD_HIREG); | |
12790 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
12791 | ||
12792 | inst.instruction = THUMB_OP16 (inst.instruction); | |
12793 | inst.instruction |= inst.operands[0].reg; | |
12794 | inst.instruction |= inst.operands[1].reg << 3; | |
12795 | } | |
12796 | } | |
12797 | ||
1c444d06 JM |
12798 | static void |
12799 | do_t_orn (void) | |
12800 | { | |
12801 | unsigned Rd, Rn; | |
12802 | ||
12803 | Rd = inst.operands[0].reg; | |
12804 | Rn = inst.operands[1].present ? inst.operands[1].reg : Rd; | |
12805 | ||
fdfde340 JM |
12806 | reject_bad_reg (Rd); |
12807 | /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */ | |
12808 | reject_bad_reg (Rn); | |
12809 | ||
1c444d06 JM |
12810 | inst.instruction |= Rd << 8; |
12811 | inst.instruction |= Rn << 16; | |
12812 | ||
12813 | if (!inst.operands[2].isreg) | |
12814 | { | |
12815 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
e2b0ab59 | 12816 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
1c444d06 JM |
12817 | } |
12818 | else | |
12819 | { | |
12820 | unsigned Rm; | |
12821 | ||
12822 | Rm = inst.operands[2].reg; | |
fdfde340 | 12823 | reject_bad_reg (Rm); |
1c444d06 JM |
12824 | |
12825 | constraint (inst.operands[2].shifted | |
12826 | && inst.operands[2].immisreg, | |
12827 | _("shift must be constant")); | |
12828 | encode_thumb32_shifted_operand (2); | |
12829 | } | |
12830 | } | |
12831 | ||
c19d1205 ZW |
12832 | static void |
12833 | do_t_pkhbt (void) | |
12834 | { | |
fdfde340 JM |
12835 | unsigned Rd, Rn, Rm; |
12836 | ||
12837 | Rd = inst.operands[0].reg; | |
12838 | Rn = inst.operands[1].reg; | |
12839 | Rm = inst.operands[2].reg; | |
12840 | ||
12841 | reject_bad_reg (Rd); | |
12842 | reject_bad_reg (Rn); | |
12843 | reject_bad_reg (Rm); | |
12844 | ||
12845 | inst.instruction |= Rd << 8; | |
12846 | inst.instruction |= Rn << 16; | |
12847 | inst.instruction |= Rm; | |
c19d1205 ZW |
12848 | if (inst.operands[3].present) |
12849 | { | |
e2b0ab59 AV |
12850 | unsigned int val = inst.relocs[0].exp.X_add_number; |
12851 | constraint (inst.relocs[0].exp.X_op != O_constant, | |
c19d1205 ZW |
12852 | _("expression too complex")); |
12853 | inst.instruction |= (val & 0x1c) << 10; | |
12854 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 12855 | } |
c19d1205 | 12856 | } |
b05fe5cf | 12857 | |
c19d1205 ZW |
12858 | static void |
12859 | do_t_pkhtb (void) | |
12860 | { | |
12861 | if (!inst.operands[3].present) | |
1ef52f49 NC |
12862 | { |
12863 | unsigned Rtmp; | |
12864 | ||
12865 | inst.instruction &= ~0x00000020; | |
12866 | ||
12867 | /* PR 10168. Swap the Rm and Rn registers. */ | |
12868 | Rtmp = inst.operands[1].reg; | |
12869 | inst.operands[1].reg = inst.operands[2].reg; | |
12870 | inst.operands[2].reg = Rtmp; | |
12871 | } | |
c19d1205 | 12872 | do_t_pkhbt (); |
b05fe5cf ZW |
12873 | } |
12874 | ||
c19d1205 ZW |
12875 | static void |
12876 | do_t_pld (void) | |
12877 | { | |
fdfde340 JM |
12878 | if (inst.operands[0].immisreg) |
12879 | reject_bad_reg (inst.operands[0].imm); | |
12880 | ||
c19d1205 ZW |
12881 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); |
12882 | } | |
b05fe5cf | 12883 | |
c19d1205 ZW |
12884 | static void |
12885 | do_t_push_pop (void) | |
b99bd4ef | 12886 | { |
e9f89963 | 12887 | unsigned mask; |
5f4273c7 | 12888 | |
c19d1205 ZW |
12889 | constraint (inst.operands[0].writeback, |
12890 | _("push/pop do not support {reglist}^")); | |
e2b0ab59 | 12891 | constraint (inst.relocs[0].type != BFD_RELOC_UNUSED, |
c19d1205 | 12892 | _("expression too complex")); |
b99bd4ef | 12893 | |
e9f89963 | 12894 | mask = inst.operands[0].imm; |
d3bfe16e | 12895 | if (inst.size_req != 4 && (mask & ~0xff) == 0) |
3c707909 | 12896 | inst.instruction = THUMB_OP16 (inst.instruction) | mask; |
d3bfe16e | 12897 | else if (inst.size_req != 4 |
c6025a80 | 12898 | && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push |
d3bfe16e | 12899 | ? REG_LR : REG_PC))) |
b99bd4ef | 12900 | { |
c19d1205 ZW |
12901 | inst.instruction = THUMB_OP16 (inst.instruction); |
12902 | inst.instruction |= THUMB_PP_PC_LR; | |
3c707909 | 12903 | inst.instruction |= mask & 0xff; |
c19d1205 ZW |
12904 | } |
12905 | else if (unified_syntax) | |
12906 | { | |
3c707909 | 12907 | inst.instruction = THUMB_OP32 (inst.instruction); |
4b5a202f AV |
12908 | encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE); |
12909 | } | |
12910 | else | |
12911 | { | |
12912 | inst.error = _("invalid register list to push/pop instruction"); | |
12913 | return; | |
c19d1205 | 12914 | } |
4b5a202f AV |
12915 | } |
12916 | ||
12917 | static void | |
12918 | do_t_clrm (void) | |
12919 | { | |
12920 | if (unified_syntax) | |
12921 | encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE); | |
c19d1205 ZW |
12922 | else |
12923 | { | |
12924 | inst.error = _("invalid register list to push/pop instruction"); | |
12925 | return; | |
12926 | } | |
c19d1205 | 12927 | } |
b99bd4ef | 12928 | |
efd6b359 AV |
12929 | static void |
12930 | do_t_vscclrm (void) | |
12931 | { | |
12932 | if (inst.operands[0].issingle) | |
12933 | { | |
12934 | inst.instruction |= (inst.operands[0].reg & 0x1) << 22; | |
12935 | inst.instruction |= (inst.operands[0].reg & 0x1e) << 11; | |
12936 | inst.instruction |= inst.operands[0].imm; | |
12937 | } | |
12938 | else | |
12939 | { | |
12940 | inst.instruction |= (inst.operands[0].reg & 0x10) << 18; | |
12941 | inst.instruction |= (inst.operands[0].reg & 0xf) << 12; | |
12942 | inst.instruction |= 1 << 8; | |
12943 | inst.instruction |= inst.operands[0].imm << 1; | |
12944 | } | |
12945 | } | |
12946 | ||
c19d1205 ZW |
12947 | static void |
12948 | do_t_rbit (void) | |
12949 | { | |
fdfde340 JM |
12950 | unsigned Rd, Rm; |
12951 | ||
12952 | Rd = inst.operands[0].reg; | |
12953 | Rm = inst.operands[1].reg; | |
12954 | ||
12955 | reject_bad_reg (Rd); | |
12956 | reject_bad_reg (Rm); | |
12957 | ||
12958 | inst.instruction |= Rd << 8; | |
12959 | inst.instruction |= Rm << 16; | |
12960 | inst.instruction |= Rm; | |
c19d1205 | 12961 | } |
b99bd4ef | 12962 | |
c19d1205 ZW |
12963 | static void |
12964 | do_t_rev (void) | |
12965 | { | |
fdfde340 JM |
12966 | unsigned Rd, Rm; |
12967 | ||
12968 | Rd = inst.operands[0].reg; | |
12969 | Rm = inst.operands[1].reg; | |
12970 | ||
12971 | reject_bad_reg (Rd); | |
12972 | reject_bad_reg (Rm); | |
12973 | ||
12974 | if (Rd <= 7 && Rm <= 7 | |
c19d1205 ZW |
12975 | && inst.size_req != 4) |
12976 | { | |
12977 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 JM |
12978 | inst.instruction |= Rd; |
12979 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
12980 | } |
12981 | else if (unified_syntax) | |
12982 | { | |
12983 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
12984 | inst.instruction |= Rd << 8; |
12985 | inst.instruction |= Rm << 16; | |
12986 | inst.instruction |= Rm; | |
c19d1205 ZW |
12987 | } |
12988 | else | |
12989 | inst.error = BAD_HIREG; | |
12990 | } | |
b99bd4ef | 12991 | |
1c444d06 JM |
12992 | static void |
12993 | do_t_rrx (void) | |
12994 | { | |
12995 | unsigned Rd, Rm; | |
12996 | ||
12997 | Rd = inst.operands[0].reg; | |
12998 | Rm = inst.operands[1].reg; | |
12999 | ||
fdfde340 JM |
13000 | reject_bad_reg (Rd); |
13001 | reject_bad_reg (Rm); | |
c921be7d | 13002 | |
1c444d06 JM |
13003 | inst.instruction |= Rd << 8; |
13004 | inst.instruction |= Rm; | |
13005 | } | |
13006 | ||
c19d1205 ZW |
13007 | static void |
13008 | do_t_rsb (void) | |
13009 | { | |
fdfde340 | 13010 | unsigned Rd, Rs; |
b99bd4ef | 13011 | |
c19d1205 ZW |
13012 | Rd = inst.operands[0].reg; |
13013 | Rs = (inst.operands[1].present | |
13014 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
13015 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 13016 | |
fdfde340 JM |
13017 | reject_bad_reg (Rd); |
13018 | reject_bad_reg (Rs); | |
13019 | if (inst.operands[2].isreg) | |
13020 | reject_bad_reg (inst.operands[2].reg); | |
13021 | ||
c19d1205 ZW |
13022 | inst.instruction |= Rd << 8; |
13023 | inst.instruction |= Rs << 16; | |
13024 | if (!inst.operands[2].isreg) | |
13025 | { | |
026d3abb PB |
13026 | bfd_boolean narrow; |
13027 | ||
13028 | if ((inst.instruction & 0x00100000) != 0) | |
e07e6e58 | 13029 | narrow = !in_it_block (); |
026d3abb | 13030 | else |
e07e6e58 | 13031 | narrow = in_it_block (); |
026d3abb PB |
13032 | |
13033 | if (Rd > 7 || Rs > 7) | |
13034 | narrow = FALSE; | |
13035 | ||
13036 | if (inst.size_req == 4 || !unified_syntax) | |
13037 | narrow = FALSE; | |
13038 | ||
e2b0ab59 AV |
13039 | if (inst.relocs[0].exp.X_op != O_constant |
13040 | || inst.relocs[0].exp.X_add_number != 0) | |
026d3abb PB |
13041 | narrow = FALSE; |
13042 | ||
13043 | /* Turn rsb #0 into 16-bit neg. We should probably do this via | |
477330fc | 13044 | relaxation, but it doesn't seem worth the hassle. */ |
026d3abb PB |
13045 | if (narrow) |
13046 | { | |
e2b0ab59 | 13047 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
026d3abb PB |
13048 | inst.instruction = THUMB_OP16 (T_MNEM_negs); |
13049 | inst.instruction |= Rs << 3; | |
13050 | inst.instruction |= Rd; | |
13051 | } | |
13052 | else | |
13053 | { | |
13054 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
e2b0ab59 | 13055 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
026d3abb | 13056 | } |
c19d1205 ZW |
13057 | } |
13058 | else | |
13059 | encode_thumb32_shifted_operand (2); | |
13060 | } | |
b99bd4ef | 13061 | |
c19d1205 ZW |
13062 | static void |
13063 | do_t_setend (void) | |
13064 | { | |
12e37cbc MGD |
13065 | if (warn_on_deprecated |
13066 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
5c3696f8 | 13067 | as_tsktsk (_("setend use is deprecated for ARMv8")); |
12e37cbc | 13068 | |
e07e6e58 | 13069 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
13070 | if (inst.operands[0].imm) |
13071 | inst.instruction |= 0x8; | |
13072 | } | |
b99bd4ef | 13073 | |
c19d1205 ZW |
13074 | static void |
13075 | do_t_shift (void) | |
13076 | { | |
13077 | if (!inst.operands[1].present) | |
13078 | inst.operands[1].reg = inst.operands[0].reg; | |
13079 | ||
13080 | if (unified_syntax) | |
13081 | { | |
3d388997 PB |
13082 | bfd_boolean narrow; |
13083 | int shift_kind; | |
13084 | ||
13085 | switch (inst.instruction) | |
13086 | { | |
13087 | case T_MNEM_asr: | |
13088 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
13089 | case T_MNEM_lsl: | |
13090 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
13091 | case T_MNEM_lsr: | |
13092 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
13093 | case T_MNEM_ror: | |
13094 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
13095 | default: abort (); | |
13096 | } | |
13097 | ||
13098 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 13099 | narrow = !in_it_block (); |
3d388997 | 13100 | else |
e07e6e58 | 13101 | narrow = in_it_block (); |
3d388997 PB |
13102 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
13103 | narrow = FALSE; | |
13104 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
13105 | narrow = FALSE; | |
13106 | if (inst.operands[2].isreg | |
13107 | && (inst.operands[1].reg != inst.operands[0].reg | |
13108 | || inst.operands[2].reg > 7)) | |
13109 | narrow = FALSE; | |
13110 | if (inst.size_req == 4) | |
13111 | narrow = FALSE; | |
13112 | ||
fdfde340 JM |
13113 | reject_bad_reg (inst.operands[0].reg); |
13114 | reject_bad_reg (inst.operands[1].reg); | |
c921be7d | 13115 | |
3d388997 | 13116 | if (!narrow) |
c19d1205 ZW |
13117 | { |
13118 | if (inst.operands[2].isreg) | |
b99bd4ef | 13119 | { |
fdfde340 | 13120 | reject_bad_reg (inst.operands[2].reg); |
c19d1205 ZW |
13121 | inst.instruction = THUMB_OP32 (inst.instruction); |
13122 | inst.instruction |= inst.operands[0].reg << 8; | |
13123 | inst.instruction |= inst.operands[1].reg << 16; | |
13124 | inst.instruction |= inst.operands[2].reg; | |
94342ec3 NC |
13125 | |
13126 | /* PR 12854: Error on extraneous shifts. */ | |
13127 | constraint (inst.operands[2].shifted, | |
13128 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
13129 | } |
13130 | else | |
13131 | { | |
13132 | inst.operands[1].shifted = 1; | |
3d388997 | 13133 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
13134 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
13135 | ? T_MNEM_movs : T_MNEM_mov); | |
13136 | inst.instruction |= inst.operands[0].reg << 8; | |
13137 | encode_thumb32_shifted_operand (1); | |
13138 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
e2b0ab59 | 13139 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
b99bd4ef NC |
13140 | } |
13141 | } | |
13142 | else | |
13143 | { | |
c19d1205 | 13144 | if (inst.operands[2].isreg) |
b99bd4ef | 13145 | { |
3d388997 | 13146 | switch (shift_kind) |
b99bd4ef | 13147 | { |
3d388997 PB |
13148 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
13149 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
13150 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
13151 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 13152 | default: abort (); |
b99bd4ef | 13153 | } |
5f4273c7 | 13154 | |
c19d1205 ZW |
13155 | inst.instruction |= inst.operands[0].reg; |
13156 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
13157 | |
13158 | /* PR 12854: Error on extraneous shifts. */ | |
13159 | constraint (inst.operands[2].shifted, | |
13160 | _("extraneous shift as part of operand to shift insn")); | |
b99bd4ef NC |
13161 | } |
13162 | else | |
13163 | { | |
3d388997 | 13164 | switch (shift_kind) |
b99bd4ef | 13165 | { |
3d388997 PB |
13166 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
13167 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
13168 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 13169 | default: abort (); |
b99bd4ef | 13170 | } |
e2b0ab59 | 13171 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT; |
c19d1205 ZW |
13172 | inst.instruction |= inst.operands[0].reg; |
13173 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
13174 | } |
13175 | } | |
c19d1205 ZW |
13176 | } |
13177 | else | |
13178 | { | |
13179 | constraint (inst.operands[0].reg > 7 | |
13180 | || inst.operands[1].reg > 7, BAD_HIREG); | |
13181 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 13182 | |
c19d1205 ZW |
13183 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
13184 | { | |
13185 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
13186 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
13187 | _("source1 and dest must be same register")); | |
b99bd4ef | 13188 | |
c19d1205 ZW |
13189 | switch (inst.instruction) |
13190 | { | |
13191 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
13192 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
13193 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
13194 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
13195 | default: abort (); | |
13196 | } | |
5f4273c7 | 13197 | |
c19d1205 ZW |
13198 | inst.instruction |= inst.operands[0].reg; |
13199 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
13200 | |
13201 | /* PR 12854: Error on extraneous shifts. */ | |
13202 | constraint (inst.operands[2].shifted, | |
13203 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
13204 | } |
13205 | else | |
b99bd4ef | 13206 | { |
c19d1205 ZW |
13207 | switch (inst.instruction) |
13208 | { | |
13209 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
13210 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
13211 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
13212 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
13213 | default: abort (); | |
13214 | } | |
e2b0ab59 | 13215 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT; |
c19d1205 ZW |
13216 | inst.instruction |= inst.operands[0].reg; |
13217 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
13218 | } |
13219 | } | |
b99bd4ef NC |
13220 | } |
13221 | ||
13222 | static void | |
c19d1205 | 13223 | do_t_simd (void) |
b99bd4ef | 13224 | { |
fdfde340 JM |
13225 | unsigned Rd, Rn, Rm; |
13226 | ||
13227 | Rd = inst.operands[0].reg; | |
13228 | Rn = inst.operands[1].reg; | |
13229 | Rm = inst.operands[2].reg; | |
13230 | ||
13231 | reject_bad_reg (Rd); | |
13232 | reject_bad_reg (Rn); | |
13233 | reject_bad_reg (Rm); | |
13234 | ||
13235 | inst.instruction |= Rd << 8; | |
13236 | inst.instruction |= Rn << 16; | |
13237 | inst.instruction |= Rm; | |
c19d1205 | 13238 | } |
b99bd4ef | 13239 | |
03ee1b7f NC |
13240 | static void |
13241 | do_t_simd2 (void) | |
13242 | { | |
13243 | unsigned Rd, Rn, Rm; | |
13244 | ||
13245 | Rd = inst.operands[0].reg; | |
13246 | Rm = inst.operands[1].reg; | |
13247 | Rn = inst.operands[2].reg; | |
13248 | ||
13249 | reject_bad_reg (Rd); | |
13250 | reject_bad_reg (Rn); | |
13251 | reject_bad_reg (Rm); | |
13252 | ||
13253 | inst.instruction |= Rd << 8; | |
13254 | inst.instruction |= Rn << 16; | |
13255 | inst.instruction |= Rm; | |
13256 | } | |
13257 | ||
c19d1205 | 13258 | static void |
3eb17e6b | 13259 | do_t_smc (void) |
c19d1205 | 13260 | { |
e2b0ab59 | 13261 | unsigned int value = inst.relocs[0].exp.X_add_number; |
f4c65163 MGD |
13262 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a), |
13263 | _("SMC is not permitted on this architecture")); | |
e2b0ab59 | 13264 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 | 13265 | _("expression too complex")); |
e2b0ab59 | 13266 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
c19d1205 ZW |
13267 | inst.instruction |= (value & 0xf000) >> 12; |
13268 | inst.instruction |= (value & 0x0ff0); | |
13269 | inst.instruction |= (value & 0x000f) << 16; | |
24382199 NC |
13270 | /* PR gas/15623: SMC instructions must be last in an IT block. */ |
13271 | set_it_insn_type_last (); | |
c19d1205 | 13272 | } |
b99bd4ef | 13273 | |
90ec0d68 MGD |
13274 | static void |
13275 | do_t_hvc (void) | |
13276 | { | |
e2b0ab59 | 13277 | unsigned int value = inst.relocs[0].exp.X_add_number; |
90ec0d68 | 13278 | |
e2b0ab59 | 13279 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
90ec0d68 MGD |
13280 | inst.instruction |= (value & 0x0fff); |
13281 | inst.instruction |= (value & 0xf000) << 4; | |
13282 | } | |
13283 | ||
c19d1205 | 13284 | static void |
3a21c15a | 13285 | do_t_ssat_usat (int bias) |
c19d1205 | 13286 | { |
fdfde340 JM |
13287 | unsigned Rd, Rn; |
13288 | ||
13289 | Rd = inst.operands[0].reg; | |
13290 | Rn = inst.operands[2].reg; | |
13291 | ||
13292 | reject_bad_reg (Rd); | |
13293 | reject_bad_reg (Rn); | |
13294 | ||
13295 | inst.instruction |= Rd << 8; | |
3a21c15a | 13296 | inst.instruction |= inst.operands[1].imm - bias; |
fdfde340 | 13297 | inst.instruction |= Rn << 16; |
b99bd4ef | 13298 | |
c19d1205 | 13299 | if (inst.operands[3].present) |
b99bd4ef | 13300 | { |
e2b0ab59 | 13301 | offsetT shift_amount = inst.relocs[0].exp.X_add_number; |
3a21c15a | 13302 | |
e2b0ab59 | 13303 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
3a21c15a | 13304 | |
e2b0ab59 | 13305 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 | 13306 | _("expression too complex")); |
b99bd4ef | 13307 | |
3a21c15a | 13308 | if (shift_amount != 0) |
6189168b | 13309 | { |
3a21c15a NC |
13310 | constraint (shift_amount > 31, |
13311 | _("shift expression is too large")); | |
13312 | ||
c19d1205 | 13313 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
3a21c15a NC |
13314 | inst.instruction |= 0x00200000; /* sh bit. */ |
13315 | ||
13316 | inst.instruction |= (shift_amount & 0x1c) << 10; | |
13317 | inst.instruction |= (shift_amount & 0x03) << 6; | |
6189168b NC |
13318 | } |
13319 | } | |
b99bd4ef | 13320 | } |
c921be7d | 13321 | |
3a21c15a NC |
13322 | static void |
13323 | do_t_ssat (void) | |
13324 | { | |
13325 | do_t_ssat_usat (1); | |
13326 | } | |
b99bd4ef | 13327 | |
0dd132b6 | 13328 | static void |
c19d1205 | 13329 | do_t_ssat16 (void) |
0dd132b6 | 13330 | { |
fdfde340 JM |
13331 | unsigned Rd, Rn; |
13332 | ||
13333 | Rd = inst.operands[0].reg; | |
13334 | Rn = inst.operands[2].reg; | |
13335 | ||
13336 | reject_bad_reg (Rd); | |
13337 | reject_bad_reg (Rn); | |
13338 | ||
13339 | inst.instruction |= Rd << 8; | |
c19d1205 | 13340 | inst.instruction |= inst.operands[1].imm - 1; |
fdfde340 | 13341 | inst.instruction |= Rn << 16; |
c19d1205 | 13342 | } |
0dd132b6 | 13343 | |
c19d1205 ZW |
13344 | static void |
13345 | do_t_strex (void) | |
13346 | { | |
13347 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
13348 | || inst.operands[2].postind || inst.operands[2].writeback | |
13349 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
13350 | || inst.operands[2].negative, | |
01cfc07f | 13351 | BAD_ADDR_MODE); |
0dd132b6 | 13352 | |
5be8be5d DG |
13353 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
13354 | ||
c19d1205 ZW |
13355 | inst.instruction |= inst.operands[0].reg << 8; |
13356 | inst.instruction |= inst.operands[1].reg << 12; | |
13357 | inst.instruction |= inst.operands[2].reg << 16; | |
e2b0ab59 | 13358 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8; |
0dd132b6 NC |
13359 | } |
13360 | ||
b99bd4ef | 13361 | static void |
c19d1205 | 13362 | do_t_strexd (void) |
b99bd4ef | 13363 | { |
c19d1205 ZW |
13364 | if (!inst.operands[2].present) |
13365 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 13366 | |
c19d1205 ZW |
13367 | constraint (inst.operands[0].reg == inst.operands[1].reg |
13368 | || inst.operands[0].reg == inst.operands[2].reg | |
f8a8e9d6 | 13369 | || inst.operands[0].reg == inst.operands[3].reg, |
c19d1205 | 13370 | BAD_OVERLAP); |
b99bd4ef | 13371 | |
c19d1205 ZW |
13372 | inst.instruction |= inst.operands[0].reg; |
13373 | inst.instruction |= inst.operands[1].reg << 12; | |
13374 | inst.instruction |= inst.operands[2].reg << 8; | |
13375 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
13376 | } |
13377 | ||
13378 | static void | |
c19d1205 | 13379 | do_t_sxtah (void) |
b99bd4ef | 13380 | { |
fdfde340 JM |
13381 | unsigned Rd, Rn, Rm; |
13382 | ||
13383 | Rd = inst.operands[0].reg; | |
13384 | Rn = inst.operands[1].reg; | |
13385 | Rm = inst.operands[2].reg; | |
13386 | ||
13387 | reject_bad_reg (Rd); | |
13388 | reject_bad_reg (Rn); | |
13389 | reject_bad_reg (Rm); | |
13390 | ||
13391 | inst.instruction |= Rd << 8; | |
13392 | inst.instruction |= Rn << 16; | |
13393 | inst.instruction |= Rm; | |
c19d1205 ZW |
13394 | inst.instruction |= inst.operands[3].imm << 4; |
13395 | } | |
b99bd4ef | 13396 | |
c19d1205 ZW |
13397 | static void |
13398 | do_t_sxth (void) | |
13399 | { | |
fdfde340 JM |
13400 | unsigned Rd, Rm; |
13401 | ||
13402 | Rd = inst.operands[0].reg; | |
13403 | Rm = inst.operands[1].reg; | |
13404 | ||
13405 | reject_bad_reg (Rd); | |
13406 | reject_bad_reg (Rm); | |
c921be7d NC |
13407 | |
13408 | if (inst.instruction <= 0xffff | |
13409 | && inst.size_req != 4 | |
fdfde340 | 13410 | && Rd <= 7 && Rm <= 7 |
c19d1205 | 13411 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) |
b99bd4ef | 13412 | { |
c19d1205 | 13413 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
13414 | inst.instruction |= Rd; |
13415 | inst.instruction |= Rm << 3; | |
b99bd4ef | 13416 | } |
c19d1205 | 13417 | else if (unified_syntax) |
b99bd4ef | 13418 | { |
c19d1205 ZW |
13419 | if (inst.instruction <= 0xffff) |
13420 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
13421 | inst.instruction |= Rd << 8; |
13422 | inst.instruction |= Rm; | |
c19d1205 | 13423 | inst.instruction |= inst.operands[2].imm << 4; |
b99bd4ef | 13424 | } |
c19d1205 | 13425 | else |
b99bd4ef | 13426 | { |
c19d1205 ZW |
13427 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
13428 | _("Thumb encoding does not support rotation")); | |
13429 | constraint (1, BAD_HIREG); | |
b99bd4ef | 13430 | } |
c19d1205 | 13431 | } |
b99bd4ef | 13432 | |
c19d1205 ZW |
13433 | static void |
13434 | do_t_swi (void) | |
13435 | { | |
e2b0ab59 | 13436 | inst.relocs[0].type = BFD_RELOC_ARM_SWI; |
c19d1205 | 13437 | } |
b99bd4ef | 13438 | |
92e90b6e PB |
13439 | static void |
13440 | do_t_tb (void) | |
13441 | { | |
fdfde340 | 13442 | unsigned Rn, Rm; |
92e90b6e PB |
13443 | int half; |
13444 | ||
13445 | half = (inst.instruction & 0x10) != 0; | |
e07e6e58 | 13446 | set_it_insn_type_last (); |
dfa9f0d5 PB |
13447 | constraint (inst.operands[0].immisreg, |
13448 | _("instruction requires register index")); | |
fdfde340 JM |
13449 | |
13450 | Rn = inst.operands[0].reg; | |
13451 | Rm = inst.operands[0].imm; | |
c921be7d | 13452 | |
5c8ed6a4 JW |
13453 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
13454 | constraint (Rn == REG_SP, BAD_SP); | |
fdfde340 JM |
13455 | reject_bad_reg (Rm); |
13456 | ||
92e90b6e PB |
13457 | constraint (!half && inst.operands[0].shifted, |
13458 | _("instruction does not allow shifted index")); | |
fdfde340 | 13459 | inst.instruction |= (Rn << 16) | Rm; |
92e90b6e PB |
13460 | } |
13461 | ||
74db7efb NC |
13462 | static void |
13463 | do_t_udf (void) | |
13464 | { | |
13465 | if (!inst.operands[0].present) | |
13466 | inst.operands[0].imm = 0; | |
13467 | ||
13468 | if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4) | |
13469 | { | |
13470 | constraint (inst.size_req == 2, | |
13471 | _("immediate value out of range")); | |
13472 | inst.instruction = THUMB_OP32 (inst.instruction); | |
13473 | inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4; | |
13474 | inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0; | |
13475 | } | |
13476 | else | |
13477 | { | |
13478 | inst.instruction = THUMB_OP16 (inst.instruction); | |
13479 | inst.instruction |= inst.operands[0].imm; | |
13480 | } | |
13481 | ||
13482 | set_it_insn_type (NEUTRAL_IT_INSN); | |
13483 | } | |
13484 | ||
13485 | ||
c19d1205 ZW |
13486 | static void |
13487 | do_t_usat (void) | |
13488 | { | |
3a21c15a | 13489 | do_t_ssat_usat (0); |
b99bd4ef NC |
13490 | } |
13491 | ||
13492 | static void | |
c19d1205 | 13493 | do_t_usat16 (void) |
b99bd4ef | 13494 | { |
fdfde340 JM |
13495 | unsigned Rd, Rn; |
13496 | ||
13497 | Rd = inst.operands[0].reg; | |
13498 | Rn = inst.operands[2].reg; | |
13499 | ||
13500 | reject_bad_reg (Rd); | |
13501 | reject_bad_reg (Rn); | |
13502 | ||
13503 | inst.instruction |= Rd << 8; | |
c19d1205 | 13504 | inst.instruction |= inst.operands[1].imm; |
fdfde340 | 13505 | inst.instruction |= Rn << 16; |
b99bd4ef | 13506 | } |
c19d1205 | 13507 | |
e12437dc AV |
13508 | /* Checking the range of the branch offset (VAL) with NBITS bits |
13509 | and IS_SIGNED signedness. Also checks the LSB to be 0. */ | |
13510 | static int | |
13511 | v8_1_branch_value_check (int val, int nbits, int is_signed) | |
13512 | { | |
13513 | gas_assert (nbits > 0 && nbits <= 32); | |
13514 | if (is_signed) | |
13515 | { | |
13516 | int cmp = (1 << (nbits - 1)); | |
13517 | if ((val < -cmp) || (val >= cmp) || (val & 0x01)) | |
13518 | return FAIL; | |
13519 | } | |
13520 | else | |
13521 | { | |
13522 | if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1)) | |
13523 | return FAIL; | |
13524 | } | |
13525 | return SUCCESS; | |
13526 | } | |
13527 | ||
4389b29a AV |
13528 | /* For branches in Armv8.1-M Mainline. */ |
13529 | static void | |
13530 | do_t_branch_future (void) | |
13531 | { | |
13532 | unsigned long insn = inst.instruction; | |
13533 | ||
13534 | inst.instruction = THUMB_OP32 (inst.instruction); | |
13535 | if (inst.operands[0].hasreloc == 0) | |
13536 | { | |
13537 | if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL) | |
13538 | as_bad (BAD_BRANCH_OFF); | |
13539 | ||
13540 | inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23; | |
13541 | } | |
13542 | else | |
13543 | { | |
13544 | inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5; | |
13545 | inst.relocs[0].pc_rel = 1; | |
13546 | } | |
13547 | ||
13548 | switch (insn) | |
13549 | { | |
13550 | case T_MNEM_bf: | |
13551 | if (inst.operands[1].hasreloc == 0) | |
13552 | { | |
13553 | int val = inst.operands[1].imm; | |
13554 | if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL) | |
13555 | as_bad (BAD_BRANCH_OFF); | |
13556 | ||
13557 | int immA = (val & 0x0001f000) >> 12; | |
13558 | int immB = (val & 0x00000ffc) >> 2; | |
13559 | int immC = (val & 0x00000002) >> 1; | |
13560 | inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11); | |
13561 | } | |
13562 | else | |
13563 | { | |
13564 | inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17; | |
13565 | inst.relocs[1].pc_rel = 1; | |
13566 | } | |
13567 | break; | |
13568 | ||
65d1bc05 AV |
13569 | case T_MNEM_bfl: |
13570 | if (inst.operands[1].hasreloc == 0) | |
13571 | { | |
13572 | int val = inst.operands[1].imm; | |
13573 | if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL) | |
13574 | as_bad (BAD_BRANCH_OFF); | |
13575 | ||
13576 | int immA = (val & 0x0007f000) >> 12; | |
13577 | int immB = (val & 0x00000ffc) >> 2; | |
13578 | int immC = (val & 0x00000002) >> 1; | |
13579 | inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11); | |
13580 | } | |
13581 | else | |
13582 | { | |
13583 | inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19; | |
13584 | inst.relocs[1].pc_rel = 1; | |
13585 | } | |
13586 | break; | |
13587 | ||
f6b2b12d AV |
13588 | case T_MNEM_bfcsel: |
13589 | /* Operand 1. */ | |
13590 | if (inst.operands[1].hasreloc == 0) | |
13591 | { | |
13592 | int val = inst.operands[1].imm; | |
13593 | int immA = (val & 0x00001000) >> 12; | |
13594 | int immB = (val & 0x00000ffc) >> 2; | |
13595 | int immC = (val & 0x00000002) >> 1; | |
13596 | inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11); | |
13597 | } | |
13598 | else | |
13599 | { | |
13600 | inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13; | |
13601 | inst.relocs[1].pc_rel = 1; | |
13602 | } | |
13603 | ||
13604 | /* Operand 2. */ | |
13605 | if (inst.operands[2].hasreloc == 0) | |
13606 | { | |
13607 | constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS); | |
13608 | int val2 = inst.operands[2].imm; | |
13609 | int val0 = inst.operands[0].imm & 0x1f; | |
13610 | int diff = val2 - val0; | |
13611 | if (diff == 4) | |
13612 | inst.instruction |= 1 << 17; /* T bit. */ | |
13613 | else if (diff != 2) | |
13614 | as_bad (_("out of range label-relative fixup value")); | |
13615 | } | |
13616 | else | |
13617 | { | |
13618 | constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS); | |
13619 | inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL; | |
13620 | inst.relocs[2].pc_rel = 1; | |
13621 | } | |
13622 | ||
13623 | /* Operand 3. */ | |
13624 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
13625 | inst.instruction |= (inst.operands[3].imm & 0xf) << 18; | |
13626 | break; | |
13627 | ||
f1c7f421 AV |
13628 | case T_MNEM_bfx: |
13629 | case T_MNEM_bflx: | |
13630 | inst.instruction |= inst.operands[1].reg << 16; | |
13631 | break; | |
13632 | ||
4389b29a AV |
13633 | default: abort (); |
13634 | } | |
13635 | } | |
13636 | ||
60f993ce AV |
13637 | /* Helper function for do_t_loloop to handle relocations. */ |
13638 | static void | |
13639 | v8_1_loop_reloc (int is_le) | |
13640 | { | |
13641 | if (inst.relocs[0].exp.X_op == O_constant) | |
13642 | { | |
13643 | int value = inst.relocs[0].exp.X_add_number; | |
13644 | value = (is_le) ? -value : value; | |
13645 | ||
13646 | if (v8_1_branch_value_check (value, 12, FALSE) == FAIL) | |
13647 | as_bad (BAD_BRANCH_OFF); | |
13648 | ||
13649 | int imml, immh; | |
13650 | ||
13651 | immh = (value & 0x00000ffc) >> 2; | |
13652 | imml = (value & 0x00000002) >> 1; | |
13653 | ||
13654 | inst.instruction |= (imml << 11) | (immh << 1); | |
13655 | } | |
13656 | else | |
13657 | { | |
13658 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12; | |
13659 | inst.relocs[0].pc_rel = 1; | |
13660 | } | |
13661 | } | |
13662 | ||
13663 | /* To handle the Scalar Low Overhead Loop instructions | |
13664 | in Armv8.1-M Mainline. */ | |
13665 | static void | |
13666 | do_t_loloop (void) | |
13667 | { | |
13668 | unsigned long insn = inst.instruction; | |
13669 | ||
13670 | set_it_insn_type (OUTSIDE_IT_INSN); | |
13671 | inst.instruction = THUMB_OP32 (inst.instruction); | |
13672 | ||
13673 | switch (insn) | |
13674 | { | |
13675 | case T_MNEM_le: | |
13676 | /* le <label>. */ | |
13677 | if (!inst.operands[0].present) | |
13678 | inst.instruction |= 1 << 21; | |
13679 | ||
13680 | v8_1_loop_reloc (TRUE); | |
13681 | break; | |
13682 | ||
13683 | case T_MNEM_wls: | |
13684 | v8_1_loop_reloc (FALSE); | |
13685 | /* Fall through. */ | |
13686 | case T_MNEM_dls: | |
13687 | constraint (inst.operands[1].isreg != 1, BAD_ARGS); | |
13688 | inst.instruction |= (inst.operands[1].reg << 16); | |
13689 | break; | |
13690 | ||
13691 | default: abort(); | |
13692 | } | |
13693 | } | |
13694 | ||
5287ad62 | 13695 | /* Neon instruction encoder helpers. */ |
5f4273c7 | 13696 | |
5287ad62 | 13697 | /* Encodings for the different types for various Neon opcodes. */ |
b99bd4ef | 13698 | |
5287ad62 JB |
13699 | /* An "invalid" code for the following tables. */ |
13700 | #define N_INV -1u | |
13701 | ||
13702 | struct neon_tab_entry | |
b99bd4ef | 13703 | { |
5287ad62 JB |
13704 | unsigned integer; |
13705 | unsigned float_or_poly; | |
13706 | unsigned scalar_or_imm; | |
13707 | }; | |
5f4273c7 | 13708 | |
5287ad62 JB |
13709 | /* Map overloaded Neon opcodes to their respective encodings. */ |
13710 | #define NEON_ENC_TAB \ | |
13711 | X(vabd, 0x0000700, 0x1200d00, N_INV), \ | |
13712 | X(vmax, 0x0000600, 0x0000f00, N_INV), \ | |
13713 | X(vmin, 0x0000610, 0x0200f00, N_INV), \ | |
13714 | X(vpadd, 0x0000b10, 0x1000d00, N_INV), \ | |
13715 | X(vpmax, 0x0000a00, 0x1000f00, N_INV), \ | |
13716 | X(vpmin, 0x0000a10, 0x1200f00, N_INV), \ | |
13717 | X(vadd, 0x0000800, 0x0000d00, N_INV), \ | |
13718 | X(vsub, 0x1000800, 0x0200d00, N_INV), \ | |
13719 | X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \ | |
13720 | X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \ | |
13721 | X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \ | |
13722 | /* Register variants of the following two instructions are encoded as | |
e07e6e58 | 13723 | vcge / vcgt with the operands reversed. */ \ |
92559b5b PB |
13724 | X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \ |
13725 | X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \ | |
62f3b8c8 PB |
13726 | X(vfma, N_INV, 0x0000c10, N_INV), \ |
13727 | X(vfms, N_INV, 0x0200c10, N_INV), \ | |
5287ad62 JB |
13728 | X(vmla, 0x0000900, 0x0000d10, 0x0800040), \ |
13729 | X(vmls, 0x1000900, 0x0200d10, 0x0800440), \ | |
13730 | X(vmul, 0x0000910, 0x1000d10, 0x0800840), \ | |
13731 | X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \ | |
13732 | X(vmlal, 0x0800800, N_INV, 0x0800240), \ | |
13733 | X(vmlsl, 0x0800a00, N_INV, 0x0800640), \ | |
13734 | X(vqdmlal, 0x0800900, N_INV, 0x0800340), \ | |
13735 | X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \ | |
13736 | X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \ | |
13737 | X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \ | |
13738 | X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \ | |
d6b4b13e MW |
13739 | X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \ |
13740 | X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \ | |
5287ad62 JB |
13741 | X(vshl, 0x0000400, N_INV, 0x0800510), \ |
13742 | X(vqshl, 0x0000410, N_INV, 0x0800710), \ | |
13743 | X(vand, 0x0000110, N_INV, 0x0800030), \ | |
13744 | X(vbic, 0x0100110, N_INV, 0x0800030), \ | |
13745 | X(veor, 0x1000110, N_INV, N_INV), \ | |
13746 | X(vorn, 0x0300110, N_INV, 0x0800010), \ | |
13747 | X(vorr, 0x0200110, N_INV, 0x0800010), \ | |
13748 | X(vmvn, 0x1b00580, N_INV, 0x0800030), \ | |
13749 | X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \ | |
13750 | X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \ | |
13751 | X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \ | |
13752 | X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \ | |
13753 | X(vst1, 0x0000000, 0x0800000, N_INV), \ | |
13754 | X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \ | |
13755 | X(vst2, 0x0000100, 0x0800100, N_INV), \ | |
13756 | X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \ | |
13757 | X(vst3, 0x0000200, 0x0800200, N_INV), \ | |
13758 | X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \ | |
13759 | X(vst4, 0x0000300, 0x0800300, N_INV), \ | |
13760 | X(vmovn, 0x1b20200, N_INV, N_INV), \ | |
13761 | X(vtrn, 0x1b20080, N_INV, N_INV), \ | |
13762 | X(vqmovn, 0x1b20200, N_INV, N_INV), \ | |
037e8744 JB |
13763 | X(vqmovun, 0x1b20240, N_INV, N_INV), \ |
13764 | X(vnmul, 0xe200a40, 0xe200b40, N_INV), \ | |
e6655fda PB |
13765 | X(vnmla, 0xe100a40, 0xe100b40, N_INV), \ |
13766 | X(vnmls, 0xe100a00, 0xe100b00, N_INV), \ | |
62f3b8c8 PB |
13767 | X(vfnma, 0xe900a40, 0xe900b40, N_INV), \ |
13768 | X(vfnms, 0xe900a00, 0xe900b00, N_INV), \ | |
037e8744 JB |
13769 | X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \ |
13770 | X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \ | |
13771 | X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \ | |
33399f07 MGD |
13772 | X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \ |
13773 | X(vseleq, 0xe000a00, N_INV, N_INV), \ | |
13774 | X(vselvs, 0xe100a00, N_INV, N_INV), \ | |
13775 | X(vselge, 0xe200a00, N_INV, N_INV), \ | |
73924fbc MGD |
13776 | X(vselgt, 0xe300a00, N_INV, N_INV), \ |
13777 | X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \ | |
7e8e6784 | 13778 | X(vminnm, 0xe800a40, 0x3200f10, N_INV), \ |
30bdf752 MGD |
13779 | X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \ |
13780 | X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \ | |
91ff7894 | 13781 | X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \ |
48adcd8e | 13782 | X(aes, 0x3b00300, N_INV, N_INV), \ |
3c9017d2 MGD |
13783 | X(sha3op, 0x2000c00, N_INV, N_INV), \ |
13784 | X(sha1h, 0x3b902c0, N_INV, N_INV), \ | |
13785 | X(sha2op, 0x3ba0380, N_INV, N_INV) | |
5287ad62 JB |
13786 | |
13787 | enum neon_opc | |
13788 | { | |
13789 | #define X(OPC,I,F,S) N_MNEM_##OPC | |
13790 | NEON_ENC_TAB | |
13791 | #undef X | |
13792 | }; | |
b99bd4ef | 13793 | |
5287ad62 JB |
13794 | static const struct neon_tab_entry neon_enc_tab[] = |
13795 | { | |
13796 | #define X(OPC,I,F,S) { (I), (F), (S) } | |
13797 | NEON_ENC_TAB | |
13798 | #undef X | |
13799 | }; | |
b99bd4ef | 13800 | |
88714cb8 DG |
13801 | /* Do not use these macros; instead, use NEON_ENCODE defined below. */ |
13802 | #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
13803 | #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
13804 | #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
13805 | #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
13806 | #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
13807 | #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
13808 | #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
13809 | #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
13810 | #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
13811 | #define NEON_ENC_SINGLE_(X) \ | |
037e8744 | 13812 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000)) |
88714cb8 | 13813 | #define NEON_ENC_DOUBLE_(X) \ |
037e8744 | 13814 | ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000)) |
33399f07 MGD |
13815 | #define NEON_ENC_FPV8_(X) \ |
13816 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000)) | |
5287ad62 | 13817 | |
88714cb8 DG |
13818 | #define NEON_ENCODE(type, inst) \ |
13819 | do \ | |
13820 | { \ | |
13821 | inst.instruction = NEON_ENC_##type##_ (inst.instruction); \ | |
13822 | inst.is_neon = 1; \ | |
13823 | } \ | |
13824 | while (0) | |
13825 | ||
13826 | #define check_neon_suffixes \ | |
13827 | do \ | |
13828 | { \ | |
13829 | if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \ | |
13830 | { \ | |
13831 | as_bad (_("invalid neon suffix for non neon instruction")); \ | |
13832 | return; \ | |
13833 | } \ | |
13834 | } \ | |
13835 | while (0) | |
13836 | ||
037e8744 JB |
13837 | /* Define shapes for instruction operands. The following mnemonic characters |
13838 | are used in this table: | |
5287ad62 | 13839 | |
037e8744 | 13840 | F - VFP S<n> register |
5287ad62 JB |
13841 | D - Neon D<n> register |
13842 | Q - Neon Q<n> register | |
13843 | I - Immediate | |
13844 | S - Scalar | |
13845 | R - ARM register | |
13846 | L - D<n> register list | |
5f4273c7 | 13847 | |
037e8744 JB |
13848 | This table is used to generate various data: |
13849 | - enumerations of the form NS_DDR to be used as arguments to | |
13850 | neon_select_shape. | |
13851 | - a table classifying shapes into single, double, quad, mixed. | |
5f4273c7 | 13852 | - a table used to drive neon_select_shape. */ |
b99bd4ef | 13853 | |
037e8744 JB |
13854 | #define NEON_SHAPE_DEF \ |
13855 | X(3, (D, D, D), DOUBLE), \ | |
13856 | X(3, (Q, Q, Q), QUAD), \ | |
13857 | X(3, (D, D, I), DOUBLE), \ | |
13858 | X(3, (Q, Q, I), QUAD), \ | |
13859 | X(3, (D, D, S), DOUBLE), \ | |
13860 | X(3, (Q, Q, S), QUAD), \ | |
13861 | X(2, (D, D), DOUBLE), \ | |
13862 | X(2, (Q, Q), QUAD), \ | |
13863 | X(2, (D, S), DOUBLE), \ | |
13864 | X(2, (Q, S), QUAD), \ | |
13865 | X(2, (D, R), DOUBLE), \ | |
13866 | X(2, (Q, R), QUAD), \ | |
13867 | X(2, (D, I), DOUBLE), \ | |
13868 | X(2, (Q, I), QUAD), \ | |
13869 | X(3, (D, L, D), DOUBLE), \ | |
13870 | X(2, (D, Q), MIXED), \ | |
13871 | X(2, (Q, D), MIXED), \ | |
13872 | X(3, (D, Q, I), MIXED), \ | |
13873 | X(3, (Q, D, I), MIXED), \ | |
13874 | X(3, (Q, D, D), MIXED), \ | |
13875 | X(3, (D, Q, Q), MIXED), \ | |
13876 | X(3, (Q, Q, D), MIXED), \ | |
13877 | X(3, (Q, D, S), MIXED), \ | |
13878 | X(3, (D, Q, S), MIXED), \ | |
13879 | X(4, (D, D, D, I), DOUBLE), \ | |
13880 | X(4, (Q, Q, Q, I), QUAD), \ | |
c28eeff2 SN |
13881 | X(4, (D, D, S, I), DOUBLE), \ |
13882 | X(4, (Q, Q, S, I), QUAD), \ | |
037e8744 JB |
13883 | X(2, (F, F), SINGLE), \ |
13884 | X(3, (F, F, F), SINGLE), \ | |
13885 | X(2, (F, I), SINGLE), \ | |
13886 | X(2, (F, D), MIXED), \ | |
13887 | X(2, (D, F), MIXED), \ | |
13888 | X(3, (F, F, I), MIXED), \ | |
13889 | X(4, (R, R, F, F), SINGLE), \ | |
13890 | X(4, (F, F, R, R), SINGLE), \ | |
13891 | X(3, (D, R, R), DOUBLE), \ | |
13892 | X(3, (R, R, D), DOUBLE), \ | |
13893 | X(2, (S, R), SINGLE), \ | |
13894 | X(2, (R, S), SINGLE), \ | |
13895 | X(2, (F, R), SINGLE), \ | |
d54af2d0 RL |
13896 | X(2, (R, F), SINGLE), \ |
13897 | /* Half float shape supported so far. */\ | |
13898 | X (2, (H, D), MIXED), \ | |
13899 | X (2, (D, H), MIXED), \ | |
13900 | X (2, (H, F), MIXED), \ | |
13901 | X (2, (F, H), MIXED), \ | |
13902 | X (2, (H, H), HALF), \ | |
13903 | X (2, (H, R), HALF), \ | |
13904 | X (2, (R, H), HALF), \ | |
13905 | X (2, (H, I), HALF), \ | |
13906 | X (3, (H, H, H), HALF), \ | |
13907 | X (3, (H, F, I), MIXED), \ | |
dec41383 JW |
13908 | X (3, (F, H, I), MIXED), \ |
13909 | X (3, (D, H, H), MIXED), \ | |
13910 | X (3, (D, H, S), MIXED) | |
037e8744 JB |
13911 | |
13912 | #define S2(A,B) NS_##A##B | |
13913 | #define S3(A,B,C) NS_##A##B##C | |
13914 | #define S4(A,B,C,D) NS_##A##B##C##D | |
13915 | ||
13916 | #define X(N, L, C) S##N L | |
13917 | ||
5287ad62 JB |
13918 | enum neon_shape |
13919 | { | |
037e8744 JB |
13920 | NEON_SHAPE_DEF, |
13921 | NS_NULL | |
5287ad62 | 13922 | }; |
b99bd4ef | 13923 | |
037e8744 JB |
13924 | #undef X |
13925 | #undef S2 | |
13926 | #undef S3 | |
13927 | #undef S4 | |
13928 | ||
13929 | enum neon_shape_class | |
13930 | { | |
d54af2d0 | 13931 | SC_HALF, |
037e8744 JB |
13932 | SC_SINGLE, |
13933 | SC_DOUBLE, | |
13934 | SC_QUAD, | |
13935 | SC_MIXED | |
13936 | }; | |
13937 | ||
13938 | #define X(N, L, C) SC_##C | |
13939 | ||
13940 | static enum neon_shape_class neon_shape_class[] = | |
13941 | { | |
13942 | NEON_SHAPE_DEF | |
13943 | }; | |
13944 | ||
13945 | #undef X | |
13946 | ||
13947 | enum neon_shape_el | |
13948 | { | |
d54af2d0 | 13949 | SE_H, |
037e8744 JB |
13950 | SE_F, |
13951 | SE_D, | |
13952 | SE_Q, | |
13953 | SE_I, | |
13954 | SE_S, | |
13955 | SE_R, | |
13956 | SE_L | |
13957 | }; | |
13958 | ||
13959 | /* Register widths of above. */ | |
13960 | static unsigned neon_shape_el_size[] = | |
13961 | { | |
d54af2d0 | 13962 | 16, |
037e8744 JB |
13963 | 32, |
13964 | 64, | |
13965 | 128, | |
13966 | 0, | |
13967 | 32, | |
13968 | 32, | |
13969 | 0 | |
13970 | }; | |
13971 | ||
13972 | struct neon_shape_info | |
13973 | { | |
13974 | unsigned els; | |
13975 | enum neon_shape_el el[NEON_MAX_TYPE_ELS]; | |
13976 | }; | |
13977 | ||
13978 | #define S2(A,B) { SE_##A, SE_##B } | |
13979 | #define S3(A,B,C) { SE_##A, SE_##B, SE_##C } | |
13980 | #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D } | |
13981 | ||
13982 | #define X(N, L, C) { N, S##N L } | |
13983 | ||
13984 | static struct neon_shape_info neon_shape_tab[] = | |
13985 | { | |
13986 | NEON_SHAPE_DEF | |
13987 | }; | |
13988 | ||
13989 | #undef X | |
13990 | #undef S2 | |
13991 | #undef S3 | |
13992 | #undef S4 | |
13993 | ||
5287ad62 JB |
13994 | /* Bit masks used in type checking given instructions. |
13995 | 'N_EQK' means the type must be the same as (or based on in some way) the key | |
13996 | type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is | |
13997 | set, various other bits can be set as well in order to modify the meaning of | |
13998 | the type constraint. */ | |
13999 | ||
14000 | enum neon_type_mask | |
14001 | { | |
8e79c3df CM |
14002 | N_S8 = 0x0000001, |
14003 | N_S16 = 0x0000002, | |
14004 | N_S32 = 0x0000004, | |
14005 | N_S64 = 0x0000008, | |
14006 | N_U8 = 0x0000010, | |
14007 | N_U16 = 0x0000020, | |
14008 | N_U32 = 0x0000040, | |
14009 | N_U64 = 0x0000080, | |
14010 | N_I8 = 0x0000100, | |
14011 | N_I16 = 0x0000200, | |
14012 | N_I32 = 0x0000400, | |
14013 | N_I64 = 0x0000800, | |
14014 | N_8 = 0x0001000, | |
14015 | N_16 = 0x0002000, | |
14016 | N_32 = 0x0004000, | |
14017 | N_64 = 0x0008000, | |
14018 | N_P8 = 0x0010000, | |
14019 | N_P16 = 0x0020000, | |
14020 | N_F16 = 0x0040000, | |
14021 | N_F32 = 0x0080000, | |
14022 | N_F64 = 0x0100000, | |
4f51b4bd | 14023 | N_P64 = 0x0200000, |
c921be7d NC |
14024 | N_KEY = 0x1000000, /* Key element (main type specifier). */ |
14025 | N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */ | |
8e79c3df | 14026 | N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */ |
91ff7894 | 14027 | N_UNT = 0x8000000, /* Must be explicitly untyped. */ |
c921be7d NC |
14028 | N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */ |
14029 | N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */ | |
14030 | N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */ | |
14031 | N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */ | |
14032 | N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */ | |
14033 | N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */ | |
14034 | N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */ | |
5287ad62 | 14035 | N_UTYP = 0, |
4f51b4bd | 14036 | N_MAX_NONSPECIAL = N_P64 |
5287ad62 JB |
14037 | }; |
14038 | ||
dcbf9037 JB |
14039 | #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ) |
14040 | ||
5287ad62 JB |
14041 | #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64) |
14042 | #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32) | |
14043 | #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64) | |
cc933301 JW |
14044 | #define N_S_32 (N_S8 | N_S16 | N_S32) |
14045 | #define N_F_16_32 (N_F16 | N_F32) | |
14046 | #define N_SUF_32 (N_SU_32 | N_F_16_32) | |
5287ad62 | 14047 | #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64) |
cc933301 | 14048 | #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32) |
d54af2d0 | 14049 | #define N_F_ALL (N_F16 | N_F32 | N_F64) |
5287ad62 JB |
14050 | |
14051 | /* Pass this as the first type argument to neon_check_type to ignore types | |
14052 | altogether. */ | |
14053 | #define N_IGNORE_TYPE (N_KEY | N_EQK) | |
14054 | ||
037e8744 JB |
14055 | /* Select a "shape" for the current instruction (describing register types or |
14056 | sizes) from a list of alternatives. Return NS_NULL if the current instruction | |
14057 | doesn't fit. For non-polymorphic shapes, checking is usually done as a | |
14058 | function of operand parsing, so this function doesn't need to be called. | |
14059 | Shapes should be listed in order of decreasing length. */ | |
5287ad62 JB |
14060 | |
14061 | static enum neon_shape | |
037e8744 | 14062 | neon_select_shape (enum neon_shape shape, ...) |
5287ad62 | 14063 | { |
037e8744 JB |
14064 | va_list ap; |
14065 | enum neon_shape first_shape = shape; | |
5287ad62 JB |
14066 | |
14067 | /* Fix missing optional operands. FIXME: we don't know at this point how | |
14068 | many arguments we should have, so this makes the assumption that we have | |
14069 | > 1. This is true of all current Neon opcodes, I think, but may not be | |
14070 | true in the future. */ | |
14071 | if (!inst.operands[1].present) | |
14072 | inst.operands[1] = inst.operands[0]; | |
14073 | ||
037e8744 | 14074 | va_start (ap, shape); |
5f4273c7 | 14075 | |
21d799b5 | 14076 | for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int)) |
037e8744 JB |
14077 | { |
14078 | unsigned j; | |
14079 | int matches = 1; | |
14080 | ||
14081 | for (j = 0; j < neon_shape_tab[shape].els; j++) | |
477330fc RM |
14082 | { |
14083 | if (!inst.operands[j].present) | |
14084 | { | |
14085 | matches = 0; | |
14086 | break; | |
14087 | } | |
14088 | ||
14089 | switch (neon_shape_tab[shape].el[j]) | |
14090 | { | |
d54af2d0 RL |
14091 | /* If a .f16, .16, .u16, .s16 type specifier is given over |
14092 | a VFP single precision register operand, it's essentially | |
14093 | means only half of the register is used. | |
14094 | ||
14095 | If the type specifier is given after the mnemonics, the | |
14096 | information is stored in inst.vectype. If the type specifier | |
14097 | is given after register operand, the information is stored | |
14098 | in inst.operands[].vectype. | |
14099 | ||
14100 | When there is only one type specifier, and all the register | |
14101 | operands are the same type of hardware register, the type | |
14102 | specifier applies to all register operands. | |
14103 | ||
14104 | If no type specifier is given, the shape is inferred from | |
14105 | operand information. | |
14106 | ||
14107 | for example: | |
14108 | vadd.f16 s0, s1, s2: NS_HHH | |
14109 | vabs.f16 s0, s1: NS_HH | |
14110 | vmov.f16 s0, r1: NS_HR | |
14111 | vmov.f16 r0, s1: NS_RH | |
14112 | vcvt.f16 r0, s1: NS_RH | |
14113 | vcvt.f16.s32 s2, s2, #29: NS_HFI | |
14114 | vcvt.f16.s32 s2, s2: NS_HF | |
14115 | */ | |
14116 | case SE_H: | |
14117 | if (!(inst.operands[j].isreg | |
14118 | && inst.operands[j].isvec | |
14119 | && inst.operands[j].issingle | |
14120 | && !inst.operands[j].isquad | |
14121 | && ((inst.vectype.elems == 1 | |
14122 | && inst.vectype.el[0].size == 16) | |
14123 | || (inst.vectype.elems > 1 | |
14124 | && inst.vectype.el[j].size == 16) | |
14125 | || (inst.vectype.elems == 0 | |
14126 | && inst.operands[j].vectype.type != NT_invtype | |
14127 | && inst.operands[j].vectype.size == 16)))) | |
14128 | matches = 0; | |
14129 | break; | |
14130 | ||
477330fc RM |
14131 | case SE_F: |
14132 | if (!(inst.operands[j].isreg | |
14133 | && inst.operands[j].isvec | |
14134 | && inst.operands[j].issingle | |
d54af2d0 RL |
14135 | && !inst.operands[j].isquad |
14136 | && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32) | |
14137 | || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32) | |
14138 | || (inst.vectype.elems == 0 | |
14139 | && (inst.operands[j].vectype.size == 32 | |
14140 | || inst.operands[j].vectype.type == NT_invtype))))) | |
477330fc RM |
14141 | matches = 0; |
14142 | break; | |
14143 | ||
14144 | case SE_D: | |
14145 | if (!(inst.operands[j].isreg | |
14146 | && inst.operands[j].isvec | |
14147 | && !inst.operands[j].isquad | |
14148 | && !inst.operands[j].issingle)) | |
14149 | matches = 0; | |
14150 | break; | |
14151 | ||
14152 | case SE_R: | |
14153 | if (!(inst.operands[j].isreg | |
14154 | && !inst.operands[j].isvec)) | |
14155 | matches = 0; | |
14156 | break; | |
14157 | ||
14158 | case SE_Q: | |
14159 | if (!(inst.operands[j].isreg | |
14160 | && inst.operands[j].isvec | |
14161 | && inst.operands[j].isquad | |
14162 | && !inst.operands[j].issingle)) | |
14163 | matches = 0; | |
14164 | break; | |
14165 | ||
14166 | case SE_I: | |
14167 | if (!(!inst.operands[j].isreg | |
14168 | && !inst.operands[j].isscalar)) | |
14169 | matches = 0; | |
14170 | break; | |
14171 | ||
14172 | case SE_S: | |
14173 | if (!(!inst.operands[j].isreg | |
14174 | && inst.operands[j].isscalar)) | |
14175 | matches = 0; | |
14176 | break; | |
14177 | ||
14178 | case SE_L: | |
14179 | break; | |
14180 | } | |
3fde54a2 JZ |
14181 | if (!matches) |
14182 | break; | |
477330fc | 14183 | } |
ad6cec43 MGD |
14184 | if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present)) |
14185 | /* We've matched all the entries in the shape table, and we don't | |
14186 | have any left over operands which have not been matched. */ | |
477330fc | 14187 | break; |
037e8744 | 14188 | } |
5f4273c7 | 14189 | |
037e8744 | 14190 | va_end (ap); |
5287ad62 | 14191 | |
037e8744 JB |
14192 | if (shape == NS_NULL && first_shape != NS_NULL) |
14193 | first_error (_("invalid instruction shape")); | |
5287ad62 | 14194 | |
037e8744 JB |
14195 | return shape; |
14196 | } | |
5287ad62 | 14197 | |
037e8744 JB |
14198 | /* True if SHAPE is predominantly a quadword operation (most of the time, this |
14199 | means the Q bit should be set). */ | |
14200 | ||
14201 | static int | |
14202 | neon_quad (enum neon_shape shape) | |
14203 | { | |
14204 | return neon_shape_class[shape] == SC_QUAD; | |
5287ad62 | 14205 | } |
037e8744 | 14206 | |
5287ad62 JB |
14207 | static void |
14208 | neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type, | |
477330fc | 14209 | unsigned *g_size) |
5287ad62 JB |
14210 | { |
14211 | /* Allow modification to be made to types which are constrained to be | |
14212 | based on the key element, based on bits set alongside N_EQK. */ | |
14213 | if ((typebits & N_EQK) != 0) | |
14214 | { | |
14215 | if ((typebits & N_HLF) != 0) | |
14216 | *g_size /= 2; | |
14217 | else if ((typebits & N_DBL) != 0) | |
14218 | *g_size *= 2; | |
14219 | if ((typebits & N_SGN) != 0) | |
14220 | *g_type = NT_signed; | |
14221 | else if ((typebits & N_UNS) != 0) | |
477330fc | 14222 | *g_type = NT_unsigned; |
5287ad62 | 14223 | else if ((typebits & N_INT) != 0) |
477330fc | 14224 | *g_type = NT_integer; |
5287ad62 | 14225 | else if ((typebits & N_FLT) != 0) |
477330fc | 14226 | *g_type = NT_float; |
dcbf9037 | 14227 | else if ((typebits & N_SIZ) != 0) |
477330fc | 14228 | *g_type = NT_untyped; |
5287ad62 JB |
14229 | } |
14230 | } | |
5f4273c7 | 14231 | |
5287ad62 JB |
14232 | /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key" |
14233 | operand type, i.e. the single type specified in a Neon instruction when it | |
14234 | is the only one given. */ | |
14235 | ||
14236 | static struct neon_type_el | |
14237 | neon_type_promote (struct neon_type_el *key, unsigned thisarg) | |
14238 | { | |
14239 | struct neon_type_el dest = *key; | |
5f4273c7 | 14240 | |
9c2799c2 | 14241 | gas_assert ((thisarg & N_EQK) != 0); |
5f4273c7 | 14242 | |
5287ad62 JB |
14243 | neon_modify_type_size (thisarg, &dest.type, &dest.size); |
14244 | ||
14245 | return dest; | |
14246 | } | |
14247 | ||
14248 | /* Convert Neon type and size into compact bitmask representation. */ | |
14249 | ||
14250 | static enum neon_type_mask | |
14251 | type_chk_of_el_type (enum neon_el_type type, unsigned size) | |
14252 | { | |
14253 | switch (type) | |
14254 | { | |
14255 | case NT_untyped: | |
14256 | switch (size) | |
477330fc RM |
14257 | { |
14258 | case 8: return N_8; | |
14259 | case 16: return N_16; | |
14260 | case 32: return N_32; | |
14261 | case 64: return N_64; | |
14262 | default: ; | |
14263 | } | |
5287ad62 JB |
14264 | break; |
14265 | ||
14266 | case NT_integer: | |
14267 | switch (size) | |
477330fc RM |
14268 | { |
14269 | case 8: return N_I8; | |
14270 | case 16: return N_I16; | |
14271 | case 32: return N_I32; | |
14272 | case 64: return N_I64; | |
14273 | default: ; | |
14274 | } | |
5287ad62 JB |
14275 | break; |
14276 | ||
14277 | case NT_float: | |
037e8744 | 14278 | switch (size) |
477330fc | 14279 | { |
8e79c3df | 14280 | case 16: return N_F16; |
477330fc RM |
14281 | case 32: return N_F32; |
14282 | case 64: return N_F64; | |
14283 | default: ; | |
14284 | } | |
5287ad62 JB |
14285 | break; |
14286 | ||
14287 | case NT_poly: | |
14288 | switch (size) | |
477330fc RM |
14289 | { |
14290 | case 8: return N_P8; | |
14291 | case 16: return N_P16; | |
4f51b4bd | 14292 | case 64: return N_P64; |
477330fc RM |
14293 | default: ; |
14294 | } | |
5287ad62 JB |
14295 | break; |
14296 | ||
14297 | case NT_signed: | |
14298 | switch (size) | |
477330fc RM |
14299 | { |
14300 | case 8: return N_S8; | |
14301 | case 16: return N_S16; | |
14302 | case 32: return N_S32; | |
14303 | case 64: return N_S64; | |
14304 | default: ; | |
14305 | } | |
5287ad62 JB |
14306 | break; |
14307 | ||
14308 | case NT_unsigned: | |
14309 | switch (size) | |
477330fc RM |
14310 | { |
14311 | case 8: return N_U8; | |
14312 | case 16: return N_U16; | |
14313 | case 32: return N_U32; | |
14314 | case 64: return N_U64; | |
14315 | default: ; | |
14316 | } | |
5287ad62 JB |
14317 | break; |
14318 | ||
14319 | default: ; | |
14320 | } | |
5f4273c7 | 14321 | |
5287ad62 JB |
14322 | return N_UTYP; |
14323 | } | |
14324 | ||
14325 | /* Convert compact Neon bitmask type representation to a type and size. Only | |
14326 | handles the case where a single bit is set in the mask. */ | |
14327 | ||
dcbf9037 | 14328 | static int |
5287ad62 | 14329 | el_type_of_type_chk (enum neon_el_type *type, unsigned *size, |
477330fc | 14330 | enum neon_type_mask mask) |
5287ad62 | 14331 | { |
dcbf9037 JB |
14332 | if ((mask & N_EQK) != 0) |
14333 | return FAIL; | |
14334 | ||
5287ad62 JB |
14335 | if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0) |
14336 | *size = 8; | |
c70a8987 | 14337 | else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0) |
5287ad62 | 14338 | *size = 16; |
dcbf9037 | 14339 | else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0) |
5287ad62 | 14340 | *size = 32; |
4f51b4bd | 14341 | else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0) |
5287ad62 | 14342 | *size = 64; |
dcbf9037 JB |
14343 | else |
14344 | return FAIL; | |
14345 | ||
5287ad62 JB |
14346 | if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0) |
14347 | *type = NT_signed; | |
dcbf9037 | 14348 | else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0) |
5287ad62 | 14349 | *type = NT_unsigned; |
dcbf9037 | 14350 | else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0) |
5287ad62 | 14351 | *type = NT_integer; |
dcbf9037 | 14352 | else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0) |
5287ad62 | 14353 | *type = NT_untyped; |
4f51b4bd | 14354 | else if ((mask & (N_P8 | N_P16 | N_P64)) != 0) |
5287ad62 | 14355 | *type = NT_poly; |
d54af2d0 | 14356 | else if ((mask & (N_F_ALL)) != 0) |
5287ad62 | 14357 | *type = NT_float; |
dcbf9037 JB |
14358 | else |
14359 | return FAIL; | |
5f4273c7 | 14360 | |
dcbf9037 | 14361 | return SUCCESS; |
5287ad62 JB |
14362 | } |
14363 | ||
14364 | /* Modify a bitmask of allowed types. This is only needed for type | |
14365 | relaxation. */ | |
14366 | ||
14367 | static unsigned | |
14368 | modify_types_allowed (unsigned allowed, unsigned mods) | |
14369 | { | |
14370 | unsigned size; | |
14371 | enum neon_el_type type; | |
14372 | unsigned destmask; | |
14373 | int i; | |
5f4273c7 | 14374 | |
5287ad62 | 14375 | destmask = 0; |
5f4273c7 | 14376 | |
5287ad62 JB |
14377 | for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1) |
14378 | { | |
21d799b5 | 14379 | if (el_type_of_type_chk (&type, &size, |
477330fc RM |
14380 | (enum neon_type_mask) (allowed & i)) == SUCCESS) |
14381 | { | |
14382 | neon_modify_type_size (mods, &type, &size); | |
14383 | destmask |= type_chk_of_el_type (type, size); | |
14384 | } | |
5287ad62 | 14385 | } |
5f4273c7 | 14386 | |
5287ad62 JB |
14387 | return destmask; |
14388 | } | |
14389 | ||
14390 | /* Check type and return type classification. | |
14391 | The manual states (paraphrase): If one datatype is given, it indicates the | |
14392 | type given in: | |
14393 | - the second operand, if there is one | |
14394 | - the operand, if there is no second operand | |
14395 | - the result, if there are no operands. | |
14396 | This isn't quite good enough though, so we use a concept of a "key" datatype | |
14397 | which is set on a per-instruction basis, which is the one which matters when | |
14398 | only one data type is written. | |
14399 | Note: this function has side-effects (e.g. filling in missing operands). All | |
037e8744 | 14400 | Neon instructions should call it before performing bit encoding. */ |
5287ad62 JB |
14401 | |
14402 | static struct neon_type_el | |
14403 | neon_check_type (unsigned els, enum neon_shape ns, ...) | |
14404 | { | |
14405 | va_list ap; | |
14406 | unsigned i, pass, key_el = 0; | |
14407 | unsigned types[NEON_MAX_TYPE_ELS]; | |
14408 | enum neon_el_type k_type = NT_invtype; | |
14409 | unsigned k_size = -1u; | |
14410 | struct neon_type_el badtype = {NT_invtype, -1}; | |
14411 | unsigned key_allowed = 0; | |
14412 | ||
14413 | /* Optional registers in Neon instructions are always (not) in operand 1. | |
14414 | Fill in the missing operand here, if it was omitted. */ | |
14415 | if (els > 1 && !inst.operands[1].present) | |
14416 | inst.operands[1] = inst.operands[0]; | |
14417 | ||
14418 | /* Suck up all the varargs. */ | |
14419 | va_start (ap, ns); | |
14420 | for (i = 0; i < els; i++) | |
14421 | { | |
14422 | unsigned thisarg = va_arg (ap, unsigned); | |
14423 | if (thisarg == N_IGNORE_TYPE) | |
477330fc RM |
14424 | { |
14425 | va_end (ap); | |
14426 | return badtype; | |
14427 | } | |
5287ad62 JB |
14428 | types[i] = thisarg; |
14429 | if ((thisarg & N_KEY) != 0) | |
477330fc | 14430 | key_el = i; |
5287ad62 JB |
14431 | } |
14432 | va_end (ap); | |
14433 | ||
dcbf9037 JB |
14434 | if (inst.vectype.elems > 0) |
14435 | for (i = 0; i < els; i++) | |
14436 | if (inst.operands[i].vectype.type != NT_invtype) | |
477330fc RM |
14437 | { |
14438 | first_error (_("types specified in both the mnemonic and operands")); | |
14439 | return badtype; | |
14440 | } | |
dcbf9037 | 14441 | |
5287ad62 JB |
14442 | /* Duplicate inst.vectype elements here as necessary. |
14443 | FIXME: No idea if this is exactly the same as the ARM assembler, | |
14444 | particularly when an insn takes one register and one non-register | |
14445 | operand. */ | |
14446 | if (inst.vectype.elems == 1 && els > 1) | |
14447 | { | |
14448 | unsigned j; | |
14449 | inst.vectype.elems = els; | |
14450 | inst.vectype.el[key_el] = inst.vectype.el[0]; | |
14451 | for (j = 0; j < els; j++) | |
477330fc RM |
14452 | if (j != key_el) |
14453 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
14454 | types[j]); | |
dcbf9037 JB |
14455 | } |
14456 | else if (inst.vectype.elems == 0 && els > 0) | |
14457 | { | |
14458 | unsigned j; | |
14459 | /* No types were given after the mnemonic, so look for types specified | |
477330fc RM |
14460 | after each operand. We allow some flexibility here; as long as the |
14461 | "key" operand has a type, we can infer the others. */ | |
dcbf9037 | 14462 | for (j = 0; j < els; j++) |
477330fc RM |
14463 | if (inst.operands[j].vectype.type != NT_invtype) |
14464 | inst.vectype.el[j] = inst.operands[j].vectype; | |
dcbf9037 JB |
14465 | |
14466 | if (inst.operands[key_el].vectype.type != NT_invtype) | |
477330fc RM |
14467 | { |
14468 | for (j = 0; j < els; j++) | |
14469 | if (inst.operands[j].vectype.type == NT_invtype) | |
14470 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
14471 | types[j]); | |
14472 | } | |
dcbf9037 | 14473 | else |
477330fc RM |
14474 | { |
14475 | first_error (_("operand types can't be inferred")); | |
14476 | return badtype; | |
14477 | } | |
5287ad62 JB |
14478 | } |
14479 | else if (inst.vectype.elems != els) | |
14480 | { | |
dcbf9037 | 14481 | first_error (_("type specifier has the wrong number of parts")); |
5287ad62 JB |
14482 | return badtype; |
14483 | } | |
14484 | ||
14485 | for (pass = 0; pass < 2; pass++) | |
14486 | { | |
14487 | for (i = 0; i < els; i++) | |
477330fc RM |
14488 | { |
14489 | unsigned thisarg = types[i]; | |
14490 | unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0) | |
14491 | ? modify_types_allowed (key_allowed, thisarg) : thisarg; | |
14492 | enum neon_el_type g_type = inst.vectype.el[i].type; | |
14493 | unsigned g_size = inst.vectype.el[i].size; | |
14494 | ||
14495 | /* Decay more-specific signed & unsigned types to sign-insensitive | |
5287ad62 | 14496 | integer types if sign-specific variants are unavailable. */ |
477330fc | 14497 | if ((g_type == NT_signed || g_type == NT_unsigned) |
5287ad62 JB |
14498 | && (types_allowed & N_SU_ALL) == 0) |
14499 | g_type = NT_integer; | |
14500 | ||
477330fc | 14501 | /* If only untyped args are allowed, decay any more specific types to |
5287ad62 JB |
14502 | them. Some instructions only care about signs for some element |
14503 | sizes, so handle that properly. */ | |
477330fc | 14504 | if (((types_allowed & N_UNT) == 0) |
91ff7894 MGD |
14505 | && ((g_size == 8 && (types_allowed & N_8) != 0) |
14506 | || (g_size == 16 && (types_allowed & N_16) != 0) | |
14507 | || (g_size == 32 && (types_allowed & N_32) != 0) | |
14508 | || (g_size == 64 && (types_allowed & N_64) != 0))) | |
5287ad62 JB |
14509 | g_type = NT_untyped; |
14510 | ||
477330fc RM |
14511 | if (pass == 0) |
14512 | { | |
14513 | if ((thisarg & N_KEY) != 0) | |
14514 | { | |
14515 | k_type = g_type; | |
14516 | k_size = g_size; | |
14517 | key_allowed = thisarg & ~N_KEY; | |
cc933301 JW |
14518 | |
14519 | /* Check architecture constraint on FP16 extension. */ | |
14520 | if (k_size == 16 | |
14521 | && k_type == NT_float | |
14522 | && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)) | |
14523 | { | |
14524 | inst.error = _(BAD_FP16); | |
14525 | return badtype; | |
14526 | } | |
477330fc RM |
14527 | } |
14528 | } | |
14529 | else | |
14530 | { | |
14531 | if ((thisarg & N_VFP) != 0) | |
14532 | { | |
14533 | enum neon_shape_el regshape; | |
14534 | unsigned regwidth, match; | |
99b253c5 NC |
14535 | |
14536 | /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */ | |
14537 | if (ns == NS_NULL) | |
14538 | { | |
14539 | first_error (_("invalid instruction shape")); | |
14540 | return badtype; | |
14541 | } | |
477330fc RM |
14542 | regshape = neon_shape_tab[ns].el[i]; |
14543 | regwidth = neon_shape_el_size[regshape]; | |
14544 | ||
14545 | /* In VFP mode, operands must match register widths. If we | |
14546 | have a key operand, use its width, else use the width of | |
14547 | the current operand. */ | |
14548 | if (k_size != -1u) | |
14549 | match = k_size; | |
14550 | else | |
14551 | match = g_size; | |
14552 | ||
9db2f6b4 RL |
14553 | /* FP16 will use a single precision register. */ |
14554 | if (regwidth == 32 && match == 16) | |
14555 | { | |
14556 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)) | |
14557 | match = regwidth; | |
14558 | else | |
14559 | { | |
14560 | inst.error = _(BAD_FP16); | |
14561 | return badtype; | |
14562 | } | |
14563 | } | |
14564 | ||
477330fc RM |
14565 | if (regwidth != match) |
14566 | { | |
14567 | first_error (_("operand size must match register width")); | |
14568 | return badtype; | |
14569 | } | |
14570 | } | |
14571 | ||
14572 | if ((thisarg & N_EQK) == 0) | |
14573 | { | |
14574 | unsigned given_type = type_chk_of_el_type (g_type, g_size); | |
14575 | ||
14576 | if ((given_type & types_allowed) == 0) | |
14577 | { | |
14578 | first_error (_("bad type in Neon instruction")); | |
14579 | return badtype; | |
14580 | } | |
14581 | } | |
14582 | else | |
14583 | { | |
14584 | enum neon_el_type mod_k_type = k_type; | |
14585 | unsigned mod_k_size = k_size; | |
14586 | neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size); | |
14587 | if (g_type != mod_k_type || g_size != mod_k_size) | |
14588 | { | |
14589 | first_error (_("inconsistent types in Neon instruction")); | |
14590 | return badtype; | |
14591 | } | |
14592 | } | |
14593 | } | |
14594 | } | |
5287ad62 JB |
14595 | } |
14596 | ||
14597 | return inst.vectype.el[key_el]; | |
14598 | } | |
14599 | ||
037e8744 | 14600 | /* Neon-style VFP instruction forwarding. */ |
5287ad62 | 14601 | |
037e8744 JB |
14602 | /* Thumb VFP instructions have 0xE in the condition field. */ |
14603 | ||
14604 | static void | |
14605 | do_vfp_cond_or_thumb (void) | |
5287ad62 | 14606 | { |
88714cb8 DG |
14607 | inst.is_neon = 1; |
14608 | ||
5287ad62 | 14609 | if (thumb_mode) |
037e8744 | 14610 | inst.instruction |= 0xe0000000; |
5287ad62 | 14611 | else |
037e8744 | 14612 | inst.instruction |= inst.cond << 28; |
5287ad62 JB |
14613 | } |
14614 | ||
037e8744 JB |
14615 | /* Look up and encode a simple mnemonic, for use as a helper function for the |
14616 | Neon-style VFP syntax. This avoids duplication of bits of the insns table, | |
14617 | etc. It is assumed that operand parsing has already been done, and that the | |
14618 | operands are in the form expected by the given opcode (this isn't necessarily | |
14619 | the same as the form in which they were parsed, hence some massaging must | |
14620 | take place before this function is called). | |
14621 | Checks current arch version against that in the looked-up opcode. */ | |
5287ad62 | 14622 | |
037e8744 JB |
14623 | static void |
14624 | do_vfp_nsyn_opcode (const char *opname) | |
5287ad62 | 14625 | { |
037e8744 | 14626 | const struct asm_opcode *opcode; |
5f4273c7 | 14627 | |
21d799b5 | 14628 | opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname); |
5287ad62 | 14629 | |
037e8744 JB |
14630 | if (!opcode) |
14631 | abort (); | |
5287ad62 | 14632 | |
037e8744 | 14633 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, |
477330fc RM |
14634 | thumb_mode ? *opcode->tvariant : *opcode->avariant), |
14635 | _(BAD_FPU)); | |
5287ad62 | 14636 | |
88714cb8 DG |
14637 | inst.is_neon = 1; |
14638 | ||
037e8744 JB |
14639 | if (thumb_mode) |
14640 | { | |
14641 | inst.instruction = opcode->tvalue; | |
14642 | opcode->tencode (); | |
14643 | } | |
14644 | else | |
14645 | { | |
14646 | inst.instruction = (inst.cond << 28) | opcode->avalue; | |
14647 | opcode->aencode (); | |
14648 | } | |
14649 | } | |
5287ad62 JB |
14650 | |
14651 | static void | |
037e8744 | 14652 | do_vfp_nsyn_add_sub (enum neon_shape rs) |
5287ad62 | 14653 | { |
037e8744 JB |
14654 | int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd; |
14655 | ||
9db2f6b4 | 14656 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 JB |
14657 | { |
14658 | if (is_add) | |
477330fc | 14659 | do_vfp_nsyn_opcode ("fadds"); |
037e8744 | 14660 | else |
477330fc | 14661 | do_vfp_nsyn_opcode ("fsubs"); |
9db2f6b4 RL |
14662 | |
14663 | /* ARMv8.2 fp16 instruction. */ | |
14664 | if (rs == NS_HHH) | |
14665 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14666 | } |
14667 | else | |
14668 | { | |
14669 | if (is_add) | |
477330fc | 14670 | do_vfp_nsyn_opcode ("faddd"); |
037e8744 | 14671 | else |
477330fc | 14672 | do_vfp_nsyn_opcode ("fsubd"); |
037e8744 JB |
14673 | } |
14674 | } | |
14675 | ||
14676 | /* Check operand types to see if this is a VFP instruction, and if so call | |
14677 | PFN (). */ | |
14678 | ||
14679 | static int | |
14680 | try_vfp_nsyn (int args, void (*pfn) (enum neon_shape)) | |
14681 | { | |
14682 | enum neon_shape rs; | |
14683 | struct neon_type_el et; | |
14684 | ||
14685 | switch (args) | |
14686 | { | |
14687 | case 2: | |
9db2f6b4 RL |
14688 | rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL); |
14689 | et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP); | |
037e8744 | 14690 | break; |
5f4273c7 | 14691 | |
037e8744 | 14692 | case 3: |
9db2f6b4 RL |
14693 | rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
14694 | et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
14695 | N_F_ALL | N_KEY | N_VFP); | |
037e8744 JB |
14696 | break; |
14697 | ||
14698 | default: | |
14699 | abort (); | |
14700 | } | |
14701 | ||
14702 | if (et.type != NT_invtype) | |
14703 | { | |
14704 | pfn (rs); | |
14705 | return SUCCESS; | |
14706 | } | |
037e8744 | 14707 | |
99b253c5 | 14708 | inst.error = NULL; |
037e8744 JB |
14709 | return FAIL; |
14710 | } | |
14711 | ||
14712 | static void | |
14713 | do_vfp_nsyn_mla_mls (enum neon_shape rs) | |
14714 | { | |
14715 | int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla; | |
5f4273c7 | 14716 | |
9db2f6b4 | 14717 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 JB |
14718 | { |
14719 | if (is_mla) | |
477330fc | 14720 | do_vfp_nsyn_opcode ("fmacs"); |
037e8744 | 14721 | else |
477330fc | 14722 | do_vfp_nsyn_opcode ("fnmacs"); |
9db2f6b4 RL |
14723 | |
14724 | /* ARMv8.2 fp16 instruction. */ | |
14725 | if (rs == NS_HHH) | |
14726 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14727 | } |
14728 | else | |
14729 | { | |
14730 | if (is_mla) | |
477330fc | 14731 | do_vfp_nsyn_opcode ("fmacd"); |
037e8744 | 14732 | else |
477330fc | 14733 | do_vfp_nsyn_opcode ("fnmacd"); |
037e8744 JB |
14734 | } |
14735 | } | |
14736 | ||
62f3b8c8 PB |
14737 | static void |
14738 | do_vfp_nsyn_fma_fms (enum neon_shape rs) | |
14739 | { | |
14740 | int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma; | |
14741 | ||
9db2f6b4 | 14742 | if (rs == NS_FFF || rs == NS_HHH) |
62f3b8c8 PB |
14743 | { |
14744 | if (is_fma) | |
477330fc | 14745 | do_vfp_nsyn_opcode ("ffmas"); |
62f3b8c8 | 14746 | else |
477330fc | 14747 | do_vfp_nsyn_opcode ("ffnmas"); |
9db2f6b4 RL |
14748 | |
14749 | /* ARMv8.2 fp16 instruction. */ | |
14750 | if (rs == NS_HHH) | |
14751 | do_scalar_fp16_v82_encode (); | |
62f3b8c8 PB |
14752 | } |
14753 | else | |
14754 | { | |
14755 | if (is_fma) | |
477330fc | 14756 | do_vfp_nsyn_opcode ("ffmad"); |
62f3b8c8 | 14757 | else |
477330fc | 14758 | do_vfp_nsyn_opcode ("ffnmad"); |
62f3b8c8 PB |
14759 | } |
14760 | } | |
14761 | ||
037e8744 JB |
14762 | static void |
14763 | do_vfp_nsyn_mul (enum neon_shape rs) | |
14764 | { | |
9db2f6b4 RL |
14765 | if (rs == NS_FFF || rs == NS_HHH) |
14766 | { | |
14767 | do_vfp_nsyn_opcode ("fmuls"); | |
14768 | ||
14769 | /* ARMv8.2 fp16 instruction. */ | |
14770 | if (rs == NS_HHH) | |
14771 | do_scalar_fp16_v82_encode (); | |
14772 | } | |
037e8744 JB |
14773 | else |
14774 | do_vfp_nsyn_opcode ("fmuld"); | |
14775 | } | |
14776 | ||
14777 | static void | |
14778 | do_vfp_nsyn_abs_neg (enum neon_shape rs) | |
14779 | { | |
14780 | int is_neg = (inst.instruction & 0x80) != 0; | |
9db2f6b4 | 14781 | neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY); |
037e8744 | 14782 | |
9db2f6b4 | 14783 | if (rs == NS_FF || rs == NS_HH) |
037e8744 JB |
14784 | { |
14785 | if (is_neg) | |
477330fc | 14786 | do_vfp_nsyn_opcode ("fnegs"); |
037e8744 | 14787 | else |
477330fc | 14788 | do_vfp_nsyn_opcode ("fabss"); |
9db2f6b4 RL |
14789 | |
14790 | /* ARMv8.2 fp16 instruction. */ | |
14791 | if (rs == NS_HH) | |
14792 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14793 | } |
14794 | else | |
14795 | { | |
14796 | if (is_neg) | |
477330fc | 14797 | do_vfp_nsyn_opcode ("fnegd"); |
037e8744 | 14798 | else |
477330fc | 14799 | do_vfp_nsyn_opcode ("fabsd"); |
037e8744 JB |
14800 | } |
14801 | } | |
14802 | ||
14803 | /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision | |
14804 | insns belong to Neon, and are handled elsewhere. */ | |
14805 | ||
14806 | static void | |
14807 | do_vfp_nsyn_ldm_stm (int is_dbmode) | |
14808 | { | |
14809 | int is_ldm = (inst.instruction & (1 << 20)) != 0; | |
14810 | if (is_ldm) | |
14811 | { | |
14812 | if (is_dbmode) | |
477330fc | 14813 | do_vfp_nsyn_opcode ("fldmdbs"); |
037e8744 | 14814 | else |
477330fc | 14815 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 JB |
14816 | } |
14817 | else | |
14818 | { | |
14819 | if (is_dbmode) | |
477330fc | 14820 | do_vfp_nsyn_opcode ("fstmdbs"); |
037e8744 | 14821 | else |
477330fc | 14822 | do_vfp_nsyn_opcode ("fstmias"); |
037e8744 JB |
14823 | } |
14824 | } | |
14825 | ||
037e8744 JB |
14826 | static void |
14827 | do_vfp_nsyn_sqrt (void) | |
14828 | { | |
9db2f6b4 RL |
14829 | enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL); |
14830 | neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP); | |
5f4273c7 | 14831 | |
9db2f6b4 RL |
14832 | if (rs == NS_FF || rs == NS_HH) |
14833 | { | |
14834 | do_vfp_nsyn_opcode ("fsqrts"); | |
14835 | ||
14836 | /* ARMv8.2 fp16 instruction. */ | |
14837 | if (rs == NS_HH) | |
14838 | do_scalar_fp16_v82_encode (); | |
14839 | } | |
037e8744 JB |
14840 | else |
14841 | do_vfp_nsyn_opcode ("fsqrtd"); | |
14842 | } | |
14843 | ||
14844 | static void | |
14845 | do_vfp_nsyn_div (void) | |
14846 | { | |
9db2f6b4 | 14847 | enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
037e8744 | 14848 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, |
9db2f6b4 | 14849 | N_F_ALL | N_KEY | N_VFP); |
5f4273c7 | 14850 | |
9db2f6b4 RL |
14851 | if (rs == NS_FFF || rs == NS_HHH) |
14852 | { | |
14853 | do_vfp_nsyn_opcode ("fdivs"); | |
14854 | ||
14855 | /* ARMv8.2 fp16 instruction. */ | |
14856 | if (rs == NS_HHH) | |
14857 | do_scalar_fp16_v82_encode (); | |
14858 | } | |
037e8744 JB |
14859 | else |
14860 | do_vfp_nsyn_opcode ("fdivd"); | |
14861 | } | |
14862 | ||
14863 | static void | |
14864 | do_vfp_nsyn_nmul (void) | |
14865 | { | |
9db2f6b4 | 14866 | enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
037e8744 | 14867 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, |
9db2f6b4 | 14868 | N_F_ALL | N_KEY | N_VFP); |
5f4273c7 | 14869 | |
9db2f6b4 | 14870 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 | 14871 | { |
88714cb8 | 14872 | NEON_ENCODE (SINGLE, inst); |
037e8744 | 14873 | do_vfp_sp_dyadic (); |
9db2f6b4 RL |
14874 | |
14875 | /* ARMv8.2 fp16 instruction. */ | |
14876 | if (rs == NS_HHH) | |
14877 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14878 | } |
14879 | else | |
14880 | { | |
88714cb8 | 14881 | NEON_ENCODE (DOUBLE, inst); |
037e8744 JB |
14882 | do_vfp_dp_rd_rn_rm (); |
14883 | } | |
14884 | do_vfp_cond_or_thumb (); | |
9db2f6b4 | 14885 | |
037e8744 JB |
14886 | } |
14887 | ||
14888 | static void | |
14889 | do_vfp_nsyn_cmp (void) | |
14890 | { | |
9db2f6b4 | 14891 | enum neon_shape rs; |
037e8744 JB |
14892 | if (inst.operands[1].isreg) |
14893 | { | |
9db2f6b4 RL |
14894 | rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL); |
14895 | neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP); | |
5f4273c7 | 14896 | |
9db2f6b4 | 14897 | if (rs == NS_FF || rs == NS_HH) |
477330fc RM |
14898 | { |
14899 | NEON_ENCODE (SINGLE, inst); | |
14900 | do_vfp_sp_monadic (); | |
14901 | } | |
037e8744 | 14902 | else |
477330fc RM |
14903 | { |
14904 | NEON_ENCODE (DOUBLE, inst); | |
14905 | do_vfp_dp_rd_rm (); | |
14906 | } | |
037e8744 JB |
14907 | } |
14908 | else | |
14909 | { | |
9db2f6b4 RL |
14910 | rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL); |
14911 | neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK); | |
037e8744 JB |
14912 | |
14913 | switch (inst.instruction & 0x0fffffff) | |
477330fc RM |
14914 | { |
14915 | case N_MNEM_vcmp: | |
14916 | inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp; | |
14917 | break; | |
14918 | case N_MNEM_vcmpe: | |
14919 | inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe; | |
14920 | break; | |
14921 | default: | |
14922 | abort (); | |
14923 | } | |
5f4273c7 | 14924 | |
9db2f6b4 | 14925 | if (rs == NS_FI || rs == NS_HI) |
477330fc RM |
14926 | { |
14927 | NEON_ENCODE (SINGLE, inst); | |
14928 | do_vfp_sp_compare_z (); | |
14929 | } | |
037e8744 | 14930 | else |
477330fc RM |
14931 | { |
14932 | NEON_ENCODE (DOUBLE, inst); | |
14933 | do_vfp_dp_rd (); | |
14934 | } | |
037e8744 JB |
14935 | } |
14936 | do_vfp_cond_or_thumb (); | |
9db2f6b4 RL |
14937 | |
14938 | /* ARMv8.2 fp16 instruction. */ | |
14939 | if (rs == NS_HI || rs == NS_HH) | |
14940 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14941 | } |
14942 | ||
14943 | static void | |
14944 | nsyn_insert_sp (void) | |
14945 | { | |
14946 | inst.operands[1] = inst.operands[0]; | |
14947 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
fdfde340 | 14948 | inst.operands[0].reg = REG_SP; |
037e8744 JB |
14949 | inst.operands[0].isreg = 1; |
14950 | inst.operands[0].writeback = 1; | |
14951 | inst.operands[0].present = 1; | |
14952 | } | |
14953 | ||
14954 | static void | |
14955 | do_vfp_nsyn_push (void) | |
14956 | { | |
14957 | nsyn_insert_sp (); | |
b126985e NC |
14958 | |
14959 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
14960 | _("register list must contain at least 1 and at most 16 " | |
14961 | "registers")); | |
14962 | ||
037e8744 JB |
14963 | if (inst.operands[1].issingle) |
14964 | do_vfp_nsyn_opcode ("fstmdbs"); | |
14965 | else | |
14966 | do_vfp_nsyn_opcode ("fstmdbd"); | |
14967 | } | |
14968 | ||
14969 | static void | |
14970 | do_vfp_nsyn_pop (void) | |
14971 | { | |
14972 | nsyn_insert_sp (); | |
b126985e NC |
14973 | |
14974 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
14975 | _("register list must contain at least 1 and at most 16 " | |
14976 | "registers")); | |
14977 | ||
037e8744 | 14978 | if (inst.operands[1].issingle) |
22b5b651 | 14979 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 | 14980 | else |
22b5b651 | 14981 | do_vfp_nsyn_opcode ("fldmiad"); |
037e8744 JB |
14982 | } |
14983 | ||
14984 | /* Fix up Neon data-processing instructions, ORing in the correct bits for | |
14985 | ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */ | |
14986 | ||
88714cb8 DG |
14987 | static void |
14988 | neon_dp_fixup (struct arm_it* insn) | |
037e8744 | 14989 | { |
88714cb8 DG |
14990 | unsigned int i = insn->instruction; |
14991 | insn->is_neon = 1; | |
14992 | ||
037e8744 JB |
14993 | if (thumb_mode) |
14994 | { | |
14995 | /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */ | |
14996 | if (i & (1 << 24)) | |
477330fc | 14997 | i |= 1 << 28; |
5f4273c7 | 14998 | |
037e8744 | 14999 | i &= ~(1 << 24); |
5f4273c7 | 15000 | |
037e8744 JB |
15001 | i |= 0xef000000; |
15002 | } | |
15003 | else | |
15004 | i |= 0xf2000000; | |
5f4273c7 | 15005 | |
88714cb8 | 15006 | insn->instruction = i; |
037e8744 JB |
15007 | } |
15008 | ||
15009 | /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3 | |
15010 | (0, 1, 2, 3). */ | |
15011 | ||
15012 | static unsigned | |
15013 | neon_logbits (unsigned x) | |
15014 | { | |
15015 | return ffs (x) - 4; | |
15016 | } | |
15017 | ||
15018 | #define LOW4(R) ((R) & 0xf) | |
15019 | #define HI1(R) (((R) >> 4) & 1) | |
15020 | ||
15021 | /* Encode insns with bit pattern: | |
15022 | ||
15023 | |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
15024 | | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm | | |
5f4273c7 | 15025 | |
037e8744 JB |
15026 | SIZE is passed in bits. -1 means size field isn't changed, in case it has a |
15027 | different meaning for some instruction. */ | |
15028 | ||
15029 | static void | |
15030 | neon_three_same (int isquad, int ubit, int size) | |
15031 | { | |
15032 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15033 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15034 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
15035 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
15036 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
15037 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
15038 | inst.instruction |= (isquad != 0) << 6; | |
15039 | inst.instruction |= (ubit != 0) << 24; | |
15040 | if (size != -1) | |
15041 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 15042 | |
88714cb8 | 15043 | neon_dp_fixup (&inst); |
037e8744 JB |
15044 | } |
15045 | ||
15046 | /* Encode instructions of the form: | |
15047 | ||
15048 | |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0| | |
15049 | | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm | | |
5287ad62 JB |
15050 | |
15051 | Don't write size if SIZE == -1. */ | |
15052 | ||
15053 | static void | |
15054 | neon_two_same (int qbit, int ubit, int size) | |
15055 | { | |
15056 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15057 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15058 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15059 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15060 | inst.instruction |= (qbit != 0) << 6; | |
15061 | inst.instruction |= (ubit != 0) << 24; | |
15062 | ||
15063 | if (size != -1) | |
15064 | inst.instruction |= neon_logbits (size) << 18; | |
15065 | ||
88714cb8 | 15066 | neon_dp_fixup (&inst); |
5287ad62 JB |
15067 | } |
15068 | ||
15069 | /* Neon instruction encoders, in approximate order of appearance. */ | |
15070 | ||
15071 | static void | |
15072 | do_neon_dyadic_i_su (void) | |
15073 | { | |
037e8744 | 15074 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
15075 | struct neon_type_el et = neon_check_type (3, rs, |
15076 | N_EQK, N_EQK, N_SU_32 | N_KEY); | |
037e8744 | 15077 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
15078 | } |
15079 | ||
15080 | static void | |
15081 | do_neon_dyadic_i64_su (void) | |
15082 | { | |
037e8744 | 15083 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
15084 | struct neon_type_el et = neon_check_type (3, rs, |
15085 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
037e8744 | 15086 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
15087 | } |
15088 | ||
15089 | static void | |
15090 | neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et, | |
477330fc | 15091 | unsigned immbits) |
5287ad62 JB |
15092 | { |
15093 | unsigned size = et.size >> 3; | |
15094 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15095 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15096 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15097 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15098 | inst.instruction |= (isquad != 0) << 6; | |
15099 | inst.instruction |= immbits << 16; | |
15100 | inst.instruction |= (size >> 3) << 7; | |
15101 | inst.instruction |= (size & 0x7) << 19; | |
15102 | if (write_ubit) | |
15103 | inst.instruction |= (uval != 0) << 24; | |
15104 | ||
88714cb8 | 15105 | neon_dp_fixup (&inst); |
5287ad62 JB |
15106 | } |
15107 | ||
15108 | static void | |
15109 | do_neon_shl_imm (void) | |
15110 | { | |
15111 | if (!inst.operands[2].isreg) | |
15112 | { | |
037e8744 | 15113 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 15114 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL); |
cb3b1e65 JB |
15115 | int imm = inst.operands[2].imm; |
15116 | ||
15117 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
15118 | _("immediate out of range for shift")); | |
88714cb8 | 15119 | NEON_ENCODE (IMMED, inst); |
cb3b1e65 | 15120 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
15121 | } |
15122 | else | |
15123 | { | |
037e8744 | 15124 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 15125 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 15126 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); |
627907b7 JB |
15127 | unsigned int tmp; |
15128 | ||
15129 | /* VSHL/VQSHL 3-register variants have syntax such as: | |
477330fc RM |
15130 | vshl.xx Dd, Dm, Dn |
15131 | whereas other 3-register operations encoded by neon_three_same have | |
15132 | syntax like: | |
15133 | vadd.xx Dd, Dn, Dm | |
15134 | (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg | |
15135 | here. */ | |
627907b7 JB |
15136 | tmp = inst.operands[2].reg; |
15137 | inst.operands[2].reg = inst.operands[1].reg; | |
15138 | inst.operands[1].reg = tmp; | |
88714cb8 | 15139 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 15140 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
15141 | } |
15142 | } | |
15143 | ||
15144 | static void | |
15145 | do_neon_qshl_imm (void) | |
15146 | { | |
15147 | if (!inst.operands[2].isreg) | |
15148 | { | |
037e8744 | 15149 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 15150 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
cb3b1e65 | 15151 | int imm = inst.operands[2].imm; |
627907b7 | 15152 | |
cb3b1e65 JB |
15153 | constraint (imm < 0 || (unsigned)imm >= et.size, |
15154 | _("immediate out of range for shift")); | |
88714cb8 | 15155 | NEON_ENCODE (IMMED, inst); |
cb3b1e65 | 15156 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm); |
5287ad62 JB |
15157 | } |
15158 | else | |
15159 | { | |
037e8744 | 15160 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 15161 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 15162 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); |
627907b7 JB |
15163 | unsigned int tmp; |
15164 | ||
15165 | /* See note in do_neon_shl_imm. */ | |
15166 | tmp = inst.operands[2].reg; | |
15167 | inst.operands[2].reg = inst.operands[1].reg; | |
15168 | inst.operands[1].reg = tmp; | |
88714cb8 | 15169 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 15170 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
15171 | } |
15172 | } | |
15173 | ||
627907b7 JB |
15174 | static void |
15175 | do_neon_rshl (void) | |
15176 | { | |
15177 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
15178 | struct neon_type_el et = neon_check_type (3, rs, | |
15179 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
15180 | unsigned int tmp; | |
15181 | ||
15182 | tmp = inst.operands[2].reg; | |
15183 | inst.operands[2].reg = inst.operands[1].reg; | |
15184 | inst.operands[1].reg = tmp; | |
15185 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
15186 | } | |
15187 | ||
5287ad62 JB |
15188 | static int |
15189 | neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size) | |
15190 | { | |
036dc3f7 PB |
15191 | /* Handle .I8 pseudo-instructions. */ |
15192 | if (size == 8) | |
5287ad62 | 15193 | { |
5287ad62 | 15194 | /* Unfortunately, this will make everything apart from zero out-of-range. |
477330fc RM |
15195 | FIXME is this the intended semantics? There doesn't seem much point in |
15196 | accepting .I8 if so. */ | |
5287ad62 JB |
15197 | immediate |= immediate << 8; |
15198 | size = 16; | |
036dc3f7 PB |
15199 | } |
15200 | ||
15201 | if (size >= 32) | |
15202 | { | |
15203 | if (immediate == (immediate & 0x000000ff)) | |
15204 | { | |
15205 | *immbits = immediate; | |
15206 | return 0x1; | |
15207 | } | |
15208 | else if (immediate == (immediate & 0x0000ff00)) | |
15209 | { | |
15210 | *immbits = immediate >> 8; | |
15211 | return 0x3; | |
15212 | } | |
15213 | else if (immediate == (immediate & 0x00ff0000)) | |
15214 | { | |
15215 | *immbits = immediate >> 16; | |
15216 | return 0x5; | |
15217 | } | |
15218 | else if (immediate == (immediate & 0xff000000)) | |
15219 | { | |
15220 | *immbits = immediate >> 24; | |
15221 | return 0x7; | |
15222 | } | |
15223 | if ((immediate & 0xffff) != (immediate >> 16)) | |
15224 | goto bad_immediate; | |
15225 | immediate &= 0xffff; | |
5287ad62 JB |
15226 | } |
15227 | ||
15228 | if (immediate == (immediate & 0x000000ff)) | |
15229 | { | |
15230 | *immbits = immediate; | |
036dc3f7 | 15231 | return 0x9; |
5287ad62 JB |
15232 | } |
15233 | else if (immediate == (immediate & 0x0000ff00)) | |
15234 | { | |
15235 | *immbits = immediate >> 8; | |
036dc3f7 | 15236 | return 0xb; |
5287ad62 JB |
15237 | } |
15238 | ||
15239 | bad_immediate: | |
dcbf9037 | 15240 | first_error (_("immediate value out of range")); |
5287ad62 JB |
15241 | return FAIL; |
15242 | } | |
15243 | ||
5287ad62 JB |
15244 | static void |
15245 | do_neon_logic (void) | |
15246 | { | |
15247 | if (inst.operands[2].present && inst.operands[2].isreg) | |
15248 | { | |
037e8744 | 15249 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
15250 | neon_check_type (3, rs, N_IGNORE_TYPE); |
15251 | /* U bit and size field were set as part of the bitmask. */ | |
88714cb8 | 15252 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 15253 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
15254 | } |
15255 | else | |
15256 | { | |
4316f0d2 DG |
15257 | const int three_ops_form = (inst.operands[2].present |
15258 | && !inst.operands[2].isreg); | |
15259 | const int immoperand = (three_ops_form ? 2 : 1); | |
15260 | enum neon_shape rs = (three_ops_form | |
15261 | ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL) | |
15262 | : neon_select_shape (NS_DI, NS_QI, NS_NULL)); | |
037e8744 | 15263 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 15264 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); |
21d799b5 | 15265 | enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff; |
5287ad62 JB |
15266 | unsigned immbits; |
15267 | int cmode; | |
5f4273c7 | 15268 | |
5287ad62 | 15269 | if (et.type == NT_invtype) |
477330fc | 15270 | return; |
5f4273c7 | 15271 | |
4316f0d2 DG |
15272 | if (three_ops_form) |
15273 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
15274 | _("first and second operands shall be the same register")); | |
15275 | ||
88714cb8 | 15276 | NEON_ENCODE (IMMED, inst); |
5287ad62 | 15277 | |
4316f0d2 | 15278 | immbits = inst.operands[immoperand].imm; |
036dc3f7 PB |
15279 | if (et.size == 64) |
15280 | { | |
15281 | /* .i64 is a pseudo-op, so the immediate must be a repeating | |
15282 | pattern. */ | |
4316f0d2 DG |
15283 | if (immbits != (inst.operands[immoperand].regisimm ? |
15284 | inst.operands[immoperand].reg : 0)) | |
036dc3f7 PB |
15285 | { |
15286 | /* Set immbits to an invalid constant. */ | |
15287 | immbits = 0xdeadbeef; | |
15288 | } | |
15289 | } | |
15290 | ||
5287ad62 | 15291 | switch (opcode) |
477330fc RM |
15292 | { |
15293 | case N_MNEM_vbic: | |
15294 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
15295 | break; | |
15296 | ||
15297 | case N_MNEM_vorr: | |
15298 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
15299 | break; | |
15300 | ||
15301 | case N_MNEM_vand: | |
15302 | /* Pseudo-instruction for VBIC. */ | |
15303 | neon_invert_size (&immbits, 0, et.size); | |
15304 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
15305 | break; | |
15306 | ||
15307 | case N_MNEM_vorn: | |
15308 | /* Pseudo-instruction for VORR. */ | |
15309 | neon_invert_size (&immbits, 0, et.size); | |
15310 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
15311 | break; | |
15312 | ||
15313 | default: | |
15314 | abort (); | |
15315 | } | |
5287ad62 JB |
15316 | |
15317 | if (cmode == FAIL) | |
477330fc | 15318 | return; |
5287ad62 | 15319 | |
037e8744 | 15320 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15321 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15322 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15323 | inst.instruction |= cmode << 8; | |
15324 | neon_write_immbits (immbits); | |
5f4273c7 | 15325 | |
88714cb8 | 15326 | neon_dp_fixup (&inst); |
5287ad62 JB |
15327 | } |
15328 | } | |
15329 | ||
15330 | static void | |
15331 | do_neon_bitfield (void) | |
15332 | { | |
037e8744 | 15333 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 15334 | neon_check_type (3, rs, N_IGNORE_TYPE); |
037e8744 | 15335 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
15336 | } |
15337 | ||
15338 | static void | |
dcbf9037 | 15339 | neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types, |
477330fc | 15340 | unsigned destbits) |
5287ad62 | 15341 | { |
037e8744 | 15342 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 15343 | struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK, |
477330fc | 15344 | types | N_KEY); |
5287ad62 JB |
15345 | if (et.type == NT_float) |
15346 | { | |
88714cb8 | 15347 | NEON_ENCODE (FLOAT, inst); |
cc933301 | 15348 | neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1); |
5287ad62 JB |
15349 | } |
15350 | else | |
15351 | { | |
88714cb8 | 15352 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 15353 | neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size); |
5287ad62 JB |
15354 | } |
15355 | } | |
15356 | ||
15357 | static void | |
15358 | do_neon_dyadic_if_su (void) | |
15359 | { | |
dcbf9037 | 15360 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
15361 | } |
15362 | ||
15363 | static void | |
15364 | do_neon_dyadic_if_su_d (void) | |
15365 | { | |
15366 | /* This version only allow D registers, but that constraint is enforced during | |
15367 | operand parsing so we don't need to do anything extra here. */ | |
dcbf9037 | 15368 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
15369 | } |
15370 | ||
5287ad62 JB |
15371 | static void |
15372 | do_neon_dyadic_if_i_d (void) | |
15373 | { | |
428e3f1f PB |
15374 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
15375 | affected if we specify unsigned args. */ | |
15376 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
5287ad62 JB |
15377 | } |
15378 | ||
037e8744 JB |
15379 | enum vfp_or_neon_is_neon_bits |
15380 | { | |
15381 | NEON_CHECK_CC = 1, | |
73924fbc MGD |
15382 | NEON_CHECK_ARCH = 2, |
15383 | NEON_CHECK_ARCH8 = 4 | |
037e8744 JB |
15384 | }; |
15385 | ||
15386 | /* Call this function if an instruction which may have belonged to the VFP or | |
15387 | Neon instruction sets, but turned out to be a Neon instruction (due to the | |
15388 | operand types involved, etc.). We have to check and/or fix-up a couple of | |
15389 | things: | |
15390 | ||
15391 | - Make sure the user hasn't attempted to make a Neon instruction | |
15392 | conditional. | |
15393 | - Alter the value in the condition code field if necessary. | |
15394 | - Make sure that the arch supports Neon instructions. | |
15395 | ||
15396 | Which of these operations take place depends on bits from enum | |
15397 | vfp_or_neon_is_neon_bits. | |
15398 | ||
15399 | WARNING: This function has side effects! If NEON_CHECK_CC is used and the | |
15400 | current instruction's condition is COND_ALWAYS, the condition field is | |
15401 | changed to inst.uncond_value. This is necessary because instructions shared | |
15402 | between VFP and Neon may be conditional for the VFP variants only, and the | |
15403 | unconditional Neon version must have, e.g., 0xF in the condition field. */ | |
15404 | ||
15405 | static int | |
15406 | vfp_or_neon_is_neon (unsigned check) | |
15407 | { | |
15408 | /* Conditions are always legal in Thumb mode (IT blocks). */ | |
15409 | if (!thumb_mode && (check & NEON_CHECK_CC)) | |
15410 | { | |
15411 | if (inst.cond != COND_ALWAYS) | |
477330fc RM |
15412 | { |
15413 | first_error (_(BAD_COND)); | |
15414 | return FAIL; | |
15415 | } | |
037e8744 | 15416 | if (inst.uncond_value != -1) |
477330fc | 15417 | inst.instruction |= inst.uncond_value << 28; |
037e8744 | 15418 | } |
5f4273c7 | 15419 | |
037e8744 | 15420 | if ((check & NEON_CHECK_ARCH) |
73924fbc MGD |
15421 | && !mark_feature_used (&fpu_neon_ext_v1)) |
15422 | { | |
15423 | first_error (_(BAD_FPU)); | |
15424 | return FAIL; | |
15425 | } | |
15426 | ||
15427 | if ((check & NEON_CHECK_ARCH8) | |
15428 | && !mark_feature_used (&fpu_neon_ext_armv8)) | |
037e8744 JB |
15429 | { |
15430 | first_error (_(BAD_FPU)); | |
15431 | return FAIL; | |
15432 | } | |
5f4273c7 | 15433 | |
037e8744 JB |
15434 | return SUCCESS; |
15435 | } | |
15436 | ||
5287ad62 JB |
15437 | static void |
15438 | do_neon_addsub_if_i (void) | |
15439 | { | |
037e8744 JB |
15440 | if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS) |
15441 | return; | |
15442 | ||
15443 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15444 | return; | |
15445 | ||
5287ad62 JB |
15446 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
15447 | affected if we specify unsigned args. */ | |
dcbf9037 | 15448 | neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0); |
5287ad62 JB |
15449 | } |
15450 | ||
15451 | /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the | |
15452 | result to be: | |
15453 | V<op> A,B (A is operand 0, B is operand 2) | |
15454 | to mean: | |
15455 | V<op> A,B,A | |
15456 | not: | |
15457 | V<op> A,B,B | |
15458 | so handle that case specially. */ | |
15459 | ||
15460 | static void | |
15461 | neon_exchange_operands (void) | |
15462 | { | |
5287ad62 JB |
15463 | if (inst.operands[1].present) |
15464 | { | |
e1fa0163 NC |
15465 | void *scratch = xmalloc (sizeof (inst.operands[0])); |
15466 | ||
5287ad62 JB |
15467 | /* Swap operands[1] and operands[2]. */ |
15468 | memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0])); | |
15469 | inst.operands[1] = inst.operands[2]; | |
15470 | memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0])); | |
e1fa0163 | 15471 | free (scratch); |
5287ad62 JB |
15472 | } |
15473 | else | |
15474 | { | |
15475 | inst.operands[1] = inst.operands[2]; | |
15476 | inst.operands[2] = inst.operands[0]; | |
15477 | } | |
15478 | } | |
15479 | ||
15480 | static void | |
15481 | neon_compare (unsigned regtypes, unsigned immtypes, int invert) | |
15482 | { | |
15483 | if (inst.operands[2].isreg) | |
15484 | { | |
15485 | if (invert) | |
477330fc | 15486 | neon_exchange_operands (); |
dcbf9037 | 15487 | neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ); |
5287ad62 JB |
15488 | } |
15489 | else | |
15490 | { | |
037e8744 | 15491 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
dcbf9037 | 15492 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 15493 | N_EQK | N_SIZ, immtypes | N_KEY); |
5287ad62 | 15494 | |
88714cb8 | 15495 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
15496 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15497 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15498 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15499 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 15500 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15501 | inst.instruction |= (et.type == NT_float) << 10; |
15502 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 15503 | |
88714cb8 | 15504 | neon_dp_fixup (&inst); |
5287ad62 JB |
15505 | } |
15506 | } | |
15507 | ||
15508 | static void | |
15509 | do_neon_cmp (void) | |
15510 | { | |
cc933301 | 15511 | neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE); |
5287ad62 JB |
15512 | } |
15513 | ||
15514 | static void | |
15515 | do_neon_cmp_inv (void) | |
15516 | { | |
cc933301 | 15517 | neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE); |
5287ad62 JB |
15518 | } |
15519 | ||
15520 | static void | |
15521 | do_neon_ceq (void) | |
15522 | { | |
15523 | neon_compare (N_IF_32, N_IF_32, FALSE); | |
15524 | } | |
15525 | ||
15526 | /* For multiply instructions, we have the possibility of 16-bit or 32-bit | |
15527 | scalars, which are encoded in 5 bits, M : Rm. | |
15528 | For 16-bit scalars, the register is encoded in Rm[2:0] and the index in | |
15529 | M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the | |
c604a79a JW |
15530 | index in M. |
15531 | ||
15532 | Dot Product instructions are similar to multiply instructions except elsize | |
15533 | should always be 32. | |
15534 | ||
15535 | This function translates SCALAR, which is GAS's internal encoding of indexed | |
15536 | scalar register, to raw encoding. There is also register and index range | |
15537 | check based on ELSIZE. */ | |
5287ad62 JB |
15538 | |
15539 | static unsigned | |
15540 | neon_scalar_for_mul (unsigned scalar, unsigned elsize) | |
15541 | { | |
dcbf9037 JB |
15542 | unsigned regno = NEON_SCALAR_REG (scalar); |
15543 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
5287ad62 JB |
15544 | |
15545 | switch (elsize) | |
15546 | { | |
15547 | case 16: | |
15548 | if (regno > 7 || elno > 3) | |
477330fc | 15549 | goto bad_scalar; |
5287ad62 | 15550 | return regno | (elno << 3); |
5f4273c7 | 15551 | |
5287ad62 JB |
15552 | case 32: |
15553 | if (regno > 15 || elno > 1) | |
477330fc | 15554 | goto bad_scalar; |
5287ad62 JB |
15555 | return regno | (elno << 4); |
15556 | ||
15557 | default: | |
15558 | bad_scalar: | |
dcbf9037 | 15559 | first_error (_("scalar out of range for multiply instruction")); |
5287ad62 JB |
15560 | } |
15561 | ||
15562 | return 0; | |
15563 | } | |
15564 | ||
15565 | /* Encode multiply / multiply-accumulate scalar instructions. */ | |
15566 | ||
15567 | static void | |
15568 | neon_mul_mac (struct neon_type_el et, int ubit) | |
15569 | { | |
dcbf9037 JB |
15570 | unsigned scalar; |
15571 | ||
15572 | /* Give a more helpful error message if we have an invalid type. */ | |
15573 | if (et.type == NT_invtype) | |
15574 | return; | |
5f4273c7 | 15575 | |
dcbf9037 | 15576 | scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size); |
5287ad62 JB |
15577 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15578 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15579 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
15580 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
15581 | inst.instruction |= LOW4 (scalar); | |
15582 | inst.instruction |= HI1 (scalar) << 5; | |
15583 | inst.instruction |= (et.type == NT_float) << 8; | |
15584 | inst.instruction |= neon_logbits (et.size) << 20; | |
15585 | inst.instruction |= (ubit != 0) << 24; | |
15586 | ||
88714cb8 | 15587 | neon_dp_fixup (&inst); |
5287ad62 JB |
15588 | } |
15589 | ||
15590 | static void | |
15591 | do_neon_mac_maybe_scalar (void) | |
15592 | { | |
037e8744 JB |
15593 | if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS) |
15594 | return; | |
15595 | ||
15596 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15597 | return; | |
15598 | ||
5287ad62 JB |
15599 | if (inst.operands[2].isscalar) |
15600 | { | |
037e8744 | 15601 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 | 15602 | struct neon_type_el et = neon_check_type (3, rs, |
589a7d88 | 15603 | N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY); |
88714cb8 | 15604 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 15605 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
15606 | } |
15607 | else | |
428e3f1f PB |
15608 | { |
15609 | /* The "untyped" case can't happen. Do this to stop the "U" bit being | |
15610 | affected if we specify unsigned args. */ | |
15611 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
15612 | } | |
5287ad62 JB |
15613 | } |
15614 | ||
62f3b8c8 PB |
15615 | static void |
15616 | do_neon_fmac (void) | |
15617 | { | |
15618 | if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS) | |
15619 | return; | |
15620 | ||
15621 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15622 | return; | |
15623 | ||
15624 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
15625 | } | |
15626 | ||
5287ad62 JB |
15627 | static void |
15628 | do_neon_tst (void) | |
15629 | { | |
037e8744 | 15630 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
15631 | struct neon_type_el et = neon_check_type (3, rs, |
15632 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
037e8744 | 15633 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
15634 | } |
15635 | ||
15636 | /* VMUL with 3 registers allows the P8 type. The scalar version supports the | |
15637 | same types as the MAC equivalents. The polynomial type for this instruction | |
15638 | is encoded the same as the integer type. */ | |
15639 | ||
15640 | static void | |
15641 | do_neon_mul (void) | |
15642 | { | |
037e8744 JB |
15643 | if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS) |
15644 | return; | |
15645 | ||
15646 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15647 | return; | |
15648 | ||
5287ad62 JB |
15649 | if (inst.operands[2].isscalar) |
15650 | do_neon_mac_maybe_scalar (); | |
15651 | else | |
cc933301 | 15652 | neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0); |
5287ad62 JB |
15653 | } |
15654 | ||
15655 | static void | |
15656 | do_neon_qdmulh (void) | |
15657 | { | |
15658 | if (inst.operands[2].isscalar) | |
15659 | { | |
037e8744 | 15660 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 | 15661 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 15662 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); |
88714cb8 | 15663 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 15664 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
15665 | } |
15666 | else | |
15667 | { | |
037e8744 | 15668 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 15669 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 15670 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); |
88714cb8 | 15671 | NEON_ENCODE (INTEGER, inst); |
5287ad62 | 15672 | /* The U bit (rounding) comes from bit mask. */ |
037e8744 | 15673 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
15674 | } |
15675 | } | |
15676 | ||
643afb90 MW |
15677 | static void |
15678 | do_neon_qrdmlah (void) | |
15679 | { | |
15680 | /* Check we're on the correct architecture. */ | |
15681 | if (!mark_feature_used (&fpu_neon_ext_armv8)) | |
15682 | inst.error = | |
15683 | _("instruction form not available on this architecture."); | |
15684 | else if (!mark_feature_used (&fpu_neon_ext_v8_1)) | |
15685 | { | |
15686 | as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD.")); | |
15687 | record_feature_use (&fpu_neon_ext_v8_1); | |
15688 | } | |
15689 | ||
15690 | if (inst.operands[2].isscalar) | |
15691 | { | |
15692 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); | |
15693 | struct neon_type_el et = neon_check_type (3, rs, | |
15694 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
15695 | NEON_ENCODE (SCALAR, inst); | |
15696 | neon_mul_mac (et, neon_quad (rs)); | |
15697 | } | |
15698 | else | |
15699 | { | |
15700 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
15701 | struct neon_type_el et = neon_check_type (3, rs, | |
15702 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
15703 | NEON_ENCODE (INTEGER, inst); | |
15704 | /* The U bit (rounding) comes from bit mask. */ | |
15705 | neon_three_same (neon_quad (rs), 0, et.size); | |
15706 | } | |
15707 | } | |
15708 | ||
5287ad62 JB |
15709 | static void |
15710 | do_neon_fcmp_absolute (void) | |
15711 | { | |
037e8744 | 15712 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
cc933301 JW |
15713 | struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK, |
15714 | N_F_16_32 | N_KEY); | |
5287ad62 | 15715 | /* Size field comes from bit mask. */ |
cc933301 | 15716 | neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1); |
5287ad62 JB |
15717 | } |
15718 | ||
15719 | static void | |
15720 | do_neon_fcmp_absolute_inv (void) | |
15721 | { | |
15722 | neon_exchange_operands (); | |
15723 | do_neon_fcmp_absolute (); | |
15724 | } | |
15725 | ||
15726 | static void | |
15727 | do_neon_step (void) | |
15728 | { | |
037e8744 | 15729 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
cc933301 JW |
15730 | struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK, |
15731 | N_F_16_32 | N_KEY); | |
15732 | neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1); | |
5287ad62 JB |
15733 | } |
15734 | ||
15735 | static void | |
15736 | do_neon_abs_neg (void) | |
15737 | { | |
037e8744 JB |
15738 | enum neon_shape rs; |
15739 | struct neon_type_el et; | |
5f4273c7 | 15740 | |
037e8744 JB |
15741 | if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS) |
15742 | return; | |
15743 | ||
15744 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15745 | return; | |
15746 | ||
15747 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
cc933301 | 15748 | et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY); |
5f4273c7 | 15749 | |
5287ad62 JB |
15750 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15751 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15752 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15753 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 15754 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15755 | inst.instruction |= (et.type == NT_float) << 10; |
15756 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 15757 | |
88714cb8 | 15758 | neon_dp_fixup (&inst); |
5287ad62 JB |
15759 | } |
15760 | ||
15761 | static void | |
15762 | do_neon_sli (void) | |
15763 | { | |
037e8744 | 15764 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
15765 | struct neon_type_el et = neon_check_type (2, rs, |
15766 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
15767 | int imm = inst.operands[2].imm; | |
15768 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
477330fc | 15769 | _("immediate out of range for insert")); |
037e8744 | 15770 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
15771 | } |
15772 | ||
15773 | static void | |
15774 | do_neon_sri (void) | |
15775 | { | |
037e8744 | 15776 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
15777 | struct neon_type_el et = neon_check_type (2, rs, |
15778 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
15779 | int imm = inst.operands[2].imm; | |
15780 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 15781 | _("immediate out of range for insert")); |
037e8744 | 15782 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm); |
5287ad62 JB |
15783 | } |
15784 | ||
15785 | static void | |
15786 | do_neon_qshlu_imm (void) | |
15787 | { | |
037e8744 | 15788 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
15789 | struct neon_type_el et = neon_check_type (2, rs, |
15790 | N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY); | |
15791 | int imm = inst.operands[2].imm; | |
15792 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
477330fc | 15793 | _("immediate out of range for shift")); |
5287ad62 JB |
15794 | /* Only encodes the 'U present' variant of the instruction. |
15795 | In this case, signed types have OP (bit 8) set to 0. | |
15796 | Unsigned types have OP set to 1. */ | |
15797 | inst.instruction |= (et.type == NT_unsigned) << 8; | |
15798 | /* The rest of the bits are the same as other immediate shifts. */ | |
037e8744 | 15799 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
15800 | } |
15801 | ||
15802 | static void | |
15803 | do_neon_qmovn (void) | |
15804 | { | |
15805 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
15806 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
15807 | /* Saturating move where operands can be signed or unsigned, and the | |
15808 | destination has the same signedness. */ | |
88714cb8 | 15809 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15810 | if (et.type == NT_unsigned) |
15811 | inst.instruction |= 0xc0; | |
15812 | else | |
15813 | inst.instruction |= 0x80; | |
15814 | neon_two_same (0, 1, et.size / 2); | |
15815 | } | |
15816 | ||
15817 | static void | |
15818 | do_neon_qmovun (void) | |
15819 | { | |
15820 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
15821 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
15822 | /* Saturating move with unsigned results. Operands must be signed. */ | |
88714cb8 | 15823 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15824 | neon_two_same (0, 1, et.size / 2); |
15825 | } | |
15826 | ||
15827 | static void | |
15828 | do_neon_rshift_sat_narrow (void) | |
15829 | { | |
15830 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
15831 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
15832 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
15833 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
15834 | int imm = inst.operands[2].imm; | |
15835 | /* This gets the bounds check, size encoding and immediate bits calculation | |
15836 | right. */ | |
15837 | et.size /= 2; | |
5f4273c7 | 15838 | |
5287ad62 JB |
15839 | /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for |
15840 | VQMOVN.I<size> <Dd>, <Qm>. */ | |
15841 | if (imm == 0) | |
15842 | { | |
15843 | inst.operands[2].present = 0; | |
15844 | inst.instruction = N_MNEM_vqmovn; | |
15845 | do_neon_qmovn (); | |
15846 | return; | |
15847 | } | |
5f4273c7 | 15848 | |
5287ad62 | 15849 | constraint (imm < 1 || (unsigned)imm > et.size, |
477330fc | 15850 | _("immediate out of range")); |
5287ad62 JB |
15851 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm); |
15852 | } | |
15853 | ||
15854 | static void | |
15855 | do_neon_rshift_sat_narrow_u (void) | |
15856 | { | |
15857 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
15858 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
15859 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
15860 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
15861 | int imm = inst.operands[2].imm; | |
15862 | /* This gets the bounds check, size encoding and immediate bits calculation | |
15863 | right. */ | |
15864 | et.size /= 2; | |
15865 | ||
15866 | /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
15867 | VQMOVUN.I<size> <Dd>, <Qm>. */ | |
15868 | if (imm == 0) | |
15869 | { | |
15870 | inst.operands[2].present = 0; | |
15871 | inst.instruction = N_MNEM_vqmovun; | |
15872 | do_neon_qmovun (); | |
15873 | return; | |
15874 | } | |
15875 | ||
15876 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 15877 | _("immediate out of range")); |
5287ad62 JB |
15878 | /* FIXME: The manual is kind of unclear about what value U should have in |
15879 | VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it | |
15880 | must be 1. */ | |
15881 | neon_imm_shift (TRUE, 1, 0, et, et.size - imm); | |
15882 | } | |
15883 | ||
15884 | static void | |
15885 | do_neon_movn (void) | |
15886 | { | |
15887 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
15888 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
88714cb8 | 15889 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15890 | neon_two_same (0, 1, et.size / 2); |
15891 | } | |
15892 | ||
15893 | static void | |
15894 | do_neon_rshift_narrow (void) | |
15895 | { | |
15896 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
15897 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
15898 | int imm = inst.operands[2].imm; | |
15899 | /* This gets the bounds check, size encoding and immediate bits calculation | |
15900 | right. */ | |
15901 | et.size /= 2; | |
5f4273c7 | 15902 | |
5287ad62 JB |
15903 | /* If immediate is zero then we are a pseudo-instruction for |
15904 | VMOVN.I<size> <Dd>, <Qm> */ | |
15905 | if (imm == 0) | |
15906 | { | |
15907 | inst.operands[2].present = 0; | |
15908 | inst.instruction = N_MNEM_vmovn; | |
15909 | do_neon_movn (); | |
15910 | return; | |
15911 | } | |
5f4273c7 | 15912 | |
5287ad62 | 15913 | constraint (imm < 1 || (unsigned)imm > et.size, |
477330fc | 15914 | _("immediate out of range for narrowing operation")); |
5287ad62 JB |
15915 | neon_imm_shift (FALSE, 0, 0, et, et.size - imm); |
15916 | } | |
15917 | ||
15918 | static void | |
15919 | do_neon_shll (void) | |
15920 | { | |
15921 | /* FIXME: Type checking when lengthening. */ | |
15922 | struct neon_type_el et = neon_check_type (2, NS_QDI, | |
15923 | N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY); | |
15924 | unsigned imm = inst.operands[2].imm; | |
15925 | ||
15926 | if (imm == et.size) | |
15927 | { | |
15928 | /* Maximum shift variant. */ | |
88714cb8 | 15929 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15930 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15931 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15932 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15933 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15934 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 15935 | |
88714cb8 | 15936 | neon_dp_fixup (&inst); |
5287ad62 JB |
15937 | } |
15938 | else | |
15939 | { | |
15940 | /* A more-specific type check for non-max versions. */ | |
15941 | et = neon_check_type (2, NS_QDI, | |
477330fc | 15942 | N_EQK | N_DBL, N_SU_32 | N_KEY); |
88714cb8 | 15943 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
15944 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm); |
15945 | } | |
15946 | } | |
15947 | ||
037e8744 | 15948 | /* Check the various types for the VCVT instruction, and return which version |
5287ad62 JB |
15949 | the current instruction is. */ |
15950 | ||
6b9a8b67 MGD |
15951 | #define CVT_FLAVOUR_VAR \ |
15952 | CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \ | |
15953 | CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \ | |
15954 | CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \ | |
15955 | CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \ | |
15956 | /* Half-precision conversions. */ \ | |
cc933301 JW |
15957 | CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \ |
15958 | CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \ | |
15959 | CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \ | |
15960 | CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \ | |
6b9a8b67 MGD |
15961 | CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \ |
15962 | CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \ | |
9db2f6b4 RL |
15963 | /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \ |
15964 | Compared with single/double precision variants, only the co-processor \ | |
15965 | field is different, so the encoding flow is reused here. */ \ | |
15966 | CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \ | |
15967 | CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \ | |
15968 | CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\ | |
15969 | CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\ | |
6b9a8b67 MGD |
15970 | /* VFP instructions. */ \ |
15971 | CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \ | |
15972 | CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \ | |
15973 | CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \ | |
15974 | CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \ | |
15975 | CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \ | |
15976 | CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \ | |
15977 | /* VFP instructions with bitshift. */ \ | |
15978 | CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \ | |
15979 | CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \ | |
15980 | CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \ | |
15981 | CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \ | |
15982 | CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \ | |
15983 | CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \ | |
15984 | CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \ | |
15985 | CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL) | |
15986 | ||
15987 | #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \ | |
15988 | neon_cvt_flavour_##C, | |
15989 | ||
15990 | /* The different types of conversions we can do. */ | |
15991 | enum neon_cvt_flavour | |
15992 | { | |
15993 | CVT_FLAVOUR_VAR | |
15994 | neon_cvt_flavour_invalid, | |
15995 | neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64 | |
15996 | }; | |
15997 | ||
15998 | #undef CVT_VAR | |
15999 | ||
16000 | static enum neon_cvt_flavour | |
16001 | get_neon_cvt_flavour (enum neon_shape rs) | |
5287ad62 | 16002 | { |
6b9a8b67 MGD |
16003 | #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \ |
16004 | et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \ | |
16005 | if (et.type != NT_invtype) \ | |
16006 | { \ | |
16007 | inst.error = NULL; \ | |
16008 | return (neon_cvt_flavour_##C); \ | |
5287ad62 | 16009 | } |
6b9a8b67 | 16010 | |
5287ad62 | 16011 | struct neon_type_el et; |
037e8744 | 16012 | unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF |
477330fc | 16013 | || rs == NS_FF) ? N_VFP : 0; |
037e8744 JB |
16014 | /* The instruction versions which take an immediate take one register |
16015 | argument, which is extended to the width of the full register. Thus the | |
16016 | "source" and "destination" registers must have the same width. Hack that | |
16017 | here by making the size equal to the key (wider, in this case) operand. */ | |
16018 | unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0; | |
5f4273c7 | 16019 | |
6b9a8b67 MGD |
16020 | CVT_FLAVOUR_VAR; |
16021 | ||
16022 | return neon_cvt_flavour_invalid; | |
5287ad62 JB |
16023 | #undef CVT_VAR |
16024 | } | |
16025 | ||
7e8e6784 MGD |
16026 | enum neon_cvt_mode |
16027 | { | |
16028 | neon_cvt_mode_a, | |
16029 | neon_cvt_mode_n, | |
16030 | neon_cvt_mode_p, | |
16031 | neon_cvt_mode_m, | |
16032 | neon_cvt_mode_z, | |
30bdf752 MGD |
16033 | neon_cvt_mode_x, |
16034 | neon_cvt_mode_r | |
7e8e6784 MGD |
16035 | }; |
16036 | ||
037e8744 JB |
16037 | /* Neon-syntax VFP conversions. */ |
16038 | ||
5287ad62 | 16039 | static void |
6b9a8b67 | 16040 | do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour) |
5287ad62 | 16041 | { |
037e8744 | 16042 | const char *opname = 0; |
5f4273c7 | 16043 | |
d54af2d0 RL |
16044 | if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI |
16045 | || rs == NS_FHI || rs == NS_HFI) | |
5287ad62 | 16046 | { |
037e8744 JB |
16047 | /* Conversions with immediate bitshift. */ |
16048 | const char *enc[] = | |
477330fc | 16049 | { |
6b9a8b67 MGD |
16050 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN, |
16051 | CVT_FLAVOUR_VAR | |
16052 | NULL | |
16053 | #undef CVT_VAR | |
477330fc | 16054 | }; |
037e8744 | 16055 | |
6b9a8b67 | 16056 | if (flavour < (int) ARRAY_SIZE (enc)) |
477330fc RM |
16057 | { |
16058 | opname = enc[flavour]; | |
16059 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
16060 | _("operands 0 and 1 must be the same register")); | |
16061 | inst.operands[1] = inst.operands[2]; | |
16062 | memset (&inst.operands[2], '\0', sizeof (inst.operands[2])); | |
16063 | } | |
5287ad62 JB |
16064 | } |
16065 | else | |
16066 | { | |
037e8744 JB |
16067 | /* Conversions without bitshift. */ |
16068 | const char *enc[] = | |
477330fc | 16069 | { |
6b9a8b67 MGD |
16070 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN, |
16071 | CVT_FLAVOUR_VAR | |
16072 | NULL | |
16073 | #undef CVT_VAR | |
477330fc | 16074 | }; |
037e8744 | 16075 | |
6b9a8b67 | 16076 | if (flavour < (int) ARRAY_SIZE (enc)) |
477330fc | 16077 | opname = enc[flavour]; |
037e8744 JB |
16078 | } |
16079 | ||
16080 | if (opname) | |
16081 | do_vfp_nsyn_opcode (opname); | |
9db2f6b4 RL |
16082 | |
16083 | /* ARMv8.2 fp16 VCVT instruction. */ | |
16084 | if (flavour == neon_cvt_flavour_s32_f16 | |
16085 | || flavour == neon_cvt_flavour_u32_f16 | |
16086 | || flavour == neon_cvt_flavour_f16_u32 | |
16087 | || flavour == neon_cvt_flavour_f16_s32) | |
16088 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
16089 | } |
16090 | ||
16091 | static void | |
16092 | do_vfp_nsyn_cvtz (void) | |
16093 | { | |
d54af2d0 | 16094 | enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL); |
6b9a8b67 | 16095 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 JB |
16096 | const char *enc[] = |
16097 | { | |
6b9a8b67 MGD |
16098 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN, |
16099 | CVT_FLAVOUR_VAR | |
16100 | NULL | |
16101 | #undef CVT_VAR | |
037e8744 JB |
16102 | }; |
16103 | ||
6b9a8b67 | 16104 | if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour]) |
037e8744 JB |
16105 | do_vfp_nsyn_opcode (enc[flavour]); |
16106 | } | |
f31fef98 | 16107 | |
037e8744 | 16108 | static void |
bacebabc | 16109 | do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour, |
7e8e6784 MGD |
16110 | enum neon_cvt_mode mode) |
16111 | { | |
16112 | int sz, op; | |
16113 | int rm; | |
16114 | ||
a715796b TG |
16115 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
16116 | D register operands. */ | |
16117 | if (flavour == neon_cvt_flavour_s32_f64 | |
16118 | || flavour == neon_cvt_flavour_u32_f64) | |
16119 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
16120 | _(BAD_FPU)); | |
16121 | ||
9db2f6b4 RL |
16122 | if (flavour == neon_cvt_flavour_s32_f16 |
16123 | || flavour == neon_cvt_flavour_u32_f16) | |
16124 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16), | |
16125 | _(BAD_FP16)); | |
16126 | ||
7e8e6784 MGD |
16127 | set_it_insn_type (OUTSIDE_IT_INSN); |
16128 | ||
16129 | switch (flavour) | |
16130 | { | |
16131 | case neon_cvt_flavour_s32_f64: | |
16132 | sz = 1; | |
827f64ff | 16133 | op = 1; |
7e8e6784 MGD |
16134 | break; |
16135 | case neon_cvt_flavour_s32_f32: | |
16136 | sz = 0; | |
16137 | op = 1; | |
16138 | break; | |
9db2f6b4 RL |
16139 | case neon_cvt_flavour_s32_f16: |
16140 | sz = 0; | |
16141 | op = 1; | |
16142 | break; | |
7e8e6784 MGD |
16143 | case neon_cvt_flavour_u32_f64: |
16144 | sz = 1; | |
16145 | op = 0; | |
16146 | break; | |
16147 | case neon_cvt_flavour_u32_f32: | |
16148 | sz = 0; | |
16149 | op = 0; | |
16150 | break; | |
9db2f6b4 RL |
16151 | case neon_cvt_flavour_u32_f16: |
16152 | sz = 0; | |
16153 | op = 0; | |
16154 | break; | |
7e8e6784 MGD |
16155 | default: |
16156 | first_error (_("invalid instruction shape")); | |
16157 | return; | |
16158 | } | |
16159 | ||
16160 | switch (mode) | |
16161 | { | |
16162 | case neon_cvt_mode_a: rm = 0; break; | |
16163 | case neon_cvt_mode_n: rm = 1; break; | |
16164 | case neon_cvt_mode_p: rm = 2; break; | |
16165 | case neon_cvt_mode_m: rm = 3; break; | |
16166 | default: first_error (_("invalid rounding mode")); return; | |
16167 | } | |
16168 | ||
16169 | NEON_ENCODE (FPV8, inst); | |
16170 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
16171 | encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm); | |
16172 | inst.instruction |= sz << 8; | |
9db2f6b4 RL |
16173 | |
16174 | /* ARMv8.2 fp16 VCVT instruction. */ | |
16175 | if (flavour == neon_cvt_flavour_s32_f16 | |
16176 | ||flavour == neon_cvt_flavour_u32_f16) | |
16177 | do_scalar_fp16_v82_encode (); | |
7e8e6784 MGD |
16178 | inst.instruction |= op << 7; |
16179 | inst.instruction |= rm << 16; | |
16180 | inst.instruction |= 0xf0000000; | |
16181 | inst.is_neon = TRUE; | |
16182 | } | |
16183 | ||
16184 | static void | |
16185 | do_neon_cvt_1 (enum neon_cvt_mode mode) | |
037e8744 JB |
16186 | { |
16187 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ, | |
d54af2d0 RL |
16188 | NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, |
16189 | NS_FH, NS_HF, NS_FHI, NS_HFI, | |
16190 | NS_NULL); | |
6b9a8b67 | 16191 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 | 16192 | |
cc933301 JW |
16193 | if (flavour == neon_cvt_flavour_invalid) |
16194 | return; | |
16195 | ||
e3e535bc | 16196 | /* PR11109: Handle round-to-zero for VCVT conversions. */ |
7e8e6784 | 16197 | if (mode == neon_cvt_mode_z |
e3e535bc | 16198 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2) |
cc933301 JW |
16199 | && (flavour == neon_cvt_flavour_s16_f16 |
16200 | || flavour == neon_cvt_flavour_u16_f16 | |
16201 | || flavour == neon_cvt_flavour_s32_f32 | |
bacebabc RM |
16202 | || flavour == neon_cvt_flavour_u32_f32 |
16203 | || flavour == neon_cvt_flavour_s32_f64 | |
6b9a8b67 | 16204 | || flavour == neon_cvt_flavour_u32_f64) |
e3e535bc NC |
16205 | && (rs == NS_FD || rs == NS_FF)) |
16206 | { | |
16207 | do_vfp_nsyn_cvtz (); | |
16208 | return; | |
16209 | } | |
16210 | ||
9db2f6b4 RL |
16211 | /* ARMv8.2 fp16 VCVT conversions. */ |
16212 | if (mode == neon_cvt_mode_z | |
16213 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16) | |
16214 | && (flavour == neon_cvt_flavour_s32_f16 | |
16215 | || flavour == neon_cvt_flavour_u32_f16) | |
16216 | && (rs == NS_FH)) | |
16217 | { | |
16218 | do_vfp_nsyn_cvtz (); | |
16219 | do_scalar_fp16_v82_encode (); | |
16220 | return; | |
16221 | } | |
16222 | ||
037e8744 | 16223 | /* VFP rather than Neon conversions. */ |
6b9a8b67 | 16224 | if (flavour >= neon_cvt_flavour_first_fp) |
037e8744 | 16225 | { |
7e8e6784 MGD |
16226 | if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z) |
16227 | do_vfp_nsyn_cvt (rs, flavour); | |
16228 | else | |
16229 | do_vfp_nsyn_cvt_fpv8 (flavour, mode); | |
16230 | ||
037e8744 JB |
16231 | return; |
16232 | } | |
16233 | ||
16234 | switch (rs) | |
16235 | { | |
16236 | case NS_DDI: | |
16237 | case NS_QQI: | |
16238 | { | |
477330fc | 16239 | unsigned immbits; |
cc933301 JW |
16240 | unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000, |
16241 | 0x0000100, 0x1000100, 0x0, 0x1000000}; | |
35997600 | 16242 | |
477330fc RM |
16243 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
16244 | return; | |
037e8744 | 16245 | |
477330fc RM |
16246 | /* Fixed-point conversion with #0 immediate is encoded as an |
16247 | integer conversion. */ | |
16248 | if (inst.operands[2].present && inst.operands[2].imm == 0) | |
16249 | goto int_encode; | |
477330fc RM |
16250 | NEON_ENCODE (IMMED, inst); |
16251 | if (flavour != neon_cvt_flavour_invalid) | |
16252 | inst.instruction |= enctab[flavour]; | |
16253 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16254 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16255 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16256 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16257 | inst.instruction |= neon_quad (rs) << 6; | |
16258 | inst.instruction |= 1 << 21; | |
cc933301 JW |
16259 | if (flavour < neon_cvt_flavour_s16_f16) |
16260 | { | |
16261 | inst.instruction |= 1 << 21; | |
16262 | immbits = 32 - inst.operands[2].imm; | |
16263 | inst.instruction |= immbits << 16; | |
16264 | } | |
16265 | else | |
16266 | { | |
16267 | inst.instruction |= 3 << 20; | |
16268 | immbits = 16 - inst.operands[2].imm; | |
16269 | inst.instruction |= immbits << 16; | |
16270 | inst.instruction &= ~(1 << 9); | |
16271 | } | |
477330fc RM |
16272 | |
16273 | neon_dp_fixup (&inst); | |
037e8744 JB |
16274 | } |
16275 | break; | |
16276 | ||
16277 | case NS_DD: | |
16278 | case NS_QQ: | |
7e8e6784 MGD |
16279 | if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z) |
16280 | { | |
16281 | NEON_ENCODE (FLOAT, inst); | |
16282 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16283 | ||
16284 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
16285 | return; | |
16286 | ||
16287 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16288 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16289 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16290 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16291 | inst.instruction |= neon_quad (rs) << 6; | |
cc933301 JW |
16292 | inst.instruction |= (flavour == neon_cvt_flavour_u16_f16 |
16293 | || flavour == neon_cvt_flavour_u32_f32) << 7; | |
7e8e6784 | 16294 | inst.instruction |= mode << 8; |
cc933301 JW |
16295 | if (flavour == neon_cvt_flavour_u16_f16 |
16296 | || flavour == neon_cvt_flavour_s16_f16) | |
16297 | /* Mask off the original size bits and reencode them. */ | |
16298 | inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18)); | |
16299 | ||
7e8e6784 MGD |
16300 | if (thumb_mode) |
16301 | inst.instruction |= 0xfc000000; | |
16302 | else | |
16303 | inst.instruction |= 0xf0000000; | |
16304 | } | |
16305 | else | |
16306 | { | |
037e8744 | 16307 | int_encode: |
7e8e6784 | 16308 | { |
cc933301 JW |
16309 | unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080, |
16310 | 0x100, 0x180, 0x0, 0x080}; | |
037e8744 | 16311 | |
7e8e6784 | 16312 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 16313 | |
7e8e6784 MGD |
16314 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
16315 | return; | |
037e8744 | 16316 | |
7e8e6784 MGD |
16317 | if (flavour != neon_cvt_flavour_invalid) |
16318 | inst.instruction |= enctab[flavour]; | |
037e8744 | 16319 | |
7e8e6784 MGD |
16320 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
16321 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16322 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16323 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16324 | inst.instruction |= neon_quad (rs) << 6; | |
cc933301 JW |
16325 | if (flavour >= neon_cvt_flavour_s16_f16 |
16326 | && flavour <= neon_cvt_flavour_f16_u16) | |
16327 | /* Half precision. */ | |
16328 | inst.instruction |= 1 << 18; | |
16329 | else | |
16330 | inst.instruction |= 2 << 18; | |
037e8744 | 16331 | |
7e8e6784 MGD |
16332 | neon_dp_fixup (&inst); |
16333 | } | |
16334 | } | |
16335 | break; | |
037e8744 | 16336 | |
8e79c3df CM |
16337 | /* Half-precision conversions for Advanced SIMD -- neon. */ |
16338 | case NS_QD: | |
16339 | case NS_DQ: | |
bc52d49c MM |
16340 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
16341 | return; | |
8e79c3df CM |
16342 | |
16343 | if ((rs == NS_DQ) | |
16344 | && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32)) | |
16345 | { | |
16346 | as_bad (_("operand size must match register width")); | |
16347 | break; | |
16348 | } | |
16349 | ||
16350 | if ((rs == NS_QD) | |
16351 | && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16))) | |
16352 | { | |
16353 | as_bad (_("operand size must match register width")); | |
16354 | break; | |
16355 | } | |
16356 | ||
16357 | if (rs == NS_DQ) | |
477330fc | 16358 | inst.instruction = 0x3b60600; |
8e79c3df CM |
16359 | else |
16360 | inst.instruction = 0x3b60700; | |
16361 | ||
16362 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16363 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16364 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16365 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
88714cb8 | 16366 | neon_dp_fixup (&inst); |
8e79c3df CM |
16367 | break; |
16368 | ||
037e8744 JB |
16369 | default: |
16370 | /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */ | |
7e8e6784 MGD |
16371 | if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z) |
16372 | do_vfp_nsyn_cvt (rs, flavour); | |
16373 | else | |
16374 | do_vfp_nsyn_cvt_fpv8 (flavour, mode); | |
5287ad62 | 16375 | } |
5287ad62 JB |
16376 | } |
16377 | ||
e3e535bc NC |
16378 | static void |
16379 | do_neon_cvtr (void) | |
16380 | { | |
7e8e6784 | 16381 | do_neon_cvt_1 (neon_cvt_mode_x); |
e3e535bc NC |
16382 | } |
16383 | ||
16384 | static void | |
16385 | do_neon_cvt (void) | |
16386 | { | |
7e8e6784 MGD |
16387 | do_neon_cvt_1 (neon_cvt_mode_z); |
16388 | } | |
16389 | ||
16390 | static void | |
16391 | do_neon_cvta (void) | |
16392 | { | |
16393 | do_neon_cvt_1 (neon_cvt_mode_a); | |
16394 | } | |
16395 | ||
16396 | static void | |
16397 | do_neon_cvtn (void) | |
16398 | { | |
16399 | do_neon_cvt_1 (neon_cvt_mode_n); | |
16400 | } | |
16401 | ||
16402 | static void | |
16403 | do_neon_cvtp (void) | |
16404 | { | |
16405 | do_neon_cvt_1 (neon_cvt_mode_p); | |
16406 | } | |
16407 | ||
16408 | static void | |
16409 | do_neon_cvtm (void) | |
16410 | { | |
16411 | do_neon_cvt_1 (neon_cvt_mode_m); | |
e3e535bc NC |
16412 | } |
16413 | ||
8e79c3df | 16414 | static void |
c70a8987 | 16415 | do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double) |
8e79c3df | 16416 | { |
c70a8987 MGD |
16417 | if (is_double) |
16418 | mark_feature_used (&fpu_vfp_ext_armv8); | |
8e79c3df | 16419 | |
c70a8987 MGD |
16420 | encode_arm_vfp_reg (inst.operands[0].reg, |
16421 | (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd); | |
16422 | encode_arm_vfp_reg (inst.operands[1].reg, | |
16423 | (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm); | |
16424 | inst.instruction |= to ? 0x10000 : 0; | |
16425 | inst.instruction |= t ? 0x80 : 0; | |
16426 | inst.instruction |= is_double ? 0x100 : 0; | |
16427 | do_vfp_cond_or_thumb (); | |
16428 | } | |
8e79c3df | 16429 | |
c70a8987 MGD |
16430 | static void |
16431 | do_neon_cvttb_1 (bfd_boolean t) | |
16432 | { | |
d54af2d0 RL |
16433 | enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD, |
16434 | NS_DF, NS_DH, NS_NULL); | |
8e79c3df | 16435 | |
c70a8987 MGD |
16436 | if (rs == NS_NULL) |
16437 | return; | |
16438 | else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype) | |
16439 | { | |
16440 | inst.error = NULL; | |
16441 | do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE); | |
16442 | } | |
16443 | else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype) | |
16444 | { | |
16445 | inst.error = NULL; | |
16446 | do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE); | |
16447 | } | |
16448 | else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype) | |
16449 | { | |
a715796b TG |
16450 | /* The VCVTB and VCVTT instructions with D-register operands |
16451 | don't work for SP only targets. */ | |
16452 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
16453 | _(BAD_FPU)); | |
16454 | ||
c70a8987 MGD |
16455 | inst.error = NULL; |
16456 | do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE); | |
16457 | } | |
16458 | else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype) | |
16459 | { | |
a715796b TG |
16460 | /* The VCVTB and VCVTT instructions with D-register operands |
16461 | don't work for SP only targets. */ | |
16462 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
16463 | _(BAD_FPU)); | |
16464 | ||
c70a8987 MGD |
16465 | inst.error = NULL; |
16466 | do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE); | |
16467 | } | |
16468 | else | |
16469 | return; | |
16470 | } | |
16471 | ||
16472 | static void | |
16473 | do_neon_cvtb (void) | |
16474 | { | |
16475 | do_neon_cvttb_1 (FALSE); | |
8e79c3df CM |
16476 | } |
16477 | ||
16478 | ||
16479 | static void | |
16480 | do_neon_cvtt (void) | |
16481 | { | |
c70a8987 | 16482 | do_neon_cvttb_1 (TRUE); |
8e79c3df CM |
16483 | } |
16484 | ||
5287ad62 JB |
16485 | static void |
16486 | neon_move_immediate (void) | |
16487 | { | |
037e8744 JB |
16488 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
16489 | struct neon_type_el et = neon_check_type (2, rs, | |
16490 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 | 16491 | unsigned immlo, immhi = 0, immbits; |
c96612cc | 16492 | int op, cmode, float_p; |
5287ad62 | 16493 | |
037e8744 | 16494 | constraint (et.type == NT_invtype, |
477330fc | 16495 | _("operand size must be specified for immediate VMOV")); |
037e8744 | 16496 | |
5287ad62 JB |
16497 | /* We start out as an MVN instruction if OP = 1, MOV otherwise. */ |
16498 | op = (inst.instruction & (1 << 5)) != 0; | |
16499 | ||
16500 | immlo = inst.operands[1].imm; | |
16501 | if (inst.operands[1].regisimm) | |
16502 | immhi = inst.operands[1].reg; | |
16503 | ||
16504 | constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0, | |
477330fc | 16505 | _("immediate has bits set outside the operand size")); |
5287ad62 | 16506 | |
c96612cc JB |
16507 | float_p = inst.operands[1].immisfloat; |
16508 | ||
16509 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op, | |
477330fc | 16510 | et.size, et.type)) == FAIL) |
5287ad62 JB |
16511 | { |
16512 | /* Invert relevant bits only. */ | |
16513 | neon_invert_size (&immlo, &immhi, et.size); | |
16514 | /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable | |
477330fc RM |
16515 | with one or the other; those cases are caught by |
16516 | neon_cmode_for_move_imm. */ | |
5287ad62 | 16517 | op = !op; |
c96612cc JB |
16518 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, |
16519 | &op, et.size, et.type)) == FAIL) | |
477330fc RM |
16520 | { |
16521 | first_error (_("immediate out of range")); | |
16522 | return; | |
16523 | } | |
5287ad62 JB |
16524 | } |
16525 | ||
16526 | inst.instruction &= ~(1 << 5); | |
16527 | inst.instruction |= op << 5; | |
16528 | ||
16529 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16530 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
037e8744 | 16531 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
16532 | inst.instruction |= cmode << 8; |
16533 | ||
16534 | neon_write_immbits (immbits); | |
16535 | } | |
16536 | ||
16537 | static void | |
16538 | do_neon_mvn (void) | |
16539 | { | |
16540 | if (inst.operands[1].isreg) | |
16541 | { | |
037e8744 | 16542 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5f4273c7 | 16543 | |
88714cb8 | 16544 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
16545 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
16546 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16547 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16548 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 16549 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
16550 | } |
16551 | else | |
16552 | { | |
88714cb8 | 16553 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
16554 | neon_move_immediate (); |
16555 | } | |
16556 | ||
88714cb8 | 16557 | neon_dp_fixup (&inst); |
5287ad62 JB |
16558 | } |
16559 | ||
16560 | /* Encode instructions of form: | |
16561 | ||
16562 | |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
5f4273c7 | 16563 | | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */ |
5287ad62 JB |
16564 | |
16565 | static void | |
16566 | neon_mixed_length (struct neon_type_el et, unsigned size) | |
16567 | { | |
16568 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16569 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16570 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16571 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16572 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16573 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
16574 | inst.instruction |= (et.type == NT_unsigned) << 24; | |
16575 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 16576 | |
88714cb8 | 16577 | neon_dp_fixup (&inst); |
5287ad62 JB |
16578 | } |
16579 | ||
16580 | static void | |
16581 | do_neon_dyadic_long (void) | |
16582 | { | |
16583 | /* FIXME: Type checking for lengthening op. */ | |
16584 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
16585 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
16586 | neon_mixed_length (et, et.size); | |
16587 | } | |
16588 | ||
16589 | static void | |
16590 | do_neon_abal (void) | |
16591 | { | |
16592 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
16593 | N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
16594 | neon_mixed_length (et, et.size); | |
16595 | } | |
16596 | ||
16597 | static void | |
16598 | neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes) | |
16599 | { | |
16600 | if (inst.operands[2].isscalar) | |
16601 | { | |
dcbf9037 | 16602 | struct neon_type_el et = neon_check_type (3, NS_QDS, |
477330fc | 16603 | N_EQK | N_DBL, N_EQK, regtypes | N_KEY); |
88714cb8 | 16604 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
16605 | neon_mul_mac (et, et.type == NT_unsigned); |
16606 | } | |
16607 | else | |
16608 | { | |
16609 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
477330fc | 16610 | N_EQK | N_DBL, N_EQK, scalartypes | N_KEY); |
88714cb8 | 16611 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
16612 | neon_mixed_length (et, et.size); |
16613 | } | |
16614 | } | |
16615 | ||
16616 | static void | |
16617 | do_neon_mac_maybe_scalar_long (void) | |
16618 | { | |
16619 | neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32); | |
16620 | } | |
16621 | ||
dec41383 JW |
16622 | /* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's |
16623 | internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */ | |
16624 | ||
16625 | static unsigned | |
16626 | neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p) | |
16627 | { | |
16628 | unsigned regno = NEON_SCALAR_REG (scalar); | |
16629 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
16630 | ||
16631 | if (quad_p) | |
16632 | { | |
16633 | if (regno > 7 || elno > 3) | |
16634 | goto bad_scalar; | |
16635 | ||
16636 | return ((regno & 0x7) | |
16637 | | ((elno & 0x1) << 3) | |
16638 | | (((elno >> 1) & 0x1) << 5)); | |
16639 | } | |
16640 | else | |
16641 | { | |
16642 | if (regno > 15 || elno > 1) | |
16643 | goto bad_scalar; | |
16644 | ||
16645 | return (((regno & 0x1) << 5) | |
16646 | | ((regno >> 1) & 0x7) | |
16647 | | ((elno & 0x1) << 3)); | |
16648 | } | |
16649 | ||
16650 | bad_scalar: | |
16651 | first_error (_("scalar out of range for multiply instruction")); | |
16652 | return 0; | |
16653 | } | |
16654 | ||
16655 | static void | |
16656 | do_neon_fmac_maybe_scalar_long (int subtype) | |
16657 | { | |
16658 | enum neon_shape rs; | |
16659 | int high8; | |
16660 | /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size" | |
16661 | field (bits[21:20]) has different meaning. For scalar index variant, it's | |
16662 | used to differentiate add and subtract, otherwise it's with fixed value | |
16663 | 0x2. */ | |
16664 | int size = -1; | |
16665 | ||
16666 | if (inst.cond != COND_ALWAYS) | |
16667 | as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the " | |
16668 | "behaviour is UNPREDICTABLE")); | |
16669 | ||
01f48020 | 16670 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml), |
dec41383 JW |
16671 | _(BAD_FP16)); |
16672 | ||
16673 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8), | |
16674 | _(BAD_FPU)); | |
16675 | ||
16676 | /* vfmal/vfmsl are in three-same D/Q register format or the third operand can | |
16677 | be a scalar index register. */ | |
16678 | if (inst.operands[2].isscalar) | |
16679 | { | |
16680 | high8 = 0xfe000000; | |
16681 | if (subtype) | |
16682 | size = 16; | |
16683 | rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL); | |
16684 | } | |
16685 | else | |
16686 | { | |
16687 | high8 = 0xfc000000; | |
16688 | size = 32; | |
16689 | if (subtype) | |
16690 | inst.instruction |= (0x1 << 23); | |
16691 | rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL); | |
16692 | } | |
16693 | ||
16694 | neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16); | |
16695 | ||
16696 | /* "opcode" from template has included "ubit", so simply pass 0 here. Also, | |
16697 | the "S" bit in size field has been reused to differentiate vfmal and vfmsl, | |
16698 | so we simply pass -1 as size. */ | |
16699 | unsigned quad_p = (rs == NS_QDD || rs == NS_QDS); | |
16700 | neon_three_same (quad_p, 0, size); | |
16701 | ||
16702 | /* Undo neon_dp_fixup. Redo the high eight bits. */ | |
16703 | inst.instruction &= 0x00ffffff; | |
16704 | inst.instruction |= high8; | |
16705 | ||
16706 | #define LOW1(R) ((R) & 0x1) | |
16707 | #define HI4(R) (((R) >> 1) & 0xf) | |
16708 | /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on | |
16709 | whether the instruction is in Q form and whether Vm is a scalar indexed | |
16710 | operand. */ | |
16711 | if (inst.operands[2].isscalar) | |
16712 | { | |
16713 | unsigned rm | |
16714 | = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p); | |
16715 | inst.instruction &= 0xffffffd0; | |
16716 | inst.instruction |= rm; | |
16717 | ||
16718 | if (!quad_p) | |
16719 | { | |
16720 | /* Redo Rn as well. */ | |
16721 | inst.instruction &= 0xfff0ff7f; | |
16722 | inst.instruction |= HI4 (inst.operands[1].reg) << 16; | |
16723 | inst.instruction |= LOW1 (inst.operands[1].reg) << 7; | |
16724 | } | |
16725 | } | |
16726 | else if (!quad_p) | |
16727 | { | |
16728 | /* Redo Rn and Rm. */ | |
16729 | inst.instruction &= 0xfff0ff50; | |
16730 | inst.instruction |= HI4 (inst.operands[1].reg) << 16; | |
16731 | inst.instruction |= LOW1 (inst.operands[1].reg) << 7; | |
16732 | inst.instruction |= HI4 (inst.operands[2].reg); | |
16733 | inst.instruction |= LOW1 (inst.operands[2].reg) << 5; | |
16734 | } | |
16735 | } | |
16736 | ||
16737 | static void | |
16738 | do_neon_vfmal (void) | |
16739 | { | |
16740 | return do_neon_fmac_maybe_scalar_long (0); | |
16741 | } | |
16742 | ||
16743 | static void | |
16744 | do_neon_vfmsl (void) | |
16745 | { | |
16746 | return do_neon_fmac_maybe_scalar_long (1); | |
16747 | } | |
16748 | ||
5287ad62 JB |
16749 | static void |
16750 | do_neon_dyadic_wide (void) | |
16751 | { | |
16752 | struct neon_type_el et = neon_check_type (3, NS_QQD, | |
16753 | N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY); | |
16754 | neon_mixed_length (et, et.size); | |
16755 | } | |
16756 | ||
16757 | static void | |
16758 | do_neon_dyadic_narrow (void) | |
16759 | { | |
16760 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
16761 | N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY); | |
428e3f1f PB |
16762 | /* Operand sign is unimportant, and the U bit is part of the opcode, |
16763 | so force the operand type to integer. */ | |
16764 | et.type = NT_integer; | |
5287ad62 JB |
16765 | neon_mixed_length (et, et.size / 2); |
16766 | } | |
16767 | ||
16768 | static void | |
16769 | do_neon_mul_sat_scalar_long (void) | |
16770 | { | |
16771 | neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32); | |
16772 | } | |
16773 | ||
16774 | static void | |
16775 | do_neon_vmull (void) | |
16776 | { | |
16777 | if (inst.operands[2].isscalar) | |
16778 | do_neon_mac_maybe_scalar_long (); | |
16779 | else | |
16780 | { | |
16781 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
477330fc | 16782 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY); |
4f51b4bd | 16783 | |
5287ad62 | 16784 | if (et.type == NT_poly) |
477330fc | 16785 | NEON_ENCODE (POLY, inst); |
5287ad62 | 16786 | else |
477330fc | 16787 | NEON_ENCODE (INTEGER, inst); |
4f51b4bd MGD |
16788 | |
16789 | /* For polynomial encoding the U bit must be zero, and the size must | |
16790 | be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non | |
16791 | obviously, as 0b10). */ | |
16792 | if (et.size == 64) | |
16793 | { | |
16794 | /* Check we're on the correct architecture. */ | |
16795 | if (!mark_feature_used (&fpu_crypto_ext_armv8)) | |
16796 | inst.error = | |
16797 | _("Instruction form not available on this architecture."); | |
16798 | ||
16799 | et.size = 32; | |
16800 | } | |
16801 | ||
5287ad62 JB |
16802 | neon_mixed_length (et, et.size); |
16803 | } | |
16804 | } | |
16805 | ||
16806 | static void | |
16807 | do_neon_ext (void) | |
16808 | { | |
037e8744 | 16809 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); |
5287ad62 JB |
16810 | struct neon_type_el et = neon_check_type (3, rs, |
16811 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
16812 | unsigned imm = (inst.operands[3].imm * et.size) / 8; | |
35997600 NC |
16813 | |
16814 | constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8), | |
16815 | _("shift out of range")); | |
5287ad62 JB |
16816 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
16817 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16818 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16819 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16820 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16821 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
037e8744 | 16822 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 | 16823 | inst.instruction |= imm << 8; |
5f4273c7 | 16824 | |
88714cb8 | 16825 | neon_dp_fixup (&inst); |
5287ad62 JB |
16826 | } |
16827 | ||
16828 | static void | |
16829 | do_neon_rev (void) | |
16830 | { | |
037e8744 | 16831 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16832 | struct neon_type_el et = neon_check_type (2, rs, |
16833 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
16834 | unsigned op = (inst.instruction >> 7) & 3; | |
16835 | /* N (width of reversed regions) is encoded as part of the bitmask. We | |
16836 | extract it here to check the elements to be reversed are smaller. | |
16837 | Otherwise we'd get a reserved instruction. */ | |
16838 | unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0; | |
9c2799c2 | 16839 | gas_assert (elsize != 0); |
5287ad62 | 16840 | constraint (et.size >= elsize, |
477330fc | 16841 | _("elements must be smaller than reversal region")); |
037e8744 | 16842 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16843 | } |
16844 | ||
16845 | static void | |
16846 | do_neon_dup (void) | |
16847 | { | |
16848 | if (inst.operands[1].isscalar) | |
16849 | { | |
037e8744 | 16850 | enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL); |
dcbf9037 | 16851 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 16852 | N_EQK, N_8 | N_16 | N_32 | N_KEY); |
5287ad62 | 16853 | unsigned sizebits = et.size >> 3; |
dcbf9037 | 16854 | unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg); |
5287ad62 | 16855 | int logsize = neon_logbits (et.size); |
dcbf9037 | 16856 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize; |
037e8744 JB |
16857 | |
16858 | if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL) | |
477330fc | 16859 | return; |
037e8744 | 16860 | |
88714cb8 | 16861 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
16862 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
16863 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16864 | inst.instruction |= LOW4 (dm); | |
16865 | inst.instruction |= HI1 (dm) << 5; | |
037e8744 | 16866 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
16867 | inst.instruction |= x << 17; |
16868 | inst.instruction |= sizebits << 16; | |
5f4273c7 | 16869 | |
88714cb8 | 16870 | neon_dp_fixup (&inst); |
5287ad62 JB |
16871 | } |
16872 | else | |
16873 | { | |
037e8744 JB |
16874 | enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL); |
16875 | struct neon_type_el et = neon_check_type (2, rs, | |
477330fc | 16876 | N_8 | N_16 | N_32 | N_KEY, N_EQK); |
5287ad62 | 16877 | /* Duplicate ARM register to lanes of vector. */ |
88714cb8 | 16878 | NEON_ENCODE (ARMREG, inst); |
5287ad62 | 16879 | switch (et.size) |
477330fc RM |
16880 | { |
16881 | case 8: inst.instruction |= 0x400000; break; | |
16882 | case 16: inst.instruction |= 0x000020; break; | |
16883 | case 32: inst.instruction |= 0x000000; break; | |
16884 | default: break; | |
16885 | } | |
5287ad62 JB |
16886 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; |
16887 | inst.instruction |= LOW4 (inst.operands[0].reg) << 16; | |
16888 | inst.instruction |= HI1 (inst.operands[0].reg) << 7; | |
037e8744 | 16889 | inst.instruction |= neon_quad (rs) << 21; |
5287ad62 | 16890 | /* The encoding for this instruction is identical for the ARM and Thumb |
477330fc | 16891 | variants, except for the condition field. */ |
037e8744 | 16892 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
16893 | } |
16894 | } | |
16895 | ||
16896 | /* VMOV has particularly many variations. It can be one of: | |
16897 | 0. VMOV<c><q> <Qd>, <Qm> | |
16898 | 1. VMOV<c><q> <Dd>, <Dm> | |
16899 | (Register operations, which are VORR with Rm = Rn.) | |
16900 | 2. VMOV<c><q>.<dt> <Qd>, #<imm> | |
16901 | 3. VMOV<c><q>.<dt> <Dd>, #<imm> | |
16902 | (Immediate loads.) | |
16903 | 4. VMOV<c><q>.<size> <Dn[x]>, <Rd> | |
16904 | (ARM register to scalar.) | |
16905 | 5. VMOV<c><q> <Dm>, <Rd>, <Rn> | |
16906 | (Two ARM registers to vector.) | |
16907 | 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]> | |
16908 | (Scalar to ARM register.) | |
16909 | 7. VMOV<c><q> <Rd>, <Rn>, <Dm> | |
16910 | (Vector to two ARM registers.) | |
037e8744 JB |
16911 | 8. VMOV.F32 <Sd>, <Sm> |
16912 | 9. VMOV.F64 <Dd>, <Dm> | |
16913 | (VFP register moves.) | |
16914 | 10. VMOV.F32 <Sd>, #imm | |
16915 | 11. VMOV.F64 <Dd>, #imm | |
16916 | (VFP float immediate load.) | |
16917 | 12. VMOV <Rd>, <Sm> | |
16918 | (VFP single to ARM reg.) | |
16919 | 13. VMOV <Sd>, <Rm> | |
16920 | (ARM reg to VFP single.) | |
16921 | 14. VMOV <Rd>, <Re>, <Sn>, <Sm> | |
16922 | (Two ARM regs to two VFP singles.) | |
16923 | 15. VMOV <Sd>, <Se>, <Rn>, <Rm> | |
16924 | (Two VFP singles to two ARM regs.) | |
5f4273c7 | 16925 | |
037e8744 JB |
16926 | These cases can be disambiguated using neon_select_shape, except cases 1/9 |
16927 | and 3/11 which depend on the operand type too. | |
5f4273c7 | 16928 | |
5287ad62 | 16929 | All the encoded bits are hardcoded by this function. |
5f4273c7 | 16930 | |
b7fc2769 JB |
16931 | Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!). |
16932 | Cases 5, 7 may be used with VFPv2 and above. | |
5f4273c7 | 16933 | |
5287ad62 | 16934 | FIXME: Some of the checking may be a bit sloppy (in a couple of cases you |
5f4273c7 | 16935 | can specify a type where it doesn't make sense to, and is ignored). */ |
5287ad62 JB |
16936 | |
16937 | static void | |
16938 | do_neon_mov (void) | |
16939 | { | |
037e8744 | 16940 | enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD, |
9db2f6b4 RL |
16941 | NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, |
16942 | NS_RS, NS_FF, NS_FI, NS_RF, NS_FR, | |
16943 | NS_HR, NS_RH, NS_HI, NS_NULL); | |
037e8744 JB |
16944 | struct neon_type_el et; |
16945 | const char *ldconst = 0; | |
5287ad62 | 16946 | |
037e8744 | 16947 | switch (rs) |
5287ad62 | 16948 | { |
037e8744 JB |
16949 | case NS_DD: /* case 1/9. */ |
16950 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
16951 | /* It is not an error here if no type is given. */ | |
16952 | inst.error = NULL; | |
16953 | if (et.type == NT_float && et.size == 64) | |
477330fc RM |
16954 | { |
16955 | do_vfp_nsyn_opcode ("fcpyd"); | |
16956 | break; | |
16957 | } | |
037e8744 | 16958 | /* fall through. */ |
5287ad62 | 16959 | |
037e8744 JB |
16960 | case NS_QQ: /* case 0/1. */ |
16961 | { | |
477330fc RM |
16962 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
16963 | return; | |
16964 | /* The architecture manual I have doesn't explicitly state which | |
16965 | value the U bit should have for register->register moves, but | |
16966 | the equivalent VORR instruction has U = 0, so do that. */ | |
16967 | inst.instruction = 0x0200110; | |
16968 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16969 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16970 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16971 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16972 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16973 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16974 | inst.instruction |= neon_quad (rs) << 6; | |
16975 | ||
16976 | neon_dp_fixup (&inst); | |
037e8744 JB |
16977 | } |
16978 | break; | |
5f4273c7 | 16979 | |
037e8744 JB |
16980 | case NS_DI: /* case 3/11. */ |
16981 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
16982 | inst.error = NULL; | |
16983 | if (et.type == NT_float && et.size == 64) | |
477330fc RM |
16984 | { |
16985 | /* case 11 (fconstd). */ | |
16986 | ldconst = "fconstd"; | |
16987 | goto encode_fconstd; | |
16988 | } | |
037e8744 JB |
16989 | /* fall through. */ |
16990 | ||
16991 | case NS_QI: /* case 2/3. */ | |
16992 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
477330fc | 16993 | return; |
037e8744 JB |
16994 | inst.instruction = 0x0800010; |
16995 | neon_move_immediate (); | |
88714cb8 | 16996 | neon_dp_fixup (&inst); |
5287ad62 | 16997 | break; |
5f4273c7 | 16998 | |
037e8744 JB |
16999 | case NS_SR: /* case 4. */ |
17000 | { | |
477330fc RM |
17001 | unsigned bcdebits = 0; |
17002 | int logsize; | |
17003 | unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg); | |
17004 | unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg); | |
037e8744 | 17005 | |
05ac0ffb JB |
17006 | /* .<size> is optional here, defaulting to .32. */ |
17007 | if (inst.vectype.elems == 0 | |
17008 | && inst.operands[0].vectype.type == NT_invtype | |
17009 | && inst.operands[1].vectype.type == NT_invtype) | |
17010 | { | |
17011 | inst.vectype.el[0].type = NT_untyped; | |
17012 | inst.vectype.el[0].size = 32; | |
17013 | inst.vectype.elems = 1; | |
17014 | } | |
17015 | ||
477330fc RM |
17016 | et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK); |
17017 | logsize = neon_logbits (et.size); | |
17018 | ||
17019 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
17020 | _(BAD_FPU)); | |
17021 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
17022 | && et.size != 32, _(BAD_FPU)); | |
17023 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
17024 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
17025 | ||
17026 | switch (et.size) | |
17027 | { | |
17028 | case 8: bcdebits = 0x8; break; | |
17029 | case 16: bcdebits = 0x1; break; | |
17030 | case 32: bcdebits = 0x0; break; | |
17031 | default: ; | |
17032 | } | |
17033 | ||
17034 | bcdebits |= x << logsize; | |
17035 | ||
17036 | inst.instruction = 0xe000b10; | |
17037 | do_vfp_cond_or_thumb (); | |
17038 | inst.instruction |= LOW4 (dn) << 16; | |
17039 | inst.instruction |= HI1 (dn) << 7; | |
17040 | inst.instruction |= inst.operands[1].reg << 12; | |
17041 | inst.instruction |= (bcdebits & 3) << 5; | |
17042 | inst.instruction |= (bcdebits >> 2) << 21; | |
037e8744 JB |
17043 | } |
17044 | break; | |
5f4273c7 | 17045 | |
037e8744 | 17046 | case NS_DRR: /* case 5 (fmdrr). */ |
b7fc2769 | 17047 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), |
477330fc | 17048 | _(BAD_FPU)); |
b7fc2769 | 17049 | |
037e8744 JB |
17050 | inst.instruction = 0xc400b10; |
17051 | do_vfp_cond_or_thumb (); | |
17052 | inst.instruction |= LOW4 (inst.operands[0].reg); | |
17053 | inst.instruction |= HI1 (inst.operands[0].reg) << 5; | |
17054 | inst.instruction |= inst.operands[1].reg << 12; | |
17055 | inst.instruction |= inst.operands[2].reg << 16; | |
17056 | break; | |
5f4273c7 | 17057 | |
037e8744 JB |
17058 | case NS_RS: /* case 6. */ |
17059 | { | |
477330fc RM |
17060 | unsigned logsize; |
17061 | unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg); | |
17062 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg); | |
17063 | unsigned abcdebits = 0; | |
037e8744 | 17064 | |
05ac0ffb JB |
17065 | /* .<dt> is optional here, defaulting to .32. */ |
17066 | if (inst.vectype.elems == 0 | |
17067 | && inst.operands[0].vectype.type == NT_invtype | |
17068 | && inst.operands[1].vectype.type == NT_invtype) | |
17069 | { | |
17070 | inst.vectype.el[0].type = NT_untyped; | |
17071 | inst.vectype.el[0].size = 32; | |
17072 | inst.vectype.elems = 1; | |
17073 | } | |
17074 | ||
91d6fa6a NC |
17075 | et = neon_check_type (2, NS_NULL, |
17076 | N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY); | |
477330fc RM |
17077 | logsize = neon_logbits (et.size); |
17078 | ||
17079 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
17080 | _(BAD_FPU)); | |
17081 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
17082 | && et.size != 32, _(BAD_FPU)); | |
17083 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
17084 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
17085 | ||
17086 | switch (et.size) | |
17087 | { | |
17088 | case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break; | |
17089 | case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break; | |
17090 | case 32: abcdebits = 0x00; break; | |
17091 | default: ; | |
17092 | } | |
17093 | ||
17094 | abcdebits |= x << logsize; | |
17095 | inst.instruction = 0xe100b10; | |
17096 | do_vfp_cond_or_thumb (); | |
17097 | inst.instruction |= LOW4 (dn) << 16; | |
17098 | inst.instruction |= HI1 (dn) << 7; | |
17099 | inst.instruction |= inst.operands[0].reg << 12; | |
17100 | inst.instruction |= (abcdebits & 3) << 5; | |
17101 | inst.instruction |= (abcdebits >> 2) << 21; | |
037e8744 JB |
17102 | } |
17103 | break; | |
5f4273c7 | 17104 | |
037e8744 JB |
17105 | case NS_RRD: /* case 7 (fmrrd). */ |
17106 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), | |
477330fc | 17107 | _(BAD_FPU)); |
037e8744 JB |
17108 | |
17109 | inst.instruction = 0xc500b10; | |
17110 | do_vfp_cond_or_thumb (); | |
17111 | inst.instruction |= inst.operands[0].reg << 12; | |
17112 | inst.instruction |= inst.operands[1].reg << 16; | |
17113 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
17114 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
17115 | break; | |
5f4273c7 | 17116 | |
037e8744 JB |
17117 | case NS_FF: /* case 8 (fcpys). */ |
17118 | do_vfp_nsyn_opcode ("fcpys"); | |
17119 | break; | |
5f4273c7 | 17120 | |
9db2f6b4 | 17121 | case NS_HI: |
037e8744 JB |
17122 | case NS_FI: /* case 10 (fconsts). */ |
17123 | ldconst = "fconsts"; | |
4ef4710f | 17124 | encode_fconstd: |
58ed5c38 TC |
17125 | if (!inst.operands[1].immisfloat) |
17126 | { | |
4ef4710f | 17127 | unsigned new_imm; |
58ed5c38 | 17128 | /* Immediate has to fit in 8 bits so float is enough. */ |
4ef4710f NC |
17129 | float imm = (float) inst.operands[1].imm; |
17130 | memcpy (&new_imm, &imm, sizeof (float)); | |
17131 | /* But the assembly may have been written to provide an integer | |
17132 | bit pattern that equates to a float, so check that the | |
17133 | conversion has worked. */ | |
17134 | if (is_quarter_float (new_imm)) | |
17135 | { | |
17136 | if (is_quarter_float (inst.operands[1].imm)) | |
17137 | as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)")); | |
17138 | ||
17139 | inst.operands[1].imm = new_imm; | |
17140 | inst.operands[1].immisfloat = 1; | |
17141 | } | |
58ed5c38 TC |
17142 | } |
17143 | ||
037e8744 | 17144 | if (is_quarter_float (inst.operands[1].imm)) |
477330fc RM |
17145 | { |
17146 | inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm); | |
17147 | do_vfp_nsyn_opcode (ldconst); | |
9db2f6b4 RL |
17148 | |
17149 | /* ARMv8.2 fp16 vmov.f16 instruction. */ | |
17150 | if (rs == NS_HI) | |
17151 | do_scalar_fp16_v82_encode (); | |
477330fc | 17152 | } |
5287ad62 | 17153 | else |
477330fc | 17154 | first_error (_("immediate out of range")); |
037e8744 | 17155 | break; |
5f4273c7 | 17156 | |
9db2f6b4 | 17157 | case NS_RH: |
037e8744 JB |
17158 | case NS_RF: /* case 12 (fmrs). */ |
17159 | do_vfp_nsyn_opcode ("fmrs"); | |
9db2f6b4 RL |
17160 | /* ARMv8.2 fp16 vmov.f16 instruction. */ |
17161 | if (rs == NS_RH) | |
17162 | do_scalar_fp16_v82_encode (); | |
037e8744 | 17163 | break; |
5f4273c7 | 17164 | |
9db2f6b4 | 17165 | case NS_HR: |
037e8744 JB |
17166 | case NS_FR: /* case 13 (fmsr). */ |
17167 | do_vfp_nsyn_opcode ("fmsr"); | |
9db2f6b4 RL |
17168 | /* ARMv8.2 fp16 vmov.f16 instruction. */ |
17169 | if (rs == NS_HR) | |
17170 | do_scalar_fp16_v82_encode (); | |
037e8744 | 17171 | break; |
5f4273c7 | 17172 | |
037e8744 JB |
17173 | /* The encoders for the fmrrs and fmsrr instructions expect three operands |
17174 | (one of which is a list), but we have parsed four. Do some fiddling to | |
17175 | make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2 | |
17176 | expect. */ | |
17177 | case NS_RRFF: /* case 14 (fmrrs). */ | |
17178 | constraint (inst.operands[3].reg != inst.operands[2].reg + 1, | |
477330fc | 17179 | _("VFP registers must be adjacent")); |
037e8744 JB |
17180 | inst.operands[2].imm = 2; |
17181 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
17182 | do_vfp_nsyn_opcode ("fmrrs"); | |
17183 | break; | |
5f4273c7 | 17184 | |
037e8744 JB |
17185 | case NS_FFRR: /* case 15 (fmsrr). */ |
17186 | constraint (inst.operands[1].reg != inst.operands[0].reg + 1, | |
477330fc | 17187 | _("VFP registers must be adjacent")); |
037e8744 JB |
17188 | inst.operands[1] = inst.operands[2]; |
17189 | inst.operands[2] = inst.operands[3]; | |
17190 | inst.operands[0].imm = 2; | |
17191 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
17192 | do_vfp_nsyn_opcode ("fmsrr"); | |
5287ad62 | 17193 | break; |
5f4273c7 | 17194 | |
4c261dff NC |
17195 | case NS_NULL: |
17196 | /* neon_select_shape has determined that the instruction | |
17197 | shape is wrong and has already set the error message. */ | |
17198 | break; | |
17199 | ||
5287ad62 JB |
17200 | default: |
17201 | abort (); | |
17202 | } | |
17203 | } | |
17204 | ||
17205 | static void | |
17206 | do_neon_rshift_round_imm (void) | |
17207 | { | |
037e8744 | 17208 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
17209 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
17210 | int imm = inst.operands[2].imm; | |
17211 | ||
17212 | /* imm == 0 case is encoded as VMOV for V{R}SHR. */ | |
17213 | if (imm == 0) | |
17214 | { | |
17215 | inst.operands[2].present = 0; | |
17216 | do_neon_mov (); | |
17217 | return; | |
17218 | } | |
17219 | ||
17220 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 17221 | _("immediate out of range for shift")); |
037e8744 | 17222 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
477330fc | 17223 | et.size - imm); |
5287ad62 JB |
17224 | } |
17225 | ||
9db2f6b4 RL |
17226 | static void |
17227 | do_neon_movhf (void) | |
17228 | { | |
17229 | enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL); | |
17230 | constraint (rs != NS_HH, _("invalid suffix")); | |
17231 | ||
7bdf778b ASDV |
17232 | if (inst.cond != COND_ALWAYS) |
17233 | { | |
17234 | if (thumb_mode) | |
17235 | { | |
17236 | as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional," | |
17237 | " the behaviour is UNPREDICTABLE")); | |
17238 | } | |
17239 | else | |
17240 | { | |
17241 | inst.error = BAD_COND; | |
17242 | return; | |
17243 | } | |
17244 | } | |
17245 | ||
9db2f6b4 RL |
17246 | do_vfp_sp_monadic (); |
17247 | ||
17248 | inst.is_neon = 1; | |
17249 | inst.instruction |= 0xf0000000; | |
17250 | } | |
17251 | ||
5287ad62 JB |
17252 | static void |
17253 | do_neon_movl (void) | |
17254 | { | |
17255 | struct neon_type_el et = neon_check_type (2, NS_QD, | |
17256 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
17257 | unsigned sizebits = et.size >> 3; | |
17258 | inst.instruction |= sizebits << 19; | |
17259 | neon_two_same (0, et.type == NT_unsigned, -1); | |
17260 | } | |
17261 | ||
17262 | static void | |
17263 | do_neon_trn (void) | |
17264 | { | |
037e8744 | 17265 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
17266 | struct neon_type_el et = neon_check_type (2, rs, |
17267 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
88714cb8 | 17268 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 17269 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
17270 | } |
17271 | ||
17272 | static void | |
17273 | do_neon_zip_uzp (void) | |
17274 | { | |
037e8744 | 17275 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
17276 | struct neon_type_el et = neon_check_type (2, rs, |
17277 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
17278 | if (rs == NS_DD && et.size == 32) | |
17279 | { | |
17280 | /* Special case: encode as VTRN.32 <Dd>, <Dm>. */ | |
17281 | inst.instruction = N_MNEM_vtrn; | |
17282 | do_neon_trn (); | |
17283 | return; | |
17284 | } | |
037e8744 | 17285 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
17286 | } |
17287 | ||
17288 | static void | |
17289 | do_neon_sat_abs_neg (void) | |
17290 | { | |
037e8744 | 17291 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
17292 | struct neon_type_el et = neon_check_type (2, rs, |
17293 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 17294 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
17295 | } |
17296 | ||
17297 | static void | |
17298 | do_neon_pair_long (void) | |
17299 | { | |
037e8744 | 17300 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
17301 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY); |
17302 | /* Unsigned is encoded in OP field (bit 7) for these instruction. */ | |
17303 | inst.instruction |= (et.type == NT_unsigned) << 7; | |
037e8744 | 17304 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
17305 | } |
17306 | ||
17307 | static void | |
17308 | do_neon_recip_est (void) | |
17309 | { | |
037e8744 | 17310 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 | 17311 | struct neon_type_el et = neon_check_type (2, rs, |
cc933301 | 17312 | N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY); |
5287ad62 | 17313 | inst.instruction |= (et.type == NT_float) << 8; |
037e8744 | 17314 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
17315 | } |
17316 | ||
17317 | static void | |
17318 | do_neon_cls (void) | |
17319 | { | |
037e8744 | 17320 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
17321 | struct neon_type_el et = neon_check_type (2, rs, |
17322 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 17323 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
17324 | } |
17325 | ||
17326 | static void | |
17327 | do_neon_clz (void) | |
17328 | { | |
037e8744 | 17329 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
17330 | struct neon_type_el et = neon_check_type (2, rs, |
17331 | N_EQK, N_I8 | N_I16 | N_I32 | N_KEY); | |
037e8744 | 17332 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
17333 | } |
17334 | ||
17335 | static void | |
17336 | do_neon_cnt (void) | |
17337 | { | |
037e8744 | 17338 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
17339 | struct neon_type_el et = neon_check_type (2, rs, |
17340 | N_EQK | N_INT, N_8 | N_KEY); | |
037e8744 | 17341 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
17342 | } |
17343 | ||
17344 | static void | |
17345 | do_neon_swp (void) | |
17346 | { | |
037e8744 JB |
17347 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
17348 | neon_two_same (neon_quad (rs), 1, -1); | |
5287ad62 JB |
17349 | } |
17350 | ||
17351 | static void | |
17352 | do_neon_tbl_tbx (void) | |
17353 | { | |
17354 | unsigned listlenbits; | |
dcbf9037 | 17355 | neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY); |
5f4273c7 | 17356 | |
5287ad62 JB |
17357 | if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4) |
17358 | { | |
dcbf9037 | 17359 | first_error (_("bad list length for table lookup")); |
5287ad62 JB |
17360 | return; |
17361 | } | |
5f4273c7 | 17362 | |
5287ad62 JB |
17363 | listlenbits = inst.operands[1].imm - 1; |
17364 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17365 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17366 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
17367 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
17368 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
17369 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
17370 | inst.instruction |= listlenbits << 8; | |
5f4273c7 | 17371 | |
88714cb8 | 17372 | neon_dp_fixup (&inst); |
5287ad62 JB |
17373 | } |
17374 | ||
17375 | static void | |
17376 | do_neon_ldm_stm (void) | |
17377 | { | |
17378 | /* P, U and L bits are part of bitmask. */ | |
17379 | int is_dbmode = (inst.instruction & (1 << 24)) != 0; | |
17380 | unsigned offsetbits = inst.operands[1].imm * 2; | |
17381 | ||
037e8744 JB |
17382 | if (inst.operands[1].issingle) |
17383 | { | |
17384 | do_vfp_nsyn_ldm_stm (is_dbmode); | |
17385 | return; | |
17386 | } | |
17387 | ||
5287ad62 | 17388 | constraint (is_dbmode && !inst.operands[0].writeback, |
477330fc | 17389 | _("writeback (!) must be used for VLDMDB and VSTMDB")); |
5287ad62 JB |
17390 | |
17391 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
477330fc RM |
17392 | _("register list must contain at least 1 and at most 16 " |
17393 | "registers")); | |
5287ad62 JB |
17394 | |
17395 | inst.instruction |= inst.operands[0].reg << 16; | |
17396 | inst.instruction |= inst.operands[0].writeback << 21; | |
17397 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
17398 | inst.instruction |= HI1 (inst.operands[1].reg) << 22; | |
17399 | ||
17400 | inst.instruction |= offsetbits; | |
5f4273c7 | 17401 | |
037e8744 | 17402 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
17403 | } |
17404 | ||
17405 | static void | |
17406 | do_neon_ldr_str (void) | |
17407 | { | |
5287ad62 | 17408 | int is_ldr = (inst.instruction & (1 << 20)) != 0; |
5f4273c7 | 17409 | |
6844b2c2 MGD |
17410 | /* Use of PC in vstr in ARM mode is deprecated in ARMv7. |
17411 | And is UNPREDICTABLE in thumb mode. */ | |
fa94de6b | 17412 | if (!is_ldr |
6844b2c2 | 17413 | && inst.operands[1].reg == REG_PC |
ba86b375 | 17414 | && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode)) |
6844b2c2 | 17415 | { |
94dcf8bf | 17416 | if (thumb_mode) |
6844b2c2 | 17417 | inst.error = _("Use of PC here is UNPREDICTABLE"); |
94dcf8bf | 17418 | else if (warn_on_deprecated) |
5c3696f8 | 17419 | as_tsktsk (_("Use of PC here is deprecated")); |
6844b2c2 MGD |
17420 | } |
17421 | ||
037e8744 JB |
17422 | if (inst.operands[0].issingle) |
17423 | { | |
cd2f129f | 17424 | if (is_ldr) |
477330fc | 17425 | do_vfp_nsyn_opcode ("flds"); |
cd2f129f | 17426 | else |
477330fc | 17427 | do_vfp_nsyn_opcode ("fsts"); |
9db2f6b4 RL |
17428 | |
17429 | /* ARMv8.2 vldr.16/vstr.16 instruction. */ | |
17430 | if (inst.vectype.el[0].size == 16) | |
17431 | do_scalar_fp16_v82_encode (); | |
5287ad62 JB |
17432 | } |
17433 | else | |
5287ad62 | 17434 | { |
cd2f129f | 17435 | if (is_ldr) |
477330fc | 17436 | do_vfp_nsyn_opcode ("fldd"); |
5287ad62 | 17437 | else |
477330fc | 17438 | do_vfp_nsyn_opcode ("fstd"); |
5287ad62 | 17439 | } |
5287ad62 JB |
17440 | } |
17441 | ||
32c36c3c AV |
17442 | static void |
17443 | do_t_vldr_vstr_sysreg (void) | |
17444 | { | |
17445 | int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20; | |
17446 | bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0); | |
17447 | ||
17448 | /* Use of PC is UNPREDICTABLE. */ | |
17449 | if (inst.operands[1].reg == REG_PC) | |
17450 | inst.error = _("Use of PC here is UNPREDICTABLE"); | |
17451 | ||
17452 | if (inst.operands[1].immisreg) | |
17453 | inst.error = _("instruction does not accept register index"); | |
17454 | ||
17455 | if (!inst.operands[1].isreg) | |
17456 | inst.error = _("instruction does not accept PC-relative addressing"); | |
17457 | ||
17458 | if (abs (inst.operands[1].imm) >= (1 << 7)) | |
17459 | inst.error = _("immediate value out of range"); | |
17460 | ||
17461 | inst.instruction = 0xec000f80; | |
17462 | if (is_vldr) | |
17463 | inst.instruction |= 1 << sysreg_vldr_bitno; | |
17464 | encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM); | |
17465 | inst.instruction |= (inst.operands[0].imm & 0x7) << 13; | |
17466 | inst.instruction |= (inst.operands[0].imm & 0x8) << 19; | |
17467 | } | |
17468 | ||
17469 | static void | |
17470 | do_vldr_vstr (void) | |
17471 | { | |
17472 | bfd_boolean sysreg_op = !inst.operands[0].isreg; | |
17473 | ||
17474 | /* VLDR/VSTR (System Register). */ | |
17475 | if (sysreg_op) | |
17476 | { | |
17477 | if (!mark_feature_used (&arm_ext_v8_1m_main)) | |
17478 | as_bad (_("Instruction not permitted on this architecture")); | |
17479 | ||
17480 | do_t_vldr_vstr_sysreg (); | |
17481 | } | |
17482 | /* VLDR/VSTR. */ | |
17483 | else | |
17484 | { | |
17485 | if (!mark_feature_used (&fpu_vfp_ext_v1xd)) | |
17486 | as_bad (_("Instruction not permitted on this architecture")); | |
17487 | do_neon_ldr_str (); | |
17488 | } | |
17489 | } | |
17490 | ||
5287ad62 JB |
17491 | /* "interleave" version also handles non-interleaving register VLD1/VST1 |
17492 | instructions. */ | |
17493 | ||
17494 | static void | |
17495 | do_neon_ld_st_interleave (void) | |
17496 | { | |
037e8744 | 17497 | struct neon_type_el et = neon_check_type (1, NS_NULL, |
477330fc | 17498 | N_8 | N_16 | N_32 | N_64); |
5287ad62 JB |
17499 | unsigned alignbits = 0; |
17500 | unsigned idx; | |
17501 | /* The bits in this table go: | |
17502 | 0: register stride of one (0) or two (1) | |
17503 | 1,2: register list length, minus one (1, 2, 3, 4). | |
17504 | 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>). | |
17505 | We use -1 for invalid entries. */ | |
17506 | const int typetable[] = | |
17507 | { | |
17508 | 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */ | |
17509 | -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */ | |
17510 | -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */ | |
17511 | -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */ | |
17512 | }; | |
17513 | int typebits; | |
17514 | ||
dcbf9037 JB |
17515 | if (et.type == NT_invtype) |
17516 | return; | |
17517 | ||
5287ad62 JB |
17518 | if (inst.operands[1].immisalign) |
17519 | switch (inst.operands[1].imm >> 8) | |
17520 | { | |
17521 | case 64: alignbits = 1; break; | |
17522 | case 128: | |
477330fc | 17523 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2 |
e23c0ad8 | 17524 | && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
477330fc RM |
17525 | goto bad_alignment; |
17526 | alignbits = 2; | |
17527 | break; | |
5287ad62 | 17528 | case 256: |
477330fc RM |
17529 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
17530 | goto bad_alignment; | |
17531 | alignbits = 3; | |
17532 | break; | |
5287ad62 JB |
17533 | default: |
17534 | bad_alignment: | |
477330fc RM |
17535 | first_error (_("bad alignment")); |
17536 | return; | |
5287ad62 JB |
17537 | } |
17538 | ||
17539 | inst.instruction |= alignbits << 4; | |
17540 | inst.instruction |= neon_logbits (et.size) << 6; | |
17541 | ||
17542 | /* Bits [4:6] of the immediate in a list specifier encode register stride | |
17543 | (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of | |
17544 | VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look | |
17545 | up the right value for "type" in a table based on this value and the given | |
17546 | list style, then stick it back. */ | |
17547 | idx = ((inst.operands[0].imm >> 4) & 7) | |
477330fc | 17548 | | (((inst.instruction >> 8) & 3) << 3); |
5287ad62 JB |
17549 | |
17550 | typebits = typetable[idx]; | |
5f4273c7 | 17551 | |
5287ad62 | 17552 | constraint (typebits == -1, _("bad list type for instruction")); |
1d50d57c WN |
17553 | constraint (((inst.instruction >> 8) & 3) && et.size == 64, |
17554 | _("bad element type for instruction")); | |
5287ad62 JB |
17555 | |
17556 | inst.instruction &= ~0xf00; | |
17557 | inst.instruction |= typebits << 8; | |
17558 | } | |
17559 | ||
17560 | /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup. | |
17561 | *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0 | |
17562 | otherwise. The variable arguments are a list of pairs of legal (size, align) | |
17563 | values, terminated with -1. */ | |
17564 | ||
17565 | static int | |
aa8a0863 | 17566 | neon_alignment_bit (int size, int align, int *do_alignment, ...) |
5287ad62 JB |
17567 | { |
17568 | va_list ap; | |
17569 | int result = FAIL, thissize, thisalign; | |
5f4273c7 | 17570 | |
5287ad62 JB |
17571 | if (!inst.operands[1].immisalign) |
17572 | { | |
aa8a0863 | 17573 | *do_alignment = 0; |
5287ad62 JB |
17574 | return SUCCESS; |
17575 | } | |
5f4273c7 | 17576 | |
aa8a0863 | 17577 | va_start (ap, do_alignment); |
5287ad62 JB |
17578 | |
17579 | do | |
17580 | { | |
17581 | thissize = va_arg (ap, int); | |
17582 | if (thissize == -1) | |
477330fc | 17583 | break; |
5287ad62 JB |
17584 | thisalign = va_arg (ap, int); |
17585 | ||
17586 | if (size == thissize && align == thisalign) | |
477330fc | 17587 | result = SUCCESS; |
5287ad62 JB |
17588 | } |
17589 | while (result != SUCCESS); | |
17590 | ||
17591 | va_end (ap); | |
17592 | ||
17593 | if (result == SUCCESS) | |
aa8a0863 | 17594 | *do_alignment = 1; |
5287ad62 | 17595 | else |
dcbf9037 | 17596 | first_error (_("unsupported alignment for instruction")); |
5f4273c7 | 17597 | |
5287ad62 JB |
17598 | return result; |
17599 | } | |
17600 | ||
17601 | static void | |
17602 | do_neon_ld_st_lane (void) | |
17603 | { | |
037e8744 | 17604 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
aa8a0863 | 17605 | int align_good, do_alignment = 0; |
5287ad62 JB |
17606 | int logsize = neon_logbits (et.size); |
17607 | int align = inst.operands[1].imm >> 8; | |
17608 | int n = (inst.instruction >> 8) & 3; | |
17609 | int max_el = 64 / et.size; | |
5f4273c7 | 17610 | |
dcbf9037 JB |
17611 | if (et.type == NT_invtype) |
17612 | return; | |
5f4273c7 | 17613 | |
5287ad62 | 17614 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1, |
477330fc | 17615 | _("bad list length")); |
5287ad62 | 17616 | constraint (NEON_LANE (inst.operands[0].imm) >= max_el, |
477330fc | 17617 | _("scalar index out of range")); |
5287ad62 | 17618 | constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2 |
477330fc RM |
17619 | && et.size == 8, |
17620 | _("stride of 2 unavailable when element size is 8")); | |
5f4273c7 | 17621 | |
5287ad62 JB |
17622 | switch (n) |
17623 | { | |
17624 | case 0: /* VLD1 / VST1. */ | |
aa8a0863 | 17625 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16, |
477330fc | 17626 | 32, 32, -1); |
5287ad62 | 17627 | if (align_good == FAIL) |
477330fc | 17628 | return; |
aa8a0863 | 17629 | if (do_alignment) |
477330fc RM |
17630 | { |
17631 | unsigned alignbits = 0; | |
17632 | switch (et.size) | |
17633 | { | |
17634 | case 16: alignbits = 0x1; break; | |
17635 | case 32: alignbits = 0x3; break; | |
17636 | default: ; | |
17637 | } | |
17638 | inst.instruction |= alignbits << 4; | |
17639 | } | |
5287ad62 JB |
17640 | break; |
17641 | ||
17642 | case 1: /* VLD2 / VST2. */ | |
aa8a0863 TS |
17643 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16, |
17644 | 16, 32, 32, 64, -1); | |
5287ad62 | 17645 | if (align_good == FAIL) |
477330fc | 17646 | return; |
aa8a0863 | 17647 | if (do_alignment) |
477330fc | 17648 | inst.instruction |= 1 << 4; |
5287ad62 JB |
17649 | break; |
17650 | ||
17651 | case 2: /* VLD3 / VST3. */ | |
17652 | constraint (inst.operands[1].immisalign, | |
477330fc | 17653 | _("can't use alignment with this instruction")); |
5287ad62 JB |
17654 | break; |
17655 | ||
17656 | case 3: /* VLD4 / VST4. */ | |
aa8a0863 | 17657 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32, |
477330fc | 17658 | 16, 64, 32, 64, 32, 128, -1); |
5287ad62 | 17659 | if (align_good == FAIL) |
477330fc | 17660 | return; |
aa8a0863 | 17661 | if (do_alignment) |
477330fc RM |
17662 | { |
17663 | unsigned alignbits = 0; | |
17664 | switch (et.size) | |
17665 | { | |
17666 | case 8: alignbits = 0x1; break; | |
17667 | case 16: alignbits = 0x1; break; | |
17668 | case 32: alignbits = (align == 64) ? 0x1 : 0x2; break; | |
17669 | default: ; | |
17670 | } | |
17671 | inst.instruction |= alignbits << 4; | |
17672 | } | |
5287ad62 JB |
17673 | break; |
17674 | ||
17675 | default: ; | |
17676 | } | |
17677 | ||
17678 | /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */ | |
17679 | if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
17680 | inst.instruction |= 1 << (4 + logsize); | |
5f4273c7 | 17681 | |
5287ad62 JB |
17682 | inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5); |
17683 | inst.instruction |= logsize << 10; | |
17684 | } | |
17685 | ||
17686 | /* Encode single n-element structure to all lanes VLD<n> instructions. */ | |
17687 | ||
17688 | static void | |
17689 | do_neon_ld_dup (void) | |
17690 | { | |
037e8744 | 17691 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
aa8a0863 | 17692 | int align_good, do_alignment = 0; |
5287ad62 | 17693 | |
dcbf9037 JB |
17694 | if (et.type == NT_invtype) |
17695 | return; | |
17696 | ||
5287ad62 JB |
17697 | switch ((inst.instruction >> 8) & 3) |
17698 | { | |
17699 | case 0: /* VLD1. */ | |
9c2799c2 | 17700 | gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2); |
5287ad62 | 17701 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, |
aa8a0863 | 17702 | &do_alignment, 16, 16, 32, 32, -1); |
5287ad62 | 17703 | if (align_good == FAIL) |
477330fc | 17704 | return; |
5287ad62 | 17705 | switch (NEON_REGLIST_LENGTH (inst.operands[0].imm)) |
477330fc RM |
17706 | { |
17707 | case 1: break; | |
17708 | case 2: inst.instruction |= 1 << 5; break; | |
17709 | default: first_error (_("bad list length")); return; | |
17710 | } | |
5287ad62 JB |
17711 | inst.instruction |= neon_logbits (et.size) << 6; |
17712 | break; | |
17713 | ||
17714 | case 1: /* VLD2. */ | |
17715 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
aa8a0863 TS |
17716 | &do_alignment, 8, 16, 16, 32, 32, 64, |
17717 | -1); | |
5287ad62 | 17718 | if (align_good == FAIL) |
477330fc | 17719 | return; |
5287ad62 | 17720 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2, |
477330fc | 17721 | _("bad list length")); |
5287ad62 | 17722 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) |
477330fc | 17723 | inst.instruction |= 1 << 5; |
5287ad62 JB |
17724 | inst.instruction |= neon_logbits (et.size) << 6; |
17725 | break; | |
17726 | ||
17727 | case 2: /* VLD3. */ | |
17728 | constraint (inst.operands[1].immisalign, | |
477330fc | 17729 | _("can't use alignment with this instruction")); |
5287ad62 | 17730 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3, |
477330fc | 17731 | _("bad list length")); |
5287ad62 | 17732 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) |
477330fc | 17733 | inst.instruction |= 1 << 5; |
5287ad62 JB |
17734 | inst.instruction |= neon_logbits (et.size) << 6; |
17735 | break; | |
17736 | ||
17737 | case 3: /* VLD4. */ | |
17738 | { | |
477330fc | 17739 | int align = inst.operands[1].imm >> 8; |
aa8a0863 | 17740 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32, |
477330fc RM |
17741 | 16, 64, 32, 64, 32, 128, -1); |
17742 | if (align_good == FAIL) | |
17743 | return; | |
17744 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4, | |
17745 | _("bad list length")); | |
17746 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
17747 | inst.instruction |= 1 << 5; | |
17748 | if (et.size == 32 && align == 128) | |
17749 | inst.instruction |= 0x3 << 6; | |
17750 | else | |
17751 | inst.instruction |= neon_logbits (et.size) << 6; | |
5287ad62 JB |
17752 | } |
17753 | break; | |
17754 | ||
17755 | default: ; | |
17756 | } | |
17757 | ||
aa8a0863 | 17758 | inst.instruction |= do_alignment << 4; |
5287ad62 JB |
17759 | } |
17760 | ||
17761 | /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those | |
17762 | apart from bits [11:4]. */ | |
17763 | ||
17764 | static void | |
17765 | do_neon_ldx_stx (void) | |
17766 | { | |
b1a769ed DG |
17767 | if (inst.operands[1].isreg) |
17768 | constraint (inst.operands[1].reg == REG_PC, BAD_PC); | |
17769 | ||
5287ad62 JB |
17770 | switch (NEON_LANE (inst.operands[0].imm)) |
17771 | { | |
17772 | case NEON_INTERLEAVE_LANES: | |
88714cb8 | 17773 | NEON_ENCODE (INTERLV, inst); |
5287ad62 JB |
17774 | do_neon_ld_st_interleave (); |
17775 | break; | |
5f4273c7 | 17776 | |
5287ad62 | 17777 | case NEON_ALL_LANES: |
88714cb8 | 17778 | NEON_ENCODE (DUP, inst); |
2d51fb74 JB |
17779 | if (inst.instruction == N_INV) |
17780 | { | |
17781 | first_error ("only loads support such operands"); | |
17782 | break; | |
17783 | } | |
5287ad62 JB |
17784 | do_neon_ld_dup (); |
17785 | break; | |
5f4273c7 | 17786 | |
5287ad62 | 17787 | default: |
88714cb8 | 17788 | NEON_ENCODE (LANE, inst); |
5287ad62 JB |
17789 | do_neon_ld_st_lane (); |
17790 | } | |
17791 | ||
17792 | /* L bit comes from bit mask. */ | |
17793 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17794 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17795 | inst.instruction |= inst.operands[1].reg << 16; | |
5f4273c7 | 17796 | |
5287ad62 JB |
17797 | if (inst.operands[1].postind) |
17798 | { | |
17799 | int postreg = inst.operands[1].imm & 0xf; | |
17800 | constraint (!inst.operands[1].immisreg, | |
477330fc | 17801 | _("post-index must be a register")); |
5287ad62 | 17802 | constraint (postreg == 0xd || postreg == 0xf, |
477330fc | 17803 | _("bad register for post-index")); |
5287ad62 JB |
17804 | inst.instruction |= postreg; |
17805 | } | |
4f2374c7 | 17806 | else |
5287ad62 | 17807 | { |
4f2374c7 | 17808 | constraint (inst.operands[1].immisreg, BAD_ADDR_MODE); |
e2b0ab59 AV |
17809 | constraint (inst.relocs[0].exp.X_op != O_constant |
17810 | || inst.relocs[0].exp.X_add_number != 0, | |
4f2374c7 WN |
17811 | BAD_ADDR_MODE); |
17812 | ||
17813 | if (inst.operands[1].writeback) | |
17814 | { | |
17815 | inst.instruction |= 0xd; | |
17816 | } | |
17817 | else | |
17818 | inst.instruction |= 0xf; | |
5287ad62 | 17819 | } |
5f4273c7 | 17820 | |
5287ad62 JB |
17821 | if (thumb_mode) |
17822 | inst.instruction |= 0xf9000000; | |
17823 | else | |
17824 | inst.instruction |= 0xf4000000; | |
17825 | } | |
33399f07 MGD |
17826 | |
17827 | /* FP v8. */ | |
17828 | static void | |
17829 | do_vfp_nsyn_fpv8 (enum neon_shape rs) | |
17830 | { | |
a715796b TG |
17831 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
17832 | D register operands. */ | |
17833 | if (neon_shape_class[rs] == SC_DOUBLE) | |
17834 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
17835 | _(BAD_FPU)); | |
17836 | ||
33399f07 MGD |
17837 | NEON_ENCODE (FPV8, inst); |
17838 | ||
9db2f6b4 RL |
17839 | if (rs == NS_FFF || rs == NS_HHH) |
17840 | { | |
17841 | do_vfp_sp_dyadic (); | |
17842 | ||
17843 | /* ARMv8.2 fp16 instruction. */ | |
17844 | if (rs == NS_HHH) | |
17845 | do_scalar_fp16_v82_encode (); | |
17846 | } | |
33399f07 MGD |
17847 | else |
17848 | do_vfp_dp_rd_rn_rm (); | |
17849 | ||
17850 | if (rs == NS_DDD) | |
17851 | inst.instruction |= 0x100; | |
17852 | ||
17853 | inst.instruction |= 0xf0000000; | |
17854 | } | |
17855 | ||
17856 | static void | |
17857 | do_vsel (void) | |
17858 | { | |
17859 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17860 | ||
17861 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS) | |
17862 | first_error (_("invalid instruction shape")); | |
17863 | } | |
17864 | ||
73924fbc MGD |
17865 | static void |
17866 | do_vmaxnm (void) | |
17867 | { | |
17868 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17869 | ||
17870 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS) | |
17871 | return; | |
17872 | ||
17873 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
17874 | return; | |
17875 | ||
cc933301 | 17876 | neon_dyadic_misc (NT_untyped, N_F_16_32, 0); |
73924fbc MGD |
17877 | } |
17878 | ||
30bdf752 MGD |
17879 | static void |
17880 | do_vrint_1 (enum neon_cvt_mode mode) | |
17881 | { | |
9db2f6b4 | 17882 | enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL); |
30bdf752 MGD |
17883 | struct neon_type_el et; |
17884 | ||
17885 | if (rs == NS_NULL) | |
17886 | return; | |
17887 | ||
a715796b TG |
17888 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
17889 | D register operands. */ | |
17890 | if (neon_shape_class[rs] == SC_DOUBLE) | |
17891 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
17892 | _(BAD_FPU)); | |
17893 | ||
9db2f6b4 RL |
17894 | et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY |
17895 | | N_VFP); | |
30bdf752 MGD |
17896 | if (et.type != NT_invtype) |
17897 | { | |
17898 | /* VFP encodings. */ | |
17899 | if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n | |
17900 | || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m) | |
17901 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17902 | ||
17903 | NEON_ENCODE (FPV8, inst); | |
9db2f6b4 | 17904 | if (rs == NS_FF || rs == NS_HH) |
30bdf752 MGD |
17905 | do_vfp_sp_monadic (); |
17906 | else | |
17907 | do_vfp_dp_rd_rm (); | |
17908 | ||
17909 | switch (mode) | |
17910 | { | |
17911 | case neon_cvt_mode_r: inst.instruction |= 0x00000000; break; | |
17912 | case neon_cvt_mode_z: inst.instruction |= 0x00000080; break; | |
17913 | case neon_cvt_mode_x: inst.instruction |= 0x00010000; break; | |
17914 | case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break; | |
17915 | case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break; | |
17916 | case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break; | |
17917 | case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break; | |
17918 | default: abort (); | |
17919 | } | |
17920 | ||
17921 | inst.instruction |= (rs == NS_DD) << 8; | |
17922 | do_vfp_cond_or_thumb (); | |
9db2f6b4 RL |
17923 | |
17924 | /* ARMv8.2 fp16 vrint instruction. */ | |
17925 | if (rs == NS_HH) | |
17926 | do_scalar_fp16_v82_encode (); | |
30bdf752 MGD |
17927 | } |
17928 | else | |
17929 | { | |
17930 | /* Neon encodings (or something broken...). */ | |
17931 | inst.error = NULL; | |
cc933301 | 17932 | et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY); |
30bdf752 MGD |
17933 | |
17934 | if (et.type == NT_invtype) | |
17935 | return; | |
17936 | ||
17937 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17938 | NEON_ENCODE (FLOAT, inst); | |
17939 | ||
17940 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
17941 | return; | |
17942 | ||
17943 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17944 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17945 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
17946 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
17947 | inst.instruction |= neon_quad (rs) << 6; | |
cc933301 JW |
17948 | /* Mask off the original size bits and reencode them. */ |
17949 | inst.instruction = ((inst.instruction & 0xfff3ffff) | |
17950 | | neon_logbits (et.size) << 18); | |
17951 | ||
30bdf752 MGD |
17952 | switch (mode) |
17953 | { | |
17954 | case neon_cvt_mode_z: inst.instruction |= 3 << 7; break; | |
17955 | case neon_cvt_mode_x: inst.instruction |= 1 << 7; break; | |
17956 | case neon_cvt_mode_a: inst.instruction |= 2 << 7; break; | |
17957 | case neon_cvt_mode_n: inst.instruction |= 0 << 7; break; | |
17958 | case neon_cvt_mode_p: inst.instruction |= 7 << 7; break; | |
17959 | case neon_cvt_mode_m: inst.instruction |= 5 << 7; break; | |
17960 | case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break; | |
17961 | default: abort (); | |
17962 | } | |
17963 | ||
17964 | if (thumb_mode) | |
17965 | inst.instruction |= 0xfc000000; | |
17966 | else | |
17967 | inst.instruction |= 0xf0000000; | |
17968 | } | |
17969 | } | |
17970 | ||
17971 | static void | |
17972 | do_vrintx (void) | |
17973 | { | |
17974 | do_vrint_1 (neon_cvt_mode_x); | |
17975 | } | |
17976 | ||
17977 | static void | |
17978 | do_vrintz (void) | |
17979 | { | |
17980 | do_vrint_1 (neon_cvt_mode_z); | |
17981 | } | |
17982 | ||
17983 | static void | |
17984 | do_vrintr (void) | |
17985 | { | |
17986 | do_vrint_1 (neon_cvt_mode_r); | |
17987 | } | |
17988 | ||
17989 | static void | |
17990 | do_vrinta (void) | |
17991 | { | |
17992 | do_vrint_1 (neon_cvt_mode_a); | |
17993 | } | |
17994 | ||
17995 | static void | |
17996 | do_vrintn (void) | |
17997 | { | |
17998 | do_vrint_1 (neon_cvt_mode_n); | |
17999 | } | |
18000 | ||
18001 | static void | |
18002 | do_vrintp (void) | |
18003 | { | |
18004 | do_vrint_1 (neon_cvt_mode_p); | |
18005 | } | |
18006 | ||
18007 | static void | |
18008 | do_vrintm (void) | |
18009 | { | |
18010 | do_vrint_1 (neon_cvt_mode_m); | |
18011 | } | |
18012 | ||
c28eeff2 SN |
18013 | static unsigned |
18014 | neon_scalar_for_vcmla (unsigned opnd, unsigned elsize) | |
18015 | { | |
18016 | unsigned regno = NEON_SCALAR_REG (opnd); | |
18017 | unsigned elno = NEON_SCALAR_INDEX (opnd); | |
18018 | ||
18019 | if (elsize == 16 && elno < 2 && regno < 16) | |
18020 | return regno | (elno << 4); | |
18021 | else if (elsize == 32 && elno == 0) | |
18022 | return regno; | |
18023 | ||
18024 | first_error (_("scalar out of range")); | |
18025 | return 0; | |
18026 | } | |
18027 | ||
18028 | static void | |
18029 | do_vcmla (void) | |
18030 | { | |
18031 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8), | |
18032 | _(BAD_FPU)); | |
e2b0ab59 AV |
18033 | constraint (inst.relocs[0].exp.X_op != O_constant, |
18034 | _("expression too complex")); | |
18035 | unsigned rot = inst.relocs[0].exp.X_add_number; | |
c28eeff2 SN |
18036 | constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270, |
18037 | _("immediate out of range")); | |
18038 | rot /= 90; | |
18039 | if (inst.operands[2].isscalar) | |
18040 | { | |
18041 | enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL); | |
18042 | unsigned size = neon_check_type (3, rs, N_EQK, N_EQK, | |
18043 | N_KEY | N_F16 | N_F32).size; | |
18044 | unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size); | |
18045 | inst.is_neon = 1; | |
18046 | inst.instruction = 0xfe000800; | |
18047 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
18048 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
18049 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
18050 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
18051 | inst.instruction |= LOW4 (m); | |
18052 | inst.instruction |= HI1 (m) << 5; | |
18053 | inst.instruction |= neon_quad (rs) << 6; | |
18054 | inst.instruction |= rot << 20; | |
18055 | inst.instruction |= (size == 32) << 23; | |
18056 | } | |
18057 | else | |
18058 | { | |
18059 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); | |
18060 | unsigned size = neon_check_type (3, rs, N_EQK, N_EQK, | |
18061 | N_KEY | N_F16 | N_F32).size; | |
18062 | neon_three_same (neon_quad (rs), 0, -1); | |
18063 | inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */ | |
18064 | inst.instruction |= 0xfc200800; | |
18065 | inst.instruction |= rot << 23; | |
18066 | inst.instruction |= (size == 32) << 20; | |
18067 | } | |
18068 | } | |
18069 | ||
18070 | static void | |
18071 | do_vcadd (void) | |
18072 | { | |
18073 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8), | |
18074 | _(BAD_FPU)); | |
e2b0ab59 AV |
18075 | constraint (inst.relocs[0].exp.X_op != O_constant, |
18076 | _("expression too complex")); | |
18077 | unsigned rot = inst.relocs[0].exp.X_add_number; | |
c28eeff2 SN |
18078 | constraint (rot != 90 && rot != 270, _("immediate out of range")); |
18079 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); | |
18080 | unsigned size = neon_check_type (3, rs, N_EQK, N_EQK, | |
18081 | N_KEY | N_F16 | N_F32).size; | |
18082 | neon_three_same (neon_quad (rs), 0, -1); | |
18083 | inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */ | |
18084 | inst.instruction |= 0xfc800800; | |
18085 | inst.instruction |= (rot == 270) << 24; | |
18086 | inst.instruction |= (size == 32) << 20; | |
18087 | } | |
18088 | ||
c604a79a JW |
18089 | /* Dot Product instructions encoding support. */ |
18090 | ||
18091 | static void | |
18092 | do_neon_dotproduct (int unsigned_p) | |
18093 | { | |
18094 | enum neon_shape rs; | |
18095 | unsigned scalar_oprd2 = 0; | |
18096 | int high8; | |
18097 | ||
18098 | if (inst.cond != COND_ALWAYS) | |
18099 | as_warn (_("Dot Product instructions cannot be conditional, the behaviour " | |
18100 | "is UNPREDICTABLE")); | |
18101 | ||
18102 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8), | |
18103 | _(BAD_FPU)); | |
18104 | ||
18105 | /* Dot Product instructions are in three-same D/Q register format or the third | |
18106 | operand can be a scalar index register. */ | |
18107 | if (inst.operands[2].isscalar) | |
18108 | { | |
18109 | scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32); | |
18110 | high8 = 0xfe000000; | |
18111 | rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); | |
18112 | } | |
18113 | else | |
18114 | { | |
18115 | high8 = 0xfc000000; | |
18116 | rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
18117 | } | |
18118 | ||
18119 | if (unsigned_p) | |
18120 | neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8); | |
18121 | else | |
18122 | neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8); | |
18123 | ||
18124 | /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot | |
18125 | Product instruction, so we pass 0 as the "ubit" parameter. And the | |
18126 | "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */ | |
18127 | neon_three_same (neon_quad (rs), 0, 32); | |
18128 | ||
18129 | /* Undo neon_dp_fixup. Dot Product instructions are using a slightly | |
18130 | different NEON three-same encoding. */ | |
18131 | inst.instruction &= 0x00ffffff; | |
18132 | inst.instruction |= high8; | |
18133 | /* Encode 'U' bit which indicates signedness. */ | |
18134 | inst.instruction |= (unsigned_p ? 1 : 0) << 4; | |
18135 | /* Re-encode operand2 if it's indexed scalar operand. What has been encoded | |
18136 | from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not | |
18137 | the instruction encoding. */ | |
18138 | if (inst.operands[2].isscalar) | |
18139 | { | |
18140 | inst.instruction &= 0xffffffd0; | |
18141 | inst.instruction |= LOW4 (scalar_oprd2); | |
18142 | inst.instruction |= HI1 (scalar_oprd2) << 5; | |
18143 | } | |
18144 | } | |
18145 | ||
18146 | /* Dot Product instructions for signed integer. */ | |
18147 | ||
18148 | static void | |
18149 | do_neon_dotproduct_s (void) | |
18150 | { | |
18151 | return do_neon_dotproduct (0); | |
18152 | } | |
18153 | ||
18154 | /* Dot Product instructions for unsigned integer. */ | |
18155 | ||
18156 | static void | |
18157 | do_neon_dotproduct_u (void) | |
18158 | { | |
18159 | return do_neon_dotproduct (1); | |
18160 | } | |
18161 | ||
91ff7894 MGD |
18162 | /* Crypto v1 instructions. */ |
18163 | static void | |
18164 | do_crypto_2op_1 (unsigned elttype, int op) | |
18165 | { | |
18166 | set_it_insn_type (OUTSIDE_IT_INSN); | |
18167 | ||
18168 | if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type | |
18169 | == NT_invtype) | |
18170 | return; | |
18171 | ||
18172 | inst.error = NULL; | |
18173 | ||
18174 | NEON_ENCODE (INTEGER, inst); | |
18175 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
18176 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
18177 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
18178 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
18179 | if (op != -1) | |
18180 | inst.instruction |= op << 6; | |
18181 | ||
18182 | if (thumb_mode) | |
18183 | inst.instruction |= 0xfc000000; | |
18184 | else | |
18185 | inst.instruction |= 0xf0000000; | |
18186 | } | |
18187 | ||
48adcd8e MGD |
18188 | static void |
18189 | do_crypto_3op_1 (int u, int op) | |
18190 | { | |
18191 | set_it_insn_type (OUTSIDE_IT_INSN); | |
18192 | ||
18193 | if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT, | |
18194 | N_32 | N_UNT | N_KEY).type == NT_invtype) | |
18195 | return; | |
18196 | ||
18197 | inst.error = NULL; | |
18198 | ||
18199 | NEON_ENCODE (INTEGER, inst); | |
18200 | neon_three_same (1, u, 8 << op); | |
18201 | } | |
18202 | ||
91ff7894 MGD |
18203 | static void |
18204 | do_aese (void) | |
18205 | { | |
18206 | do_crypto_2op_1 (N_8, 0); | |
18207 | } | |
18208 | ||
18209 | static void | |
18210 | do_aesd (void) | |
18211 | { | |
18212 | do_crypto_2op_1 (N_8, 1); | |
18213 | } | |
18214 | ||
18215 | static void | |
18216 | do_aesmc (void) | |
18217 | { | |
18218 | do_crypto_2op_1 (N_8, 2); | |
18219 | } | |
18220 | ||
18221 | static void | |
18222 | do_aesimc (void) | |
18223 | { | |
18224 | do_crypto_2op_1 (N_8, 3); | |
18225 | } | |
18226 | ||
48adcd8e MGD |
18227 | static void |
18228 | do_sha1c (void) | |
18229 | { | |
18230 | do_crypto_3op_1 (0, 0); | |
18231 | } | |
18232 | ||
18233 | static void | |
18234 | do_sha1p (void) | |
18235 | { | |
18236 | do_crypto_3op_1 (0, 1); | |
18237 | } | |
18238 | ||
18239 | static void | |
18240 | do_sha1m (void) | |
18241 | { | |
18242 | do_crypto_3op_1 (0, 2); | |
18243 | } | |
18244 | ||
18245 | static void | |
18246 | do_sha1su0 (void) | |
18247 | { | |
18248 | do_crypto_3op_1 (0, 3); | |
18249 | } | |
91ff7894 | 18250 | |
48adcd8e MGD |
18251 | static void |
18252 | do_sha256h (void) | |
18253 | { | |
18254 | do_crypto_3op_1 (1, 0); | |
18255 | } | |
18256 | ||
18257 | static void | |
18258 | do_sha256h2 (void) | |
18259 | { | |
18260 | do_crypto_3op_1 (1, 1); | |
18261 | } | |
18262 | ||
18263 | static void | |
18264 | do_sha256su1 (void) | |
18265 | { | |
18266 | do_crypto_3op_1 (1, 2); | |
18267 | } | |
3c9017d2 MGD |
18268 | |
18269 | static void | |
18270 | do_sha1h (void) | |
18271 | { | |
18272 | do_crypto_2op_1 (N_32, -1); | |
18273 | } | |
18274 | ||
18275 | static void | |
18276 | do_sha1su1 (void) | |
18277 | { | |
18278 | do_crypto_2op_1 (N_32, 0); | |
18279 | } | |
18280 | ||
18281 | static void | |
18282 | do_sha256su0 (void) | |
18283 | { | |
18284 | do_crypto_2op_1 (N_32, 1); | |
18285 | } | |
dd5181d5 KT |
18286 | |
18287 | static void | |
18288 | do_crc32_1 (unsigned int poly, unsigned int sz) | |
18289 | { | |
18290 | unsigned int Rd = inst.operands[0].reg; | |
18291 | unsigned int Rn = inst.operands[1].reg; | |
18292 | unsigned int Rm = inst.operands[2].reg; | |
18293 | ||
18294 | set_it_insn_type (OUTSIDE_IT_INSN); | |
18295 | inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12); | |
18296 | inst.instruction |= LOW4 (Rn) << 16; | |
18297 | inst.instruction |= LOW4 (Rm); | |
18298 | inst.instruction |= sz << (thumb_mode ? 4 : 21); | |
18299 | inst.instruction |= poly << (thumb_mode ? 20 : 9); | |
18300 | ||
18301 | if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC) | |
18302 | as_warn (UNPRED_REG ("r15")); | |
dd5181d5 KT |
18303 | } |
18304 | ||
18305 | static void | |
18306 | do_crc32b (void) | |
18307 | { | |
18308 | do_crc32_1 (0, 0); | |
18309 | } | |
18310 | ||
18311 | static void | |
18312 | do_crc32h (void) | |
18313 | { | |
18314 | do_crc32_1 (0, 1); | |
18315 | } | |
18316 | ||
18317 | static void | |
18318 | do_crc32w (void) | |
18319 | { | |
18320 | do_crc32_1 (0, 2); | |
18321 | } | |
18322 | ||
18323 | static void | |
18324 | do_crc32cb (void) | |
18325 | { | |
18326 | do_crc32_1 (1, 0); | |
18327 | } | |
18328 | ||
18329 | static void | |
18330 | do_crc32ch (void) | |
18331 | { | |
18332 | do_crc32_1 (1, 1); | |
18333 | } | |
18334 | ||
18335 | static void | |
18336 | do_crc32cw (void) | |
18337 | { | |
18338 | do_crc32_1 (1, 2); | |
18339 | } | |
18340 | ||
49e8a725 SN |
18341 | static void |
18342 | do_vjcvt (void) | |
18343 | { | |
18344 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
18345 | _(BAD_FPU)); | |
18346 | neon_check_type (2, NS_FD, N_S32, N_F64); | |
18347 | do_vfp_sp_dp_cvt (); | |
18348 | do_vfp_cond_or_thumb (); | |
18349 | } | |
18350 | ||
5287ad62 JB |
18351 | \f |
18352 | /* Overall per-instruction processing. */ | |
18353 | ||
18354 | /* We need to be able to fix up arbitrary expressions in some statements. | |
18355 | This is so that we can handle symbols that are an arbitrary distance from | |
18356 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
18357 | which returns part of an address in a form which will be valid for | |
18358 | a data instruction. We do this by pushing the expression into a symbol | |
18359 | in the expr_section, and creating a fix for that. */ | |
18360 | ||
18361 | static void | |
18362 | fix_new_arm (fragS * frag, | |
18363 | int where, | |
18364 | short int size, | |
18365 | expressionS * exp, | |
18366 | int pc_rel, | |
18367 | int reloc) | |
18368 | { | |
18369 | fixS * new_fix; | |
18370 | ||
18371 | switch (exp->X_op) | |
18372 | { | |
18373 | case O_constant: | |
6e7ce2cd PB |
18374 | if (pc_rel) |
18375 | { | |
18376 | /* Create an absolute valued symbol, so we have something to | |
477330fc RM |
18377 | refer to in the object file. Unfortunately for us, gas's |
18378 | generic expression parsing will already have folded out | |
18379 | any use of .set foo/.type foo %function that may have | |
18380 | been used to set type information of the target location, | |
18381 | that's being specified symbolically. We have to presume | |
18382 | the user knows what they are doing. */ | |
6e7ce2cd PB |
18383 | char name[16 + 8]; |
18384 | symbolS *symbol; | |
18385 | ||
18386 | sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number); | |
18387 | ||
18388 | symbol = symbol_find_or_make (name); | |
18389 | S_SET_SEGMENT (symbol, absolute_section); | |
18390 | symbol_set_frag (symbol, &zero_address_frag); | |
18391 | S_SET_VALUE (symbol, exp->X_add_number); | |
18392 | exp->X_op = O_symbol; | |
18393 | exp->X_add_symbol = symbol; | |
18394 | exp->X_add_number = 0; | |
18395 | } | |
18396 | /* FALLTHROUGH */ | |
5287ad62 JB |
18397 | case O_symbol: |
18398 | case O_add: | |
18399 | case O_subtract: | |
21d799b5 | 18400 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, |
477330fc | 18401 | (enum bfd_reloc_code_real) reloc); |
5287ad62 JB |
18402 | break; |
18403 | ||
18404 | default: | |
21d799b5 | 18405 | new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0, |
477330fc | 18406 | pc_rel, (enum bfd_reloc_code_real) reloc); |
5287ad62 JB |
18407 | break; |
18408 | } | |
18409 | ||
18410 | /* Mark whether the fix is to a THUMB instruction, or an ARM | |
18411 | instruction. */ | |
18412 | new_fix->tc_fix_data = thumb_mode; | |
18413 | } | |
18414 | ||
18415 | /* Create a frg for an instruction requiring relaxation. */ | |
18416 | static void | |
18417 | output_relax_insn (void) | |
18418 | { | |
18419 | char * to; | |
18420 | symbolS *sym; | |
0110f2b8 PB |
18421 | int offset; |
18422 | ||
6e1cb1a6 PB |
18423 | /* The size of the instruction is unknown, so tie the debug info to the |
18424 | start of the instruction. */ | |
18425 | dwarf2_emit_insn (0); | |
6e1cb1a6 | 18426 | |
e2b0ab59 | 18427 | switch (inst.relocs[0].exp.X_op) |
0110f2b8 PB |
18428 | { |
18429 | case O_symbol: | |
e2b0ab59 AV |
18430 | sym = inst.relocs[0].exp.X_add_symbol; |
18431 | offset = inst.relocs[0].exp.X_add_number; | |
0110f2b8 PB |
18432 | break; |
18433 | case O_constant: | |
18434 | sym = NULL; | |
e2b0ab59 | 18435 | offset = inst.relocs[0].exp.X_add_number; |
0110f2b8 PB |
18436 | break; |
18437 | default: | |
e2b0ab59 | 18438 | sym = make_expr_symbol (&inst.relocs[0].exp); |
0110f2b8 PB |
18439 | offset = 0; |
18440 | break; | |
18441 | } | |
18442 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
18443 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
18444 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
0110f2b8 PB |
18445 | } |
18446 | ||
18447 | /* Write a 32-bit thumb instruction to buf. */ | |
18448 | static void | |
18449 | put_thumb32_insn (char * buf, unsigned long insn) | |
18450 | { | |
18451 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
18452 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
18453 | } | |
18454 | ||
b99bd4ef | 18455 | static void |
c19d1205 | 18456 | output_inst (const char * str) |
b99bd4ef | 18457 | { |
c19d1205 | 18458 | char * to = NULL; |
b99bd4ef | 18459 | |
c19d1205 | 18460 | if (inst.error) |
b99bd4ef | 18461 | { |
c19d1205 | 18462 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
18463 | return; |
18464 | } | |
5f4273c7 NC |
18465 | if (inst.relax) |
18466 | { | |
18467 | output_relax_insn (); | |
0110f2b8 | 18468 | return; |
5f4273c7 | 18469 | } |
c19d1205 ZW |
18470 | if (inst.size == 0) |
18471 | return; | |
b99bd4ef | 18472 | |
c19d1205 | 18473 | to = frag_more (inst.size); |
8dc2430f NC |
18474 | /* PR 9814: Record the thumb mode into the current frag so that we know |
18475 | what type of NOP padding to use, if necessary. We override any previous | |
18476 | setting so that if the mode has changed then the NOPS that we use will | |
18477 | match the encoding of the last instruction in the frag. */ | |
cd000bff | 18478 | frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
c19d1205 ZW |
18479 | |
18480 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 18481 | { |
9c2799c2 | 18482 | gas_assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 18483 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 18484 | } |
c19d1205 | 18485 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 18486 | { |
9c2799c2 | 18487 | gas_assert (inst.size == (2 * INSN_SIZE)); |
c19d1205 ZW |
18488 | md_number_to_chars (to, inst.instruction, INSN_SIZE); |
18489 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 18490 | } |
c19d1205 ZW |
18491 | else |
18492 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 18493 | |
e2b0ab59 AV |
18494 | int r; |
18495 | for (r = 0; r < ARM_IT_MAX_RELOCS; r++) | |
18496 | { | |
18497 | if (inst.relocs[r].type != BFD_RELOC_UNUSED) | |
18498 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
18499 | inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel, | |
18500 | inst.relocs[r].type); | |
18501 | } | |
b99bd4ef | 18502 | |
c19d1205 | 18503 | dwarf2_emit_insn (inst.size); |
c19d1205 | 18504 | } |
b99bd4ef | 18505 | |
e07e6e58 NC |
18506 | static char * |
18507 | output_it_inst (int cond, int mask, char * to) | |
18508 | { | |
18509 | unsigned long instruction = 0xbf00; | |
18510 | ||
18511 | mask &= 0xf; | |
18512 | instruction |= mask; | |
18513 | instruction |= cond << 4; | |
18514 | ||
18515 | if (to == NULL) | |
18516 | { | |
18517 | to = frag_more (2); | |
18518 | #ifdef OBJ_ELF | |
18519 | dwarf2_emit_insn (2); | |
18520 | #endif | |
18521 | } | |
18522 | ||
18523 | md_number_to_chars (to, instruction, 2); | |
18524 | ||
18525 | return to; | |
18526 | } | |
18527 | ||
c19d1205 ZW |
18528 | /* Tag values used in struct asm_opcode's tag field. */ |
18529 | enum opcode_tag | |
18530 | { | |
18531 | OT_unconditional, /* Instruction cannot be conditionalized. | |
18532 | The ARM condition field is still 0xE. */ | |
18533 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
18534 | and carries 0xF in its ARM condition field. */ | |
18535 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
037e8744 | 18536 | OT_csuffixF, /* Some forms of the instruction take a conditional |
477330fc RM |
18537 | suffix, others place 0xF where the condition field |
18538 | would be. */ | |
c19d1205 ZW |
18539 | OT_cinfix3, /* Instruction takes a conditional infix, |
18540 | beginning at character index 3. (In | |
18541 | unified mode, it becomes a suffix.) */ | |
088fa78e KH |
18542 | OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for |
18543 | tsts, cmps, cmns, and teqs. */ | |
e3cb604e PB |
18544 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
18545 | character index 3, even in unified mode. Used for | |
18546 | legacy instructions where suffix and infix forms | |
18547 | may be ambiguous. */ | |
c19d1205 | 18548 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 18549 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
18550 | OT_odd_infix_unc, /* This is the unconditional variant of an |
18551 | instruction that takes a conditional infix | |
18552 | at an unusual position. In unified mode, | |
18553 | this variant will accept a suffix. */ | |
18554 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
18555 | are the conditional variants of instructions that | |
18556 | take conditional infixes in unusual positions. | |
18557 | The infix appears at character index | |
18558 | (tag - OT_odd_infix_0). These are not accepted | |
18559 | in unified mode. */ | |
18560 | }; | |
b99bd4ef | 18561 | |
c19d1205 ZW |
18562 | /* Subroutine of md_assemble, responsible for looking up the primary |
18563 | opcode from the mnemonic the user wrote. STR points to the | |
18564 | beginning of the mnemonic. | |
18565 | ||
18566 | This is not simply a hash table lookup, because of conditional | |
18567 | variants. Most instructions have conditional variants, which are | |
18568 | expressed with a _conditional affix_ to the mnemonic. If we were | |
18569 | to encode each conditional variant as a literal string in the opcode | |
18570 | table, it would have approximately 20,000 entries. | |
18571 | ||
18572 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
18573 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
18574 | instructions take the affix as an infix, notably the s-variants of | |
18575 | the arithmetic instructions. Of those instructions, all but six | |
18576 | have the infix appear after the third character of the mnemonic. | |
18577 | ||
18578 | Accordingly, the algorithm for looking up primary opcodes given | |
18579 | an identifier is: | |
18580 | ||
18581 | 1. Look up the identifier in the opcode table. | |
18582 | If we find a match, go to step U. | |
18583 | ||
18584 | 2. Look up the last two characters of the identifier in the | |
18585 | conditions table. If we find a match, look up the first N-2 | |
18586 | characters of the identifier in the opcode table. If we | |
18587 | find a match, go to step CE. | |
18588 | ||
18589 | 3. Look up the fourth and fifth characters of the identifier in | |
18590 | the conditions table. If we find a match, extract those | |
18591 | characters from the identifier, and look up the remaining | |
18592 | characters in the opcode table. If we find a match, go | |
18593 | to step CM. | |
18594 | ||
18595 | 4. Fail. | |
18596 | ||
18597 | U. Examine the tag field of the opcode structure, in case this is | |
18598 | one of the six instructions with its conditional infix in an | |
18599 | unusual place. If it is, the tag tells us where to find the | |
18600 | infix; look it up in the conditions table and set inst.cond | |
18601 | accordingly. Otherwise, this is an unconditional instruction. | |
18602 | Again set inst.cond accordingly. Return the opcode structure. | |
18603 | ||
18604 | CE. Examine the tag field to make sure this is an instruction that | |
18605 | should receive a conditional suffix. If it is not, fail. | |
18606 | Otherwise, set inst.cond from the suffix we already looked up, | |
18607 | and return the opcode structure. | |
18608 | ||
18609 | CM. Examine the tag field to make sure this is an instruction that | |
18610 | should receive a conditional infix after the third character. | |
18611 | If it is not, fail. Otherwise, undo the edits to the current | |
18612 | line of input and proceed as for case CE. */ | |
18613 | ||
18614 | static const struct asm_opcode * | |
18615 | opcode_lookup (char **str) | |
18616 | { | |
18617 | char *end, *base; | |
18618 | char *affix; | |
18619 | const struct asm_opcode *opcode; | |
18620 | const struct asm_cond *cond; | |
e3cb604e | 18621 | char save[2]; |
c19d1205 ZW |
18622 | |
18623 | /* Scan up to the end of the mnemonic, which must end in white space, | |
721a8186 | 18624 | '.' (in unified mode, or for Neon/VFP instructions), or end of string. */ |
c19d1205 | 18625 | for (base = end = *str; *end != '\0'; end++) |
721a8186 | 18626 | if (*end == ' ' || *end == '.') |
c19d1205 | 18627 | break; |
b99bd4ef | 18628 | |
c19d1205 | 18629 | if (end == base) |
c921be7d | 18630 | return NULL; |
b99bd4ef | 18631 | |
5287ad62 | 18632 | /* Handle a possible width suffix and/or Neon type suffix. */ |
c19d1205 | 18633 | if (end[0] == '.') |
b99bd4ef | 18634 | { |
5287ad62 | 18635 | int offset = 2; |
5f4273c7 | 18636 | |
267d2029 | 18637 | /* The .w and .n suffixes are only valid if the unified syntax is in |
477330fc | 18638 | use. */ |
267d2029 | 18639 | if (unified_syntax && end[1] == 'w') |
c19d1205 | 18640 | inst.size_req = 4; |
267d2029 | 18641 | else if (unified_syntax && end[1] == 'n') |
c19d1205 ZW |
18642 | inst.size_req = 2; |
18643 | else | |
477330fc | 18644 | offset = 0; |
5287ad62 JB |
18645 | |
18646 | inst.vectype.elems = 0; | |
18647 | ||
18648 | *str = end + offset; | |
b99bd4ef | 18649 | |
5f4273c7 | 18650 | if (end[offset] == '.') |
5287ad62 | 18651 | { |
267d2029 | 18652 | /* See if we have a Neon type suffix (possible in either unified or |
477330fc RM |
18653 | non-unified ARM syntax mode). */ |
18654 | if (parse_neon_type (&inst.vectype, str) == FAIL) | |
c921be7d | 18655 | return NULL; |
477330fc | 18656 | } |
5287ad62 | 18657 | else if (end[offset] != '\0' && end[offset] != ' ') |
477330fc | 18658 | return NULL; |
b99bd4ef | 18659 | } |
c19d1205 ZW |
18660 | else |
18661 | *str = end; | |
b99bd4ef | 18662 | |
c19d1205 | 18663 | /* Look for unaffixed or special-case affixed mnemonic. */ |
21d799b5 | 18664 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
477330fc | 18665 | end - base); |
c19d1205 | 18666 | if (opcode) |
b99bd4ef | 18667 | { |
c19d1205 ZW |
18668 | /* step U */ |
18669 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 18670 | { |
c19d1205 ZW |
18671 | inst.cond = COND_ALWAYS; |
18672 | return opcode; | |
b99bd4ef | 18673 | } |
b99bd4ef | 18674 | |
278df34e | 18675 | if (warn_on_deprecated && unified_syntax) |
5c3696f8 | 18676 | as_tsktsk (_("conditional infixes are deprecated in unified syntax")); |
c19d1205 | 18677 | affix = base + (opcode->tag - OT_odd_infix_0); |
21d799b5 | 18678 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
9c2799c2 | 18679 | gas_assert (cond); |
b99bd4ef | 18680 | |
c19d1205 ZW |
18681 | inst.cond = cond->value; |
18682 | return opcode; | |
18683 | } | |
b99bd4ef | 18684 | |
c19d1205 ZW |
18685 | /* Cannot have a conditional suffix on a mnemonic of less than two |
18686 | characters. */ | |
18687 | if (end - base < 3) | |
c921be7d | 18688 | return NULL; |
b99bd4ef | 18689 | |
c19d1205 ZW |
18690 | /* Look for suffixed mnemonic. */ |
18691 | affix = end - 2; | |
21d799b5 NC |
18692 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
18693 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, | |
477330fc | 18694 | affix - base); |
c19d1205 ZW |
18695 | if (opcode && cond) |
18696 | { | |
18697 | /* step CE */ | |
18698 | switch (opcode->tag) | |
18699 | { | |
e3cb604e PB |
18700 | case OT_cinfix3_legacy: |
18701 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
18702 | break; | |
18703 | ||
c19d1205 | 18704 | case OT_cinfix3: |
088fa78e | 18705 | case OT_cinfix3_deprecated: |
c19d1205 ZW |
18706 | case OT_odd_infix_unc: |
18707 | if (!unified_syntax) | |
0198d5e6 | 18708 | return NULL; |
1a0670f3 | 18709 | /* Fall through. */ |
c19d1205 ZW |
18710 | |
18711 | case OT_csuffix: | |
477330fc | 18712 | case OT_csuffixF: |
c19d1205 ZW |
18713 | case OT_csuf_or_in3: |
18714 | inst.cond = cond->value; | |
18715 | return opcode; | |
18716 | ||
18717 | case OT_unconditional: | |
18718 | case OT_unconditionalF: | |
dfa9f0d5 | 18719 | if (thumb_mode) |
c921be7d | 18720 | inst.cond = cond->value; |
dfa9f0d5 PB |
18721 | else |
18722 | { | |
c921be7d | 18723 | /* Delayed diagnostic. */ |
dfa9f0d5 PB |
18724 | inst.error = BAD_COND; |
18725 | inst.cond = COND_ALWAYS; | |
18726 | } | |
c19d1205 | 18727 | return opcode; |
b99bd4ef | 18728 | |
c19d1205 | 18729 | default: |
c921be7d | 18730 | return NULL; |
c19d1205 ZW |
18731 | } |
18732 | } | |
b99bd4ef | 18733 | |
c19d1205 ZW |
18734 | /* Cannot have a usual-position infix on a mnemonic of less than |
18735 | six characters (five would be a suffix). */ | |
18736 | if (end - base < 6) | |
c921be7d | 18737 | return NULL; |
b99bd4ef | 18738 | |
c19d1205 ZW |
18739 | /* Look for infixed mnemonic in the usual position. */ |
18740 | affix = base + 3; | |
21d799b5 | 18741 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
e3cb604e | 18742 | if (!cond) |
c921be7d | 18743 | return NULL; |
e3cb604e PB |
18744 | |
18745 | memcpy (save, affix, 2); | |
18746 | memmove (affix, affix + 2, (end - affix) - 2); | |
21d799b5 | 18747 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
477330fc | 18748 | (end - base) - 2); |
e3cb604e PB |
18749 | memmove (affix + 2, affix, (end - affix) - 2); |
18750 | memcpy (affix, save, 2); | |
18751 | ||
088fa78e KH |
18752 | if (opcode |
18753 | && (opcode->tag == OT_cinfix3 | |
18754 | || opcode->tag == OT_cinfix3_deprecated | |
18755 | || opcode->tag == OT_csuf_or_in3 | |
18756 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 18757 | { |
c921be7d | 18758 | /* Step CM. */ |
278df34e | 18759 | if (warn_on_deprecated && unified_syntax |
088fa78e KH |
18760 | && (opcode->tag == OT_cinfix3 |
18761 | || opcode->tag == OT_cinfix3_deprecated)) | |
5c3696f8 | 18762 | as_tsktsk (_("conditional infixes are deprecated in unified syntax")); |
c19d1205 ZW |
18763 | |
18764 | inst.cond = cond->value; | |
18765 | return opcode; | |
b99bd4ef NC |
18766 | } |
18767 | ||
c921be7d | 18768 | return NULL; |
b99bd4ef NC |
18769 | } |
18770 | ||
e07e6e58 NC |
18771 | /* This function generates an initial IT instruction, leaving its block |
18772 | virtually open for the new instructions. Eventually, | |
18773 | the mask will be updated by now_it_add_mask () each time | |
18774 | a new instruction needs to be included in the IT block. | |
18775 | Finally, the block is closed with close_automatic_it_block (). | |
18776 | The block closure can be requested either from md_assemble (), | |
18777 | a tencode (), or due to a label hook. */ | |
18778 | ||
18779 | static void | |
18780 | new_automatic_it_block (int cond) | |
18781 | { | |
18782 | now_it.state = AUTOMATIC_IT_BLOCK; | |
18783 | now_it.mask = 0x18; | |
18784 | now_it.cc = cond; | |
18785 | now_it.block_length = 1; | |
cd000bff | 18786 | mapping_state (MAP_THUMB); |
e07e6e58 | 18787 | now_it.insn = output_it_inst (cond, now_it.mask, NULL); |
5a01bb1d MGD |
18788 | now_it.warn_deprecated = FALSE; |
18789 | now_it.insn_cond = TRUE; | |
e07e6e58 NC |
18790 | } |
18791 | ||
18792 | /* Close an automatic IT block. | |
18793 | See comments in new_automatic_it_block (). */ | |
18794 | ||
18795 | static void | |
18796 | close_automatic_it_block (void) | |
18797 | { | |
18798 | now_it.mask = 0x10; | |
18799 | now_it.block_length = 0; | |
18800 | } | |
18801 | ||
18802 | /* Update the mask of the current automatically-generated IT | |
18803 | instruction. See comments in new_automatic_it_block (). */ | |
18804 | ||
18805 | static void | |
18806 | now_it_add_mask (int cond) | |
18807 | { | |
18808 | #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit))) | |
18809 | #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \ | |
477330fc | 18810 | | ((bitvalue) << (nbit))) |
e07e6e58 | 18811 | const int resulting_bit = (cond & 1); |
c921be7d | 18812 | |
e07e6e58 NC |
18813 | now_it.mask &= 0xf; |
18814 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
477330fc RM |
18815 | resulting_bit, |
18816 | (5 - now_it.block_length)); | |
e07e6e58 | 18817 | now_it.mask = SET_BIT_VALUE (now_it.mask, |
477330fc RM |
18818 | 1, |
18819 | ((5 - now_it.block_length) - 1) ); | |
e07e6e58 NC |
18820 | output_it_inst (now_it.cc, now_it.mask, now_it.insn); |
18821 | ||
18822 | #undef CLEAR_BIT | |
18823 | #undef SET_BIT_VALUE | |
e07e6e58 NC |
18824 | } |
18825 | ||
18826 | /* The IT blocks handling machinery is accessed through the these functions: | |
18827 | it_fsm_pre_encode () from md_assemble () | |
18828 | set_it_insn_type () optional, from the tencode functions | |
18829 | set_it_insn_type_last () ditto | |
18830 | in_it_block () ditto | |
18831 | it_fsm_post_encode () from md_assemble () | |
33eaf5de | 18832 | force_automatic_it_block_close () from label handling functions |
e07e6e58 NC |
18833 | |
18834 | Rationale: | |
18835 | 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (), | |
477330fc RM |
18836 | initializing the IT insn type with a generic initial value depending |
18837 | on the inst.condition. | |
e07e6e58 | 18838 | 2) During the tencode function, two things may happen: |
477330fc RM |
18839 | a) The tencode function overrides the IT insn type by |
18840 | calling either set_it_insn_type (type) or set_it_insn_type_last (). | |
18841 | b) The tencode function queries the IT block state by | |
18842 | calling in_it_block () (i.e. to determine narrow/not narrow mode). | |
18843 | ||
18844 | Both set_it_insn_type and in_it_block run the internal FSM state | |
18845 | handling function (handle_it_state), because: a) setting the IT insn | |
18846 | type may incur in an invalid state (exiting the function), | |
18847 | and b) querying the state requires the FSM to be updated. | |
18848 | Specifically we want to avoid creating an IT block for conditional | |
18849 | branches, so it_fsm_pre_encode is actually a guess and we can't | |
18850 | determine whether an IT block is required until the tencode () routine | |
18851 | has decided what type of instruction this actually it. | |
18852 | Because of this, if set_it_insn_type and in_it_block have to be used, | |
18853 | set_it_insn_type has to be called first. | |
18854 | ||
18855 | set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that | |
18856 | determines the insn IT type depending on the inst.cond code. | |
18857 | When a tencode () routine encodes an instruction that can be | |
18858 | either outside an IT block, or, in the case of being inside, has to be | |
18859 | the last one, set_it_insn_type_last () will determine the proper | |
18860 | IT instruction type based on the inst.cond code. Otherwise, | |
18861 | set_it_insn_type can be called for overriding that logic or | |
18862 | for covering other cases. | |
18863 | ||
18864 | Calling handle_it_state () may not transition the IT block state to | |
2b0f3761 | 18865 | OUTSIDE_IT_BLOCK immediately, since the (current) state could be |
477330fc RM |
18866 | still queried. Instead, if the FSM determines that the state should |
18867 | be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed | |
18868 | after the tencode () function: that's what it_fsm_post_encode () does. | |
18869 | ||
18870 | Since in_it_block () calls the state handling function to get an | |
18871 | updated state, an error may occur (due to invalid insns combination). | |
18872 | In that case, inst.error is set. | |
18873 | Therefore, inst.error has to be checked after the execution of | |
18874 | the tencode () routine. | |
e07e6e58 NC |
18875 | |
18876 | 3) Back in md_assemble(), it_fsm_post_encode () is called to commit | |
477330fc RM |
18877 | any pending state change (if any) that didn't take place in |
18878 | handle_it_state () as explained above. */ | |
e07e6e58 NC |
18879 | |
18880 | static void | |
18881 | it_fsm_pre_encode (void) | |
18882 | { | |
18883 | if (inst.cond != COND_ALWAYS) | |
18884 | inst.it_insn_type = INSIDE_IT_INSN; | |
18885 | else | |
18886 | inst.it_insn_type = OUTSIDE_IT_INSN; | |
18887 | ||
18888 | now_it.state_handled = 0; | |
18889 | } | |
18890 | ||
18891 | /* IT state FSM handling function. */ | |
18892 | ||
18893 | static int | |
18894 | handle_it_state (void) | |
18895 | { | |
18896 | now_it.state_handled = 1; | |
5a01bb1d | 18897 | now_it.insn_cond = FALSE; |
e07e6e58 NC |
18898 | |
18899 | switch (now_it.state) | |
18900 | { | |
18901 | case OUTSIDE_IT_BLOCK: | |
18902 | switch (inst.it_insn_type) | |
18903 | { | |
18904 | case OUTSIDE_IT_INSN: | |
18905 | break; | |
18906 | ||
18907 | case INSIDE_IT_INSN: | |
18908 | case INSIDE_IT_LAST_INSN: | |
18909 | if (thumb_mode == 0) | |
18910 | { | |
c921be7d | 18911 | if (unified_syntax |
e07e6e58 NC |
18912 | && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM)) |
18913 | as_tsktsk (_("Warning: conditional outside an IT block"\ | |
18914 | " for Thumb.")); | |
18915 | } | |
18916 | else | |
18917 | { | |
18918 | if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB) | |
fc289b0a | 18919 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) |
e07e6e58 NC |
18920 | { |
18921 | /* Automatically generate the IT instruction. */ | |
18922 | new_automatic_it_block (inst.cond); | |
18923 | if (inst.it_insn_type == INSIDE_IT_LAST_INSN) | |
18924 | close_automatic_it_block (); | |
18925 | } | |
18926 | else | |
18927 | { | |
18928 | inst.error = BAD_OUT_IT; | |
18929 | return FAIL; | |
18930 | } | |
18931 | } | |
18932 | break; | |
18933 | ||
18934 | case IF_INSIDE_IT_LAST_INSN: | |
18935 | case NEUTRAL_IT_INSN: | |
18936 | break; | |
18937 | ||
18938 | case IT_INSN: | |
18939 | now_it.state = MANUAL_IT_BLOCK; | |
18940 | now_it.block_length = 0; | |
18941 | break; | |
18942 | } | |
18943 | break; | |
18944 | ||
18945 | case AUTOMATIC_IT_BLOCK: | |
18946 | /* Three things may happen now: | |
18947 | a) We should increment current it block size; | |
18948 | b) We should close current it block (closing insn or 4 insns); | |
18949 | c) We should close current it block and start a new one (due | |
18950 | to incompatible conditions or | |
18951 | 4 insns-length block reached). */ | |
18952 | ||
18953 | switch (inst.it_insn_type) | |
18954 | { | |
18955 | case OUTSIDE_IT_INSN: | |
2b0f3761 | 18956 | /* The closure of the block shall happen immediately, |
e07e6e58 NC |
18957 | so any in_it_block () call reports the block as closed. */ |
18958 | force_automatic_it_block_close (); | |
18959 | break; | |
18960 | ||
18961 | case INSIDE_IT_INSN: | |
18962 | case INSIDE_IT_LAST_INSN: | |
18963 | case IF_INSIDE_IT_LAST_INSN: | |
18964 | now_it.block_length++; | |
18965 | ||
18966 | if (now_it.block_length > 4 | |
18967 | || !now_it_compatible (inst.cond)) | |
18968 | { | |
18969 | force_automatic_it_block_close (); | |
18970 | if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN) | |
18971 | new_automatic_it_block (inst.cond); | |
18972 | } | |
18973 | else | |
18974 | { | |
5a01bb1d | 18975 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
18976 | now_it_add_mask (inst.cond); |
18977 | } | |
18978 | ||
18979 | if (now_it.state == AUTOMATIC_IT_BLOCK | |
18980 | && (inst.it_insn_type == INSIDE_IT_LAST_INSN | |
18981 | || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN)) | |
18982 | close_automatic_it_block (); | |
18983 | break; | |
18984 | ||
18985 | case NEUTRAL_IT_INSN: | |
18986 | now_it.block_length++; | |
5a01bb1d | 18987 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
18988 | |
18989 | if (now_it.block_length > 4) | |
18990 | force_automatic_it_block_close (); | |
18991 | else | |
18992 | now_it_add_mask (now_it.cc & 1); | |
18993 | break; | |
18994 | ||
18995 | case IT_INSN: | |
18996 | close_automatic_it_block (); | |
18997 | now_it.state = MANUAL_IT_BLOCK; | |
18998 | break; | |
18999 | } | |
19000 | break; | |
19001 | ||
19002 | case MANUAL_IT_BLOCK: | |
19003 | { | |
19004 | /* Check conditional suffixes. */ | |
19005 | const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1; | |
19006 | int is_last; | |
19007 | now_it.mask <<= 1; | |
19008 | now_it.mask &= 0x1f; | |
19009 | is_last = (now_it.mask == 0x10); | |
5a01bb1d | 19010 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
19011 | |
19012 | switch (inst.it_insn_type) | |
19013 | { | |
19014 | case OUTSIDE_IT_INSN: | |
19015 | inst.error = BAD_NOT_IT; | |
19016 | return FAIL; | |
19017 | ||
19018 | case INSIDE_IT_INSN: | |
19019 | if (cond != inst.cond) | |
19020 | { | |
19021 | inst.error = BAD_IT_COND; | |
19022 | return FAIL; | |
19023 | } | |
19024 | break; | |
19025 | ||
19026 | case INSIDE_IT_LAST_INSN: | |
19027 | case IF_INSIDE_IT_LAST_INSN: | |
19028 | if (cond != inst.cond) | |
19029 | { | |
19030 | inst.error = BAD_IT_COND; | |
19031 | return FAIL; | |
19032 | } | |
19033 | if (!is_last) | |
19034 | { | |
19035 | inst.error = BAD_BRANCH; | |
19036 | return FAIL; | |
19037 | } | |
19038 | break; | |
19039 | ||
19040 | case NEUTRAL_IT_INSN: | |
19041 | /* The BKPT instruction is unconditional even in an IT block. */ | |
19042 | break; | |
19043 | ||
19044 | case IT_INSN: | |
19045 | inst.error = BAD_IT_IT; | |
19046 | return FAIL; | |
19047 | } | |
19048 | } | |
19049 | break; | |
19050 | } | |
19051 | ||
19052 | return SUCCESS; | |
19053 | } | |
19054 | ||
5a01bb1d MGD |
19055 | struct depr_insn_mask |
19056 | { | |
19057 | unsigned long pattern; | |
19058 | unsigned long mask; | |
19059 | const char* description; | |
19060 | }; | |
19061 | ||
19062 | /* List of 16-bit instruction patterns deprecated in an IT block in | |
19063 | ARMv8. */ | |
19064 | static const struct depr_insn_mask depr_it_insns[] = { | |
19065 | { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") }, | |
19066 | { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") }, | |
19067 | { 0xa000, 0xb800, N_("ADR") }, | |
19068 | { 0x4800, 0xf800, N_("Literal loads") }, | |
19069 | { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") }, | |
19070 | { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") }, | |
c8de034b JW |
19071 | /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue' |
19072 | field in asm_opcode. 'tvalue' is used at the stage this check happen. */ | |
19073 | { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") }, | |
5a01bb1d MGD |
19074 | { 0, 0, NULL } |
19075 | }; | |
19076 | ||
e07e6e58 NC |
19077 | static void |
19078 | it_fsm_post_encode (void) | |
19079 | { | |
19080 | int is_last; | |
19081 | ||
19082 | if (!now_it.state_handled) | |
19083 | handle_it_state (); | |
19084 | ||
5a01bb1d MGD |
19085 | if (now_it.insn_cond |
19086 | && !now_it.warn_deprecated | |
19087 | && warn_on_deprecated | |
df9909b8 TP |
19088 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8) |
19089 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m)) | |
5a01bb1d MGD |
19090 | { |
19091 | if (inst.instruction >= 0x10000) | |
19092 | { | |
5c3696f8 | 19093 | as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are " |
df9909b8 | 19094 | "performance deprecated in ARMv8-A and ARMv8-R")); |
5a01bb1d MGD |
19095 | now_it.warn_deprecated = TRUE; |
19096 | } | |
19097 | else | |
19098 | { | |
19099 | const struct depr_insn_mask *p = depr_it_insns; | |
19100 | ||
19101 | while (p->mask != 0) | |
19102 | { | |
19103 | if ((inst.instruction & p->mask) == p->pattern) | |
19104 | { | |
df9909b8 TP |
19105 | as_tsktsk (_("IT blocks containing 16-bit Thumb " |
19106 | "instructions of the following class are " | |
19107 | "performance deprecated in ARMv8-A and " | |
19108 | "ARMv8-R: %s"), p->description); | |
5a01bb1d MGD |
19109 | now_it.warn_deprecated = TRUE; |
19110 | break; | |
19111 | } | |
19112 | ||
19113 | ++p; | |
19114 | } | |
19115 | } | |
19116 | ||
19117 | if (now_it.block_length > 1) | |
19118 | { | |
5c3696f8 | 19119 | as_tsktsk (_("IT blocks containing more than one conditional " |
df9909b8 TP |
19120 | "instruction are performance deprecated in ARMv8-A and " |
19121 | "ARMv8-R")); | |
5a01bb1d MGD |
19122 | now_it.warn_deprecated = TRUE; |
19123 | } | |
19124 | } | |
19125 | ||
e07e6e58 NC |
19126 | is_last = (now_it.mask == 0x10); |
19127 | if (is_last) | |
19128 | { | |
19129 | now_it.state = OUTSIDE_IT_BLOCK; | |
19130 | now_it.mask = 0; | |
19131 | } | |
19132 | } | |
19133 | ||
19134 | static void | |
19135 | force_automatic_it_block_close (void) | |
19136 | { | |
19137 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
19138 | { | |
19139 | close_automatic_it_block (); | |
19140 | now_it.state = OUTSIDE_IT_BLOCK; | |
19141 | now_it.mask = 0; | |
19142 | } | |
19143 | } | |
19144 | ||
19145 | static int | |
19146 | in_it_block (void) | |
19147 | { | |
19148 | if (!now_it.state_handled) | |
19149 | handle_it_state (); | |
19150 | ||
19151 | return now_it.state != OUTSIDE_IT_BLOCK; | |
19152 | } | |
19153 | ||
ff8646ee TP |
19154 | /* Whether OPCODE only has T32 encoding. Since this function is only used by |
19155 | t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed | |
19156 | here, hence the "known" in the function name. */ | |
fc289b0a TP |
19157 | |
19158 | static bfd_boolean | |
ff8646ee | 19159 | known_t32_only_insn (const struct asm_opcode *opcode) |
fc289b0a TP |
19160 | { |
19161 | /* Original Thumb-1 wide instruction. */ | |
19162 | if (opcode->tencode == do_t_blx | |
19163 | || opcode->tencode == do_t_branch23 | |
19164 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr) | |
19165 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)) | |
19166 | return TRUE; | |
19167 | ||
16a1fa25 TP |
19168 | /* Wide-only instruction added to ARMv8-M Baseline. */ |
19169 | if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only) | |
ff8646ee TP |
19170 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics) |
19171 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m) | |
19172 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div)) | |
19173 | return TRUE; | |
19174 | ||
19175 | return FALSE; | |
19176 | } | |
19177 | ||
19178 | /* Whether wide instruction variant can be used if available for a valid OPCODE | |
19179 | in ARCH. */ | |
19180 | ||
19181 | static bfd_boolean | |
19182 | t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode) | |
19183 | { | |
19184 | if (known_t32_only_insn (opcode)) | |
19185 | return TRUE; | |
19186 | ||
19187 | /* Instruction with narrow and wide encoding added to ARMv8-M. Availability | |
19188 | of variant T3 of B.W is checked in do_t_branch. */ | |
19189 | if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m) | |
19190 | && opcode->tencode == do_t_branch) | |
19191 | return TRUE; | |
19192 | ||
bada4342 JW |
19193 | /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */ |
19194 | if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m) | |
19195 | && opcode->tencode == do_t_mov_cmp | |
19196 | /* Make sure CMP instruction is not affected. */ | |
19197 | && opcode->aencode == do_mov) | |
19198 | return TRUE; | |
19199 | ||
ff8646ee TP |
19200 | /* Wide instruction variants of all instructions with narrow *and* wide |
19201 | variants become available with ARMv6t2. Other opcodes are either | |
19202 | narrow-only or wide-only and are thus available if OPCODE is valid. */ | |
19203 | if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2)) | |
19204 | return TRUE; | |
19205 | ||
19206 | /* OPCODE with narrow only instruction variant or wide variant not | |
19207 | available. */ | |
fc289b0a TP |
19208 | return FALSE; |
19209 | } | |
19210 | ||
c19d1205 ZW |
19211 | void |
19212 | md_assemble (char *str) | |
b99bd4ef | 19213 | { |
c19d1205 ZW |
19214 | char *p = str; |
19215 | const struct asm_opcode * opcode; | |
b99bd4ef | 19216 | |
c19d1205 ZW |
19217 | /* Align the previous label if needed. */ |
19218 | if (last_label_seen != NULL) | |
b99bd4ef | 19219 | { |
c19d1205 ZW |
19220 | symbol_set_frag (last_label_seen, frag_now); |
19221 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
19222 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
19223 | } |
19224 | ||
c19d1205 | 19225 | memset (&inst, '\0', sizeof (inst)); |
e2b0ab59 AV |
19226 | int r; |
19227 | for (r = 0; r < ARM_IT_MAX_RELOCS; r++) | |
19228 | inst.relocs[r].type = BFD_RELOC_UNUSED; | |
b99bd4ef | 19229 | |
c19d1205 ZW |
19230 | opcode = opcode_lookup (&p); |
19231 | if (!opcode) | |
b99bd4ef | 19232 | { |
c19d1205 | 19233 | /* It wasn't an instruction, but it might be a register alias of |
dcbf9037 | 19234 | the form alias .req reg, or a Neon .dn/.qn directive. */ |
c921be7d | 19235 | if (! create_register_alias (str, p) |
477330fc | 19236 | && ! create_neon_reg_alias (str, p)) |
c19d1205 | 19237 | as_bad (_("bad instruction `%s'"), str); |
b99bd4ef | 19238 | |
b99bd4ef NC |
19239 | return; |
19240 | } | |
19241 | ||
278df34e | 19242 | if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated) |
5c3696f8 | 19243 | as_tsktsk (_("s suffix on comparison instruction is deprecated")); |
088fa78e | 19244 | |
037e8744 JB |
19245 | /* The value which unconditional instructions should have in place of the |
19246 | condition field. */ | |
19247 | inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1; | |
19248 | ||
c19d1205 | 19249 | if (thumb_mode) |
b99bd4ef | 19250 | { |
e74cfd16 | 19251 | arm_feature_set variant; |
8f06b2d8 PB |
19252 | |
19253 | variant = cpu_variant; | |
19254 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
19255 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
19256 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 19257 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
19258 | if (!opcode->tvariant |
19259 | || (thumb_mode == 1 | |
19260 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 19261 | { |
173205ca TP |
19262 | if (opcode->tencode == do_t_swi) |
19263 | as_bad (_("SVC is not permitted on this architecture")); | |
19264 | else | |
19265 | as_bad (_("selected processor does not support `%s' in Thumb mode"), str); | |
b99bd4ef NC |
19266 | return; |
19267 | } | |
c19d1205 ZW |
19268 | if (inst.cond != COND_ALWAYS && !unified_syntax |
19269 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 19270 | { |
c19d1205 | 19271 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
19272 | return; |
19273 | } | |
19274 | ||
fc289b0a TP |
19275 | /* Two things are addressed here: |
19276 | 1) Implicit require narrow instructions on Thumb-1. | |
19277 | This avoids relaxation accidentally introducing Thumb-2 | |
19278 | instructions. | |
19279 | 2) Reject wide instructions in non Thumb-2 cores. | |
19280 | ||
19281 | Only instructions with narrow and wide variants need to be handled | |
19282 | but selecting all non wide-only instructions is easier. */ | |
19283 | if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) | |
ff8646ee | 19284 | && !t32_insn_ok (variant, opcode)) |
076d447c | 19285 | { |
fc289b0a TP |
19286 | if (inst.size_req == 0) |
19287 | inst.size_req = 2; | |
19288 | else if (inst.size_req == 4) | |
752d5da4 | 19289 | { |
ff8646ee TP |
19290 | if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m)) |
19291 | as_bad (_("selected processor does not support 32bit wide " | |
19292 | "variant of instruction `%s'"), str); | |
19293 | else | |
19294 | as_bad (_("selected processor does not support `%s' in " | |
19295 | "Thumb-2 mode"), str); | |
fc289b0a | 19296 | return; |
752d5da4 | 19297 | } |
076d447c PB |
19298 | } |
19299 | ||
c19d1205 ZW |
19300 | inst.instruction = opcode->tvalue; |
19301 | ||
5be8be5d | 19302 | if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE)) |
477330fc RM |
19303 | { |
19304 | /* Prepare the it_insn_type for those encodings that don't set | |
19305 | it. */ | |
19306 | it_fsm_pre_encode (); | |
c19d1205 | 19307 | |
477330fc | 19308 | opcode->tencode (); |
e07e6e58 | 19309 | |
477330fc RM |
19310 | it_fsm_post_encode (); |
19311 | } | |
e27ec89e | 19312 | |
0110f2b8 | 19313 | if (!(inst.error || inst.relax)) |
b99bd4ef | 19314 | { |
9c2799c2 | 19315 | gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
c19d1205 ZW |
19316 | inst.size = (inst.instruction > 0xffff ? 4 : 2); |
19317 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 19318 | { |
c19d1205 | 19319 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
19320 | return; |
19321 | } | |
19322 | } | |
076d447c PB |
19323 | |
19324 | /* Something has gone badly wrong if we try to relax a fixed size | |
477330fc | 19325 | instruction. */ |
9c2799c2 | 19326 | gas_assert (inst.size_req == 0 || !inst.relax); |
076d447c | 19327 | |
e74cfd16 PB |
19328 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
19329 | *opcode->tvariant); | |
ee065d83 | 19330 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
fc289b0a TP |
19331 | set those bits when Thumb-2 32-bit instructions are seen. The impact |
19332 | of relaxable instructions will be considered later after we finish all | |
19333 | relaxation. */ | |
ff8646ee TP |
19334 | if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any)) |
19335 | variant = arm_arch_none; | |
19336 | else | |
19337 | variant = cpu_variant; | |
19338 | if (inst.size == 4 && !t32_insn_ok (variant, opcode)) | |
e74cfd16 PB |
19339 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
19340 | arm_ext_v6t2); | |
cd000bff | 19341 | |
88714cb8 DG |
19342 | check_neon_suffixes; |
19343 | ||
cd000bff | 19344 | if (!inst.error) |
c877a2f2 NC |
19345 | { |
19346 | mapping_state (MAP_THUMB); | |
19347 | } | |
c19d1205 | 19348 | } |
3e9e4fcf | 19349 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 | 19350 | { |
845b51d6 PB |
19351 | bfd_boolean is_bx; |
19352 | ||
19353 | /* bx is allowed on v5 cores, and sometimes on v4 cores. */ | |
19354 | is_bx = (opcode->aencode == do_bx); | |
19355 | ||
c19d1205 | 19356 | /* Check that this instruction is supported for this CPU. */ |
845b51d6 PB |
19357 | if (!(is_bx && fix_v4bx) |
19358 | && !(opcode->avariant && | |
19359 | ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))) | |
b99bd4ef | 19360 | { |
84b52b66 | 19361 | as_bad (_("selected processor does not support `%s' in ARM mode"), str); |
c19d1205 | 19362 | return; |
b99bd4ef | 19363 | } |
c19d1205 | 19364 | if (inst.size_req) |
b99bd4ef | 19365 | { |
c19d1205 ZW |
19366 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
19367 | return; | |
b99bd4ef NC |
19368 | } |
19369 | ||
c19d1205 ZW |
19370 | inst.instruction = opcode->avalue; |
19371 | if (opcode->tag == OT_unconditionalF) | |
eff0bc54 | 19372 | inst.instruction |= 0xFU << 28; |
c19d1205 ZW |
19373 | else |
19374 | inst.instruction |= inst.cond << 28; | |
19375 | inst.size = INSN_SIZE; | |
5be8be5d | 19376 | if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE)) |
477330fc RM |
19377 | { |
19378 | it_fsm_pre_encode (); | |
19379 | opcode->aencode (); | |
19380 | it_fsm_post_encode (); | |
19381 | } | |
ee065d83 | 19382 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
477330fc | 19383 | on a hypothetical non-thumb v5 core. */ |
845b51d6 | 19384 | if (is_bx) |
e74cfd16 | 19385 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); |
ee065d83 | 19386 | else |
e74cfd16 PB |
19387 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
19388 | *opcode->avariant); | |
88714cb8 DG |
19389 | |
19390 | check_neon_suffixes; | |
19391 | ||
cd000bff | 19392 | if (!inst.error) |
c877a2f2 NC |
19393 | { |
19394 | mapping_state (MAP_ARM); | |
19395 | } | |
b99bd4ef | 19396 | } |
3e9e4fcf JB |
19397 | else |
19398 | { | |
19399 | as_bad (_("attempt to use an ARM instruction on a Thumb-only processor " | |
19400 | "-- `%s'"), str); | |
19401 | return; | |
19402 | } | |
c19d1205 ZW |
19403 | output_inst (str); |
19404 | } | |
b99bd4ef | 19405 | |
e07e6e58 NC |
19406 | static void |
19407 | check_it_blocks_finished (void) | |
19408 | { | |
19409 | #ifdef OBJ_ELF | |
19410 | asection *sect; | |
19411 | ||
19412 | for (sect = stdoutput->sections; sect != NULL; sect = sect->next) | |
19413 | if (seg_info (sect)->tc_segment_info_data.current_it.state | |
19414 | == MANUAL_IT_BLOCK) | |
19415 | { | |
19416 | as_warn (_("section '%s' finished with an open IT block."), | |
19417 | sect->name); | |
19418 | } | |
19419 | #else | |
19420 | if (now_it.state == MANUAL_IT_BLOCK) | |
19421 | as_warn (_("file finished with an open IT block.")); | |
19422 | #endif | |
19423 | } | |
19424 | ||
c19d1205 ZW |
19425 | /* Various frobbings of labels and their addresses. */ |
19426 | ||
19427 | void | |
19428 | arm_start_line_hook (void) | |
19429 | { | |
19430 | last_label_seen = NULL; | |
b99bd4ef NC |
19431 | } |
19432 | ||
c19d1205 ZW |
19433 | void |
19434 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 19435 | { |
c19d1205 | 19436 | last_label_seen = sym; |
b99bd4ef | 19437 | |
c19d1205 | 19438 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 19439 | |
c19d1205 ZW |
19440 | #if defined OBJ_COFF || defined OBJ_ELF |
19441 | ARM_SET_INTERWORK (sym, support_interwork); | |
19442 | #endif | |
b99bd4ef | 19443 | |
e07e6e58 NC |
19444 | force_automatic_it_block_close (); |
19445 | ||
5f4273c7 | 19446 | /* Note - do not allow local symbols (.Lxxx) to be labelled |
c19d1205 ZW |
19447 | as Thumb functions. This is because these labels, whilst |
19448 | they exist inside Thumb code, are not the entry points for | |
19449 | possible ARM->Thumb calls. Also, these labels can be used | |
19450 | as part of a computed goto or switch statement. eg gcc | |
19451 | can generate code that looks like this: | |
b99bd4ef | 19452 | |
c19d1205 ZW |
19453 | ldr r2, [pc, .Laaa] |
19454 | lsl r3, r3, #2 | |
19455 | ldr r2, [r3, r2] | |
19456 | mov pc, r2 | |
b99bd4ef | 19457 | |
c19d1205 ZW |
19458 | .Lbbb: .word .Lxxx |
19459 | .Lccc: .word .Lyyy | |
19460 | ..etc... | |
19461 | .Laaa: .word Lbbb | |
b99bd4ef | 19462 | |
c19d1205 ZW |
19463 | The first instruction loads the address of the jump table. |
19464 | The second instruction converts a table index into a byte offset. | |
19465 | The third instruction gets the jump address out of the table. | |
19466 | The fourth instruction performs the jump. | |
b99bd4ef | 19467 | |
c19d1205 ZW |
19468 | If the address stored at .Laaa is that of a symbol which has the |
19469 | Thumb_Func bit set, then the linker will arrange for this address | |
19470 | to have the bottom bit set, which in turn would mean that the | |
19471 | address computation performed by the third instruction would end | |
19472 | up with the bottom bit set. Since the ARM is capable of unaligned | |
19473 | word loads, the instruction would then load the incorrect address | |
19474 | out of the jump table, and chaos would ensue. */ | |
19475 | if (label_is_thumb_function_name | |
19476 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
19477 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 19478 | { |
c19d1205 ZW |
19479 | /* When the address of a Thumb function is taken the bottom |
19480 | bit of that address should be set. This will allow | |
19481 | interworking between Arm and Thumb functions to work | |
19482 | correctly. */ | |
b99bd4ef | 19483 | |
c19d1205 | 19484 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 19485 | |
c19d1205 | 19486 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 19487 | } |
07a53e5c | 19488 | |
07a53e5c | 19489 | dwarf2_emit_label (sym); |
b99bd4ef NC |
19490 | } |
19491 | ||
c921be7d | 19492 | bfd_boolean |
c19d1205 | 19493 | arm_data_in_code (void) |
b99bd4ef | 19494 | { |
c19d1205 | 19495 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 19496 | { |
c19d1205 ZW |
19497 | *input_line_pointer = '/'; |
19498 | input_line_pointer += 5; | |
19499 | *input_line_pointer = 0; | |
c921be7d | 19500 | return TRUE; |
b99bd4ef NC |
19501 | } |
19502 | ||
c921be7d | 19503 | return FALSE; |
b99bd4ef NC |
19504 | } |
19505 | ||
c19d1205 ZW |
19506 | char * |
19507 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 19508 | { |
c19d1205 | 19509 | int len; |
b99bd4ef | 19510 | |
c19d1205 ZW |
19511 | if (thumb_mode && (len = strlen (name)) > 5 |
19512 | && streq (name + len - 5, "/data")) | |
19513 | *(name + len - 5) = 0; | |
b99bd4ef | 19514 | |
c19d1205 | 19515 | return name; |
b99bd4ef | 19516 | } |
c19d1205 ZW |
19517 | \f |
19518 | /* Table of all register names defined by default. The user can | |
19519 | define additional names with .req. Note that all register names | |
19520 | should appear in both upper and lowercase variants. Some registers | |
19521 | also have mixed-case names. */ | |
b99bd4ef | 19522 | |
dcbf9037 | 19523 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 } |
c19d1205 | 19524 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 19525 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
19526 | #define REGSET(p,t) \ |
19527 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
19528 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
19529 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
19530 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
5287ad62 JB |
19531 | #define REGSETH(p,t) \ |
19532 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ | |
19533 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
19534 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
19535 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t) | |
19536 | #define REGSET2(p,t) \ | |
19537 | REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \ | |
19538 | REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \ | |
19539 | REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \ | |
19540 | REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t) | |
90ec0d68 MGD |
19541 | #define SPLRBANK(base,bank,t) \ |
19542 | REGDEF(lr_##bank, 768|((base+0)<<16), t), \ | |
19543 | REGDEF(sp_##bank, 768|((base+1)<<16), t), \ | |
19544 | REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \ | |
19545 | REGDEF(LR_##bank, 768|((base+0)<<16), t), \ | |
19546 | REGDEF(SP_##bank, 768|((base+1)<<16), t), \ | |
19547 | REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t) | |
7ed4c4c5 | 19548 | |
c19d1205 | 19549 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 19550 | { |
c19d1205 ZW |
19551 | /* ARM integer registers. */ |
19552 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 19553 | |
c19d1205 ZW |
19554 | /* ATPCS synonyms. */ |
19555 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
19556 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
19557 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 19558 | |
c19d1205 ZW |
19559 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
19560 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
19561 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 19562 | |
c19d1205 ZW |
19563 | /* Well-known aliases. */ |
19564 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
19565 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
19566 | ||
19567 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
19568 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
19569 | ||
19570 | /* Coprocessor numbers. */ | |
19571 | REGSET(p, CP), REGSET(P, CP), | |
19572 | ||
19573 | /* Coprocessor register numbers. The "cr" variants are for backward | |
19574 | compatibility. */ | |
19575 | REGSET(c, CN), REGSET(C, CN), | |
19576 | REGSET(cr, CN), REGSET(CR, CN), | |
19577 | ||
90ec0d68 MGD |
19578 | /* ARM banked registers. */ |
19579 | REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB), | |
19580 | REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB), | |
19581 | REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB), | |
19582 | REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB), | |
19583 | REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB), | |
19584 | REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB), | |
19585 | REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB), | |
19586 | ||
19587 | REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB), | |
19588 | REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB), | |
19589 | REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB), | |
19590 | REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB), | |
19591 | REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB), | |
1472d06f | 19592 | REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB), |
90ec0d68 MGD |
19593 | REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB), |
19594 | REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB), | |
19595 | ||
19596 | SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB), | |
19597 | SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB), | |
19598 | SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB), | |
19599 | SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB), | |
19600 | SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB), | |
19601 | REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB), | |
19602 | REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB), | |
fa94de6b | 19603 | REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB), |
90ec0d68 MGD |
19604 | REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB), |
19605 | ||
c19d1205 ZW |
19606 | /* FPA registers. */ |
19607 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
19608 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
19609 | ||
19610 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
19611 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
19612 | ||
19613 | /* VFP SP registers. */ | |
5287ad62 JB |
19614 | REGSET(s,VFS), REGSET(S,VFS), |
19615 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
19616 | |
19617 | /* VFP DP Registers. */ | |
5287ad62 JB |
19618 | REGSET(d,VFD), REGSET(D,VFD), |
19619 | /* Extra Neon DP registers. */ | |
19620 | REGSETH(d,VFD), REGSETH(D,VFD), | |
19621 | ||
19622 | /* Neon QP registers. */ | |
19623 | REGSET2(q,NQ), REGSET2(Q,NQ), | |
c19d1205 ZW |
19624 | |
19625 | /* VFP control registers. */ | |
19626 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
19627 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
cd2cf30b PB |
19628 | REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC), |
19629 | REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC), | |
19630 | REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC), | |
19631 | REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC), | |
40c7d507 | 19632 | REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC), |
c19d1205 ZW |
19633 | |
19634 | /* Maverick DSP coprocessor registers. */ | |
19635 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
19636 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
19637 | ||
19638 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
19639 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
19640 | REGDEF(dspsc,0,DSPSC), | |
19641 | ||
19642 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
19643 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
19644 | REGDEF(DSPSC,0,DSPSC), | |
19645 | ||
19646 | /* iWMMXt data registers - p0, c0-15. */ | |
19647 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
19648 | ||
19649 | /* iWMMXt control registers - p1, c0-3. */ | |
19650 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
19651 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
19652 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
19653 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
19654 | ||
19655 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
19656 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
19657 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
19658 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
19659 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
19660 | ||
19661 | /* XScale accumulator registers. */ | |
19662 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
19663 | }; | |
19664 | #undef REGDEF | |
19665 | #undef REGNUM | |
19666 | #undef REGSET | |
7ed4c4c5 | 19667 | |
c19d1205 ZW |
19668 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
19669 | within psr_required_here. */ | |
19670 | static const struct asm_psr psrs[] = | |
19671 | { | |
19672 | /* Backward compatibility notation. Note that "all" is no longer | |
19673 | truly all possible PSR bits. */ | |
19674 | {"all", PSR_c | PSR_f}, | |
19675 | {"flg", PSR_f}, | |
19676 | {"ctl", PSR_c}, | |
19677 | ||
19678 | /* Individual flags. */ | |
19679 | {"f", PSR_f}, | |
19680 | {"c", PSR_c}, | |
19681 | {"x", PSR_x}, | |
19682 | {"s", PSR_s}, | |
59b42a0d | 19683 | |
c19d1205 ZW |
19684 | /* Combinations of flags. */ |
19685 | {"fs", PSR_f | PSR_s}, | |
19686 | {"fx", PSR_f | PSR_x}, | |
19687 | {"fc", PSR_f | PSR_c}, | |
19688 | {"sf", PSR_s | PSR_f}, | |
19689 | {"sx", PSR_s | PSR_x}, | |
19690 | {"sc", PSR_s | PSR_c}, | |
19691 | {"xf", PSR_x | PSR_f}, | |
19692 | {"xs", PSR_x | PSR_s}, | |
19693 | {"xc", PSR_x | PSR_c}, | |
19694 | {"cf", PSR_c | PSR_f}, | |
19695 | {"cs", PSR_c | PSR_s}, | |
19696 | {"cx", PSR_c | PSR_x}, | |
19697 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
19698 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
19699 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
19700 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
19701 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
19702 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
19703 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
19704 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
19705 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
19706 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
19707 | {"scf", PSR_s | PSR_c | PSR_f}, | |
19708 | {"scx", PSR_s | PSR_c | PSR_x}, | |
19709 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
19710 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
19711 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
19712 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
19713 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
19714 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
19715 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
19716 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
19717 | {"csf", PSR_c | PSR_s | PSR_f}, | |
19718 | {"csx", PSR_c | PSR_s | PSR_x}, | |
19719 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
19720 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
19721 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
19722 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
19723 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
19724 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
19725 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
19726 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
19727 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
19728 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
19729 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
19730 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
19731 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
19732 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
19733 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
19734 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
19735 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
19736 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
19737 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
19738 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
19739 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
19740 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
19741 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
19742 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
19743 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
19744 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
19745 | }; | |
19746 | ||
62b3e311 PB |
19747 | /* Table of V7M psr names. */ |
19748 | static const struct asm_psr v7m_psrs[] = | |
19749 | { | |
1a336194 TP |
19750 | {"apsr", 0x0 }, {"APSR", 0x0 }, |
19751 | {"iapsr", 0x1 }, {"IAPSR", 0x1 }, | |
19752 | {"eapsr", 0x2 }, {"EAPSR", 0x2 }, | |
19753 | {"psr", 0x3 }, {"PSR", 0x3 }, | |
19754 | {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 }, | |
19755 | {"ipsr", 0x5 }, {"IPSR", 0x5 }, | |
19756 | {"epsr", 0x6 }, {"EPSR", 0x6 }, | |
19757 | {"iepsr", 0x7 }, {"IEPSR", 0x7 }, | |
19758 | {"msp", 0x8 }, {"MSP", 0x8 }, | |
19759 | {"psp", 0x9 }, {"PSP", 0x9 }, | |
19760 | {"msplim", 0xa }, {"MSPLIM", 0xa }, | |
19761 | {"psplim", 0xb }, {"PSPLIM", 0xb }, | |
19762 | {"primask", 0x10}, {"PRIMASK", 0x10}, | |
19763 | {"basepri", 0x11}, {"BASEPRI", 0x11}, | |
19764 | {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12}, | |
1a336194 TP |
19765 | {"faultmask", 0x13}, {"FAULTMASK", 0x13}, |
19766 | {"control", 0x14}, {"CONTROL", 0x14}, | |
19767 | {"msp_ns", 0x88}, {"MSP_NS", 0x88}, | |
19768 | {"psp_ns", 0x89}, {"PSP_NS", 0x89}, | |
19769 | {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a}, | |
19770 | {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b}, | |
19771 | {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90}, | |
19772 | {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91}, | |
19773 | {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93}, | |
19774 | {"control_ns", 0x94}, {"CONTROL_NS", 0x94}, | |
19775 | {"sp_ns", 0x98}, {"SP_NS", 0x98 } | |
62b3e311 PB |
19776 | }; |
19777 | ||
c19d1205 ZW |
19778 | /* Table of all shift-in-operand names. */ |
19779 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 19780 | { |
c19d1205 ZW |
19781 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
19782 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
19783 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
19784 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
19785 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
19786 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
19787 | }; | |
b99bd4ef | 19788 | |
c19d1205 ZW |
19789 | /* Table of all explicit relocation names. */ |
19790 | #ifdef OBJ_ELF | |
19791 | static struct reloc_entry reloc_names[] = | |
19792 | { | |
19793 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
19794 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
19795 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
19796 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
19797 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
19798 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
19799 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
19800 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
19801 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
19802 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
b43420e6 | 19803 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}, |
0855e32b NS |
19804 | { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}, |
19805 | { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC}, | |
477330fc | 19806 | { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC}, |
0855e32b | 19807 | { "tlscall", BFD_RELOC_ARM_TLS_CALL}, |
477330fc | 19808 | { "TLSCALL", BFD_RELOC_ARM_TLS_CALL}, |
0855e32b | 19809 | { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ}, |
188fd7ae CL |
19810 | { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}, |
19811 | { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC }, | |
19812 | { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC }, | |
19813 | { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC }, | |
19814 | { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC }, | |
19815 | { "funcdesc", BFD_RELOC_ARM_FUNCDESC }, | |
5c5a4843 CL |
19816 | { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC }, |
19817 | { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC }, | |
19818 | { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, | |
19819 | { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC }, | |
c19d1205 ZW |
19820 | }; |
19821 | #endif | |
b99bd4ef | 19822 | |
c19d1205 ZW |
19823 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
19824 | static const struct asm_cond conds[] = | |
19825 | { | |
19826 | {"eq", 0x0}, | |
19827 | {"ne", 0x1}, | |
19828 | {"cs", 0x2}, {"hs", 0x2}, | |
19829 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
19830 | {"mi", 0x4}, | |
19831 | {"pl", 0x5}, | |
19832 | {"vs", 0x6}, | |
19833 | {"vc", 0x7}, | |
19834 | {"hi", 0x8}, | |
19835 | {"ls", 0x9}, | |
19836 | {"ge", 0xa}, | |
19837 | {"lt", 0xb}, | |
19838 | {"gt", 0xc}, | |
19839 | {"le", 0xd}, | |
19840 | {"al", 0xe} | |
19841 | }; | |
bfae80f2 | 19842 | |
e797f7e0 | 19843 | #define UL_BARRIER(L,U,CODE,FEAT) \ |
823d2571 TG |
19844 | { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \ |
19845 | { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) } | |
e797f7e0 | 19846 | |
62b3e311 PB |
19847 | static struct asm_barrier_opt barrier_opt_names[] = |
19848 | { | |
e797f7e0 MGD |
19849 | UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER), |
19850 | UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER), | |
19851 | UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8), | |
19852 | UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER), | |
19853 | UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER), | |
19854 | UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER), | |
19855 | UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER), | |
19856 | UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8), | |
19857 | UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER), | |
19858 | UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER), | |
19859 | UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER), | |
19860 | UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER), | |
19861 | UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8), | |
19862 | UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER), | |
19863 | UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER), | |
19864 | UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8) | |
62b3e311 PB |
19865 | }; |
19866 | ||
e797f7e0 MGD |
19867 | #undef UL_BARRIER |
19868 | ||
c19d1205 ZW |
19869 | /* Table of ARM-format instructions. */ |
19870 | ||
19871 | /* Macros for gluing together operand strings. N.B. In all cases | |
19872 | other than OPS0, the trailing OP_stop comes from default | |
19873 | zero-initialization of the unspecified elements of the array. */ | |
19874 | #define OPS0() { OP_stop, } | |
19875 | #define OPS1(a) { OP_##a, } | |
19876 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
19877 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
19878 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
19879 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
19880 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
19881 | ||
5be8be5d DG |
19882 | /* These macros are similar to the OPSn, but do not prepend the OP_ prefix. |
19883 | This is useful when mixing operands for ARM and THUMB, i.e. using the | |
19884 | MIX_ARM_THUMB_OPERANDS macro. | |
19885 | In order to use these macros, prefix the number of operands with _ | |
19886 | e.g. _3. */ | |
19887 | #define OPS_1(a) { a, } | |
19888 | #define OPS_2(a,b) { a,b, } | |
19889 | #define OPS_3(a,b,c) { a,b,c, } | |
19890 | #define OPS_4(a,b,c,d) { a,b,c,d, } | |
19891 | #define OPS_5(a,b,c,d,e) { a,b,c,d,e, } | |
19892 | #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, } | |
19893 | ||
c19d1205 ZW |
19894 | /* These macros abstract out the exact format of the mnemonic table and |
19895 | save some repeated characters. */ | |
19896 | ||
19897 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
19898 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 19899 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 19900 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
19901 | |
19902 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
19903 | a T_MNEM_xyz enumerator. */ | |
19904 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
e07e6e58 | 19905 | TxCE (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 19906 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 19907 | TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 ZW |
19908 | |
19909 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
19910 | infix after the third character. */ | |
19911 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 19912 | { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 19913 | THUMB_VARIANT, do_##ae, do_##te } |
088fa78e | 19914 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 19915 | { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ |
088fa78e | 19916 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 | 19917 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 19918 | TxC3 (mnem, aop, 0x##top, nops, ops, ae, te) |
088fa78e | 19919 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 19920 | TxC3w (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 19921 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 19922 | TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
088fa78e | 19923 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 19924 | TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 | 19925 | |
c19d1205 | 19926 | /* Mnemonic that cannot be conditionalized. The ARM condition-code |
dfa9f0d5 PB |
19927 | field is still 0xE. Many of the Thumb variants can be executed |
19928 | conditionally, so this is checked separately. */ | |
c19d1205 | 19929 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 19930 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 19931 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 | 19932 | |
dd5181d5 KT |
19933 | /* Same as TUE but the encoding function for ARM and Thumb modes is the same. |
19934 | Used by mnemonics that have very minimal differences in the encoding for | |
19935 | ARM and Thumb variants and can be handled in a common function. */ | |
19936 | #define TUEc(mnem, op, top, nops, ops, en) \ | |
19937 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ | |
19938 | THUMB_VARIANT, do_##en, do_##en } | |
19939 | ||
c19d1205 ZW |
19940 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM |
19941 | condition code field. */ | |
19942 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 19943 | { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 19944 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
19945 | |
19946 | /* ARM-only variants of all the above. */ | |
6a86118a | 19947 | #define CE(mnem, op, nops, ops, ae) \ |
21d799b5 | 19948 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
6a86118a NC |
19949 | |
19950 | #define C3(mnem, op, nops, ops, ae) \ | |
19951 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
19952 | ||
cf3cf39d TP |
19953 | /* Thumb-only variants of TCE and TUE. */ |
19954 | #define ToC(mnem, top, nops, ops, te) \ | |
19955 | { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \ | |
19956 | do_##te } | |
cf3cf39d TP |
19957 | |
19958 | #define ToU(mnem, top, nops, ops, te) \ | |
19959 | { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \ | |
19960 | NULL, do_##te } | |
cf3cf39d | 19961 | |
4389b29a AV |
19962 | /* T_MNEM_xyz enumerator variants of ToC. */ |
19963 | #define toC(mnem, top, nops, ops, te) \ | |
19964 | { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \ | |
19965 | do_##te } | |
19966 | ||
f6b2b12d AV |
19967 | /* T_MNEM_xyz enumerator variants of ToU. */ |
19968 | #define toU(mnem, top, nops, ops, te) \ | |
19969 | { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \ | |
19970 | NULL, do_##te } | |
19971 | ||
e3cb604e PB |
19972 | /* Legacy mnemonics that always have conditional infix after the third |
19973 | character. */ | |
19974 | #define CL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 19975 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
19976 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
19977 | ||
8f06b2d8 PB |
19978 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
19979 | #define cCE(mnem, op, nops, ops, ae) \ | |
21d799b5 | 19980 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 19981 | |
e3cb604e PB |
19982 | /* Legacy coprocessor instructions where conditional infix and conditional |
19983 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
19984 | not just the potentially ambiguous ones. */ | |
19985 | #define cCL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 19986 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
19987 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
19988 | ||
19989 | /* Coprocessor, takes either a suffix or a position-3 infix | |
19990 | (for an FPA corner case). */ | |
19991 | #define C3E(mnem, op, nops, ops, ae) \ | |
21d799b5 | 19992 | { mnem, OPS##nops ops, OT_csuf_or_in3, \ |
e3cb604e | 19993 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 19994 | |
6a86118a | 19995 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
21d799b5 NC |
19996 | { m1 #m2 m3, OPS##nops ops, \ |
19997 | sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \ | |
6a86118a NC |
19998 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
19999 | ||
20000 | #define CM(m1, m2, op, nops, ops, ae) \ | |
e07e6e58 NC |
20001 | xCM_ (m1, , m2, op, nops, ops, ae), \ |
20002 | xCM_ (m1, eq, m2, op, nops, ops, ae), \ | |
20003 | xCM_ (m1, ne, m2, op, nops, ops, ae), \ | |
20004 | xCM_ (m1, cs, m2, op, nops, ops, ae), \ | |
20005 | xCM_ (m1, hs, m2, op, nops, ops, ae), \ | |
20006 | xCM_ (m1, cc, m2, op, nops, ops, ae), \ | |
20007 | xCM_ (m1, ul, m2, op, nops, ops, ae), \ | |
20008 | xCM_ (m1, lo, m2, op, nops, ops, ae), \ | |
20009 | xCM_ (m1, mi, m2, op, nops, ops, ae), \ | |
20010 | xCM_ (m1, pl, m2, op, nops, ops, ae), \ | |
20011 | xCM_ (m1, vs, m2, op, nops, ops, ae), \ | |
20012 | xCM_ (m1, vc, m2, op, nops, ops, ae), \ | |
20013 | xCM_ (m1, hi, m2, op, nops, ops, ae), \ | |
20014 | xCM_ (m1, ls, m2, op, nops, ops, ae), \ | |
20015 | xCM_ (m1, ge, m2, op, nops, ops, ae), \ | |
20016 | xCM_ (m1, lt, m2, op, nops, ops, ae), \ | |
20017 | xCM_ (m1, gt, m2, op, nops, ops, ae), \ | |
20018 | xCM_ (m1, le, m2, op, nops, ops, ae), \ | |
20019 | xCM_ (m1, al, m2, op, nops, ops, ae) | |
6a86118a NC |
20020 | |
20021 | #define UE(mnem, op, nops, ops, ae) \ | |
20022 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
20023 | ||
20024 | #define UF(mnem, op, nops, ops, ae) \ | |
20025 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
20026 | ||
5287ad62 JB |
20027 | /* Neon data-processing. ARM versions are unconditional with cond=0xf. |
20028 | The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we | |
20029 | use the same encoding function for each. */ | |
20030 | #define NUF(mnem, op, nops, ops, enc) \ | |
20031 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
20032 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
20033 | ||
20034 | /* Neon data processing, version which indirects through neon_enc_tab for | |
20035 | the various overloaded versions of opcodes. */ | |
20036 | #define nUF(mnem, op, nops, ops, enc) \ | |
21d799b5 | 20037 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
20038 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
20039 | ||
20040 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
20041 | version. */ | |
037e8744 JB |
20042 | #define NCE_tag(mnem, op, nops, ops, enc, tag) \ |
20043 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ | |
5287ad62 JB |
20044 | THUMB_VARIANT, do_##enc, do_##enc } |
20045 | ||
037e8744 | 20046 | #define NCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 20047 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
20048 | |
20049 | #define NCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 20050 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 20051 | |
5287ad62 | 20052 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
037e8744 | 20053 | #define nCE_tag(mnem, op, nops, ops, enc, tag) \ |
21d799b5 | 20054 | { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
20055 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
20056 | ||
037e8744 | 20057 | #define nCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 20058 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
20059 | |
20060 | #define nCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 20061 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 20062 | |
c19d1205 ZW |
20063 | #define do_0 0 |
20064 | ||
c19d1205 | 20065 | static const struct asm_opcode insns[] = |
bfae80f2 | 20066 | { |
74db7efb NC |
20067 | #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */ |
20068 | #define THUMB_VARIANT & arm_ext_v4t | |
21d799b5 NC |
20069 | tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c), |
20070 | tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
20071 | tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
20072 | tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
20073 | tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
20074 | tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
20075 | tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub), | |
20076 | tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub), | |
20077 | tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c), | |
20078 | tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
20079 | tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
20080 | tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
20081 | tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
20082 | tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
20083 | tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3), | |
20084 | tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3), | |
c19d1205 ZW |
20085 | |
20086 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
20087 | for setting PSR flag bits. They are obsolete in V6 and do not | |
20088 | have Thumb equivalents. */ | |
21d799b5 NC |
20089 | tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), |
20090 | tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), | |
20091 | CL("tstp", 110f000, 2, (RR, SH), cmp), | |
20092 | tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
20093 | tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
20094 | CL("cmpp", 150f000, 2, (RR, SH), cmp), | |
20095 | tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
20096 | tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
20097 | CL("cmnp", 170f000, 2, (RR, SH), cmp), | |
20098 | ||
20099 | tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp), | |
72d98d16 | 20100 | tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp), |
21d799b5 NC |
20101 | tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst), |
20102 | tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst), | |
20103 | ||
20104 | tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
5be8be5d DG |
20105 | tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), |
20106 | tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR, | |
20107 | OP_RRnpc), | |
20108 | OP_ADDRGLDR),ldst, t_ldst), | |
20109 | tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), | |
21d799b5 NC |
20110 | |
20111 | tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
20112 | tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
20113 | tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
20114 | tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
20115 | tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
20116 | tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
20117 | ||
21d799b5 NC |
20118 | tCE("b", a000000, _b, 1, (EXPr), branch, t_branch), |
20119 | TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23), | |
bfae80f2 | 20120 | |
c19d1205 | 20121 | /* Pseudo ops. */ |
21d799b5 | 20122 | tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac | 20123 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
21d799b5 | 20124 | tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop), |
74db7efb | 20125 | tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf), |
c19d1205 ZW |
20126 | |
20127 | /* Thumb-compatibility pseudo ops. */ | |
21d799b5 NC |
20128 | tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift), |
20129 | tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift), | |
20130 | tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift), | |
20131 | tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
20132 | tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift), | |
20133 | tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift), | |
20134 | tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift), | |
20135 | tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift), | |
20136 | tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg), | |
20137 | tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg), | |
20138 | tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop), | |
20139 | tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop), | |
c19d1205 | 20140 | |
16a4cf17 | 20141 | /* These may simplify to neg. */ |
21d799b5 NC |
20142 | TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), |
20143 | TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16a4cf17 | 20144 | |
173205ca TP |
20145 | #undef THUMB_VARIANT |
20146 | #define THUMB_VARIANT & arm_ext_os | |
20147 | ||
20148 | TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi), | |
20149 | TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi), | |
20150 | ||
c921be7d NC |
20151 | #undef THUMB_VARIANT |
20152 | #define THUMB_VARIANT & arm_ext_v6 | |
20153 | ||
21d799b5 | 20154 | TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
20155 | |
20156 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
c921be7d NC |
20157 | #undef THUMB_VARIANT |
20158 | #define THUMB_VARIANT & arm_ext_v6t2 | |
20159 | ||
21d799b5 NC |
20160 | TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
20161 | TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
20162 | CL("teqp", 130f000, 2, (RR, SH), cmp), | |
c19d1205 | 20163 | |
5be8be5d DG |
20164 | TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), |
20165 | TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
20166 | TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt), | |
20167 | TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
c19d1205 | 20168 | |
21d799b5 NC |
20169 | TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
20170 | TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 20171 | |
21d799b5 NC |
20172 | TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
20173 | TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
20174 | |
20175 | /* V1 instructions with no Thumb analogue at all. */ | |
21d799b5 | 20176 | CE("rsc", 0e00000, 3, (RR, oRR, SH), arit), |
c19d1205 ZW |
20177 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), |
20178 | ||
20179 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
20180 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
20181 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
20182 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
20183 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
20184 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
20185 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
20186 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
20187 | ||
c921be7d NC |
20188 | #undef ARM_VARIANT |
20189 | #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */ | |
20190 | #undef THUMB_VARIANT | |
20191 | #define THUMB_VARIANT & arm_ext_v4t | |
20192 | ||
21d799b5 NC |
20193 | tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
20194 | tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
c19d1205 | 20195 | |
c921be7d NC |
20196 | #undef THUMB_VARIANT |
20197 | #define THUMB_VARIANT & arm_ext_v6t2 | |
20198 | ||
21d799b5 | 20199 | TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
c19d1205 ZW |
20200 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), |
20201 | ||
20202 | /* Generic coprocessor instructions. */ | |
21d799b5 NC |
20203 | TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), |
20204 | TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
20205 | TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
20206 | TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
20207 | TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
20208 | TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
db472d6f | 20209 | TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg), |
c19d1205 | 20210 | |
c921be7d NC |
20211 | #undef ARM_VARIANT |
20212 | #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */ | |
20213 | ||
21d799b5 | 20214 | CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
c19d1205 ZW |
20215 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
20216 | ||
c921be7d NC |
20217 | #undef ARM_VARIANT |
20218 | #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */ | |
20219 | #undef THUMB_VARIANT | |
20220 | #define THUMB_VARIANT & arm_ext_msr | |
20221 | ||
d2cd1205 JB |
20222 | TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs), |
20223 | TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr), | |
c19d1205 | 20224 | |
c921be7d NC |
20225 | #undef ARM_VARIANT |
20226 | #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */ | |
20227 | #undef THUMB_VARIANT | |
20228 | #define THUMB_VARIANT & arm_ext_v6t2 | |
20229 | ||
21d799b5 NC |
20230 | TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
20231 | CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
20232 | TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
20233 | CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
20234 | TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
20235 | CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
20236 | TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
20237 | CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
c19d1205 | 20238 | |
c921be7d NC |
20239 | #undef ARM_VARIANT |
20240 | #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */ | |
20241 | #undef THUMB_VARIANT | |
20242 | #define THUMB_VARIANT & arm_ext_v4t | |
20243 | ||
5be8be5d DG |
20244 | tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
20245 | tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
20246 | tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
20247 | tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
56c0a61f RE |
20248 | tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
20249 | tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 | 20250 | |
c921be7d NC |
20251 | #undef ARM_VARIANT |
20252 | #define ARM_VARIANT & arm_ext_v4t_5 | |
20253 | ||
c19d1205 ZW |
20254 | /* ARM Architecture 4T. */ |
20255 | /* Note: bx (and blx) are required on V5, even if the processor does | |
20256 | not support Thumb. */ | |
21d799b5 | 20257 | TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx), |
c19d1205 | 20258 | |
c921be7d NC |
20259 | #undef ARM_VARIANT |
20260 | #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */ | |
20261 | #undef THUMB_VARIANT | |
20262 | #define THUMB_VARIANT & arm_ext_v5t | |
20263 | ||
c19d1205 ZW |
20264 | /* Note: blx has 2 variants; the .value coded here is for |
20265 | BLX(2). Only this variant has conditional execution. */ | |
21d799b5 NC |
20266 | TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx), |
20267 | TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
c19d1205 | 20268 | |
c921be7d NC |
20269 | #undef THUMB_VARIANT |
20270 | #define THUMB_VARIANT & arm_ext_v6t2 | |
20271 | ||
21d799b5 NC |
20272 | TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
20273 | TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
20274 | TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
20275 | TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
20276 | TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
20277 | TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
20278 | TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
20279 | TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
c19d1205 | 20280 | |
c921be7d | 20281 | #undef ARM_VARIANT |
74db7efb NC |
20282 | #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */ |
20283 | #undef THUMB_VARIANT | |
20284 | #define THUMB_VARIANT & arm_ext_v5exp | |
c921be7d | 20285 | |
21d799b5 NC |
20286 | TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
20287 | TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
20288 | TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
20289 | TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 20290 | |
21d799b5 NC |
20291 | TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
20292 | TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 20293 | |
21d799b5 NC |
20294 | TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), |
20295 | TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
20296 | TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
20297 | TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
c19d1205 | 20298 | |
21d799b5 NC |
20299 | TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
20300 | TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20301 | TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20302 | TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 20303 | |
21d799b5 NC |
20304 | TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
20305 | TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 20306 | |
03ee1b7f NC |
20307 | TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), |
20308 | TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
20309 | TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
20310 | TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
c19d1205 | 20311 | |
c921be7d | 20312 | #undef ARM_VARIANT |
74db7efb NC |
20313 | #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */ |
20314 | #undef THUMB_VARIANT | |
20315 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 20316 | |
21d799b5 | 20317 | TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld), |
5be8be5d DG |
20318 | TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS), |
20319 | ldrd, t_ldstd), | |
20320 | TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp, | |
20321 | ADDRGLDRS), ldrd, t_ldstd), | |
c19d1205 | 20322 | |
21d799b5 NC |
20323 | TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
20324 | TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
c19d1205 | 20325 | |
c921be7d NC |
20326 | #undef ARM_VARIANT |
20327 | #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */ | |
20328 | ||
21d799b5 | 20329 | TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
c19d1205 | 20330 | |
c921be7d NC |
20331 | #undef ARM_VARIANT |
20332 | #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */ | |
20333 | #undef THUMB_VARIANT | |
20334 | #define THUMB_VARIANT & arm_ext_v6 | |
20335 | ||
21d799b5 NC |
20336 | TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
20337 | TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
20338 | tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
20339 | tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
20340 | tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
20341 | tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
20342 | tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
20343 | tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
20344 | tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
20345 | TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend), | |
c19d1205 | 20346 | |
c921be7d | 20347 | #undef THUMB_VARIANT |
ff8646ee | 20348 | #define THUMB_VARIANT & arm_ext_v6t2_v8m |
c921be7d | 20349 | |
5be8be5d DG |
20350 | TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex), |
20351 | TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
20352 | strex, t_strex), | |
ff8646ee TP |
20353 | #undef THUMB_VARIANT |
20354 | #define THUMB_VARIANT & arm_ext_v6t2 | |
20355 | ||
21d799b5 NC |
20356 | TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
20357 | TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 | 20358 | |
21d799b5 NC |
20359 | TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), |
20360 | TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
62b3e311 | 20361 | |
9e3c6df6 | 20362 | /* ARM V6 not included in V7M. */ |
c921be7d NC |
20363 | #undef THUMB_VARIANT |
20364 | #define THUMB_VARIANT & arm_ext_v6_notm | |
9e3c6df6 | 20365 | TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
d709e4e6 | 20366 | TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
9e3c6df6 PB |
20367 | UF(rfeib, 9900a00, 1, (RRw), rfe), |
20368 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
20369 | TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
20370 | TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
d709e4e6 RE |
20371 | UF(rfefa, 8100a00, 1, (RRw), rfe), |
20372 | TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
20373 | UF(rfeed, 9900a00, 1, (RRw), rfe), | |
9e3c6df6 | 20374 | TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 RE |
20375 | TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
20376 | TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), | |
9e3c6df6 | 20377 | UF(srsib, 9c00500, 2, (oRRw, I31w), srs), |
d709e4e6 | 20378 | UF(srsfa, 9c00500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 20379 | UF(srsda, 8400500, 2, (oRRw, I31w), srs), |
d709e4e6 | 20380 | UF(srsed, 8400500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 20381 | TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 | 20382 | TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
941c9cad | 20383 | TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
c921be7d | 20384 | |
9e3c6df6 PB |
20385 | /* ARM V6 not included in V7M (eg. integer SIMD). */ |
20386 | #undef THUMB_VARIANT | |
20387 | #define THUMB_VARIANT & arm_ext_v6_dsp | |
21d799b5 NC |
20388 | TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), |
20389 | TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
20390 | TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20391 | TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20392 | TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20393 | /* Old name for QASX. */ |
74db7efb | 20394 | TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 | 20395 | TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 20396 | /* Old name for QSAX. */ |
74db7efb | 20397 | TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
20398 | TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20399 | TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20400 | TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20401 | TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20402 | TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20403 | /* Old name for SASX. */ |
74db7efb | 20404 | TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
20405 | TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20406 | TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 20407 | TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 20408 | /* Old name for SHASX. */ |
21d799b5 | 20409 | TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
74db7efb | 20410 | TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 20411 | /* Old name for SHSAX. */ |
21d799b5 NC |
20412 | TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20413 | TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20414 | TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20415 | TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20416 | /* Old name for SSAX. */ |
74db7efb | 20417 | TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
20418 | TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20419 | TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20420 | TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20421 | TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20422 | TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20423 | /* Old name for UASX. */ |
74db7efb | 20424 | TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
20425 | TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20426 | TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 20427 | TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 20428 | /* Old name for UHASX. */ |
21d799b5 NC |
20429 | TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20430 | TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20431 | /* Old name for UHSAX. */ |
21d799b5 NC |
20432 | TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20433 | TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20434 | TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20435 | TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20436 | TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 20437 | TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 20438 | /* Old name for UQASX. */ |
21d799b5 NC |
20439 | TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20440 | TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20441 | /* Old name for UQSAX. */ |
21d799b5 NC |
20442 | TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20443 | TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20444 | TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20445 | TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20446 | TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20447 | /* Old name for USAX. */ |
74db7efb | 20448 | TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 | 20449 | TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
20450 | TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), |
20451 | TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
20452 | TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
20453 | TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
20454 | TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
20455 | TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
20456 | TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
20457 | TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
20458 | TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20459 | TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20460 | TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20461 | TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
20462 | TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
20463 | TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20464 | TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20465 | TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
20466 | TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
20467 | TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20468 | TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20469 | TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20470 | TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20471 | TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20472 | TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20473 | TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20474 | TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20475 | TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20476 | TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
21d799b5 NC |
20477 | TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), |
20478 | TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), | |
20479 | TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20480 | TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20481 | TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), | |
c19d1205 | 20482 | |
c921be7d | 20483 | #undef ARM_VARIANT |
55e8aae7 | 20484 | #define ARM_VARIANT & arm_ext_v6k_v6t2 |
c921be7d | 20485 | #undef THUMB_VARIANT |
55e8aae7 | 20486 | #define THUMB_VARIANT & arm_ext_v6k_v6t2 |
c921be7d | 20487 | |
21d799b5 NC |
20488 | tCE("yield", 320f001, _yield, 0, (), noargs, t_hint), |
20489 | tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint), | |
20490 | tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint), | |
20491 | tCE("sev", 320f004, _sev, 0, (), noargs, t_hint), | |
c19d1205 | 20492 | |
c921be7d NC |
20493 | #undef THUMB_VARIANT |
20494 | #define THUMB_VARIANT & arm_ext_v6_notm | |
5be8be5d DG |
20495 | TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb), |
20496 | ldrexd, t_ldrexd), | |
20497 | TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp, | |
20498 | RRnpcb), strexd, t_strexd), | |
ebdca51a | 20499 | |
c921be7d | 20500 | #undef THUMB_VARIANT |
ff8646ee | 20501 | #define THUMB_VARIANT & arm_ext_v6t2_v8m |
5be8be5d DG |
20502 | TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb), |
20503 | rd_rn, rd_rn), | |
20504 | TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb), | |
20505 | rd_rn, rd_rn), | |
20506 | TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
877807f8 | 20507 | strex, t_strexbh), |
5be8be5d | 20508 | TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), |
877807f8 | 20509 | strex, t_strexbh), |
21d799b5 | 20510 | TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
c19d1205 | 20511 | |
c921be7d | 20512 | #undef ARM_VARIANT |
f4c65163 | 20513 | #define ARM_VARIANT & arm_ext_sec |
74db7efb | 20514 | #undef THUMB_VARIANT |
f4c65163 | 20515 | #define THUMB_VARIANT & arm_ext_sec |
c921be7d | 20516 | |
21d799b5 | 20517 | TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 | 20518 | |
90ec0d68 MGD |
20519 | #undef ARM_VARIANT |
20520 | #define ARM_VARIANT & arm_ext_virt | |
20521 | #undef THUMB_VARIANT | |
20522 | #define THUMB_VARIANT & arm_ext_virt | |
20523 | ||
20524 | TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc), | |
20525 | TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs), | |
20526 | ||
ddfded2f MW |
20527 | #undef ARM_VARIANT |
20528 | #define ARM_VARIANT & arm_ext_pan | |
20529 | #undef THUMB_VARIANT | |
20530 | #define THUMB_VARIANT & arm_ext_pan | |
20531 | ||
20532 | TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan), | |
20533 | ||
c921be7d | 20534 | #undef ARM_VARIANT |
74db7efb | 20535 | #define ARM_VARIANT & arm_ext_v6t2 |
f4c65163 MGD |
20536 | #undef THUMB_VARIANT |
20537 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 20538 | |
21d799b5 NC |
20539 | TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
20540 | TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
20541 | TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
20542 | TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
c19d1205 | 20543 | |
21d799b5 | 20544 | TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
21d799b5 | 20545 | TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), |
c19d1205 | 20546 | |
5be8be5d DG |
20547 | TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), |
20548 | TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
20549 | TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
20550 | TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
c19d1205 | 20551 | |
91d8b670 JG |
20552 | #undef ARM_VARIANT |
20553 | #define ARM_VARIANT & arm_ext_v3 | |
20554 | #undef THUMB_VARIANT | |
20555 | #define THUMB_VARIANT & arm_ext_v6t2 | |
20556 | ||
20557 | TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb), | |
c597cc3d SD |
20558 | TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb), |
20559 | TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb), | |
91d8b670 JG |
20560 | |
20561 | #undef ARM_VARIANT | |
20562 | #define ARM_VARIANT & arm_ext_v6t2 | |
ff8646ee TP |
20563 | #undef THUMB_VARIANT |
20564 | #define THUMB_VARIANT & arm_ext_v6t2_v8m | |
20565 | TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16), | |
20566 | TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16), | |
20567 | ||
bf3eeda7 | 20568 | /* Thumb-only instructions. */ |
74db7efb | 20569 | #undef ARM_VARIANT |
bf3eeda7 NS |
20570 | #define ARM_VARIANT NULL |
20571 | TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz), | |
20572 | TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz), | |
c921be7d NC |
20573 | |
20574 | /* ARM does not really have an IT instruction, so always allow it. | |
20575 | The opcode is copied from Thumb in order to allow warnings in | |
20576 | -mimplicit-it=[never | arm] modes. */ | |
20577 | #undef ARM_VARIANT | |
20578 | #define ARM_VARIANT & arm_ext_v1 | |
ff8646ee TP |
20579 | #undef THUMB_VARIANT |
20580 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 20581 | |
21d799b5 NC |
20582 | TUE("it", bf08, bf08, 1, (COND), it, t_it), |
20583 | TUE("itt", bf0c, bf0c, 1, (COND), it, t_it), | |
20584 | TUE("ite", bf04, bf04, 1, (COND), it, t_it), | |
20585 | TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it), | |
20586 | TUE("itet", bf06, bf06, 1, (COND), it, t_it), | |
20587 | TUE("itte", bf0a, bf0a, 1, (COND), it, t_it), | |
20588 | TUE("itee", bf02, bf02, 1, (COND), it, t_it), | |
20589 | TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it), | |
20590 | TUE("itett", bf07, bf07, 1, (COND), it, t_it), | |
20591 | TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it), | |
20592 | TUE("iteet", bf03, bf03, 1, (COND), it, t_it), | |
20593 | TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it), | |
20594 | TUE("itete", bf05, bf05, 1, (COND), it, t_it), | |
20595 | TUE("ittee", bf09, bf09, 1, (COND), it, t_it), | |
20596 | TUE("iteee", bf01, bf01, 1, (COND), it, t_it), | |
1c444d06 | 20597 | /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */ |
21d799b5 NC |
20598 | TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx), |
20599 | TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx), | |
c19d1205 | 20600 | |
92e90b6e | 20601 | /* Thumb2 only instructions. */ |
c921be7d NC |
20602 | #undef ARM_VARIANT |
20603 | #define ARM_VARIANT NULL | |
92e90b6e | 20604 | |
21d799b5 NC |
20605 | TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), |
20606 | TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
20607 | TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn), | |
20608 | TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn), | |
20609 | TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb), | |
20610 | TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb), | |
92e90b6e | 20611 | |
eea54501 MGD |
20612 | /* Hardware division instructions. */ |
20613 | #undef ARM_VARIANT | |
20614 | #define ARM_VARIANT & arm_ext_adiv | |
c921be7d NC |
20615 | #undef THUMB_VARIANT |
20616 | #define THUMB_VARIANT & arm_ext_div | |
20617 | ||
eea54501 MGD |
20618 | TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div), |
20619 | TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div), | |
62b3e311 | 20620 | |
7e806470 | 20621 | /* ARM V6M/V7 instructions. */ |
c921be7d NC |
20622 | #undef ARM_VARIANT |
20623 | #define ARM_VARIANT & arm_ext_barrier | |
20624 | #undef THUMB_VARIANT | |
20625 | #define THUMB_VARIANT & arm_ext_barrier | |
20626 | ||
ccb84d65 JB |
20627 | TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier), |
20628 | TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier), | |
20629 | TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier), | |
7e806470 | 20630 | |
62b3e311 | 20631 | /* ARM V7 instructions. */ |
c921be7d NC |
20632 | #undef ARM_VARIANT |
20633 | #define ARM_VARIANT & arm_ext_v7 | |
20634 | #undef THUMB_VARIANT | |
20635 | #define THUMB_VARIANT & arm_ext_v7 | |
20636 | ||
21d799b5 NC |
20637 | TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld), |
20638 | TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
62b3e311 | 20639 | |
74db7efb | 20640 | #undef ARM_VARIANT |
60e5ef9f | 20641 | #define ARM_VARIANT & arm_ext_mp |
74db7efb | 20642 | #undef THUMB_VARIANT |
60e5ef9f MGD |
20643 | #define THUMB_VARIANT & arm_ext_mp |
20644 | ||
20645 | TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld), | |
20646 | ||
53c4b28b MGD |
20647 | /* AArchv8 instructions. */ |
20648 | #undef ARM_VARIANT | |
20649 | #define ARM_VARIANT & arm_ext_v8 | |
4ed7ed8d TP |
20650 | |
20651 | /* Instructions shared between armv8-a and armv8-m. */ | |
53c4b28b | 20652 | #undef THUMB_VARIANT |
4ed7ed8d | 20653 | #define THUMB_VARIANT & arm_ext_atomics |
53c4b28b | 20654 | |
4ed7ed8d TP |
20655 | TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
20656 | TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
20657 | TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
20658 | TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
20659 | TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
20660 | TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
4b8c8c02 | 20661 | TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
4b8c8c02 RE |
20662 | TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn), |
20663 | TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
20664 | TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb), | |
20665 | stlex, t_stlex), | |
4b8c8c02 RE |
20666 | TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb), |
20667 | stlex, t_stlex), | |
20668 | TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb), | |
20669 | stlex, t_stlex), | |
4ed7ed8d TP |
20670 | #undef THUMB_VARIANT |
20671 | #define THUMB_VARIANT & arm_ext_v8 | |
53c4b28b | 20672 | |
4ed7ed8d | 20673 | tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint), |
4ed7ed8d TP |
20674 | TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb), |
20675 | ldrexd, t_ldrexd), | |
20676 | TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), | |
20677 | strexd, t_strexd), | |
f7dd2fb2 TC |
20678 | |
20679 | /* Defined in V8 but is in undefined encoding space for earlier | |
20680 | architectures. However earlier architectures are required to treat | |
20681 | this instuction as a semihosting trap as well. Hence while not explicitly | |
20682 | defined as such, it is in fact correct to define the instruction for all | |
20683 | architectures. */ | |
20684 | #undef THUMB_VARIANT | |
20685 | #define THUMB_VARIANT & arm_ext_v1 | |
20686 | #undef ARM_VARIANT | |
20687 | #define ARM_VARIANT & arm_ext_v1 | |
20688 | TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt), | |
20689 | ||
8884b720 | 20690 | /* ARMv8 T32 only. */ |
74db7efb | 20691 | #undef ARM_VARIANT |
b79f7053 MGD |
20692 | #define ARM_VARIANT NULL |
20693 | TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs), | |
20694 | TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs), | |
20695 | TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs), | |
20696 | ||
33399f07 MGD |
20697 | /* FP for ARMv8. */ |
20698 | #undef ARM_VARIANT | |
a715796b | 20699 | #define ARM_VARIANT & fpu_vfp_ext_armv8xd |
33399f07 | 20700 | #undef THUMB_VARIANT |
a715796b | 20701 | #define THUMB_VARIANT & fpu_vfp_ext_armv8xd |
33399f07 MGD |
20702 | |
20703 | nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel), | |
20704 | nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel), | |
20705 | nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel), | |
20706 | nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel), | |
73924fbc MGD |
20707 | nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm), |
20708 | nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm), | |
7e8e6784 MGD |
20709 | nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta), |
20710 | nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn), | |
20711 | nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp), | |
20712 | nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm), | |
30bdf752 MGD |
20713 | nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr), |
20714 | nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz), | |
20715 | nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx), | |
20716 | nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta), | |
20717 | nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn), | |
20718 | nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp), | |
20719 | nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm), | |
33399f07 | 20720 | |
91ff7894 MGD |
20721 | /* Crypto v1 extensions. */ |
20722 | #undef ARM_VARIANT | |
20723 | #define ARM_VARIANT & fpu_crypto_ext_armv8 | |
20724 | #undef THUMB_VARIANT | |
20725 | #define THUMB_VARIANT & fpu_crypto_ext_armv8 | |
20726 | ||
20727 | nUF(aese, _aes, 2, (RNQ, RNQ), aese), | |
20728 | nUF(aesd, _aes, 2, (RNQ, RNQ), aesd), | |
20729 | nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc), | |
20730 | nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc), | |
48adcd8e MGD |
20731 | nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c), |
20732 | nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p), | |
20733 | nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m), | |
20734 | nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0), | |
20735 | nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h), | |
20736 | nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2), | |
20737 | nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1), | |
3c9017d2 MGD |
20738 | nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h), |
20739 | nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1), | |
20740 | nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0), | |
91ff7894 | 20741 | |
dd5181d5 | 20742 | #undef ARM_VARIANT |
74db7efb | 20743 | #define ARM_VARIANT & crc_ext_armv8 |
dd5181d5 KT |
20744 | #undef THUMB_VARIANT |
20745 | #define THUMB_VARIANT & crc_ext_armv8 | |
20746 | TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b), | |
20747 | TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h), | |
20748 | TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w), | |
20749 | TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb), | |
20750 | TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch), | |
20751 | TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw), | |
20752 | ||
105bde57 MW |
20753 | /* ARMv8.2 RAS extension. */ |
20754 | #undef ARM_VARIANT | |
4d1464f2 | 20755 | #define ARM_VARIANT & arm_ext_ras |
105bde57 | 20756 | #undef THUMB_VARIANT |
4d1464f2 | 20757 | #define THUMB_VARIANT & arm_ext_ras |
105bde57 MW |
20758 | TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs), |
20759 | ||
49e8a725 SN |
20760 | #undef ARM_VARIANT |
20761 | #define ARM_VARIANT & arm_ext_v8_3 | |
20762 | #undef THUMB_VARIANT | |
20763 | #define THUMB_VARIANT & arm_ext_v8_3 | |
20764 | NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt), | |
c28eeff2 SN |
20765 | NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla), |
20766 | NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd), | |
49e8a725 | 20767 | |
c604a79a JW |
20768 | #undef ARM_VARIANT |
20769 | #define ARM_VARIANT & fpu_neon_ext_dotprod | |
20770 | #undef THUMB_VARIANT | |
20771 | #define THUMB_VARIANT & fpu_neon_ext_dotprod | |
20772 | NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s), | |
20773 | NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u), | |
20774 | ||
c921be7d NC |
20775 | #undef ARM_VARIANT |
20776 | #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ | |
53c4b28b MGD |
20777 | #undef THUMB_VARIANT |
20778 | #define THUMB_VARIANT NULL | |
c921be7d | 20779 | |
21d799b5 NC |
20780 | cCE("wfs", e200110, 1, (RR), rd), |
20781 | cCE("rfs", e300110, 1, (RR), rd), | |
20782 | cCE("wfc", e400110, 1, (RR), rd), | |
20783 | cCE("rfc", e500110, 1, (RR), rd), | |
20784 | ||
20785 | cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20786 | cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20787 | cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20788 | cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20789 | ||
20790 | cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20791 | cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20792 | cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20793 | cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20794 | ||
20795 | cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm), | |
20796 | cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm), | |
20797 | cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm), | |
20798 | cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm), | |
20799 | cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm), | |
20800 | cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm), | |
20801 | cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm), | |
20802 | cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm), | |
20803 | cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm), | |
20804 | cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm), | |
20805 | cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm), | |
20806 | cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm), | |
20807 | ||
20808 | cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm), | |
20809 | cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm), | |
20810 | cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm), | |
20811 | cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm), | |
20812 | cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm), | |
20813 | cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm), | |
20814 | cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm), | |
20815 | cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm), | |
20816 | cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm), | |
20817 | cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm), | |
20818 | cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm), | |
20819 | cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm), | |
20820 | ||
20821 | cCL("abss", e208100, 2, (RF, RF_IF), rd_rm), | |
20822 | cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm), | |
20823 | cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm), | |
20824 | cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm), | |
20825 | cCL("absd", e208180, 2, (RF, RF_IF), rd_rm), | |
20826 | cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm), | |
20827 | cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm), | |
20828 | cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm), | |
20829 | cCL("abse", e288100, 2, (RF, RF_IF), rd_rm), | |
20830 | cCL("absep", e288120, 2, (RF, RF_IF), rd_rm), | |
20831 | cCL("absem", e288140, 2, (RF, RF_IF), rd_rm), | |
20832 | cCL("absez", e288160, 2, (RF, RF_IF), rd_rm), | |
20833 | ||
20834 | cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm), | |
20835 | cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm), | |
20836 | cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm), | |
20837 | cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm), | |
20838 | cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm), | |
20839 | cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm), | |
20840 | cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm), | |
20841 | cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm), | |
20842 | cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm), | |
20843 | cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm), | |
20844 | cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm), | |
20845 | cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm), | |
20846 | ||
20847 | cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm), | |
20848 | cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm), | |
20849 | cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm), | |
20850 | cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm), | |
20851 | cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm), | |
20852 | cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm), | |
20853 | cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm), | |
20854 | cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm), | |
20855 | cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm), | |
20856 | cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm), | |
20857 | cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm), | |
20858 | cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm), | |
20859 | ||
20860 | cCL("logs", e508100, 2, (RF, RF_IF), rd_rm), | |
20861 | cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm), | |
20862 | cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm), | |
20863 | cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm), | |
20864 | cCL("logd", e508180, 2, (RF, RF_IF), rd_rm), | |
20865 | cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm), | |
20866 | cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm), | |
20867 | cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm), | |
20868 | cCL("loge", e588100, 2, (RF, RF_IF), rd_rm), | |
20869 | cCL("logep", e588120, 2, (RF, RF_IF), rd_rm), | |
20870 | cCL("logem", e588140, 2, (RF, RF_IF), rd_rm), | |
20871 | cCL("logez", e588160, 2, (RF, RF_IF), rd_rm), | |
20872 | ||
20873 | cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm), | |
20874 | cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm), | |
20875 | cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm), | |
20876 | cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm), | |
20877 | cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm), | |
20878 | cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm), | |
20879 | cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm), | |
20880 | cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm), | |
20881 | cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm), | |
20882 | cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm), | |
20883 | cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm), | |
20884 | cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm), | |
20885 | ||
20886 | cCL("exps", e708100, 2, (RF, RF_IF), rd_rm), | |
20887 | cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm), | |
20888 | cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm), | |
20889 | cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm), | |
20890 | cCL("expd", e708180, 2, (RF, RF_IF), rd_rm), | |
20891 | cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm), | |
20892 | cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm), | |
20893 | cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm), | |
20894 | cCL("expe", e788100, 2, (RF, RF_IF), rd_rm), | |
20895 | cCL("expep", e788120, 2, (RF, RF_IF), rd_rm), | |
20896 | cCL("expem", e788140, 2, (RF, RF_IF), rd_rm), | |
20897 | cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm), | |
20898 | ||
20899 | cCL("sins", e808100, 2, (RF, RF_IF), rd_rm), | |
20900 | cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm), | |
20901 | cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm), | |
20902 | cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm), | |
20903 | cCL("sind", e808180, 2, (RF, RF_IF), rd_rm), | |
20904 | cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm), | |
20905 | cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm), | |
20906 | cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm), | |
20907 | cCL("sine", e888100, 2, (RF, RF_IF), rd_rm), | |
20908 | cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm), | |
20909 | cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm), | |
20910 | cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm), | |
20911 | ||
20912 | cCL("coss", e908100, 2, (RF, RF_IF), rd_rm), | |
20913 | cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm), | |
20914 | cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm), | |
20915 | cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm), | |
20916 | cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm), | |
20917 | cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm), | |
20918 | cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm), | |
20919 | cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm), | |
20920 | cCL("cose", e988100, 2, (RF, RF_IF), rd_rm), | |
20921 | cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm), | |
20922 | cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm), | |
20923 | cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm), | |
20924 | ||
20925 | cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm), | |
20926 | cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm), | |
20927 | cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm), | |
20928 | cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm), | |
20929 | cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm), | |
20930 | cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm), | |
20931 | cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm), | |
20932 | cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm), | |
20933 | cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm), | |
20934 | cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm), | |
20935 | cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm), | |
20936 | cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm), | |
20937 | ||
20938 | cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm), | |
20939 | cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm), | |
20940 | cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm), | |
20941 | cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm), | |
20942 | cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm), | |
20943 | cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm), | |
20944 | cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm), | |
20945 | cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm), | |
20946 | cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm), | |
20947 | cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm), | |
20948 | cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm), | |
20949 | cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm), | |
20950 | ||
20951 | cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm), | |
20952 | cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm), | |
20953 | cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm), | |
20954 | cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm), | |
20955 | cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm), | |
20956 | cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm), | |
20957 | cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm), | |
20958 | cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm), | |
20959 | cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm), | |
20960 | cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm), | |
20961 | cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm), | |
20962 | cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm), | |
20963 | ||
20964 | cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm), | |
20965 | cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm), | |
20966 | cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm), | |
20967 | cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm), | |
20968 | cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm), | |
20969 | cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm), | |
20970 | cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm), | |
20971 | cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm), | |
20972 | cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm), | |
20973 | cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm), | |
20974 | cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm), | |
20975 | cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm), | |
20976 | ||
20977 | cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm), | |
20978 | cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm), | |
20979 | cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm), | |
20980 | cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm), | |
20981 | cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm), | |
20982 | cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm), | |
20983 | cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm), | |
20984 | cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm), | |
20985 | cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm), | |
20986 | cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm), | |
20987 | cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm), | |
20988 | cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm), | |
20989 | ||
20990 | cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm), | |
20991 | cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm), | |
20992 | cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm), | |
20993 | cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm), | |
20994 | cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm), | |
20995 | cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm), | |
20996 | cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm), | |
20997 | cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm), | |
20998 | cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm), | |
20999 | cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm), | |
21000 | cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm), | |
21001 | cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm), | |
21002 | ||
21003 | cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21004 | cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21005 | cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21006 | cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21007 | cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21008 | cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21009 | cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21010 | cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21011 | cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21012 | cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21013 | cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21014 | cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21015 | ||
21016 | cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21017 | cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21018 | cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21019 | cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21020 | cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21021 | cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21022 | cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21023 | cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21024 | cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21025 | cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21026 | cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21027 | cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21028 | ||
21029 | cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21030 | cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21031 | cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21032 | cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21033 | cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21034 | cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21035 | cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21036 | cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21037 | cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21038 | cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21039 | cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21040 | cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21041 | ||
21042 | cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21043 | cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21044 | cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21045 | cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21046 | cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21047 | cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21048 | cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21049 | cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21050 | cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21051 | cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21052 | cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21053 | cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21054 | ||
21055 | cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21056 | cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21057 | cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21058 | cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21059 | cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21060 | cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21061 | cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21062 | cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21063 | cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21064 | cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21065 | cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21066 | cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21067 | ||
21068 | cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21069 | cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21070 | cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21071 | cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21072 | cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21073 | cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21074 | cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21075 | cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21076 | cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21077 | cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21078 | cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21079 | cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21080 | ||
21081 | cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21082 | cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21083 | cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21084 | cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21085 | cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21086 | cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21087 | cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21088 | cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21089 | cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21090 | cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21091 | cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21092 | cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21093 | ||
21094 | cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21095 | cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21096 | cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21097 | cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21098 | cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21099 | cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21100 | cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21101 | cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21102 | cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21103 | cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21104 | cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21105 | cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21106 | ||
21107 | cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21108 | cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21109 | cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21110 | cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21111 | cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21112 | cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21113 | cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21114 | cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21115 | cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21116 | cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21117 | cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21118 | cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21119 | ||
21120 | cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21121 | cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21122 | cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21123 | cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21124 | cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21125 | cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21126 | cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21127 | cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21128 | cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21129 | cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21130 | cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21131 | cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21132 | ||
21133 | cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21134 | cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21135 | cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21136 | cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21137 | cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21138 | cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21139 | cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21140 | cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21141 | cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21142 | cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21143 | cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21144 | cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21145 | ||
21146 | cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21147 | cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21148 | cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21149 | cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21150 | cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21151 | cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21152 | cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21153 | cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21154 | cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21155 | cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21156 | cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21157 | cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21158 | ||
21159 | cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21160 | cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21161 | cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21162 | cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21163 | cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21164 | cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21165 | cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21166 | cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21167 | cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21168 | cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21169 | cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21170 | cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
21171 | ||
21172 | cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp), | |
21173 | C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp), | |
21174 | cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp), | |
21175 | C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp), | |
21176 | ||
21177 | cCL("flts", e000110, 2, (RF, RR), rn_rd), | |
21178 | cCL("fltsp", e000130, 2, (RF, RR), rn_rd), | |
21179 | cCL("fltsm", e000150, 2, (RF, RR), rn_rd), | |
21180 | cCL("fltsz", e000170, 2, (RF, RR), rn_rd), | |
21181 | cCL("fltd", e000190, 2, (RF, RR), rn_rd), | |
21182 | cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd), | |
21183 | cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd), | |
21184 | cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd), | |
21185 | cCL("flte", e080110, 2, (RF, RR), rn_rd), | |
21186 | cCL("fltep", e080130, 2, (RF, RR), rn_rd), | |
21187 | cCL("fltem", e080150, 2, (RF, RR), rn_rd), | |
21188 | cCL("fltez", e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 21189 | |
c19d1205 ZW |
21190 | /* The implementation of the FIX instruction is broken on some |
21191 | assemblers, in that it accepts a precision specifier as well as a | |
21192 | rounding specifier, despite the fact that this is meaningless. | |
21193 | To be more compatible, we accept it as well, though of course it | |
21194 | does not set any bits. */ | |
21d799b5 NC |
21195 | cCE("fix", e100110, 2, (RR, RF), rd_rm), |
21196 | cCL("fixp", e100130, 2, (RR, RF), rd_rm), | |
21197 | cCL("fixm", e100150, 2, (RR, RF), rd_rm), | |
21198 | cCL("fixz", e100170, 2, (RR, RF), rd_rm), | |
21199 | cCL("fixsp", e100130, 2, (RR, RF), rd_rm), | |
21200 | cCL("fixsm", e100150, 2, (RR, RF), rd_rm), | |
21201 | cCL("fixsz", e100170, 2, (RR, RF), rd_rm), | |
21202 | cCL("fixdp", e100130, 2, (RR, RF), rd_rm), | |
21203 | cCL("fixdm", e100150, 2, (RR, RF), rd_rm), | |
21204 | cCL("fixdz", e100170, 2, (RR, RF), rd_rm), | |
21205 | cCL("fixep", e100130, 2, (RR, RF), rd_rm), | |
21206 | cCL("fixem", e100150, 2, (RR, RF), rd_rm), | |
21207 | cCL("fixez", e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 21208 | |
c19d1205 | 21209 | /* Instructions that were new with the real FPA, call them V2. */ |
c921be7d NC |
21210 | #undef ARM_VARIANT |
21211 | #define ARM_VARIANT & fpu_fpa_ext_v2 | |
21212 | ||
21d799b5 NC |
21213 | cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
21214 | cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
21215 | cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
21216 | cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
21217 | cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
21218 | cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 | 21219 | |
c921be7d NC |
21220 | #undef ARM_VARIANT |
21221 | #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ | |
21222 | ||
c19d1205 | 21223 | /* Moves and type conversions. */ |
21d799b5 NC |
21224 | cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
21225 | cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
21226 | cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
21227 | cCE("fmstat", ef1fa10, 0, (), noargs), | |
7465e07a NC |
21228 | cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs), |
21229 | cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr), | |
21d799b5 NC |
21230 | cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), |
21231 | cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
21232 | cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
21233 | cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
21234 | cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
21235 | cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
21236 | cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn), | |
21237 | cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
21238 | |
21239 | /* Memory operations. */ | |
21d799b5 NC |
21240 | cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), |
21241 | cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), | |
55881a11 MGD |
21242 | cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), |
21243 | cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
21244 | cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
21245 | cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
21246 | cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
21247 | cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
21248 | cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
21249 | cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
21250 | cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
21251 | cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
21252 | cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
21253 | cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
21254 | cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
21255 | cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
21256 | cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
21257 | cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 21258 | |
c19d1205 | 21259 | /* Monadic operations. */ |
21d799b5 NC |
21260 | cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
21261 | cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
21262 | cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
21263 | |
21264 | /* Dyadic operations. */ | |
21d799b5 NC |
21265 | cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
21266 | cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
21267 | cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
21268 | cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
21269 | cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
21270 | cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
21271 | cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
21272 | cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
21273 | cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 21274 | |
c19d1205 | 21275 | /* Comparisons. */ |
21d799b5 NC |
21276 | cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
21277 | cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z), | |
21278 | cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
21279 | cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 21280 | |
62f3b8c8 PB |
21281 | /* Double precision load/store are still present on single precision |
21282 | implementations. */ | |
21283 | cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
21284 | cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
55881a11 MGD |
21285 | cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), |
21286 | cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
21287 | cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
21288 | cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
21289 | cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
21290 | cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
21291 | cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
21292 | cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
62f3b8c8 | 21293 | |
c921be7d NC |
21294 | #undef ARM_VARIANT |
21295 | #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ | |
21296 | ||
c19d1205 | 21297 | /* Moves and type conversions. */ |
21d799b5 NC |
21298 | cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
21299 | cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
21300 | cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
21301 | cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
21302 | cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
21303 | cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
21304 | cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
21305 | cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
21306 | cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
21307 | cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
21308 | cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
21309 | cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
21310 | cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 | 21311 | |
c19d1205 | 21312 | /* Monadic operations. */ |
21d799b5 NC |
21313 | cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm), |
21314 | cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm), | |
21315 | cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
c19d1205 ZW |
21316 | |
21317 | /* Dyadic operations. */ | |
21d799b5 NC |
21318 | cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), |
21319 | cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
21320 | cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
21321 | cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
21322 | cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
21323 | cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
21324 | cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
21325 | cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
21326 | cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
b99bd4ef | 21327 | |
c19d1205 | 21328 | /* Comparisons. */ |
21d799b5 NC |
21329 | cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
21330 | cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd), | |
21331 | cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
21332 | cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd), | |
c19d1205 | 21333 | |
c921be7d NC |
21334 | #undef ARM_VARIANT |
21335 | #define ARM_VARIANT & fpu_vfp_ext_v2 | |
21336 | ||
21d799b5 NC |
21337 | cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
21338 | cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
21339 | cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn), | |
21340 | cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm), | |
5287ad62 | 21341 | |
037e8744 JB |
21342 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
21343 | Individual encoder functions perform additional architecture checks. */ | |
c921be7d NC |
21344 | #undef ARM_VARIANT |
21345 | #define ARM_VARIANT & fpu_vfp_ext_v1xd | |
21346 | #undef THUMB_VARIANT | |
21347 | #define THUMB_VARIANT & fpu_vfp_ext_v1xd | |
21348 | ||
037e8744 JB |
21349 | /* These mnemonics are unique to VFP. */ |
21350 | NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt), | |
21351 | NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div), | |
21d799b5 NC |
21352 | nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), |
21353 | nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
21354 | nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
aacf0b33 KT |
21355 | nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp), |
21356 | nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp), | |
037e8744 JB |
21357 | NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push), |
21358 | NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop), | |
21359 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), | |
21360 | ||
21361 | /* Mnemonics shared by Neon and VFP. */ | |
21d799b5 NC |
21362 | nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul), |
21363 | nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
21364 | nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
037e8744 | 21365 | |
21d799b5 NC |
21366 | nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), |
21367 | nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
037e8744 JB |
21368 | |
21369 | NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
21370 | NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
21371 | ||
55881a11 MGD |
21372 | NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), |
21373 | NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
21374 | NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
21375 | NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
21376 | NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
21377 | NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
037e8744 | 21378 | |
5f1af56b | 21379 | nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt), |
e3e535bc | 21380 | nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr), |
c70a8987 MGD |
21381 | NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb), |
21382 | NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt), | |
f31fef98 | 21383 | |
037e8744 JB |
21384 | |
21385 | /* NOTE: All VMOV encoding is special-cased! */ | |
21386 | NCE(vmov, 0, 1, (VMOV), neon_mov), | |
21387 | NCE(vmovq, 0, 1, (VMOV), neon_mov), | |
21388 | ||
32c36c3c AV |
21389 | #undef THUMB_VARIANT |
21390 | /* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded | |
21391 | by different feature bits. Since we are setting the Thumb guard, we can | |
21392 | require Thumb-1 which makes it a nop guard and set the right feature bit in | |
21393 | do_vldr_vstr (). */ | |
21394 | #define THUMB_VARIANT & arm_ext_v4t | |
21395 | NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr), | |
21396 | NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr), | |
21397 | ||
9db2f6b4 RL |
21398 | #undef ARM_VARIANT |
21399 | #define ARM_VARIANT & arm_ext_fp16 | |
21400 | #undef THUMB_VARIANT | |
21401 | #define THUMB_VARIANT & arm_ext_fp16 | |
21402 | /* New instructions added from v8.2, allowing the extraction and insertion of | |
21403 | the upper 16 bits of a 32-bit vector register. */ | |
21404 | NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf), | |
21405 | NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf), | |
21406 | ||
dec41383 JW |
21407 | /* New backported fma/fms instructions optional in v8.2. */ |
21408 | NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal), | |
21409 | NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl), | |
21410 | ||
c921be7d NC |
21411 | #undef THUMB_VARIANT |
21412 | #define THUMB_VARIANT & fpu_neon_ext_v1 | |
21413 | #undef ARM_VARIANT | |
21414 | #define ARM_VARIANT & fpu_neon_ext_v1 | |
21415 | ||
5287ad62 JB |
21416 | /* Data processing with three registers of the same length. */ |
21417 | /* integer ops, valid types S8 S16 S32 U8 U16 U32. */ | |
21418 | NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su), | |
21419 | NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su), | |
21420 | NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
21421 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
21422 | NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
21423 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
21424 | NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
21425 | NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
21426 | /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */ | |
21427 | NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
21428 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
21429 | NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
21430 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
627907b7 JB |
21431 | NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), |
21432 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
21433 | NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), | |
21434 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
5287ad62 JB |
21435 | /* If not immediate, fall back to neon_dyadic_i64_su. |
21436 | shl_imm should accept I8 I16 I32 I64, | |
21437 | qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */ | |
21d799b5 NC |
21438 | nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm), |
21439 | nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm), | |
21440 | nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm), | |
21441 | nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm), | |
5287ad62 | 21442 | /* Logic ops, types optional & ignored. */ |
4316f0d2 DG |
21443 | nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), |
21444 | nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
21445 | nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
21446 | nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
21447 | nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
21448 | nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
21449 | nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
21450 | nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
21451 | nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic), | |
21452 | nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic), | |
5287ad62 JB |
21453 | /* Bitfield ops, untyped. */ |
21454 | NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
21455 | NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
21456 | NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
21457 | NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
21458 | NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
21459 | NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
cc933301 | 21460 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */ |
21d799b5 NC |
21461 | nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), |
21462 | nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
21463 | nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
21464 | nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
21465 | nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
21466 | nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
5287ad62 JB |
21467 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall |
21468 | back to neon_dyadic_if_su. */ | |
21d799b5 NC |
21469 | nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), |
21470 | nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
21471 | nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
21472 | nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
21473 | nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
21474 | nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
21475 | nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
21476 | nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
428e3f1f | 21477 | /* Comparison. Type I8 I16 I32 F32. */ |
21d799b5 NC |
21478 | nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), |
21479 | nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
5287ad62 | 21480 | /* As above, D registers only. */ |
21d799b5 NC |
21481 | nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d), |
21482 | nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
5287ad62 | 21483 | /* Int and float variants, signedness unimportant. */ |
21d799b5 NC |
21484 | nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
21485 | nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), | |
21486 | nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d), | |
5287ad62 | 21487 | /* Add/sub take types I8 I16 I32 I64 F32. */ |
21d799b5 NC |
21488 | nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
21489 | nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), | |
5287ad62 JB |
21490 | /* vtst takes sizes 8, 16, 32. */ |
21491 | NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst), | |
21492 | NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst), | |
21493 | /* VMUL takes I8 I16 I32 F32 P8. */ | |
21d799b5 | 21494 | nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 | 21495 | /* VQD{R}MULH takes S16 S32. */ |
21d799b5 NC |
21496 | nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), |
21497 | nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
21498 | nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
21499 | nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
5287ad62 JB |
21500 | NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), |
21501 | NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
21502 | NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
21503 | NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
92559b5b PB |
21504 | NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), |
21505 | NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
21506 | NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
21507 | NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
5287ad62 JB |
21508 | NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), |
21509 | NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
21510 | NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
21511 | NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
d6b4b13e | 21512 | /* ARM v8.1 extension. */ |
643afb90 MW |
21513 | nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah), |
21514 | nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah), | |
21515 | nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah), | |
21516 | nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah), | |
5287ad62 JB |
21517 | |
21518 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 21519 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
21520 | NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg), |
21521 | ||
21522 | /* Data processing with two registers and a shift amount. */ | |
21523 | /* Right shifts, and variants with rounding. | |
21524 | Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */ | |
21525 | NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
21526 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
21527 | NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
21528 | NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
21529 | NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
21530 | NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
21531 | NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
21532 | NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
21533 | /* Shift and insert. Sizes accepted 8 16 32 64. */ | |
21534 | NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli), | |
21535 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), | |
21536 | NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri), | |
21537 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), | |
21538 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
21539 | NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm), | |
21540 | NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm), | |
21541 | /* Right shift immediate, saturating & narrowing, with rounding variants. | |
21542 | Types accepted S16 S32 S64 U16 U32 U64. */ | |
21543 | NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
21544 | NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
21545 | /* As above, unsigned. Types accepted S16 S32 S64. */ | |
21546 | NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
21547 | NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
21548 | /* Right shift narrowing. Types accepted I16 I32 I64. */ | |
21549 | NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
21550 | NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
21551 | /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */ | |
21d799b5 | 21552 | nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll), |
5287ad62 | 21553 | /* CVT with optional immediate for fixed-point variant. */ |
21d799b5 | 21554 | nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 21555 | |
4316f0d2 DG |
21556 | nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn), |
21557 | nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn), | |
5287ad62 JB |
21558 | |
21559 | /* Data processing, three registers of different lengths. */ | |
21560 | /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */ | |
21561 | NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal), | |
21562 | NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long), | |
21563 | NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long), | |
21564 | NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long), | |
21565 | /* If not scalar, fall back to neon_dyadic_long. | |
21566 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
21d799b5 NC |
21567 | nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), |
21568 | nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
5287ad62 JB |
21569 | /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */ |
21570 | NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
21571 | NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
21572 | /* Dyadic, narrowing insns. Types I16 I32 I64. */ | |
21573 | NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
21574 | NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
21575 | NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
21576 | NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
21577 | /* Saturating doubling multiplies. Types S16 S32. */ | |
21d799b5 NC |
21578 | nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), |
21579 | nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
21580 | nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
5287ad62 JB |
21581 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types |
21582 | S16 S32 U16 U32. */ | |
21d799b5 | 21583 | nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), |
5287ad62 JB |
21584 | |
21585 | /* Extract. Size 8. */ | |
3b8d421e PB |
21586 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext), |
21587 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext), | |
5287ad62 JB |
21588 | |
21589 | /* Two registers, miscellaneous. */ | |
21590 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
21591 | NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev), | |
21592 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), | |
21593 | NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev), | |
21594 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), | |
21595 | NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev), | |
21596 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), | |
21597 | /* Vector replicate. Sizes 8 16 32. */ | |
21d799b5 NC |
21598 | nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup), |
21599 | nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup), | |
5287ad62 JB |
21600 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ |
21601 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
21602 | /* VMOVN. Types I16 I32 I64. */ | |
21d799b5 | 21603 | nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn), |
5287ad62 | 21604 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ |
21d799b5 | 21605 | nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn), |
5287ad62 | 21606 | /* VQMOVUN. Types S16 S32 S64. */ |
21d799b5 | 21607 | nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun), |
5287ad62 JB |
21608 | /* VZIP / VUZP. Sizes 8 16 32. */ |
21609 | NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
21610 | NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp), | |
21611 | NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
21612 | NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp), | |
21613 | /* VQABS / VQNEG. Types S8 S16 S32. */ | |
21614 | NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
21615 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
21616 | NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
21617 | NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
21618 | /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */ | |
21619 | NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long), | |
21620 | NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long), | |
21621 | NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long), | |
21622 | NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long), | |
cc933301 | 21623 | /* Reciprocal estimates. Types U32 F16 F32. */ |
5287ad62 JB |
21624 | NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est), |
21625 | NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est), | |
21626 | NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est), | |
21627 | NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est), | |
21628 | /* VCLS. Types S8 S16 S32. */ | |
21629 | NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls), | |
21630 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), | |
21631 | /* VCLZ. Types I8 I16 I32. */ | |
21632 | NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz), | |
21633 | NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz), | |
21634 | /* VCNT. Size 8. */ | |
21635 | NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt), | |
21636 | NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt), | |
21637 | /* Two address, untyped. */ | |
21638 | NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp), | |
21639 | NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp), | |
21640 | /* VTRN. Sizes 8 16 32. */ | |
21d799b5 NC |
21641 | nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn), |
21642 | nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn), | |
5287ad62 JB |
21643 | |
21644 | /* Table lookup. Size 8. */ | |
21645 | NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
21646 | NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
21647 | ||
c921be7d NC |
21648 | #undef THUMB_VARIANT |
21649 | #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext | |
21650 | #undef ARM_VARIANT | |
21651 | #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext | |
21652 | ||
5287ad62 | 21653 | /* Neon element/structure load/store. */ |
21d799b5 NC |
21654 | nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx), |
21655 | nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
21656 | nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
21657 | nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
21658 | nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
21659 | nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
21660 | nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
21661 | nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
5287ad62 | 21662 | |
c921be7d | 21663 | #undef THUMB_VARIANT |
74db7efb NC |
21664 | #define THUMB_VARIANT & fpu_vfp_ext_v3xd |
21665 | #undef ARM_VARIANT | |
21666 | #define ARM_VARIANT & fpu_vfp_ext_v3xd | |
62f3b8c8 PB |
21667 | cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const), |
21668 | cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
21669 | cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
21670 | cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
21671 | cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
21672 | cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
21673 | cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
21674 | cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
21675 | cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
21676 | ||
74db7efb | 21677 | #undef THUMB_VARIANT |
c921be7d NC |
21678 | #define THUMB_VARIANT & fpu_vfp_ext_v3 |
21679 | #undef ARM_VARIANT | |
21680 | #define ARM_VARIANT & fpu_vfp_ext_v3 | |
21681 | ||
21d799b5 | 21682 | cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const), |
21d799b5 | 21683 | cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 21684 | cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 21685 | cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 21686 | cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 21687 | cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 21688 | cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 21689 | cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 21690 | cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
c19d1205 | 21691 | |
74db7efb NC |
21692 | #undef ARM_VARIANT |
21693 | #define ARM_VARIANT & fpu_vfp_ext_fma | |
21694 | #undef THUMB_VARIANT | |
21695 | #define THUMB_VARIANT & fpu_vfp_ext_fma | |
62f3b8c8 PB |
21696 | /* Mnemonics shared by Neon and VFP. These are included in the |
21697 | VFP FMA variant; NEON and VFP FMA always includes the NEON | |
21698 | FMA instructions. */ | |
21699 | nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
21700 | nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
21701 | /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas; | |
21702 | the v form should always be used. */ | |
21703 | cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
21704 | cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
21705 | cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
21706 | cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
21707 | nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
21708 | nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
21709 | ||
5287ad62 | 21710 | #undef THUMB_VARIANT |
c921be7d NC |
21711 | #undef ARM_VARIANT |
21712 | #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */ | |
21713 | ||
21d799b5 NC |
21714 | cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
21715 | cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
21716 | cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
21717 | cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
21718 | cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
21719 | cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
21720 | cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
21721 | cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 | 21722 | |
c921be7d NC |
21723 | #undef ARM_VARIANT |
21724 | #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */ | |
21725 | ||
21d799b5 NC |
21726 | cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc), |
21727 | cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc), | |
21728 | cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc), | |
21729 | cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd), | |
21730 | cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd), | |
21731 | cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd), | |
21732 | cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc), | |
21733 | cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc), | |
21734 | cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc), | |
74db7efb NC |
21735 | cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), |
21736 | cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
21737 | cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
21738 | cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
21739 | cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
21740 | cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
21d799b5 NC |
21741 | cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), |
21742 | cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
21743 | cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
21744 | cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd), | |
21745 | cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn), | |
21746 | cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
21747 | cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
21748 | cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
21749 | cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
21750 | cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
21751 | cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
74db7efb NC |
21752 | cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn), |
21753 | cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn), | |
21754 | cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn), | |
21d799b5 NC |
21755 | cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn), |
21756 | cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm), | |
21757 | cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc), | |
21758 | cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc), | |
21759 | cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc), | |
21760 | cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn), | |
21761 | cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn), | |
21762 | cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn), | |
21763 | cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21764 | cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21765 | cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21766 | cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21767 | cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21768 | cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21769 | cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21770 | cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21771 | cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21772 | cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
74db7efb NC |
21773 | cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
21774 | cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21775 | cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21776 | cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
21777 | cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
21778 | cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21779 | cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21780 | cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21781 | cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21782 | cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21783 | cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21784 | cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21785 | cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
74db7efb NC |
21786 | cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
21787 | cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21788 | cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21789 | cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21790 | cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21791 | cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
21792 | cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), |
21793 | cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
21794 | cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
21795 | cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
21796 | cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21797 | cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21798 | cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21799 | cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21800 | cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21801 | cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21802 | cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21803 | cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21804 | cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21805 | cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21806 | cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21807 | cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21808 | cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21809 | cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21810 | cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21811 | cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21812 | cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21813 | cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21814 | cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
21815 | cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21816 | cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21817 | cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21818 | cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21819 | cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
74db7efb NC |
21820 | cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
21821 | cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21822 | cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21823 | cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21824 | cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21825 | cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
21826 | cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
21827 | cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21828 | cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21829 | cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21830 | cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21831 | cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21832 | cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21833 | cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21834 | cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21835 | cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21836 | cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
21837 | cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21838 | cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21839 | cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21840 | cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21841 | cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21842 | cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21843 | cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21844 | cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21845 | cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21846 | cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21847 | cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21848 | cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21849 | cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21850 | cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21851 | cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21852 | cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21853 | cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21854 | cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21855 | cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
21856 | cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
21857 | cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
21858 | cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
21859 | cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21860 | cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21861 | cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21862 | cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21863 | cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21864 | cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21865 | cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21866 | cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21867 | cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21868 | cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn), | |
21869 | cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn), | |
21870 | cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn), | |
21871 | cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn), | |
21872 | cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn), | |
21873 | cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn), | |
21874 | cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21875 | cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21876 | cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21877 | cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn), | |
21878 | cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn), | |
21879 | cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn), | |
21880 | cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn), | |
21881 | cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn), | |
21882 | cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn), | |
21883 | cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21884 | cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21885 | cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21886 | cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21887 | cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 | 21888 | |
c921be7d NC |
21889 | #undef ARM_VARIANT |
21890 | #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */ | |
21891 | ||
21d799b5 NC |
21892 | cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc), |
21893 | cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc), | |
21894 | cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc), | |
21895 | cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn), | |
21896 | cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn), | |
21897 | cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn), | |
21898 | cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21899 | cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21900 | cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21901 | cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21902 | cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21903 | cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21904 | cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21905 | cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21906 | cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21907 | cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21908 | cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21909 | cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21910 | cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21911 | cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21912 | cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge), | |
21913 | cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21914 | cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21915 | cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21916 | cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21917 | cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21918 | cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21919 | cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21920 | cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21921 | cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21922 | cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21923 | cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21924 | cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21925 | cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21926 | cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21927 | cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21928 | cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21929 | cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21930 | cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21931 | cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21932 | cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21933 | cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21934 | cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21935 | cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21936 | cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21937 | cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21938 | cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21939 | cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21940 | cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21941 | cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21942 | cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21943 | cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21944 | cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21945 | cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21946 | cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21947 | cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21948 | cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
2d447fca | 21949 | |
c921be7d NC |
21950 | #undef ARM_VARIANT |
21951 | #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */ | |
21952 | ||
21d799b5 NC |
21953 | cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr), |
21954 | cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
21955 | cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
21956 | cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
21957 | cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr), | |
21958 | cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
21959 | cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
21960 | cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
21961 | cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd), | |
21962 | cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn), | |
21963 | cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd), | |
21964 | cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn), | |
21965 | cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd), | |
21966 | cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn), | |
74db7efb NC |
21967 | cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd), |
21968 | cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn), | |
21969 | cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd), | |
21970 | cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn), | |
21971 | cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn), | |
21972 | cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn), | |
21973 | cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn), | |
21974 | cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn), | |
21975 | cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn), | |
21976 | cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn), | |
21d799b5 NC |
21977 | cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn), |
21978 | cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn), | |
21979 | cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn), | |
21980 | cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn), | |
74db7efb NC |
21981 | cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc), |
21982 | cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd), | |
21d799b5 NC |
21983 | cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn), |
21984 | cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn), | |
21985 | cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn), | |
21986 | cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn), | |
74db7efb NC |
21987 | cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn), |
21988 | cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn), | |
21989 | cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn), | |
21990 | cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn), | |
21991 | cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn), | |
21992 | cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn), | |
21d799b5 NC |
21993 | cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn), |
21994 | cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn), | |
74db7efb NC |
21995 | cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple), |
21996 | cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
21d799b5 NC |
21997 | cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift), |
21998 | cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
21999 | cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
22000 | cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
22001 | cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
22002 | cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
22003 | cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn), | |
22004 | cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn), | |
22005 | cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn), | |
22006 | cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn), | |
22007 | cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
22008 | cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
22009 | cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
22010 | cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
22011 | cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
22012 | cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
22013 | cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn), | |
22014 | cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn), | |
22015 | cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn), | |
22016 | cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn), | |
22017 | cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
22018 | cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
22019 | cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
22020 | cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
22021 | cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
22022 | cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
22023 | cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
22024 | cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
74db7efb NC |
22025 | cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), |
22026 | cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
21d799b5 NC |
22027 | cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), |
22028 | cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
4ed7ed8d | 22029 | |
7fadb25d SD |
22030 | /* ARMv8.5-A instructions. */ |
22031 | #undef ARM_VARIANT | |
22032 | #define ARM_VARIANT & arm_ext_sb | |
22033 | #undef THUMB_VARIANT | |
22034 | #define THUMB_VARIANT & arm_ext_sb | |
22035 | TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs), | |
22036 | ||
dad0c3bf SD |
22037 | #undef ARM_VARIANT |
22038 | #define ARM_VARIANT & arm_ext_predres | |
22039 | #undef THUMB_VARIANT | |
22040 | #define THUMB_VARIANT & arm_ext_predres | |
22041 | CE("cfprctx", e070f93, 1, (RRnpc), rd), | |
22042 | CE("dvprctx", e070fb3, 1, (RRnpc), rd), | |
22043 | CE("cpprctx", e070ff3, 1, (RRnpc), rd), | |
22044 | ||
16a1fa25 | 22045 | /* ARMv8-M instructions. */ |
4ed7ed8d TP |
22046 | #undef ARM_VARIANT |
22047 | #define ARM_VARIANT NULL | |
22048 | #undef THUMB_VARIANT | |
22049 | #define THUMB_VARIANT & arm_ext_v8m | |
cf3cf39d TP |
22050 | ToU("sg", e97fe97f, 0, (), noargs), |
22051 | ToC("blxns", 4784, 1, (RRnpc), t_blx), | |
22052 | ToC("bxns", 4704, 1, (RRnpc), t_bx), | |
22053 | ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt), | |
22054 | ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt), | |
22055 | ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt), | |
22056 | ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt), | |
16a1fa25 TP |
22057 | |
22058 | /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the | |
22059 | instructions behave as nop if no VFP is present. */ | |
22060 | #undef THUMB_VARIANT | |
22061 | #define THUMB_VARIANT & arm_ext_v8m_main | |
cf3cf39d TP |
22062 | ToC("vlldm", ec300a00, 1, (RRnpc), rn), |
22063 | ToC("vlstm", ec200a00, 1, (RRnpc), rn), | |
4389b29a AV |
22064 | |
22065 | /* Armv8.1-M Mainline instructions. */ | |
22066 | #undef THUMB_VARIANT | |
22067 | #define THUMB_VARIANT & arm_ext_v8_1m_main | |
22068 | toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future), | |
f6b2b12d | 22069 | toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future), |
f1c7f421 | 22070 | toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future), |
65d1bc05 | 22071 | toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future), |
f1c7f421 | 22072 | toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future), |
60f993ce AV |
22073 | |
22074 | toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop), | |
22075 | toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop), | |
22076 | toU("le", _le, 2, (oLR, EXP), t_loloop), | |
4b5a202f | 22077 | |
efd6b359 AV |
22078 | ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm), |
22079 | ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm) | |
c19d1205 ZW |
22080 | }; |
22081 | #undef ARM_VARIANT | |
22082 | #undef THUMB_VARIANT | |
22083 | #undef TCE | |
c19d1205 ZW |
22084 | #undef TUE |
22085 | #undef TUF | |
22086 | #undef TCC | |
8f06b2d8 | 22087 | #undef cCE |
e3cb604e PB |
22088 | #undef cCL |
22089 | #undef C3E | |
4389b29a | 22090 | #undef C3 |
c19d1205 ZW |
22091 | #undef CE |
22092 | #undef CM | |
4389b29a | 22093 | #undef CL |
c19d1205 ZW |
22094 | #undef UE |
22095 | #undef UF | |
22096 | #undef UT | |
5287ad62 JB |
22097 | #undef NUF |
22098 | #undef nUF | |
22099 | #undef NCE | |
22100 | #undef nCE | |
c19d1205 ZW |
22101 | #undef OPS0 |
22102 | #undef OPS1 | |
22103 | #undef OPS2 | |
22104 | #undef OPS3 | |
22105 | #undef OPS4 | |
22106 | #undef OPS5 | |
22107 | #undef OPS6 | |
22108 | #undef do_0 | |
4389b29a AV |
22109 | #undef ToC |
22110 | #undef toC | |
22111 | #undef ToU | |
f6b2b12d | 22112 | #undef toU |
c19d1205 ZW |
22113 | \f |
22114 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 22115 | |
c19d1205 ZW |
22116 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
22117 | for use in the a.out file, and stores them in the array pointed to by buf. | |
22118 | This knows about the endian-ness of the target machine and does | |
22119 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
22120 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
22121 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 22122 | |
c19d1205 ZW |
22123 | void |
22124 | md_number_to_chars (char * buf, valueT val, int n) | |
22125 | { | |
22126 | if (target_big_endian) | |
22127 | number_to_chars_bigendian (buf, val, n); | |
22128 | else | |
22129 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
22130 | } |
22131 | ||
c19d1205 ZW |
22132 | static valueT |
22133 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 22134 | { |
c19d1205 ZW |
22135 | valueT result = 0; |
22136 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 22137 | |
c19d1205 | 22138 | if (target_big_endian) |
b99bd4ef | 22139 | { |
c19d1205 ZW |
22140 | while (n--) |
22141 | { | |
22142 | result <<= 8; | |
22143 | result |= (*where++ & 255); | |
22144 | } | |
b99bd4ef | 22145 | } |
c19d1205 | 22146 | else |
b99bd4ef | 22147 | { |
c19d1205 ZW |
22148 | while (n--) |
22149 | { | |
22150 | result <<= 8; | |
22151 | result |= (where[n] & 255); | |
22152 | } | |
bfae80f2 | 22153 | } |
b99bd4ef | 22154 | |
c19d1205 | 22155 | return result; |
bfae80f2 | 22156 | } |
b99bd4ef | 22157 | |
c19d1205 | 22158 | /* MD interface: Sections. */ |
b99bd4ef | 22159 | |
fa94de6b RM |
22160 | /* Calculate the maximum variable size (i.e., excluding fr_fix) |
22161 | that an rs_machine_dependent frag may reach. */ | |
22162 | ||
22163 | unsigned int | |
22164 | arm_frag_max_var (fragS *fragp) | |
22165 | { | |
22166 | /* We only use rs_machine_dependent for variable-size Thumb instructions, | |
22167 | which are either THUMB_SIZE (2) or INSN_SIZE (4). | |
22168 | ||
22169 | Note that we generate relaxable instructions even for cases that don't | |
22170 | really need it, like an immediate that's a trivial constant. So we're | |
22171 | overestimating the instruction size for some of those cases. Rather | |
22172 | than putting more intelligence here, it would probably be better to | |
22173 | avoid generating a relaxation frag in the first place when it can be | |
22174 | determined up front that a short instruction will suffice. */ | |
22175 | ||
22176 | gas_assert (fragp->fr_type == rs_machine_dependent); | |
22177 | return INSN_SIZE; | |
22178 | } | |
22179 | ||
0110f2b8 PB |
22180 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
22181 | 2 bytes. */ | |
22182 | ||
c19d1205 | 22183 | int |
0110f2b8 | 22184 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
22185 | segT segtype ATTRIBUTE_UNUSED) |
22186 | { | |
0110f2b8 PB |
22187 | fragp->fr_var = 2; |
22188 | return 2; | |
22189 | } | |
22190 | ||
22191 | /* Convert a machine dependent frag. */ | |
22192 | ||
22193 | void | |
22194 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
22195 | { | |
22196 | unsigned long insn; | |
22197 | unsigned long old_op; | |
22198 | char *buf; | |
22199 | expressionS exp; | |
22200 | fixS *fixp; | |
22201 | int reloc_type; | |
22202 | int pc_rel; | |
22203 | int opcode; | |
22204 | ||
22205 | buf = fragp->fr_literal + fragp->fr_fix; | |
22206 | ||
22207 | old_op = bfd_get_16(abfd, buf); | |
5f4273c7 NC |
22208 | if (fragp->fr_symbol) |
22209 | { | |
0110f2b8 PB |
22210 | exp.X_op = O_symbol; |
22211 | exp.X_add_symbol = fragp->fr_symbol; | |
5f4273c7 NC |
22212 | } |
22213 | else | |
22214 | { | |
0110f2b8 | 22215 | exp.X_op = O_constant; |
5f4273c7 | 22216 | } |
0110f2b8 PB |
22217 | exp.X_add_number = fragp->fr_offset; |
22218 | opcode = fragp->fr_subtype; | |
22219 | switch (opcode) | |
22220 | { | |
22221 | case T_MNEM_ldr_pc: | |
22222 | case T_MNEM_ldr_pc2: | |
22223 | case T_MNEM_ldr_sp: | |
22224 | case T_MNEM_str_sp: | |
22225 | case T_MNEM_ldr: | |
22226 | case T_MNEM_ldrb: | |
22227 | case T_MNEM_ldrh: | |
22228 | case T_MNEM_str: | |
22229 | case T_MNEM_strb: | |
22230 | case T_MNEM_strh: | |
22231 | if (fragp->fr_var == 4) | |
22232 | { | |
5f4273c7 | 22233 | insn = THUMB_OP32 (opcode); |
0110f2b8 PB |
22234 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) |
22235 | { | |
22236 | insn |= (old_op & 0x700) << 4; | |
22237 | } | |
22238 | else | |
22239 | { | |
22240 | insn |= (old_op & 7) << 12; | |
22241 | insn |= (old_op & 0x38) << 13; | |
22242 | } | |
22243 | insn |= 0x00000c00; | |
22244 | put_thumb32_insn (buf, insn); | |
22245 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
22246 | } | |
22247 | else | |
22248 | { | |
22249 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
22250 | } | |
22251 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
22252 | break; | |
22253 | case T_MNEM_adr: | |
22254 | if (fragp->fr_var == 4) | |
22255 | { | |
22256 | insn = THUMB_OP32 (opcode); | |
22257 | insn |= (old_op & 0xf0) << 4; | |
22258 | put_thumb32_insn (buf, insn); | |
22259 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
22260 | } | |
22261 | else | |
22262 | { | |
22263 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
22264 | exp.X_add_number -= 4; | |
22265 | } | |
22266 | pc_rel = 1; | |
22267 | break; | |
22268 | case T_MNEM_mov: | |
22269 | case T_MNEM_movs: | |
22270 | case T_MNEM_cmp: | |
22271 | case T_MNEM_cmn: | |
22272 | if (fragp->fr_var == 4) | |
22273 | { | |
22274 | int r0off = (opcode == T_MNEM_mov | |
22275 | || opcode == T_MNEM_movs) ? 0 : 8; | |
22276 | insn = THUMB_OP32 (opcode); | |
22277 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
22278 | insn |= (old_op & 0x700) << r0off; | |
22279 | put_thumb32_insn (buf, insn); | |
22280 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
22281 | } | |
22282 | else | |
22283 | { | |
22284 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
22285 | } | |
22286 | pc_rel = 0; | |
22287 | break; | |
22288 | case T_MNEM_b: | |
22289 | if (fragp->fr_var == 4) | |
22290 | { | |
22291 | insn = THUMB_OP32(opcode); | |
22292 | put_thumb32_insn (buf, insn); | |
22293 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
22294 | } | |
22295 | else | |
22296 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
22297 | pc_rel = 1; | |
22298 | break; | |
22299 | case T_MNEM_bcond: | |
22300 | if (fragp->fr_var == 4) | |
22301 | { | |
22302 | insn = THUMB_OP32(opcode); | |
22303 | insn |= (old_op & 0xf00) << 14; | |
22304 | put_thumb32_insn (buf, insn); | |
22305 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
22306 | } | |
22307 | else | |
22308 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
22309 | pc_rel = 1; | |
22310 | break; | |
22311 | case T_MNEM_add_sp: | |
22312 | case T_MNEM_add_pc: | |
22313 | case T_MNEM_inc_sp: | |
22314 | case T_MNEM_dec_sp: | |
22315 | if (fragp->fr_var == 4) | |
22316 | { | |
22317 | /* ??? Choose between add and addw. */ | |
22318 | insn = THUMB_OP32 (opcode); | |
22319 | insn |= (old_op & 0xf0) << 4; | |
22320 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
22321 | if (opcode == T_MNEM_add_pc) |
22322 | reloc_type = BFD_RELOC_ARM_T32_IMM12; | |
22323 | else | |
22324 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
0110f2b8 PB |
22325 | } |
22326 | else | |
22327 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
22328 | pc_rel = 0; | |
22329 | break; | |
22330 | ||
22331 | case T_MNEM_addi: | |
22332 | case T_MNEM_addis: | |
22333 | case T_MNEM_subi: | |
22334 | case T_MNEM_subis: | |
22335 | if (fragp->fr_var == 4) | |
22336 | { | |
22337 | insn = THUMB_OP32 (opcode); | |
22338 | insn |= (old_op & 0xf0) << 4; | |
22339 | insn |= (old_op & 0xf) << 16; | |
22340 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
22341 | if (insn & (1 << 20)) |
22342 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
22343 | else | |
22344 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
0110f2b8 PB |
22345 | } |
22346 | else | |
22347 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
22348 | pc_rel = 0; | |
22349 | break; | |
22350 | default: | |
5f4273c7 | 22351 | abort (); |
0110f2b8 PB |
22352 | } |
22353 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
21d799b5 | 22354 | (enum bfd_reloc_code_real) reloc_type); |
0110f2b8 PB |
22355 | fixp->fx_file = fragp->fr_file; |
22356 | fixp->fx_line = fragp->fr_line; | |
22357 | fragp->fr_fix += fragp->fr_var; | |
3cfdb781 TG |
22358 | |
22359 | /* Set whether we use thumb-2 ISA based on final relaxation results. */ | |
22360 | if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected () | |
22361 | && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2)) | |
22362 | ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2); | |
0110f2b8 PB |
22363 | } |
22364 | ||
22365 | /* Return the size of a relaxable immediate operand instruction. | |
22366 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
22367 | static int | |
22368 | relax_immediate (fragS *fragp, int size, int shift) | |
22369 | { | |
22370 | offsetT offset; | |
22371 | offsetT mask; | |
22372 | offsetT low; | |
22373 | ||
22374 | /* ??? Should be able to do better than this. */ | |
22375 | if (fragp->fr_symbol) | |
22376 | return 4; | |
22377 | ||
22378 | low = (1 << shift) - 1; | |
22379 | mask = (1 << (shift + size)) - (1 << shift); | |
22380 | offset = fragp->fr_offset; | |
22381 | /* Force misaligned offsets to 32-bit variant. */ | |
22382 | if (offset & low) | |
5e77afaa | 22383 | return 4; |
0110f2b8 PB |
22384 | if (offset & ~mask) |
22385 | return 4; | |
22386 | return 2; | |
22387 | } | |
22388 | ||
5e77afaa PB |
22389 | /* Get the address of a symbol during relaxation. */ |
22390 | static addressT | |
5f4273c7 | 22391 | relaxed_symbol_addr (fragS *fragp, long stretch) |
5e77afaa PB |
22392 | { |
22393 | fragS *sym_frag; | |
22394 | addressT addr; | |
22395 | symbolS *sym; | |
22396 | ||
22397 | sym = fragp->fr_symbol; | |
22398 | sym_frag = symbol_get_frag (sym); | |
22399 | know (S_GET_SEGMENT (sym) != absolute_section | |
22400 | || sym_frag == &zero_address_frag); | |
22401 | addr = S_GET_VALUE (sym) + fragp->fr_offset; | |
22402 | ||
22403 | /* If frag has yet to be reached on this pass, assume it will | |
22404 | move by STRETCH just as we did. If this is not so, it will | |
22405 | be because some frag between grows, and that will force | |
22406 | another pass. */ | |
22407 | ||
22408 | if (stretch != 0 | |
22409 | && sym_frag->relax_marker != fragp->relax_marker) | |
4396b686 PB |
22410 | { |
22411 | fragS *f; | |
22412 | ||
22413 | /* Adjust stretch for any alignment frag. Note that if have | |
22414 | been expanding the earlier code, the symbol may be | |
22415 | defined in what appears to be an earlier frag. FIXME: | |
22416 | This doesn't handle the fr_subtype field, which specifies | |
22417 | a maximum number of bytes to skip when doing an | |
22418 | alignment. */ | |
22419 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) | |
22420 | { | |
22421 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
22422 | { | |
22423 | if (stretch < 0) | |
22424 | stretch = - ((- stretch) | |
22425 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
22426 | else | |
22427 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
22428 | if (stretch == 0) | |
22429 | break; | |
22430 | } | |
22431 | } | |
22432 | if (f != NULL) | |
22433 | addr += stretch; | |
22434 | } | |
5e77afaa PB |
22435 | |
22436 | return addr; | |
22437 | } | |
22438 | ||
0110f2b8 PB |
22439 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative |
22440 | load. */ | |
22441 | static int | |
5e77afaa | 22442 | relax_adr (fragS *fragp, asection *sec, long stretch) |
0110f2b8 PB |
22443 | { |
22444 | addressT addr; | |
22445 | offsetT val; | |
22446 | ||
22447 | /* Assume worst case for symbols not known to be in the same section. */ | |
974da60d NC |
22448 | if (fragp->fr_symbol == NULL |
22449 | || !S_IS_DEFINED (fragp->fr_symbol) | |
77db8e2e NC |
22450 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
22451 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
22452 | return 4; |
22453 | ||
5f4273c7 | 22454 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
22455 | addr = fragp->fr_address + fragp->fr_fix; |
22456 | addr = (addr + 4) & ~3; | |
5e77afaa | 22457 | /* Force misaligned targets to 32-bit variant. */ |
0110f2b8 | 22458 | if (val & 3) |
5e77afaa | 22459 | return 4; |
0110f2b8 PB |
22460 | val -= addr; |
22461 | if (val < 0 || val > 1020) | |
22462 | return 4; | |
22463 | return 2; | |
22464 | } | |
22465 | ||
22466 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
22467 | static int | |
22468 | relax_addsub (fragS *fragp, asection *sec) | |
22469 | { | |
22470 | char *buf; | |
22471 | int op; | |
22472 | ||
22473 | buf = fragp->fr_literal + fragp->fr_fix; | |
22474 | op = bfd_get_16(sec->owner, buf); | |
22475 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
22476 | return relax_immediate (fragp, 8, 0); | |
22477 | else | |
22478 | return relax_immediate (fragp, 3, 0); | |
22479 | } | |
22480 | ||
e83a675f RE |
22481 | /* Return TRUE iff the definition of symbol S could be pre-empted |
22482 | (overridden) at link or load time. */ | |
22483 | static bfd_boolean | |
22484 | symbol_preemptible (symbolS *s) | |
22485 | { | |
22486 | /* Weak symbols can always be pre-empted. */ | |
22487 | if (S_IS_WEAK (s)) | |
22488 | return TRUE; | |
22489 | ||
22490 | /* Non-global symbols cannot be pre-empted. */ | |
22491 | if (! S_IS_EXTERNAL (s)) | |
22492 | return FALSE; | |
22493 | ||
22494 | #ifdef OBJ_ELF | |
22495 | /* In ELF, a global symbol can be marked protected, or private. In that | |
22496 | case it can't be pre-empted (other definitions in the same link unit | |
22497 | would violate the ODR). */ | |
22498 | if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT) | |
22499 | return FALSE; | |
22500 | #endif | |
22501 | ||
22502 | /* Other global symbols might be pre-empted. */ | |
22503 | return TRUE; | |
22504 | } | |
0110f2b8 PB |
22505 | |
22506 | /* Return the size of a relaxable branch instruction. BITS is the | |
22507 | size of the offset field in the narrow instruction. */ | |
22508 | ||
22509 | static int | |
5e77afaa | 22510 | relax_branch (fragS *fragp, asection *sec, int bits, long stretch) |
0110f2b8 PB |
22511 | { |
22512 | addressT addr; | |
22513 | offsetT val; | |
22514 | offsetT limit; | |
22515 | ||
22516 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 22517 | if (!S_IS_DEFINED (fragp->fr_symbol) |
77db8e2e NC |
22518 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
22519 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
22520 | return 4; |
22521 | ||
267bf995 | 22522 | #ifdef OBJ_ELF |
e83a675f | 22523 | /* A branch to a function in ARM state will require interworking. */ |
267bf995 RR |
22524 | if (S_IS_DEFINED (fragp->fr_symbol) |
22525 | && ARM_IS_FUNC (fragp->fr_symbol)) | |
22526 | return 4; | |
e83a675f | 22527 | #endif |
0d9b4b55 | 22528 | |
e83a675f | 22529 | if (symbol_preemptible (fragp->fr_symbol)) |
0d9b4b55 | 22530 | return 4; |
267bf995 | 22531 | |
5f4273c7 | 22532 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
22533 | addr = fragp->fr_address + fragp->fr_fix + 4; |
22534 | val -= addr; | |
22535 | ||
22536 | /* Offset is a signed value *2 */ | |
22537 | limit = 1 << bits; | |
22538 | if (val >= limit || val < -limit) | |
22539 | return 4; | |
22540 | return 2; | |
22541 | } | |
22542 | ||
22543 | ||
22544 | /* Relax a machine dependent frag. This returns the amount by which | |
22545 | the current size of the frag should change. */ | |
22546 | ||
22547 | int | |
5e77afaa | 22548 | arm_relax_frag (asection *sec, fragS *fragp, long stretch) |
0110f2b8 PB |
22549 | { |
22550 | int oldsize; | |
22551 | int newsize; | |
22552 | ||
22553 | oldsize = fragp->fr_var; | |
22554 | switch (fragp->fr_subtype) | |
22555 | { | |
22556 | case T_MNEM_ldr_pc2: | |
5f4273c7 | 22557 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
22558 | break; |
22559 | case T_MNEM_ldr_pc: | |
22560 | case T_MNEM_ldr_sp: | |
22561 | case T_MNEM_str_sp: | |
5f4273c7 | 22562 | newsize = relax_immediate (fragp, 8, 2); |
0110f2b8 PB |
22563 | break; |
22564 | case T_MNEM_ldr: | |
22565 | case T_MNEM_str: | |
5f4273c7 | 22566 | newsize = relax_immediate (fragp, 5, 2); |
0110f2b8 PB |
22567 | break; |
22568 | case T_MNEM_ldrh: | |
22569 | case T_MNEM_strh: | |
5f4273c7 | 22570 | newsize = relax_immediate (fragp, 5, 1); |
0110f2b8 PB |
22571 | break; |
22572 | case T_MNEM_ldrb: | |
22573 | case T_MNEM_strb: | |
5f4273c7 | 22574 | newsize = relax_immediate (fragp, 5, 0); |
0110f2b8 PB |
22575 | break; |
22576 | case T_MNEM_adr: | |
5f4273c7 | 22577 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
22578 | break; |
22579 | case T_MNEM_mov: | |
22580 | case T_MNEM_movs: | |
22581 | case T_MNEM_cmp: | |
22582 | case T_MNEM_cmn: | |
5f4273c7 | 22583 | newsize = relax_immediate (fragp, 8, 0); |
0110f2b8 PB |
22584 | break; |
22585 | case T_MNEM_b: | |
5f4273c7 | 22586 | newsize = relax_branch (fragp, sec, 11, stretch); |
0110f2b8 PB |
22587 | break; |
22588 | case T_MNEM_bcond: | |
5f4273c7 | 22589 | newsize = relax_branch (fragp, sec, 8, stretch); |
0110f2b8 PB |
22590 | break; |
22591 | case T_MNEM_add_sp: | |
22592 | case T_MNEM_add_pc: | |
22593 | newsize = relax_immediate (fragp, 8, 2); | |
22594 | break; | |
22595 | case T_MNEM_inc_sp: | |
22596 | case T_MNEM_dec_sp: | |
22597 | newsize = relax_immediate (fragp, 7, 2); | |
22598 | break; | |
22599 | case T_MNEM_addi: | |
22600 | case T_MNEM_addis: | |
22601 | case T_MNEM_subi: | |
22602 | case T_MNEM_subis: | |
22603 | newsize = relax_addsub (fragp, sec); | |
22604 | break; | |
22605 | default: | |
5f4273c7 | 22606 | abort (); |
0110f2b8 | 22607 | } |
5e77afaa PB |
22608 | |
22609 | fragp->fr_var = newsize; | |
22610 | /* Freeze wide instructions that are at or before the same location as | |
22611 | in the previous pass. This avoids infinite loops. | |
5f4273c7 NC |
22612 | Don't freeze them unconditionally because targets may be artificially |
22613 | misaligned by the expansion of preceding frags. */ | |
5e77afaa | 22614 | if (stretch <= 0 && newsize > 2) |
0110f2b8 | 22615 | { |
0110f2b8 | 22616 | md_convert_frag (sec->owner, sec, fragp); |
5f4273c7 | 22617 | frag_wane (fragp); |
0110f2b8 | 22618 | } |
5e77afaa | 22619 | |
0110f2b8 | 22620 | return newsize - oldsize; |
c19d1205 | 22621 | } |
b99bd4ef | 22622 | |
c19d1205 | 22623 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 22624 | |
c19d1205 ZW |
22625 | valueT |
22626 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
22627 | valueT size) | |
22628 | { | |
6844c0cc | 22629 | return size; |
bfae80f2 | 22630 | } |
b99bd4ef | 22631 | |
c19d1205 ZW |
22632 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
22633 | of an rs_align_code fragment. */ | |
22634 | ||
22635 | void | |
22636 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 22637 | { |
d9235011 | 22638 | static unsigned char const arm_noop[2][2][4] = |
e7495e45 NS |
22639 | { |
22640 | { /* ARMv1 */ | |
22641 | {0x00, 0x00, 0xa0, 0xe1}, /* LE */ | |
22642 | {0xe1, 0xa0, 0x00, 0x00}, /* BE */ | |
22643 | }, | |
22644 | { /* ARMv6k */ | |
22645 | {0x00, 0xf0, 0x20, 0xe3}, /* LE */ | |
22646 | {0xe3, 0x20, 0xf0, 0x00}, /* BE */ | |
22647 | }, | |
22648 | }; | |
d9235011 | 22649 | static unsigned char const thumb_noop[2][2][2] = |
e7495e45 NS |
22650 | { |
22651 | { /* Thumb-1 */ | |
22652 | {0xc0, 0x46}, /* LE */ | |
22653 | {0x46, 0xc0}, /* BE */ | |
22654 | }, | |
22655 | { /* Thumb-2 */ | |
22656 | {0x00, 0xbf}, /* LE */ | |
22657 | {0xbf, 0x00} /* BE */ | |
22658 | } | |
22659 | }; | |
d9235011 | 22660 | static unsigned char const wide_thumb_noop[2][4] = |
e7495e45 NS |
22661 | { /* Wide Thumb-2 */ |
22662 | {0xaf, 0xf3, 0x00, 0x80}, /* LE */ | |
22663 | {0xf3, 0xaf, 0x80, 0x00}, /* BE */ | |
22664 | }; | |
c921be7d | 22665 | |
e7495e45 | 22666 | unsigned bytes, fix, noop_size; |
c19d1205 | 22667 | char * p; |
d9235011 TS |
22668 | const unsigned char * noop; |
22669 | const unsigned char *narrow_noop = NULL; | |
cd000bff DJ |
22670 | #ifdef OBJ_ELF |
22671 | enum mstate state; | |
22672 | #endif | |
bfae80f2 | 22673 | |
c19d1205 | 22674 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
22675 | return; |
22676 | ||
c19d1205 ZW |
22677 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
22678 | p = fragP->fr_literal + fragP->fr_fix; | |
22679 | fix = 0; | |
bfae80f2 | 22680 | |
c19d1205 ZW |
22681 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
22682 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 22683 | |
cd000bff | 22684 | gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0); |
8dc2430f | 22685 | |
cd000bff | 22686 | if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED)) |
a737bd4d | 22687 | { |
7f78eb34 JW |
22688 | if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0] |
22689 | ? selected_cpu : arm_arch_none, arm_ext_v6t2)) | |
e7495e45 NS |
22690 | { |
22691 | narrow_noop = thumb_noop[1][target_big_endian]; | |
22692 | noop = wide_thumb_noop[target_big_endian]; | |
22693 | } | |
c19d1205 | 22694 | else |
e7495e45 NS |
22695 | noop = thumb_noop[0][target_big_endian]; |
22696 | noop_size = 2; | |
cd000bff DJ |
22697 | #ifdef OBJ_ELF |
22698 | state = MAP_THUMB; | |
22699 | #endif | |
7ed4c4c5 NC |
22700 | } |
22701 | else | |
22702 | { | |
7f78eb34 JW |
22703 | noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0] |
22704 | ? selected_cpu : arm_arch_none, | |
22705 | arm_ext_v6k) != 0] | |
e7495e45 NS |
22706 | [target_big_endian]; |
22707 | noop_size = 4; | |
cd000bff DJ |
22708 | #ifdef OBJ_ELF |
22709 | state = MAP_ARM; | |
22710 | #endif | |
7ed4c4c5 | 22711 | } |
c921be7d | 22712 | |
e7495e45 | 22713 | fragP->fr_var = noop_size; |
c921be7d | 22714 | |
c19d1205 | 22715 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 22716 | { |
c19d1205 | 22717 | fix = bytes & (noop_size - 1); |
cd000bff DJ |
22718 | #ifdef OBJ_ELF |
22719 | insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix); | |
22720 | #endif | |
c19d1205 ZW |
22721 | memset (p, 0, fix); |
22722 | p += fix; | |
22723 | bytes -= fix; | |
a737bd4d | 22724 | } |
a737bd4d | 22725 | |
e7495e45 NS |
22726 | if (narrow_noop) |
22727 | { | |
22728 | if (bytes & noop_size) | |
22729 | { | |
22730 | /* Insert a narrow noop. */ | |
22731 | memcpy (p, narrow_noop, noop_size); | |
22732 | p += noop_size; | |
22733 | bytes -= noop_size; | |
22734 | fix += noop_size; | |
22735 | } | |
22736 | ||
22737 | /* Use wide noops for the remainder */ | |
22738 | noop_size = 4; | |
22739 | } | |
22740 | ||
c19d1205 | 22741 | while (bytes >= noop_size) |
a737bd4d | 22742 | { |
c19d1205 ZW |
22743 | memcpy (p, noop, noop_size); |
22744 | p += noop_size; | |
22745 | bytes -= noop_size; | |
22746 | fix += noop_size; | |
a737bd4d NC |
22747 | } |
22748 | ||
c19d1205 | 22749 | fragP->fr_fix += fix; |
a737bd4d NC |
22750 | } |
22751 | ||
c19d1205 ZW |
22752 | /* Called from md_do_align. Used to create an alignment |
22753 | frag in a code section. */ | |
22754 | ||
22755 | void | |
22756 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 22757 | { |
c19d1205 | 22758 | char * p; |
7ed4c4c5 | 22759 | |
c19d1205 | 22760 | /* We assume that there will never be a requirement |
6ec8e702 | 22761 | to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */ |
c19d1205 | 22762 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) |
6ec8e702 NC |
22763 | { |
22764 | char err_msg[128]; | |
22765 | ||
fa94de6b | 22766 | sprintf (err_msg, |
477330fc RM |
22767 | _("alignments greater than %d bytes not supported in .text sections."), |
22768 | MAX_MEM_FOR_RS_ALIGN_CODE + 1); | |
20203fb9 | 22769 | as_fatal ("%s", err_msg); |
6ec8e702 | 22770 | } |
bfae80f2 | 22771 | |
c19d1205 ZW |
22772 | p = frag_var (rs_align_code, |
22773 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
22774 | 1, | |
22775 | (relax_substateT) max, | |
22776 | (symbolS *) NULL, | |
22777 | (offsetT) n, | |
22778 | (char *) NULL); | |
22779 | *p = 0; | |
22780 | } | |
bfae80f2 | 22781 | |
8dc2430f NC |
22782 | /* Perform target specific initialisation of a frag. |
22783 | Note - despite the name this initialisation is not done when the frag | |
22784 | is created, but only when its type is assigned. A frag can be created | |
22785 | and used a long time before its type is set, so beware of assuming that | |
33eaf5de | 22786 | this initialisation is performed first. */ |
bfae80f2 | 22787 | |
cd000bff DJ |
22788 | #ifndef OBJ_ELF |
22789 | void | |
22790 | arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED) | |
22791 | { | |
22792 | /* Record whether this frag is in an ARM or a THUMB area. */ | |
2e98972e | 22793 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
cd000bff DJ |
22794 | } |
22795 | ||
22796 | #else /* OBJ_ELF is defined. */ | |
c19d1205 | 22797 | void |
cd000bff | 22798 | arm_init_frag (fragS * fragP, int max_chars) |
c19d1205 | 22799 | { |
e8d84ca1 | 22800 | bfd_boolean frag_thumb_mode; |
b968d18a | 22801 | |
8dc2430f NC |
22802 | /* If the current ARM vs THUMB mode has not already |
22803 | been recorded into this frag then do so now. */ | |
cd000bff | 22804 | if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0) |
b968d18a JW |
22805 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
22806 | ||
e8d84ca1 NC |
22807 | /* PR 21809: Do not set a mapping state for debug sections |
22808 | - it just confuses other tools. */ | |
22809 | if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING) | |
22810 | return; | |
22811 | ||
b968d18a | 22812 | frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED; |
cd000bff | 22813 | |
f9c1b181 RL |
22814 | /* Record a mapping symbol for alignment frags. We will delete this |
22815 | later if the alignment ends up empty. */ | |
22816 | switch (fragP->fr_type) | |
22817 | { | |
22818 | case rs_align: | |
22819 | case rs_align_test: | |
22820 | case rs_fill: | |
22821 | mapping_state_2 (MAP_DATA, max_chars); | |
22822 | break; | |
22823 | case rs_align_code: | |
b968d18a | 22824 | mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars); |
f9c1b181 RL |
22825 | break; |
22826 | default: | |
22827 | break; | |
cd000bff | 22828 | } |
bfae80f2 RE |
22829 | } |
22830 | ||
c19d1205 ZW |
22831 | /* When we change sections we need to issue a new mapping symbol. */ |
22832 | ||
22833 | void | |
22834 | arm_elf_change_section (void) | |
bfae80f2 | 22835 | { |
c19d1205 ZW |
22836 | /* Link an unlinked unwind index table section to the .text section. */ |
22837 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
22838 | && elf_linked_to_section (now_seg) == NULL) | |
22839 | elf_linked_to_section (now_seg) = text_section; | |
bfae80f2 RE |
22840 | } |
22841 | ||
c19d1205 ZW |
22842 | int |
22843 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 22844 | { |
c19d1205 ZW |
22845 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
22846 | return SHT_ARM_EXIDX; | |
e45d0630 | 22847 | |
c19d1205 ZW |
22848 | return -1; |
22849 | } | |
22850 | \f | |
22851 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 22852 | |
c19d1205 | 22853 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 22854 | |
5f4273c7 | 22855 | /* Generate any deferred unwind frame offset. */ |
e45d0630 | 22856 | |
bfae80f2 | 22857 | static void |
c19d1205 | 22858 | flush_pending_unwind (void) |
bfae80f2 | 22859 | { |
c19d1205 | 22860 | offsetT offset; |
bfae80f2 | 22861 | |
c19d1205 ZW |
22862 | offset = unwind.pending_offset; |
22863 | unwind.pending_offset = 0; | |
22864 | if (offset != 0) | |
22865 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
22866 | } |
22867 | ||
c19d1205 ZW |
22868 | /* Add an opcode to this list for this function. Two-byte opcodes should |
22869 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
22870 | order. */ | |
22871 | ||
bfae80f2 | 22872 | static void |
c19d1205 | 22873 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 22874 | { |
c19d1205 ZW |
22875 | /* Add any deferred stack adjustment. */ |
22876 | if (unwind.pending_offset) | |
22877 | flush_pending_unwind (); | |
bfae80f2 | 22878 | |
c19d1205 | 22879 | unwind.sp_restored = 0; |
bfae80f2 | 22880 | |
c19d1205 | 22881 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 22882 | { |
c19d1205 ZW |
22883 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
22884 | if (unwind.opcodes) | |
325801bd TS |
22885 | unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes, |
22886 | unwind.opcode_alloc); | |
c19d1205 | 22887 | else |
325801bd | 22888 | unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc); |
bfae80f2 | 22889 | } |
c19d1205 | 22890 | while (length > 0) |
bfae80f2 | 22891 | { |
c19d1205 ZW |
22892 | length--; |
22893 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
22894 | op >>= 8; | |
22895 | unwind.opcode_count++; | |
bfae80f2 | 22896 | } |
bfae80f2 RE |
22897 | } |
22898 | ||
c19d1205 ZW |
22899 | /* Add unwind opcodes to adjust the stack pointer. */ |
22900 | ||
bfae80f2 | 22901 | static void |
c19d1205 | 22902 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 22903 | { |
c19d1205 | 22904 | valueT op; |
bfae80f2 | 22905 | |
c19d1205 | 22906 | if (offset > 0x200) |
bfae80f2 | 22907 | { |
c19d1205 ZW |
22908 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
22909 | char bytes[5]; | |
22910 | int n; | |
22911 | valueT o; | |
bfae80f2 | 22912 | |
c19d1205 ZW |
22913 | /* Long form: 0xb2, uleb128. */ |
22914 | /* This might not fit in a word so add the individual bytes, | |
22915 | remembering the list is built in reverse order. */ | |
22916 | o = (valueT) ((offset - 0x204) >> 2); | |
22917 | if (o == 0) | |
22918 | add_unwind_opcode (0, 1); | |
bfae80f2 | 22919 | |
c19d1205 ZW |
22920 | /* Calculate the uleb128 encoding of the offset. */ |
22921 | n = 0; | |
22922 | while (o) | |
22923 | { | |
22924 | bytes[n] = o & 0x7f; | |
22925 | o >>= 7; | |
22926 | if (o) | |
22927 | bytes[n] |= 0x80; | |
22928 | n++; | |
22929 | } | |
22930 | /* Add the insn. */ | |
22931 | for (; n; n--) | |
22932 | add_unwind_opcode (bytes[n - 1], 1); | |
22933 | add_unwind_opcode (0xb2, 1); | |
22934 | } | |
22935 | else if (offset > 0x100) | |
bfae80f2 | 22936 | { |
c19d1205 ZW |
22937 | /* Two short opcodes. */ |
22938 | add_unwind_opcode (0x3f, 1); | |
22939 | op = (offset - 0x104) >> 2; | |
22940 | add_unwind_opcode (op, 1); | |
bfae80f2 | 22941 | } |
c19d1205 ZW |
22942 | else if (offset > 0) |
22943 | { | |
22944 | /* Short opcode. */ | |
22945 | op = (offset - 4) >> 2; | |
22946 | add_unwind_opcode (op, 1); | |
22947 | } | |
22948 | else if (offset < 0) | |
bfae80f2 | 22949 | { |
c19d1205 ZW |
22950 | offset = -offset; |
22951 | while (offset > 0x100) | |
bfae80f2 | 22952 | { |
c19d1205 ZW |
22953 | add_unwind_opcode (0x7f, 1); |
22954 | offset -= 0x100; | |
bfae80f2 | 22955 | } |
c19d1205 ZW |
22956 | op = ((offset - 4) >> 2) | 0x40; |
22957 | add_unwind_opcode (op, 1); | |
bfae80f2 | 22958 | } |
bfae80f2 RE |
22959 | } |
22960 | ||
c19d1205 | 22961 | /* Finish the list of unwind opcodes for this function. */ |
0198d5e6 | 22962 | |
c19d1205 ZW |
22963 | static void |
22964 | finish_unwind_opcodes (void) | |
bfae80f2 | 22965 | { |
c19d1205 | 22966 | valueT op; |
bfae80f2 | 22967 | |
c19d1205 | 22968 | if (unwind.fp_used) |
bfae80f2 | 22969 | { |
708587a4 | 22970 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
22971 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
22972 | flush_pending_unwind (); | |
bfae80f2 | 22973 | |
c19d1205 ZW |
22974 | /* After restoring sp from the frame pointer. */ |
22975 | op = 0x90 | unwind.fp_reg; | |
22976 | add_unwind_opcode (op, 1); | |
22977 | } | |
22978 | else | |
22979 | flush_pending_unwind (); | |
bfae80f2 RE |
22980 | } |
22981 | ||
bfae80f2 | 22982 | |
c19d1205 ZW |
22983 | /* Start an exception table entry. If idx is nonzero this is an index table |
22984 | entry. */ | |
bfae80f2 RE |
22985 | |
22986 | static void | |
c19d1205 | 22987 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 22988 | { |
c19d1205 ZW |
22989 | const char * text_name; |
22990 | const char * prefix; | |
22991 | const char * prefix_once; | |
22992 | const char * group_name; | |
c19d1205 | 22993 | char * sec_name; |
c19d1205 ZW |
22994 | int type; |
22995 | int flags; | |
22996 | int linkonce; | |
bfae80f2 | 22997 | |
c19d1205 | 22998 | if (idx) |
bfae80f2 | 22999 | { |
c19d1205 ZW |
23000 | prefix = ELF_STRING_ARM_unwind; |
23001 | prefix_once = ELF_STRING_ARM_unwind_once; | |
23002 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 23003 | } |
c19d1205 | 23004 | else |
bfae80f2 | 23005 | { |
c19d1205 ZW |
23006 | prefix = ELF_STRING_ARM_unwind_info; |
23007 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
23008 | type = SHT_PROGBITS; | |
bfae80f2 RE |
23009 | } |
23010 | ||
c19d1205 ZW |
23011 | text_name = segment_name (text_seg); |
23012 | if (streq (text_name, ".text")) | |
23013 | text_name = ""; | |
23014 | ||
23015 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
23016 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 23017 | { |
c19d1205 ZW |
23018 | prefix = prefix_once; |
23019 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
23020 | } |
23021 | ||
29a2809e | 23022 | sec_name = concat (prefix, text_name, (char *) NULL); |
bfae80f2 | 23023 | |
c19d1205 ZW |
23024 | flags = SHF_ALLOC; |
23025 | linkonce = 0; | |
23026 | group_name = 0; | |
bfae80f2 | 23027 | |
c19d1205 ZW |
23028 | /* Handle COMDAT group. */ |
23029 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 23030 | { |
c19d1205 ZW |
23031 | group_name = elf_group_name (text_seg); |
23032 | if (group_name == NULL) | |
23033 | { | |
bd3ba5d1 | 23034 | as_bad (_("Group section `%s' has no group signature"), |
c19d1205 ZW |
23035 | segment_name (text_seg)); |
23036 | ignore_rest_of_line (); | |
23037 | return; | |
23038 | } | |
23039 | flags |= SHF_GROUP; | |
23040 | linkonce = 1; | |
bfae80f2 RE |
23041 | } |
23042 | ||
a91e1603 L |
23043 | obj_elf_change_section (sec_name, type, 0, flags, 0, group_name, |
23044 | linkonce, 0); | |
bfae80f2 | 23045 | |
5f4273c7 | 23046 | /* Set the section link for index tables. */ |
c19d1205 ZW |
23047 | if (idx) |
23048 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
23049 | } |
23050 | ||
bfae80f2 | 23051 | |
c19d1205 ZW |
23052 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
23053 | personality routine data. Returns zero, or the index table value for | |
cad0da33 | 23054 | an inline entry. */ |
c19d1205 ZW |
23055 | |
23056 | static valueT | |
23057 | create_unwind_entry (int have_data) | |
bfae80f2 | 23058 | { |
c19d1205 ZW |
23059 | int size; |
23060 | addressT where; | |
23061 | char *ptr; | |
23062 | /* The current word of data. */ | |
23063 | valueT data; | |
23064 | /* The number of bytes left in this word. */ | |
23065 | int n; | |
bfae80f2 | 23066 | |
c19d1205 | 23067 | finish_unwind_opcodes (); |
bfae80f2 | 23068 | |
c19d1205 ZW |
23069 | /* Remember the current text section. */ |
23070 | unwind.saved_seg = now_seg; | |
23071 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 23072 | |
c19d1205 | 23073 | start_unwind_section (now_seg, 0); |
bfae80f2 | 23074 | |
c19d1205 | 23075 | if (unwind.personality_routine == NULL) |
bfae80f2 | 23076 | { |
c19d1205 ZW |
23077 | if (unwind.personality_index == -2) |
23078 | { | |
23079 | if (have_data) | |
5f4273c7 | 23080 | as_bad (_("handlerdata in cantunwind frame")); |
c19d1205 ZW |
23081 | return 1; /* EXIDX_CANTUNWIND. */ |
23082 | } | |
bfae80f2 | 23083 | |
c19d1205 ZW |
23084 | /* Use a default personality routine if none is specified. */ |
23085 | if (unwind.personality_index == -1) | |
23086 | { | |
23087 | if (unwind.opcode_count > 3) | |
23088 | unwind.personality_index = 1; | |
23089 | else | |
23090 | unwind.personality_index = 0; | |
23091 | } | |
bfae80f2 | 23092 | |
c19d1205 ZW |
23093 | /* Space for the personality routine entry. */ |
23094 | if (unwind.personality_index == 0) | |
23095 | { | |
23096 | if (unwind.opcode_count > 3) | |
23097 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 23098 | |
c19d1205 ZW |
23099 | if (!have_data) |
23100 | { | |
23101 | /* All the data is inline in the index table. */ | |
23102 | data = 0x80; | |
23103 | n = 3; | |
23104 | while (unwind.opcode_count > 0) | |
23105 | { | |
23106 | unwind.opcode_count--; | |
23107 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
23108 | n--; | |
23109 | } | |
bfae80f2 | 23110 | |
c19d1205 ZW |
23111 | /* Pad with "finish" opcodes. */ |
23112 | while (n--) | |
23113 | data = (data << 8) | 0xb0; | |
bfae80f2 | 23114 | |
c19d1205 ZW |
23115 | return data; |
23116 | } | |
23117 | size = 0; | |
23118 | } | |
23119 | else | |
23120 | /* We get two opcodes "free" in the first word. */ | |
23121 | size = unwind.opcode_count - 2; | |
23122 | } | |
23123 | else | |
5011093d | 23124 | { |
cad0da33 NC |
23125 | /* PR 16765: Missing or misplaced unwind directives can trigger this. */ |
23126 | if (unwind.personality_index != -1) | |
23127 | { | |
23128 | as_bad (_("attempt to recreate an unwind entry")); | |
23129 | return 1; | |
23130 | } | |
5011093d NC |
23131 | |
23132 | /* An extra byte is required for the opcode count. */ | |
23133 | size = unwind.opcode_count + 1; | |
23134 | } | |
bfae80f2 | 23135 | |
c19d1205 ZW |
23136 | size = (size + 3) >> 2; |
23137 | if (size > 0xff) | |
23138 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 23139 | |
c19d1205 ZW |
23140 | frag_align (2, 0, 0); |
23141 | record_alignment (now_seg, 2); | |
23142 | unwind.table_entry = expr_build_dot (); | |
23143 | ||
23144 | /* Allocate the table entry. */ | |
23145 | ptr = frag_more ((size << 2) + 4); | |
74929e7b NC |
23146 | /* PR 13449: Zero the table entries in case some of them are not used. */ |
23147 | memset (ptr, 0, (size << 2) + 4); | |
c19d1205 | 23148 | where = frag_now_fix () - ((size << 2) + 4); |
bfae80f2 | 23149 | |
c19d1205 | 23150 | switch (unwind.personality_index) |
bfae80f2 | 23151 | { |
c19d1205 ZW |
23152 | case -1: |
23153 | /* ??? Should this be a PLT generating relocation? */ | |
23154 | /* Custom personality routine. */ | |
23155 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
23156 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 23157 | |
c19d1205 ZW |
23158 | where += 4; |
23159 | ptr += 4; | |
bfae80f2 | 23160 | |
c19d1205 | 23161 | /* Set the first byte to the number of additional words. */ |
5011093d | 23162 | data = size > 0 ? size - 1 : 0; |
c19d1205 ZW |
23163 | n = 3; |
23164 | break; | |
bfae80f2 | 23165 | |
c19d1205 ZW |
23166 | /* ABI defined personality routines. */ |
23167 | case 0: | |
23168 | /* Three opcodes bytes are packed into the first word. */ | |
23169 | data = 0x80; | |
23170 | n = 3; | |
23171 | break; | |
bfae80f2 | 23172 | |
c19d1205 ZW |
23173 | case 1: |
23174 | case 2: | |
23175 | /* The size and first two opcode bytes go in the first word. */ | |
23176 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
23177 | n = 2; | |
23178 | break; | |
bfae80f2 | 23179 | |
c19d1205 ZW |
23180 | default: |
23181 | /* Should never happen. */ | |
23182 | abort (); | |
23183 | } | |
bfae80f2 | 23184 | |
c19d1205 ZW |
23185 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
23186 | time. */ | |
23187 | while (unwind.opcode_count > 0) | |
23188 | { | |
23189 | if (n == 0) | |
23190 | { | |
23191 | md_number_to_chars (ptr, data, 4); | |
23192 | ptr += 4; | |
23193 | n = 4; | |
23194 | data = 0; | |
23195 | } | |
23196 | unwind.opcode_count--; | |
23197 | n--; | |
23198 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
23199 | } | |
23200 | ||
23201 | /* Finish off the last word. */ | |
23202 | if (n < 4) | |
23203 | { | |
23204 | /* Pad with "finish" opcodes. */ | |
23205 | while (n--) | |
23206 | data = (data << 8) | 0xb0; | |
23207 | ||
23208 | md_number_to_chars (ptr, data, 4); | |
23209 | } | |
23210 | ||
23211 | if (!have_data) | |
23212 | { | |
23213 | /* Add an empty descriptor if there is no user-specified data. */ | |
23214 | ptr = frag_more (4); | |
23215 | md_number_to_chars (ptr, 0, 4); | |
23216 | } | |
23217 | ||
23218 | return 0; | |
bfae80f2 RE |
23219 | } |
23220 | ||
f0927246 NC |
23221 | |
23222 | /* Initialize the DWARF-2 unwind information for this procedure. */ | |
23223 | ||
23224 | void | |
23225 | tc_arm_frame_initial_instructions (void) | |
23226 | { | |
23227 | cfi_add_CFA_def_cfa (REG_SP, 0); | |
23228 | } | |
23229 | #endif /* OBJ_ELF */ | |
23230 | ||
c19d1205 ZW |
23231 | /* Convert REGNAME to a DWARF-2 register number. */ |
23232 | ||
23233 | int | |
1df69f4f | 23234 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 23235 | { |
1df69f4f | 23236 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
1f5afe1c NC |
23237 | if (reg != FAIL) |
23238 | return reg; | |
c19d1205 | 23239 | |
1f5afe1c NC |
23240 | /* PR 16694: Allow VFP registers as well. */ |
23241 | reg = arm_reg_parse (®name, REG_TYPE_VFS); | |
23242 | if (reg != FAIL) | |
23243 | return 64 + reg; | |
c19d1205 | 23244 | |
1f5afe1c NC |
23245 | reg = arm_reg_parse (®name, REG_TYPE_VFD); |
23246 | if (reg != FAIL) | |
23247 | return reg + 256; | |
23248 | ||
0198d5e6 | 23249 | return FAIL; |
bfae80f2 RE |
23250 | } |
23251 | ||
f0927246 | 23252 | #ifdef TE_PE |
c19d1205 | 23253 | void |
f0927246 | 23254 | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
bfae80f2 | 23255 | { |
91d6fa6a | 23256 | expressionS exp; |
bfae80f2 | 23257 | |
91d6fa6a NC |
23258 | exp.X_op = O_secrel; |
23259 | exp.X_add_symbol = symbol; | |
23260 | exp.X_add_number = 0; | |
23261 | emit_expr (&exp, size); | |
f0927246 NC |
23262 | } |
23263 | #endif | |
bfae80f2 | 23264 | |
c19d1205 | 23265 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 23266 | |
2fc8bdac ZW |
23267 | /* Return the address within the segment that a PC-relative fixup is |
23268 | relative to. For ARM, PC-relative fixups applied to instructions | |
23269 | are generally relative to the location of the fixup plus 8 bytes. | |
23270 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
23271 | require special handling. */ | |
bfae80f2 | 23272 | |
c19d1205 | 23273 | long |
2fc8bdac | 23274 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 23275 | { |
2fc8bdac ZW |
23276 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
23277 | ||
23278 | /* If this is pc-relative and we are going to emit a relocation | |
23279 | then we just want to put out any pipeline compensation that the linker | |
53baae48 NC |
23280 | will need. Otherwise we want to use the calculated base. |
23281 | For WinCE we skip the bias for externals as well, since this | |
23282 | is how the MS ARM-CE assembler behaves and we want to be compatible. */ | |
5f4273c7 | 23283 | if (fixP->fx_pcrel |
2fc8bdac | 23284 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) |
53baae48 NC |
23285 | || (arm_force_relocation (fixP) |
23286 | #ifdef TE_WINCE | |
23287 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
23288 | #endif | |
23289 | ))) | |
2fc8bdac | 23290 | base = 0; |
bfae80f2 | 23291 | |
267bf995 | 23292 | |
c19d1205 | 23293 | switch (fixP->fx_r_type) |
bfae80f2 | 23294 | { |
2fc8bdac ZW |
23295 | /* PC relative addressing on the Thumb is slightly odd as the |
23296 | bottom two bits of the PC are forced to zero for the | |
23297 | calculation. This happens *after* application of the | |
23298 | pipeline offset. However, Thumb adrl already adjusts for | |
23299 | this, so we need not do it again. */ | |
c19d1205 | 23300 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 23301 | return base & ~3; |
c19d1205 ZW |
23302 | |
23303 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
23304 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 23305 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 23306 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 23307 | return (base + 4) & ~3; |
c19d1205 | 23308 | |
2fc8bdac | 23309 | /* Thumb branches are simply offset by +4. */ |
e12437dc | 23310 | case BFD_RELOC_THUMB_PCREL_BRANCH5: |
2fc8bdac ZW |
23311 | case BFD_RELOC_THUMB_PCREL_BRANCH7: |
23312 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
23313 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
23314 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
2fc8bdac | 23315 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
f6b2b12d | 23316 | case BFD_RELOC_THUMB_PCREL_BFCSEL: |
e5d6e09e | 23317 | case BFD_RELOC_ARM_THUMB_BF17: |
1caf72a5 | 23318 | case BFD_RELOC_ARM_THUMB_BF19: |
1889da70 | 23319 | case BFD_RELOC_ARM_THUMB_BF13: |
60f993ce | 23320 | case BFD_RELOC_ARM_THUMB_LOOP12: |
2fc8bdac | 23321 | return base + 4; |
bfae80f2 | 23322 | |
267bf995 | 23323 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
486499d0 CL |
23324 | if (fixP->fx_addsy |
23325 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 23326 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 | 23327 | && ARM_IS_FUNC (fixP->fx_addsy) |
477330fc RM |
23328 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) |
23329 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
267bf995 RR |
23330 | return base + 4; |
23331 | ||
00adf2d4 JB |
23332 | /* BLX is like branches above, but forces the low two bits of PC to |
23333 | zero. */ | |
486499d0 CL |
23334 | case BFD_RELOC_THUMB_PCREL_BLX: |
23335 | if (fixP->fx_addsy | |
23336 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 23337 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
23338 | && THUMB_IS_FUNC (fixP->fx_addsy) |
23339 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
23340 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
00adf2d4 JB |
23341 | return (base + 4) & ~3; |
23342 | ||
2fc8bdac ZW |
23343 | /* ARM mode branches are offset by +8. However, the Windows CE |
23344 | loader expects the relocation not to take this into account. */ | |
267bf995 | 23345 | case BFD_RELOC_ARM_PCREL_BLX: |
486499d0 CL |
23346 | if (fixP->fx_addsy |
23347 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 23348 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
23349 | && ARM_IS_FUNC (fixP->fx_addsy) |
23350 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
23351 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 23352 | return base + 8; |
267bf995 | 23353 | |
486499d0 CL |
23354 | case BFD_RELOC_ARM_PCREL_CALL: |
23355 | if (fixP->fx_addsy | |
23356 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 23357 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
23358 | && THUMB_IS_FUNC (fixP->fx_addsy) |
23359 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
23360 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 23361 | return base + 8; |
267bf995 | 23362 | |
2fc8bdac | 23363 | case BFD_RELOC_ARM_PCREL_BRANCH: |
39b41c9c | 23364 | case BFD_RELOC_ARM_PCREL_JUMP: |
2fc8bdac | 23365 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 23366 | #ifdef TE_WINCE |
5f4273c7 | 23367 | /* When handling fixups immediately, because we have already |
477330fc | 23368 | discovered the value of a symbol, or the address of the frag involved |
53baae48 | 23369 | we must account for the offset by +8, as the OS loader will never see the reloc. |
477330fc RM |
23370 | see fixup_segment() in write.c |
23371 | The S_IS_EXTERNAL test handles the case of global symbols. | |
23372 | Those need the calculated base, not just the pipe compensation the linker will need. */ | |
53baae48 NC |
23373 | if (fixP->fx_pcrel |
23374 | && fixP->fx_addsy != NULL | |
23375 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
23376 | && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP))) | |
23377 | return base + 8; | |
2fc8bdac | 23378 | return base; |
c19d1205 | 23379 | #else |
2fc8bdac | 23380 | return base + 8; |
c19d1205 | 23381 | #endif |
2fc8bdac | 23382 | |
267bf995 | 23383 | |
2fc8bdac ZW |
23384 | /* ARM mode loads relative to PC are also offset by +8. Unlike |
23385 | branches, the Windows CE loader *does* expect the relocation | |
23386 | to take this into account. */ | |
23387 | case BFD_RELOC_ARM_OFFSET_IMM: | |
23388 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
23389 | case BFD_RELOC_ARM_HWLITERAL: | |
23390 | case BFD_RELOC_ARM_LITERAL: | |
23391 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
23392 | return base + 8; | |
23393 | ||
23394 | ||
23395 | /* Other PC-relative relocations are un-offset. */ | |
23396 | default: | |
23397 | return base; | |
23398 | } | |
bfae80f2 RE |
23399 | } |
23400 | ||
8b2d793c NC |
23401 | static bfd_boolean flag_warn_syms = TRUE; |
23402 | ||
ae8714c2 NC |
23403 | bfd_boolean |
23404 | arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name) | |
bfae80f2 | 23405 | { |
8b2d793c NC |
23406 | /* PR 18347 - Warn if the user attempts to create a symbol with the same |
23407 | name as an ARM instruction. Whilst strictly speaking it is allowed, it | |
23408 | does mean that the resulting code might be very confusing to the reader. | |
23409 | Also this warning can be triggered if the user omits an operand before | |
23410 | an immediate address, eg: | |
23411 | ||
23412 | LDR =foo | |
23413 | ||
23414 | GAS treats this as an assignment of the value of the symbol foo to a | |
23415 | symbol LDR, and so (without this code) it will not issue any kind of | |
23416 | warning or error message. | |
23417 | ||
23418 | Note - ARM instructions are case-insensitive but the strings in the hash | |
23419 | table are all stored in lower case, so we must first ensure that name is | |
ae8714c2 NC |
23420 | lower case too. */ |
23421 | if (flag_warn_syms && arm_ops_hsh) | |
8b2d793c NC |
23422 | { |
23423 | char * nbuf = strdup (name); | |
23424 | char * p; | |
23425 | ||
23426 | for (p = nbuf; *p; p++) | |
23427 | *p = TOLOWER (*p); | |
23428 | if (hash_find (arm_ops_hsh, nbuf) != NULL) | |
23429 | { | |
23430 | static struct hash_control * already_warned = NULL; | |
23431 | ||
23432 | if (already_warned == NULL) | |
23433 | already_warned = hash_new (); | |
23434 | /* Only warn about the symbol once. To keep the code | |
23435 | simple we let hash_insert do the lookup for us. */ | |
3076e594 | 23436 | if (hash_insert (already_warned, nbuf, NULL) == NULL) |
ae8714c2 | 23437 | as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name); |
8b2d793c NC |
23438 | } |
23439 | else | |
23440 | free (nbuf); | |
23441 | } | |
3739860c | 23442 | |
ae8714c2 NC |
23443 | return FALSE; |
23444 | } | |
23445 | ||
23446 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. | |
23447 | Otherwise we have no need to default values of symbols. */ | |
23448 | ||
23449 | symbolS * | |
23450 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
23451 | { | |
23452 | #ifdef OBJ_ELF | |
23453 | if (name[0] == '_' && name[1] == 'G' | |
23454 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
23455 | { | |
23456 | if (!GOT_symbol) | |
23457 | { | |
23458 | if (symbol_find (name)) | |
23459 | as_bad (_("GOT already in the symbol table")); | |
23460 | ||
23461 | GOT_symbol = symbol_new (name, undefined_section, | |
23462 | (valueT) 0, & zero_address_frag); | |
23463 | } | |
23464 | ||
23465 | return GOT_symbol; | |
23466 | } | |
23467 | #endif | |
23468 | ||
c921be7d | 23469 | return NULL; |
bfae80f2 RE |
23470 | } |
23471 | ||
55cf6793 | 23472 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
23473 | computed as two separate immediate values, added together. We |
23474 | already know that this value cannot be computed by just one ARM | |
23475 | instruction. */ | |
23476 | ||
23477 | static unsigned int | |
23478 | validate_immediate_twopart (unsigned int val, | |
23479 | unsigned int * highpart) | |
bfae80f2 | 23480 | { |
c19d1205 ZW |
23481 | unsigned int a; |
23482 | unsigned int i; | |
bfae80f2 | 23483 | |
c19d1205 ZW |
23484 | for (i = 0; i < 32; i += 2) |
23485 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
23486 | { | |
23487 | if (a & 0xff00) | |
23488 | { | |
23489 | if (a & ~ 0xffff) | |
23490 | continue; | |
23491 | * highpart = (a >> 8) | ((i + 24) << 7); | |
23492 | } | |
23493 | else if (a & 0xff0000) | |
23494 | { | |
23495 | if (a & 0xff000000) | |
23496 | continue; | |
23497 | * highpart = (a >> 16) | ((i + 16) << 7); | |
23498 | } | |
23499 | else | |
23500 | { | |
9c2799c2 | 23501 | gas_assert (a & 0xff000000); |
c19d1205 ZW |
23502 | * highpart = (a >> 24) | ((i + 8) << 7); |
23503 | } | |
bfae80f2 | 23504 | |
c19d1205 ZW |
23505 | return (a & 0xff) | (i << 7); |
23506 | } | |
bfae80f2 | 23507 | |
c19d1205 | 23508 | return FAIL; |
bfae80f2 RE |
23509 | } |
23510 | ||
c19d1205 ZW |
23511 | static int |
23512 | validate_offset_imm (unsigned int val, int hwse) | |
23513 | { | |
23514 | if ((hwse && val > 255) || val > 4095) | |
23515 | return FAIL; | |
23516 | return val; | |
23517 | } | |
bfae80f2 | 23518 | |
55cf6793 | 23519 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
23520 | negative immediate constant by altering the instruction. A bit of |
23521 | a hack really. | |
23522 | MOV <-> MVN | |
23523 | AND <-> BIC | |
23524 | ADC <-> SBC | |
23525 | by inverting the second operand, and | |
23526 | ADD <-> SUB | |
23527 | CMP <-> CMN | |
23528 | by negating the second operand. */ | |
bfae80f2 | 23529 | |
c19d1205 ZW |
23530 | static int |
23531 | negate_data_op (unsigned long * instruction, | |
23532 | unsigned long value) | |
bfae80f2 | 23533 | { |
c19d1205 ZW |
23534 | int op, new_inst; |
23535 | unsigned long negated, inverted; | |
bfae80f2 | 23536 | |
c19d1205 ZW |
23537 | negated = encode_arm_immediate (-value); |
23538 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 23539 | |
c19d1205 ZW |
23540 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
23541 | switch (op) | |
bfae80f2 | 23542 | { |
c19d1205 ZW |
23543 | /* First negates. */ |
23544 | case OPCODE_SUB: /* ADD <-> SUB */ | |
23545 | new_inst = OPCODE_ADD; | |
23546 | value = negated; | |
23547 | break; | |
bfae80f2 | 23548 | |
c19d1205 ZW |
23549 | case OPCODE_ADD: |
23550 | new_inst = OPCODE_SUB; | |
23551 | value = negated; | |
23552 | break; | |
bfae80f2 | 23553 | |
c19d1205 ZW |
23554 | case OPCODE_CMP: /* CMP <-> CMN */ |
23555 | new_inst = OPCODE_CMN; | |
23556 | value = negated; | |
23557 | break; | |
bfae80f2 | 23558 | |
c19d1205 ZW |
23559 | case OPCODE_CMN: |
23560 | new_inst = OPCODE_CMP; | |
23561 | value = negated; | |
23562 | break; | |
bfae80f2 | 23563 | |
c19d1205 ZW |
23564 | /* Now Inverted ops. */ |
23565 | case OPCODE_MOV: /* MOV <-> MVN */ | |
23566 | new_inst = OPCODE_MVN; | |
23567 | value = inverted; | |
23568 | break; | |
bfae80f2 | 23569 | |
c19d1205 ZW |
23570 | case OPCODE_MVN: |
23571 | new_inst = OPCODE_MOV; | |
23572 | value = inverted; | |
23573 | break; | |
bfae80f2 | 23574 | |
c19d1205 ZW |
23575 | case OPCODE_AND: /* AND <-> BIC */ |
23576 | new_inst = OPCODE_BIC; | |
23577 | value = inverted; | |
23578 | break; | |
bfae80f2 | 23579 | |
c19d1205 ZW |
23580 | case OPCODE_BIC: |
23581 | new_inst = OPCODE_AND; | |
23582 | value = inverted; | |
23583 | break; | |
bfae80f2 | 23584 | |
c19d1205 ZW |
23585 | case OPCODE_ADC: /* ADC <-> SBC */ |
23586 | new_inst = OPCODE_SBC; | |
23587 | value = inverted; | |
23588 | break; | |
bfae80f2 | 23589 | |
c19d1205 ZW |
23590 | case OPCODE_SBC: |
23591 | new_inst = OPCODE_ADC; | |
23592 | value = inverted; | |
23593 | break; | |
bfae80f2 | 23594 | |
c19d1205 ZW |
23595 | /* We cannot do anything. */ |
23596 | default: | |
23597 | return FAIL; | |
b99bd4ef NC |
23598 | } |
23599 | ||
c19d1205 ZW |
23600 | if (value == (unsigned) FAIL) |
23601 | return FAIL; | |
23602 | ||
23603 | *instruction &= OPCODE_MASK; | |
23604 | *instruction |= new_inst << DATA_OP_SHIFT; | |
23605 | return value; | |
b99bd4ef NC |
23606 | } |
23607 | ||
ef8d22e6 PB |
23608 | /* Like negate_data_op, but for Thumb-2. */ |
23609 | ||
23610 | static unsigned int | |
16dd5e42 | 23611 | thumb32_negate_data_op (offsetT *instruction, unsigned int value) |
ef8d22e6 PB |
23612 | { |
23613 | int op, new_inst; | |
23614 | int rd; | |
16dd5e42 | 23615 | unsigned int negated, inverted; |
ef8d22e6 PB |
23616 | |
23617 | negated = encode_thumb32_immediate (-value); | |
23618 | inverted = encode_thumb32_immediate (~value); | |
23619 | ||
23620 | rd = (*instruction >> 8) & 0xf; | |
23621 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
23622 | switch (op) | |
23623 | { | |
23624 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
23625 | case T2_OPCODE_SUB: | |
23626 | new_inst = T2_OPCODE_ADD; | |
23627 | value = negated; | |
23628 | break; | |
23629 | ||
23630 | case T2_OPCODE_ADD: | |
23631 | new_inst = T2_OPCODE_SUB; | |
23632 | value = negated; | |
23633 | break; | |
23634 | ||
23635 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
23636 | case T2_OPCODE_ORR: | |
23637 | new_inst = T2_OPCODE_ORN; | |
23638 | value = inverted; | |
23639 | break; | |
23640 | ||
23641 | case T2_OPCODE_ORN: | |
23642 | new_inst = T2_OPCODE_ORR; | |
23643 | value = inverted; | |
23644 | break; | |
23645 | ||
23646 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
23647 | case T2_OPCODE_AND: | |
23648 | new_inst = T2_OPCODE_BIC; | |
23649 | if (rd == 15) | |
23650 | value = FAIL; | |
23651 | else | |
23652 | value = inverted; | |
23653 | break; | |
23654 | ||
23655 | case T2_OPCODE_BIC: | |
23656 | new_inst = T2_OPCODE_AND; | |
23657 | value = inverted; | |
23658 | break; | |
23659 | ||
23660 | /* ADC <-> SBC */ | |
23661 | case T2_OPCODE_ADC: | |
23662 | new_inst = T2_OPCODE_SBC; | |
23663 | value = inverted; | |
23664 | break; | |
23665 | ||
23666 | case T2_OPCODE_SBC: | |
23667 | new_inst = T2_OPCODE_ADC; | |
23668 | value = inverted; | |
23669 | break; | |
23670 | ||
23671 | /* We cannot do anything. */ | |
23672 | default: | |
23673 | return FAIL; | |
23674 | } | |
23675 | ||
16dd5e42 | 23676 | if (value == (unsigned int)FAIL) |
ef8d22e6 PB |
23677 | return FAIL; |
23678 | ||
23679 | *instruction &= T2_OPCODE_MASK; | |
23680 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
23681 | return value; | |
23682 | } | |
23683 | ||
8f06b2d8 | 23684 | /* Read a 32-bit thumb instruction from buf. */ |
0198d5e6 | 23685 | |
8f06b2d8 PB |
23686 | static unsigned long |
23687 | get_thumb32_insn (char * buf) | |
23688 | { | |
23689 | unsigned long insn; | |
23690 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
23691 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
23692 | ||
23693 | return insn; | |
23694 | } | |
23695 | ||
a8bc6c78 PB |
23696 | /* We usually want to set the low bit on the address of thumb function |
23697 | symbols. In particular .word foo - . should have the low bit set. | |
23698 | Generic code tries to fold the difference of two symbols to | |
23699 | a constant. Prevent this and force a relocation when the first symbols | |
23700 | is a thumb function. */ | |
c921be7d NC |
23701 | |
23702 | bfd_boolean | |
a8bc6c78 PB |
23703 | arm_optimize_expr (expressionS *l, operatorT op, expressionS *r) |
23704 | { | |
23705 | if (op == O_subtract | |
23706 | && l->X_op == O_symbol | |
23707 | && r->X_op == O_symbol | |
23708 | && THUMB_IS_FUNC (l->X_add_symbol)) | |
23709 | { | |
23710 | l->X_op = O_subtract; | |
23711 | l->X_op_symbol = r->X_add_symbol; | |
23712 | l->X_add_number -= r->X_add_number; | |
c921be7d | 23713 | return TRUE; |
a8bc6c78 | 23714 | } |
c921be7d | 23715 | |
a8bc6c78 | 23716 | /* Process as normal. */ |
c921be7d | 23717 | return FALSE; |
a8bc6c78 PB |
23718 | } |
23719 | ||
4a42ebbc RR |
23720 | /* Encode Thumb2 unconditional branches and calls. The encoding |
23721 | for the 2 are identical for the immediate values. */ | |
23722 | ||
23723 | static void | |
23724 | encode_thumb2_b_bl_offset (char * buf, offsetT value) | |
23725 | { | |
23726 | #define T2I1I2MASK ((1 << 13) | (1 << 11)) | |
23727 | offsetT newval; | |
23728 | offsetT newval2; | |
23729 | addressT S, I1, I2, lo, hi; | |
23730 | ||
23731 | S = (value >> 24) & 0x01; | |
23732 | I1 = (value >> 23) & 0x01; | |
23733 | I2 = (value >> 22) & 0x01; | |
23734 | hi = (value >> 12) & 0x3ff; | |
fa94de6b | 23735 | lo = (value >> 1) & 0x7ff; |
4a42ebbc RR |
23736 | newval = md_chars_to_number (buf, THUMB_SIZE); |
23737 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
23738 | newval |= (S << 10) | hi; | |
23739 | newval2 &= ~T2I1I2MASK; | |
23740 | newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK; | |
23741 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23742 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
23743 | } | |
23744 | ||
c19d1205 | 23745 | void |
55cf6793 | 23746 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
23747 | valueT * valP, |
23748 | segT seg) | |
23749 | { | |
23750 | offsetT value = * valP; | |
23751 | offsetT newval; | |
23752 | unsigned int newimm; | |
23753 | unsigned long temp; | |
23754 | int sign; | |
23755 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 23756 | |
9c2799c2 | 23757 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 23758 | |
c19d1205 | 23759 | /* Note whether this will delete the relocation. */ |
4962c51a | 23760 | |
c19d1205 ZW |
23761 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
23762 | fixP->fx_done = 1; | |
b99bd4ef | 23763 | |
adbaf948 | 23764 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
5f4273c7 | 23765 | consistency with the behaviour on 32-bit hosts. Remember value |
adbaf948 ZW |
23766 | for emit_reloc. */ |
23767 | value &= 0xffffffff; | |
23768 | value ^= 0x80000000; | |
5f4273c7 | 23769 | value -= 0x80000000; |
adbaf948 ZW |
23770 | |
23771 | *valP = value; | |
c19d1205 | 23772 | fixP->fx_addnumber = value; |
b99bd4ef | 23773 | |
adbaf948 ZW |
23774 | /* Same treatment for fixP->fx_offset. */ |
23775 | fixP->fx_offset &= 0xffffffff; | |
23776 | fixP->fx_offset ^= 0x80000000; | |
23777 | fixP->fx_offset -= 0x80000000; | |
23778 | ||
c19d1205 | 23779 | switch (fixP->fx_r_type) |
b99bd4ef | 23780 | { |
c19d1205 ZW |
23781 | case BFD_RELOC_NONE: |
23782 | /* This will need to go in the object file. */ | |
23783 | fixP->fx_done = 0; | |
23784 | break; | |
b99bd4ef | 23785 | |
c19d1205 ZW |
23786 | case BFD_RELOC_ARM_IMMEDIATE: |
23787 | /* We claim that this fixup has been processed here, | |
23788 | even if in fact we generate an error because we do | |
23789 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
23790 | fixP->fx_done = 1; | |
b99bd4ef | 23791 | |
77db8e2e | 23792 | if (fixP->fx_addsy) |
b99bd4ef | 23793 | { |
77db8e2e | 23794 | const char *msg = 0; |
b99bd4ef | 23795 | |
77db8e2e NC |
23796 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
23797 | msg = _("undefined symbol %s used as an immediate value"); | |
23798 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
23799 | msg = _("symbol %s is in a different section"); | |
23800 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
23801 | msg = _("symbol %s is weak and may be overridden later"); | |
23802 | ||
23803 | if (msg) | |
23804 | { | |
23805 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23806 | msg, S_GET_NAME (fixP->fx_addsy)); | |
23807 | break; | |
23808 | } | |
42e5fcbf AS |
23809 | } |
23810 | ||
c19d1205 ZW |
23811 | temp = md_chars_to_number (buf, INSN_SIZE); |
23812 | ||
5e73442d SL |
23813 | /* If the offset is negative, we should use encoding A2 for ADR. */ |
23814 | if ((temp & 0xfff0000) == 0x28f0000 && value < 0) | |
23815 | newimm = negate_data_op (&temp, value); | |
23816 | else | |
23817 | { | |
23818 | newimm = encode_arm_immediate (value); | |
23819 | ||
23820 | /* If the instruction will fail, see if we can fix things up by | |
23821 | changing the opcode. */ | |
23822 | if (newimm == (unsigned int) FAIL) | |
23823 | newimm = negate_data_op (&temp, value); | |
bada4342 JW |
23824 | /* MOV accepts both ARM modified immediate (A1 encoding) and |
23825 | UINT16 (A2 encoding) when possible, MOVW only accepts UINT16. | |
23826 | When disassembling, MOV is preferred when there is no encoding | |
23827 | overlap. */ | |
23828 | if (newimm == (unsigned int) FAIL | |
23829 | && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV | |
23830 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2) | |
23831 | && !((temp >> SBIT_SHIFT) & 0x1) | |
23832 | && value >= 0 && value <= 0xffff) | |
23833 | { | |
23834 | /* Clear bits[23:20] to change encoding from A1 to A2. */ | |
23835 | temp &= 0xff0fffff; | |
23836 | /* Encoding high 4bits imm. Code below will encode the remaining | |
23837 | low 12bits. */ | |
23838 | temp |= (value & 0x0000f000) << 4; | |
23839 | newimm = value & 0x00000fff; | |
23840 | } | |
5e73442d SL |
23841 | } |
23842 | ||
23843 | if (newimm == (unsigned int) FAIL) | |
b99bd4ef | 23844 | { |
c19d1205 ZW |
23845 | as_bad_where (fixP->fx_file, fixP->fx_line, |
23846 | _("invalid constant (%lx) after fixup"), | |
23847 | (unsigned long) value); | |
23848 | break; | |
b99bd4ef | 23849 | } |
b99bd4ef | 23850 | |
c19d1205 ZW |
23851 | newimm |= (temp & 0xfffff000); |
23852 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
23853 | break; | |
b99bd4ef | 23854 | |
c19d1205 ZW |
23855 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
23856 | { | |
23857 | unsigned int highpart = 0; | |
23858 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 23859 | |
77db8e2e | 23860 | if (fixP->fx_addsy) |
42e5fcbf | 23861 | { |
77db8e2e | 23862 | const char *msg = 0; |
42e5fcbf | 23863 | |
77db8e2e NC |
23864 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
23865 | msg = _("undefined symbol %s used as an immediate value"); | |
23866 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
23867 | msg = _("symbol %s is in a different section"); | |
23868 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
23869 | msg = _("symbol %s is weak and may be overridden later"); | |
42e5fcbf | 23870 | |
77db8e2e NC |
23871 | if (msg) |
23872 | { | |
23873 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23874 | msg, S_GET_NAME (fixP->fx_addsy)); | |
23875 | break; | |
23876 | } | |
23877 | } | |
fa94de6b | 23878 | |
c19d1205 ZW |
23879 | newimm = encode_arm_immediate (value); |
23880 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 23881 | |
c19d1205 ZW |
23882 | /* If the instruction will fail, see if we can fix things up by |
23883 | changing the opcode. */ | |
23884 | if (newimm == (unsigned int) FAIL | |
23885 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
23886 | { | |
23887 | /* No ? OK - try using two ADD instructions to generate | |
23888 | the value. */ | |
23889 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 23890 | |
c19d1205 ZW |
23891 | /* Yes - then make sure that the second instruction is |
23892 | also an add. */ | |
23893 | if (newimm != (unsigned int) FAIL) | |
23894 | newinsn = temp; | |
23895 | /* Still No ? Try using a negated value. */ | |
23896 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
23897 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
23898 | /* Otherwise - give up. */ | |
23899 | else | |
23900 | { | |
23901 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23902 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
23903 | (long) value); | |
23904 | break; | |
23905 | } | |
b99bd4ef | 23906 | |
c19d1205 ZW |
23907 | /* Replace the first operand in the 2nd instruction (which |
23908 | is the PC) with the destination register. We have | |
23909 | already added in the PC in the first instruction and we | |
23910 | do not want to do it again. */ | |
23911 | newinsn &= ~ 0xf0000; | |
23912 | newinsn |= ((newinsn & 0x0f000) << 4); | |
23913 | } | |
b99bd4ef | 23914 | |
c19d1205 ZW |
23915 | newimm |= (temp & 0xfffff000); |
23916 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 23917 | |
c19d1205 ZW |
23918 | highpart |= (newinsn & 0xfffff000); |
23919 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
23920 | } | |
23921 | break; | |
b99bd4ef | 23922 | |
c19d1205 | 23923 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
23924 | if (!fixP->fx_done && seg->use_rela_p) |
23925 | value = 0; | |
1a0670f3 | 23926 | /* Fall through. */ |
00a97672 | 23927 | |
c19d1205 | 23928 | case BFD_RELOC_ARM_LITERAL: |
26d97720 | 23929 | sign = value > 0; |
b99bd4ef | 23930 | |
c19d1205 ZW |
23931 | if (value < 0) |
23932 | value = - value; | |
b99bd4ef | 23933 | |
c19d1205 | 23934 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 23935 | { |
c19d1205 ZW |
23936 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
23937 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23938 | _("invalid literal constant: pool needs to be closer")); | |
23939 | else | |
23940 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23941 | _("bad immediate value for offset (%ld)"), | |
23942 | (long) value); | |
23943 | break; | |
f03698e6 RE |
23944 | } |
23945 | ||
c19d1205 | 23946 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
23947 | if (value == 0) |
23948 | newval &= 0xfffff000; | |
23949 | else | |
23950 | { | |
23951 | newval &= 0xff7ff000; | |
23952 | newval |= value | (sign ? INDEX_UP : 0); | |
23953 | } | |
c19d1205 ZW |
23954 | md_number_to_chars (buf, newval, INSN_SIZE); |
23955 | break; | |
b99bd4ef | 23956 | |
c19d1205 ZW |
23957 | case BFD_RELOC_ARM_OFFSET_IMM8: |
23958 | case BFD_RELOC_ARM_HWLITERAL: | |
26d97720 | 23959 | sign = value > 0; |
b99bd4ef | 23960 | |
c19d1205 ZW |
23961 | if (value < 0) |
23962 | value = - value; | |
b99bd4ef | 23963 | |
c19d1205 | 23964 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 23965 | { |
c19d1205 ZW |
23966 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
23967 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23968 | _("invalid literal constant: pool needs to be closer")); | |
23969 | else | |
427d0db6 RM |
23970 | as_bad_where (fixP->fx_file, fixP->fx_line, |
23971 | _("bad immediate value for 8-bit offset (%ld)"), | |
23972 | (long) value); | |
c19d1205 | 23973 | break; |
b99bd4ef NC |
23974 | } |
23975 | ||
c19d1205 | 23976 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
23977 | if (value == 0) |
23978 | newval &= 0xfffff0f0; | |
23979 | else | |
23980 | { | |
23981 | newval &= 0xff7ff0f0; | |
23982 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
23983 | } | |
c19d1205 ZW |
23984 | md_number_to_chars (buf, newval, INSN_SIZE); |
23985 | break; | |
b99bd4ef | 23986 | |
c19d1205 ZW |
23987 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
23988 | if (value < 0 || value > 1020 || value % 4 != 0) | |
23989 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23990 | _("bad immediate value for offset (%ld)"), (long) value); | |
23991 | value /= 4; | |
b99bd4ef | 23992 | |
c19d1205 | 23993 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
23994 | newval |= value; |
23995 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
23996 | break; | |
b99bd4ef | 23997 | |
c19d1205 ZW |
23998 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
23999 | /* This is a complicated relocation used for all varieties of Thumb32 | |
24000 | load/store instruction with immediate offset: | |
24001 | ||
24002 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
477330fc | 24003 | *4, optional writeback(W) |
c19d1205 ZW |
24004 | (doubleword load/store) |
24005 | ||
24006 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
24007 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
24008 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
24009 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
24010 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
24011 | ||
24012 | Uppercase letters indicate bits that are already encoded at | |
24013 | this point. Lowercase letters are our problem. For the | |
24014 | second block of instructions, the secondary opcode nybble | |
24015 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
24016 | a PC-relative operation. */ | |
24017 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24018 | newval <<= 16; | |
24019 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 24020 | |
c19d1205 | 24021 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 24022 | { |
c19d1205 ZW |
24023 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
24024 | if (value >= 0) | |
24025 | newval |= (1 << 23); | |
24026 | else | |
24027 | value = -value; | |
24028 | if (value % 4 != 0) | |
24029 | { | |
24030 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24031 | _("offset not a multiple of 4")); | |
24032 | break; | |
24033 | } | |
24034 | value /= 4; | |
216d22bc | 24035 | if (value > 0xff) |
c19d1205 ZW |
24036 | { |
24037 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24038 | _("offset out of range")); | |
24039 | break; | |
24040 | } | |
24041 | newval &= ~0xff; | |
b99bd4ef | 24042 | } |
c19d1205 | 24043 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 24044 | { |
c19d1205 ZW |
24045 | /* PC-relative, 12-bit offset. */ |
24046 | if (value >= 0) | |
24047 | newval |= (1 << 23); | |
24048 | else | |
24049 | value = -value; | |
216d22bc | 24050 | if (value > 0xfff) |
c19d1205 ZW |
24051 | { |
24052 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24053 | _("offset out of range")); | |
24054 | break; | |
24055 | } | |
24056 | newval &= ~0xfff; | |
b99bd4ef | 24057 | } |
c19d1205 | 24058 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 24059 | { |
c19d1205 ZW |
24060 | /* Writeback: 8-bit, +/- offset. */ |
24061 | if (value >= 0) | |
24062 | newval |= (1 << 9); | |
24063 | else | |
24064 | value = -value; | |
216d22bc | 24065 | if (value > 0xff) |
c19d1205 ZW |
24066 | { |
24067 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24068 | _("offset out of range")); | |
24069 | break; | |
24070 | } | |
24071 | newval &= ~0xff; | |
b99bd4ef | 24072 | } |
c19d1205 | 24073 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 24074 | { |
c19d1205 | 24075 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 24076 | if (value < 0 || value > 0xff) |
b99bd4ef | 24077 | { |
c19d1205 ZW |
24078 | as_bad_where (fixP->fx_file, fixP->fx_line, |
24079 | _("offset out of range")); | |
24080 | break; | |
b99bd4ef | 24081 | } |
c19d1205 ZW |
24082 | newval &= ~0xff; |
24083 | newval |= value; | |
b99bd4ef NC |
24084 | } |
24085 | else | |
b99bd4ef | 24086 | { |
c19d1205 ZW |
24087 | /* Positive 12-bit or negative 8-bit offset. */ |
24088 | int limit; | |
24089 | if (value >= 0) | |
b99bd4ef | 24090 | { |
c19d1205 ZW |
24091 | newval |= (1 << 23); |
24092 | limit = 0xfff; | |
24093 | } | |
24094 | else | |
24095 | { | |
24096 | value = -value; | |
24097 | limit = 0xff; | |
24098 | } | |
24099 | if (value > limit) | |
24100 | { | |
24101 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24102 | _("offset out of range")); | |
24103 | break; | |
b99bd4ef | 24104 | } |
c19d1205 | 24105 | newval &= ~limit; |
b99bd4ef | 24106 | } |
b99bd4ef | 24107 | |
c19d1205 ZW |
24108 | newval |= value; |
24109 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
24110 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
24111 | break; | |
404ff6b5 | 24112 | |
c19d1205 ZW |
24113 | case BFD_RELOC_ARM_SHIFT_IMM: |
24114 | newval = md_chars_to_number (buf, INSN_SIZE); | |
24115 | if (((unsigned long) value) > 32 | |
24116 | || (value == 32 | |
24117 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
24118 | { | |
24119 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24120 | _("shift expression is too large")); | |
24121 | break; | |
24122 | } | |
404ff6b5 | 24123 | |
c19d1205 ZW |
24124 | if (value == 0) |
24125 | /* Shifts of zero must be done as lsl. */ | |
24126 | newval &= ~0x60; | |
24127 | else if (value == 32) | |
24128 | value = 0; | |
24129 | newval &= 0xfffff07f; | |
24130 | newval |= (value & 0x1f) << 7; | |
24131 | md_number_to_chars (buf, newval, INSN_SIZE); | |
24132 | break; | |
404ff6b5 | 24133 | |
c19d1205 | 24134 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
16805f35 | 24135 | case BFD_RELOC_ARM_T32_ADD_IMM: |
92e90b6e | 24136 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 24137 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
24138 | /* We claim that this fixup has been processed here, |
24139 | even if in fact we generate an error because we do | |
24140 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
24141 | fixP->fx_done = 1; | |
404ff6b5 | 24142 | |
c19d1205 ZW |
24143 | if (fixP->fx_addsy |
24144 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
24145 | { | |
24146 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24147 | _("undefined symbol %s used as an immediate value"), | |
24148 | S_GET_NAME (fixP->fx_addsy)); | |
24149 | break; | |
24150 | } | |
404ff6b5 | 24151 | |
c19d1205 ZW |
24152 | newval = md_chars_to_number (buf, THUMB_SIZE); |
24153 | newval <<= 16; | |
24154 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 24155 | |
16805f35 | 24156 | newimm = FAIL; |
bada4342 JW |
24157 | if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
24158 | /* ARMv8-M Baseline MOV will reach here, but it doesn't support | |
24159 | Thumb2 modified immediate encoding (T2). */ | |
24160 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) | |
16805f35 | 24161 | || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) |
ef8d22e6 PB |
24162 | { |
24163 | newimm = encode_thumb32_immediate (value); | |
24164 | if (newimm == (unsigned int) FAIL) | |
24165 | newimm = thumb32_negate_data_op (&newval, value); | |
24166 | } | |
bada4342 | 24167 | if (newimm == (unsigned int) FAIL) |
92e90b6e | 24168 | { |
bada4342 | 24169 | if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE) |
e9f89963 | 24170 | { |
bada4342 JW |
24171 | /* Turn add/sum into addw/subw. */ |
24172 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
24173 | newval = (newval & 0xfeffffff) | 0x02000000; | |
24174 | /* No flat 12-bit imm encoding for addsw/subsw. */ | |
24175 | if ((newval & 0x00100000) == 0) | |
40f246e3 | 24176 | { |
bada4342 JW |
24177 | /* 12 bit immediate for addw/subw. */ |
24178 | if (value < 0) | |
24179 | { | |
24180 | value = -value; | |
24181 | newval ^= 0x00a00000; | |
24182 | } | |
24183 | if (value > 0xfff) | |
24184 | newimm = (unsigned int) FAIL; | |
24185 | else | |
24186 | newimm = value; | |
24187 | } | |
24188 | } | |
24189 | else | |
24190 | { | |
24191 | /* MOV accepts both Thumb2 modified immediate (T2 encoding) and | |
24192 | UINT16 (T3 encoding), MOVW only accepts UINT16. When | |
24193 | disassembling, MOV is preferred when there is no encoding | |
db7bf105 | 24194 | overlap. */ |
bada4342 | 24195 | if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR |
db7bf105 NC |
24196 | /* NOTE: MOV uses the ORR opcode in Thumb 2 mode |
24197 | but with the Rn field [19:16] set to 1111. */ | |
24198 | && (((newval >> 16) & 0xf) == 0xf) | |
bada4342 JW |
24199 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m) |
24200 | && !((newval >> T2_SBIT_SHIFT) & 0x1) | |
db7bf105 | 24201 | && value >= 0 && value <= 0xffff) |
bada4342 JW |
24202 | { |
24203 | /* Toggle bit[25] to change encoding from T2 to T3. */ | |
24204 | newval ^= 1 << 25; | |
24205 | /* Clear bits[19:16]. */ | |
24206 | newval &= 0xfff0ffff; | |
24207 | /* Encoding high 4bits imm. Code below will encode the | |
24208 | remaining low 12bits. */ | |
24209 | newval |= (value & 0x0000f000) << 4; | |
24210 | newimm = value & 0x00000fff; | |
40f246e3 | 24211 | } |
e9f89963 | 24212 | } |
92e90b6e | 24213 | } |
cc8a6dd0 | 24214 | |
c19d1205 | 24215 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 24216 | { |
c19d1205 ZW |
24217 | as_bad_where (fixP->fx_file, fixP->fx_line, |
24218 | _("invalid constant (%lx) after fixup"), | |
24219 | (unsigned long) value); | |
24220 | break; | |
3631a3c8 NC |
24221 | } |
24222 | ||
c19d1205 ZW |
24223 | newval |= (newimm & 0x800) << 15; |
24224 | newval |= (newimm & 0x700) << 4; | |
24225 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 24226 | |
c19d1205 ZW |
24227 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
24228 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
24229 | break; | |
a737bd4d | 24230 | |
3eb17e6b | 24231 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
24232 | if (((unsigned long) value) > 0xffff) |
24233 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 24234 | _("invalid smc expression")); |
2fc8bdac | 24235 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
24236 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
24237 | md_number_to_chars (buf, newval, INSN_SIZE); | |
24238 | break; | |
a737bd4d | 24239 | |
90ec0d68 MGD |
24240 | case BFD_RELOC_ARM_HVC: |
24241 | if (((unsigned long) value) > 0xffff) | |
24242 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24243 | _("invalid hvc expression")); | |
24244 | newval = md_chars_to_number (buf, INSN_SIZE); | |
24245 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); | |
24246 | md_number_to_chars (buf, newval, INSN_SIZE); | |
24247 | break; | |
24248 | ||
c19d1205 | 24249 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 24250 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
24251 | { |
24252 | if (((unsigned long) value) > 0xff) | |
24253 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24254 | _("invalid swi expression")); | |
2fc8bdac | 24255 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
24256 | newval |= value; |
24257 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24258 | } | |
24259 | else | |
24260 | { | |
24261 | if (((unsigned long) value) > 0x00ffffff) | |
24262 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24263 | _("invalid swi expression")); | |
2fc8bdac | 24264 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
24265 | newval |= value; |
24266 | md_number_to_chars (buf, newval, INSN_SIZE); | |
24267 | } | |
24268 | break; | |
a737bd4d | 24269 | |
c19d1205 ZW |
24270 | case BFD_RELOC_ARM_MULTI: |
24271 | if (((unsigned long) value) > 0xffff) | |
24272 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24273 | _("invalid expression in load/store multiple")); | |
24274 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
24275 | md_number_to_chars (buf, newval, INSN_SIZE); | |
24276 | break; | |
a737bd4d | 24277 | |
c19d1205 | 24278 | #ifdef OBJ_ELF |
39b41c9c | 24279 | case BFD_RELOC_ARM_PCREL_CALL: |
267bf995 RR |
24280 | |
24281 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
24282 | && fixP->fx_addsy | |
34e77a92 | 24283 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
24284 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
24285 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
24286 | /* Flip the bl to blx. This is a simple flip | |
24287 | bit here because we generate PCREL_CALL for | |
24288 | unconditional bls. */ | |
24289 | { | |
24290 | newval = md_chars_to_number (buf, INSN_SIZE); | |
24291 | newval = newval | 0x10000000; | |
24292 | md_number_to_chars (buf, newval, INSN_SIZE); | |
24293 | temp = 1; | |
24294 | fixP->fx_done = 1; | |
24295 | } | |
39b41c9c PB |
24296 | else |
24297 | temp = 3; | |
24298 | goto arm_branch_common; | |
24299 | ||
24300 | case BFD_RELOC_ARM_PCREL_JUMP: | |
267bf995 RR |
24301 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
24302 | && fixP->fx_addsy | |
34e77a92 | 24303 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
24304 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
24305 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
24306 | { | |
24307 | /* This would map to a bl<cond>, b<cond>, | |
24308 | b<always> to a Thumb function. We | |
24309 | need to force a relocation for this particular | |
24310 | case. */ | |
24311 | newval = md_chars_to_number (buf, INSN_SIZE); | |
24312 | fixP->fx_done = 0; | |
24313 | } | |
1a0670f3 | 24314 | /* Fall through. */ |
267bf995 | 24315 | |
2fc8bdac | 24316 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 24317 | #endif |
39b41c9c PB |
24318 | case BFD_RELOC_ARM_PCREL_BRANCH: |
24319 | temp = 3; | |
24320 | goto arm_branch_common; | |
a737bd4d | 24321 | |
39b41c9c | 24322 | case BFD_RELOC_ARM_PCREL_BLX: |
267bf995 | 24323 | |
39b41c9c | 24324 | temp = 1; |
267bf995 RR |
24325 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
24326 | && fixP->fx_addsy | |
34e77a92 | 24327 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
24328 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
24329 | && ARM_IS_FUNC (fixP->fx_addsy)) | |
24330 | { | |
24331 | /* Flip the blx to a bl and warn. */ | |
24332 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
24333 | newval = 0xeb000000; | |
24334 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
24335 | _("blx to '%s' an ARM ISA state function changed to bl"), | |
24336 | name); | |
24337 | md_number_to_chars (buf, newval, INSN_SIZE); | |
24338 | temp = 3; | |
24339 | fixP->fx_done = 1; | |
24340 | } | |
24341 | ||
24342 | #ifdef OBJ_ELF | |
24343 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
477330fc | 24344 | fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL; |
267bf995 RR |
24345 | #endif |
24346 | ||
39b41c9c | 24347 | arm_branch_common: |
c19d1205 | 24348 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
24349 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
24350 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
de194d85 | 24351 | also be clear. */ |
39b41c9c | 24352 | if (value & temp) |
c19d1205 | 24353 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
24354 | _("misaligned branch destination")); |
24355 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
24356 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
08f10d51 | 24357 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 24358 | |
2fc8bdac | 24359 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 24360 | { |
2fc8bdac ZW |
24361 | newval = md_chars_to_number (buf, INSN_SIZE); |
24362 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
24363 | /* Set the H bit on BLX instructions. */ |
24364 | if (temp == 1) | |
24365 | { | |
24366 | if (value & 2) | |
24367 | newval |= 0x01000000; | |
24368 | else | |
24369 | newval &= ~0x01000000; | |
24370 | } | |
2fc8bdac | 24371 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 24372 | } |
c19d1205 | 24373 | break; |
a737bd4d | 24374 | |
25fe350b MS |
24375 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */ |
24376 | /* CBZ can only branch forward. */ | |
a737bd4d | 24377 | |
738755b0 | 24378 | /* Attempts to use CBZ to branch to the next instruction |
477330fc RM |
24379 | (which, strictly speaking, are prohibited) will be turned into |
24380 | no-ops. | |
738755b0 MS |
24381 | |
24382 | FIXME: It may be better to remove the instruction completely and | |
24383 | perform relaxation. */ | |
24384 | if (value == -2) | |
2fc8bdac ZW |
24385 | { |
24386 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
738755b0 | 24387 | newval = 0xbf00; /* NOP encoding T1 */ |
2fc8bdac ZW |
24388 | md_number_to_chars (buf, newval, THUMB_SIZE); |
24389 | } | |
738755b0 MS |
24390 | else |
24391 | { | |
24392 | if (value & ~0x7e) | |
08f10d51 | 24393 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
738755b0 | 24394 | |
477330fc | 24395 | if (fixP->fx_done || !seg->use_rela_p) |
738755b0 MS |
24396 | { |
24397 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24398 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); | |
24399 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24400 | } | |
24401 | } | |
c19d1205 | 24402 | break; |
a737bd4d | 24403 | |
c19d1205 | 24404 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac | 24405 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
08f10d51 | 24406 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 24407 | |
2fc8bdac ZW |
24408 | if (fixP->fx_done || !seg->use_rela_p) |
24409 | { | |
24410 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24411 | newval |= (value & 0x1ff) >> 1; | |
24412 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24413 | } | |
c19d1205 | 24414 | break; |
a737bd4d | 24415 | |
c19d1205 | 24416 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac | 24417 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
08f10d51 | 24418 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 24419 | |
2fc8bdac ZW |
24420 | if (fixP->fx_done || !seg->use_rela_p) |
24421 | { | |
24422 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24423 | newval |= (value & 0xfff) >> 1; | |
24424 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24425 | } | |
c19d1205 | 24426 | break; |
a737bd4d | 24427 | |
c19d1205 | 24428 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
267bf995 RR |
24429 | if (fixP->fx_addsy |
24430 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 24431 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
24432 | && ARM_IS_FUNC (fixP->fx_addsy) |
24433 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
24434 | { | |
24435 | /* Force a relocation for a branch 20 bits wide. */ | |
24436 | fixP->fx_done = 0; | |
24437 | } | |
08f10d51 | 24438 | if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff)) |
2fc8bdac ZW |
24439 | as_bad_where (fixP->fx_file, fixP->fx_line, |
24440 | _("conditional branch out of range")); | |
404ff6b5 | 24441 | |
2fc8bdac ZW |
24442 | if (fixP->fx_done || !seg->use_rela_p) |
24443 | { | |
24444 | offsetT newval2; | |
24445 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 24446 | |
2fc8bdac ZW |
24447 | S = (value & 0x00100000) >> 20; |
24448 | J2 = (value & 0x00080000) >> 19; | |
24449 | J1 = (value & 0x00040000) >> 18; | |
24450 | hi = (value & 0x0003f000) >> 12; | |
24451 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 24452 | |
2fc8bdac ZW |
24453 | newval = md_chars_to_number (buf, THUMB_SIZE); |
24454 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
24455 | newval |= (S << 10) | hi; | |
24456 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
24457 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24458 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
24459 | } | |
c19d1205 | 24460 | break; |
6c43fab6 | 24461 | |
c19d1205 | 24462 | case BFD_RELOC_THUMB_PCREL_BLX: |
267bf995 RR |
24463 | /* If there is a blx from a thumb state function to |
24464 | another thumb function flip this to a bl and warn | |
24465 | about it. */ | |
24466 | ||
24467 | if (fixP->fx_addsy | |
34e77a92 | 24468 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
24469 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
24470 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
24471 | { | |
24472 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
24473 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
24474 | _("blx to Thumb func '%s' from Thumb ISA state changed to bl"), | |
24475 | name); | |
24476 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
24477 | newval = newval | 0x1000; | |
24478 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
24479 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
24480 | fixP->fx_done = 1; | |
24481 | } | |
24482 | ||
24483 | ||
24484 | goto thumb_bl_common; | |
24485 | ||
c19d1205 | 24486 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
267bf995 RR |
24487 | /* A bl from Thumb state ISA to an internal ARM state function |
24488 | is converted to a blx. */ | |
24489 | if (fixP->fx_addsy | |
24490 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 24491 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
24492 | && ARM_IS_FUNC (fixP->fx_addsy) |
24493 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
24494 | { | |
24495 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
24496 | newval = newval & ~0x1000; | |
24497 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
24498 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX; | |
24499 | fixP->fx_done = 1; | |
24500 | } | |
24501 | ||
24502 | thumb_bl_common: | |
24503 | ||
2fc8bdac ZW |
24504 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
24505 | /* For a BLX instruction, make sure that the relocation is rounded up | |
24506 | to a word boundary. This follows the semantics of the instruction | |
24507 | which specifies that bit 1 of the target address will come from bit | |
24508 | 1 of the base address. */ | |
d406f3e4 JB |
24509 | value = (value + 3) & ~ 3; |
24510 | ||
24511 | #ifdef OBJ_ELF | |
24512 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 | |
24513 | && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) | |
24514 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
24515 | #endif | |
404ff6b5 | 24516 | |
2b2f5df9 NC |
24517 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
24518 | { | |
fc289b0a | 24519 | if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))) |
2b2f5df9 NC |
24520 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
24521 | else if ((value & ~0x1ffffff) | |
24522 | && ((value & ~0x1ffffff) != ~0x1ffffff)) | |
24523 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24524 | _("Thumb2 branch out of range")); | |
24525 | } | |
4a42ebbc RR |
24526 | |
24527 | if (fixP->fx_done || !seg->use_rela_p) | |
24528 | encode_thumb2_b_bl_offset (buf, value); | |
24529 | ||
c19d1205 | 24530 | break; |
404ff6b5 | 24531 | |
c19d1205 | 24532 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
08f10d51 NC |
24533 | if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff)) |
24534 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); | |
6c43fab6 | 24535 | |
2fc8bdac | 24536 | if (fixP->fx_done || !seg->use_rela_p) |
4a42ebbc | 24537 | encode_thumb2_b_bl_offset (buf, value); |
6c43fab6 | 24538 | |
2fc8bdac | 24539 | break; |
a737bd4d | 24540 | |
2fc8bdac ZW |
24541 | case BFD_RELOC_8: |
24542 | if (fixP->fx_done || !seg->use_rela_p) | |
4b1a927e | 24543 | *buf = value; |
c19d1205 | 24544 | break; |
a737bd4d | 24545 | |
c19d1205 | 24546 | case BFD_RELOC_16: |
2fc8bdac | 24547 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 24548 | md_number_to_chars (buf, value, 2); |
c19d1205 | 24549 | break; |
a737bd4d | 24550 | |
c19d1205 | 24551 | #ifdef OBJ_ELF |
0855e32b NS |
24552 | case BFD_RELOC_ARM_TLS_CALL: |
24553 | case BFD_RELOC_ARM_THM_TLS_CALL: | |
24554 | case BFD_RELOC_ARM_TLS_DESCSEQ: | |
24555 | case BFD_RELOC_ARM_THM_TLS_DESCSEQ: | |
0855e32b | 24556 | case BFD_RELOC_ARM_TLS_GOTDESC: |
c19d1205 ZW |
24557 | case BFD_RELOC_ARM_TLS_GD32: |
24558 | case BFD_RELOC_ARM_TLS_LE32: | |
24559 | case BFD_RELOC_ARM_TLS_IE32: | |
24560 | case BFD_RELOC_ARM_TLS_LDM32: | |
24561 | case BFD_RELOC_ARM_TLS_LDO32: | |
24562 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
4b1a927e | 24563 | break; |
6c43fab6 | 24564 | |
5c5a4843 CL |
24565 | /* Same handling as above, but with the arm_fdpic guard. */ |
24566 | case BFD_RELOC_ARM_TLS_GD32_FDPIC: | |
24567 | case BFD_RELOC_ARM_TLS_IE32_FDPIC: | |
24568 | case BFD_RELOC_ARM_TLS_LDM32_FDPIC: | |
24569 | if (arm_fdpic) | |
24570 | { | |
24571 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
24572 | } | |
24573 | else | |
24574 | { | |
24575 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24576 | _("Relocation supported only in FDPIC mode")); | |
24577 | } | |
24578 | break; | |
24579 | ||
c19d1205 ZW |
24580 | case BFD_RELOC_ARM_GOT32: |
24581 | case BFD_RELOC_ARM_GOTOFF: | |
c19d1205 | 24582 | break; |
b43420e6 NC |
24583 | |
24584 | case BFD_RELOC_ARM_GOT_PREL: | |
24585 | if (fixP->fx_done || !seg->use_rela_p) | |
477330fc | 24586 | md_number_to_chars (buf, value, 4); |
b43420e6 NC |
24587 | break; |
24588 | ||
9a6f4e97 NS |
24589 | case BFD_RELOC_ARM_TARGET2: |
24590 | /* TARGET2 is not partial-inplace, so we need to write the | |
477330fc RM |
24591 | addend here for REL targets, because it won't be written out |
24592 | during reloc processing later. */ | |
9a6f4e97 NS |
24593 | if (fixP->fx_done || !seg->use_rela_p) |
24594 | md_number_to_chars (buf, fixP->fx_offset, 4); | |
24595 | break; | |
188fd7ae CL |
24596 | |
24597 | /* Relocations for FDPIC. */ | |
24598 | case BFD_RELOC_ARM_GOTFUNCDESC: | |
24599 | case BFD_RELOC_ARM_GOTOFFFUNCDESC: | |
24600 | case BFD_RELOC_ARM_FUNCDESC: | |
24601 | if (arm_fdpic) | |
24602 | { | |
24603 | if (fixP->fx_done || !seg->use_rela_p) | |
24604 | md_number_to_chars (buf, 0, 4); | |
24605 | } | |
24606 | else | |
24607 | { | |
24608 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24609 | _("Relocation supported only in FDPIC mode")); | |
24610 | } | |
24611 | break; | |
c19d1205 | 24612 | #endif |
6c43fab6 | 24613 | |
c19d1205 ZW |
24614 | case BFD_RELOC_RVA: |
24615 | case BFD_RELOC_32: | |
24616 | case BFD_RELOC_ARM_TARGET1: | |
24617 | case BFD_RELOC_ARM_ROSEGREL32: | |
24618 | case BFD_RELOC_ARM_SBREL32: | |
24619 | case BFD_RELOC_32_PCREL: | |
f0927246 NC |
24620 | #ifdef TE_PE |
24621 | case BFD_RELOC_32_SECREL: | |
24622 | #endif | |
2fc8bdac | 24623 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
24624 | #ifdef TE_WINCE |
24625 | /* For WinCE we only do this for pcrel fixups. */ | |
24626 | if (fixP->fx_done || fixP->fx_pcrel) | |
24627 | #endif | |
24628 | md_number_to_chars (buf, value, 4); | |
c19d1205 | 24629 | break; |
6c43fab6 | 24630 | |
c19d1205 ZW |
24631 | #ifdef OBJ_ELF |
24632 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 24633 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
24634 | { |
24635 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
24636 | if ((value ^ (value >> 1)) & 0x40000000) | |
24637 | { | |
24638 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24639 | _("rel31 relocation overflow")); | |
24640 | } | |
24641 | newval |= value & 0x7fffffff; | |
24642 | md_number_to_chars (buf, newval, 4); | |
24643 | } | |
24644 | break; | |
c19d1205 | 24645 | #endif |
a737bd4d | 24646 | |
c19d1205 | 24647 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 24648 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
32c36c3c | 24649 | case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM: |
9db2f6b4 RL |
24650 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM) |
24651 | newval = md_chars_to_number (buf, INSN_SIZE); | |
24652 | else | |
24653 | newval = get_thumb32_insn (buf); | |
24654 | if ((newval & 0x0f200f00) == 0x0d000900) | |
24655 | { | |
24656 | /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic | |
24657 | has permitted values that are multiples of 2, in the range 0 | |
24658 | to 510. */ | |
24659 | if (value < -510 || value > 510 || (value & 1)) | |
24660 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24661 | _("co-processor offset out of range")); | |
24662 | } | |
32c36c3c AV |
24663 | else if ((newval & 0xfe001f80) == 0xec000f80) |
24664 | { | |
24665 | if (value < -511 || value > 512 || (value & 3)) | |
24666 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24667 | _("co-processor offset out of range")); | |
24668 | } | |
9db2f6b4 | 24669 | else if (value < -1023 || value > 1023 || (value & 3)) |
c19d1205 ZW |
24670 | as_bad_where (fixP->fx_file, fixP->fx_line, |
24671 | _("co-processor offset out of range")); | |
24672 | cp_off_common: | |
26d97720 | 24673 | sign = value > 0; |
c19d1205 ZW |
24674 | if (value < 0) |
24675 | value = -value; | |
8f06b2d8 PB |
24676 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
24677 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
24678 | newval = md_chars_to_number (buf, INSN_SIZE); | |
24679 | else | |
24680 | newval = get_thumb32_insn (buf); | |
26d97720 | 24681 | if (value == 0) |
32c36c3c AV |
24682 | { |
24683 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM) | |
24684 | newval &= 0xffffff80; | |
24685 | else | |
24686 | newval &= 0xffffff00; | |
24687 | } | |
26d97720 NS |
24688 | else |
24689 | { | |
32c36c3c AV |
24690 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM) |
24691 | newval &= 0xff7fff80; | |
24692 | else | |
24693 | newval &= 0xff7fff00; | |
9db2f6b4 RL |
24694 | if ((newval & 0x0f200f00) == 0x0d000900) |
24695 | { | |
24696 | /* This is a fp16 vstr/vldr. | |
24697 | ||
24698 | It requires the immediate offset in the instruction is shifted | |
24699 | left by 1 to be a half-word offset. | |
24700 | ||
24701 | Here, left shift by 1 first, and later right shift by 2 | |
24702 | should get the right offset. */ | |
24703 | value <<= 1; | |
24704 | } | |
26d97720 NS |
24705 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
24706 | } | |
8f06b2d8 PB |
24707 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
24708 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
24709 | md_number_to_chars (buf, newval, INSN_SIZE); | |
24710 | else | |
24711 | put_thumb32_insn (buf, newval); | |
c19d1205 | 24712 | break; |
a737bd4d | 24713 | |
c19d1205 | 24714 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 24715 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
24716 | if (value < -255 || value > 255) |
24717 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24718 | _("co-processor offset out of range")); | |
df7849c5 | 24719 | value *= 4; |
c19d1205 | 24720 | goto cp_off_common; |
6c43fab6 | 24721 | |
c19d1205 ZW |
24722 | case BFD_RELOC_ARM_THUMB_OFFSET: |
24723 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24724 | /* Exactly what ranges, and where the offset is inserted depends | |
24725 | on the type of instruction, we can establish this from the | |
24726 | top 4 bits. */ | |
24727 | switch (newval >> 12) | |
24728 | { | |
24729 | case 4: /* PC load. */ | |
24730 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
24731 | forced to zero for these loads; md_pcrel_from has already | |
24732 | compensated for this. */ | |
24733 | if (value & 3) | |
24734 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24735 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
24736 | (((unsigned long) fixP->fx_frag->fr_address |
24737 | + (unsigned long) fixP->fx_where) & ~3) | |
24738 | + (unsigned long) value); | |
a737bd4d | 24739 | |
c19d1205 ZW |
24740 | if (value & ~0x3fc) |
24741 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24742 | _("invalid offset, value too big (0x%08lX)"), | |
24743 | (long) value); | |
a737bd4d | 24744 | |
c19d1205 ZW |
24745 | newval |= value >> 2; |
24746 | break; | |
a737bd4d | 24747 | |
c19d1205 ZW |
24748 | case 9: /* SP load/store. */ |
24749 | if (value & ~0x3fc) | |
24750 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24751 | _("invalid offset, value too big (0x%08lX)"), | |
24752 | (long) value); | |
24753 | newval |= value >> 2; | |
24754 | break; | |
6c43fab6 | 24755 | |
c19d1205 ZW |
24756 | case 6: /* Word load/store. */ |
24757 | if (value & ~0x7c) | |
24758 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24759 | _("invalid offset, value too big (0x%08lX)"), | |
24760 | (long) value); | |
24761 | newval |= value << 4; /* 6 - 2. */ | |
24762 | break; | |
a737bd4d | 24763 | |
c19d1205 ZW |
24764 | case 7: /* Byte load/store. */ |
24765 | if (value & ~0x1f) | |
24766 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24767 | _("invalid offset, value too big (0x%08lX)"), | |
24768 | (long) value); | |
24769 | newval |= value << 6; | |
24770 | break; | |
a737bd4d | 24771 | |
c19d1205 ZW |
24772 | case 8: /* Halfword load/store. */ |
24773 | if (value & ~0x3e) | |
24774 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24775 | _("invalid offset, value too big (0x%08lX)"), | |
24776 | (long) value); | |
24777 | newval |= value << 5; /* 6 - 1. */ | |
24778 | break; | |
a737bd4d | 24779 | |
c19d1205 ZW |
24780 | default: |
24781 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24782 | "Unable to process relocation for thumb opcode: %lx", | |
24783 | (unsigned long) newval); | |
24784 | break; | |
24785 | } | |
24786 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24787 | break; | |
a737bd4d | 24788 | |
c19d1205 ZW |
24789 | case BFD_RELOC_ARM_THUMB_ADD: |
24790 | /* This is a complicated relocation, since we use it for all of | |
24791 | the following immediate relocations: | |
a737bd4d | 24792 | |
c19d1205 ZW |
24793 | 3bit ADD/SUB |
24794 | 8bit ADD/SUB | |
24795 | 9bit ADD/SUB SP word-aligned | |
24796 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 24797 | |
c19d1205 ZW |
24798 | The type of instruction being processed is encoded in the |
24799 | instruction field: | |
a737bd4d | 24800 | |
c19d1205 ZW |
24801 | 0x8000 SUB |
24802 | 0x00F0 Rd | |
24803 | 0x000F Rs | |
24804 | */ | |
24805 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24806 | { | |
24807 | int rd = (newval >> 4) & 0xf; | |
24808 | int rs = newval & 0xf; | |
24809 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 24810 | |
c19d1205 ZW |
24811 | /* Check for HI regs, only very restricted cases allowed: |
24812 | Adjusting SP, and using PC or SP to get an address. */ | |
24813 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
24814 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
24815 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24816 | _("invalid Hi register with immediate")); | |
a737bd4d | 24817 | |
c19d1205 ZW |
24818 | /* If value is negative, choose the opposite instruction. */ |
24819 | if (value < 0) | |
24820 | { | |
24821 | value = -value; | |
24822 | subtract = !subtract; | |
24823 | if (value < 0) | |
24824 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24825 | _("immediate value out of range")); | |
24826 | } | |
a737bd4d | 24827 | |
c19d1205 ZW |
24828 | if (rd == REG_SP) |
24829 | { | |
75c11999 | 24830 | if (value & ~0x1fc) |
c19d1205 ZW |
24831 | as_bad_where (fixP->fx_file, fixP->fx_line, |
24832 | _("invalid immediate for stack address calculation")); | |
24833 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
24834 | newval |= value >> 2; | |
24835 | } | |
24836 | else if (rs == REG_PC || rs == REG_SP) | |
24837 | { | |
c12d2c9d NC |
24838 | /* PR gas/18541. If the addition is for a defined symbol |
24839 | within range of an ADR instruction then accept it. */ | |
24840 | if (subtract | |
24841 | && value == 4 | |
24842 | && fixP->fx_addsy != NULL) | |
24843 | { | |
24844 | subtract = 0; | |
24845 | ||
24846 | if (! S_IS_DEFINED (fixP->fx_addsy) | |
24847 | || S_GET_SEGMENT (fixP->fx_addsy) != seg | |
24848 | || S_IS_WEAK (fixP->fx_addsy)) | |
24849 | { | |
24850 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24851 | _("address calculation needs a strongly defined nearby symbol")); | |
24852 | } | |
24853 | else | |
24854 | { | |
24855 | offsetT v = fixP->fx_where + fixP->fx_frag->fr_address; | |
24856 | ||
24857 | /* Round up to the next 4-byte boundary. */ | |
24858 | if (v & 3) | |
24859 | v = (v + 3) & ~ 3; | |
24860 | else | |
24861 | v += 4; | |
24862 | v = S_GET_VALUE (fixP->fx_addsy) - v; | |
24863 | ||
24864 | if (v & ~0x3fc) | |
24865 | { | |
24866 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24867 | _("symbol too far away")); | |
24868 | } | |
24869 | else | |
24870 | { | |
24871 | fixP->fx_done = 1; | |
24872 | value = v; | |
24873 | } | |
24874 | } | |
24875 | } | |
24876 | ||
c19d1205 ZW |
24877 | if (subtract || value & ~0x3fc) |
24878 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24879 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
5fc177c8 | 24880 | (unsigned long) (subtract ? - value : value)); |
c19d1205 ZW |
24881 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); |
24882 | newval |= rd << 8; | |
24883 | newval |= value >> 2; | |
24884 | } | |
24885 | else if (rs == rd) | |
24886 | { | |
24887 | if (value & ~0xff) | |
24888 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24889 | _("immediate value out of range")); | |
24890 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
24891 | newval |= (rd << 8) | value; | |
24892 | } | |
24893 | else | |
24894 | { | |
24895 | if (value & ~0x7) | |
24896 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24897 | _("immediate value out of range")); | |
24898 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
24899 | newval |= rd | (rs << 3) | (value << 6); | |
24900 | } | |
24901 | } | |
24902 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24903 | break; | |
a737bd4d | 24904 | |
c19d1205 ZW |
24905 | case BFD_RELOC_ARM_THUMB_IMM: |
24906 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24907 | if (value < 0 || value > 255) | |
24908 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4e6e072b | 24909 | _("invalid immediate: %ld is out of range"), |
c19d1205 ZW |
24910 | (long) value); |
24911 | newval |= value; | |
24912 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24913 | break; | |
a737bd4d | 24914 | |
c19d1205 ZW |
24915 | case BFD_RELOC_ARM_THUMB_SHIFT: |
24916 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
24917 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
24918 | temp = newval & 0xf800; | |
24919 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
24920 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24921 | _("invalid shift value: %ld"), (long) value); | |
24922 | /* Shifts of zero must be encoded as LSL. */ | |
24923 | if (value == 0) | |
24924 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
24925 | /* Shifts of 32 are encoded as zero. */ | |
24926 | else if (value == 32) | |
24927 | value = 0; | |
24928 | newval |= value << 6; | |
24929 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24930 | break; | |
a737bd4d | 24931 | |
c19d1205 ZW |
24932 | case BFD_RELOC_VTABLE_INHERIT: |
24933 | case BFD_RELOC_VTABLE_ENTRY: | |
24934 | fixP->fx_done = 0; | |
24935 | return; | |
6c43fab6 | 24936 | |
b6895b4f PB |
24937 | case BFD_RELOC_ARM_MOVW: |
24938 | case BFD_RELOC_ARM_MOVT: | |
24939 | case BFD_RELOC_ARM_THUMB_MOVW: | |
24940 | case BFD_RELOC_ARM_THUMB_MOVT: | |
24941 | if (fixP->fx_done || !seg->use_rela_p) | |
24942 | { | |
24943 | /* REL format relocations are limited to a 16-bit addend. */ | |
24944 | if (!fixP->fx_done) | |
24945 | { | |
39623e12 | 24946 | if (value < -0x8000 || value > 0x7fff) |
b6895b4f | 24947 | as_bad_where (fixP->fx_file, fixP->fx_line, |
ff5075ca | 24948 | _("offset out of range")); |
b6895b4f PB |
24949 | } |
24950 | else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
24951 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
24952 | { | |
24953 | value >>= 16; | |
24954 | } | |
24955 | ||
24956 | if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
24957 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
24958 | { | |
24959 | newval = get_thumb32_insn (buf); | |
24960 | newval &= 0xfbf08f00; | |
24961 | newval |= (value & 0xf000) << 4; | |
24962 | newval |= (value & 0x0800) << 15; | |
24963 | newval |= (value & 0x0700) << 4; | |
24964 | newval |= (value & 0x00ff); | |
24965 | put_thumb32_insn (buf, newval); | |
24966 | } | |
24967 | else | |
24968 | { | |
24969 | newval = md_chars_to_number (buf, 4); | |
24970 | newval &= 0xfff0f000; | |
24971 | newval |= value & 0x0fff; | |
24972 | newval |= (value & 0xf000) << 4; | |
24973 | md_number_to_chars (buf, newval, 4); | |
24974 | } | |
24975 | } | |
24976 | return; | |
24977 | ||
72d98d16 MG |
24978 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC: |
24979 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC: | |
24980 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC: | |
24981 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC: | |
24982 | gas_assert (!fixP->fx_done); | |
24983 | { | |
24984 | bfd_vma insn; | |
24985 | bfd_boolean is_mov; | |
24986 | bfd_vma encoded_addend = value; | |
24987 | ||
24988 | /* Check that addend can be encoded in instruction. */ | |
24989 | if (!seg->use_rela_p && (value < 0 || value > 255)) | |
24990 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24991 | _("the offset 0x%08lX is not representable"), | |
24992 | (unsigned long) encoded_addend); | |
24993 | ||
24994 | /* Extract the instruction. */ | |
24995 | insn = md_chars_to_number (buf, THUMB_SIZE); | |
24996 | is_mov = (insn & 0xf800) == 0x2000; | |
24997 | ||
24998 | /* Encode insn. */ | |
24999 | if (is_mov) | |
25000 | { | |
25001 | if (!seg->use_rela_p) | |
25002 | insn |= encoded_addend; | |
25003 | } | |
25004 | else | |
25005 | { | |
25006 | int rd, rs; | |
25007 | ||
25008 | /* Extract the instruction. */ | |
25009 | /* Encoding is the following | |
25010 | 0x8000 SUB | |
25011 | 0x00F0 Rd | |
25012 | 0x000F Rs | |
25013 | */ | |
25014 | /* The following conditions must be true : | |
25015 | - ADD | |
25016 | - Rd == Rs | |
25017 | - Rd <= 7 | |
25018 | */ | |
25019 | rd = (insn >> 4) & 0xf; | |
25020 | rs = insn & 0xf; | |
25021 | if ((insn & 0x8000) || (rd != rs) || rd > 7) | |
25022 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
25023 | _("Unable to process relocation for thumb opcode: %lx"), | |
25024 | (unsigned long) insn); | |
25025 | ||
25026 | /* Encode as ADD immediate8 thumb 1 code. */ | |
25027 | insn = 0x3000 | (rd << 8); | |
25028 | ||
25029 | /* Place the encoded addend into the first 8 bits of the | |
25030 | instruction. */ | |
25031 | if (!seg->use_rela_p) | |
25032 | insn |= encoded_addend; | |
25033 | } | |
25034 | ||
25035 | /* Update the instruction. */ | |
25036 | md_number_to_chars (buf, insn, THUMB_SIZE); | |
25037 | } | |
25038 | break; | |
25039 | ||
4962c51a MS |
25040 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
25041 | case BFD_RELOC_ARM_ALU_PC_G0: | |
25042 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
25043 | case BFD_RELOC_ARM_ALU_PC_G1: | |
25044 | case BFD_RELOC_ARM_ALU_PC_G2: | |
25045 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
25046 | case BFD_RELOC_ARM_ALU_SB_G0: | |
25047 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
25048 | case BFD_RELOC_ARM_ALU_SB_G1: | |
25049 | case BFD_RELOC_ARM_ALU_SB_G2: | |
9c2799c2 | 25050 | gas_assert (!fixP->fx_done); |
4962c51a MS |
25051 | if (!seg->use_rela_p) |
25052 | { | |
477330fc RM |
25053 | bfd_vma insn; |
25054 | bfd_vma encoded_addend; | |
3ca4a8ec | 25055 | bfd_vma addend_abs = llabs (value); |
477330fc RM |
25056 | |
25057 | /* Check that the absolute value of the addend can be | |
25058 | expressed as an 8-bit constant plus a rotation. */ | |
25059 | encoded_addend = encode_arm_immediate (addend_abs); | |
25060 | if (encoded_addend == (unsigned int) FAIL) | |
4962c51a | 25061 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
25062 | _("the offset 0x%08lX is not representable"), |
25063 | (unsigned long) addend_abs); | |
25064 | ||
25065 | /* Extract the instruction. */ | |
25066 | insn = md_chars_to_number (buf, INSN_SIZE); | |
25067 | ||
25068 | /* If the addend is positive, use an ADD instruction. | |
25069 | Otherwise use a SUB. Take care not to destroy the S bit. */ | |
25070 | insn &= 0xff1fffff; | |
25071 | if (value < 0) | |
25072 | insn |= 1 << 22; | |
25073 | else | |
25074 | insn |= 1 << 23; | |
25075 | ||
25076 | /* Place the encoded addend into the first 12 bits of the | |
25077 | instruction. */ | |
25078 | insn &= 0xfffff000; | |
25079 | insn |= encoded_addend; | |
25080 | ||
25081 | /* Update the instruction. */ | |
25082 | md_number_to_chars (buf, insn, INSN_SIZE); | |
4962c51a MS |
25083 | } |
25084 | break; | |
25085 | ||
25086 | case BFD_RELOC_ARM_LDR_PC_G0: | |
25087 | case BFD_RELOC_ARM_LDR_PC_G1: | |
25088 | case BFD_RELOC_ARM_LDR_PC_G2: | |
25089 | case BFD_RELOC_ARM_LDR_SB_G0: | |
25090 | case BFD_RELOC_ARM_LDR_SB_G1: | |
25091 | case BFD_RELOC_ARM_LDR_SB_G2: | |
9c2799c2 | 25092 | gas_assert (!fixP->fx_done); |
4962c51a | 25093 | if (!seg->use_rela_p) |
477330fc RM |
25094 | { |
25095 | bfd_vma insn; | |
3ca4a8ec | 25096 | bfd_vma addend_abs = llabs (value); |
4962c51a | 25097 | |
477330fc RM |
25098 | /* Check that the absolute value of the addend can be |
25099 | encoded in 12 bits. */ | |
25100 | if (addend_abs >= 0x1000) | |
4962c51a | 25101 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
25102 | _("bad offset 0x%08lX (only 12 bits available for the magnitude)"), |
25103 | (unsigned long) addend_abs); | |
25104 | ||
25105 | /* Extract the instruction. */ | |
25106 | insn = md_chars_to_number (buf, INSN_SIZE); | |
25107 | ||
25108 | /* If the addend is negative, clear bit 23 of the instruction. | |
25109 | Otherwise set it. */ | |
25110 | if (value < 0) | |
25111 | insn &= ~(1 << 23); | |
25112 | else | |
25113 | insn |= 1 << 23; | |
25114 | ||
25115 | /* Place the absolute value of the addend into the first 12 bits | |
25116 | of the instruction. */ | |
25117 | insn &= 0xfffff000; | |
25118 | insn |= addend_abs; | |
25119 | ||
25120 | /* Update the instruction. */ | |
25121 | md_number_to_chars (buf, insn, INSN_SIZE); | |
25122 | } | |
4962c51a MS |
25123 | break; |
25124 | ||
25125 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
25126 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
25127 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
25128 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
25129 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
25130 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
9c2799c2 | 25131 | gas_assert (!fixP->fx_done); |
4962c51a | 25132 | if (!seg->use_rela_p) |
477330fc RM |
25133 | { |
25134 | bfd_vma insn; | |
3ca4a8ec | 25135 | bfd_vma addend_abs = llabs (value); |
4962c51a | 25136 | |
477330fc RM |
25137 | /* Check that the absolute value of the addend can be |
25138 | encoded in 8 bits. */ | |
25139 | if (addend_abs >= 0x100) | |
4962c51a | 25140 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
25141 | _("bad offset 0x%08lX (only 8 bits available for the magnitude)"), |
25142 | (unsigned long) addend_abs); | |
25143 | ||
25144 | /* Extract the instruction. */ | |
25145 | insn = md_chars_to_number (buf, INSN_SIZE); | |
25146 | ||
25147 | /* If the addend is negative, clear bit 23 of the instruction. | |
25148 | Otherwise set it. */ | |
25149 | if (value < 0) | |
25150 | insn &= ~(1 << 23); | |
25151 | else | |
25152 | insn |= 1 << 23; | |
25153 | ||
25154 | /* Place the first four bits of the absolute value of the addend | |
25155 | into the first 4 bits of the instruction, and the remaining | |
25156 | four into bits 8 .. 11. */ | |
25157 | insn &= 0xfffff0f0; | |
25158 | insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4); | |
25159 | ||
25160 | /* Update the instruction. */ | |
25161 | md_number_to_chars (buf, insn, INSN_SIZE); | |
25162 | } | |
4962c51a MS |
25163 | break; |
25164 | ||
25165 | case BFD_RELOC_ARM_LDC_PC_G0: | |
25166 | case BFD_RELOC_ARM_LDC_PC_G1: | |
25167 | case BFD_RELOC_ARM_LDC_PC_G2: | |
25168 | case BFD_RELOC_ARM_LDC_SB_G0: | |
25169 | case BFD_RELOC_ARM_LDC_SB_G1: | |
25170 | case BFD_RELOC_ARM_LDC_SB_G2: | |
9c2799c2 | 25171 | gas_assert (!fixP->fx_done); |
4962c51a | 25172 | if (!seg->use_rela_p) |
477330fc RM |
25173 | { |
25174 | bfd_vma insn; | |
3ca4a8ec | 25175 | bfd_vma addend_abs = llabs (value); |
4962c51a | 25176 | |
477330fc RM |
25177 | /* Check that the absolute value of the addend is a multiple of |
25178 | four and, when divided by four, fits in 8 bits. */ | |
25179 | if (addend_abs & 0x3) | |
4962c51a | 25180 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
25181 | _("bad offset 0x%08lX (must be word-aligned)"), |
25182 | (unsigned long) addend_abs); | |
4962c51a | 25183 | |
477330fc | 25184 | if ((addend_abs >> 2) > 0xff) |
4962c51a | 25185 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
25186 | _("bad offset 0x%08lX (must be an 8-bit number of words)"), |
25187 | (unsigned long) addend_abs); | |
25188 | ||
25189 | /* Extract the instruction. */ | |
25190 | insn = md_chars_to_number (buf, INSN_SIZE); | |
25191 | ||
25192 | /* If the addend is negative, clear bit 23 of the instruction. | |
25193 | Otherwise set it. */ | |
25194 | if (value < 0) | |
25195 | insn &= ~(1 << 23); | |
25196 | else | |
25197 | insn |= 1 << 23; | |
25198 | ||
25199 | /* Place the addend (divided by four) into the first eight | |
25200 | bits of the instruction. */ | |
25201 | insn &= 0xfffffff0; | |
25202 | insn |= addend_abs >> 2; | |
25203 | ||
25204 | /* Update the instruction. */ | |
25205 | md_number_to_chars (buf, insn, INSN_SIZE); | |
25206 | } | |
4962c51a MS |
25207 | break; |
25208 | ||
e12437dc AV |
25209 | case BFD_RELOC_THUMB_PCREL_BRANCH5: |
25210 | if (fixP->fx_addsy | |
25211 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
25212 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
25213 | && ARM_IS_FUNC (fixP->fx_addsy) | |
25214 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
25215 | { | |
25216 | /* Force a relocation for a branch 5 bits wide. */ | |
25217 | fixP->fx_done = 0; | |
25218 | } | |
25219 | if (v8_1_branch_value_check (value, 5, FALSE) == FAIL) | |
25220 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
25221 | BAD_BRANCH_OFF); | |
25222 | ||
25223 | if (fixP->fx_done || !seg->use_rela_p) | |
25224 | { | |
25225 | addressT boff = value >> 1; | |
25226 | ||
25227 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
25228 | newval |= (boff << 7); | |
25229 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
25230 | } | |
25231 | break; | |
25232 | ||
f6b2b12d AV |
25233 | case BFD_RELOC_THUMB_PCREL_BFCSEL: |
25234 | if (fixP->fx_addsy | |
25235 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
25236 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
25237 | && ARM_IS_FUNC (fixP->fx_addsy) | |
25238 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
25239 | { | |
25240 | fixP->fx_done = 0; | |
25241 | } | |
25242 | if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f)) | |
25243 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
25244 | _("branch out of range")); | |
25245 | ||
25246 | if (fixP->fx_done || !seg->use_rela_p) | |
25247 | { | |
25248 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
25249 | ||
25250 | addressT boff = ((newval & 0x0780) >> 7) << 1; | |
25251 | addressT diff = value - boff; | |
25252 | ||
25253 | if (diff == 4) | |
25254 | { | |
25255 | newval |= 1 << 1; /* T bit. */ | |
25256 | } | |
25257 | else if (diff != 2) | |
25258 | { | |
25259 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
25260 | _("out of range label-relative fixup value")); | |
25261 | } | |
25262 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
25263 | } | |
25264 | break; | |
25265 | ||
e5d6e09e AV |
25266 | case BFD_RELOC_ARM_THUMB_BF17: |
25267 | if (fixP->fx_addsy | |
25268 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
25269 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
25270 | && ARM_IS_FUNC (fixP->fx_addsy) | |
25271 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
25272 | { | |
25273 | /* Force a relocation for a branch 17 bits wide. */ | |
25274 | fixP->fx_done = 0; | |
25275 | } | |
25276 | ||
25277 | if (v8_1_branch_value_check (value, 17, TRUE) == FAIL) | |
25278 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
25279 | BAD_BRANCH_OFF); | |
25280 | ||
25281 | if (fixP->fx_done || !seg->use_rela_p) | |
25282 | { | |
25283 | offsetT newval2; | |
25284 | addressT immA, immB, immC; | |
25285 | ||
25286 | immA = (value & 0x0001f000) >> 12; | |
25287 | immB = (value & 0x00000ffc) >> 2; | |
25288 | immC = (value & 0x00000002) >> 1; | |
25289 | ||
25290 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
25291 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
25292 | newval |= immA; | |
25293 | newval2 |= (immC << 11) | (immB << 1); | |
25294 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
25295 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
25296 | } | |
25297 | break; | |
25298 | ||
1caf72a5 AV |
25299 | case BFD_RELOC_ARM_THUMB_BF19: |
25300 | if (fixP->fx_addsy | |
25301 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
25302 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
25303 | && ARM_IS_FUNC (fixP->fx_addsy) | |
25304 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
25305 | { | |
25306 | /* Force a relocation for a branch 19 bits wide. */ | |
25307 | fixP->fx_done = 0; | |
25308 | } | |
25309 | ||
25310 | if (v8_1_branch_value_check (value, 19, TRUE) == FAIL) | |
25311 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
25312 | BAD_BRANCH_OFF); | |
25313 | ||
25314 | if (fixP->fx_done || !seg->use_rela_p) | |
25315 | { | |
25316 | offsetT newval2; | |
25317 | addressT immA, immB, immC; | |
25318 | ||
25319 | immA = (value & 0x0007f000) >> 12; | |
25320 | immB = (value & 0x00000ffc) >> 2; | |
25321 | immC = (value & 0x00000002) >> 1; | |
25322 | ||
25323 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
25324 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
25325 | newval |= immA; | |
25326 | newval2 |= (immC << 11) | (immB << 1); | |
25327 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
25328 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
25329 | } | |
25330 | break; | |
25331 | ||
1889da70 AV |
25332 | case BFD_RELOC_ARM_THUMB_BF13: |
25333 | if (fixP->fx_addsy | |
25334 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
25335 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
25336 | && ARM_IS_FUNC (fixP->fx_addsy) | |
25337 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
25338 | { | |
25339 | /* Force a relocation for a branch 13 bits wide. */ | |
25340 | fixP->fx_done = 0; | |
25341 | } | |
25342 | ||
25343 | if (v8_1_branch_value_check (value, 13, TRUE) == FAIL) | |
25344 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
25345 | BAD_BRANCH_OFF); | |
25346 | ||
25347 | if (fixP->fx_done || !seg->use_rela_p) | |
25348 | { | |
25349 | offsetT newval2; | |
25350 | addressT immA, immB, immC; | |
25351 | ||
25352 | immA = (value & 0x00001000) >> 12; | |
25353 | immB = (value & 0x00000ffc) >> 2; | |
25354 | immC = (value & 0x00000002) >> 1; | |
25355 | ||
25356 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
25357 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
25358 | newval |= immA; | |
25359 | newval2 |= (immC << 11) | (immB << 1); | |
25360 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
25361 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
25362 | } | |
25363 | break; | |
25364 | ||
60f993ce AV |
25365 | case BFD_RELOC_ARM_THUMB_LOOP12: |
25366 | if (fixP->fx_addsy | |
25367 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
25368 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
25369 | && ARM_IS_FUNC (fixP->fx_addsy) | |
25370 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
25371 | { | |
25372 | /* Force a relocation for a branch 12 bits wide. */ | |
25373 | fixP->fx_done = 0; | |
25374 | } | |
25375 | ||
25376 | bfd_vma insn = get_thumb32_insn (buf); | |
25377 | /* le lr, <label> or le <label> */ | |
25378 | if (((insn & 0xffffffff) == 0xf00fc001) | |
25379 | || ((insn & 0xffffffff) == 0xf02fc001)) | |
25380 | value = -value; | |
25381 | ||
25382 | if (v8_1_branch_value_check (value, 12, FALSE) == FAIL) | |
25383 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
25384 | BAD_BRANCH_OFF); | |
25385 | if (fixP->fx_done || !seg->use_rela_p) | |
25386 | { | |
25387 | addressT imml, immh; | |
25388 | ||
25389 | immh = (value & 0x00000ffc) >> 2; | |
25390 | imml = (value & 0x00000002) >> 1; | |
25391 | ||
25392 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
25393 | newval |= (imml << 11) | (immh << 1); | |
25394 | md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE); | |
25395 | } | |
25396 | break; | |
25397 | ||
845b51d6 PB |
25398 | case BFD_RELOC_ARM_V4BX: |
25399 | /* This will need to go in the object file. */ | |
25400 | fixP->fx_done = 0; | |
25401 | break; | |
25402 | ||
c19d1205 ZW |
25403 | case BFD_RELOC_UNUSED: |
25404 | default: | |
25405 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
25406 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
25407 | } | |
6c43fab6 RE |
25408 | } |
25409 | ||
c19d1205 ZW |
25410 | /* Translate internal representation of relocation info to BFD target |
25411 | format. */ | |
a737bd4d | 25412 | |
c19d1205 | 25413 | arelent * |
00a97672 | 25414 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 25415 | { |
c19d1205 ZW |
25416 | arelent * reloc; |
25417 | bfd_reloc_code_real_type code; | |
a737bd4d | 25418 | |
325801bd | 25419 | reloc = XNEW (arelent); |
a737bd4d | 25420 | |
325801bd | 25421 | reloc->sym_ptr_ptr = XNEW (asymbol *); |
c19d1205 ZW |
25422 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
25423 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 25424 | |
2fc8bdac | 25425 | if (fixp->fx_pcrel) |
00a97672 RS |
25426 | { |
25427 | if (section->use_rela_p) | |
25428 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
25429 | else | |
25430 | fixp->fx_offset = reloc->address; | |
25431 | } | |
c19d1205 | 25432 | reloc->addend = fixp->fx_offset; |
a737bd4d | 25433 | |
c19d1205 | 25434 | switch (fixp->fx_r_type) |
a737bd4d | 25435 | { |
c19d1205 ZW |
25436 | case BFD_RELOC_8: |
25437 | if (fixp->fx_pcrel) | |
25438 | { | |
25439 | code = BFD_RELOC_8_PCREL; | |
25440 | break; | |
25441 | } | |
1a0670f3 | 25442 | /* Fall through. */ |
a737bd4d | 25443 | |
c19d1205 ZW |
25444 | case BFD_RELOC_16: |
25445 | if (fixp->fx_pcrel) | |
25446 | { | |
25447 | code = BFD_RELOC_16_PCREL; | |
25448 | break; | |
25449 | } | |
1a0670f3 | 25450 | /* Fall through. */ |
6c43fab6 | 25451 | |
c19d1205 ZW |
25452 | case BFD_RELOC_32: |
25453 | if (fixp->fx_pcrel) | |
25454 | { | |
25455 | code = BFD_RELOC_32_PCREL; | |
25456 | break; | |
25457 | } | |
1a0670f3 | 25458 | /* Fall through. */ |
a737bd4d | 25459 | |
b6895b4f PB |
25460 | case BFD_RELOC_ARM_MOVW: |
25461 | if (fixp->fx_pcrel) | |
25462 | { | |
25463 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
25464 | break; | |
25465 | } | |
1a0670f3 | 25466 | /* Fall through. */ |
b6895b4f PB |
25467 | |
25468 | case BFD_RELOC_ARM_MOVT: | |
25469 | if (fixp->fx_pcrel) | |
25470 | { | |
25471 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
25472 | break; | |
25473 | } | |
1a0670f3 | 25474 | /* Fall through. */ |
b6895b4f PB |
25475 | |
25476 | case BFD_RELOC_ARM_THUMB_MOVW: | |
25477 | if (fixp->fx_pcrel) | |
25478 | { | |
25479 | code = BFD_RELOC_ARM_THUMB_MOVW_PCREL; | |
25480 | break; | |
25481 | } | |
1a0670f3 | 25482 | /* Fall through. */ |
b6895b4f PB |
25483 | |
25484 | case BFD_RELOC_ARM_THUMB_MOVT: | |
25485 | if (fixp->fx_pcrel) | |
25486 | { | |
25487 | code = BFD_RELOC_ARM_THUMB_MOVT_PCREL; | |
25488 | break; | |
25489 | } | |
1a0670f3 | 25490 | /* Fall through. */ |
b6895b4f | 25491 | |
c19d1205 ZW |
25492 | case BFD_RELOC_NONE: |
25493 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
25494 | case BFD_RELOC_ARM_PCREL_BLX: | |
25495 | case BFD_RELOC_RVA: | |
25496 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
25497 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
25498 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
25499 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
25500 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
25501 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
c19d1205 ZW |
25502 | case BFD_RELOC_VTABLE_ENTRY: |
25503 | case BFD_RELOC_VTABLE_INHERIT: | |
f0927246 NC |
25504 | #ifdef TE_PE |
25505 | case BFD_RELOC_32_SECREL: | |
25506 | #endif | |
c19d1205 ZW |
25507 | code = fixp->fx_r_type; |
25508 | break; | |
a737bd4d | 25509 | |
00adf2d4 JB |
25510 | case BFD_RELOC_THUMB_PCREL_BLX: |
25511 | #ifdef OBJ_ELF | |
25512 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
25513 | code = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
25514 | else | |
25515 | #endif | |
25516 | code = BFD_RELOC_THUMB_PCREL_BLX; | |
25517 | break; | |
25518 | ||
c19d1205 ZW |
25519 | case BFD_RELOC_ARM_LITERAL: |
25520 | case BFD_RELOC_ARM_HWLITERAL: | |
25521 | /* If this is called then the a literal has | |
25522 | been referenced across a section boundary. */ | |
25523 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
25524 | _("literal referenced across section boundary")); | |
25525 | return NULL; | |
a737bd4d | 25526 | |
c19d1205 | 25527 | #ifdef OBJ_ELF |
0855e32b NS |
25528 | case BFD_RELOC_ARM_TLS_CALL: |
25529 | case BFD_RELOC_ARM_THM_TLS_CALL: | |
25530 | case BFD_RELOC_ARM_TLS_DESCSEQ: | |
25531 | case BFD_RELOC_ARM_THM_TLS_DESCSEQ: | |
c19d1205 ZW |
25532 | case BFD_RELOC_ARM_GOT32: |
25533 | case BFD_RELOC_ARM_GOTOFF: | |
b43420e6 | 25534 | case BFD_RELOC_ARM_GOT_PREL: |
c19d1205 ZW |
25535 | case BFD_RELOC_ARM_PLT32: |
25536 | case BFD_RELOC_ARM_TARGET1: | |
25537 | case BFD_RELOC_ARM_ROSEGREL32: | |
25538 | case BFD_RELOC_ARM_SBREL32: | |
25539 | case BFD_RELOC_ARM_PREL31: | |
25540 | case BFD_RELOC_ARM_TARGET2: | |
c19d1205 | 25541 | case BFD_RELOC_ARM_TLS_LDO32: |
39b41c9c PB |
25542 | case BFD_RELOC_ARM_PCREL_CALL: |
25543 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
25544 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
25545 | case BFD_RELOC_ARM_ALU_PC_G0: | |
25546 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
25547 | case BFD_RELOC_ARM_ALU_PC_G1: | |
25548 | case BFD_RELOC_ARM_ALU_PC_G2: | |
25549 | case BFD_RELOC_ARM_LDR_PC_G0: | |
25550 | case BFD_RELOC_ARM_LDR_PC_G1: | |
25551 | case BFD_RELOC_ARM_LDR_PC_G2: | |
25552 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
25553 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
25554 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
25555 | case BFD_RELOC_ARM_LDC_PC_G0: | |
25556 | case BFD_RELOC_ARM_LDC_PC_G1: | |
25557 | case BFD_RELOC_ARM_LDC_PC_G2: | |
25558 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
25559 | case BFD_RELOC_ARM_ALU_SB_G0: | |
25560 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
25561 | case BFD_RELOC_ARM_ALU_SB_G1: | |
25562 | case BFD_RELOC_ARM_ALU_SB_G2: | |
25563 | case BFD_RELOC_ARM_LDR_SB_G0: | |
25564 | case BFD_RELOC_ARM_LDR_SB_G1: | |
25565 | case BFD_RELOC_ARM_LDR_SB_G2: | |
25566 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
25567 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
25568 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
25569 | case BFD_RELOC_ARM_LDC_SB_G0: | |
25570 | case BFD_RELOC_ARM_LDC_SB_G1: | |
25571 | case BFD_RELOC_ARM_LDC_SB_G2: | |
845b51d6 | 25572 | case BFD_RELOC_ARM_V4BX: |
72d98d16 MG |
25573 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC: |
25574 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC: | |
25575 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC: | |
25576 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC: | |
188fd7ae CL |
25577 | case BFD_RELOC_ARM_GOTFUNCDESC: |
25578 | case BFD_RELOC_ARM_GOTOFFFUNCDESC: | |
25579 | case BFD_RELOC_ARM_FUNCDESC: | |
e5d6e09e | 25580 | case BFD_RELOC_ARM_THUMB_BF17: |
1caf72a5 | 25581 | case BFD_RELOC_ARM_THUMB_BF19: |
1889da70 | 25582 | case BFD_RELOC_ARM_THUMB_BF13: |
c19d1205 ZW |
25583 | code = fixp->fx_r_type; |
25584 | break; | |
a737bd4d | 25585 | |
0855e32b | 25586 | case BFD_RELOC_ARM_TLS_GOTDESC: |
c19d1205 | 25587 | case BFD_RELOC_ARM_TLS_GD32: |
5c5a4843 | 25588 | case BFD_RELOC_ARM_TLS_GD32_FDPIC: |
75c11999 | 25589 | case BFD_RELOC_ARM_TLS_LE32: |
c19d1205 | 25590 | case BFD_RELOC_ARM_TLS_IE32: |
5c5a4843 | 25591 | case BFD_RELOC_ARM_TLS_IE32_FDPIC: |
c19d1205 | 25592 | case BFD_RELOC_ARM_TLS_LDM32: |
5c5a4843 | 25593 | case BFD_RELOC_ARM_TLS_LDM32_FDPIC: |
c19d1205 ZW |
25594 | /* BFD will include the symbol's address in the addend. |
25595 | But we don't want that, so subtract it out again here. */ | |
25596 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
25597 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
25598 | code = fixp->fx_r_type; | |
25599 | break; | |
25600 | #endif | |
a737bd4d | 25601 | |
c19d1205 ZW |
25602 | case BFD_RELOC_ARM_IMMEDIATE: |
25603 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
25604 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
25605 | return NULL; | |
a737bd4d | 25606 | |
c19d1205 ZW |
25607 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
25608 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
25609 | _("ADRL used for a symbol not defined in the same file")); | |
25610 | return NULL; | |
a737bd4d | 25611 | |
e12437dc | 25612 | case BFD_RELOC_THUMB_PCREL_BRANCH5: |
f6b2b12d | 25613 | case BFD_RELOC_THUMB_PCREL_BFCSEL: |
60f993ce | 25614 | case BFD_RELOC_ARM_THUMB_LOOP12: |
e12437dc AV |
25615 | as_bad_where (fixp->fx_file, fixp->fx_line, |
25616 | _("%s used for a symbol not defined in the same file"), | |
25617 | bfd_get_reloc_code_name (fixp->fx_r_type)); | |
25618 | return NULL; | |
25619 | ||
c19d1205 | 25620 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
25621 | if (section->use_rela_p) |
25622 | { | |
25623 | code = fixp->fx_r_type; | |
25624 | break; | |
25625 | } | |
25626 | ||
c19d1205 ZW |
25627 | if (fixp->fx_addsy != NULL |
25628 | && !S_IS_DEFINED (fixp->fx_addsy) | |
25629 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 25630 | { |
c19d1205 ZW |
25631 | as_bad_where (fixp->fx_file, fixp->fx_line, |
25632 | _("undefined local label `%s'"), | |
25633 | S_GET_NAME (fixp->fx_addsy)); | |
25634 | return NULL; | |
a737bd4d NC |
25635 | } |
25636 | ||
c19d1205 ZW |
25637 | as_bad_where (fixp->fx_file, fixp->fx_line, |
25638 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
25639 | return NULL; | |
a737bd4d | 25640 | |
c19d1205 ZW |
25641 | default: |
25642 | { | |
e0471c16 | 25643 | const char * type; |
6c43fab6 | 25644 | |
c19d1205 ZW |
25645 | switch (fixp->fx_r_type) |
25646 | { | |
25647 | case BFD_RELOC_NONE: type = "NONE"; break; | |
25648 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
25649 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 25650 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
25651 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
25652 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
25653 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
db187cb9 | 25654 | case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break; |
8f06b2d8 | 25655 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
25656 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
25657 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
25658 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
25659 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
25660 | default: type = _("<unknown>"); break; | |
25661 | } | |
25662 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
25663 | _("cannot represent %s relocation in this object file format"), | |
25664 | type); | |
25665 | return NULL; | |
25666 | } | |
a737bd4d | 25667 | } |
6c43fab6 | 25668 | |
c19d1205 ZW |
25669 | #ifdef OBJ_ELF |
25670 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
25671 | && GOT_symbol | |
25672 | && fixp->fx_addsy == GOT_symbol) | |
25673 | { | |
25674 | code = BFD_RELOC_ARM_GOTPC; | |
25675 | reloc->addend = fixp->fx_offset = reloc->address; | |
25676 | } | |
25677 | #endif | |
6c43fab6 | 25678 | |
c19d1205 | 25679 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 25680 | |
c19d1205 ZW |
25681 | if (reloc->howto == NULL) |
25682 | { | |
25683 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
25684 | _("cannot represent %s relocation in this object file format"), | |
25685 | bfd_get_reloc_code_name (code)); | |
25686 | return NULL; | |
25687 | } | |
6c43fab6 | 25688 | |
c19d1205 ZW |
25689 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
25690 | vtable entry to be used in the relocation's section offset. */ | |
25691 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
25692 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 25693 | |
c19d1205 | 25694 | return reloc; |
6c43fab6 RE |
25695 | } |
25696 | ||
c19d1205 | 25697 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 25698 | |
c19d1205 ZW |
25699 | void |
25700 | cons_fix_new_arm (fragS * frag, | |
25701 | int where, | |
25702 | int size, | |
62ebcb5c AM |
25703 | expressionS * exp, |
25704 | bfd_reloc_code_real_type reloc) | |
6c43fab6 | 25705 | { |
c19d1205 | 25706 | int pcrel = 0; |
6c43fab6 | 25707 | |
c19d1205 ZW |
25708 | /* Pick a reloc. |
25709 | FIXME: @@ Should look at CPU word size. */ | |
25710 | switch (size) | |
25711 | { | |
25712 | case 1: | |
62ebcb5c | 25713 | reloc = BFD_RELOC_8; |
c19d1205 ZW |
25714 | break; |
25715 | case 2: | |
62ebcb5c | 25716 | reloc = BFD_RELOC_16; |
c19d1205 ZW |
25717 | break; |
25718 | case 4: | |
25719 | default: | |
62ebcb5c | 25720 | reloc = BFD_RELOC_32; |
c19d1205 ZW |
25721 | break; |
25722 | case 8: | |
62ebcb5c | 25723 | reloc = BFD_RELOC_64; |
c19d1205 ZW |
25724 | break; |
25725 | } | |
6c43fab6 | 25726 | |
f0927246 NC |
25727 | #ifdef TE_PE |
25728 | if (exp->X_op == O_secrel) | |
25729 | { | |
25730 | exp->X_op = O_symbol; | |
62ebcb5c | 25731 | reloc = BFD_RELOC_32_SECREL; |
f0927246 NC |
25732 | } |
25733 | #endif | |
25734 | ||
62ebcb5c | 25735 | fix_new_exp (frag, where, size, exp, pcrel, reloc); |
c19d1205 | 25736 | } |
6c43fab6 | 25737 | |
4343666d | 25738 | #if defined (OBJ_COFF) |
c19d1205 ZW |
25739 | void |
25740 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 25741 | { |
c19d1205 ZW |
25742 | /* If the destination of the branch is a defined symbol which does not have |
25743 | the THUMB_FUNC attribute, then we must be calling a function which has | |
25744 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
25745 | function and change the branch to refer to that function instead. */ | |
25746 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
25747 | && fixP->fx_addsy != NULL | |
25748 | && S_IS_DEFINED (fixP->fx_addsy) | |
25749 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 25750 | { |
c19d1205 | 25751 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 25752 | } |
c19d1205 ZW |
25753 | } |
25754 | #endif | |
6c43fab6 | 25755 | |
267bf995 | 25756 | |
c19d1205 ZW |
25757 | int |
25758 | arm_force_relocation (struct fix * fixp) | |
25759 | { | |
25760 | #if defined (OBJ_COFF) && defined (TE_PE) | |
25761 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
25762 | return 1; | |
25763 | #endif | |
6c43fab6 | 25764 | |
267bf995 RR |
25765 | /* In case we have a call or a branch to a function in ARM ISA mode from |
25766 | a thumb function or vice-versa force the relocation. These relocations | |
25767 | are cleared off for some cores that might have blx and simple transformations | |
25768 | are possible. */ | |
25769 | ||
25770 | #ifdef OBJ_ELF | |
25771 | switch (fixp->fx_r_type) | |
25772 | { | |
25773 | case BFD_RELOC_ARM_PCREL_JUMP: | |
25774 | case BFD_RELOC_ARM_PCREL_CALL: | |
25775 | case BFD_RELOC_THUMB_PCREL_BLX: | |
25776 | if (THUMB_IS_FUNC (fixp->fx_addsy)) | |
25777 | return 1; | |
25778 | break; | |
25779 | ||
25780 | case BFD_RELOC_ARM_PCREL_BLX: | |
25781 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
25782 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
25783 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
25784 | if (ARM_IS_FUNC (fixp->fx_addsy)) | |
25785 | return 1; | |
25786 | break; | |
25787 | ||
25788 | default: | |
25789 | break; | |
25790 | } | |
25791 | #endif | |
25792 | ||
b5884301 PB |
25793 | /* Resolve these relocations even if the symbol is extern or weak. |
25794 | Technically this is probably wrong due to symbol preemption. | |
25795 | In practice these relocations do not have enough range to be useful | |
25796 | at dynamic link time, and some code (e.g. in the Linux kernel) | |
25797 | expects these references to be resolved. */ | |
c19d1205 ZW |
25798 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE |
25799 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
b5884301 | 25800 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8 |
0110f2b8 | 25801 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
b5884301 PB |
25802 | || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
25803 | || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2 | |
25804 | || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET | |
16805f35 | 25805 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM |
0110f2b8 PB |
25806 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
25807 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
b5884301 PB |
25808 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM |
25809 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12 | |
25810 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM | |
25811 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2) | |
c19d1205 | 25812 | return 0; |
a737bd4d | 25813 | |
4962c51a MS |
25814 | /* Always leave these relocations for the linker. */ |
25815 | if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
25816 | && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
25817 | || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
25818 | return 1; | |
25819 | ||
f0291e4c PB |
25820 | /* Always generate relocations against function symbols. */ |
25821 | if (fixp->fx_r_type == BFD_RELOC_32 | |
25822 | && fixp->fx_addsy | |
25823 | && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION)) | |
25824 | return 1; | |
25825 | ||
c19d1205 | 25826 | return generic_force_reloc (fixp); |
404ff6b5 AH |
25827 | } |
25828 | ||
0ffdc86c | 25829 | #if defined (OBJ_ELF) || defined (OBJ_COFF) |
e28387c3 PB |
25830 | /* Relocations against function names must be left unadjusted, |
25831 | so that the linker can use this information to generate interworking | |
25832 | stubs. The MIPS version of this function | |
c19d1205 ZW |
25833 | also prevents relocations that are mips-16 specific, but I do not |
25834 | know why it does this. | |
404ff6b5 | 25835 | |
c19d1205 ZW |
25836 | FIXME: |
25837 | There is one other problem that ought to be addressed here, but | |
25838 | which currently is not: Taking the address of a label (rather | |
25839 | than a function) and then later jumping to that address. Such | |
25840 | addresses also ought to have their bottom bit set (assuming that | |
25841 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 25842 | |
c19d1205 ZW |
25843 | bfd_boolean |
25844 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 25845 | { |
c19d1205 ZW |
25846 | if (fixP->fx_addsy == NULL) |
25847 | return 1; | |
404ff6b5 | 25848 | |
e28387c3 PB |
25849 | /* Preserve relocations against symbols with function type. */ |
25850 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
c921be7d | 25851 | return FALSE; |
e28387c3 | 25852 | |
c19d1205 ZW |
25853 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
25854 | && fixP->fx_subsy == NULL) | |
c921be7d | 25855 | return FALSE; |
a737bd4d | 25856 | |
c19d1205 ZW |
25857 | /* We need the symbol name for the VTABLE entries. */ |
25858 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
25859 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
c921be7d | 25860 | return FALSE; |
404ff6b5 | 25861 | |
c19d1205 ZW |
25862 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
25863 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
25864 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
25865 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
25866 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
5c5a4843 | 25867 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC |
c19d1205 ZW |
25868 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 |
25869 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
5c5a4843 | 25870 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC |
c19d1205 | 25871 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 |
5c5a4843 | 25872 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC |
c19d1205 | 25873 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 |
0855e32b NS |
25874 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC |
25875 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL | |
25876 | || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL | |
25877 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ | |
25878 | || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ | |
c19d1205 | 25879 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) |
c921be7d | 25880 | return FALSE; |
a737bd4d | 25881 | |
4962c51a MS |
25882 | /* Similarly for group relocations. */ |
25883 | if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
25884 | && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
25885 | || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
c921be7d | 25886 | return FALSE; |
4962c51a | 25887 | |
79947c54 CD |
25888 | /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */ |
25889 | if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW | |
25890 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
25891 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL | |
25892 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL | |
25893 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
25894 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT | |
25895 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL | |
25896 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL) | |
c921be7d | 25897 | return FALSE; |
79947c54 | 25898 | |
72d98d16 MG |
25899 | /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited |
25900 | offsets, so keep these symbols. */ | |
25901 | if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC | |
25902 | && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) | |
25903 | return FALSE; | |
25904 | ||
c921be7d | 25905 | return TRUE; |
a737bd4d | 25906 | } |
0ffdc86c NC |
25907 | #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */ |
25908 | ||
25909 | #ifdef OBJ_ELF | |
c19d1205 ZW |
25910 | const char * |
25911 | elf32_arm_target_format (void) | |
404ff6b5 | 25912 | { |
c19d1205 ZW |
25913 | #ifdef TE_SYMBIAN |
25914 | return (target_big_endian | |
25915 | ? "elf32-bigarm-symbian" | |
25916 | : "elf32-littlearm-symbian"); | |
25917 | #elif defined (TE_VXWORKS) | |
25918 | return (target_big_endian | |
25919 | ? "elf32-bigarm-vxworks" | |
25920 | : "elf32-littlearm-vxworks"); | |
b38cadfb NC |
25921 | #elif defined (TE_NACL) |
25922 | return (target_big_endian | |
25923 | ? "elf32-bigarm-nacl" | |
25924 | : "elf32-littlearm-nacl"); | |
c19d1205 | 25925 | #else |
18a20338 CL |
25926 | if (arm_fdpic) |
25927 | { | |
25928 | if (target_big_endian) | |
25929 | return "elf32-bigarm-fdpic"; | |
25930 | else | |
25931 | return "elf32-littlearm-fdpic"; | |
25932 | } | |
c19d1205 | 25933 | else |
18a20338 CL |
25934 | { |
25935 | if (target_big_endian) | |
25936 | return "elf32-bigarm"; | |
25937 | else | |
25938 | return "elf32-littlearm"; | |
25939 | } | |
c19d1205 | 25940 | #endif |
404ff6b5 AH |
25941 | } |
25942 | ||
c19d1205 ZW |
25943 | void |
25944 | armelf_frob_symbol (symbolS * symp, | |
25945 | int * puntp) | |
404ff6b5 | 25946 | { |
c19d1205 ZW |
25947 | elf_frob_symbol (symp, puntp); |
25948 | } | |
25949 | #endif | |
404ff6b5 | 25950 | |
c19d1205 | 25951 | /* MD interface: Finalization. */ |
a737bd4d | 25952 | |
c19d1205 ZW |
25953 | void |
25954 | arm_cleanup (void) | |
25955 | { | |
25956 | literal_pool * pool; | |
a737bd4d | 25957 | |
e07e6e58 NC |
25958 | /* Ensure that all the IT blocks are properly closed. */ |
25959 | check_it_blocks_finished (); | |
25960 | ||
c19d1205 ZW |
25961 | for (pool = list_of_pools; pool; pool = pool->next) |
25962 | { | |
5f4273c7 | 25963 | /* Put it at the end of the relevant section. */ |
c19d1205 ZW |
25964 | subseg_set (pool->section, pool->sub_section); |
25965 | #ifdef OBJ_ELF | |
25966 | arm_elf_change_section (); | |
25967 | #endif | |
25968 | s_ltorg (0); | |
25969 | } | |
404ff6b5 AH |
25970 | } |
25971 | ||
cd000bff DJ |
25972 | #ifdef OBJ_ELF |
25973 | /* Remove any excess mapping symbols generated for alignment frags in | |
25974 | SEC. We may have created a mapping symbol before a zero byte | |
25975 | alignment; remove it if there's a mapping symbol after the | |
25976 | alignment. */ | |
25977 | static void | |
25978 | check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, | |
25979 | void *dummy ATTRIBUTE_UNUSED) | |
25980 | { | |
25981 | segment_info_type *seginfo = seg_info (sec); | |
25982 | fragS *fragp; | |
25983 | ||
25984 | if (seginfo == NULL || seginfo->frchainP == NULL) | |
25985 | return; | |
25986 | ||
25987 | for (fragp = seginfo->frchainP->frch_root; | |
25988 | fragp != NULL; | |
25989 | fragp = fragp->fr_next) | |
25990 | { | |
25991 | symbolS *sym = fragp->tc_frag_data.last_map; | |
25992 | fragS *next = fragp->fr_next; | |
25993 | ||
25994 | /* Variable-sized frags have been converted to fixed size by | |
25995 | this point. But if this was variable-sized to start with, | |
25996 | there will be a fixed-size frag after it. So don't handle | |
25997 | next == NULL. */ | |
25998 | if (sym == NULL || next == NULL) | |
25999 | continue; | |
26000 | ||
26001 | if (S_GET_VALUE (sym) < next->fr_address) | |
26002 | /* Not at the end of this frag. */ | |
26003 | continue; | |
26004 | know (S_GET_VALUE (sym) == next->fr_address); | |
26005 | ||
26006 | do | |
26007 | { | |
26008 | if (next->tc_frag_data.first_map != NULL) | |
26009 | { | |
26010 | /* Next frag starts with a mapping symbol. Discard this | |
26011 | one. */ | |
26012 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
26013 | break; | |
26014 | } | |
26015 | ||
26016 | if (next->fr_next == NULL) | |
26017 | { | |
26018 | /* This mapping symbol is at the end of the section. Discard | |
26019 | it. */ | |
26020 | know (next->fr_fix == 0 && next->fr_var == 0); | |
26021 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
26022 | break; | |
26023 | } | |
26024 | ||
26025 | /* As long as we have empty frags without any mapping symbols, | |
26026 | keep looking. */ | |
26027 | /* If the next frag is non-empty and does not start with a | |
26028 | mapping symbol, then this mapping symbol is required. */ | |
26029 | if (next->fr_address != next->fr_next->fr_address) | |
26030 | break; | |
26031 | ||
26032 | next = next->fr_next; | |
26033 | } | |
26034 | while (next != NULL); | |
26035 | } | |
26036 | } | |
26037 | #endif | |
26038 | ||
c19d1205 ZW |
26039 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
26040 | ARM ones. */ | |
404ff6b5 | 26041 | |
c19d1205 ZW |
26042 | void |
26043 | arm_adjust_symtab (void) | |
404ff6b5 | 26044 | { |
c19d1205 ZW |
26045 | #ifdef OBJ_COFF |
26046 | symbolS * sym; | |
404ff6b5 | 26047 | |
c19d1205 ZW |
26048 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
26049 | { | |
26050 | if (ARM_IS_THUMB (sym)) | |
26051 | { | |
26052 | if (THUMB_IS_FUNC (sym)) | |
26053 | { | |
26054 | /* Mark the symbol as a Thumb function. */ | |
26055 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
26056 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
26057 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 26058 | |
c19d1205 ZW |
26059 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
26060 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
26061 | else | |
26062 | as_bad (_("%s: unexpected function type: %d"), | |
26063 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
26064 | } | |
26065 | else switch (S_GET_STORAGE_CLASS (sym)) | |
26066 | { | |
26067 | case C_EXT: | |
26068 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
26069 | break; | |
26070 | case C_STAT: | |
26071 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
26072 | break; | |
26073 | case C_LABEL: | |
26074 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
26075 | break; | |
26076 | default: | |
26077 | /* Do nothing. */ | |
26078 | break; | |
26079 | } | |
26080 | } | |
a737bd4d | 26081 | |
c19d1205 ZW |
26082 | if (ARM_IS_INTERWORK (sym)) |
26083 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 26084 | } |
c19d1205 ZW |
26085 | #endif |
26086 | #ifdef OBJ_ELF | |
26087 | symbolS * sym; | |
26088 | char bind; | |
404ff6b5 | 26089 | |
c19d1205 | 26090 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 26091 | { |
c19d1205 ZW |
26092 | if (ARM_IS_THUMB (sym)) |
26093 | { | |
26094 | elf_symbol_type * elf_sym; | |
404ff6b5 | 26095 | |
c19d1205 ZW |
26096 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
26097 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 26098 | |
b0796911 PB |
26099 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
26100 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
26101 | { |
26102 | /* If it's a .thumb_func, declare it as so, | |
26103 | otherwise tag label as .code 16. */ | |
26104 | if (THUMB_IS_FUNC (sym)) | |
39d911fc TP |
26105 | ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal, |
26106 | ST_BRANCH_TO_THUMB); | |
3ba67470 | 26107 | else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
c19d1205 ZW |
26108 | elf_sym->internal_elf_sym.st_info = |
26109 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
26110 | } | |
26111 | } | |
26112 | } | |
cd000bff DJ |
26113 | |
26114 | /* Remove any overlapping mapping symbols generated by alignment frags. */ | |
26115 | bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0); | |
709001e9 MM |
26116 | /* Now do generic ELF adjustments. */ |
26117 | elf_adjust_symtab (); | |
c19d1205 | 26118 | #endif |
404ff6b5 AH |
26119 | } |
26120 | ||
c19d1205 | 26121 | /* MD interface: Initialization. */ |
404ff6b5 | 26122 | |
a737bd4d | 26123 | static void |
c19d1205 | 26124 | set_constant_flonums (void) |
a737bd4d | 26125 | { |
c19d1205 | 26126 | int i; |
404ff6b5 | 26127 | |
c19d1205 ZW |
26128 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
26129 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
26130 | abort (); | |
a737bd4d | 26131 | } |
404ff6b5 | 26132 | |
3e9e4fcf JB |
26133 | /* Auto-select Thumb mode if it's the only available instruction set for the |
26134 | given architecture. */ | |
26135 | ||
26136 | static void | |
26137 | autoselect_thumb_from_cpu_variant (void) | |
26138 | { | |
26139 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) | |
26140 | opcode_select (16); | |
26141 | } | |
26142 | ||
c19d1205 ZW |
26143 | void |
26144 | md_begin (void) | |
a737bd4d | 26145 | { |
c19d1205 ZW |
26146 | unsigned mach; |
26147 | unsigned int i; | |
404ff6b5 | 26148 | |
c19d1205 ZW |
26149 | if ( (arm_ops_hsh = hash_new ()) == NULL |
26150 | || (arm_cond_hsh = hash_new ()) == NULL | |
26151 | || (arm_shift_hsh = hash_new ()) == NULL | |
26152 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 26153 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 26154 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
26155 | || (arm_reloc_hsh = hash_new ()) == NULL |
26156 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
26157 | as_fatal (_("virtual memory exhausted")); |
26158 | ||
26159 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
d3ce72d0 | 26160 | hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i)); |
c19d1205 | 26161 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) |
d3ce72d0 | 26162 | hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i)); |
c19d1205 | 26163 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) |
5a49b8ac | 26164 | hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i)); |
c19d1205 | 26165 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 | 26166 | hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i)); |
62b3e311 | 26167 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 | 26168 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name, |
477330fc | 26169 | (void *) (v7m_psrs + i)); |
c19d1205 | 26170 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
5a49b8ac | 26171 | hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i)); |
62b3e311 PB |
26172 | for (i = 0; |
26173 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
26174 | i++) | |
d3ce72d0 | 26175 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name, |
5a49b8ac | 26176 | (void *) (barrier_opt_names + i)); |
c19d1205 | 26177 | #ifdef OBJ_ELF |
3da1d841 NC |
26178 | for (i = 0; i < ARRAY_SIZE (reloc_names); i++) |
26179 | { | |
26180 | struct reloc_entry * entry = reloc_names + i; | |
26181 | ||
26182 | if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32) | |
26183 | /* This makes encode_branch() use the EABI versions of this relocation. */ | |
26184 | entry->reloc = BFD_RELOC_UNUSED; | |
26185 | ||
26186 | hash_insert (arm_reloc_hsh, entry->name, (void *) entry); | |
26187 | } | |
c19d1205 ZW |
26188 | #endif |
26189 | ||
26190 | set_constant_flonums (); | |
404ff6b5 | 26191 | |
c19d1205 ZW |
26192 | /* Set the cpu variant based on the command-line options. We prefer |
26193 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
26194 | -mfpu= over any other way of setting the floating point unit. | |
26195 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 26196 | if (legacy_cpu) |
404ff6b5 | 26197 | { |
e74cfd16 | 26198 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
26199 | as_bad (_("use of old and new-style options to set CPU type")); |
26200 | ||
4d354d8b | 26201 | selected_arch = *legacy_cpu; |
404ff6b5 | 26202 | } |
4d354d8b TP |
26203 | else if (mcpu_cpu_opt) |
26204 | { | |
26205 | selected_arch = *mcpu_cpu_opt; | |
26206 | selected_ext = *mcpu_ext_opt; | |
26207 | } | |
26208 | else if (march_cpu_opt) | |
c168ce07 | 26209 | { |
4d354d8b TP |
26210 | selected_arch = *march_cpu_opt; |
26211 | selected_ext = *march_ext_opt; | |
c168ce07 | 26212 | } |
4d354d8b | 26213 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext); |
404ff6b5 | 26214 | |
e74cfd16 | 26215 | if (legacy_fpu) |
c19d1205 | 26216 | { |
e74cfd16 | 26217 | if (mfpu_opt) |
c19d1205 | 26218 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f | 26219 | |
4d354d8b | 26220 | selected_fpu = *legacy_fpu; |
03b1477f | 26221 | } |
4d354d8b TP |
26222 | else if (mfpu_opt) |
26223 | selected_fpu = *mfpu_opt; | |
26224 | else | |
03b1477f | 26225 | { |
45eb4c1b NS |
26226 | #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \ |
26227 | || defined (TE_NetBSD) || defined (TE_VXWORKS)) | |
39c2da32 RE |
26228 | /* Some environments specify a default FPU. If they don't, infer it |
26229 | from the processor. */ | |
e74cfd16 | 26230 | if (mcpu_fpu_opt) |
4d354d8b | 26231 | selected_fpu = *mcpu_fpu_opt; |
e7da50fa | 26232 | else if (march_fpu_opt) |
4d354d8b | 26233 | selected_fpu = *march_fpu_opt; |
39c2da32 | 26234 | #else |
4d354d8b | 26235 | selected_fpu = fpu_default; |
39c2da32 | 26236 | #endif |
03b1477f RE |
26237 | } |
26238 | ||
4d354d8b | 26239 | if (ARM_FEATURE_ZERO (selected_fpu)) |
03b1477f | 26240 | { |
4d354d8b TP |
26241 | if (!no_cpu_selected ()) |
26242 | selected_fpu = fpu_default; | |
03b1477f | 26243 | else |
4d354d8b | 26244 | selected_fpu = fpu_arch_fpa; |
03b1477f RE |
26245 | } |
26246 | ||
ee065d83 | 26247 | #ifdef CPU_DEFAULT |
4d354d8b | 26248 | if (ARM_FEATURE_ZERO (selected_arch)) |
ee065d83 | 26249 | { |
4d354d8b TP |
26250 | selected_arch = cpu_default; |
26251 | selected_cpu = selected_arch; | |
ee065d83 | 26252 | } |
4d354d8b | 26253 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
e74cfd16 | 26254 | #else |
4d354d8b TP |
26255 | /* Autodection of feature mode: allow all features in cpu_variant but leave |
26256 | selected_cpu unset. It will be set in aeabi_set_public_attributes () | |
26257 | after all instruction have been processed and we can decide what CPU | |
26258 | should be selected. */ | |
26259 | if (ARM_FEATURE_ZERO (selected_arch)) | |
26260 | ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu); | |
ee065d83 | 26261 | else |
4d354d8b | 26262 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
ee065d83 | 26263 | #endif |
03b1477f | 26264 | |
3e9e4fcf JB |
26265 | autoselect_thumb_from_cpu_variant (); |
26266 | ||
e74cfd16 | 26267 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 26268 | |
f17c130b | 26269 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 26270 | { |
7cc69913 NC |
26271 | unsigned int flags = 0; |
26272 | ||
26273 | #if defined OBJ_ELF | |
26274 | flags = meabi_flags; | |
d507cf36 PB |
26275 | |
26276 | switch (meabi_flags) | |
33a392fb | 26277 | { |
d507cf36 | 26278 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 26279 | #endif |
d507cf36 PB |
26280 | /* Set the flags in the private structure. */ |
26281 | if (uses_apcs_26) flags |= F_APCS26; | |
26282 | if (support_interwork) flags |= F_INTERWORK; | |
26283 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 26284 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 26285 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
26286 | flags |= F_SOFT_FLOAT; |
26287 | ||
d507cf36 PB |
26288 | switch (mfloat_abi_opt) |
26289 | { | |
26290 | case ARM_FLOAT_ABI_SOFT: | |
26291 | case ARM_FLOAT_ABI_SOFTFP: | |
26292 | flags |= F_SOFT_FLOAT; | |
26293 | break; | |
33a392fb | 26294 | |
d507cf36 PB |
26295 | case ARM_FLOAT_ABI_HARD: |
26296 | if (flags & F_SOFT_FLOAT) | |
26297 | as_bad (_("hard-float conflicts with specified fpu")); | |
26298 | break; | |
26299 | } | |
03b1477f | 26300 | |
e74cfd16 PB |
26301 | /* Using pure-endian doubles (even if soft-float). */ |
26302 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 26303 | flags |= F_VFP_FLOAT; |
f17c130b | 26304 | |
fde78edd | 26305 | #if defined OBJ_ELF |
e74cfd16 | 26306 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 26307 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
26308 | break; |
26309 | ||
8cb51566 | 26310 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 26311 | case EF_ARM_EABI_VER5: |
c19d1205 | 26312 | /* No additional flags to set. */ |
d507cf36 PB |
26313 | break; |
26314 | ||
26315 | default: | |
26316 | abort (); | |
26317 | } | |
7cc69913 | 26318 | #endif |
b99bd4ef NC |
26319 | bfd_set_private_flags (stdoutput, flags); |
26320 | ||
26321 | /* We have run out flags in the COFF header to encode the | |
26322 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 26323 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
26324 | if (atpcs) |
26325 | { | |
26326 | asection * sec; | |
26327 | ||
26328 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
26329 | ||
26330 | if (sec != NULL) | |
26331 | { | |
26332 | bfd_set_section_flags | |
26333 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
26334 | bfd_set_section_size (stdoutput, sec, 0); | |
26335 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
26336 | } | |
26337 | } | |
7cc69913 | 26338 | } |
f17c130b | 26339 | #endif |
b99bd4ef NC |
26340 | |
26341 | /* Record the CPU type as well. */ | |
2d447fca JM |
26342 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)) |
26343 | mach = bfd_mach_arm_iWMMXt2; | |
26344 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) | |
e16bb312 | 26345 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 26346 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 26347 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 26348 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 26349 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 26350 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 26351 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 26352 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 26353 | { |
e74cfd16 | 26354 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
26355 | mach = bfd_mach_arm_5T; |
26356 | else | |
26357 | mach = bfd_mach_arm_5; | |
26358 | } | |
e74cfd16 | 26359 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 26360 | { |
e74cfd16 | 26361 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
26362 | mach = bfd_mach_arm_4T; |
26363 | else | |
26364 | mach = bfd_mach_arm_4; | |
26365 | } | |
e74cfd16 | 26366 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 26367 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
26368 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
26369 | mach = bfd_mach_arm_3; | |
26370 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
26371 | mach = bfd_mach_arm_2a; | |
26372 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
26373 | mach = bfd_mach_arm_2; | |
26374 | else | |
26375 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
26376 | |
26377 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
26378 | } | |
26379 | ||
c19d1205 | 26380 | /* Command line processing. */ |
b99bd4ef | 26381 | |
c19d1205 ZW |
26382 | /* md_parse_option |
26383 | Invocation line includes a switch not recognized by the base assembler. | |
26384 | See if it's a processor-specific option. | |
b99bd4ef | 26385 | |
c19d1205 ZW |
26386 | This routine is somewhat complicated by the need for backwards |
26387 | compatibility (since older releases of gcc can't be changed). | |
26388 | The new options try to make the interface as compatible as | |
26389 | possible with GCC. | |
b99bd4ef | 26390 | |
c19d1205 | 26391 | New options (supported) are: |
b99bd4ef | 26392 | |
c19d1205 ZW |
26393 | -mcpu=<cpu name> Assemble for selected processor |
26394 | -march=<architecture name> Assemble for selected architecture | |
26395 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
26396 | -EB/-mbig-endian Big-endian | |
26397 | -EL/-mlittle-endian Little-endian | |
26398 | -k Generate PIC code | |
26399 | -mthumb Start in Thumb mode | |
26400 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 26401 | |
278df34e | 26402 | -m[no-]warn-deprecated Warn about deprecated features |
8b2d793c | 26403 | -m[no-]warn-syms Warn when symbols match instructions |
267bf995 | 26404 | |
c19d1205 | 26405 | For now we will also provide support for: |
b99bd4ef | 26406 | |
c19d1205 ZW |
26407 | -mapcs-32 32-bit Program counter |
26408 | -mapcs-26 26-bit Program counter | |
26409 | -macps-float Floats passed in FP registers | |
26410 | -mapcs-reentrant Reentrant code | |
26411 | -matpcs | |
26412 | (sometime these will probably be replaced with -mapcs=<list of options> | |
26413 | and -matpcs=<list of options>) | |
b99bd4ef | 26414 | |
c19d1205 ZW |
26415 | The remaining options are only supported for back-wards compatibility. |
26416 | Cpu variants, the arm part is optional: | |
26417 | -m[arm]1 Currently not supported. | |
26418 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
26419 | -m[arm]3 Arm 3 processor | |
26420 | -m[arm]6[xx], Arm 6 processors | |
26421 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
26422 | -m[arm]8[10] Arm 8 processors | |
26423 | -m[arm]9[20][tdmi] Arm 9 processors | |
26424 | -mstrongarm[110[0]] StrongARM processors | |
26425 | -mxscale XScale processors | |
26426 | -m[arm]v[2345[t[e]]] Arm architectures | |
26427 | -mall All (except the ARM1) | |
26428 | FP variants: | |
26429 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
26430 | -mfpe-old (No float load/store multiples) | |
26431 | -mvfpxd VFP Single precision | |
26432 | -mvfp All VFP | |
26433 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 26434 | |
c19d1205 ZW |
26435 | The following CPU names are recognized: |
26436 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
26437 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
26438 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
26439 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
26440 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
26441 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
26442 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 26443 | |
c19d1205 | 26444 | */ |
b99bd4ef | 26445 | |
c19d1205 | 26446 | const char * md_shortopts = "m:k"; |
b99bd4ef | 26447 | |
c19d1205 ZW |
26448 | #ifdef ARM_BI_ENDIAN |
26449 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
26450 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 26451 | #else |
c19d1205 ZW |
26452 | #if TARGET_BYTES_BIG_ENDIAN |
26453 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 26454 | #else |
c19d1205 ZW |
26455 | #define OPTION_EL (OPTION_MD_BASE + 1) |
26456 | #endif | |
b99bd4ef | 26457 | #endif |
845b51d6 | 26458 | #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2) |
18a20338 | 26459 | #define OPTION_FDPIC (OPTION_MD_BASE + 3) |
b99bd4ef | 26460 | |
c19d1205 | 26461 | struct option md_longopts[] = |
b99bd4ef | 26462 | { |
c19d1205 ZW |
26463 | #ifdef OPTION_EB |
26464 | {"EB", no_argument, NULL, OPTION_EB}, | |
26465 | #endif | |
26466 | #ifdef OPTION_EL | |
26467 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 26468 | #endif |
845b51d6 | 26469 | {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX}, |
18a20338 CL |
26470 | #ifdef OBJ_ELF |
26471 | {"fdpic", no_argument, NULL, OPTION_FDPIC}, | |
26472 | #endif | |
c19d1205 ZW |
26473 | {NULL, no_argument, NULL, 0} |
26474 | }; | |
b99bd4ef | 26475 | |
c19d1205 | 26476 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 26477 | |
c19d1205 | 26478 | struct arm_option_table |
b99bd4ef | 26479 | { |
0198d5e6 TC |
26480 | const char * option; /* Option name to match. */ |
26481 | const char * help; /* Help information. */ | |
26482 | int * var; /* Variable to change. */ | |
26483 | int value; /* What to change it to. */ | |
26484 | const char * deprecated; /* If non-null, print this message. */ | |
c19d1205 | 26485 | }; |
b99bd4ef | 26486 | |
c19d1205 ZW |
26487 | struct arm_option_table arm_opts[] = |
26488 | { | |
26489 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
26490 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
26491 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
26492 | &support_interwork, 1, NULL}, | |
26493 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
26494 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
26495 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
26496 | 1, NULL}, | |
26497 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
26498 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
26499 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
26500 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
26501 | NULL}, | |
b99bd4ef | 26502 | |
c19d1205 ZW |
26503 | /* These are recognized by the assembler, but have no affect on code. */ |
26504 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
26505 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
278df34e NS |
26506 | |
26507 | {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL}, | |
26508 | {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"), | |
26509 | &warn_on_deprecated, 0, NULL}, | |
8b2d793c NC |
26510 | {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL}, |
26511 | {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL}, | |
e74cfd16 PB |
26512 | {NULL, NULL, NULL, 0, NULL} |
26513 | }; | |
26514 | ||
26515 | struct arm_legacy_option_table | |
26516 | { | |
0198d5e6 TC |
26517 | const char * option; /* Option name to match. */ |
26518 | const arm_feature_set ** var; /* Variable to change. */ | |
26519 | const arm_feature_set value; /* What to change it to. */ | |
26520 | const char * deprecated; /* If non-null, print this message. */ | |
e74cfd16 | 26521 | }; |
b99bd4ef | 26522 | |
e74cfd16 PB |
26523 | const struct arm_legacy_option_table arm_legacy_opts[] = |
26524 | { | |
c19d1205 ZW |
26525 | /* DON'T add any new processors to this list -- we want the whole list |
26526 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
26527 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
26528 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
26529 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
26530 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
26531 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
26532 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
26533 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
26534 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
26535 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
26536 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
26537 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
26538 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
26539 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
26540 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
26541 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
26542 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
26543 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
26544 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
26545 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
26546 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
26547 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
26548 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
26549 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
26550 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
26551 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
26552 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
26553 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
26554 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
26555 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
26556 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
26557 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
26558 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
26559 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
26560 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
26561 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
26562 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
26563 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
26564 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
26565 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
26566 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
26567 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
26568 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
26569 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
26570 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
26571 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
26572 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
26573 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
26574 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
26575 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
26576 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
26577 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
26578 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
26579 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
26580 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
26581 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
26582 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
26583 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
26584 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
26585 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
26586 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
26587 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
26588 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
26589 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
26590 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
26591 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
26592 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
26593 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
26594 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
26595 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
26596 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 26597 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 26598 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 26599 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 26600 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 26601 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
26602 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
26603 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
26604 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 26605 | |
c19d1205 | 26606 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
26607 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
26608 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
26609 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
26610 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
26611 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
26612 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
26613 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
26614 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
26615 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
26616 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
26617 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
26618 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
26619 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
26620 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
26621 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
26622 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
26623 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
26624 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 26625 | |
c19d1205 | 26626 | /* Floating point variants -- don't add any more to this list either. */ |
0198d5e6 TC |
26627 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
26628 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
26629 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
26630 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 26631 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 26632 | |
e74cfd16 | 26633 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 26634 | }; |
7ed4c4c5 | 26635 | |
c19d1205 | 26636 | struct arm_cpu_option_table |
7ed4c4c5 | 26637 | { |
0198d5e6 TC |
26638 | const char * name; |
26639 | size_t name_len; | |
26640 | const arm_feature_set value; | |
26641 | const arm_feature_set ext; | |
c19d1205 ZW |
26642 | /* For some CPUs we assume an FPU unless the user explicitly sets |
26643 | -mfpu=... */ | |
0198d5e6 | 26644 | const arm_feature_set default_fpu; |
ee065d83 PB |
26645 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
26646 | case. */ | |
0198d5e6 | 26647 | const char * canonical_name; |
c19d1205 | 26648 | }; |
7ed4c4c5 | 26649 | |
c19d1205 ZW |
26650 | /* This list should, at a minimum, contain all the cpu names |
26651 | recognized by GCC. */ | |
996b5569 | 26652 | #define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN } |
0198d5e6 | 26653 | |
e74cfd16 | 26654 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 26655 | { |
996b5569 TP |
26656 | ARM_CPU_OPT ("all", NULL, ARM_ANY, |
26657 | ARM_ARCH_NONE, | |
26658 | FPU_ARCH_FPA), | |
26659 | ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1, | |
26660 | ARM_ARCH_NONE, | |
26661 | FPU_ARCH_FPA), | |
26662 | ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2, | |
26663 | ARM_ARCH_NONE, | |
26664 | FPU_ARCH_FPA), | |
26665 | ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S, | |
26666 | ARM_ARCH_NONE, | |
26667 | FPU_ARCH_FPA), | |
26668 | ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S, | |
26669 | ARM_ARCH_NONE, | |
26670 | FPU_ARCH_FPA), | |
26671 | ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3, | |
26672 | ARM_ARCH_NONE, | |
26673 | FPU_ARCH_FPA), | |
26674 | ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3, | |
26675 | ARM_ARCH_NONE, | |
26676 | FPU_ARCH_FPA), | |
26677 | ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3, | |
26678 | ARM_ARCH_NONE, | |
26679 | FPU_ARCH_FPA), | |
26680 | ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3, | |
26681 | ARM_ARCH_NONE, | |
26682 | FPU_ARCH_FPA), | |
26683 | ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3, | |
26684 | ARM_ARCH_NONE, | |
26685 | FPU_ARCH_FPA), | |
26686 | ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3, | |
26687 | ARM_ARCH_NONE, | |
26688 | FPU_ARCH_FPA), | |
26689 | ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M, | |
26690 | ARM_ARCH_NONE, | |
26691 | FPU_ARCH_FPA), | |
26692 | ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3, | |
26693 | ARM_ARCH_NONE, | |
26694 | FPU_ARCH_FPA), | |
26695 | ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M, | |
26696 | ARM_ARCH_NONE, | |
26697 | FPU_ARCH_FPA), | |
26698 | ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3, | |
26699 | ARM_ARCH_NONE, | |
26700 | FPU_ARCH_FPA), | |
26701 | ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M, | |
26702 | ARM_ARCH_NONE, | |
26703 | FPU_ARCH_FPA), | |
26704 | ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3, | |
26705 | ARM_ARCH_NONE, | |
26706 | FPU_ARCH_FPA), | |
26707 | ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3, | |
26708 | ARM_ARCH_NONE, | |
26709 | FPU_ARCH_FPA), | |
26710 | ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3, | |
26711 | ARM_ARCH_NONE, | |
26712 | FPU_ARCH_FPA), | |
26713 | ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3, | |
26714 | ARM_ARCH_NONE, | |
26715 | FPU_ARCH_FPA), | |
26716 | ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T, | |
26717 | ARM_ARCH_NONE, | |
26718 | FPU_ARCH_FPA), | |
26719 | ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3, | |
26720 | ARM_ARCH_NONE, | |
26721 | FPU_ARCH_FPA), | |
26722 | ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T, | |
26723 | ARM_ARCH_NONE, | |
26724 | FPU_ARCH_FPA), | |
26725 | ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T, | |
26726 | ARM_ARCH_NONE, | |
26727 | FPU_ARCH_FPA), | |
26728 | ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3, | |
26729 | ARM_ARCH_NONE, | |
26730 | FPU_ARCH_FPA), | |
26731 | ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3, | |
26732 | ARM_ARCH_NONE, | |
26733 | FPU_ARCH_FPA), | |
26734 | ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3, | |
26735 | ARM_ARCH_NONE, | |
26736 | FPU_ARCH_FPA), | |
26737 | ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3, | |
26738 | ARM_ARCH_NONE, | |
26739 | FPU_ARCH_FPA), | |
26740 | ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T, | |
26741 | ARM_ARCH_NONE, | |
26742 | FPU_ARCH_FPA), | |
26743 | ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T, | |
26744 | ARM_ARCH_NONE, | |
26745 | FPU_ARCH_FPA), | |
26746 | ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T, | |
26747 | ARM_ARCH_NONE, | |
26748 | FPU_ARCH_FPA), | |
26749 | ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4, | |
26750 | ARM_ARCH_NONE, | |
26751 | FPU_ARCH_FPA), | |
26752 | ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4, | |
26753 | ARM_ARCH_NONE, | |
26754 | FPU_ARCH_FPA), | |
26755 | ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4, | |
26756 | ARM_ARCH_NONE, | |
26757 | FPU_ARCH_FPA), | |
26758 | ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4, | |
26759 | ARM_ARCH_NONE, | |
26760 | FPU_ARCH_FPA), | |
26761 | ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4, | |
26762 | ARM_ARCH_NONE, | |
26763 | FPU_ARCH_FPA), | |
26764 | ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4, | |
26765 | ARM_ARCH_NONE, | |
26766 | FPU_ARCH_FPA), | |
26767 | ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4, | |
26768 | ARM_ARCH_NONE, | |
26769 | FPU_ARCH_FPA), | |
26770 | ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T, | |
26771 | ARM_ARCH_NONE, | |
26772 | FPU_ARCH_FPA), | |
26773 | ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T, | |
26774 | ARM_ARCH_NONE, | |
26775 | FPU_ARCH_FPA), | |
26776 | ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T, | |
26777 | ARM_ARCH_NONE, | |
26778 | FPU_ARCH_FPA), | |
26779 | ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T, | |
26780 | ARM_ARCH_NONE, | |
26781 | FPU_ARCH_FPA), | |
26782 | ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T, | |
26783 | ARM_ARCH_NONE, | |
26784 | FPU_ARCH_FPA), | |
26785 | ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T, | |
26786 | ARM_ARCH_NONE, | |
26787 | FPU_ARCH_FPA), | |
26788 | ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4, | |
26789 | ARM_ARCH_NONE, | |
26790 | FPU_ARCH_FPA), | |
26791 | ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4, | |
26792 | ARM_ARCH_NONE, | |
26793 | FPU_ARCH_FPA), | |
26794 | ||
c19d1205 ZW |
26795 | /* For V5 or later processors we default to using VFP; but the user |
26796 | should really set the FPU type explicitly. */ | |
996b5569 TP |
26797 | ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP, |
26798 | ARM_ARCH_NONE, | |
26799 | FPU_ARCH_VFP_V2), | |
26800 | ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE, | |
26801 | ARM_ARCH_NONE, | |
26802 | FPU_ARCH_VFP_V2), | |
26803 | ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ, | |
26804 | ARM_ARCH_NONE, | |
26805 | FPU_ARCH_VFP_V2), | |
26806 | ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ, | |
26807 | ARM_ARCH_NONE, | |
26808 | FPU_ARCH_VFP_V2), | |
26809 | ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ, | |
26810 | ARM_ARCH_NONE, | |
26811 | FPU_ARCH_VFP_V2), | |
26812 | ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP, | |
26813 | ARM_ARCH_NONE, | |
26814 | FPU_ARCH_VFP_V2), | |
26815 | ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE, | |
26816 | ARM_ARCH_NONE, | |
26817 | FPU_ARCH_VFP_V2), | |
26818 | ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE, | |
26819 | ARM_ARCH_NONE, | |
26820 | FPU_ARCH_VFP_V2), | |
26821 | ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP, | |
26822 | ARM_ARCH_NONE, | |
26823 | FPU_ARCH_VFP_V2), | |
26824 | ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE, | |
26825 | ARM_ARCH_NONE, | |
26826 | FPU_ARCH_VFP_V2), | |
26827 | ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE, | |
26828 | ARM_ARCH_NONE, | |
26829 | FPU_ARCH_VFP_V2), | |
26830 | ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE, | |
26831 | ARM_ARCH_NONE, | |
26832 | FPU_ARCH_VFP_V2), | |
26833 | ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T, | |
26834 | ARM_ARCH_NONE, | |
26835 | FPU_ARCH_VFP_V1), | |
26836 | ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T, | |
26837 | ARM_ARCH_NONE, | |
26838 | FPU_ARCH_VFP_V1), | |
26839 | ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE, | |
26840 | ARM_ARCH_NONE, | |
26841 | FPU_ARCH_VFP_V2), | |
26842 | ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE, | |
26843 | ARM_ARCH_NONE, | |
26844 | FPU_ARCH_VFP_V2), | |
26845 | ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T, | |
26846 | ARM_ARCH_NONE, | |
26847 | FPU_ARCH_VFP_V1), | |
26848 | ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE, | |
26849 | ARM_ARCH_NONE, | |
26850 | FPU_ARCH_VFP_V2), | |
26851 | ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE, | |
26852 | ARM_ARCH_NONE, | |
26853 | FPU_ARCH_VFP_V2), | |
26854 | ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ, | |
26855 | ARM_ARCH_NONE, | |
26856 | FPU_ARCH_VFP_V2), | |
26857 | ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ, | |
26858 | ARM_ARCH_NONE, | |
26859 | FPU_ARCH_VFP_V2), | |
26860 | ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE, | |
26861 | ARM_ARCH_NONE, | |
26862 | FPU_ARCH_VFP_V2), | |
26863 | ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE, | |
26864 | ARM_ARCH_NONE, | |
26865 | FPU_ARCH_VFP_V2), | |
26866 | ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE, | |
26867 | ARM_ARCH_NONE, | |
26868 | FPU_ARCH_VFP_V2), | |
26869 | ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE, | |
26870 | ARM_ARCH_NONE, | |
26871 | FPU_ARCH_VFP_V2), | |
26872 | ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE, | |
26873 | ARM_ARCH_NONE, | |
26874 | FPU_ARCH_VFP_V2), | |
26875 | ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6, | |
26876 | ARM_ARCH_NONE, | |
26877 | FPU_NONE), | |
26878 | ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6, | |
26879 | ARM_ARCH_NONE, | |
26880 | FPU_NONE), | |
26881 | ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6, | |
26882 | ARM_ARCH_NONE, | |
26883 | FPU_ARCH_VFP_V2), | |
26884 | ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6, | |
26885 | ARM_ARCH_NONE, | |
26886 | FPU_ARCH_VFP_V2), | |
26887 | ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K, | |
26888 | ARM_ARCH_NONE, | |
26889 | FPU_ARCH_VFP_V2), | |
26890 | ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K, | |
26891 | ARM_ARCH_NONE, | |
26892 | FPU_NONE), | |
26893 | ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2, | |
26894 | ARM_ARCH_NONE, | |
26895 | FPU_NONE), | |
26896 | ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2, | |
26897 | ARM_ARCH_NONE, | |
26898 | FPU_ARCH_VFP_V2), | |
26899 | ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ, | |
26900 | ARM_ARCH_NONE, | |
26901 | FPU_NONE), | |
26902 | ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ, | |
26903 | ARM_ARCH_NONE, | |
26904 | FPU_ARCH_VFP_V2), | |
26905 | ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A, | |
26906 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC), | |
26907 | FPU_NONE), | |
26908 | ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE, | |
26909 | ARM_ARCH_NONE, | |
26910 | FPU_ARCH_NEON_VFP_V4), | |
26911 | ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A, | |
26912 | ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), | |
26913 | ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)), | |
26914 | ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A, | |
26915 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC), | |
26916 | ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)), | |
26917 | ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE, | |
26918 | ARM_ARCH_NONE, | |
26919 | FPU_ARCH_NEON_VFP_V4), | |
26920 | ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE, | |
26921 | ARM_ARCH_NONE, | |
26922 | FPU_ARCH_NEON_VFP_V4), | |
26923 | ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE, | |
26924 | ARM_ARCH_NONE, | |
26925 | FPU_ARCH_NEON_VFP_V4), | |
26926 | ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A, | |
26927 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26928 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
26929 | ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A, | |
26930 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26931 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
26932 | ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A, | |
26933 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26934 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
15a7695f JG |
26935 | ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A, |
26936 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
0198d5e6 | 26937 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), |
996b5569 TP |
26938 | ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A, |
26939 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26940 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
26941 | ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A, | |
26942 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26943 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
26944 | ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A, | |
26945 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26946 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
15a7695f JG |
26947 | ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A, |
26948 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
0198d5e6 | 26949 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), |
7ebd1359 | 26950 | ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A, |
26951 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
26952 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), | |
ef8df4ca KT |
26953 | ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A, |
26954 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
26955 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), | |
996b5569 TP |
26956 | ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R, |
26957 | ARM_ARCH_NONE, | |
26958 | FPU_NONE), | |
26959 | ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R, | |
26960 | ARM_ARCH_NONE, | |
26961 | FPU_ARCH_VFP_V3D16), | |
26962 | ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R, | |
26963 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV), | |
26964 | FPU_NONE), | |
26965 | ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R, | |
26966 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV), | |
26967 | FPU_ARCH_VFP_V3D16), | |
26968 | ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R, | |
26969 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV), | |
26970 | FPU_ARCH_VFP_V3D16), | |
0cda1e19 TP |
26971 | ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R, |
26972 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26973 | FPU_ARCH_NEON_VFP_ARMV8), | |
996b5569 TP |
26974 | ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN, |
26975 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), | |
26976 | FPU_NONE), | |
26977 | ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE, | |
26978 | ARM_ARCH_NONE, | |
26979 | FPU_NONE), | |
26980 | ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM, | |
26981 | ARM_ARCH_NONE, | |
26982 | FPU_NONE), | |
26983 | ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM, | |
26984 | ARM_ARCH_NONE, | |
26985 | FPU_NONE), | |
26986 | ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M, | |
26987 | ARM_ARCH_NONE, | |
26988 | FPU_NONE), | |
26989 | ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM, | |
26990 | ARM_ARCH_NONE, | |
26991 | FPU_NONE), | |
26992 | ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM, | |
26993 | ARM_ARCH_NONE, | |
26994 | FPU_NONE), | |
26995 | ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM, | |
26996 | ARM_ARCH_NONE, | |
26997 | FPU_NONE), | |
26998 | ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A, | |
26999 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
27000 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
83f43c83 KT |
27001 | ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A, |
27002 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
27003 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), | |
c19d1205 | 27004 | /* ??? XSCALE is really an architecture. */ |
996b5569 TP |
27005 | ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE, |
27006 | ARM_ARCH_NONE, | |
27007 | FPU_ARCH_VFP_V2), | |
27008 | ||
c19d1205 | 27009 | /* ??? iwmmxt is not a processor. */ |
996b5569 TP |
27010 | ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT, |
27011 | ARM_ARCH_NONE, | |
27012 | FPU_ARCH_VFP_V2), | |
27013 | ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2, | |
27014 | ARM_ARCH_NONE, | |
27015 | FPU_ARCH_VFP_V2), | |
27016 | ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE, | |
27017 | ARM_ARCH_NONE, | |
27018 | FPU_ARCH_VFP_V2), | |
27019 | ||
0198d5e6 | 27020 | /* Maverick. */ |
996b5569 TP |
27021 | ARM_CPU_OPT ("ep9312", "ARM920T", |
27022 | ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), | |
27023 | ARM_ARCH_NONE, FPU_ARCH_MAVERICK), | |
27024 | ||
da4339ed | 27025 | /* Marvell processors. */ |
996b5569 TP |
27026 | ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A, |
27027 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC), | |
27028 | FPU_ARCH_VFP_V3D16), | |
27029 | ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A, | |
27030 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC), | |
27031 | FPU_ARCH_NEON_VFP_V4), | |
da4339ed | 27032 | |
996b5569 TP |
27033 | /* APM X-Gene family. */ |
27034 | ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A, | |
27035 | ARM_ARCH_NONE, | |
27036 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
27037 | ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A, | |
27038 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
27039 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
27040 | ||
27041 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL } | |
c19d1205 | 27042 | }; |
f3bad469 | 27043 | #undef ARM_CPU_OPT |
7ed4c4c5 | 27044 | |
34ef62f4 AV |
27045 | struct arm_ext_table |
27046 | { | |
27047 | const char * name; | |
27048 | size_t name_len; | |
27049 | const arm_feature_set merge; | |
27050 | const arm_feature_set clear; | |
27051 | }; | |
27052 | ||
c19d1205 | 27053 | struct arm_arch_option_table |
7ed4c4c5 | 27054 | { |
34ef62f4 AV |
27055 | const char * name; |
27056 | size_t name_len; | |
27057 | const arm_feature_set value; | |
27058 | const arm_feature_set default_fpu; | |
27059 | const struct arm_ext_table * ext_table; | |
27060 | }; | |
27061 | ||
27062 | /* Used to add support for +E and +noE extension. */ | |
27063 | #define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C } | |
27064 | /* Used to add support for a +E extension. */ | |
27065 | #define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE } | |
27066 | /* Used to add support for a +noE extension. */ | |
27067 | #define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C } | |
27068 | ||
27069 | #define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \ | |
27070 | ~0 & ~FPU_ENDIAN_PURE) | |
27071 | ||
27072 | static const struct arm_ext_table armv5te_ext_table[] = | |
27073 | { | |
27074 | ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP), | |
27075 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
27076 | }; | |
27077 | ||
27078 | static const struct arm_ext_table armv7_ext_table[] = | |
27079 | { | |
27080 | ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP), | |
27081 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
27082 | }; | |
27083 | ||
27084 | static const struct arm_ext_table armv7ve_ext_table[] = | |
27085 | { | |
27086 | ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP), | |
27087 | ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), | |
27088 | ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3), | |
27089 | ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16), | |
27090 | ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16), | |
27091 | ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */ | |
27092 | ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4), | |
27093 | ||
27094 | ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4, | |
27095 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)), | |
27096 | ||
27097 | /* Aliases for +simd. */ | |
27098 | ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4), | |
27099 | ||
27100 | ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1), | |
27101 | ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1), | |
27102 | ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16), | |
27103 | ||
27104 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
27105 | }; | |
27106 | ||
27107 | static const struct arm_ext_table armv7a_ext_table[] = | |
27108 | { | |
27109 | ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP), | |
27110 | ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */ | |
27111 | ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3), | |
27112 | ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16), | |
27113 | ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16), | |
27114 | ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), | |
27115 | ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4), | |
27116 | ||
27117 | ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1, | |
27118 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)), | |
27119 | ||
27120 | /* Aliases for +simd. */ | |
27121 | ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1), | |
27122 | ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1), | |
27123 | ||
27124 | ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16), | |
27125 | ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4), | |
27126 | ||
27127 | ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)), | |
27128 | ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)), | |
27129 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
27130 | }; | |
27131 | ||
27132 | static const struct arm_ext_table armv7r_ext_table[] = | |
27133 | { | |
27134 | ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD), | |
27135 | ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */ | |
27136 | ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP), | |
27137 | ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */ | |
27138 | ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16), | |
27139 | ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16), | |
27140 | ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), | |
27141 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)), | |
27142 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
27143 | }; | |
27144 | ||
27145 | static const struct arm_ext_table armv7em_ext_table[] = | |
27146 | { | |
27147 | ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP), | |
27148 | /* Alias for +fp, used to be known as fpv4-sp-d16. */ | |
27149 | ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16), | |
27150 | ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16), | |
27151 | ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16), | |
27152 | ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16), | |
27153 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
27154 | }; | |
27155 | ||
27156 | static const struct arm_ext_table armv8a_ext_table[] = | |
27157 | { | |
27158 | ARM_ADD ("crc", ARCH_CRC_ARMV8), | |
27159 | ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8), | |
27160 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, | |
27161 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
27162 | ||
27163 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
27164 | should use the +simd option to turn on FP. */ | |
27165 | ARM_REMOVE ("fp", ALL_FP), | |
27166 | ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)), | |
27167 | ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)), | |
27168 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
27169 | }; | |
27170 | ||
27171 | ||
27172 | static const struct arm_ext_table armv81a_ext_table[] = | |
27173 | { | |
27174 | ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1), | |
27175 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1, | |
27176 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
27177 | ||
27178 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
27179 | should use the +simd option to turn on FP. */ | |
27180 | ARM_REMOVE ("fp", ALL_FP), | |
27181 | ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)), | |
27182 | ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)), | |
27183 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
27184 | }; | |
27185 | ||
27186 | static const struct arm_ext_table armv82a_ext_table[] = | |
27187 | { | |
27188 | ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1), | |
27189 | ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16), | |
27190 | ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML), | |
27191 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1, | |
27192 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
27193 | ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8), | |
27194 | ||
27195 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
27196 | should use the +simd option to turn on FP. */ | |
27197 | ARM_REMOVE ("fp", ALL_FP), | |
27198 | ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)), | |
27199 | ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)), | |
27200 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
27201 | }; | |
27202 | ||
27203 | static const struct arm_ext_table armv84a_ext_table[] = | |
27204 | { | |
27205 | ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8), | |
27206 | ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML), | |
27207 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4, | |
27208 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
27209 | ||
27210 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
27211 | should use the +simd option to turn on FP. */ | |
27212 | ARM_REMOVE ("fp", ALL_FP), | |
27213 | ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)), | |
27214 | ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)), | |
27215 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
27216 | }; | |
27217 | ||
27218 | static const struct arm_ext_table armv85a_ext_table[] = | |
27219 | { | |
27220 | ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8), | |
27221 | ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML), | |
27222 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4, | |
27223 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
27224 | ||
27225 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
27226 | should use the +simd option to turn on FP. */ | |
27227 | ARM_REMOVE ("fp", ALL_FP), | |
27228 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
27229 | }; | |
27230 | ||
27231 | static const struct arm_ext_table armv8m_main_ext_table[] = | |
27232 | { | |
27233 | ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), | |
27234 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)), | |
27235 | ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP), | |
27236 | ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16), | |
27237 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
27238 | }; | |
27239 | ||
e0991585 AV |
27240 | static const struct arm_ext_table armv8_1m_main_ext_table[] = |
27241 | { | |
27242 | ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), | |
27243 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)), | |
27244 | ARM_EXT ("fp", | |
27245 | ARM_FEATURE (0, ARM_EXT2_FP16_INST, | |
27246 | FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA), | |
27247 | ALL_FP), | |
27248 | ARM_ADD ("fp.dp", | |
27249 | ARM_FEATURE (0, ARM_EXT2_FP16_INST, | |
27250 | FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)), | |
27251 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
27252 | }; | |
27253 | ||
34ef62f4 AV |
27254 | static const struct arm_ext_table armv8r_ext_table[] = |
27255 | { | |
27256 | ARM_ADD ("crc", ARCH_CRC_ARMV8), | |
27257 | ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8), | |
27258 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, | |
27259 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
27260 | ARM_REMOVE ("fp", ALL_FP), | |
27261 | ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16), | |
27262 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
c19d1205 | 27263 | }; |
7ed4c4c5 | 27264 | |
c19d1205 ZW |
27265 | /* This list should, at a minimum, contain all the architecture names |
27266 | recognized by GCC. */ | |
34ef62f4 AV |
27267 | #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL } |
27268 | #define ARM_ARCH_OPT2(N, V, DF, ext) \ | |
27269 | { N, sizeof (N) - 1, V, DF, ext##_ext_table } | |
0198d5e6 | 27270 | |
e74cfd16 | 27271 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 | 27272 | { |
497d849d TP |
27273 | ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA), |
27274 | ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA), | |
27275 | ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA), | |
27276 | ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA), | |
27277 | ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA), | |
27278 | ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA), | |
27279 | ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA), | |
27280 | ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA), | |
27281 | ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA), | |
27282 | ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA), | |
27283 | ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA), | |
27284 | ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP), | |
27285 | ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP), | |
27286 | ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP), | |
34ef62f4 AV |
27287 | ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te), |
27288 | ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te), | |
27289 | ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te), | |
27290 | ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te), | |
27291 | ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te), | |
27292 | ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te), | |
27293 | ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te), | |
f33026a9 MW |
27294 | /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is |
27295 | kept to preserve existing behaviour. */ | |
34ef62f4 AV |
27296 | ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te), |
27297 | ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te), | |
27298 | ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te), | |
27299 | ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te), | |
27300 | ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te), | |
f33026a9 MW |
27301 | /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is |
27302 | kept to preserve existing behaviour. */ | |
34ef62f4 AV |
27303 | ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te), |
27304 | ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te), | |
497d849d TP |
27305 | ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP), |
27306 | ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP), | |
34ef62f4 | 27307 | ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7), |
c450d570 PB |
27308 | /* The official spelling of the ARMv7 profile variants is the dashed form. |
27309 | Accept the non-dashed form for compatibility with old toolchains. */ | |
34ef62f4 AV |
27310 | ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a), |
27311 | ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve), | |
27312 | ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r), | |
497d849d | 27313 | ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP), |
34ef62f4 AV |
27314 | ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a), |
27315 | ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r), | |
497d849d | 27316 | ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP), |
34ef62f4 | 27317 | ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em), |
497d849d | 27318 | ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP), |
34ef62f4 AV |
27319 | ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP, |
27320 | armv8m_main), | |
e0991585 AV |
27321 | ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP, |
27322 | armv8_1m_main), | |
34ef62f4 AV |
27323 | ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a), |
27324 | ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a), | |
27325 | ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a), | |
27326 | ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a), | |
27327 | ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r), | |
27328 | ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a), | |
27329 | ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a), | |
497d849d TP |
27330 | ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP), |
27331 | ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP), | |
27332 | ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP), | |
34ef62f4 | 27333 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL } |
c19d1205 | 27334 | }; |
f3bad469 | 27335 | #undef ARM_ARCH_OPT |
7ed4c4c5 | 27336 | |
69133863 | 27337 | /* ISA extensions in the co-processor and main instruction set space. */ |
0198d5e6 | 27338 | |
69133863 | 27339 | struct arm_option_extension_value_table |
c19d1205 | 27340 | { |
0198d5e6 TC |
27341 | const char * name; |
27342 | size_t name_len; | |
27343 | const arm_feature_set merge_value; | |
27344 | const arm_feature_set clear_value; | |
d942732e TP |
27345 | /* List of architectures for which an extension is available. ARM_ARCH_NONE |
27346 | indicates that an extension is available for all architectures while | |
27347 | ARM_ANY marks an empty entry. */ | |
0198d5e6 | 27348 | const arm_feature_set allowed_archs[2]; |
c19d1205 | 27349 | }; |
7ed4c4c5 | 27350 | |
0198d5e6 TC |
27351 | /* The following table must be in alphabetical order with a NULL last entry. */ |
27352 | ||
d942732e TP |
27353 | #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } } |
27354 | #define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} } | |
0198d5e6 | 27355 | |
34ef62f4 AV |
27356 | /* DEPRECATED: Refrain from using this table to add any new extensions, instead |
27357 | use the context sensitive approach using arm_ext_table's. */ | |
69133863 | 27358 | static const struct arm_option_extension_value_table arm_extensions[] = |
c19d1205 | 27359 | { |
823d2571 TG |
27360 | ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8), |
27361 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
bca38921 | 27362 | ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
823d2571 TG |
27363 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8), |
27364 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
c604a79a JW |
27365 | ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8, |
27366 | ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD), | |
27367 | ARM_ARCH_V8_2A), | |
15afaa63 TP |
27368 | ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), |
27369 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), | |
27370 | ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)), | |
823d2571 TG |
27371 | ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8), |
27372 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
b8ec4e87 JW |
27373 | ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), |
27374 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
27375 | ARM_ARCH_V8_2A), | |
01f48020 TC |
27376 | ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST |
27377 | | ARM_EXT2_FP16_FML), | |
27378 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | |
27379 | | ARM_EXT2_FP16_FML), | |
27380 | ARM_ARCH_V8_2A), | |
d942732e | 27381 | ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), |
823d2571 | 27382 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), |
d942732e TP |
27383 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A), |
27384 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)), | |
3d030cdb TP |
27385 | /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of |
27386 | Thumb divide instruction. Due to this having the same name as the | |
27387 | previous entry, this will be ignored when doing command-line parsing and | |
27388 | only considered by build attribute selection code. */ | |
27389 | ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV), | |
27390 | ARM_FEATURE_CORE_LOW (ARM_EXT_DIV), | |
27391 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7)), | |
823d2571 | 27392 | ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), |
d942732e | 27393 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE), |
823d2571 | 27394 | ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), |
d942732e | 27395 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE), |
823d2571 | 27396 | ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), |
d942732e TP |
27397 | ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE), |
27398 | ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP), | |
823d2571 | 27399 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP), |
d942732e TP |
27400 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A), |
27401 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)), | |
823d2571 TG |
27402 | ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS), |
27403 | ARM_FEATURE_CORE_LOW (ARM_EXT_OS), | |
27404 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)), | |
ddfded2f MW |
27405 | ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN), |
27406 | ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0), | |
ced40572 | 27407 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)), |
dad0c3bf SD |
27408 | ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES), |
27409 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES), | |
27410 | ARM_ARCH_V8A), | |
4d1464f2 MW |
27411 | ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS), |
27412 | ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0), | |
ced40572 | 27413 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)), |
643afb90 MW |
27414 | ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1, |
27415 | ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA), | |
ced40572 | 27416 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)), |
7fadb25d SD |
27417 | ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB), |
27418 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB), | |
27419 | ARM_ARCH_V8A), | |
d942732e | 27420 | ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), |
823d2571 | 27421 | ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), |
d942732e TP |
27422 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6K), |
27423 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)), | |
643afb90 MW |
27424 | ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8, |
27425 | ARM_FEATURE_COPROC (FPU_NEON_ARMV8), | |
27426 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
823d2571 TG |
27427 | ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV |
27428 | | ARM_EXT_DIV), | |
27429 | ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT), | |
27430 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)), | |
27431 | ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), | |
d942732e TP |
27432 | ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE), |
27433 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } } | |
69133863 | 27434 | }; |
f3bad469 | 27435 | #undef ARM_EXT_OPT |
69133863 MGD |
27436 | |
27437 | /* ISA floating-point and Advanced SIMD extensions. */ | |
27438 | struct arm_option_fpu_value_table | |
27439 | { | |
0198d5e6 TC |
27440 | const char * name; |
27441 | const arm_feature_set value; | |
c19d1205 | 27442 | }; |
7ed4c4c5 | 27443 | |
c19d1205 ZW |
27444 | /* This list should, at a minimum, contain all the fpu names |
27445 | recognized by GCC. */ | |
69133863 | 27446 | static const struct arm_option_fpu_value_table arm_fpus[] = |
c19d1205 ZW |
27447 | { |
27448 | {"softfpa", FPU_NONE}, | |
27449 | {"fpe", FPU_ARCH_FPE}, | |
27450 | {"fpe2", FPU_ARCH_FPE}, | |
27451 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
27452 | {"fpa", FPU_ARCH_FPA}, | |
27453 | {"fpa10", FPU_ARCH_FPA}, | |
27454 | {"fpa11", FPU_ARCH_FPA}, | |
27455 | {"arm7500fe", FPU_ARCH_FPA}, | |
27456 | {"softvfp", FPU_ARCH_VFP}, | |
27457 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
27458 | {"vfp", FPU_ARCH_VFP_V2}, | |
27459 | {"vfp9", FPU_ARCH_VFP_V2}, | |
d5e0ba9c | 27460 | {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */ |
c19d1205 ZW |
27461 | {"vfp10", FPU_ARCH_VFP_V2}, |
27462 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
27463 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
b1cc4aeb PB |
27464 | {"vfpv2", FPU_ARCH_VFP_V2}, |
27465 | {"vfpv3", FPU_ARCH_VFP_V3}, | |
62f3b8c8 | 27466 | {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16}, |
b1cc4aeb | 27467 | {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, |
62f3b8c8 PB |
27468 | {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16}, |
27469 | {"vfpv3xd", FPU_ARCH_VFP_V3xD}, | |
27470 | {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16}, | |
c19d1205 ZW |
27471 | {"arm1020t", FPU_ARCH_VFP_V1}, |
27472 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
d5e0ba9c | 27473 | {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */ |
c19d1205 ZW |
27474 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, |
27475 | {"maverick", FPU_ARCH_MAVERICK}, | |
d5e0ba9c | 27476 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
d3375ddd | 27477 | {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
8e79c3df | 27478 | {"neon-fp16", FPU_ARCH_NEON_FP16}, |
62f3b8c8 PB |
27479 | {"vfpv4", FPU_ARCH_VFP_V4}, |
27480 | {"vfpv4-d16", FPU_ARCH_VFP_V4D16}, | |
ada65aa3 | 27481 | {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16}, |
a715796b TG |
27482 | {"fpv5-d16", FPU_ARCH_VFP_V5D16}, |
27483 | {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16}, | |
62f3b8c8 | 27484 | {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4}, |
bca38921 MGD |
27485 | {"fp-armv8", FPU_ARCH_VFP_ARMV8}, |
27486 | {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8}, | |
27487 | {"crypto-neon-fp-armv8", | |
27488 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8}, | |
d6b4b13e | 27489 | {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1}, |
081e4c7d MW |
27490 | {"crypto-neon-fp-armv8.1", |
27491 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1}, | |
e74cfd16 PB |
27492 | {NULL, ARM_ARCH_NONE} |
27493 | }; | |
27494 | ||
27495 | struct arm_option_value_table | |
27496 | { | |
e0471c16 | 27497 | const char *name; |
e74cfd16 | 27498 | long value; |
c19d1205 | 27499 | }; |
7ed4c4c5 | 27500 | |
e74cfd16 | 27501 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
27502 | { |
27503 | {"hard", ARM_FLOAT_ABI_HARD}, | |
27504 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
27505 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 27506 | {NULL, 0} |
c19d1205 | 27507 | }; |
7ed4c4c5 | 27508 | |
c19d1205 | 27509 | #ifdef OBJ_ELF |
3a4a14e9 | 27510 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 27511 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
27512 | { |
27513 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
27514 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 27515 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 27516 | {NULL, 0} |
c19d1205 ZW |
27517 | }; |
27518 | #endif | |
7ed4c4c5 | 27519 | |
c19d1205 ZW |
27520 | struct arm_long_option_table |
27521 | { | |
0198d5e6 | 27522 | const char * option; /* Substring to match. */ |
e0471c16 | 27523 | const char * help; /* Help information. */ |
17b9d67d | 27524 | int (* func) (const char * subopt); /* Function to decode sub-option. */ |
e0471c16 | 27525 | const char * deprecated; /* If non-null, print this message. */ |
c19d1205 | 27526 | }; |
7ed4c4c5 | 27527 | |
c921be7d | 27528 | static bfd_boolean |
c168ce07 | 27529 | arm_parse_extension (const char *str, const arm_feature_set *opt_set, |
34ef62f4 AV |
27530 | arm_feature_set *ext_set, |
27531 | const struct arm_ext_table *ext_table) | |
7ed4c4c5 | 27532 | { |
69133863 | 27533 | /* We insist on extensions being specified in alphabetical order, and with |
fa94de6b RM |
27534 | extensions being added before being removed. We achieve this by having |
27535 | the global ARM_EXTENSIONS table in alphabetical order, and using the | |
69133863 | 27536 | ADDING_VALUE variable to indicate whether we are adding an extension (1) |
fa94de6b | 27537 | or removing it (0) and only allowing it to change in the order |
69133863 MGD |
27538 | -1 -> 1 -> 0. */ |
27539 | const struct arm_option_extension_value_table * opt = NULL; | |
d942732e | 27540 | const arm_feature_set arm_any = ARM_ANY; |
69133863 MGD |
27541 | int adding_value = -1; |
27542 | ||
c19d1205 | 27543 | while (str != NULL && *str != 0) |
7ed4c4c5 | 27544 | { |
82b8a785 | 27545 | const char *ext; |
f3bad469 | 27546 | size_t len; |
7ed4c4c5 | 27547 | |
c19d1205 ZW |
27548 | if (*str != '+') |
27549 | { | |
27550 | as_bad (_("invalid architectural extension")); | |
c921be7d | 27551 | return FALSE; |
c19d1205 | 27552 | } |
7ed4c4c5 | 27553 | |
c19d1205 ZW |
27554 | str++; |
27555 | ext = strchr (str, '+'); | |
7ed4c4c5 | 27556 | |
c19d1205 | 27557 | if (ext != NULL) |
f3bad469 | 27558 | len = ext - str; |
c19d1205 | 27559 | else |
f3bad469 | 27560 | len = strlen (str); |
7ed4c4c5 | 27561 | |
f3bad469 | 27562 | if (len >= 2 && strncmp (str, "no", 2) == 0) |
69133863 MGD |
27563 | { |
27564 | if (adding_value != 0) | |
27565 | { | |
27566 | adding_value = 0; | |
27567 | opt = arm_extensions; | |
27568 | } | |
27569 | ||
f3bad469 | 27570 | len -= 2; |
69133863 MGD |
27571 | str += 2; |
27572 | } | |
f3bad469 | 27573 | else if (len > 0) |
69133863 MGD |
27574 | { |
27575 | if (adding_value == -1) | |
27576 | { | |
27577 | adding_value = 1; | |
27578 | opt = arm_extensions; | |
27579 | } | |
27580 | else if (adding_value != 1) | |
27581 | { | |
27582 | as_bad (_("must specify extensions to add before specifying " | |
27583 | "those to remove")); | |
27584 | return FALSE; | |
27585 | } | |
27586 | } | |
27587 | ||
f3bad469 | 27588 | if (len == 0) |
c19d1205 ZW |
27589 | { |
27590 | as_bad (_("missing architectural extension")); | |
c921be7d | 27591 | return FALSE; |
c19d1205 | 27592 | } |
7ed4c4c5 | 27593 | |
69133863 MGD |
27594 | gas_assert (adding_value != -1); |
27595 | gas_assert (opt != NULL); | |
27596 | ||
34ef62f4 AV |
27597 | if (ext_table != NULL) |
27598 | { | |
27599 | const struct arm_ext_table * ext_opt = ext_table; | |
27600 | bfd_boolean found = FALSE; | |
27601 | for (; ext_opt->name != NULL; ext_opt++) | |
27602 | if (ext_opt->name_len == len | |
27603 | && strncmp (ext_opt->name, str, len) == 0) | |
27604 | { | |
27605 | if (adding_value) | |
27606 | { | |
27607 | if (ARM_FEATURE_ZERO (ext_opt->merge)) | |
27608 | /* TODO: Option not supported. When we remove the | |
27609 | legacy table this case should error out. */ | |
27610 | continue; | |
27611 | ||
27612 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge); | |
27613 | } | |
27614 | else | |
27615 | { | |
27616 | if (ARM_FEATURE_ZERO (ext_opt->clear)) | |
27617 | /* TODO: Option not supported. When we remove the | |
27618 | legacy table this case should error out. */ | |
27619 | continue; | |
27620 | ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear); | |
27621 | } | |
27622 | found = TRUE; | |
27623 | break; | |
27624 | } | |
27625 | if (found) | |
27626 | { | |
27627 | str = ext; | |
27628 | continue; | |
27629 | } | |
27630 | } | |
27631 | ||
69133863 MGD |
27632 | /* Scan over the options table trying to find an exact match. */ |
27633 | for (; opt->name != NULL; opt++) | |
f3bad469 | 27634 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 27635 | { |
d942732e TP |
27636 | int i, nb_allowed_archs = |
27637 | sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]); | |
69133863 | 27638 | /* Check we can apply the extension to this architecture. */ |
d942732e TP |
27639 | for (i = 0; i < nb_allowed_archs; i++) |
27640 | { | |
27641 | /* Empty entry. */ | |
27642 | if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any)) | |
27643 | continue; | |
c168ce07 | 27644 | if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set)) |
d942732e TP |
27645 | break; |
27646 | } | |
27647 | if (i == nb_allowed_archs) | |
69133863 MGD |
27648 | { |
27649 | as_bad (_("extension does not apply to the base architecture")); | |
27650 | return FALSE; | |
27651 | } | |
27652 | ||
27653 | /* Add or remove the extension. */ | |
27654 | if (adding_value) | |
4d354d8b | 27655 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value); |
69133863 | 27656 | else |
4d354d8b | 27657 | ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value); |
69133863 | 27658 | |
3d030cdb TP |
27659 | /* Allowing Thumb division instructions for ARMv7 in autodetection |
27660 | rely on this break so that duplicate extensions (extensions | |
27661 | with the same name as a previous extension in the list) are not | |
27662 | considered for command-line parsing. */ | |
c19d1205 ZW |
27663 | break; |
27664 | } | |
7ed4c4c5 | 27665 | |
c19d1205 ZW |
27666 | if (opt->name == NULL) |
27667 | { | |
69133863 MGD |
27668 | /* Did we fail to find an extension because it wasn't specified in |
27669 | alphabetical order, or because it does not exist? */ | |
27670 | ||
27671 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
f3bad469 | 27672 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
69133863 MGD |
27673 | break; |
27674 | ||
27675 | if (opt->name == NULL) | |
27676 | as_bad (_("unknown architectural extension `%s'"), str); | |
27677 | else | |
27678 | as_bad (_("architectural extensions must be specified in " | |
27679 | "alphabetical order")); | |
27680 | ||
c921be7d | 27681 | return FALSE; |
c19d1205 | 27682 | } |
69133863 MGD |
27683 | else |
27684 | { | |
27685 | /* We should skip the extension we've just matched the next time | |
27686 | round. */ | |
27687 | opt++; | |
27688 | } | |
7ed4c4c5 | 27689 | |
c19d1205 ZW |
27690 | str = ext; |
27691 | }; | |
7ed4c4c5 | 27692 | |
c921be7d | 27693 | return TRUE; |
c19d1205 | 27694 | } |
7ed4c4c5 | 27695 | |
c921be7d | 27696 | static bfd_boolean |
17b9d67d | 27697 | arm_parse_cpu (const char *str) |
7ed4c4c5 | 27698 | { |
f3bad469 | 27699 | const struct arm_cpu_option_table *opt; |
82b8a785 | 27700 | const char *ext = strchr (str, '+'); |
f3bad469 | 27701 | size_t len; |
7ed4c4c5 | 27702 | |
c19d1205 | 27703 | if (ext != NULL) |
f3bad469 | 27704 | len = ext - str; |
7ed4c4c5 | 27705 | else |
f3bad469 | 27706 | len = strlen (str); |
7ed4c4c5 | 27707 | |
f3bad469 | 27708 | if (len == 0) |
7ed4c4c5 | 27709 | { |
c19d1205 | 27710 | as_bad (_("missing cpu name `%s'"), str); |
c921be7d | 27711 | return FALSE; |
7ed4c4c5 NC |
27712 | } |
27713 | ||
c19d1205 | 27714 | for (opt = arm_cpus; opt->name != NULL; opt++) |
f3bad469 | 27715 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 27716 | { |
c168ce07 | 27717 | mcpu_cpu_opt = &opt->value; |
4d354d8b TP |
27718 | if (mcpu_ext_opt == NULL) |
27719 | mcpu_ext_opt = XNEW (arm_feature_set); | |
27720 | *mcpu_ext_opt = opt->ext; | |
e74cfd16 | 27721 | mcpu_fpu_opt = &opt->default_fpu; |
ee065d83 | 27722 | if (opt->canonical_name) |
ef8e6722 JW |
27723 | { |
27724 | gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name)); | |
27725 | strcpy (selected_cpu_name, opt->canonical_name); | |
27726 | } | |
ee065d83 PB |
27727 | else |
27728 | { | |
f3bad469 | 27729 | size_t i; |
c921be7d | 27730 | |
ef8e6722 JW |
27731 | if (len >= sizeof selected_cpu_name) |
27732 | len = (sizeof selected_cpu_name) - 1; | |
27733 | ||
f3bad469 | 27734 | for (i = 0; i < len; i++) |
ee065d83 PB |
27735 | selected_cpu_name[i] = TOUPPER (opt->name[i]); |
27736 | selected_cpu_name[i] = 0; | |
27737 | } | |
7ed4c4c5 | 27738 | |
c19d1205 | 27739 | if (ext != NULL) |
34ef62f4 | 27740 | return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL); |
7ed4c4c5 | 27741 | |
c921be7d | 27742 | return TRUE; |
c19d1205 | 27743 | } |
7ed4c4c5 | 27744 | |
c19d1205 | 27745 | as_bad (_("unknown cpu `%s'"), str); |
c921be7d | 27746 | return FALSE; |
7ed4c4c5 NC |
27747 | } |
27748 | ||
c921be7d | 27749 | static bfd_boolean |
17b9d67d | 27750 | arm_parse_arch (const char *str) |
7ed4c4c5 | 27751 | { |
e74cfd16 | 27752 | const struct arm_arch_option_table *opt; |
82b8a785 | 27753 | const char *ext = strchr (str, '+'); |
f3bad469 | 27754 | size_t len; |
7ed4c4c5 | 27755 | |
c19d1205 | 27756 | if (ext != NULL) |
f3bad469 | 27757 | len = ext - str; |
7ed4c4c5 | 27758 | else |
f3bad469 | 27759 | len = strlen (str); |
7ed4c4c5 | 27760 | |
f3bad469 | 27761 | if (len == 0) |
7ed4c4c5 | 27762 | { |
c19d1205 | 27763 | as_bad (_("missing architecture name `%s'"), str); |
c921be7d | 27764 | return FALSE; |
7ed4c4c5 NC |
27765 | } |
27766 | ||
c19d1205 | 27767 | for (opt = arm_archs; opt->name != NULL; opt++) |
f3bad469 | 27768 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 27769 | { |
e74cfd16 | 27770 | march_cpu_opt = &opt->value; |
4d354d8b TP |
27771 | if (march_ext_opt == NULL) |
27772 | march_ext_opt = XNEW (arm_feature_set); | |
27773 | *march_ext_opt = arm_arch_none; | |
e74cfd16 | 27774 | march_fpu_opt = &opt->default_fpu; |
5f4273c7 | 27775 | strcpy (selected_cpu_name, opt->name); |
7ed4c4c5 | 27776 | |
c19d1205 | 27777 | if (ext != NULL) |
34ef62f4 AV |
27778 | return arm_parse_extension (ext, march_cpu_opt, march_ext_opt, |
27779 | opt->ext_table); | |
7ed4c4c5 | 27780 | |
c921be7d | 27781 | return TRUE; |
c19d1205 ZW |
27782 | } |
27783 | ||
27784 | as_bad (_("unknown architecture `%s'\n"), str); | |
c921be7d | 27785 | return FALSE; |
7ed4c4c5 | 27786 | } |
eb043451 | 27787 | |
c921be7d | 27788 | static bfd_boolean |
17b9d67d | 27789 | arm_parse_fpu (const char * str) |
c19d1205 | 27790 | { |
69133863 | 27791 | const struct arm_option_fpu_value_table * opt; |
b99bd4ef | 27792 | |
c19d1205 ZW |
27793 | for (opt = arm_fpus; opt->name != NULL; opt++) |
27794 | if (streq (opt->name, str)) | |
27795 | { | |
e74cfd16 | 27796 | mfpu_opt = &opt->value; |
c921be7d | 27797 | return TRUE; |
c19d1205 | 27798 | } |
b99bd4ef | 27799 | |
c19d1205 | 27800 | as_bad (_("unknown floating point format `%s'\n"), str); |
c921be7d | 27801 | return FALSE; |
c19d1205 ZW |
27802 | } |
27803 | ||
c921be7d | 27804 | static bfd_boolean |
17b9d67d | 27805 | arm_parse_float_abi (const char * str) |
b99bd4ef | 27806 | { |
e74cfd16 | 27807 | const struct arm_option_value_table * opt; |
b99bd4ef | 27808 | |
c19d1205 ZW |
27809 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
27810 | if (streq (opt->name, str)) | |
27811 | { | |
27812 | mfloat_abi_opt = opt->value; | |
c921be7d | 27813 | return TRUE; |
c19d1205 | 27814 | } |
cc8a6dd0 | 27815 | |
c19d1205 | 27816 | as_bad (_("unknown floating point abi `%s'\n"), str); |
c921be7d | 27817 | return FALSE; |
c19d1205 | 27818 | } |
b99bd4ef | 27819 | |
c19d1205 | 27820 | #ifdef OBJ_ELF |
c921be7d | 27821 | static bfd_boolean |
17b9d67d | 27822 | arm_parse_eabi (const char * str) |
c19d1205 | 27823 | { |
e74cfd16 | 27824 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 27825 | |
c19d1205 ZW |
27826 | for (opt = arm_eabis; opt->name != NULL; opt++) |
27827 | if (streq (opt->name, str)) | |
27828 | { | |
27829 | meabi_flags = opt->value; | |
c921be7d | 27830 | return TRUE; |
c19d1205 ZW |
27831 | } |
27832 | as_bad (_("unknown EABI `%s'\n"), str); | |
c921be7d | 27833 | return FALSE; |
c19d1205 ZW |
27834 | } |
27835 | #endif | |
cc8a6dd0 | 27836 | |
c921be7d | 27837 | static bfd_boolean |
17b9d67d | 27838 | arm_parse_it_mode (const char * str) |
e07e6e58 | 27839 | { |
c921be7d | 27840 | bfd_boolean ret = TRUE; |
e07e6e58 NC |
27841 | |
27842 | if (streq ("arm", str)) | |
27843 | implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
27844 | else if (streq ("thumb", str)) | |
27845 | implicit_it_mode = IMPLICIT_IT_MODE_THUMB; | |
27846 | else if (streq ("always", str)) | |
27847 | implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS; | |
27848 | else if (streq ("never", str)) | |
27849 | implicit_it_mode = IMPLICIT_IT_MODE_NEVER; | |
27850 | else | |
27851 | { | |
27852 | as_bad (_("unknown implicit IT mode `%s', should be "\ | |
477330fc | 27853 | "arm, thumb, always, or never."), str); |
c921be7d | 27854 | ret = FALSE; |
e07e6e58 NC |
27855 | } |
27856 | ||
27857 | return ret; | |
27858 | } | |
27859 | ||
2e6976a8 | 27860 | static bfd_boolean |
17b9d67d | 27861 | arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED) |
2e6976a8 DG |
27862 | { |
27863 | codecomposer_syntax = TRUE; | |
27864 | arm_comment_chars[0] = ';'; | |
27865 | arm_line_separator_chars[0] = 0; | |
27866 | return TRUE; | |
27867 | } | |
27868 | ||
c19d1205 ZW |
27869 | struct arm_long_option_table arm_long_opts[] = |
27870 | { | |
27871 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
27872 | arm_parse_cpu, NULL}, | |
27873 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
27874 | arm_parse_arch, NULL}, | |
27875 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
27876 | arm_parse_fpu, NULL}, | |
27877 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
27878 | arm_parse_float_abi, NULL}, | |
27879 | #ifdef OBJ_ELF | |
7fac0536 | 27880 | {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"), |
c19d1205 ZW |
27881 | arm_parse_eabi, NULL}, |
27882 | #endif | |
e07e6e58 NC |
27883 | {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"), |
27884 | arm_parse_it_mode, NULL}, | |
2e6976a8 DG |
27885 | {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"), |
27886 | arm_ccs_mode, NULL}, | |
c19d1205 ZW |
27887 | {NULL, NULL, 0, NULL} |
27888 | }; | |
cc8a6dd0 | 27889 | |
c19d1205 | 27890 | int |
17b9d67d | 27891 | md_parse_option (int c, const char * arg) |
c19d1205 ZW |
27892 | { |
27893 | struct arm_option_table *opt; | |
e74cfd16 | 27894 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 27895 | struct arm_long_option_table *lopt; |
b99bd4ef | 27896 | |
c19d1205 | 27897 | switch (c) |
b99bd4ef | 27898 | { |
c19d1205 ZW |
27899 | #ifdef OPTION_EB |
27900 | case OPTION_EB: | |
27901 | target_big_endian = 1; | |
27902 | break; | |
27903 | #endif | |
cc8a6dd0 | 27904 | |
c19d1205 ZW |
27905 | #ifdef OPTION_EL |
27906 | case OPTION_EL: | |
27907 | target_big_endian = 0; | |
27908 | break; | |
27909 | #endif | |
b99bd4ef | 27910 | |
845b51d6 PB |
27911 | case OPTION_FIX_V4BX: |
27912 | fix_v4bx = TRUE; | |
27913 | break; | |
27914 | ||
18a20338 CL |
27915 | #ifdef OBJ_ELF |
27916 | case OPTION_FDPIC: | |
27917 | arm_fdpic = TRUE; | |
27918 | break; | |
27919 | #endif /* OBJ_ELF */ | |
27920 | ||
c19d1205 ZW |
27921 | case 'a': |
27922 | /* Listing option. Just ignore these, we don't support additional | |
27923 | ones. */ | |
27924 | return 0; | |
b99bd4ef | 27925 | |
c19d1205 ZW |
27926 | default: |
27927 | for (opt = arm_opts; opt->option != NULL; opt++) | |
27928 | { | |
27929 | if (c == opt->option[0] | |
27930 | && ((arg == NULL && opt->option[1] == 0) | |
27931 | || streq (arg, opt->option + 1))) | |
27932 | { | |
c19d1205 | 27933 | /* If the option is deprecated, tell the user. */ |
278df34e | 27934 | if (warn_on_deprecated && opt->deprecated != NULL) |
c19d1205 ZW |
27935 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
27936 | arg ? arg : "", _(opt->deprecated)); | |
b99bd4ef | 27937 | |
c19d1205 ZW |
27938 | if (opt->var != NULL) |
27939 | *opt->var = opt->value; | |
cc8a6dd0 | 27940 | |
c19d1205 ZW |
27941 | return 1; |
27942 | } | |
27943 | } | |
b99bd4ef | 27944 | |
e74cfd16 PB |
27945 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
27946 | { | |
27947 | if (c == fopt->option[0] | |
27948 | && ((arg == NULL && fopt->option[1] == 0) | |
27949 | || streq (arg, fopt->option + 1))) | |
27950 | { | |
e74cfd16 | 27951 | /* If the option is deprecated, tell the user. */ |
278df34e | 27952 | if (warn_on_deprecated && fopt->deprecated != NULL) |
e74cfd16 PB |
27953 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
27954 | arg ? arg : "", _(fopt->deprecated)); | |
e74cfd16 PB |
27955 | |
27956 | if (fopt->var != NULL) | |
27957 | *fopt->var = &fopt->value; | |
27958 | ||
27959 | return 1; | |
27960 | } | |
27961 | } | |
27962 | ||
c19d1205 ZW |
27963 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
27964 | { | |
27965 | /* These options are expected to have an argument. */ | |
27966 | if (c == lopt->option[0] | |
27967 | && arg != NULL | |
27968 | && strncmp (arg, lopt->option + 1, | |
27969 | strlen (lopt->option + 1)) == 0) | |
27970 | { | |
c19d1205 | 27971 | /* If the option is deprecated, tell the user. */ |
278df34e | 27972 | if (warn_on_deprecated && lopt->deprecated != NULL) |
c19d1205 ZW |
27973 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, |
27974 | _(lopt->deprecated)); | |
b99bd4ef | 27975 | |
c19d1205 ZW |
27976 | /* Call the sup-option parser. */ |
27977 | return lopt->func (arg + strlen (lopt->option) - 1); | |
27978 | } | |
27979 | } | |
a737bd4d | 27980 | |
c19d1205 ZW |
27981 | return 0; |
27982 | } | |
a394c00f | 27983 | |
c19d1205 ZW |
27984 | return 1; |
27985 | } | |
a394c00f | 27986 | |
c19d1205 ZW |
27987 | void |
27988 | md_show_usage (FILE * fp) | |
a394c00f | 27989 | { |
c19d1205 ZW |
27990 | struct arm_option_table *opt; |
27991 | struct arm_long_option_table *lopt; | |
a394c00f | 27992 | |
c19d1205 | 27993 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 27994 | |
c19d1205 ZW |
27995 | for (opt = arm_opts; opt->option != NULL; opt++) |
27996 | if (opt->help != NULL) | |
27997 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 27998 | |
c19d1205 ZW |
27999 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
28000 | if (lopt->help != NULL) | |
28001 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 28002 | |
c19d1205 ZW |
28003 | #ifdef OPTION_EB |
28004 | fprintf (fp, _("\ | |
28005 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
28006 | #endif |
28007 | ||
c19d1205 ZW |
28008 | #ifdef OPTION_EL |
28009 | fprintf (fp, _("\ | |
28010 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 28011 | #endif |
845b51d6 PB |
28012 | |
28013 | fprintf (fp, _("\ | |
28014 | --fix-v4bx Allow BX in ARMv4 code\n")); | |
18a20338 CL |
28015 | |
28016 | #ifdef OBJ_ELF | |
28017 | fprintf (fp, _("\ | |
28018 | --fdpic generate an FDPIC object file\n")); | |
28019 | #endif /* OBJ_ELF */ | |
c19d1205 | 28020 | } |
ee065d83 | 28021 | |
ee065d83 | 28022 | #ifdef OBJ_ELF |
0198d5e6 | 28023 | |
62b3e311 PB |
28024 | typedef struct |
28025 | { | |
28026 | int val; | |
28027 | arm_feature_set flags; | |
28028 | } cpu_arch_ver_table; | |
28029 | ||
2c6b98ea TP |
28030 | /* Mapping from CPU features to EABI CPU arch values. Table must be sorted |
28031 | chronologically for architectures, with an exception for ARMv6-M and | |
28032 | ARMv6S-M due to legacy reasons. No new architecture should have a | |
28033 | special case. This allows for build attribute selection results to be | |
28034 | stable when new architectures are added. */ | |
62b3e311 PB |
28035 | static const cpu_arch_ver_table cpu_arch_ver[] = |
28036 | { | |
031254f2 AV |
28037 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1}, |
28038 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2}, | |
28039 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S}, | |
28040 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3}, | |
28041 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M}, | |
28042 | {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM}, | |
28043 | {TAG_CPU_ARCH_V4, ARM_ARCH_V4}, | |
28044 | {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM}, | |
28045 | {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T}, | |
28046 | {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM}, | |
28047 | {TAG_CPU_ARCH_V5T, ARM_ARCH_V5}, | |
28048 | {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM}, | |
28049 | {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T}, | |
28050 | {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP}, | |
28051 | {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE}, | |
28052 | {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ}, | |
28053 | {TAG_CPU_ARCH_V6, ARM_ARCH_V6}, | |
28054 | {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z}, | |
28055 | {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ}, | |
28056 | {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K}, | |
28057 | {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2}, | |
28058 | {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2}, | |
28059 | {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2}, | |
28060 | {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2}, | |
2c6b98ea TP |
28061 | |
28062 | /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as | |
28063 | always selected build attributes to match those of ARMv6-M | |
28064 | (resp. ARMv6S-M). However, due to these architectures being a strict | |
28065 | subset of ARMv7-M in terms of instructions available, ARMv7-M attributes | |
28066 | would be selected when fully respecting chronology of architectures. | |
28067 | It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and | |
28068 | move them before ARMv7 architectures. */ | |
031254f2 AV |
28069 | {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M}, |
28070 | {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM}, | |
28071 | ||
28072 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7}, | |
28073 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7A}, | |
28074 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7R}, | |
28075 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7M}, | |
28076 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE}, | |
28077 | {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM}, | |
28078 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8A}, | |
28079 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A}, | |
28080 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A}, | |
28081 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A}, | |
28082 | {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE}, | |
28083 | {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN}, | |
28084 | {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R}, | |
28085 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A}, | |
28086 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A}, | |
28087 | {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN}, | |
28088 | {-1, ARM_ARCH_NONE} | |
62b3e311 PB |
28089 | }; |
28090 | ||
ee3c0378 | 28091 | /* Set an attribute if it has not already been set by the user. */ |
0198d5e6 | 28092 | |
ee3c0378 AS |
28093 | static void |
28094 | aeabi_set_attribute_int (int tag, int value) | |
28095 | { | |
28096 | if (tag < 1 | |
28097 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
28098 | || !attributes_set_explicitly[tag]) | |
28099 | bfd_elf_add_proc_attr_int (stdoutput, tag, value); | |
28100 | } | |
28101 | ||
28102 | static void | |
28103 | aeabi_set_attribute_string (int tag, const char *value) | |
28104 | { | |
28105 | if (tag < 1 | |
28106 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
28107 | || !attributes_set_explicitly[tag]) | |
28108 | bfd_elf_add_proc_attr_string (stdoutput, tag, value); | |
28109 | } | |
28110 | ||
2c6b98ea TP |
28111 | /* Return whether features in the *NEEDED feature set are available via |
28112 | extensions for the architecture whose feature set is *ARCH_FSET. */ | |
0198d5e6 | 28113 | |
2c6b98ea TP |
28114 | static bfd_boolean |
28115 | have_ext_for_needed_feat_p (const arm_feature_set *arch_fset, | |
28116 | const arm_feature_set *needed) | |
28117 | { | |
28118 | int i, nb_allowed_archs; | |
28119 | arm_feature_set ext_fset; | |
28120 | const struct arm_option_extension_value_table *opt; | |
28121 | ||
28122 | ext_fset = arm_arch_none; | |
28123 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
28124 | { | |
28125 | /* Extension does not provide any feature we need. */ | |
28126 | if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value)) | |
28127 | continue; | |
28128 | ||
28129 | nb_allowed_archs = | |
28130 | sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]); | |
28131 | for (i = 0; i < nb_allowed_archs; i++) | |
28132 | { | |
28133 | /* Empty entry. */ | |
28134 | if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any)) | |
28135 | break; | |
28136 | ||
28137 | /* Extension is available, add it. */ | |
28138 | if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset)) | |
28139 | ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value); | |
28140 | } | |
28141 | } | |
28142 | ||
28143 | /* Can we enable all features in *needed? */ | |
28144 | return ARM_FSET_CPU_SUBSET (*needed, ext_fset); | |
28145 | } | |
28146 | ||
28147 | /* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for | |
28148 | a given architecture feature set *ARCH_EXT_FSET including extension feature | |
28149 | set *EXT_FSET. Selection logic used depend on EXACT_MATCH: | |
28150 | - if true, check for an exact match of the architecture modulo extensions; | |
28151 | - otherwise, select build attribute value of the first superset | |
28152 | architecture released so that results remains stable when new architectures | |
28153 | are added. | |
28154 | For -march/-mcpu=all the build attribute value of the most featureful | |
28155 | architecture is returned. Tag_CPU_arch_profile result is returned in | |
28156 | PROFILE. */ | |
0198d5e6 | 28157 | |
2c6b98ea TP |
28158 | static int |
28159 | get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset, | |
28160 | const arm_feature_set *ext_fset, | |
28161 | char *profile, int exact_match) | |
28162 | { | |
28163 | arm_feature_set arch_fset; | |
28164 | const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL; | |
28165 | ||
28166 | /* Select most featureful architecture with all its extensions if building | |
28167 | for -march=all as the feature sets used to set build attributes. */ | |
28168 | if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any)) | |
28169 | { | |
28170 | /* Force revisiting of decision for each new architecture. */ | |
031254f2 | 28171 | gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN); |
2c6b98ea TP |
28172 | *profile = 'A'; |
28173 | return TAG_CPU_ARCH_V8; | |
28174 | } | |
28175 | ||
28176 | ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset); | |
28177 | ||
28178 | for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++) | |
28179 | { | |
28180 | arm_feature_set known_arch_fset; | |
28181 | ||
28182 | ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any); | |
28183 | if (exact_match) | |
28184 | { | |
28185 | /* Base architecture match user-specified architecture and | |
28186 | extensions, eg. ARMv6S-M matching -march=armv6-m+os. */ | |
28187 | if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset)) | |
28188 | { | |
28189 | p_ver_ret = p_ver; | |
28190 | goto found; | |
28191 | } | |
28192 | /* Base architecture match user-specified architecture only | |
28193 | (eg. ARMv6-M in the same case as above). Record it in case we | |
28194 | find a match with above condition. */ | |
28195 | else if (p_ver_ret == NULL | |
28196 | && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset)) | |
28197 | p_ver_ret = p_ver; | |
28198 | } | |
28199 | else | |
28200 | { | |
28201 | ||
28202 | /* Architecture has all features wanted. */ | |
28203 | if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset)) | |
28204 | { | |
28205 | arm_feature_set added_fset; | |
28206 | ||
28207 | /* Compute features added by this architecture over the one | |
28208 | recorded in p_ver_ret. */ | |
28209 | if (p_ver_ret != NULL) | |
28210 | ARM_CLEAR_FEATURE (added_fset, known_arch_fset, | |
28211 | p_ver_ret->flags); | |
28212 | /* First architecture that match incl. with extensions, or the | |
28213 | only difference in features over the recorded match is | |
28214 | features that were optional and are now mandatory. */ | |
28215 | if (p_ver_ret == NULL | |
28216 | || ARM_FSET_CPU_SUBSET (added_fset, arch_fset)) | |
28217 | { | |
28218 | p_ver_ret = p_ver; | |
28219 | goto found; | |
28220 | } | |
28221 | } | |
28222 | else if (p_ver_ret == NULL) | |
28223 | { | |
28224 | arm_feature_set needed_ext_fset; | |
28225 | ||
28226 | ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset); | |
28227 | ||
28228 | /* Architecture has all features needed when using some | |
28229 | extensions. Record it and continue searching in case there | |
28230 | exist an architecture providing all needed features without | |
28231 | the need for extensions (eg. ARMv6S-M Vs ARMv6-M with | |
28232 | OS extension). */ | |
28233 | if (have_ext_for_needed_feat_p (&known_arch_fset, | |
28234 | &needed_ext_fset)) | |
28235 | p_ver_ret = p_ver; | |
28236 | } | |
28237 | } | |
28238 | } | |
28239 | ||
28240 | if (p_ver_ret == NULL) | |
28241 | return -1; | |
28242 | ||
28243 | found: | |
28244 | /* Tag_CPU_arch_profile. */ | |
28245 | if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a) | |
28246 | || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8) | |
28247 | || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics) | |
28248 | && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only))) | |
28249 | *profile = 'A'; | |
28250 | else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r)) | |
28251 | *profile = 'R'; | |
28252 | else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m)) | |
28253 | *profile = 'M'; | |
28254 | else | |
28255 | *profile = '\0'; | |
28256 | return p_ver_ret->val; | |
28257 | } | |
28258 | ||
ee065d83 | 28259 | /* Set the public EABI object attributes. */ |
0198d5e6 | 28260 | |
c168ce07 | 28261 | static void |
ee065d83 PB |
28262 | aeabi_set_public_attributes (void) |
28263 | { | |
b90d5ba0 | 28264 | char profile = '\0'; |
2c6b98ea | 28265 | int arch = -1; |
90ec0d68 | 28266 | int virt_sec = 0; |
bca38921 | 28267 | int fp16_optional = 0; |
2c6b98ea TP |
28268 | int skip_exact_match = 0; |
28269 | arm_feature_set flags, flags_arch, flags_ext; | |
ee065d83 | 28270 | |
54bab281 TP |
28271 | /* Autodetection mode, choose the architecture based the instructions |
28272 | actually used. */ | |
28273 | if (no_cpu_selected ()) | |
28274 | { | |
28275 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); | |
ddd7f988 | 28276 | |
54bab281 TP |
28277 | if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)) |
28278 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1); | |
ddd7f988 | 28279 | |
54bab281 TP |
28280 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any)) |
28281 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t); | |
ddd7f988 | 28282 | |
54bab281 | 28283 | /* Code run during relaxation relies on selected_cpu being set. */ |
4d354d8b TP |
28284 | ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any); |
28285 | flags_ext = arm_arch_none; | |
28286 | ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext); | |
28287 | selected_ext = flags_ext; | |
54bab281 TP |
28288 | selected_cpu = flags; |
28289 | } | |
28290 | /* Otherwise, choose the architecture based on the capabilities of the | |
28291 | requested cpu. */ | |
28292 | else | |
4d354d8b TP |
28293 | { |
28294 | ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext); | |
28295 | ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any); | |
28296 | flags_ext = selected_ext; | |
28297 | flags = selected_cpu; | |
28298 | } | |
28299 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu); | |
7f78eb34 | 28300 | |
ddd7f988 | 28301 | /* Allow the user to override the reported architecture. */ |
4d354d8b | 28302 | if (!ARM_FEATURE_ZERO (selected_object_arch)) |
7a1d4c38 | 28303 | { |
4d354d8b | 28304 | ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any); |
2c6b98ea | 28305 | flags_ext = arm_arch_none; |
7a1d4c38 | 28306 | } |
2c6b98ea | 28307 | else |
4d354d8b | 28308 | skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any); |
2c6b98ea TP |
28309 | |
28310 | /* When this function is run again after relaxation has happened there is no | |
28311 | way to determine whether an architecture or CPU was specified by the user: | |
28312 | - selected_cpu is set above for relaxation to work; | |
28313 | - march_cpu_opt is not set if only -mcpu or .cpu is used; | |
28314 | - mcpu_cpu_opt is set to arm_arch_any for autodetection. | |
28315 | Therefore, if not in -march=all case we first try an exact match and fall | |
28316 | back to autodetection. */ | |
28317 | if (!skip_exact_match) | |
28318 | arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1); | |
28319 | if (arch == -1) | |
28320 | arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0); | |
28321 | if (arch == -1) | |
28322 | as_bad (_("no architecture contains all the instructions used\n")); | |
9e3c6df6 | 28323 | |
ee065d83 PB |
28324 | /* Tag_CPU_name. */ |
28325 | if (selected_cpu_name[0]) | |
28326 | { | |
91d6fa6a | 28327 | char *q; |
ee065d83 | 28328 | |
91d6fa6a NC |
28329 | q = selected_cpu_name; |
28330 | if (strncmp (q, "armv", 4) == 0) | |
ee065d83 PB |
28331 | { |
28332 | int i; | |
5f4273c7 | 28333 | |
91d6fa6a NC |
28334 | q += 4; |
28335 | for (i = 0; q[i]; i++) | |
28336 | q[i] = TOUPPER (q[i]); | |
ee065d83 | 28337 | } |
91d6fa6a | 28338 | aeabi_set_attribute_string (Tag_CPU_name, q); |
ee065d83 | 28339 | } |
62f3b8c8 | 28340 | |
ee065d83 | 28341 | /* Tag_CPU_arch. */ |
ee3c0378 | 28342 | aeabi_set_attribute_int (Tag_CPU_arch, arch); |
62f3b8c8 | 28343 | |
62b3e311 | 28344 | /* Tag_CPU_arch_profile. */ |
69239280 MGD |
28345 | if (profile != '\0') |
28346 | aeabi_set_attribute_int (Tag_CPU_arch_profile, profile); | |
62f3b8c8 | 28347 | |
15afaa63 | 28348 | /* Tag_DSP_extension. */ |
4d354d8b | 28349 | if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp)) |
6c290d53 | 28350 | aeabi_set_attribute_int (Tag_DSP_extension, 1); |
15afaa63 | 28351 | |
2c6b98ea | 28352 | ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any); |
ee065d83 | 28353 | /* Tag_ARM_ISA_use. */ |
ee3c0378 | 28354 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1) |
2c6b98ea | 28355 | || ARM_FEATURE_ZERO (flags_arch)) |
ee3c0378 | 28356 | aeabi_set_attribute_int (Tag_ARM_ISA_use, 1); |
62f3b8c8 | 28357 | |
ee065d83 | 28358 | /* Tag_THUMB_ISA_use. */ |
ee3c0378 | 28359 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t) |
2c6b98ea | 28360 | || ARM_FEATURE_ZERO (flags_arch)) |
4ed7ed8d TP |
28361 | { |
28362 | int thumb_isa_use; | |
28363 | ||
28364 | if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) | |
16a1fa25 | 28365 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only)) |
4ed7ed8d TP |
28366 | thumb_isa_use = 3; |
28367 | else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2)) | |
28368 | thumb_isa_use = 2; | |
28369 | else | |
28370 | thumb_isa_use = 1; | |
28371 | aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use); | |
28372 | } | |
62f3b8c8 | 28373 | |
ee065d83 | 28374 | /* Tag_VFP_arch. */ |
a715796b TG |
28375 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd)) |
28376 | aeabi_set_attribute_int (Tag_VFP_arch, | |
28377 | ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32) | |
28378 | ? 7 : 8); | |
bca38921 | 28379 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma)) |
62f3b8c8 PB |
28380 | aeabi_set_attribute_int (Tag_VFP_arch, |
28381 | ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32) | |
28382 | ? 5 : 6); | |
28383 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)) | |
bca38921 MGD |
28384 | { |
28385 | fp16_optional = 1; | |
28386 | aeabi_set_attribute_int (Tag_VFP_arch, 3); | |
28387 | } | |
ada65aa3 | 28388 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd)) |
bca38921 MGD |
28389 | { |
28390 | aeabi_set_attribute_int (Tag_VFP_arch, 4); | |
28391 | fp16_optional = 1; | |
28392 | } | |
ee3c0378 AS |
28393 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2)) |
28394 | aeabi_set_attribute_int (Tag_VFP_arch, 2); | |
28395 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1) | |
477330fc | 28396 | || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)) |
ee3c0378 | 28397 | aeabi_set_attribute_int (Tag_VFP_arch, 1); |
62f3b8c8 | 28398 | |
4547cb56 NC |
28399 | /* Tag_ABI_HardFP_use. */ |
28400 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd) | |
28401 | && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)) | |
28402 | aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1); | |
28403 | ||
ee065d83 | 28404 | /* Tag_WMMX_arch. */ |
ee3c0378 AS |
28405 | if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2)) |
28406 | aeabi_set_attribute_int (Tag_WMMX_arch, 2); | |
28407 | else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt)) | |
28408 | aeabi_set_attribute_int (Tag_WMMX_arch, 1); | |
62f3b8c8 | 28409 | |
ee3c0378 | 28410 | /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */ |
9411fd44 MW |
28411 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1)) |
28412 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4); | |
28413 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8)) | |
bca38921 MGD |
28414 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3); |
28415 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1)) | |
28416 | { | |
28417 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)) | |
28418 | { | |
28419 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2); | |
28420 | } | |
28421 | else | |
28422 | { | |
28423 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1); | |
28424 | fp16_optional = 1; | |
28425 | } | |
28426 | } | |
fa94de6b | 28427 | |
ee3c0378 | 28428 | /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */ |
bca38921 | 28429 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional) |
ee3c0378 | 28430 | aeabi_set_attribute_int (Tag_VFP_HP_extension, 1); |
4547cb56 | 28431 | |
69239280 MGD |
28432 | /* Tag_DIV_use. |
28433 | ||
28434 | We set Tag_DIV_use to two when integer divide instructions have been used | |
28435 | in ARM state, or when Thumb integer divide instructions have been used, | |
28436 | but we have no architecture profile set, nor have we any ARM instructions. | |
28437 | ||
4ed7ed8d TP |
28438 | For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied |
28439 | by the base architecture. | |
bca38921 | 28440 | |
69239280 | 28441 | For new architectures we will have to check these tests. */ |
031254f2 | 28442 | gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN); |
4ed7ed8d TP |
28443 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) |
28444 | || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m)) | |
bca38921 MGD |
28445 | aeabi_set_attribute_int (Tag_DIV_use, 0); |
28446 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv) | |
28447 | || (profile == '\0' | |
28448 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_div) | |
28449 | && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))) | |
eea54501 | 28450 | aeabi_set_attribute_int (Tag_DIV_use, 2); |
60e5ef9f MGD |
28451 | |
28452 | /* Tag_MP_extension_use. */ | |
28453 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp)) | |
28454 | aeabi_set_attribute_int (Tag_MPextension_use, 1); | |
f4c65163 MGD |
28455 | |
28456 | /* Tag Virtualization_use. */ | |
28457 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec)) | |
90ec0d68 MGD |
28458 | virt_sec |= 1; |
28459 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt)) | |
28460 | virt_sec |= 2; | |
28461 | if (virt_sec != 0) | |
28462 | aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec); | |
ee065d83 PB |
28463 | } |
28464 | ||
c168ce07 TP |
28465 | /* Post relaxation hook. Recompute ARM attributes now that relaxation is |
28466 | finished and free extension feature bits which will not be used anymore. */ | |
0198d5e6 | 28467 | |
c168ce07 TP |
28468 | void |
28469 | arm_md_post_relax (void) | |
28470 | { | |
28471 | aeabi_set_public_attributes (); | |
4d354d8b TP |
28472 | XDELETE (mcpu_ext_opt); |
28473 | mcpu_ext_opt = NULL; | |
28474 | XDELETE (march_ext_opt); | |
28475 | march_ext_opt = NULL; | |
c168ce07 TP |
28476 | } |
28477 | ||
104d59d1 | 28478 | /* Add the default contents for the .ARM.attributes section. */ |
0198d5e6 | 28479 | |
ee065d83 PB |
28480 | void |
28481 | arm_md_end (void) | |
28482 | { | |
ee065d83 PB |
28483 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
28484 | return; | |
28485 | ||
28486 | aeabi_set_public_attributes (); | |
ee065d83 | 28487 | } |
8463be01 | 28488 | #endif /* OBJ_ELF */ |
ee065d83 | 28489 | |
ee065d83 PB |
28490 | /* Parse a .cpu directive. */ |
28491 | ||
28492 | static void | |
28493 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
28494 | { | |
e74cfd16 | 28495 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
28496 | char *name; |
28497 | char saved_char; | |
28498 | ||
28499 | name = input_line_pointer; | |
5f4273c7 | 28500 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
28501 | input_line_pointer++; |
28502 | saved_char = *input_line_pointer; | |
28503 | *input_line_pointer = 0; | |
28504 | ||
28505 | /* Skip the first "all" entry. */ | |
28506 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
28507 | if (streq (opt->name, name)) | |
28508 | { | |
4d354d8b TP |
28509 | selected_arch = opt->value; |
28510 | selected_ext = opt->ext; | |
28511 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext); | |
ee065d83 | 28512 | if (opt->canonical_name) |
5f4273c7 | 28513 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
28514 | else |
28515 | { | |
28516 | int i; | |
28517 | for (i = 0; opt->name[i]; i++) | |
28518 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
f3bad469 | 28519 | |
ee065d83 PB |
28520 | selected_cpu_name[i] = 0; |
28521 | } | |
4d354d8b TP |
28522 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
28523 | ||
ee065d83 PB |
28524 | *input_line_pointer = saved_char; |
28525 | demand_empty_rest_of_line (); | |
28526 | return; | |
28527 | } | |
28528 | as_bad (_("unknown cpu `%s'"), name); | |
28529 | *input_line_pointer = saved_char; | |
28530 | ignore_rest_of_line (); | |
28531 | } | |
28532 | ||
ee065d83 PB |
28533 | /* Parse a .arch directive. */ |
28534 | ||
28535 | static void | |
28536 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
28537 | { | |
e74cfd16 | 28538 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
28539 | char saved_char; |
28540 | char *name; | |
28541 | ||
28542 | name = input_line_pointer; | |
5f4273c7 | 28543 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
28544 | input_line_pointer++; |
28545 | saved_char = *input_line_pointer; | |
28546 | *input_line_pointer = 0; | |
28547 | ||
28548 | /* Skip the first "all" entry. */ | |
28549 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
28550 | if (streq (opt->name, name)) | |
28551 | { | |
4d354d8b TP |
28552 | selected_arch = opt->value; |
28553 | selected_ext = arm_arch_none; | |
28554 | selected_cpu = selected_arch; | |
5f4273c7 | 28555 | strcpy (selected_cpu_name, opt->name); |
4d354d8b | 28556 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
ee065d83 PB |
28557 | *input_line_pointer = saved_char; |
28558 | demand_empty_rest_of_line (); | |
28559 | return; | |
28560 | } | |
28561 | ||
28562 | as_bad (_("unknown architecture `%s'\n"), name); | |
28563 | *input_line_pointer = saved_char; | |
28564 | ignore_rest_of_line (); | |
28565 | } | |
28566 | ||
7a1d4c38 PB |
28567 | /* Parse a .object_arch directive. */ |
28568 | ||
28569 | static void | |
28570 | s_arm_object_arch (int ignored ATTRIBUTE_UNUSED) | |
28571 | { | |
28572 | const struct arm_arch_option_table *opt; | |
28573 | char saved_char; | |
28574 | char *name; | |
28575 | ||
28576 | name = input_line_pointer; | |
5f4273c7 | 28577 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
7a1d4c38 PB |
28578 | input_line_pointer++; |
28579 | saved_char = *input_line_pointer; | |
28580 | *input_line_pointer = 0; | |
28581 | ||
28582 | /* Skip the first "all" entry. */ | |
28583 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
28584 | if (streq (opt->name, name)) | |
28585 | { | |
4d354d8b | 28586 | selected_object_arch = opt->value; |
7a1d4c38 PB |
28587 | *input_line_pointer = saved_char; |
28588 | demand_empty_rest_of_line (); | |
28589 | return; | |
28590 | } | |
28591 | ||
28592 | as_bad (_("unknown architecture `%s'\n"), name); | |
28593 | *input_line_pointer = saved_char; | |
28594 | ignore_rest_of_line (); | |
28595 | } | |
28596 | ||
69133863 MGD |
28597 | /* Parse a .arch_extension directive. */ |
28598 | ||
28599 | static void | |
28600 | s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED) | |
28601 | { | |
28602 | const struct arm_option_extension_value_table *opt; | |
28603 | char saved_char; | |
28604 | char *name; | |
28605 | int adding_value = 1; | |
28606 | ||
28607 | name = input_line_pointer; | |
28608 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) | |
28609 | input_line_pointer++; | |
28610 | saved_char = *input_line_pointer; | |
28611 | *input_line_pointer = 0; | |
28612 | ||
28613 | if (strlen (name) >= 2 | |
28614 | && strncmp (name, "no", 2) == 0) | |
28615 | { | |
28616 | adding_value = 0; | |
28617 | name += 2; | |
28618 | } | |
28619 | ||
28620 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
28621 | if (streq (opt->name, name)) | |
28622 | { | |
d942732e TP |
28623 | int i, nb_allowed_archs = |
28624 | sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]); | |
28625 | for (i = 0; i < nb_allowed_archs; i++) | |
28626 | { | |
28627 | /* Empty entry. */ | |
4d354d8b | 28628 | if (ARM_CPU_IS_ANY (opt->allowed_archs[i])) |
d942732e | 28629 | continue; |
4d354d8b | 28630 | if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch)) |
d942732e TP |
28631 | break; |
28632 | } | |
28633 | ||
28634 | if (i == nb_allowed_archs) | |
69133863 MGD |
28635 | { |
28636 | as_bad (_("architectural extension `%s' is not allowed for the " | |
28637 | "current base architecture"), name); | |
28638 | break; | |
28639 | } | |
28640 | ||
28641 | if (adding_value) | |
4d354d8b | 28642 | ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext, |
5a70a223 | 28643 | opt->merge_value); |
69133863 | 28644 | else |
4d354d8b | 28645 | ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value); |
69133863 | 28646 | |
4d354d8b TP |
28647 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext); |
28648 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); | |
69133863 MGD |
28649 | *input_line_pointer = saved_char; |
28650 | demand_empty_rest_of_line (); | |
3d030cdb TP |
28651 | /* Allowing Thumb division instructions for ARMv7 in autodetection rely |
28652 | on this return so that duplicate extensions (extensions with the | |
28653 | same name as a previous extension in the list) are not considered | |
28654 | for command-line parsing. */ | |
69133863 MGD |
28655 | return; |
28656 | } | |
28657 | ||
28658 | if (opt->name == NULL) | |
e673710a | 28659 | as_bad (_("unknown architecture extension `%s'\n"), name); |
69133863 MGD |
28660 | |
28661 | *input_line_pointer = saved_char; | |
28662 | ignore_rest_of_line (); | |
28663 | } | |
28664 | ||
ee065d83 PB |
28665 | /* Parse a .fpu directive. */ |
28666 | ||
28667 | static void | |
28668 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
28669 | { | |
69133863 | 28670 | const struct arm_option_fpu_value_table *opt; |
ee065d83 PB |
28671 | char saved_char; |
28672 | char *name; | |
28673 | ||
28674 | name = input_line_pointer; | |
5f4273c7 | 28675 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
28676 | input_line_pointer++; |
28677 | saved_char = *input_line_pointer; | |
28678 | *input_line_pointer = 0; | |
5f4273c7 | 28679 | |
ee065d83 PB |
28680 | for (opt = arm_fpus; opt->name != NULL; opt++) |
28681 | if (streq (opt->name, name)) | |
28682 | { | |
4d354d8b TP |
28683 | selected_fpu = opt->value; |
28684 | #ifndef CPU_DEFAULT | |
28685 | if (no_cpu_selected ()) | |
28686 | ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu); | |
28687 | else | |
28688 | #endif | |
28689 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); | |
ee065d83 PB |
28690 | *input_line_pointer = saved_char; |
28691 | demand_empty_rest_of_line (); | |
28692 | return; | |
28693 | } | |
28694 | ||
28695 | as_bad (_("unknown floating point format `%s'\n"), name); | |
28696 | *input_line_pointer = saved_char; | |
28697 | ignore_rest_of_line (); | |
28698 | } | |
ee065d83 | 28699 | |
794ba86a | 28700 | /* Copy symbol information. */ |
f31fef98 | 28701 | |
794ba86a DJ |
28702 | void |
28703 | arm_copy_symbol_attributes (symbolS *dest, symbolS *src) | |
28704 | { | |
28705 | ARM_GET_FLAG (dest) = ARM_GET_FLAG (src); | |
28706 | } | |
e04befd0 | 28707 | |
f31fef98 | 28708 | #ifdef OBJ_ELF |
e04befd0 AS |
28709 | /* Given a symbolic attribute NAME, return the proper integer value. |
28710 | Returns -1 if the attribute is not known. */ | |
f31fef98 | 28711 | |
e04befd0 AS |
28712 | int |
28713 | arm_convert_symbolic_attribute (const char *name) | |
28714 | { | |
f31fef98 NC |
28715 | static const struct |
28716 | { | |
28717 | const char * name; | |
28718 | const int tag; | |
28719 | } | |
28720 | attribute_table[] = | |
28721 | { | |
28722 | /* When you modify this table you should | |
28723 | also modify the list in doc/c-arm.texi. */ | |
e04befd0 | 28724 | #define T(tag) {#tag, tag} |
f31fef98 NC |
28725 | T (Tag_CPU_raw_name), |
28726 | T (Tag_CPU_name), | |
28727 | T (Tag_CPU_arch), | |
28728 | T (Tag_CPU_arch_profile), | |
28729 | T (Tag_ARM_ISA_use), | |
28730 | T (Tag_THUMB_ISA_use), | |
75375b3e | 28731 | T (Tag_FP_arch), |
f31fef98 NC |
28732 | T (Tag_VFP_arch), |
28733 | T (Tag_WMMX_arch), | |
28734 | T (Tag_Advanced_SIMD_arch), | |
28735 | T (Tag_PCS_config), | |
28736 | T (Tag_ABI_PCS_R9_use), | |
28737 | T (Tag_ABI_PCS_RW_data), | |
28738 | T (Tag_ABI_PCS_RO_data), | |
28739 | T (Tag_ABI_PCS_GOT_use), | |
28740 | T (Tag_ABI_PCS_wchar_t), | |
28741 | T (Tag_ABI_FP_rounding), | |
28742 | T (Tag_ABI_FP_denormal), | |
28743 | T (Tag_ABI_FP_exceptions), | |
28744 | T (Tag_ABI_FP_user_exceptions), | |
28745 | T (Tag_ABI_FP_number_model), | |
75375b3e | 28746 | T (Tag_ABI_align_needed), |
f31fef98 | 28747 | T (Tag_ABI_align8_needed), |
75375b3e | 28748 | T (Tag_ABI_align_preserved), |
f31fef98 NC |
28749 | T (Tag_ABI_align8_preserved), |
28750 | T (Tag_ABI_enum_size), | |
28751 | T (Tag_ABI_HardFP_use), | |
28752 | T (Tag_ABI_VFP_args), | |
28753 | T (Tag_ABI_WMMX_args), | |
28754 | T (Tag_ABI_optimization_goals), | |
28755 | T (Tag_ABI_FP_optimization_goals), | |
28756 | T (Tag_compatibility), | |
28757 | T (Tag_CPU_unaligned_access), | |
75375b3e | 28758 | T (Tag_FP_HP_extension), |
f31fef98 NC |
28759 | T (Tag_VFP_HP_extension), |
28760 | T (Tag_ABI_FP_16bit_format), | |
cd21e546 MGD |
28761 | T (Tag_MPextension_use), |
28762 | T (Tag_DIV_use), | |
f31fef98 NC |
28763 | T (Tag_nodefaults), |
28764 | T (Tag_also_compatible_with), | |
28765 | T (Tag_conformance), | |
28766 | T (Tag_T2EE_use), | |
28767 | T (Tag_Virtualization_use), | |
15afaa63 | 28768 | T (Tag_DSP_extension), |
cd21e546 | 28769 | /* We deliberately do not include Tag_MPextension_use_legacy. */ |
e04befd0 | 28770 | #undef T |
f31fef98 | 28771 | }; |
e04befd0 AS |
28772 | unsigned int i; |
28773 | ||
28774 | if (name == NULL) | |
28775 | return -1; | |
28776 | ||
f31fef98 | 28777 | for (i = 0; i < ARRAY_SIZE (attribute_table); i++) |
c921be7d | 28778 | if (streq (name, attribute_table[i].name)) |
e04befd0 AS |
28779 | return attribute_table[i].tag; |
28780 | ||
28781 | return -1; | |
28782 | } | |
267bf995 | 28783 | |
93ef582d NC |
28784 | /* Apply sym value for relocations only in the case that they are for |
28785 | local symbols in the same segment as the fixup and you have the | |
28786 | respective architectural feature for blx and simple switches. */ | |
0198d5e6 | 28787 | |
267bf995 | 28788 | int |
93ef582d | 28789 | arm_apply_sym_value (struct fix * fixP, segT this_seg) |
267bf995 RR |
28790 | { |
28791 | if (fixP->fx_addsy | |
28792 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
93ef582d NC |
28793 | /* PR 17444: If the local symbol is in a different section then a reloc |
28794 | will always be generated for it, so applying the symbol value now | |
28795 | will result in a double offset being stored in the relocation. */ | |
28796 | && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg) | |
34e77a92 | 28797 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)) |
267bf995 RR |
28798 | { |
28799 | switch (fixP->fx_r_type) | |
28800 | { | |
28801 | case BFD_RELOC_ARM_PCREL_BLX: | |
28802 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
28803 | if (ARM_IS_FUNC (fixP->fx_addsy)) | |
28804 | return 1; | |
28805 | break; | |
28806 | ||
28807 | case BFD_RELOC_ARM_PCREL_CALL: | |
28808 | case BFD_RELOC_THUMB_PCREL_BLX: | |
28809 | if (THUMB_IS_FUNC (fixP->fx_addsy)) | |
93ef582d | 28810 | return 1; |
267bf995 RR |
28811 | break; |
28812 | ||
28813 | default: | |
28814 | break; | |
28815 | } | |
28816 | ||
28817 | } | |
28818 | return 0; | |
28819 | } | |
f31fef98 | 28820 | #endif /* OBJ_ELF */ |