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 | 34 | #include "opcode/arm.h" |
f37164d7 | 35 | #include "cpu-arm.h" |
f263249b | 36 | |
b99bd4ef NC |
37 | #ifdef OBJ_ELF |
38 | #include "elf/arm.h" | |
a394c00f | 39 | #include "dw2gencfi.h" |
b99bd4ef NC |
40 | #endif |
41 | ||
f0927246 NC |
42 | #include "dwarf2dbg.h" |
43 | ||
7ed4c4c5 NC |
44 | #ifdef OBJ_ELF |
45 | /* Must be at least the size of the largest unwind opcode (currently two). */ | |
46 | #define ARM_OPCODE_CHUNK_SIZE 8 | |
47 | ||
48 | /* This structure holds the unwinding state. */ | |
49 | ||
50 | static struct | |
51 | { | |
c19d1205 ZW |
52 | symbolS * proc_start; |
53 | symbolS * table_entry; | |
54 | symbolS * personality_routine; | |
55 | int personality_index; | |
7ed4c4c5 | 56 | /* The segment containing the function. */ |
c19d1205 ZW |
57 | segT saved_seg; |
58 | subsegT saved_subseg; | |
7ed4c4c5 NC |
59 | /* Opcodes generated from this function. */ |
60 | unsigned char * opcodes; | |
c19d1205 ZW |
61 | int opcode_count; |
62 | int opcode_alloc; | |
7ed4c4c5 | 63 | /* The number of bytes pushed to the stack. */ |
c19d1205 | 64 | offsetT frame_size; |
7ed4c4c5 NC |
65 | /* We don't add stack adjustment opcodes immediately so that we can merge |
66 | multiple adjustments. We can also omit the final adjustment | |
67 | when using a frame pointer. */ | |
c19d1205 | 68 | offsetT pending_offset; |
7ed4c4c5 | 69 | /* These two fields are set by both unwind_movsp and unwind_setfp. They |
c19d1205 ZW |
70 | hold the reg+offset to use when restoring sp from a frame pointer. */ |
71 | offsetT fp_offset; | |
72 | int fp_reg; | |
7ed4c4c5 | 73 | /* Nonzero if an unwind_setfp directive has been seen. */ |
c19d1205 | 74 | unsigned fp_used:1; |
7ed4c4c5 | 75 | /* Nonzero if the last opcode restores sp from fp_reg. */ |
c19d1205 | 76 | unsigned sp_restored:1; |
7ed4c4c5 NC |
77 | } unwind; |
78 | ||
18a20338 CL |
79 | /* Whether --fdpic was given. */ |
80 | static int arm_fdpic; | |
81 | ||
8b1ad454 NC |
82 | #endif /* OBJ_ELF */ |
83 | ||
4962c51a MS |
84 | /* Results from operand parsing worker functions. */ |
85 | ||
86 | typedef enum | |
87 | { | |
88 | PARSE_OPERAND_SUCCESS, | |
89 | PARSE_OPERAND_FAIL, | |
90 | PARSE_OPERAND_FAIL_NO_BACKTRACK | |
91 | } parse_operand_result; | |
92 | ||
33a392fb PB |
93 | enum arm_float_abi |
94 | { | |
95 | ARM_FLOAT_ABI_HARD, | |
96 | ARM_FLOAT_ABI_SOFTFP, | |
97 | ARM_FLOAT_ABI_SOFT | |
98 | }; | |
99 | ||
c19d1205 | 100 | /* Types of processor to assemble for. */ |
b99bd4ef | 101 | #ifndef CPU_DEFAULT |
8a59fff3 | 102 | /* The code that was here used to select a default CPU depending on compiler |
fa94de6b | 103 | pre-defines which were only present when doing native builds, thus |
8a59fff3 MGD |
104 | changing gas' default behaviour depending upon the build host. |
105 | ||
106 | If you have a target that requires a default CPU option then the you | |
107 | should define CPU_DEFAULT here. */ | |
b99bd4ef NC |
108 | #endif |
109 | ||
110 | #ifndef FPU_DEFAULT | |
c820d418 MM |
111 | # ifdef TE_LINUX |
112 | # define FPU_DEFAULT FPU_ARCH_FPA | |
113 | # elif defined (TE_NetBSD) | |
114 | # ifdef OBJ_ELF | |
115 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */ | |
116 | # else | |
117 | /* Legacy a.out format. */ | |
118 | # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */ | |
119 | # endif | |
4e7fd91e PB |
120 | # elif defined (TE_VXWORKS) |
121 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */ | |
c820d418 MM |
122 | # else |
123 | /* For backwards compatibility, default to FPA. */ | |
124 | # define FPU_DEFAULT FPU_ARCH_FPA | |
125 | # endif | |
126 | #endif /* ifndef FPU_DEFAULT */ | |
b99bd4ef | 127 | |
c19d1205 | 128 | #define streq(a, b) (strcmp (a, b) == 0) |
b99bd4ef | 129 | |
4d354d8b TP |
130 | /* Current set of feature bits available (CPU+FPU). Different from |
131 | selected_cpu + selected_fpu in case of autodetection since the CPU | |
132 | feature bits are then all set. */ | |
e74cfd16 | 133 | static arm_feature_set cpu_variant; |
4d354d8b TP |
134 | /* Feature bits used in each execution state. Used to set build attribute |
135 | (in particular Tag_*_ISA_use) in CPU autodetection mode. */ | |
e74cfd16 PB |
136 | static arm_feature_set arm_arch_used; |
137 | static arm_feature_set thumb_arch_used; | |
b99bd4ef | 138 | |
b99bd4ef | 139 | /* Flags stored in private area of BFD structure. */ |
c19d1205 ZW |
140 | static int uses_apcs_26 = FALSE; |
141 | static int atpcs = FALSE; | |
b34976b6 AM |
142 | static int support_interwork = FALSE; |
143 | static int uses_apcs_float = FALSE; | |
c19d1205 | 144 | static int pic_code = FALSE; |
845b51d6 | 145 | static int fix_v4bx = FALSE; |
278df34e NS |
146 | /* Warn on using deprecated features. */ |
147 | static int warn_on_deprecated = TRUE; | |
148 | ||
2e6976a8 DG |
149 | /* Understand CodeComposer Studio assembly syntax. */ |
150 | bfd_boolean codecomposer_syntax = FALSE; | |
03b1477f RE |
151 | |
152 | /* Variables that we set while parsing command-line options. Once all | |
153 | options have been read we re-process these values to set the real | |
154 | assembly flags. */ | |
4d354d8b TP |
155 | |
156 | /* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1 | |
157 | instead of -mcpu=arm1). */ | |
158 | static const arm_feature_set *legacy_cpu = NULL; | |
159 | static const arm_feature_set *legacy_fpu = NULL; | |
160 | ||
161 | /* CPU, extension and FPU feature bits selected by -mcpu. */ | |
162 | static const arm_feature_set *mcpu_cpu_opt = NULL; | |
163 | static arm_feature_set *mcpu_ext_opt = NULL; | |
164 | static const arm_feature_set *mcpu_fpu_opt = NULL; | |
165 | ||
166 | /* CPU, extension and FPU feature bits selected by -march. */ | |
167 | static const arm_feature_set *march_cpu_opt = NULL; | |
168 | static arm_feature_set *march_ext_opt = NULL; | |
169 | static const arm_feature_set *march_fpu_opt = NULL; | |
170 | ||
171 | /* Feature bits selected by -mfpu. */ | |
172 | static const arm_feature_set *mfpu_opt = NULL; | |
e74cfd16 PB |
173 | |
174 | /* Constants for known architecture features. */ | |
175 | static const arm_feature_set fpu_default = FPU_DEFAULT; | |
f85d59c3 | 176 | static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1; |
e74cfd16 | 177 | static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2; |
f85d59c3 KT |
178 | static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3; |
179 | static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1; | |
e74cfd16 PB |
180 | static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA; |
181 | static const arm_feature_set fpu_any_hard = FPU_ANY_HARD; | |
69c9e028 | 182 | #ifdef OBJ_ELF |
e74cfd16 | 183 | static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK; |
69c9e028 | 184 | #endif |
e74cfd16 PB |
185 | static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE; |
186 | ||
187 | #ifdef CPU_DEFAULT | |
188 | static const arm_feature_set cpu_default = CPU_DEFAULT; | |
189 | #endif | |
190 | ||
823d2571 | 191 | static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1); |
4070243b | 192 | static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2); |
823d2571 TG |
193 | static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S); |
194 | static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3); | |
195 | static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M); | |
196 | static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4); | |
197 | static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T); | |
198 | static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5); | |
e74cfd16 | 199 | static const arm_feature_set arm_ext_v4t_5 = |
823d2571 TG |
200 | ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5); |
201 | static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T); | |
202 | static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E); | |
203 | static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP); | |
204 | static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J); | |
205 | static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6); | |
206 | static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K); | |
207 | static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2); | |
55e8aae7 SP |
208 | /* Only for compatability of hint instructions. */ |
209 | static const arm_feature_set arm_ext_v6k_v6t2 = | |
210 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2); | |
823d2571 TG |
211 | static const arm_feature_set arm_ext_v6_notm = |
212 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM); | |
213 | static const arm_feature_set arm_ext_v6_dsp = | |
214 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP); | |
215 | static const arm_feature_set arm_ext_barrier = | |
216 | ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER); | |
217 | static const arm_feature_set arm_ext_msr = | |
218 | ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR); | |
219 | static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV); | |
220 | static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7); | |
221 | static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A); | |
222 | static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R); | |
69c9e028 | 223 | #ifdef OBJ_ELF |
e7d39ed3 | 224 | static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M); |
69c9e028 | 225 | #endif |
823d2571 | 226 | static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8); |
7e806470 | 227 | static const arm_feature_set arm_ext_m = |
173205ca | 228 | ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M, |
16a1fa25 | 229 | ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN); |
823d2571 TG |
230 | static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP); |
231 | static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC); | |
232 | static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS); | |
233 | static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV); | |
234 | static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT); | |
ddfded2f | 235 | static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN); |
4ed7ed8d | 236 | static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M); |
16a1fa25 TP |
237 | static const arm_feature_set arm_ext_v8m_main = |
238 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN); | |
e12437dc AV |
239 | static const arm_feature_set arm_ext_v8_1m_main = |
240 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN); | |
16a1fa25 TP |
241 | /* Instructions in ARMv8-M only found in M profile architectures. */ |
242 | static const arm_feature_set arm_ext_v8m_m_only = | |
243 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN); | |
ff8646ee TP |
244 | static const arm_feature_set arm_ext_v6t2_v8m = |
245 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M); | |
4ed7ed8d TP |
246 | /* Instructions shared between ARMv8-A and ARMv8-M. */ |
247 | static const arm_feature_set arm_ext_atomics = | |
248 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS); | |
69c9e028 | 249 | #ifdef OBJ_ELF |
15afaa63 TP |
250 | /* DSP instructions Tag_DSP_extension refers to. */ |
251 | static const arm_feature_set arm_ext_dsp = | |
252 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP); | |
69c9e028 | 253 | #endif |
4d1464f2 MW |
254 | static const arm_feature_set arm_ext_ras = |
255 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS); | |
b8ec4e87 JW |
256 | /* FP16 instructions. */ |
257 | static const arm_feature_set arm_ext_fp16 = | |
258 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST); | |
01f48020 TC |
259 | static const arm_feature_set arm_ext_fp16_fml = |
260 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML); | |
dec41383 JW |
261 | static const arm_feature_set arm_ext_v8_2 = |
262 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A); | |
49e8a725 SN |
263 | static const arm_feature_set arm_ext_v8_3 = |
264 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A); | |
7fadb25d SD |
265 | static const arm_feature_set arm_ext_sb = |
266 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB); | |
dad0c3bf SD |
267 | static const arm_feature_set arm_ext_predres = |
268 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES); | |
e74cfd16 PB |
269 | |
270 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
49fa50ef | 271 | #ifdef OBJ_ELF |
2c6b98ea | 272 | static const arm_feature_set fpu_any = FPU_ANY; |
49fa50ef | 273 | #endif |
f85d59c3 | 274 | static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1); |
e74cfd16 PB |
275 | static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2; |
276 | static const arm_feature_set arm_arch_none = ARM_ARCH_NONE; | |
277 | ||
2d447fca | 278 | static const arm_feature_set arm_cext_iwmmxt2 = |
823d2571 | 279 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2); |
e74cfd16 | 280 | static const arm_feature_set arm_cext_iwmmxt = |
823d2571 | 281 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT); |
e74cfd16 | 282 | static const arm_feature_set arm_cext_xscale = |
823d2571 | 283 | ARM_FEATURE_COPROC (ARM_CEXT_XSCALE); |
e74cfd16 | 284 | static const arm_feature_set arm_cext_maverick = |
823d2571 TG |
285 | ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK); |
286 | static const arm_feature_set fpu_fpa_ext_v1 = | |
287 | ARM_FEATURE_COPROC (FPU_FPA_EXT_V1); | |
288 | static const arm_feature_set fpu_fpa_ext_v2 = | |
289 | ARM_FEATURE_COPROC (FPU_FPA_EXT_V2); | |
e74cfd16 | 290 | static const arm_feature_set fpu_vfp_ext_v1xd = |
823d2571 TG |
291 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD); |
292 | static const arm_feature_set fpu_vfp_ext_v1 = | |
293 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V1); | |
294 | static const arm_feature_set fpu_vfp_ext_v2 = | |
295 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V2); | |
296 | static const arm_feature_set fpu_vfp_ext_v3xd = | |
297 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD); | |
298 | static const arm_feature_set fpu_vfp_ext_v3 = | |
299 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V3); | |
b1cc4aeb | 300 | static const arm_feature_set fpu_vfp_ext_d32 = |
823d2571 TG |
301 | ARM_FEATURE_COPROC (FPU_VFP_EXT_D32); |
302 | static const arm_feature_set fpu_neon_ext_v1 = | |
303 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1); | |
5287ad62 | 304 | static const arm_feature_set fpu_vfp_v3_or_neon_ext = |
823d2571 | 305 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3); |
a7ad558c AV |
306 | static const arm_feature_set mve_ext = |
307 | ARM_FEATURE_COPROC (FPU_MVE); | |
308 | static const arm_feature_set mve_fp_ext = | |
309 | ARM_FEATURE_COPROC (FPU_MVE_FP); | |
69c9e028 | 310 | #ifdef OBJ_ELF |
823d2571 TG |
311 | static const arm_feature_set fpu_vfp_fp16 = |
312 | ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16); | |
313 | static const arm_feature_set fpu_neon_ext_fma = | |
314 | ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA); | |
69c9e028 | 315 | #endif |
823d2571 TG |
316 | static const arm_feature_set fpu_vfp_ext_fma = |
317 | ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA); | |
bca38921 | 318 | static const arm_feature_set fpu_vfp_ext_armv8 = |
823d2571 | 319 | ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8); |
a715796b | 320 | static const arm_feature_set fpu_vfp_ext_armv8xd = |
823d2571 | 321 | ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD); |
bca38921 | 322 | static const arm_feature_set fpu_neon_ext_armv8 = |
823d2571 | 323 | ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8); |
bca38921 | 324 | static const arm_feature_set fpu_crypto_ext_armv8 = |
823d2571 | 325 | ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8); |
dd5181d5 | 326 | static const arm_feature_set crc_ext_armv8 = |
823d2571 | 327 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8); |
d6b4b13e | 328 | static const arm_feature_set fpu_neon_ext_v8_1 = |
643afb90 | 329 | ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA); |
c604a79a JW |
330 | static const arm_feature_set fpu_neon_ext_dotprod = |
331 | ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD); | |
e74cfd16 | 332 | |
33a392fb | 333 | static int mfloat_abi_opt = -1; |
4d354d8b TP |
334 | /* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch |
335 | directive. */ | |
336 | static arm_feature_set selected_arch = ARM_ARCH_NONE; | |
337 | /* Extension feature bits selected by the last -mcpu/-march or .arch_extension | |
338 | directive. */ | |
339 | static arm_feature_set selected_ext = ARM_ARCH_NONE; | |
340 | /* Feature bits selected by the last -mcpu/-march or by the combination of the | |
341 | last .cpu/.arch directive .arch_extension directives since that | |
342 | directive. */ | |
e74cfd16 | 343 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; |
4d354d8b TP |
344 | /* FPU feature bits selected by the last -mfpu or .fpu directive. */ |
345 | static arm_feature_set selected_fpu = FPU_NONE; | |
346 | /* Feature bits selected by the last .object_arch directive. */ | |
347 | static arm_feature_set selected_object_arch = ARM_ARCH_NONE; | |
ee065d83 | 348 | /* Must be long enough to hold any of the names in arm_cpus. */ |
ef8e6722 | 349 | static char selected_cpu_name[20]; |
8d67f500 | 350 | |
aacf0b33 KT |
351 | extern FLONUM_TYPE generic_floating_point_number; |
352 | ||
8d67f500 NC |
353 | /* Return if no cpu was selected on command-line. */ |
354 | static bfd_boolean | |
355 | no_cpu_selected (void) | |
356 | { | |
823d2571 | 357 | return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none); |
8d67f500 NC |
358 | } |
359 | ||
7cc69913 | 360 | #ifdef OBJ_ELF |
deeaaff8 DJ |
361 | # ifdef EABI_DEFAULT |
362 | static int meabi_flags = EABI_DEFAULT; | |
363 | # else | |
d507cf36 | 364 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 365 | # endif |
e1da3f5b | 366 | |
ee3c0378 AS |
367 | static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES]; |
368 | ||
e1da3f5b | 369 | bfd_boolean |
5f4273c7 | 370 | arm_is_eabi (void) |
e1da3f5b PB |
371 | { |
372 | return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4); | |
373 | } | |
7cc69913 | 374 | #endif |
b99bd4ef | 375 | |
b99bd4ef | 376 | #ifdef OBJ_ELF |
c19d1205 | 377 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
378 | symbolS * GOT_symbol; |
379 | #endif | |
380 | ||
b99bd4ef NC |
381 | /* 0: assemble for ARM, |
382 | 1: assemble for Thumb, | |
383 | 2: assemble for Thumb even though target CPU does not support thumb | |
384 | instructions. */ | |
385 | static int thumb_mode = 0; | |
8dc2430f NC |
386 | /* A value distinct from the possible values for thumb_mode that we |
387 | can use to record whether thumb_mode has been copied into the | |
388 | tc_frag_data field of a frag. */ | |
389 | #define MODE_RECORDED (1 << 4) | |
b99bd4ef | 390 | |
e07e6e58 NC |
391 | /* Specifies the intrinsic IT insn behavior mode. */ |
392 | enum implicit_it_mode | |
393 | { | |
394 | IMPLICIT_IT_MODE_NEVER = 0x00, | |
395 | IMPLICIT_IT_MODE_ARM = 0x01, | |
396 | IMPLICIT_IT_MODE_THUMB = 0x02, | |
397 | IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB) | |
398 | }; | |
399 | static int implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
400 | ||
c19d1205 ZW |
401 | /* If unified_syntax is true, we are processing the new unified |
402 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
403 | ||
404 | - Immediate operands do not require a # prefix. | |
405 | - Conditional affixes always appear at the end of the | |
406 | instruction. (For backward compatibility, those instructions | |
407 | that formerly had them in the middle, continue to accept them | |
408 | there.) | |
409 | - The IT instruction may appear, and if it does is validated | |
410 | against subsequent conditional affixes. It does not generate | |
411 | machine code. | |
412 | ||
413 | Important differences from the old Thumb mode: | |
414 | ||
415 | - Immediate operands do not require a # prefix. | |
416 | - Most of the V6T2 instructions are only available in unified mode. | |
417 | - The .N and .W suffixes are recognized and honored (it is an error | |
418 | if they cannot be honored). | |
419 | - All instructions set the flags if and only if they have an 's' affix. | |
420 | - Conditional affixes may be used. They are validated against | |
421 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
422 | conditional affix except in the scope of an IT instruction. */ | |
423 | ||
424 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef | 425 | |
bacebabc RM |
426 | /* An immediate operand can start with #, and ld*, st*, pld operands |
427 | can contain [ and ]. We need to tell APP not to elide whitespace | |
477330fc RM |
428 | before a [, which can appear as the first operand for pld. |
429 | Likewise, a { can appear as the first operand for push, pop, vld*, etc. */ | |
430 | const char arm_symbol_chars[] = "#[]{}"; | |
bacebabc | 431 | |
5287ad62 JB |
432 | enum neon_el_type |
433 | { | |
dcbf9037 | 434 | NT_invtype, |
5287ad62 JB |
435 | NT_untyped, |
436 | NT_integer, | |
437 | NT_float, | |
438 | NT_poly, | |
439 | NT_signed, | |
dcbf9037 | 440 | NT_unsigned |
5287ad62 JB |
441 | }; |
442 | ||
443 | struct neon_type_el | |
444 | { | |
445 | enum neon_el_type type; | |
446 | unsigned size; | |
447 | }; | |
448 | ||
449 | #define NEON_MAX_TYPE_ELS 4 | |
450 | ||
451 | struct neon_type | |
452 | { | |
453 | struct neon_type_el el[NEON_MAX_TYPE_ELS]; | |
454 | unsigned elems; | |
455 | }; | |
456 | ||
5ee91343 | 457 | enum pred_instruction_type |
e07e6e58 | 458 | { |
5ee91343 AV |
459 | OUTSIDE_PRED_INSN, |
460 | INSIDE_VPT_INSN, | |
e07e6e58 NC |
461 | INSIDE_IT_INSN, |
462 | INSIDE_IT_LAST_INSN, | |
463 | IF_INSIDE_IT_LAST_INSN, /* Either outside or inside; | |
477330fc | 464 | if inside, should be the last one. */ |
e07e6e58 | 465 | NEUTRAL_IT_INSN, /* This could be either inside or outside, |
477330fc | 466 | i.e. BKPT and NOP. */ |
5ee91343 AV |
467 | IT_INSN, /* The IT insn has been parsed. */ |
468 | VPT_INSN, /* The VPT/VPST insn has been parsed. */ | |
35c228db | 469 | MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without |
5ee91343 | 470 | a predication code. */ |
35c228db | 471 | MVE_UNPREDICABLE_INSN /* MVE instruction that is non-predicable. */ |
e07e6e58 NC |
472 | }; |
473 | ||
ad6cec43 MGD |
474 | /* The maximum number of operands we need. */ |
475 | #define ARM_IT_MAX_OPERANDS 6 | |
e2b0ab59 | 476 | #define ARM_IT_MAX_RELOCS 3 |
ad6cec43 | 477 | |
b99bd4ef NC |
478 | struct arm_it |
479 | { | |
c19d1205 | 480 | const char * error; |
b99bd4ef | 481 | unsigned long instruction; |
c19d1205 ZW |
482 | int size; |
483 | int size_req; | |
484 | int cond; | |
037e8744 JB |
485 | /* "uncond_value" is set to the value in place of the conditional field in |
486 | unconditional versions of the instruction, or -1 if nothing is | |
487 | appropriate. */ | |
488 | int uncond_value; | |
5287ad62 | 489 | struct neon_type vectype; |
88714cb8 DG |
490 | /* This does not indicate an actual NEON instruction, only that |
491 | the mnemonic accepts neon-style type suffixes. */ | |
492 | int is_neon; | |
0110f2b8 PB |
493 | /* Set to the opcode if the instruction needs relaxation. |
494 | Zero if the instruction is not relaxed. */ | |
495 | unsigned long relax; | |
b99bd4ef NC |
496 | struct |
497 | { | |
498 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
499 | expressionS exp; |
500 | int pc_rel; | |
e2b0ab59 | 501 | } relocs[ARM_IT_MAX_RELOCS]; |
b99bd4ef | 502 | |
5ee91343 | 503 | enum pred_instruction_type pred_insn_type; |
e07e6e58 | 504 | |
c19d1205 ZW |
505 | struct |
506 | { | |
507 | unsigned reg; | |
ca3f61f7 | 508 | signed int imm; |
dcbf9037 | 509 | struct neon_type_el vectype; |
ca3f61f7 NC |
510 | unsigned present : 1; /* Operand present. */ |
511 | unsigned isreg : 1; /* Operand was a register. */ | |
f5f10c66 AV |
512 | unsigned immisreg : 2; /* .imm field is a second register. |
513 | 0: imm, 1: gpr, 2: MVE Q-register. */ | |
57785aa2 AV |
514 | unsigned isscalar : 2; /* Operand is a (SIMD) scalar: |
515 | 0) not scalar, | |
516 | 1) Neon scalar, | |
517 | 2) MVE scalar. */ | |
5287ad62 | 518 | unsigned immisalign : 1; /* Immediate is an alignment specifier. */ |
c96612cc | 519 | unsigned immisfloat : 1; /* Immediate was parsed as a float. */ |
5287ad62 JB |
520 | /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV |
521 | instructions. This allows us to disambiguate ARM <-> vector insns. */ | |
522 | unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */ | |
037e8744 | 523 | unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */ |
5ee91343 | 524 | unsigned isquad : 1; /* Operand is SIMD quad register. */ |
037e8744 | 525 | unsigned issingle : 1; /* Operand is VFP single-precision register. */ |
1b883319 | 526 | unsigned iszr : 1; /* Operand is ZR register. */ |
ca3f61f7 NC |
527 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ |
528 | unsigned writeback : 1; /* Operand has trailing ! */ | |
529 | unsigned preind : 1; /* Preindexed address. */ | |
530 | unsigned postind : 1; /* Postindexed address. */ | |
531 | unsigned negative : 1; /* Index register was negated. */ | |
532 | unsigned shifted : 1; /* Shift applied to operation. */ | |
533 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
ad6cec43 | 534 | } operands[ARM_IT_MAX_OPERANDS]; |
b99bd4ef NC |
535 | }; |
536 | ||
c19d1205 | 537 | static struct arm_it inst; |
b99bd4ef NC |
538 | |
539 | #define NUM_FLOAT_VALS 8 | |
540 | ||
05d2d07e | 541 | const char * fp_const[] = |
b99bd4ef NC |
542 | { |
543 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
544 | }; | |
545 | ||
b99bd4ef NC |
546 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; |
547 | ||
548 | #define FAIL (-1) | |
549 | #define SUCCESS (0) | |
550 | ||
551 | #define SUFF_S 1 | |
552 | #define SUFF_D 2 | |
553 | #define SUFF_E 3 | |
554 | #define SUFF_P 4 | |
555 | ||
c19d1205 ZW |
556 | #define CP_T_X 0x00008000 |
557 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 558 | |
c19d1205 ZW |
559 | #define CONDS_BIT 0x00100000 |
560 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
561 | |
562 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
563 | ||
564 | struct asm_cond | |
565 | { | |
d3ce72d0 | 566 | const char * template_name; |
c921be7d | 567 | unsigned long value; |
b99bd4ef NC |
568 | }; |
569 | ||
c19d1205 | 570 | #define COND_ALWAYS 0xE |
b99bd4ef | 571 | |
b99bd4ef NC |
572 | struct asm_psr |
573 | { | |
d3ce72d0 | 574 | const char * template_name; |
c921be7d | 575 | unsigned long field; |
b99bd4ef NC |
576 | }; |
577 | ||
62b3e311 PB |
578 | struct asm_barrier_opt |
579 | { | |
e797f7e0 MGD |
580 | const char * template_name; |
581 | unsigned long value; | |
582 | const arm_feature_set arch; | |
62b3e311 PB |
583 | }; |
584 | ||
2d2255b5 | 585 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
586 | #define SPSR_BIT (1 << 22) |
587 | ||
c19d1205 ZW |
588 | /* The individual PSR flag bits. */ |
589 | #define PSR_c (1 << 16) | |
590 | #define PSR_x (1 << 17) | |
591 | #define PSR_s (1 << 18) | |
592 | #define PSR_f (1 << 19) | |
b99bd4ef | 593 | |
c19d1205 | 594 | struct reloc_entry |
bfae80f2 | 595 | { |
0198d5e6 | 596 | const char * name; |
c921be7d | 597 | bfd_reloc_code_real_type reloc; |
bfae80f2 RE |
598 | }; |
599 | ||
5287ad62 | 600 | enum vfp_reg_pos |
bfae80f2 | 601 | { |
5287ad62 JB |
602 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn, |
603 | VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn | |
bfae80f2 RE |
604 | }; |
605 | ||
606 | enum vfp_ldstm_type | |
607 | { | |
608 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
609 | }; | |
610 | ||
dcbf9037 JB |
611 | /* Bits for DEFINED field in neon_typed_alias. */ |
612 | #define NTA_HASTYPE 1 | |
613 | #define NTA_HASINDEX 2 | |
614 | ||
615 | struct neon_typed_alias | |
616 | { | |
c921be7d NC |
617 | unsigned char defined; |
618 | unsigned char index; | |
619 | struct neon_type_el eltype; | |
dcbf9037 JB |
620 | }; |
621 | ||
c19d1205 | 622 | /* ARM register categories. This includes coprocessor numbers and various |
5aa75429 TP |
623 | architecture extensions' registers. Each entry should have an error message |
624 | in reg_expected_msgs below. */ | |
c19d1205 | 625 | enum arm_reg_type |
bfae80f2 | 626 | { |
c19d1205 ZW |
627 | REG_TYPE_RN, |
628 | REG_TYPE_CP, | |
629 | REG_TYPE_CN, | |
630 | REG_TYPE_FN, | |
631 | REG_TYPE_VFS, | |
632 | REG_TYPE_VFD, | |
5287ad62 | 633 | REG_TYPE_NQ, |
037e8744 | 634 | REG_TYPE_VFSD, |
5287ad62 | 635 | REG_TYPE_NDQ, |
dec41383 | 636 | REG_TYPE_NSD, |
037e8744 | 637 | REG_TYPE_NSDQ, |
c19d1205 ZW |
638 | REG_TYPE_VFC, |
639 | REG_TYPE_MVF, | |
640 | REG_TYPE_MVD, | |
641 | REG_TYPE_MVFX, | |
642 | REG_TYPE_MVDX, | |
643 | REG_TYPE_MVAX, | |
5ee91343 | 644 | REG_TYPE_MQ, |
c19d1205 ZW |
645 | REG_TYPE_DSPSC, |
646 | REG_TYPE_MMXWR, | |
647 | REG_TYPE_MMXWC, | |
648 | REG_TYPE_MMXWCG, | |
649 | REG_TYPE_XSCALE, | |
5ee91343 | 650 | REG_TYPE_RNB, |
1b883319 | 651 | REG_TYPE_ZR |
bfae80f2 RE |
652 | }; |
653 | ||
dcbf9037 JB |
654 | /* Structure for a hash table entry for a register. |
655 | If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra | |
656 | information which states whether a vector type or index is specified (for a | |
657 | register alias created with .dn or .qn). Otherwise NEON should be NULL. */ | |
6c43fab6 RE |
658 | struct reg_entry |
659 | { | |
c921be7d | 660 | const char * name; |
90ec0d68 | 661 | unsigned int number; |
c921be7d NC |
662 | unsigned char type; |
663 | unsigned char builtin; | |
664 | struct neon_typed_alias * neon; | |
6c43fab6 RE |
665 | }; |
666 | ||
c19d1205 | 667 | /* Diagnostics used when we don't get a register of the expected type. */ |
c921be7d | 668 | const char * const reg_expected_msgs[] = |
c19d1205 | 669 | { |
5aa75429 TP |
670 | [REG_TYPE_RN] = N_("ARM register expected"), |
671 | [REG_TYPE_CP] = N_("bad or missing co-processor number"), | |
672 | [REG_TYPE_CN] = N_("co-processor register expected"), | |
673 | [REG_TYPE_FN] = N_("FPA register expected"), | |
674 | [REG_TYPE_VFS] = N_("VFP single precision register expected"), | |
675 | [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"), | |
676 | [REG_TYPE_NQ] = N_("Neon quad precision register expected"), | |
677 | [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"), | |
678 | [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"), | |
679 | [REG_TYPE_NSD] = N_("Neon single or double precision register expected"), | |
680 | [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register" | |
681 | " expected"), | |
682 | [REG_TYPE_VFC] = N_("VFP system register expected"), | |
683 | [REG_TYPE_MVF] = N_("Maverick MVF register expected"), | |
684 | [REG_TYPE_MVD] = N_("Maverick MVD register expected"), | |
685 | [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"), | |
686 | [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"), | |
687 | [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"), | |
688 | [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"), | |
689 | [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"), | |
690 | [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"), | |
691 | [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"), | |
692 | [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"), | |
5ee91343 | 693 | [REG_TYPE_MQ] = N_("MVE vector register expected"), |
5aa75429 | 694 | [REG_TYPE_RNB] = N_("") |
6c43fab6 RE |
695 | }; |
696 | ||
c19d1205 | 697 | /* Some well known registers that we refer to directly elsewhere. */ |
bd340a04 | 698 | #define REG_R12 12 |
c19d1205 ZW |
699 | #define REG_SP 13 |
700 | #define REG_LR 14 | |
701 | #define REG_PC 15 | |
404ff6b5 | 702 | |
b99bd4ef NC |
703 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
704 | take 2: */ | |
c19d1205 | 705 | #define INSN_SIZE 4 |
b99bd4ef NC |
706 | |
707 | struct asm_opcode | |
708 | { | |
709 | /* Basic string to match. */ | |
d3ce72d0 | 710 | const char * template_name; |
c19d1205 ZW |
711 | |
712 | /* Parameters to instruction. */ | |
5be8be5d | 713 | unsigned int operands[8]; |
c19d1205 ZW |
714 | |
715 | /* Conditional tag - see opcode_lookup. */ | |
716 | unsigned int tag : 4; | |
b99bd4ef NC |
717 | |
718 | /* Basic instruction code. */ | |
a302e574 | 719 | unsigned int avalue; |
b99bd4ef | 720 | |
c19d1205 ZW |
721 | /* Thumb-format instruction code. */ |
722 | unsigned int tvalue; | |
b99bd4ef | 723 | |
90e4755a | 724 | /* Which architecture variant provides this instruction. */ |
c921be7d NC |
725 | const arm_feature_set * avariant; |
726 | const arm_feature_set * tvariant; | |
c19d1205 ZW |
727 | |
728 | /* Function to call to encode instruction in ARM format. */ | |
729 | void (* aencode) (void); | |
b99bd4ef | 730 | |
c19d1205 ZW |
731 | /* Function to call to encode instruction in Thumb format. */ |
732 | void (* tencode) (void); | |
5ee91343 AV |
733 | |
734 | /* Indicates whether this instruction may be vector predicated. */ | |
735 | unsigned int mayBeVecPred : 1; | |
b99bd4ef NC |
736 | }; |
737 | ||
a737bd4d NC |
738 | /* Defines for various bits that we will want to toggle. */ |
739 | #define INST_IMMEDIATE 0x02000000 | |
740 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 741 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
742 | #define SHIFT_BY_REG 0x00000010 |
743 | #define PRE_INDEX 0x01000000 | |
744 | #define INDEX_UP 0x00800000 | |
745 | #define WRITE_BACK 0x00200000 | |
746 | #define LDM_TYPE_2_OR_3 0x00400000 | |
a028a6f5 | 747 | #define CPSI_MMOD 0x00020000 |
90e4755a | 748 | |
a737bd4d NC |
749 | #define LITERAL_MASK 0xf000f000 |
750 | #define OPCODE_MASK 0xfe1fffff | |
751 | #define V4_STR_BIT 0x00000020 | |
8335d6aa | 752 | #define VLDR_VMOV_SAME 0x0040f000 |
90e4755a | 753 | |
efd81785 PB |
754 | #define T2_SUBS_PC_LR 0xf3de8f00 |
755 | ||
a737bd4d | 756 | #define DATA_OP_SHIFT 21 |
bada4342 | 757 | #define SBIT_SHIFT 20 |
90e4755a | 758 | |
ef8d22e6 PB |
759 | #define T2_OPCODE_MASK 0xfe1fffff |
760 | #define T2_DATA_OP_SHIFT 21 | |
bada4342 | 761 | #define T2_SBIT_SHIFT 20 |
ef8d22e6 | 762 | |
6530b175 NC |
763 | #define A_COND_MASK 0xf0000000 |
764 | #define A_PUSH_POP_OP_MASK 0x0fff0000 | |
765 | ||
766 | /* Opcodes for pushing/poping registers to/from the stack. */ | |
767 | #define A1_OPCODE_PUSH 0x092d0000 | |
768 | #define A2_OPCODE_PUSH 0x052d0004 | |
769 | #define A2_OPCODE_POP 0x049d0004 | |
770 | ||
a737bd4d NC |
771 | /* Codes to distinguish the arithmetic instructions. */ |
772 | #define OPCODE_AND 0 | |
773 | #define OPCODE_EOR 1 | |
774 | #define OPCODE_SUB 2 | |
775 | #define OPCODE_RSB 3 | |
776 | #define OPCODE_ADD 4 | |
777 | #define OPCODE_ADC 5 | |
778 | #define OPCODE_SBC 6 | |
779 | #define OPCODE_RSC 7 | |
780 | #define OPCODE_TST 8 | |
781 | #define OPCODE_TEQ 9 | |
782 | #define OPCODE_CMP 10 | |
783 | #define OPCODE_CMN 11 | |
784 | #define OPCODE_ORR 12 | |
785 | #define OPCODE_MOV 13 | |
786 | #define OPCODE_BIC 14 | |
787 | #define OPCODE_MVN 15 | |
90e4755a | 788 | |
ef8d22e6 PB |
789 | #define T2_OPCODE_AND 0 |
790 | #define T2_OPCODE_BIC 1 | |
791 | #define T2_OPCODE_ORR 2 | |
792 | #define T2_OPCODE_ORN 3 | |
793 | #define T2_OPCODE_EOR 4 | |
794 | #define T2_OPCODE_ADD 8 | |
795 | #define T2_OPCODE_ADC 10 | |
796 | #define T2_OPCODE_SBC 11 | |
797 | #define T2_OPCODE_SUB 13 | |
798 | #define T2_OPCODE_RSB 14 | |
799 | ||
a737bd4d NC |
800 | #define T_OPCODE_MUL 0x4340 |
801 | #define T_OPCODE_TST 0x4200 | |
802 | #define T_OPCODE_CMN 0x42c0 | |
803 | #define T_OPCODE_NEG 0x4240 | |
804 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 805 | |
a737bd4d NC |
806 | #define T_OPCODE_ADD_R3 0x1800 |
807 | #define T_OPCODE_SUB_R3 0x1a00 | |
808 | #define T_OPCODE_ADD_HI 0x4400 | |
809 | #define T_OPCODE_ADD_ST 0xb000 | |
810 | #define T_OPCODE_SUB_ST 0xb080 | |
811 | #define T_OPCODE_ADD_SP 0xa800 | |
812 | #define T_OPCODE_ADD_PC 0xa000 | |
813 | #define T_OPCODE_ADD_I8 0x3000 | |
814 | #define T_OPCODE_SUB_I8 0x3800 | |
815 | #define T_OPCODE_ADD_I3 0x1c00 | |
816 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 817 | |
a737bd4d NC |
818 | #define T_OPCODE_ASR_R 0x4100 |
819 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
820 | #define T_OPCODE_LSR_R 0x40c0 |
821 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
822 | #define T_OPCODE_ASR_I 0x1000 |
823 | #define T_OPCODE_LSL_I 0x0000 | |
824 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 825 | |
a737bd4d NC |
826 | #define T_OPCODE_MOV_I8 0x2000 |
827 | #define T_OPCODE_CMP_I8 0x2800 | |
828 | #define T_OPCODE_CMP_LR 0x4280 | |
829 | #define T_OPCODE_MOV_HR 0x4600 | |
830 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 831 | |
a737bd4d NC |
832 | #define T_OPCODE_LDR_PC 0x4800 |
833 | #define T_OPCODE_LDR_SP 0x9800 | |
834 | #define T_OPCODE_STR_SP 0x9000 | |
835 | #define T_OPCODE_LDR_IW 0x6800 | |
836 | #define T_OPCODE_STR_IW 0x6000 | |
837 | #define T_OPCODE_LDR_IH 0x8800 | |
838 | #define T_OPCODE_STR_IH 0x8000 | |
839 | #define T_OPCODE_LDR_IB 0x7800 | |
840 | #define T_OPCODE_STR_IB 0x7000 | |
841 | #define T_OPCODE_LDR_RW 0x5800 | |
842 | #define T_OPCODE_STR_RW 0x5000 | |
843 | #define T_OPCODE_LDR_RH 0x5a00 | |
844 | #define T_OPCODE_STR_RH 0x5200 | |
845 | #define T_OPCODE_LDR_RB 0x5c00 | |
846 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 847 | |
a737bd4d NC |
848 | #define T_OPCODE_PUSH 0xb400 |
849 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 850 | |
2fc8bdac | 851 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 852 | |
a737bd4d | 853 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 854 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 855 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 856 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 | 857 | |
5ee91343 | 858 | #define BAD_SYNTAX _("syntax error") |
c19d1205 | 859 | #define BAD_ARGS _("bad arguments to instruction") |
fdfde340 | 860 | #define BAD_SP _("r13 not allowed here") |
c19d1205 | 861 | #define BAD_PC _("r15 not allowed here") |
a302e574 AV |
862 | #define BAD_ODD _("Odd register not allowed here") |
863 | #define BAD_EVEN _("Even register not allowed here") | |
c19d1205 ZW |
864 | #define BAD_COND _("instruction cannot be conditional") |
865 | #define BAD_OVERLAP _("registers may not be the same") | |
866 | #define BAD_HIREG _("lo register required") | |
867 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
35c228db | 868 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode") |
dfa9f0d5 | 869 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
e12437dc | 870 | #define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2") |
dfa9f0d5 | 871 | #define BAD_NOT_IT _("instruction not allowed in IT block") |
5ee91343 | 872 | #define BAD_NOT_VPT _("instruction missing MVE vector predication code") |
037e8744 | 873 | #define BAD_FPU _("selected FPU does not support instruction") |
e07e6e58 | 874 | #define BAD_OUT_IT _("thumb conditional instruction should be in IT block") |
5ee91343 AV |
875 | #define BAD_OUT_VPT \ |
876 | _("vector predicated instruction should be in VPT/VPST block") | |
e07e6e58 | 877 | #define BAD_IT_COND _("incorrect condition in IT block") |
5ee91343 | 878 | #define BAD_VPT_COND _("incorrect condition in VPT/VPST block") |
e07e6e58 | 879 | #define BAD_IT_IT _("IT falling in the range of a previous IT block") |
921e5f0a | 880 | #define MISSING_FNSTART _("missing .fnstart before unwinding directive") |
5be8be5d DG |
881 | #define BAD_PC_ADDRESSING \ |
882 | _("cannot use register index with PC-relative addressing") | |
883 | #define BAD_PC_WRITEBACK \ | |
884 | _("cannot use writeback with PC-relative addressing") | |
9db2f6b4 RL |
885 | #define BAD_RANGE _("branch out of range") |
886 | #define BAD_FP16 _("selected processor does not support fp16 instruction") | |
dd5181d5 | 887 | #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour") |
a9f02af8 | 888 | #define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only") |
5ee91343 AV |
889 | #define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \ |
890 | "block") | |
891 | #define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \ | |
892 | "block") | |
893 | #define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \ | |
894 | " operand") | |
895 | #define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \ | |
896 | " operand") | |
a302e574 | 897 | #define BAD_SIMD_TYPE _("bad type in SIMD instruction") |
886e1c73 AV |
898 | #define BAD_MVE_AUTO \ |
899 | _("GAS auto-detection mode and -march=all is deprecated for MVE, please" \ | |
900 | " use a valid -march or -mcpu option.") | |
901 | #define BAD_MVE_SRCDEST _("Warning: 32-bit element size and same destination "\ | |
902 | "and source operands makes instruction UNPREDICTABLE") | |
35c228db | 903 | #define BAD_EL_TYPE _("bad element type for instruction") |
1b883319 | 904 | #define MVE_BAD_QREG _("MVE vector register Q[0..7] expected") |
c19d1205 | 905 | |
c921be7d NC |
906 | static struct hash_control * arm_ops_hsh; |
907 | static struct hash_control * arm_cond_hsh; | |
5ee91343 | 908 | static struct hash_control * arm_vcond_hsh; |
c921be7d NC |
909 | static struct hash_control * arm_shift_hsh; |
910 | static struct hash_control * arm_psr_hsh; | |
911 | static struct hash_control * arm_v7m_psr_hsh; | |
912 | static struct hash_control * arm_reg_hsh; | |
913 | static struct hash_control * arm_reloc_hsh; | |
914 | static struct hash_control * arm_barrier_opt_hsh; | |
b99bd4ef | 915 | |
b99bd4ef NC |
916 | /* Stuff needed to resolve the label ambiguity |
917 | As: | |
918 | ... | |
919 | label: <insn> | |
920 | may differ from: | |
921 | ... | |
922 | label: | |
5f4273c7 | 923 | <insn> */ |
b99bd4ef NC |
924 | |
925 | symbolS * last_label_seen; | |
b34976b6 | 926 | static int label_is_thumb_function_name = FALSE; |
e07e6e58 | 927 | |
3d0c9500 NC |
928 | /* Literal pool structure. Held on a per-section |
929 | and per-sub-section basis. */ | |
a737bd4d | 930 | |
c19d1205 | 931 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 932 | typedef struct literal_pool |
b99bd4ef | 933 | { |
c921be7d NC |
934 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
935 | unsigned int next_free_entry; | |
936 | unsigned int id; | |
937 | symbolS * symbol; | |
938 | segT section; | |
939 | subsegT sub_section; | |
a8040cf2 NC |
940 | #ifdef OBJ_ELF |
941 | struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE]; | |
942 | #endif | |
c921be7d | 943 | struct literal_pool * next; |
8335d6aa | 944 | unsigned int alignment; |
3d0c9500 | 945 | } literal_pool; |
b99bd4ef | 946 | |
3d0c9500 NC |
947 | /* Pointer to a linked list of literal pools. */ |
948 | literal_pool * list_of_pools = NULL; | |
e27ec89e | 949 | |
2e6976a8 DG |
950 | typedef enum asmfunc_states |
951 | { | |
952 | OUTSIDE_ASMFUNC, | |
953 | WAITING_ASMFUNC_NAME, | |
954 | WAITING_ENDASMFUNC | |
955 | } asmfunc_states; | |
956 | ||
957 | static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC; | |
958 | ||
e07e6e58 | 959 | #ifdef OBJ_ELF |
5ee91343 | 960 | # define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred |
e07e6e58 | 961 | #else |
5ee91343 | 962 | static struct current_pred now_pred; |
e07e6e58 NC |
963 | #endif |
964 | ||
965 | static inline int | |
5ee91343 | 966 | now_pred_compatible (int cond) |
e07e6e58 | 967 | { |
5ee91343 | 968 | return (cond & ~1) == (now_pred.cc & ~1); |
e07e6e58 NC |
969 | } |
970 | ||
971 | static inline int | |
972 | conditional_insn (void) | |
973 | { | |
974 | return inst.cond != COND_ALWAYS; | |
975 | } | |
976 | ||
5ee91343 | 977 | static int in_pred_block (void); |
e07e6e58 | 978 | |
5ee91343 | 979 | static int handle_pred_state (void); |
e07e6e58 NC |
980 | |
981 | static void force_automatic_it_block_close (void); | |
982 | ||
c921be7d NC |
983 | static void it_fsm_post_encode (void); |
984 | ||
5ee91343 | 985 | #define set_pred_insn_type(type) \ |
e07e6e58 NC |
986 | do \ |
987 | { \ | |
5ee91343 AV |
988 | inst.pred_insn_type = type; \ |
989 | if (handle_pred_state () == FAIL) \ | |
477330fc | 990 | return; \ |
e07e6e58 NC |
991 | } \ |
992 | while (0) | |
993 | ||
5ee91343 | 994 | #define set_pred_insn_type_nonvoid(type, failret) \ |
c921be7d NC |
995 | do \ |
996 | { \ | |
5ee91343 AV |
997 | inst.pred_insn_type = type; \ |
998 | if (handle_pred_state () == FAIL) \ | |
477330fc | 999 | return failret; \ |
c921be7d NC |
1000 | } \ |
1001 | while(0) | |
1002 | ||
5ee91343 | 1003 | #define set_pred_insn_type_last() \ |
e07e6e58 NC |
1004 | do \ |
1005 | { \ | |
1006 | if (inst.cond == COND_ALWAYS) \ | |
5ee91343 | 1007 | set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \ |
e07e6e58 | 1008 | else \ |
5ee91343 | 1009 | set_pred_insn_type (INSIDE_IT_LAST_INSN); \ |
e07e6e58 NC |
1010 | } \ |
1011 | while (0) | |
1012 | ||
e39c1607 SD |
1013 | /* Toggle value[pos]. */ |
1014 | #define TOGGLE_BIT(value, pos) (value ^ (1 << pos)) | |
1015 | ||
c19d1205 | 1016 | /* Pure syntax. */ |
b99bd4ef | 1017 | |
c19d1205 ZW |
1018 | /* This array holds the chars that always start a comment. If the |
1019 | pre-processor is disabled, these aren't very useful. */ | |
2e6976a8 | 1020 | char arm_comment_chars[] = "@"; |
3d0c9500 | 1021 | |
c19d1205 ZW |
1022 | /* This array holds the chars that only start a comment at the beginning of |
1023 | a line. If the line seems to have the form '# 123 filename' | |
1024 | .line and .file directives will appear in the pre-processed output. */ | |
1025 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
1026 | first line of the input file. This is because the compiler outputs | |
1027 | #NO_APP at the beginning of its output. */ | |
1028 | /* Also note that comments like this one will always work. */ | |
1029 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 1030 | |
2e6976a8 | 1031 | char arm_line_separator_chars[] = ";"; |
b99bd4ef | 1032 | |
c19d1205 ZW |
1033 | /* Chars that can be used to separate mant |
1034 | from exp in floating point numbers. */ | |
1035 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 1036 | |
c19d1205 ZW |
1037 | /* Chars that mean this number is a floating point constant. */ |
1038 | /* As in 0f12.456 */ | |
1039 | /* or 0d1.2345e12 */ | |
b99bd4ef | 1040 | |
5312fe52 | 1041 | const char FLT_CHARS[] = "rRsSfFdDxXeEpPHh"; |
3d0c9500 | 1042 | |
c19d1205 ZW |
1043 | /* Prefix characters that indicate the start of an immediate |
1044 | value. */ | |
1045 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 1046 | |
c19d1205 ZW |
1047 | /* Separator character handling. */ |
1048 | ||
1049 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
1050 | ||
5312fe52 BW |
1051 | enum fp_16bit_format |
1052 | { | |
1053 | ARM_FP16_FORMAT_IEEE = 0x1, | |
1054 | ARM_FP16_FORMAT_ALTERNATIVE = 0x2, | |
1055 | ARM_FP16_FORMAT_DEFAULT = 0x3 | |
1056 | }; | |
1057 | ||
1058 | static enum fp_16bit_format fp16_format = ARM_FP16_FORMAT_DEFAULT; | |
1059 | ||
1060 | ||
c19d1205 ZW |
1061 | static inline int |
1062 | skip_past_char (char ** str, char c) | |
1063 | { | |
8ab8155f NC |
1064 | /* PR gas/14987: Allow for whitespace before the expected character. */ |
1065 | skip_whitespace (*str); | |
427d0db6 | 1066 | |
c19d1205 ZW |
1067 | if (**str == c) |
1068 | { | |
1069 | (*str)++; | |
1070 | return SUCCESS; | |
3d0c9500 | 1071 | } |
c19d1205 ZW |
1072 | else |
1073 | return FAIL; | |
1074 | } | |
c921be7d | 1075 | |
c19d1205 | 1076 | #define skip_past_comma(str) skip_past_char (str, ',') |
3d0c9500 | 1077 | |
c19d1205 ZW |
1078 | /* Arithmetic expressions (possibly involving symbols). */ |
1079 | ||
1080 | /* Return TRUE if anything in the expression is a bignum. */ | |
1081 | ||
0198d5e6 | 1082 | static bfd_boolean |
c19d1205 ZW |
1083 | walk_no_bignums (symbolS * sp) |
1084 | { | |
1085 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
0198d5e6 | 1086 | return TRUE; |
c19d1205 ZW |
1087 | |
1088 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 1089 | { |
c19d1205 ZW |
1090 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
1091 | || (symbol_get_value_expression (sp)->X_op_symbol | |
1092 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
1093 | } |
1094 | ||
0198d5e6 | 1095 | return FALSE; |
3d0c9500 NC |
1096 | } |
1097 | ||
0198d5e6 | 1098 | static bfd_boolean in_my_get_expression = FALSE; |
c19d1205 ZW |
1099 | |
1100 | /* Third argument to my_get_expression. */ | |
1101 | #define GE_NO_PREFIX 0 | |
1102 | #define GE_IMM_PREFIX 1 | |
1103 | #define GE_OPT_PREFIX 2 | |
5287ad62 JB |
1104 | /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit) |
1105 | immediates, as can be used in Neon VMVN and VMOV immediate instructions. */ | |
1106 | #define GE_OPT_PREFIX_BIG 3 | |
a737bd4d | 1107 | |
b99bd4ef | 1108 | static int |
c19d1205 | 1109 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 1110 | { |
c19d1205 | 1111 | char * save_in; |
b99bd4ef | 1112 | |
c19d1205 ZW |
1113 | /* In unified syntax, all prefixes are optional. */ |
1114 | if (unified_syntax) | |
5287ad62 | 1115 | prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode |
477330fc | 1116 | : GE_OPT_PREFIX; |
b99bd4ef | 1117 | |
c19d1205 | 1118 | switch (prefix_mode) |
b99bd4ef | 1119 | { |
c19d1205 ZW |
1120 | case GE_NO_PREFIX: break; |
1121 | case GE_IMM_PREFIX: | |
1122 | if (!is_immediate_prefix (**str)) | |
1123 | { | |
1124 | inst.error = _("immediate expression requires a # prefix"); | |
1125 | return FAIL; | |
1126 | } | |
1127 | (*str)++; | |
1128 | break; | |
1129 | case GE_OPT_PREFIX: | |
5287ad62 | 1130 | case GE_OPT_PREFIX_BIG: |
c19d1205 ZW |
1131 | if (is_immediate_prefix (**str)) |
1132 | (*str)++; | |
1133 | break; | |
0198d5e6 TC |
1134 | default: |
1135 | abort (); | |
c19d1205 | 1136 | } |
b99bd4ef | 1137 | |
c19d1205 | 1138 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 1139 | |
c19d1205 ZW |
1140 | save_in = input_line_pointer; |
1141 | input_line_pointer = *str; | |
0198d5e6 | 1142 | in_my_get_expression = TRUE; |
2ac93be7 | 1143 | expression (ep); |
0198d5e6 | 1144 | in_my_get_expression = FALSE; |
c19d1205 | 1145 | |
f86adc07 | 1146 | if (ep->X_op == O_illegal || ep->X_op == O_absent) |
b99bd4ef | 1147 | { |
f86adc07 | 1148 | /* We found a bad or missing expression in md_operand(). */ |
c19d1205 ZW |
1149 | *str = input_line_pointer; |
1150 | input_line_pointer = save_in; | |
1151 | if (inst.error == NULL) | |
f86adc07 NS |
1152 | inst.error = (ep->X_op == O_absent |
1153 | ? _("missing expression") :_("bad expression")); | |
c19d1205 ZW |
1154 | return 1; |
1155 | } | |
b99bd4ef | 1156 | |
c19d1205 ZW |
1157 | /* Get rid of any bignums now, so that we don't generate an error for which |
1158 | we can't establish a line number later on. Big numbers are never valid | |
1159 | in instructions, which is where this routine is always called. */ | |
5287ad62 JB |
1160 | if (prefix_mode != GE_OPT_PREFIX_BIG |
1161 | && (ep->X_op == O_big | |
477330fc | 1162 | || (ep->X_add_symbol |
5287ad62 | 1163 | && (walk_no_bignums (ep->X_add_symbol) |
477330fc | 1164 | || (ep->X_op_symbol |
5287ad62 | 1165 | && walk_no_bignums (ep->X_op_symbol)))))) |
c19d1205 ZW |
1166 | { |
1167 | inst.error = _("invalid constant"); | |
1168 | *str = input_line_pointer; | |
1169 | input_line_pointer = save_in; | |
1170 | return 1; | |
1171 | } | |
b99bd4ef | 1172 | |
c19d1205 ZW |
1173 | *str = input_line_pointer; |
1174 | input_line_pointer = save_in; | |
0198d5e6 | 1175 | return SUCCESS; |
b99bd4ef NC |
1176 | } |
1177 | ||
c19d1205 ZW |
1178 | /* Turn a string in input_line_pointer into a floating point constant |
1179 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
1180 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
1181 | returned, or NULL on OK. | |
b99bd4ef | 1182 | |
c19d1205 ZW |
1183 | Note that fp constants aren't represent in the normal way on the ARM. |
1184 | In big endian mode, things are as expected. However, in little endian | |
1185 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
1186 | within the words. For example, (double) 1.1 in big endian mode is | |
1187 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
1188 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 1189 | |
c19d1205 | 1190 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 1191 | |
6d4af3c2 | 1192 | const char * |
c19d1205 ZW |
1193 | md_atof (int type, char * litP, int * sizeP) |
1194 | { | |
1195 | int prec; | |
1196 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
1197 | char *t; | |
1198 | int i; | |
b99bd4ef | 1199 | |
c19d1205 ZW |
1200 | switch (type) |
1201 | { | |
5312fe52 BW |
1202 | case 'H': |
1203 | case 'h': | |
1204 | prec = 1; | |
1205 | break; | |
1206 | ||
c19d1205 ZW |
1207 | case 'f': |
1208 | case 'F': | |
1209 | case 's': | |
1210 | case 'S': | |
1211 | prec = 2; | |
1212 | break; | |
b99bd4ef | 1213 | |
c19d1205 ZW |
1214 | case 'd': |
1215 | case 'D': | |
1216 | case 'r': | |
1217 | case 'R': | |
1218 | prec = 4; | |
1219 | break; | |
b99bd4ef | 1220 | |
c19d1205 ZW |
1221 | case 'x': |
1222 | case 'X': | |
499ac353 | 1223 | prec = 5; |
c19d1205 | 1224 | break; |
b99bd4ef | 1225 | |
c19d1205 ZW |
1226 | case 'p': |
1227 | case 'P': | |
499ac353 | 1228 | prec = 5; |
c19d1205 | 1229 | break; |
a737bd4d | 1230 | |
c19d1205 ZW |
1231 | default: |
1232 | *sizeP = 0; | |
499ac353 | 1233 | return _("Unrecognized or unsupported floating point constant"); |
c19d1205 | 1234 | } |
b99bd4ef | 1235 | |
c19d1205 ZW |
1236 | t = atof_ieee (input_line_pointer, type, words); |
1237 | if (t) | |
1238 | input_line_pointer = t; | |
499ac353 | 1239 | *sizeP = prec * sizeof (LITTLENUM_TYPE); |
b99bd4ef | 1240 | |
72c03e30 BW |
1241 | if (target_big_endian || prec == 1) |
1242 | for (i = 0; i < prec; i++) | |
1243 | { | |
1244 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
1245 | litP += sizeof (LITTLENUM_TYPE); | |
1246 | } | |
1247 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
1248 | for (i = prec - 1; i >= 0; i--) | |
1249 | { | |
1250 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
1251 | litP += sizeof (LITTLENUM_TYPE); | |
1252 | } | |
c19d1205 | 1253 | else |
72c03e30 BW |
1254 | /* For a 4 byte float the order of elements in `words' is 1 0. |
1255 | For an 8 byte float the order is 1 0 3 2. */ | |
1256 | for (i = 0; i < prec; i += 2) | |
1257 | { | |
1258 | md_number_to_chars (litP, (valueT) words[i + 1], | |
1259 | sizeof (LITTLENUM_TYPE)); | |
1260 | md_number_to_chars (litP + sizeof (LITTLENUM_TYPE), | |
1261 | (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
1262 | litP += 2 * sizeof (LITTLENUM_TYPE); | |
1263 | } | |
b99bd4ef | 1264 | |
499ac353 | 1265 | return NULL; |
c19d1205 | 1266 | } |
b99bd4ef | 1267 | |
c19d1205 ZW |
1268 | /* We handle all bad expressions here, so that we can report the faulty |
1269 | instruction in the error message. */ | |
0198d5e6 | 1270 | |
c19d1205 | 1271 | void |
91d6fa6a | 1272 | md_operand (expressionS * exp) |
c19d1205 ZW |
1273 | { |
1274 | if (in_my_get_expression) | |
91d6fa6a | 1275 | exp->X_op = O_illegal; |
b99bd4ef NC |
1276 | } |
1277 | ||
c19d1205 | 1278 | /* Immediate values. */ |
b99bd4ef | 1279 | |
0198d5e6 | 1280 | #ifdef OBJ_ELF |
c19d1205 ZW |
1281 | /* Generic immediate-value read function for use in directives. |
1282 | Accepts anything that 'expression' can fold to a constant. | |
1283 | *val receives the number. */ | |
0198d5e6 | 1284 | |
c19d1205 ZW |
1285 | static int |
1286 | immediate_for_directive (int *val) | |
b99bd4ef | 1287 | { |
c19d1205 ZW |
1288 | expressionS exp; |
1289 | exp.X_op = O_illegal; | |
b99bd4ef | 1290 | |
c19d1205 ZW |
1291 | if (is_immediate_prefix (*input_line_pointer)) |
1292 | { | |
1293 | input_line_pointer++; | |
1294 | expression (&exp); | |
1295 | } | |
b99bd4ef | 1296 | |
c19d1205 ZW |
1297 | if (exp.X_op != O_constant) |
1298 | { | |
1299 | as_bad (_("expected #constant")); | |
1300 | ignore_rest_of_line (); | |
1301 | return FAIL; | |
1302 | } | |
1303 | *val = exp.X_add_number; | |
1304 | return SUCCESS; | |
b99bd4ef | 1305 | } |
c19d1205 | 1306 | #endif |
b99bd4ef | 1307 | |
c19d1205 | 1308 | /* Register parsing. */ |
b99bd4ef | 1309 | |
c19d1205 ZW |
1310 | /* Generic register parser. CCP points to what should be the |
1311 | beginning of a register name. If it is indeed a valid register | |
1312 | name, advance CCP over it and return the reg_entry structure; | |
1313 | otherwise return NULL. Does not issue diagnostics. */ | |
1314 | ||
1315 | static struct reg_entry * | |
1316 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 1317 | { |
c19d1205 ZW |
1318 | char *start = *ccp; |
1319 | char *p; | |
1320 | struct reg_entry *reg; | |
b99bd4ef | 1321 | |
477330fc RM |
1322 | skip_whitespace (start); |
1323 | ||
c19d1205 ZW |
1324 | #ifdef REGISTER_PREFIX |
1325 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 1326 | return NULL; |
c19d1205 ZW |
1327 | start++; |
1328 | #endif | |
1329 | #ifdef OPTIONAL_REGISTER_PREFIX | |
1330 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
1331 | start++; | |
1332 | #endif | |
b99bd4ef | 1333 | |
c19d1205 ZW |
1334 | p = start; |
1335 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
1336 | return NULL; | |
b99bd4ef | 1337 | |
c19d1205 ZW |
1338 | do |
1339 | p++; | |
1340 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
1341 | ||
1342 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
1343 | ||
1344 | if (!reg) | |
1345 | return NULL; | |
1346 | ||
1347 | *ccp = p; | |
1348 | return reg; | |
b99bd4ef NC |
1349 | } |
1350 | ||
1351 | static int | |
dcbf9037 | 1352 | arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg, |
477330fc | 1353 | enum arm_reg_type type) |
b99bd4ef | 1354 | { |
c19d1205 ZW |
1355 | /* Alternative syntaxes are accepted for a few register classes. */ |
1356 | switch (type) | |
1357 | { | |
1358 | case REG_TYPE_MVF: | |
1359 | case REG_TYPE_MVD: | |
1360 | case REG_TYPE_MVFX: | |
1361 | case REG_TYPE_MVDX: | |
1362 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 1363 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
1364 | return reg->number; |
1365 | break; | |
69b97547 | 1366 | |
c19d1205 ZW |
1367 | case REG_TYPE_CP: |
1368 | /* For backward compatibility, a bare number is valid here. */ | |
1369 | { | |
1370 | unsigned long processor = strtoul (start, ccp, 10); | |
1371 | if (*ccp != start && processor <= 15) | |
1372 | return processor; | |
1373 | } | |
1a0670f3 | 1374 | /* Fall through. */ |
6057a28f | 1375 | |
c19d1205 ZW |
1376 | case REG_TYPE_MMXWC: |
1377 | /* WC includes WCG. ??? I'm not sure this is true for all | |
1378 | instructions that take WC registers. */ | |
79134647 | 1379 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 1380 | return reg->number; |
6057a28f | 1381 | break; |
c19d1205 | 1382 | |
6057a28f | 1383 | default: |
c19d1205 | 1384 | break; |
6057a28f NC |
1385 | } |
1386 | ||
dcbf9037 JB |
1387 | return FAIL; |
1388 | } | |
1389 | ||
1390 | /* As arm_reg_parse_multi, but the register must be of type TYPE, and the | |
1391 | return value is the register number or FAIL. */ | |
1392 | ||
1393 | static int | |
1394 | arm_reg_parse (char **ccp, enum arm_reg_type type) | |
1395 | { | |
1396 | char *start = *ccp; | |
1397 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
1398 | int ret; | |
1399 | ||
1400 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1401 | if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX)) | |
1402 | return FAIL; | |
1403 | ||
1404 | if (reg && reg->type == type) | |
1405 | return reg->number; | |
1406 | ||
1407 | if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL) | |
1408 | return ret; | |
1409 | ||
c19d1205 ZW |
1410 | *ccp = start; |
1411 | return FAIL; | |
1412 | } | |
69b97547 | 1413 | |
dcbf9037 JB |
1414 | /* Parse a Neon type specifier. *STR should point at the leading '.' |
1415 | character. Does no verification at this stage that the type fits the opcode | |
1416 | properly. E.g., | |
1417 | ||
1418 | .i32.i32.s16 | |
1419 | .s32.f32 | |
1420 | .u16 | |
1421 | ||
1422 | Can all be legally parsed by this function. | |
1423 | ||
1424 | Fills in neon_type struct pointer with parsed information, and updates STR | |
1425 | to point after the parsed type specifier. Returns SUCCESS if this was a legal | |
1426 | type, FAIL if not. */ | |
1427 | ||
1428 | static int | |
1429 | parse_neon_type (struct neon_type *type, char **str) | |
1430 | { | |
1431 | char *ptr = *str; | |
1432 | ||
1433 | if (type) | |
1434 | type->elems = 0; | |
1435 | ||
1436 | while (type->elems < NEON_MAX_TYPE_ELS) | |
1437 | { | |
1438 | enum neon_el_type thistype = NT_untyped; | |
1439 | unsigned thissize = -1u; | |
1440 | ||
1441 | if (*ptr != '.') | |
1442 | break; | |
1443 | ||
1444 | ptr++; | |
1445 | ||
1446 | /* Just a size without an explicit type. */ | |
1447 | if (ISDIGIT (*ptr)) | |
1448 | goto parsesize; | |
1449 | ||
1450 | switch (TOLOWER (*ptr)) | |
1451 | { | |
1452 | case 'i': thistype = NT_integer; break; | |
1453 | case 'f': thistype = NT_float; break; | |
1454 | case 'p': thistype = NT_poly; break; | |
1455 | case 's': thistype = NT_signed; break; | |
1456 | case 'u': thistype = NT_unsigned; break; | |
477330fc RM |
1457 | case 'd': |
1458 | thistype = NT_float; | |
1459 | thissize = 64; | |
1460 | ptr++; | |
1461 | goto done; | |
dcbf9037 JB |
1462 | default: |
1463 | as_bad (_("unexpected character `%c' in type specifier"), *ptr); | |
1464 | return FAIL; | |
1465 | } | |
1466 | ||
1467 | ptr++; | |
1468 | ||
1469 | /* .f is an abbreviation for .f32. */ | |
1470 | if (thistype == NT_float && !ISDIGIT (*ptr)) | |
1471 | thissize = 32; | |
1472 | else | |
1473 | { | |
1474 | parsesize: | |
1475 | thissize = strtoul (ptr, &ptr, 10); | |
1476 | ||
1477 | if (thissize != 8 && thissize != 16 && thissize != 32 | |
477330fc RM |
1478 | && thissize != 64) |
1479 | { | |
1480 | as_bad (_("bad size %d in type specifier"), thissize); | |
dcbf9037 JB |
1481 | return FAIL; |
1482 | } | |
1483 | } | |
1484 | ||
037e8744 | 1485 | done: |
dcbf9037 | 1486 | if (type) |
477330fc RM |
1487 | { |
1488 | type->el[type->elems].type = thistype; | |
dcbf9037 JB |
1489 | type->el[type->elems].size = thissize; |
1490 | type->elems++; | |
1491 | } | |
1492 | } | |
1493 | ||
1494 | /* Empty/missing type is not a successful parse. */ | |
1495 | if (type->elems == 0) | |
1496 | return FAIL; | |
1497 | ||
1498 | *str = ptr; | |
1499 | ||
1500 | return SUCCESS; | |
1501 | } | |
1502 | ||
1503 | /* Errors may be set multiple times during parsing or bit encoding | |
1504 | (particularly in the Neon bits), but usually the earliest error which is set | |
1505 | will be the most meaningful. Avoid overwriting it with later (cascading) | |
1506 | errors by calling this function. */ | |
1507 | ||
1508 | static void | |
1509 | first_error (const char *err) | |
1510 | { | |
1511 | if (!inst.error) | |
1512 | inst.error = err; | |
1513 | } | |
1514 | ||
1515 | /* Parse a single type, e.g. ".s32", leading period included. */ | |
1516 | static int | |
1517 | parse_neon_operand_type (struct neon_type_el *vectype, char **ccp) | |
1518 | { | |
1519 | char *str = *ccp; | |
1520 | struct neon_type optype; | |
1521 | ||
1522 | if (*str == '.') | |
1523 | { | |
1524 | if (parse_neon_type (&optype, &str) == SUCCESS) | |
477330fc RM |
1525 | { |
1526 | if (optype.elems == 1) | |
1527 | *vectype = optype.el[0]; | |
1528 | else | |
1529 | { | |
1530 | first_error (_("only one type should be specified for operand")); | |
1531 | return FAIL; | |
1532 | } | |
1533 | } | |
dcbf9037 | 1534 | else |
477330fc RM |
1535 | { |
1536 | first_error (_("vector type expected")); | |
1537 | return FAIL; | |
1538 | } | |
dcbf9037 JB |
1539 | } |
1540 | else | |
1541 | return FAIL; | |
5f4273c7 | 1542 | |
dcbf9037 | 1543 | *ccp = str; |
5f4273c7 | 1544 | |
dcbf9037 JB |
1545 | return SUCCESS; |
1546 | } | |
1547 | ||
1548 | /* Special meanings for indices (which have a range of 0-7), which will fit into | |
1549 | a 4-bit integer. */ | |
1550 | ||
1551 | #define NEON_ALL_LANES 15 | |
1552 | #define NEON_INTERLEAVE_LANES 14 | |
1553 | ||
5ee91343 AV |
1554 | /* Record a use of the given feature. */ |
1555 | static void | |
1556 | record_feature_use (const arm_feature_set *feature) | |
1557 | { | |
1558 | if (thumb_mode) | |
1559 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature); | |
1560 | else | |
1561 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature); | |
1562 | } | |
1563 | ||
1564 | /* If the given feature available in the selected CPU, mark it as used. | |
1565 | Returns TRUE iff feature is available. */ | |
1566 | static bfd_boolean | |
1567 | mark_feature_used (const arm_feature_set *feature) | |
1568 | { | |
886e1c73 AV |
1569 | |
1570 | /* Do not support the use of MVE only instructions when in auto-detection or | |
1571 | -march=all. */ | |
1572 | if (((feature == &mve_ext) || (feature == &mve_fp_ext)) | |
1573 | && ARM_CPU_IS_ANY (cpu_variant)) | |
1574 | { | |
1575 | first_error (BAD_MVE_AUTO); | |
1576 | return FALSE; | |
1577 | } | |
5ee91343 AV |
1578 | /* Ensure the option is valid on the current architecture. */ |
1579 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) | |
1580 | return FALSE; | |
1581 | ||
1582 | /* Add the appropriate architecture feature for the barrier option used. | |
1583 | */ | |
1584 | record_feature_use (feature); | |
1585 | ||
1586 | return TRUE; | |
1587 | } | |
1588 | ||
dcbf9037 JB |
1589 | /* Parse either a register or a scalar, with an optional type. Return the |
1590 | register number, and optionally fill in the actual type of the register | |
1591 | when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and | |
1592 | type/index information in *TYPEINFO. */ | |
1593 | ||
1594 | static int | |
1595 | parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type, | |
477330fc RM |
1596 | enum arm_reg_type *rtype, |
1597 | struct neon_typed_alias *typeinfo) | |
dcbf9037 JB |
1598 | { |
1599 | char *str = *ccp; | |
1600 | struct reg_entry *reg = arm_reg_parse_multi (&str); | |
1601 | struct neon_typed_alias atype; | |
1602 | struct neon_type_el parsetype; | |
1603 | ||
1604 | atype.defined = 0; | |
1605 | atype.index = -1; | |
1606 | atype.eltype.type = NT_invtype; | |
1607 | atype.eltype.size = -1; | |
1608 | ||
1609 | /* Try alternate syntax for some types of register. Note these are mutually | |
1610 | exclusive with the Neon syntax extensions. */ | |
1611 | if (reg == NULL) | |
1612 | { | |
1613 | int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type); | |
1614 | if (altreg != FAIL) | |
477330fc | 1615 | *ccp = str; |
dcbf9037 | 1616 | if (typeinfo) |
477330fc | 1617 | *typeinfo = atype; |
dcbf9037 JB |
1618 | return altreg; |
1619 | } | |
1620 | ||
037e8744 JB |
1621 | /* Undo polymorphism when a set of register types may be accepted. */ |
1622 | if ((type == REG_TYPE_NDQ | |
1623 | && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD)) | |
1624 | || (type == REG_TYPE_VFSD | |
477330fc | 1625 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) |
037e8744 | 1626 | || (type == REG_TYPE_NSDQ |
477330fc RM |
1627 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD |
1628 | || reg->type == REG_TYPE_NQ)) | |
dec41383 JW |
1629 | || (type == REG_TYPE_NSD |
1630 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) | |
f512f76f NC |
1631 | || (type == REG_TYPE_MMXWC |
1632 | && (reg->type == REG_TYPE_MMXWCG))) | |
21d799b5 | 1633 | type = (enum arm_reg_type) reg->type; |
dcbf9037 | 1634 | |
5ee91343 AV |
1635 | if (type == REG_TYPE_MQ) |
1636 | { | |
1637 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
1638 | return FAIL; | |
1639 | ||
1640 | if (!reg || reg->type != REG_TYPE_NQ) | |
1641 | return FAIL; | |
1642 | ||
1643 | if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32)) | |
1644 | { | |
1645 | first_error (_("expected MVE register [q0..q7]")); | |
1646 | return FAIL; | |
1647 | } | |
1648 | type = REG_TYPE_NQ; | |
1649 | } | |
1650 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) | |
1651 | && (type == REG_TYPE_NQ)) | |
1652 | return FAIL; | |
1653 | ||
1654 | ||
dcbf9037 JB |
1655 | if (type != reg->type) |
1656 | return FAIL; | |
1657 | ||
1658 | if (reg->neon) | |
1659 | atype = *reg->neon; | |
5f4273c7 | 1660 | |
dcbf9037 JB |
1661 | if (parse_neon_operand_type (&parsetype, &str) == SUCCESS) |
1662 | { | |
1663 | if ((atype.defined & NTA_HASTYPE) != 0) | |
477330fc RM |
1664 | { |
1665 | first_error (_("can't redefine type for operand")); | |
1666 | return FAIL; | |
1667 | } | |
dcbf9037 JB |
1668 | atype.defined |= NTA_HASTYPE; |
1669 | atype.eltype = parsetype; | |
1670 | } | |
5f4273c7 | 1671 | |
dcbf9037 JB |
1672 | if (skip_past_char (&str, '[') == SUCCESS) |
1673 | { | |
dec41383 JW |
1674 | if (type != REG_TYPE_VFD |
1675 | && !(type == REG_TYPE_VFS | |
57785aa2 AV |
1676 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2)) |
1677 | && !(type == REG_TYPE_NQ | |
1678 | && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))) | |
477330fc | 1679 | { |
57785aa2 AV |
1680 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) |
1681 | first_error (_("only D and Q registers may be indexed")); | |
1682 | else | |
1683 | first_error (_("only D registers may be indexed")); | |
477330fc RM |
1684 | return FAIL; |
1685 | } | |
5f4273c7 | 1686 | |
dcbf9037 | 1687 | if ((atype.defined & NTA_HASINDEX) != 0) |
477330fc RM |
1688 | { |
1689 | first_error (_("can't change index for operand")); | |
1690 | return FAIL; | |
1691 | } | |
dcbf9037 JB |
1692 | |
1693 | atype.defined |= NTA_HASINDEX; | |
1694 | ||
1695 | if (skip_past_char (&str, ']') == SUCCESS) | |
477330fc | 1696 | atype.index = NEON_ALL_LANES; |
dcbf9037 | 1697 | else |
477330fc RM |
1698 | { |
1699 | expressionS exp; | |
dcbf9037 | 1700 | |
477330fc | 1701 | my_get_expression (&exp, &str, GE_NO_PREFIX); |
dcbf9037 | 1702 | |
477330fc RM |
1703 | if (exp.X_op != O_constant) |
1704 | { | |
1705 | first_error (_("constant expression required")); | |
1706 | return FAIL; | |
1707 | } | |
dcbf9037 | 1708 | |
477330fc RM |
1709 | if (skip_past_char (&str, ']') == FAIL) |
1710 | return FAIL; | |
dcbf9037 | 1711 | |
477330fc RM |
1712 | atype.index = exp.X_add_number; |
1713 | } | |
dcbf9037 | 1714 | } |
5f4273c7 | 1715 | |
dcbf9037 JB |
1716 | if (typeinfo) |
1717 | *typeinfo = atype; | |
5f4273c7 | 1718 | |
dcbf9037 JB |
1719 | if (rtype) |
1720 | *rtype = type; | |
5f4273c7 | 1721 | |
dcbf9037 | 1722 | *ccp = str; |
5f4273c7 | 1723 | |
dcbf9037 JB |
1724 | return reg->number; |
1725 | } | |
1726 | ||
efd6b359 | 1727 | /* Like arm_reg_parse, but also allow the following extra features: |
dcbf9037 JB |
1728 | - If RTYPE is non-zero, return the (possibly restricted) type of the |
1729 | register (e.g. Neon double or quad reg when either has been requested). | |
1730 | - If this is a Neon vector type with additional type information, fill | |
1731 | in the struct pointed to by VECTYPE (if non-NULL). | |
5f4273c7 | 1732 | This function will fault on encountering a scalar. */ |
dcbf9037 JB |
1733 | |
1734 | static int | |
1735 | arm_typed_reg_parse (char **ccp, enum arm_reg_type type, | |
477330fc | 1736 | enum arm_reg_type *rtype, struct neon_type_el *vectype) |
dcbf9037 JB |
1737 | { |
1738 | struct neon_typed_alias atype; | |
1739 | char *str = *ccp; | |
1740 | int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype); | |
1741 | ||
1742 | if (reg == FAIL) | |
1743 | return FAIL; | |
1744 | ||
0855e32b NS |
1745 | /* Do not allow regname(... to parse as a register. */ |
1746 | if (*str == '(') | |
1747 | return FAIL; | |
1748 | ||
dcbf9037 JB |
1749 | /* Do not allow a scalar (reg+index) to parse as a register. */ |
1750 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1751 | { | |
1752 | first_error (_("register operand expected, but got scalar")); | |
1753 | return FAIL; | |
1754 | } | |
1755 | ||
1756 | if (vectype) | |
1757 | *vectype = atype.eltype; | |
1758 | ||
1759 | *ccp = str; | |
1760 | ||
1761 | return reg; | |
1762 | } | |
1763 | ||
1764 | #define NEON_SCALAR_REG(X) ((X) >> 4) | |
1765 | #define NEON_SCALAR_INDEX(X) ((X) & 15) | |
1766 | ||
5287ad62 JB |
1767 | /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't |
1768 | have enough information to be able to do a good job bounds-checking. So, we | |
1769 | just do easy checks here, and do further checks later. */ | |
1770 | ||
1771 | static int | |
57785aa2 AV |
1772 | parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum |
1773 | arm_reg_type reg_type) | |
5287ad62 | 1774 | { |
dcbf9037 | 1775 | int reg; |
5287ad62 | 1776 | char *str = *ccp; |
dcbf9037 | 1777 | struct neon_typed_alias atype; |
57785aa2 | 1778 | unsigned reg_size; |
5f4273c7 | 1779 | |
dec41383 | 1780 | reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype); |
5f4273c7 | 1781 | |
57785aa2 AV |
1782 | switch (reg_type) |
1783 | { | |
1784 | case REG_TYPE_VFS: | |
1785 | reg_size = 32; | |
1786 | break; | |
1787 | case REG_TYPE_VFD: | |
1788 | reg_size = 64; | |
1789 | break; | |
1790 | case REG_TYPE_MQ: | |
1791 | reg_size = 128; | |
1792 | break; | |
1793 | default: | |
1794 | gas_assert (0); | |
1795 | return FAIL; | |
1796 | } | |
1797 | ||
dcbf9037 | 1798 | if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0) |
5287ad62 | 1799 | return FAIL; |
5f4273c7 | 1800 | |
57785aa2 | 1801 | if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES) |
5287ad62 | 1802 | { |
dcbf9037 | 1803 | first_error (_("scalar must have an index")); |
5287ad62 JB |
1804 | return FAIL; |
1805 | } | |
57785aa2 | 1806 | else if (atype.index >= reg_size / elsize) |
5287ad62 | 1807 | { |
dcbf9037 | 1808 | first_error (_("scalar index out of range")); |
5287ad62 JB |
1809 | return FAIL; |
1810 | } | |
5f4273c7 | 1811 | |
dcbf9037 JB |
1812 | if (type) |
1813 | *type = atype.eltype; | |
5f4273c7 | 1814 | |
5287ad62 | 1815 | *ccp = str; |
5f4273c7 | 1816 | |
dcbf9037 | 1817 | return reg * 16 + atype.index; |
5287ad62 JB |
1818 | } |
1819 | ||
4b5a202f AV |
1820 | /* Types of registers in a list. */ |
1821 | ||
1822 | enum reg_list_els | |
1823 | { | |
1824 | REGLIST_RN, | |
1825 | REGLIST_CLRM, | |
1826 | REGLIST_VFP_S, | |
efd6b359 | 1827 | REGLIST_VFP_S_VPR, |
4b5a202f | 1828 | REGLIST_VFP_D, |
efd6b359 | 1829 | REGLIST_VFP_D_VPR, |
4b5a202f AV |
1830 | REGLIST_NEON_D |
1831 | }; | |
1832 | ||
c19d1205 | 1833 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
e07e6e58 | 1834 | |
c19d1205 | 1835 | static long |
4b5a202f | 1836 | parse_reg_list (char ** strp, enum reg_list_els etype) |
c19d1205 | 1837 | { |
4b5a202f AV |
1838 | char *str = *strp; |
1839 | long range = 0; | |
1840 | int another_range; | |
1841 | ||
1842 | gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM); | |
a737bd4d | 1843 | |
c19d1205 ZW |
1844 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
1845 | do | |
6057a28f | 1846 | { |
477330fc RM |
1847 | skip_whitespace (str); |
1848 | ||
c19d1205 | 1849 | another_range = 0; |
a737bd4d | 1850 | |
c19d1205 ZW |
1851 | if (*str == '{') |
1852 | { | |
1853 | int in_range = 0; | |
1854 | int cur_reg = -1; | |
a737bd4d | 1855 | |
c19d1205 ZW |
1856 | str++; |
1857 | do | |
1858 | { | |
1859 | int reg; | |
4b5a202f AV |
1860 | const char apsr_str[] = "apsr"; |
1861 | int apsr_str_len = strlen (apsr_str); | |
6057a28f | 1862 | |
4b5a202f AV |
1863 | reg = arm_reg_parse (&str, REGLIST_RN); |
1864 | if (etype == REGLIST_CLRM) | |
c19d1205 | 1865 | { |
4b5a202f AV |
1866 | if (reg == REG_SP || reg == REG_PC) |
1867 | reg = FAIL; | |
1868 | else if (reg == FAIL | |
1869 | && !strncasecmp (str, apsr_str, apsr_str_len) | |
1870 | && !ISALPHA (*(str + apsr_str_len))) | |
1871 | { | |
1872 | reg = 15; | |
1873 | str += apsr_str_len; | |
1874 | } | |
1875 | ||
1876 | if (reg == FAIL) | |
1877 | { | |
1878 | first_error (_("r0-r12, lr or APSR expected")); | |
1879 | return FAIL; | |
1880 | } | |
1881 | } | |
1882 | else /* etype == REGLIST_RN. */ | |
1883 | { | |
1884 | if (reg == FAIL) | |
1885 | { | |
1886 | first_error (_(reg_expected_msgs[REGLIST_RN])); | |
1887 | return FAIL; | |
1888 | } | |
c19d1205 | 1889 | } |
a737bd4d | 1890 | |
c19d1205 ZW |
1891 | if (in_range) |
1892 | { | |
1893 | int i; | |
a737bd4d | 1894 | |
c19d1205 ZW |
1895 | if (reg <= cur_reg) |
1896 | { | |
dcbf9037 | 1897 | first_error (_("bad range in register list")); |
c19d1205 ZW |
1898 | return FAIL; |
1899 | } | |
40a18ebd | 1900 | |
c19d1205 ZW |
1901 | for (i = cur_reg + 1; i < reg; i++) |
1902 | { | |
1903 | if (range & (1 << i)) | |
1904 | as_tsktsk | |
1905 | (_("Warning: duplicated register (r%d) in register list"), | |
1906 | i); | |
1907 | else | |
1908 | range |= 1 << i; | |
1909 | } | |
1910 | in_range = 0; | |
1911 | } | |
a737bd4d | 1912 | |
c19d1205 ZW |
1913 | if (range & (1 << reg)) |
1914 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1915 | reg); | |
1916 | else if (reg <= cur_reg) | |
1917 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1918 | |
c19d1205 ZW |
1919 | range |= 1 << reg; |
1920 | cur_reg = reg; | |
1921 | } | |
1922 | while (skip_past_comma (&str) != FAIL | |
1923 | || (in_range = 1, *str++ == '-')); | |
1924 | str--; | |
a737bd4d | 1925 | |
d996d970 | 1926 | if (skip_past_char (&str, '}') == FAIL) |
c19d1205 | 1927 | { |
dcbf9037 | 1928 | first_error (_("missing `}'")); |
c19d1205 ZW |
1929 | return FAIL; |
1930 | } | |
1931 | } | |
4b5a202f | 1932 | else if (etype == REGLIST_RN) |
c19d1205 | 1933 | { |
91d6fa6a | 1934 | expressionS exp; |
40a18ebd | 1935 | |
91d6fa6a | 1936 | if (my_get_expression (&exp, &str, GE_NO_PREFIX)) |
c19d1205 | 1937 | return FAIL; |
40a18ebd | 1938 | |
91d6fa6a | 1939 | if (exp.X_op == O_constant) |
c19d1205 | 1940 | { |
91d6fa6a NC |
1941 | if (exp.X_add_number |
1942 | != (exp.X_add_number & 0x0000ffff)) | |
c19d1205 ZW |
1943 | { |
1944 | inst.error = _("invalid register mask"); | |
1945 | return FAIL; | |
1946 | } | |
a737bd4d | 1947 | |
91d6fa6a | 1948 | if ((range & exp.X_add_number) != 0) |
c19d1205 | 1949 | { |
91d6fa6a | 1950 | int regno = range & exp.X_add_number; |
a737bd4d | 1951 | |
c19d1205 ZW |
1952 | regno &= -regno; |
1953 | regno = (1 << regno) - 1; | |
1954 | as_tsktsk | |
1955 | (_("Warning: duplicated register (r%d) in register list"), | |
1956 | regno); | |
1957 | } | |
a737bd4d | 1958 | |
91d6fa6a | 1959 | range |= exp.X_add_number; |
c19d1205 ZW |
1960 | } |
1961 | else | |
1962 | { | |
e2b0ab59 | 1963 | if (inst.relocs[0].type != 0) |
c19d1205 ZW |
1964 | { |
1965 | inst.error = _("expression too complex"); | |
1966 | return FAIL; | |
1967 | } | |
a737bd4d | 1968 | |
e2b0ab59 AV |
1969 | memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS)); |
1970 | inst.relocs[0].type = BFD_RELOC_ARM_MULTI; | |
1971 | inst.relocs[0].pc_rel = 0; | |
c19d1205 ZW |
1972 | } |
1973 | } | |
a737bd4d | 1974 | |
c19d1205 ZW |
1975 | if (*str == '|' || *str == '+') |
1976 | { | |
1977 | str++; | |
1978 | another_range = 1; | |
1979 | } | |
a737bd4d | 1980 | } |
c19d1205 | 1981 | while (another_range); |
a737bd4d | 1982 | |
c19d1205 ZW |
1983 | *strp = str; |
1984 | return range; | |
a737bd4d NC |
1985 | } |
1986 | ||
c19d1205 ZW |
1987 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1988 | Otherwise return the number of registers, and set PBASE to the first | |
5287ad62 JB |
1989 | register. Parses registers of type ETYPE. |
1990 | If REGLIST_NEON_D is used, several syntax enhancements are enabled: | |
1991 | - Q registers can be used to specify pairs of D registers | |
1992 | - { } can be omitted from around a singleton register list | |
477330fc RM |
1993 | FIXME: This is not implemented, as it would require backtracking in |
1994 | some cases, e.g.: | |
1995 | vtbl.8 d3,d4,d5 | |
1996 | This could be done (the meaning isn't really ambiguous), but doesn't | |
1997 | fit in well with the current parsing framework. | |
dcbf9037 JB |
1998 | - 32 D registers may be used (also true for VFPv3). |
1999 | FIXME: Types are ignored in these register lists, which is probably a | |
2000 | bug. */ | |
6057a28f | 2001 | |
c19d1205 | 2002 | static int |
efd6b359 AV |
2003 | parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype, |
2004 | bfd_boolean *partial_match) | |
6057a28f | 2005 | { |
037e8744 | 2006 | char *str = *ccp; |
c19d1205 ZW |
2007 | int base_reg; |
2008 | int new_base; | |
21d799b5 | 2009 | enum arm_reg_type regtype = (enum arm_reg_type) 0; |
5287ad62 | 2010 | int max_regs = 0; |
c19d1205 ZW |
2011 | int count = 0; |
2012 | int warned = 0; | |
2013 | unsigned long mask = 0; | |
a737bd4d | 2014 | int i; |
efd6b359 AV |
2015 | bfd_boolean vpr_seen = FALSE; |
2016 | bfd_boolean expect_vpr = | |
2017 | (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR); | |
6057a28f | 2018 | |
477330fc | 2019 | if (skip_past_char (&str, '{') == FAIL) |
5287ad62 JB |
2020 | { |
2021 | inst.error = _("expecting {"); | |
2022 | return FAIL; | |
2023 | } | |
6057a28f | 2024 | |
5287ad62 | 2025 | switch (etype) |
c19d1205 | 2026 | { |
5287ad62 | 2027 | case REGLIST_VFP_S: |
efd6b359 | 2028 | case REGLIST_VFP_S_VPR: |
c19d1205 ZW |
2029 | regtype = REG_TYPE_VFS; |
2030 | max_regs = 32; | |
5287ad62 | 2031 | break; |
5f4273c7 | 2032 | |
5287ad62 | 2033 | case REGLIST_VFP_D: |
efd6b359 | 2034 | case REGLIST_VFP_D_VPR: |
5287ad62 | 2035 | regtype = REG_TYPE_VFD; |
b7fc2769 | 2036 | break; |
5f4273c7 | 2037 | |
b7fc2769 JB |
2038 | case REGLIST_NEON_D: |
2039 | regtype = REG_TYPE_NDQ; | |
2040 | break; | |
4b5a202f AV |
2041 | |
2042 | default: | |
2043 | gas_assert (0); | |
b7fc2769 JB |
2044 | } |
2045 | ||
efd6b359 | 2046 | if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR) |
b7fc2769 | 2047 | { |
b1cc4aeb PB |
2048 | /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */ |
2049 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) | |
477330fc RM |
2050 | { |
2051 | max_regs = 32; | |
2052 | if (thumb_mode) | |
2053 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
2054 | fpu_vfp_ext_d32); | |
2055 | else | |
2056 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
2057 | fpu_vfp_ext_d32); | |
2058 | } | |
5287ad62 | 2059 | else |
477330fc | 2060 | max_regs = 16; |
c19d1205 | 2061 | } |
6057a28f | 2062 | |
c19d1205 | 2063 | base_reg = max_regs; |
efd6b359 | 2064 | *partial_match = FALSE; |
a737bd4d | 2065 | |
c19d1205 ZW |
2066 | do |
2067 | { | |
5287ad62 | 2068 | int setmask = 1, addregs = 1; |
efd6b359 AV |
2069 | const char vpr_str[] = "vpr"; |
2070 | int vpr_str_len = strlen (vpr_str); | |
dcbf9037 | 2071 | |
037e8744 | 2072 | new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL); |
dcbf9037 | 2073 | |
efd6b359 AV |
2074 | if (expect_vpr) |
2075 | { | |
2076 | if (new_base == FAIL | |
2077 | && !strncasecmp (str, vpr_str, vpr_str_len) | |
2078 | && !ISALPHA (*(str + vpr_str_len)) | |
2079 | && !vpr_seen) | |
2080 | { | |
2081 | vpr_seen = TRUE; | |
2082 | str += vpr_str_len; | |
2083 | if (count == 0) | |
2084 | base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */ | |
2085 | } | |
2086 | else if (vpr_seen) | |
2087 | { | |
2088 | first_error (_("VPR expected last")); | |
2089 | return FAIL; | |
2090 | } | |
2091 | else if (new_base == FAIL) | |
2092 | { | |
2093 | if (regtype == REG_TYPE_VFS) | |
2094 | first_error (_("VFP single precision register or VPR " | |
2095 | "expected")); | |
2096 | else /* regtype == REG_TYPE_VFD. */ | |
2097 | first_error (_("VFP/Neon double precision register or VPR " | |
2098 | "expected")); | |
2099 | return FAIL; | |
2100 | } | |
2101 | } | |
2102 | else if (new_base == FAIL) | |
a737bd4d | 2103 | { |
dcbf9037 | 2104 | first_error (_(reg_expected_msgs[regtype])); |
c19d1205 ZW |
2105 | return FAIL; |
2106 | } | |
5f4273c7 | 2107 | |
efd6b359 AV |
2108 | *partial_match = TRUE; |
2109 | if (vpr_seen) | |
2110 | continue; | |
2111 | ||
b7fc2769 | 2112 | if (new_base >= max_regs) |
477330fc RM |
2113 | { |
2114 | first_error (_("register out of range in list")); | |
2115 | return FAIL; | |
2116 | } | |
5f4273c7 | 2117 | |
5287ad62 JB |
2118 | /* Note: a value of 2 * n is returned for the register Q<n>. */ |
2119 | if (regtype == REG_TYPE_NQ) | |
477330fc RM |
2120 | { |
2121 | setmask = 3; | |
2122 | addregs = 2; | |
2123 | } | |
5287ad62 | 2124 | |
c19d1205 ZW |
2125 | if (new_base < base_reg) |
2126 | base_reg = new_base; | |
a737bd4d | 2127 | |
5287ad62 | 2128 | if (mask & (setmask << new_base)) |
c19d1205 | 2129 | { |
dcbf9037 | 2130 | first_error (_("invalid register list")); |
c19d1205 | 2131 | return FAIL; |
a737bd4d | 2132 | } |
a737bd4d | 2133 | |
efd6b359 | 2134 | if ((mask >> new_base) != 0 && ! warned && !vpr_seen) |
c19d1205 ZW |
2135 | { |
2136 | as_tsktsk (_("register list not in ascending order")); | |
2137 | warned = 1; | |
2138 | } | |
0bbf2aa4 | 2139 | |
5287ad62 JB |
2140 | mask |= setmask << new_base; |
2141 | count += addregs; | |
0bbf2aa4 | 2142 | |
037e8744 | 2143 | if (*str == '-') /* We have the start of a range expression */ |
c19d1205 ZW |
2144 | { |
2145 | int high_range; | |
0bbf2aa4 | 2146 | |
037e8744 | 2147 | str++; |
0bbf2aa4 | 2148 | |
037e8744 | 2149 | if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL)) |
477330fc | 2150 | == FAIL) |
c19d1205 ZW |
2151 | { |
2152 | inst.error = gettext (reg_expected_msgs[regtype]); | |
2153 | return FAIL; | |
2154 | } | |
0bbf2aa4 | 2155 | |
477330fc RM |
2156 | if (high_range >= max_regs) |
2157 | { | |
2158 | first_error (_("register out of range in list")); | |
2159 | return FAIL; | |
2160 | } | |
b7fc2769 | 2161 | |
477330fc RM |
2162 | if (regtype == REG_TYPE_NQ) |
2163 | high_range = high_range + 1; | |
5287ad62 | 2164 | |
c19d1205 ZW |
2165 | if (high_range <= new_base) |
2166 | { | |
2167 | inst.error = _("register range not in ascending order"); | |
2168 | return FAIL; | |
2169 | } | |
0bbf2aa4 | 2170 | |
5287ad62 | 2171 | for (new_base += addregs; new_base <= high_range; new_base += addregs) |
0bbf2aa4 | 2172 | { |
5287ad62 | 2173 | if (mask & (setmask << new_base)) |
0bbf2aa4 | 2174 | { |
c19d1205 ZW |
2175 | inst.error = _("invalid register list"); |
2176 | return FAIL; | |
0bbf2aa4 | 2177 | } |
c19d1205 | 2178 | |
5287ad62 JB |
2179 | mask |= setmask << new_base; |
2180 | count += addregs; | |
0bbf2aa4 | 2181 | } |
0bbf2aa4 | 2182 | } |
0bbf2aa4 | 2183 | } |
037e8744 | 2184 | while (skip_past_comma (&str) != FAIL); |
0bbf2aa4 | 2185 | |
037e8744 | 2186 | str++; |
0bbf2aa4 | 2187 | |
c19d1205 | 2188 | /* Sanity check -- should have raised a parse error above. */ |
efd6b359 | 2189 | if ((!vpr_seen && count == 0) || count > max_regs) |
c19d1205 ZW |
2190 | abort (); |
2191 | ||
2192 | *pbase = base_reg; | |
2193 | ||
efd6b359 AV |
2194 | if (expect_vpr && !vpr_seen) |
2195 | { | |
2196 | first_error (_("VPR expected last")); | |
2197 | return FAIL; | |
2198 | } | |
2199 | ||
c19d1205 ZW |
2200 | /* Final test -- the registers must be consecutive. */ |
2201 | mask >>= base_reg; | |
2202 | for (i = 0; i < count; i++) | |
2203 | { | |
2204 | if ((mask & (1u << i)) == 0) | |
2205 | { | |
2206 | inst.error = _("non-contiguous register range"); | |
2207 | return FAIL; | |
2208 | } | |
2209 | } | |
2210 | ||
037e8744 JB |
2211 | *ccp = str; |
2212 | ||
c19d1205 | 2213 | return count; |
b99bd4ef NC |
2214 | } |
2215 | ||
dcbf9037 JB |
2216 | /* True if two alias types are the same. */ |
2217 | ||
c921be7d | 2218 | static bfd_boolean |
dcbf9037 JB |
2219 | neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b) |
2220 | { | |
2221 | if (!a && !b) | |
c921be7d | 2222 | return TRUE; |
5f4273c7 | 2223 | |
dcbf9037 | 2224 | if (!a || !b) |
c921be7d | 2225 | return FALSE; |
dcbf9037 JB |
2226 | |
2227 | if (a->defined != b->defined) | |
c921be7d | 2228 | return FALSE; |
5f4273c7 | 2229 | |
dcbf9037 JB |
2230 | if ((a->defined & NTA_HASTYPE) != 0 |
2231 | && (a->eltype.type != b->eltype.type | |
477330fc | 2232 | || a->eltype.size != b->eltype.size)) |
c921be7d | 2233 | return FALSE; |
dcbf9037 JB |
2234 | |
2235 | if ((a->defined & NTA_HASINDEX) != 0 | |
2236 | && (a->index != b->index)) | |
c921be7d | 2237 | return FALSE; |
5f4273c7 | 2238 | |
c921be7d | 2239 | return TRUE; |
dcbf9037 JB |
2240 | } |
2241 | ||
5287ad62 JB |
2242 | /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions. |
2243 | The base register is put in *PBASE. | |
dcbf9037 | 2244 | The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of |
5287ad62 JB |
2245 | the return value. |
2246 | The register stride (minus one) is put in bit 4 of the return value. | |
dcbf9037 JB |
2247 | Bits [6:5] encode the list length (minus one). |
2248 | The type of the list elements is put in *ELTYPE, if non-NULL. */ | |
5287ad62 | 2249 | |
5287ad62 | 2250 | #define NEON_LANE(X) ((X) & 0xf) |
dcbf9037 | 2251 | #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1) |
5287ad62 JB |
2252 | #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1) |
2253 | ||
2254 | static int | |
dcbf9037 | 2255 | parse_neon_el_struct_list (char **str, unsigned *pbase, |
35c228db | 2256 | int mve, |
477330fc | 2257 | struct neon_type_el *eltype) |
5287ad62 JB |
2258 | { |
2259 | char *ptr = *str; | |
2260 | int base_reg = -1; | |
2261 | int reg_incr = -1; | |
2262 | int count = 0; | |
2263 | int lane = -1; | |
2264 | int leading_brace = 0; | |
2265 | enum arm_reg_type rtype = REG_TYPE_NDQ; | |
35c228db AV |
2266 | const char *const incr_error = mve ? _("register stride must be 1") : |
2267 | _("register stride must be 1 or 2"); | |
20203fb9 | 2268 | const char *const type_error = _("mismatched element/structure types in list"); |
dcbf9037 | 2269 | struct neon_typed_alias firsttype; |
f85d59c3 KT |
2270 | firsttype.defined = 0; |
2271 | firsttype.eltype.type = NT_invtype; | |
2272 | firsttype.eltype.size = -1; | |
2273 | firsttype.index = -1; | |
5f4273c7 | 2274 | |
5287ad62 JB |
2275 | if (skip_past_char (&ptr, '{') == SUCCESS) |
2276 | leading_brace = 1; | |
5f4273c7 | 2277 | |
5287ad62 JB |
2278 | do |
2279 | { | |
dcbf9037 | 2280 | struct neon_typed_alias atype; |
35c228db AV |
2281 | if (mve) |
2282 | rtype = REG_TYPE_MQ; | |
dcbf9037 JB |
2283 | int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype); |
2284 | ||
5287ad62 | 2285 | if (getreg == FAIL) |
477330fc RM |
2286 | { |
2287 | first_error (_(reg_expected_msgs[rtype])); | |
2288 | return FAIL; | |
2289 | } | |
5f4273c7 | 2290 | |
5287ad62 | 2291 | if (base_reg == -1) |
477330fc RM |
2292 | { |
2293 | base_reg = getreg; | |
2294 | if (rtype == REG_TYPE_NQ) | |
2295 | { | |
2296 | reg_incr = 1; | |
2297 | } | |
2298 | firsttype = atype; | |
2299 | } | |
5287ad62 | 2300 | else if (reg_incr == -1) |
477330fc RM |
2301 | { |
2302 | reg_incr = getreg - base_reg; | |
2303 | if (reg_incr < 1 || reg_incr > 2) | |
2304 | { | |
2305 | first_error (_(incr_error)); | |
2306 | return FAIL; | |
2307 | } | |
2308 | } | |
5287ad62 | 2309 | else if (getreg != base_reg + reg_incr * count) |
477330fc RM |
2310 | { |
2311 | first_error (_(incr_error)); | |
2312 | return FAIL; | |
2313 | } | |
dcbf9037 | 2314 | |
c921be7d | 2315 | if (! neon_alias_types_same (&atype, &firsttype)) |
477330fc RM |
2316 | { |
2317 | first_error (_(type_error)); | |
2318 | return FAIL; | |
2319 | } | |
5f4273c7 | 2320 | |
5287ad62 | 2321 | /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list |
477330fc | 2322 | modes. */ |
5287ad62 | 2323 | if (ptr[0] == '-') |
477330fc RM |
2324 | { |
2325 | struct neon_typed_alias htype; | |
2326 | int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1; | |
2327 | if (lane == -1) | |
2328 | lane = NEON_INTERLEAVE_LANES; | |
2329 | else if (lane != NEON_INTERLEAVE_LANES) | |
2330 | { | |
2331 | first_error (_(type_error)); | |
2332 | return FAIL; | |
2333 | } | |
2334 | if (reg_incr == -1) | |
2335 | reg_incr = 1; | |
2336 | else if (reg_incr != 1) | |
2337 | { | |
2338 | first_error (_("don't use Rn-Rm syntax with non-unit stride")); | |
2339 | return FAIL; | |
2340 | } | |
2341 | ptr++; | |
2342 | hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype); | |
2343 | if (hireg == FAIL) | |
2344 | { | |
2345 | first_error (_(reg_expected_msgs[rtype])); | |
2346 | return FAIL; | |
2347 | } | |
2348 | if (! neon_alias_types_same (&htype, &firsttype)) | |
2349 | { | |
2350 | first_error (_(type_error)); | |
2351 | return FAIL; | |
2352 | } | |
2353 | count += hireg + dregs - getreg; | |
2354 | continue; | |
2355 | } | |
5f4273c7 | 2356 | |
5287ad62 JB |
2357 | /* If we're using Q registers, we can't use [] or [n] syntax. */ |
2358 | if (rtype == REG_TYPE_NQ) | |
477330fc RM |
2359 | { |
2360 | count += 2; | |
2361 | continue; | |
2362 | } | |
5f4273c7 | 2363 | |
dcbf9037 | 2364 | if ((atype.defined & NTA_HASINDEX) != 0) |
477330fc RM |
2365 | { |
2366 | if (lane == -1) | |
2367 | lane = atype.index; | |
2368 | else if (lane != atype.index) | |
2369 | { | |
2370 | first_error (_(type_error)); | |
2371 | return FAIL; | |
2372 | } | |
2373 | } | |
5287ad62 | 2374 | else if (lane == -1) |
477330fc | 2375 | lane = NEON_INTERLEAVE_LANES; |
5287ad62 | 2376 | else if (lane != NEON_INTERLEAVE_LANES) |
477330fc RM |
2377 | { |
2378 | first_error (_(type_error)); | |
2379 | return FAIL; | |
2380 | } | |
5287ad62 JB |
2381 | count++; |
2382 | } | |
2383 | while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL); | |
5f4273c7 | 2384 | |
5287ad62 JB |
2385 | /* No lane set by [x]. We must be interleaving structures. */ |
2386 | if (lane == -1) | |
2387 | lane = NEON_INTERLEAVE_LANES; | |
5f4273c7 | 2388 | |
5287ad62 | 2389 | /* Sanity check. */ |
35c228db | 2390 | if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4) |
5287ad62 JB |
2391 | || (count > 1 && reg_incr == -1)) |
2392 | { | |
dcbf9037 | 2393 | first_error (_("error parsing element/structure list")); |
5287ad62 JB |
2394 | return FAIL; |
2395 | } | |
2396 | ||
2397 | if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL) | |
2398 | { | |
dcbf9037 | 2399 | first_error (_("expected }")); |
5287ad62 JB |
2400 | return FAIL; |
2401 | } | |
5f4273c7 | 2402 | |
5287ad62 JB |
2403 | if (reg_incr == -1) |
2404 | reg_incr = 1; | |
2405 | ||
dcbf9037 JB |
2406 | if (eltype) |
2407 | *eltype = firsttype.eltype; | |
2408 | ||
5287ad62 JB |
2409 | *pbase = base_reg; |
2410 | *str = ptr; | |
5f4273c7 | 2411 | |
5287ad62 JB |
2412 | return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5); |
2413 | } | |
2414 | ||
c19d1205 ZW |
2415 | /* Parse an explicit relocation suffix on an expression. This is |
2416 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
2417 | arm_reloc_hsh contains no entries, so this function can only | |
2418 | succeed if there is no () after the word. Returns -1 on error, | |
2419 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
3da1d841 | 2420 | |
c19d1205 ZW |
2421 | static int |
2422 | parse_reloc (char **str) | |
b99bd4ef | 2423 | { |
c19d1205 ZW |
2424 | struct reloc_entry *r; |
2425 | char *p, *q; | |
b99bd4ef | 2426 | |
c19d1205 ZW |
2427 | if (**str != '(') |
2428 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 2429 | |
c19d1205 ZW |
2430 | p = *str + 1; |
2431 | q = p; | |
2432 | ||
2433 | while (*q && *q != ')' && *q != ',') | |
2434 | q++; | |
2435 | if (*q != ')') | |
2436 | return -1; | |
2437 | ||
21d799b5 NC |
2438 | if ((r = (struct reloc_entry *) |
2439 | hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
c19d1205 ZW |
2440 | return -1; |
2441 | ||
2442 | *str = q + 1; | |
2443 | return r->reloc; | |
b99bd4ef NC |
2444 | } |
2445 | ||
c19d1205 ZW |
2446 | /* Directives: register aliases. */ |
2447 | ||
dcbf9037 | 2448 | static struct reg_entry * |
90ec0d68 | 2449 | insert_reg_alias (char *str, unsigned number, int type) |
b99bd4ef | 2450 | { |
d3ce72d0 | 2451 | struct reg_entry *new_reg; |
c19d1205 | 2452 | const char *name; |
b99bd4ef | 2453 | |
d3ce72d0 | 2454 | if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0) |
c19d1205 | 2455 | { |
d3ce72d0 | 2456 | if (new_reg->builtin) |
c19d1205 | 2457 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); |
b99bd4ef | 2458 | |
c19d1205 ZW |
2459 | /* Only warn about a redefinition if it's not defined as the |
2460 | same register. */ | |
d3ce72d0 | 2461 | else if (new_reg->number != number || new_reg->type != type) |
c19d1205 | 2462 | as_warn (_("ignoring redefinition of register alias '%s'"), str); |
69b97547 | 2463 | |
d929913e | 2464 | return NULL; |
c19d1205 | 2465 | } |
b99bd4ef | 2466 | |
c19d1205 | 2467 | name = xstrdup (str); |
325801bd | 2468 | new_reg = XNEW (struct reg_entry); |
b99bd4ef | 2469 | |
d3ce72d0 NC |
2470 | new_reg->name = name; |
2471 | new_reg->number = number; | |
2472 | new_reg->type = type; | |
2473 | new_reg->builtin = FALSE; | |
2474 | new_reg->neon = NULL; | |
b99bd4ef | 2475 | |
d3ce72d0 | 2476 | if (hash_insert (arm_reg_hsh, name, (void *) new_reg)) |
c19d1205 | 2477 | abort (); |
5f4273c7 | 2478 | |
d3ce72d0 | 2479 | return new_reg; |
dcbf9037 JB |
2480 | } |
2481 | ||
2482 | static void | |
2483 | insert_neon_reg_alias (char *str, int number, int type, | |
477330fc | 2484 | struct neon_typed_alias *atype) |
dcbf9037 JB |
2485 | { |
2486 | struct reg_entry *reg = insert_reg_alias (str, number, type); | |
5f4273c7 | 2487 | |
dcbf9037 JB |
2488 | if (!reg) |
2489 | { | |
2490 | first_error (_("attempt to redefine typed alias")); | |
2491 | return; | |
2492 | } | |
5f4273c7 | 2493 | |
dcbf9037 JB |
2494 | if (atype) |
2495 | { | |
325801bd | 2496 | reg->neon = XNEW (struct neon_typed_alias); |
dcbf9037 JB |
2497 | *reg->neon = *atype; |
2498 | } | |
c19d1205 | 2499 | } |
b99bd4ef | 2500 | |
c19d1205 | 2501 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 2502 | |
c19d1205 | 2503 | new_register_name .req existing_register_name |
b99bd4ef | 2504 | |
c19d1205 | 2505 | If we find one, or if it looks sufficiently like one that we want to |
d929913e | 2506 | handle any error here, return TRUE. Otherwise return FALSE. */ |
b99bd4ef | 2507 | |
d929913e | 2508 | static bfd_boolean |
c19d1205 ZW |
2509 | create_register_alias (char * newname, char *p) |
2510 | { | |
2511 | struct reg_entry *old; | |
2512 | char *oldname, *nbuf; | |
2513 | size_t nlen; | |
b99bd4ef | 2514 | |
c19d1205 ZW |
2515 | /* The input scrubber ensures that whitespace after the mnemonic is |
2516 | collapsed to single spaces. */ | |
2517 | oldname = p; | |
2518 | if (strncmp (oldname, " .req ", 6) != 0) | |
d929913e | 2519 | return FALSE; |
b99bd4ef | 2520 | |
c19d1205 ZW |
2521 | oldname += 6; |
2522 | if (*oldname == '\0') | |
d929913e | 2523 | return FALSE; |
b99bd4ef | 2524 | |
21d799b5 | 2525 | old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname); |
c19d1205 | 2526 | if (!old) |
b99bd4ef | 2527 | { |
c19d1205 | 2528 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
d929913e | 2529 | return TRUE; |
b99bd4ef NC |
2530 | } |
2531 | ||
c19d1205 ZW |
2532 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2533 | the desired alias name, and p points to its end. If not, then | |
2534 | the desired alias name is in the global original_case_string. */ | |
2535 | #ifdef TC_CASE_SENSITIVE | |
2536 | nlen = p - newname; | |
2537 | #else | |
2538 | newname = original_case_string; | |
2539 | nlen = strlen (newname); | |
2540 | #endif | |
b99bd4ef | 2541 | |
29a2809e | 2542 | nbuf = xmemdup0 (newname, nlen); |
b99bd4ef | 2543 | |
c19d1205 ZW |
2544 | /* Create aliases under the new name as stated; an all-lowercase |
2545 | version of the new name; and an all-uppercase version of the new | |
2546 | name. */ | |
d929913e NC |
2547 | if (insert_reg_alias (nbuf, old->number, old->type) != NULL) |
2548 | { | |
2549 | for (p = nbuf; *p; p++) | |
2550 | *p = TOUPPER (*p); | |
c19d1205 | 2551 | |
d929913e NC |
2552 | if (strncmp (nbuf, newname, nlen)) |
2553 | { | |
2554 | /* If this attempt to create an additional alias fails, do not bother | |
2555 | trying to create the all-lower case alias. We will fail and issue | |
2556 | a second, duplicate error message. This situation arises when the | |
2557 | programmer does something like: | |
2558 | foo .req r0 | |
2559 | Foo .req r1 | |
2560 | The second .req creates the "Foo" alias but then fails to create | |
5f4273c7 | 2561 | the artificial FOO alias because it has already been created by the |
d929913e NC |
2562 | first .req. */ |
2563 | if (insert_reg_alias (nbuf, old->number, old->type) == NULL) | |
e1fa0163 NC |
2564 | { |
2565 | free (nbuf); | |
2566 | return TRUE; | |
2567 | } | |
d929913e | 2568 | } |
c19d1205 | 2569 | |
d929913e NC |
2570 | for (p = nbuf; *p; p++) |
2571 | *p = TOLOWER (*p); | |
c19d1205 | 2572 | |
d929913e NC |
2573 | if (strncmp (nbuf, newname, nlen)) |
2574 | insert_reg_alias (nbuf, old->number, old->type); | |
2575 | } | |
c19d1205 | 2576 | |
e1fa0163 | 2577 | free (nbuf); |
d929913e | 2578 | return TRUE; |
b99bd4ef NC |
2579 | } |
2580 | ||
dcbf9037 JB |
2581 | /* Create a Neon typed/indexed register alias using directives, e.g.: |
2582 | X .dn d5.s32[1] | |
2583 | Y .qn 6.s16 | |
2584 | Z .dn d7 | |
2585 | T .dn Z[0] | |
2586 | These typed registers can be used instead of the types specified after the | |
2587 | Neon mnemonic, so long as all operands given have types. Types can also be | |
2588 | specified directly, e.g.: | |
5f4273c7 | 2589 | vadd d0.s32, d1.s32, d2.s32 */ |
dcbf9037 | 2590 | |
c921be7d | 2591 | static bfd_boolean |
dcbf9037 JB |
2592 | create_neon_reg_alias (char *newname, char *p) |
2593 | { | |
2594 | enum arm_reg_type basetype; | |
2595 | struct reg_entry *basereg; | |
2596 | struct reg_entry mybasereg; | |
2597 | struct neon_type ntype; | |
2598 | struct neon_typed_alias typeinfo; | |
12d6b0b7 | 2599 | char *namebuf, *nameend ATTRIBUTE_UNUSED; |
dcbf9037 | 2600 | int namelen; |
5f4273c7 | 2601 | |
dcbf9037 JB |
2602 | typeinfo.defined = 0; |
2603 | typeinfo.eltype.type = NT_invtype; | |
2604 | typeinfo.eltype.size = -1; | |
2605 | typeinfo.index = -1; | |
5f4273c7 | 2606 | |
dcbf9037 | 2607 | nameend = p; |
5f4273c7 | 2608 | |
dcbf9037 JB |
2609 | if (strncmp (p, " .dn ", 5) == 0) |
2610 | basetype = REG_TYPE_VFD; | |
2611 | else if (strncmp (p, " .qn ", 5) == 0) | |
2612 | basetype = REG_TYPE_NQ; | |
2613 | else | |
c921be7d | 2614 | return FALSE; |
5f4273c7 | 2615 | |
dcbf9037 | 2616 | p += 5; |
5f4273c7 | 2617 | |
dcbf9037 | 2618 | if (*p == '\0') |
c921be7d | 2619 | return FALSE; |
5f4273c7 | 2620 | |
dcbf9037 JB |
2621 | basereg = arm_reg_parse_multi (&p); |
2622 | ||
2623 | if (basereg && basereg->type != basetype) | |
2624 | { | |
2625 | as_bad (_("bad type for register")); | |
c921be7d | 2626 | return FALSE; |
dcbf9037 JB |
2627 | } |
2628 | ||
2629 | if (basereg == NULL) | |
2630 | { | |
2631 | expressionS exp; | |
2632 | /* Try parsing as an integer. */ | |
2633 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2634 | if (exp.X_op != O_constant) | |
477330fc RM |
2635 | { |
2636 | as_bad (_("expression must be constant")); | |
2637 | return FALSE; | |
2638 | } | |
dcbf9037 JB |
2639 | basereg = &mybasereg; |
2640 | basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2 | |
477330fc | 2641 | : exp.X_add_number; |
dcbf9037 JB |
2642 | basereg->neon = 0; |
2643 | } | |
2644 | ||
2645 | if (basereg->neon) | |
2646 | typeinfo = *basereg->neon; | |
2647 | ||
2648 | if (parse_neon_type (&ntype, &p) == SUCCESS) | |
2649 | { | |
2650 | /* We got a type. */ | |
2651 | if (typeinfo.defined & NTA_HASTYPE) | |
477330fc RM |
2652 | { |
2653 | as_bad (_("can't redefine the type of a register alias")); | |
2654 | return FALSE; | |
2655 | } | |
5f4273c7 | 2656 | |
dcbf9037 JB |
2657 | typeinfo.defined |= NTA_HASTYPE; |
2658 | if (ntype.elems != 1) | |
477330fc RM |
2659 | { |
2660 | as_bad (_("you must specify a single type only")); | |
2661 | return FALSE; | |
2662 | } | |
dcbf9037 JB |
2663 | typeinfo.eltype = ntype.el[0]; |
2664 | } | |
5f4273c7 | 2665 | |
dcbf9037 JB |
2666 | if (skip_past_char (&p, '[') == SUCCESS) |
2667 | { | |
2668 | expressionS exp; | |
2669 | /* We got a scalar index. */ | |
5f4273c7 | 2670 | |
dcbf9037 | 2671 | if (typeinfo.defined & NTA_HASINDEX) |
477330fc RM |
2672 | { |
2673 | as_bad (_("can't redefine the index of a scalar alias")); | |
2674 | return FALSE; | |
2675 | } | |
5f4273c7 | 2676 | |
dcbf9037 | 2677 | my_get_expression (&exp, &p, GE_NO_PREFIX); |
5f4273c7 | 2678 | |
dcbf9037 | 2679 | if (exp.X_op != O_constant) |
477330fc RM |
2680 | { |
2681 | as_bad (_("scalar index must be constant")); | |
2682 | return FALSE; | |
2683 | } | |
5f4273c7 | 2684 | |
dcbf9037 JB |
2685 | typeinfo.defined |= NTA_HASINDEX; |
2686 | typeinfo.index = exp.X_add_number; | |
5f4273c7 | 2687 | |
dcbf9037 | 2688 | if (skip_past_char (&p, ']') == FAIL) |
477330fc RM |
2689 | { |
2690 | as_bad (_("expecting ]")); | |
2691 | return FALSE; | |
2692 | } | |
dcbf9037 JB |
2693 | } |
2694 | ||
15735687 NS |
2695 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2696 | the desired alias name, and p points to its end. If not, then | |
2697 | the desired alias name is in the global original_case_string. */ | |
2698 | #ifdef TC_CASE_SENSITIVE | |
dcbf9037 | 2699 | namelen = nameend - newname; |
15735687 NS |
2700 | #else |
2701 | newname = original_case_string; | |
2702 | namelen = strlen (newname); | |
2703 | #endif | |
2704 | ||
29a2809e | 2705 | namebuf = xmemdup0 (newname, namelen); |
5f4273c7 | 2706 | |
dcbf9037 | 2707 | insert_neon_reg_alias (namebuf, basereg->number, basetype, |
477330fc | 2708 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2709 | |
dcbf9037 JB |
2710 | /* Insert name in all uppercase. */ |
2711 | for (p = namebuf; *p; p++) | |
2712 | *p = TOUPPER (*p); | |
5f4273c7 | 2713 | |
dcbf9037 JB |
2714 | if (strncmp (namebuf, newname, namelen)) |
2715 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
477330fc | 2716 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2717 | |
dcbf9037 JB |
2718 | /* Insert name in all lowercase. */ |
2719 | for (p = namebuf; *p; p++) | |
2720 | *p = TOLOWER (*p); | |
5f4273c7 | 2721 | |
dcbf9037 JB |
2722 | if (strncmp (namebuf, newname, namelen)) |
2723 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
477330fc | 2724 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2725 | |
e1fa0163 | 2726 | free (namebuf); |
c921be7d | 2727 | return TRUE; |
dcbf9037 JB |
2728 | } |
2729 | ||
c19d1205 ZW |
2730 | /* Should never be called, as .req goes between the alias and the |
2731 | register name, not at the beginning of the line. */ | |
c921be7d | 2732 | |
b99bd4ef | 2733 | static void |
c19d1205 | 2734 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2735 | { |
c19d1205 ZW |
2736 | as_bad (_("invalid syntax for .req directive")); |
2737 | } | |
b99bd4ef | 2738 | |
dcbf9037 JB |
2739 | static void |
2740 | s_dn (int a ATTRIBUTE_UNUSED) | |
2741 | { | |
2742 | as_bad (_("invalid syntax for .dn directive")); | |
2743 | } | |
2744 | ||
2745 | static void | |
2746 | s_qn (int a ATTRIBUTE_UNUSED) | |
2747 | { | |
2748 | as_bad (_("invalid syntax for .qn directive")); | |
2749 | } | |
2750 | ||
c19d1205 ZW |
2751 | /* The .unreq directive deletes an alias which was previously defined |
2752 | by .req. For example: | |
b99bd4ef | 2753 | |
c19d1205 ZW |
2754 | my_alias .req r11 |
2755 | .unreq my_alias */ | |
b99bd4ef NC |
2756 | |
2757 | static void | |
c19d1205 | 2758 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2759 | { |
c19d1205 ZW |
2760 | char * name; |
2761 | char saved_char; | |
b99bd4ef | 2762 | |
c19d1205 ZW |
2763 | name = input_line_pointer; |
2764 | ||
2765 | while (*input_line_pointer != 0 | |
2766 | && *input_line_pointer != ' ' | |
2767 | && *input_line_pointer != '\n') | |
2768 | ++input_line_pointer; | |
2769 | ||
2770 | saved_char = *input_line_pointer; | |
2771 | *input_line_pointer = 0; | |
2772 | ||
2773 | if (!*name) | |
2774 | as_bad (_("invalid syntax for .unreq directive")); | |
2775 | else | |
2776 | { | |
21d799b5 | 2777 | struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh, |
477330fc | 2778 | name); |
c19d1205 ZW |
2779 | |
2780 | if (!reg) | |
2781 | as_bad (_("unknown register alias '%s'"), name); | |
2782 | else if (reg->builtin) | |
a1727c1a | 2783 | as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"), |
c19d1205 ZW |
2784 | name); |
2785 | else | |
2786 | { | |
d929913e NC |
2787 | char * p; |
2788 | char * nbuf; | |
2789 | ||
db0bc284 | 2790 | hash_delete (arm_reg_hsh, name, FALSE); |
c19d1205 | 2791 | free ((char *) reg->name); |
477330fc RM |
2792 | if (reg->neon) |
2793 | free (reg->neon); | |
c19d1205 | 2794 | free (reg); |
d929913e NC |
2795 | |
2796 | /* Also locate the all upper case and all lower case versions. | |
2797 | Do not complain if we cannot find one or the other as it | |
2798 | was probably deleted above. */ | |
5f4273c7 | 2799 | |
d929913e NC |
2800 | nbuf = strdup (name); |
2801 | for (p = nbuf; *p; p++) | |
2802 | *p = TOUPPER (*p); | |
21d799b5 | 2803 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2804 | if (reg) |
2805 | { | |
db0bc284 | 2806 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2807 | free ((char *) reg->name); |
2808 | if (reg->neon) | |
2809 | free (reg->neon); | |
2810 | free (reg); | |
2811 | } | |
2812 | ||
2813 | for (p = nbuf; *p; p++) | |
2814 | *p = TOLOWER (*p); | |
21d799b5 | 2815 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2816 | if (reg) |
2817 | { | |
db0bc284 | 2818 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2819 | free ((char *) reg->name); |
2820 | if (reg->neon) | |
2821 | free (reg->neon); | |
2822 | free (reg); | |
2823 | } | |
2824 | ||
2825 | free (nbuf); | |
c19d1205 ZW |
2826 | } |
2827 | } | |
b99bd4ef | 2828 | |
c19d1205 | 2829 | *input_line_pointer = saved_char; |
b99bd4ef NC |
2830 | demand_empty_rest_of_line (); |
2831 | } | |
2832 | ||
c19d1205 ZW |
2833 | /* Directives: Instruction set selection. */ |
2834 | ||
2835 | #ifdef OBJ_ELF | |
2836 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
2837 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
2838 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
2839 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
2840 | ||
cd000bff DJ |
2841 | /* Create a new mapping symbol for the transition to STATE. */ |
2842 | ||
2843 | static void | |
2844 | make_mapping_symbol (enum mstate state, valueT value, fragS *frag) | |
b99bd4ef | 2845 | { |
a737bd4d | 2846 | symbolS * symbolP; |
c19d1205 ZW |
2847 | const char * symname; |
2848 | int type; | |
b99bd4ef | 2849 | |
c19d1205 | 2850 | switch (state) |
b99bd4ef | 2851 | { |
c19d1205 ZW |
2852 | case MAP_DATA: |
2853 | symname = "$d"; | |
2854 | type = BSF_NO_FLAGS; | |
2855 | break; | |
2856 | case MAP_ARM: | |
2857 | symname = "$a"; | |
2858 | type = BSF_NO_FLAGS; | |
2859 | break; | |
2860 | case MAP_THUMB: | |
2861 | symname = "$t"; | |
2862 | type = BSF_NO_FLAGS; | |
2863 | break; | |
c19d1205 ZW |
2864 | default: |
2865 | abort (); | |
2866 | } | |
2867 | ||
cd000bff | 2868 | symbolP = symbol_new (symname, now_seg, value, frag); |
c19d1205 ZW |
2869 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; |
2870 | ||
2871 | switch (state) | |
2872 | { | |
2873 | case MAP_ARM: | |
2874 | THUMB_SET_FUNC (symbolP, 0); | |
2875 | ARM_SET_THUMB (symbolP, 0); | |
2876 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2877 | break; | |
2878 | ||
2879 | case MAP_THUMB: | |
2880 | THUMB_SET_FUNC (symbolP, 1); | |
2881 | ARM_SET_THUMB (symbolP, 1); | |
2882 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2883 | break; | |
2884 | ||
2885 | case MAP_DATA: | |
2886 | default: | |
cd000bff DJ |
2887 | break; |
2888 | } | |
2889 | ||
2890 | /* Save the mapping symbols for future reference. Also check that | |
2891 | we do not place two mapping symbols at the same offset within a | |
2892 | frag. We'll handle overlap between frags in | |
2de7820f JZ |
2893 | check_mapping_symbols. |
2894 | ||
2895 | If .fill or other data filling directive generates zero sized data, | |
2896 | the mapping symbol for the following code will have the same value | |
2897 | as the one generated for the data filling directive. In this case, | |
2898 | we replace the old symbol with the new one at the same address. */ | |
cd000bff DJ |
2899 | if (value == 0) |
2900 | { | |
2de7820f JZ |
2901 | if (frag->tc_frag_data.first_map != NULL) |
2902 | { | |
2903 | know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0); | |
2904 | symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP); | |
2905 | } | |
cd000bff DJ |
2906 | frag->tc_frag_data.first_map = symbolP; |
2907 | } | |
2908 | if (frag->tc_frag_data.last_map != NULL) | |
0f020cef JZ |
2909 | { |
2910 | know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP)); | |
0f020cef JZ |
2911 | if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP)) |
2912 | symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP); | |
2913 | } | |
cd000bff DJ |
2914 | frag->tc_frag_data.last_map = symbolP; |
2915 | } | |
2916 | ||
2917 | /* We must sometimes convert a region marked as code to data during | |
2918 | code alignment, if an odd number of bytes have to be padded. The | |
2919 | code mapping symbol is pushed to an aligned address. */ | |
2920 | ||
2921 | static void | |
2922 | insert_data_mapping_symbol (enum mstate state, | |
2923 | valueT value, fragS *frag, offsetT bytes) | |
2924 | { | |
2925 | /* If there was already a mapping symbol, remove it. */ | |
2926 | if (frag->tc_frag_data.last_map != NULL | |
2927 | && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value) | |
2928 | { | |
2929 | symbolS *symp = frag->tc_frag_data.last_map; | |
2930 | ||
2931 | if (value == 0) | |
2932 | { | |
2933 | know (frag->tc_frag_data.first_map == symp); | |
2934 | frag->tc_frag_data.first_map = NULL; | |
2935 | } | |
2936 | frag->tc_frag_data.last_map = NULL; | |
2937 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
c19d1205 | 2938 | } |
cd000bff DJ |
2939 | |
2940 | make_mapping_symbol (MAP_DATA, value, frag); | |
2941 | make_mapping_symbol (state, value + bytes, frag); | |
2942 | } | |
2943 | ||
2944 | static void mapping_state_2 (enum mstate state, int max_chars); | |
2945 | ||
2946 | /* Set the mapping state to STATE. Only call this when about to | |
2947 | emit some STATE bytes to the file. */ | |
2948 | ||
4e9aaefb | 2949 | #define TRANSITION(from, to) (mapstate == (from) && state == (to)) |
cd000bff DJ |
2950 | void |
2951 | mapping_state (enum mstate state) | |
2952 | { | |
940b5ce0 DJ |
2953 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2954 | ||
cd000bff DJ |
2955 | if (mapstate == state) |
2956 | /* The mapping symbol has already been emitted. | |
2957 | There is nothing else to do. */ | |
2958 | return; | |
49c62a33 NC |
2959 | |
2960 | if (state == MAP_ARM || state == MAP_THUMB) | |
2961 | /* PR gas/12931 | |
2962 | All ARM instructions require 4-byte alignment. | |
2963 | (Almost) all Thumb instructions require 2-byte alignment. | |
2964 | ||
2965 | When emitting instructions into any section, mark the section | |
2966 | appropriately. | |
2967 | ||
2968 | Some Thumb instructions are alignment-sensitive modulo 4 bytes, | |
2969 | but themselves require 2-byte alignment; this applies to some | |
33eaf5de | 2970 | PC- relative forms. However, these cases will involve implicit |
49c62a33 NC |
2971 | literal pool generation or an explicit .align >=2, both of |
2972 | which will cause the section to me marked with sufficient | |
2973 | alignment. Thus, we don't handle those cases here. */ | |
2974 | record_alignment (now_seg, state == MAP_ARM ? 2 : 1); | |
2975 | ||
2976 | if (TRANSITION (MAP_UNDEFINED, MAP_DATA)) | |
4e9aaefb | 2977 | /* This case will be evaluated later. */ |
cd000bff | 2978 | return; |
cd000bff DJ |
2979 | |
2980 | mapping_state_2 (state, 0); | |
cd000bff DJ |
2981 | } |
2982 | ||
2983 | /* Same as mapping_state, but MAX_CHARS bytes have already been | |
2984 | allocated. Put the mapping symbol that far back. */ | |
2985 | ||
2986 | static void | |
2987 | mapping_state_2 (enum mstate state, int max_chars) | |
2988 | { | |
940b5ce0 DJ |
2989 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2990 | ||
2991 | if (!SEG_NORMAL (now_seg)) | |
2992 | return; | |
2993 | ||
cd000bff DJ |
2994 | if (mapstate == state) |
2995 | /* The mapping symbol has already been emitted. | |
2996 | There is nothing else to do. */ | |
2997 | return; | |
2998 | ||
4e9aaefb SA |
2999 | if (TRANSITION (MAP_UNDEFINED, MAP_ARM) |
3000 | || TRANSITION (MAP_UNDEFINED, MAP_THUMB)) | |
3001 | { | |
3002 | struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root; | |
3003 | const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0); | |
3004 | ||
3005 | if (add_symbol) | |
3006 | make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first); | |
3007 | } | |
3008 | ||
cd000bff DJ |
3009 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; |
3010 | make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now); | |
c19d1205 | 3011 | } |
4e9aaefb | 3012 | #undef TRANSITION |
c19d1205 | 3013 | #else |
d3106081 NS |
3014 | #define mapping_state(x) ((void)0) |
3015 | #define mapping_state_2(x, y) ((void)0) | |
c19d1205 ZW |
3016 | #endif |
3017 | ||
3018 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
3019 | ||
4343666d | 3020 | #ifdef OBJ_COFF |
c19d1205 ZW |
3021 | static symbolS * |
3022 | find_real_start (symbolS * symbolP) | |
3023 | { | |
3024 | char * real_start; | |
3025 | const char * name = S_GET_NAME (symbolP); | |
3026 | symbolS * new_target; | |
3027 | ||
3028 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
3029 | #define STUB_NAME ".real_start_of" | |
3030 | ||
3031 | if (name == NULL) | |
3032 | abort (); | |
3033 | ||
37f6032b ZW |
3034 | /* The compiler may generate BL instructions to local labels because |
3035 | it needs to perform a branch to a far away location. These labels | |
3036 | do not have a corresponding ".real_start_of" label. We check | |
3037 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
3038 | the ".real_start_of" convention for nonlocal branches. */ | |
3039 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
3040 | return symbolP; |
3041 | ||
e1fa0163 | 3042 | real_start = concat (STUB_NAME, name, NULL); |
c19d1205 | 3043 | new_target = symbol_find (real_start); |
e1fa0163 | 3044 | free (real_start); |
c19d1205 ZW |
3045 | |
3046 | if (new_target == NULL) | |
3047 | { | |
bd3ba5d1 | 3048 | as_warn (_("Failed to find real start of function: %s\n"), name); |
c19d1205 ZW |
3049 | new_target = symbolP; |
3050 | } | |
3051 | ||
c19d1205 ZW |
3052 | return new_target; |
3053 | } | |
4343666d | 3054 | #endif |
c19d1205 ZW |
3055 | |
3056 | static void | |
3057 | opcode_select (int width) | |
3058 | { | |
3059 | switch (width) | |
3060 | { | |
3061 | case 16: | |
3062 | if (! thumb_mode) | |
3063 | { | |
e74cfd16 | 3064 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
3065 | as_bad (_("selected processor does not support THUMB opcodes")); |
3066 | ||
3067 | thumb_mode = 1; | |
3068 | /* No need to force the alignment, since we will have been | |
3069 | coming from ARM mode, which is word-aligned. */ | |
3070 | record_alignment (now_seg, 1); | |
3071 | } | |
c19d1205 ZW |
3072 | break; |
3073 | ||
3074 | case 32: | |
3075 | if (thumb_mode) | |
3076 | { | |
e74cfd16 | 3077 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
3078 | as_bad (_("selected processor does not support ARM opcodes")); |
3079 | ||
3080 | thumb_mode = 0; | |
3081 | ||
3082 | if (!need_pass_2) | |
3083 | frag_align (2, 0, 0); | |
3084 | ||
3085 | record_alignment (now_seg, 1); | |
3086 | } | |
c19d1205 ZW |
3087 | break; |
3088 | ||
3089 | default: | |
3090 | as_bad (_("invalid instruction size selected (%d)"), width); | |
3091 | } | |
3092 | } | |
3093 | ||
3094 | static void | |
3095 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
3096 | { | |
3097 | opcode_select (32); | |
3098 | demand_empty_rest_of_line (); | |
3099 | } | |
3100 | ||
3101 | static void | |
3102 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
3103 | { | |
3104 | opcode_select (16); | |
3105 | demand_empty_rest_of_line (); | |
3106 | } | |
3107 | ||
3108 | static void | |
3109 | s_code (int unused ATTRIBUTE_UNUSED) | |
3110 | { | |
3111 | int temp; | |
3112 | ||
3113 | temp = get_absolute_expression (); | |
3114 | switch (temp) | |
3115 | { | |
3116 | case 16: | |
3117 | case 32: | |
3118 | opcode_select (temp); | |
3119 | break; | |
3120 | ||
3121 | default: | |
3122 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
3123 | } | |
3124 | } | |
3125 | ||
3126 | static void | |
3127 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
3128 | { | |
3129 | /* If we are not already in thumb mode go into it, EVEN if | |
3130 | the target processor does not support thumb instructions. | |
3131 | This is used by gcc/config/arm/lib1funcs.asm for example | |
3132 | to compile interworking support functions even if the | |
3133 | target processor should not support interworking. */ | |
3134 | if (! thumb_mode) | |
3135 | { | |
3136 | thumb_mode = 2; | |
3137 | record_alignment (now_seg, 1); | |
3138 | } | |
3139 | ||
3140 | demand_empty_rest_of_line (); | |
3141 | } | |
3142 | ||
3143 | static void | |
3144 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
3145 | { | |
3146 | s_thumb (0); | |
3147 | ||
3148 | /* The following label is the name/address of the start of a Thumb function. | |
3149 | We need to know this for the interworking support. */ | |
3150 | label_is_thumb_function_name = TRUE; | |
3151 | } | |
3152 | ||
3153 | /* Perform a .set directive, but also mark the alias as | |
3154 | being a thumb function. */ | |
3155 | ||
3156 | static void | |
3157 | s_thumb_set (int equiv) | |
3158 | { | |
3159 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
3160 | We cannot just call that code as we need to get at the symbol that | |
3161 | is created. */ | |
3162 | char * name; | |
3163 | char delim; | |
3164 | char * end_name; | |
3165 | symbolS * symbolP; | |
3166 | ||
3167 | /* Especial apologies for the random logic: | |
3168 | This just grew, and could be parsed much more simply! | |
3169 | Dean - in haste. */ | |
d02603dc | 3170 | delim = get_symbol_name (& name); |
c19d1205 | 3171 | end_name = input_line_pointer; |
d02603dc | 3172 | (void) restore_line_pointer (delim); |
c19d1205 ZW |
3173 | |
3174 | if (*input_line_pointer != ',') | |
3175 | { | |
3176 | *end_name = 0; | |
3177 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
3178 | *end_name = delim; |
3179 | ignore_rest_of_line (); | |
3180 | return; | |
3181 | } | |
3182 | ||
3183 | input_line_pointer++; | |
3184 | *end_name = 0; | |
3185 | ||
3186 | if (name[0] == '.' && name[1] == '\0') | |
3187 | { | |
3188 | /* XXX - this should not happen to .thumb_set. */ | |
3189 | abort (); | |
3190 | } | |
3191 | ||
3192 | if ((symbolP = symbol_find (name)) == NULL | |
3193 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
3194 | { | |
3195 | #ifndef NO_LISTING | |
3196 | /* When doing symbol listings, play games with dummy fragments living | |
3197 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 3198 | for this symbol. */ |
b99bd4ef NC |
3199 | if (listing & LISTING_SYMBOLS) |
3200 | { | |
3201 | extern struct list_info_struct * listing_tail; | |
21d799b5 | 3202 | fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS)); |
b99bd4ef NC |
3203 | |
3204 | memset (dummy_frag, 0, sizeof (fragS)); | |
3205 | dummy_frag->fr_type = rs_fill; | |
3206 | dummy_frag->line = listing_tail; | |
3207 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
3208 | dummy_frag->fr_symbol = symbolP; | |
3209 | } | |
3210 | else | |
3211 | #endif | |
3212 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
3213 | ||
3214 | #ifdef OBJ_COFF | |
3215 | /* "set" symbols are local unless otherwise specified. */ | |
3216 | SF_SET_LOCAL (symbolP); | |
3217 | #endif /* OBJ_COFF */ | |
3218 | } /* Make a new symbol. */ | |
3219 | ||
3220 | symbol_table_insert (symbolP); | |
3221 | ||
3222 | * end_name = delim; | |
3223 | ||
3224 | if (equiv | |
3225 | && S_IS_DEFINED (symbolP) | |
3226 | && S_GET_SEGMENT (symbolP) != reg_section) | |
3227 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
3228 | ||
3229 | pseudo_set (symbolP); | |
3230 | ||
3231 | demand_empty_rest_of_line (); | |
3232 | ||
c19d1205 | 3233 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
3234 | |
3235 | THUMB_SET_FUNC (symbolP, 1); | |
3236 | ARM_SET_THUMB (symbolP, 1); | |
3237 | #if defined OBJ_ELF || defined OBJ_COFF | |
3238 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
3239 | #endif | |
3240 | } | |
3241 | ||
c19d1205 | 3242 | /* Directives: Mode selection. */ |
b99bd4ef | 3243 | |
c19d1205 ZW |
3244 | /* .syntax [unified|divided] - choose the new unified syntax |
3245 | (same for Arm and Thumb encoding, modulo slight differences in what | |
3246 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 3247 | static void |
c19d1205 | 3248 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 3249 | { |
c19d1205 ZW |
3250 | char *name, delim; |
3251 | ||
d02603dc | 3252 | delim = get_symbol_name (& name); |
c19d1205 ZW |
3253 | |
3254 | if (!strcasecmp (name, "unified")) | |
3255 | unified_syntax = TRUE; | |
3256 | else if (!strcasecmp (name, "divided")) | |
3257 | unified_syntax = FALSE; | |
3258 | else | |
3259 | { | |
3260 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
3261 | return; | |
3262 | } | |
d02603dc | 3263 | (void) restore_line_pointer (delim); |
b99bd4ef NC |
3264 | demand_empty_rest_of_line (); |
3265 | } | |
3266 | ||
c19d1205 ZW |
3267 | /* Directives: sectioning and alignment. */ |
3268 | ||
c19d1205 ZW |
3269 | static void |
3270 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 3271 | { |
c19d1205 ZW |
3272 | /* We don't support putting frags in the BSS segment, we fake it by |
3273 | marking in_bss, then looking at s_skip for clues. */ | |
3274 | subseg_set (bss_section, 0); | |
3275 | demand_empty_rest_of_line (); | |
cd000bff DJ |
3276 | |
3277 | #ifdef md_elf_section_change_hook | |
3278 | md_elf_section_change_hook (); | |
3279 | #endif | |
c19d1205 | 3280 | } |
b99bd4ef | 3281 | |
c19d1205 ZW |
3282 | static void |
3283 | s_even (int ignore ATTRIBUTE_UNUSED) | |
3284 | { | |
3285 | /* Never make frag if expect extra pass. */ | |
3286 | if (!need_pass_2) | |
3287 | frag_align (1, 0, 0); | |
b99bd4ef | 3288 | |
c19d1205 | 3289 | record_alignment (now_seg, 1); |
b99bd4ef | 3290 | |
c19d1205 | 3291 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3292 | } |
3293 | ||
2e6976a8 DG |
3294 | /* Directives: CodeComposer Studio. */ |
3295 | ||
3296 | /* .ref (for CodeComposer Studio syntax only). */ | |
3297 | static void | |
3298 | s_ccs_ref (int unused ATTRIBUTE_UNUSED) | |
3299 | { | |
3300 | if (codecomposer_syntax) | |
3301 | ignore_rest_of_line (); | |
3302 | else | |
3303 | as_bad (_(".ref pseudo-op only available with -mccs flag.")); | |
3304 | } | |
3305 | ||
3306 | /* If name is not NULL, then it is used for marking the beginning of a | |
2b0f3761 | 3307 | function, whereas if it is NULL then it means the function end. */ |
2e6976a8 DG |
3308 | static void |
3309 | asmfunc_debug (const char * name) | |
3310 | { | |
3311 | static const char * last_name = NULL; | |
3312 | ||
3313 | if (name != NULL) | |
3314 | { | |
3315 | gas_assert (last_name == NULL); | |
3316 | last_name = name; | |
3317 | ||
3318 | if (debug_type == DEBUG_STABS) | |
3319 | stabs_generate_asm_func (name, name); | |
3320 | } | |
3321 | else | |
3322 | { | |
3323 | gas_assert (last_name != NULL); | |
3324 | ||
3325 | if (debug_type == DEBUG_STABS) | |
3326 | stabs_generate_asm_endfunc (last_name, last_name); | |
3327 | ||
3328 | last_name = NULL; | |
3329 | } | |
3330 | } | |
3331 | ||
3332 | static void | |
3333 | s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED) | |
3334 | { | |
3335 | if (codecomposer_syntax) | |
3336 | { | |
3337 | switch (asmfunc_state) | |
3338 | { | |
3339 | case OUTSIDE_ASMFUNC: | |
3340 | asmfunc_state = WAITING_ASMFUNC_NAME; | |
3341 | break; | |
3342 | ||
3343 | case WAITING_ASMFUNC_NAME: | |
3344 | as_bad (_(".asmfunc repeated.")); | |
3345 | break; | |
3346 | ||
3347 | case WAITING_ENDASMFUNC: | |
3348 | as_bad (_(".asmfunc without function.")); | |
3349 | break; | |
3350 | } | |
3351 | demand_empty_rest_of_line (); | |
3352 | } | |
3353 | else | |
3354 | as_bad (_(".asmfunc pseudo-op only available with -mccs flag.")); | |
3355 | } | |
3356 | ||
3357 | static void | |
3358 | s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED) | |
3359 | { | |
3360 | if (codecomposer_syntax) | |
3361 | { | |
3362 | switch (asmfunc_state) | |
3363 | { | |
3364 | case OUTSIDE_ASMFUNC: | |
3365 | as_bad (_(".endasmfunc without a .asmfunc.")); | |
3366 | break; | |
3367 | ||
3368 | case WAITING_ASMFUNC_NAME: | |
3369 | as_bad (_(".endasmfunc without function.")); | |
3370 | break; | |
3371 | ||
3372 | case WAITING_ENDASMFUNC: | |
3373 | asmfunc_state = OUTSIDE_ASMFUNC; | |
3374 | asmfunc_debug (NULL); | |
3375 | break; | |
3376 | } | |
3377 | demand_empty_rest_of_line (); | |
3378 | } | |
3379 | else | |
3380 | as_bad (_(".endasmfunc pseudo-op only available with -mccs flag.")); | |
3381 | } | |
3382 | ||
3383 | static void | |
3384 | s_ccs_def (int name) | |
3385 | { | |
3386 | if (codecomposer_syntax) | |
3387 | s_globl (name); | |
3388 | else | |
3389 | as_bad (_(".def pseudo-op only available with -mccs flag.")); | |
3390 | } | |
3391 | ||
c19d1205 | 3392 | /* Directives: Literal pools. */ |
a737bd4d | 3393 | |
c19d1205 ZW |
3394 | static literal_pool * |
3395 | find_literal_pool (void) | |
a737bd4d | 3396 | { |
c19d1205 | 3397 | literal_pool * pool; |
a737bd4d | 3398 | |
c19d1205 | 3399 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 3400 | { |
c19d1205 ZW |
3401 | if (pool->section == now_seg |
3402 | && pool->sub_section == now_subseg) | |
3403 | break; | |
a737bd4d NC |
3404 | } |
3405 | ||
c19d1205 | 3406 | return pool; |
a737bd4d NC |
3407 | } |
3408 | ||
c19d1205 ZW |
3409 | static literal_pool * |
3410 | find_or_make_literal_pool (void) | |
a737bd4d | 3411 | { |
c19d1205 ZW |
3412 | /* Next literal pool ID number. */ |
3413 | static unsigned int latest_pool_num = 1; | |
3414 | literal_pool * pool; | |
a737bd4d | 3415 | |
c19d1205 | 3416 | pool = find_literal_pool (); |
a737bd4d | 3417 | |
c19d1205 | 3418 | if (pool == NULL) |
a737bd4d | 3419 | { |
c19d1205 | 3420 | /* Create a new pool. */ |
325801bd | 3421 | pool = XNEW (literal_pool); |
c19d1205 ZW |
3422 | if (! pool) |
3423 | return NULL; | |
a737bd4d | 3424 | |
c19d1205 ZW |
3425 | pool->next_free_entry = 0; |
3426 | pool->section = now_seg; | |
3427 | pool->sub_section = now_subseg; | |
3428 | pool->next = list_of_pools; | |
3429 | pool->symbol = NULL; | |
8335d6aa | 3430 | pool->alignment = 2; |
c19d1205 ZW |
3431 | |
3432 | /* Add it to the list. */ | |
3433 | list_of_pools = pool; | |
a737bd4d | 3434 | } |
a737bd4d | 3435 | |
c19d1205 ZW |
3436 | /* New pools, and emptied pools, will have a NULL symbol. */ |
3437 | if (pool->symbol == NULL) | |
a737bd4d | 3438 | { |
c19d1205 ZW |
3439 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
3440 | (valueT) 0, &zero_address_frag); | |
3441 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
3442 | } |
3443 | ||
c19d1205 ZW |
3444 | /* Done. */ |
3445 | return pool; | |
a737bd4d NC |
3446 | } |
3447 | ||
c19d1205 | 3448 | /* Add the literal in the global 'inst' |
5f4273c7 | 3449 | structure to the relevant literal pool. */ |
b99bd4ef NC |
3450 | |
3451 | static int | |
8335d6aa | 3452 | add_to_lit_pool (unsigned int nbytes) |
b99bd4ef | 3453 | { |
8335d6aa JW |
3454 | #define PADDING_SLOT 0x1 |
3455 | #define LIT_ENTRY_SIZE_MASK 0xFF | |
c19d1205 | 3456 | literal_pool * pool; |
8335d6aa JW |
3457 | unsigned int entry, pool_size = 0; |
3458 | bfd_boolean padding_slot_p = FALSE; | |
e56c722b | 3459 | unsigned imm1 = 0; |
8335d6aa JW |
3460 | unsigned imm2 = 0; |
3461 | ||
3462 | if (nbytes == 8) | |
3463 | { | |
3464 | imm1 = inst.operands[1].imm; | |
3465 | imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg | |
e2b0ab59 | 3466 | : inst.relocs[0].exp.X_unsigned ? 0 |
2569ceb0 | 3467 | : ((bfd_int64_t) inst.operands[1].imm) >> 32); |
8335d6aa JW |
3468 | if (target_big_endian) |
3469 | { | |
3470 | imm1 = imm2; | |
3471 | imm2 = inst.operands[1].imm; | |
3472 | } | |
3473 | } | |
b99bd4ef | 3474 | |
c19d1205 ZW |
3475 | pool = find_or_make_literal_pool (); |
3476 | ||
3477 | /* Check if this literal value is already in the pool. */ | |
3478 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 3479 | { |
8335d6aa JW |
3480 | if (nbytes == 4) |
3481 | { | |
e2b0ab59 AV |
3482 | if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op) |
3483 | && (inst.relocs[0].exp.X_op == O_constant) | |
8335d6aa | 3484 | && (pool->literals[entry].X_add_number |
e2b0ab59 | 3485 | == inst.relocs[0].exp.X_add_number) |
8335d6aa JW |
3486 | && (pool->literals[entry].X_md == nbytes) |
3487 | && (pool->literals[entry].X_unsigned | |
e2b0ab59 | 3488 | == inst.relocs[0].exp.X_unsigned)) |
8335d6aa JW |
3489 | break; |
3490 | ||
e2b0ab59 AV |
3491 | if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op) |
3492 | && (inst.relocs[0].exp.X_op == O_symbol) | |
8335d6aa | 3493 | && (pool->literals[entry].X_add_number |
e2b0ab59 | 3494 | == inst.relocs[0].exp.X_add_number) |
8335d6aa | 3495 | && (pool->literals[entry].X_add_symbol |
e2b0ab59 | 3496 | == inst.relocs[0].exp.X_add_symbol) |
8335d6aa | 3497 | && (pool->literals[entry].X_op_symbol |
e2b0ab59 | 3498 | == inst.relocs[0].exp.X_op_symbol) |
8335d6aa JW |
3499 | && (pool->literals[entry].X_md == nbytes)) |
3500 | break; | |
3501 | } | |
3502 | else if ((nbytes == 8) | |
3503 | && !(pool_size & 0x7) | |
3504 | && ((entry + 1) != pool->next_free_entry) | |
3505 | && (pool->literals[entry].X_op == O_constant) | |
19f2f6a9 | 3506 | && (pool->literals[entry].X_add_number == (offsetT) imm1) |
8335d6aa | 3507 | && (pool->literals[entry].X_unsigned |
e2b0ab59 | 3508 | == inst.relocs[0].exp.X_unsigned) |
8335d6aa | 3509 | && (pool->literals[entry + 1].X_op == O_constant) |
19f2f6a9 | 3510 | && (pool->literals[entry + 1].X_add_number == (offsetT) imm2) |
8335d6aa | 3511 | && (pool->literals[entry + 1].X_unsigned |
e2b0ab59 | 3512 | == inst.relocs[0].exp.X_unsigned)) |
c19d1205 ZW |
3513 | break; |
3514 | ||
8335d6aa JW |
3515 | padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT); |
3516 | if (padding_slot_p && (nbytes == 4)) | |
c19d1205 | 3517 | break; |
8335d6aa JW |
3518 | |
3519 | pool_size += 4; | |
b99bd4ef NC |
3520 | } |
3521 | ||
c19d1205 ZW |
3522 | /* Do we need to create a new entry? */ |
3523 | if (entry == pool->next_free_entry) | |
3524 | { | |
3525 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
3526 | { | |
3527 | inst.error = _("literal pool overflow"); | |
3528 | return FAIL; | |
3529 | } | |
3530 | ||
8335d6aa JW |
3531 | if (nbytes == 8) |
3532 | { | |
3533 | /* For 8-byte entries, we align to an 8-byte boundary, | |
3534 | and split it into two 4-byte entries, because on 32-bit | |
3535 | host, 8-byte constants are treated as big num, thus | |
3536 | saved in "generic_bignum" which will be overwritten | |
3537 | by later assignments. | |
3538 | ||
3539 | We also need to make sure there is enough space for | |
3540 | the split. | |
3541 | ||
3542 | We also check to make sure the literal operand is a | |
3543 | constant number. */ | |
e2b0ab59 AV |
3544 | if (!(inst.relocs[0].exp.X_op == O_constant |
3545 | || inst.relocs[0].exp.X_op == O_big)) | |
8335d6aa JW |
3546 | { |
3547 | inst.error = _("invalid type for literal pool"); | |
3548 | return FAIL; | |
3549 | } | |
3550 | else if (pool_size & 0x7) | |
3551 | { | |
3552 | if ((entry + 2) >= MAX_LITERAL_POOL_SIZE) | |
3553 | { | |
3554 | inst.error = _("literal pool overflow"); | |
3555 | return FAIL; | |
3556 | } | |
3557 | ||
e2b0ab59 | 3558 | pool->literals[entry] = inst.relocs[0].exp; |
a6684f0d | 3559 | pool->literals[entry].X_op = O_constant; |
8335d6aa JW |
3560 | pool->literals[entry].X_add_number = 0; |
3561 | pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4; | |
3562 | pool->next_free_entry += 1; | |
3563 | pool_size += 4; | |
3564 | } | |
3565 | else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE) | |
3566 | { | |
3567 | inst.error = _("literal pool overflow"); | |
3568 | return FAIL; | |
3569 | } | |
3570 | ||
e2b0ab59 | 3571 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3572 | pool->literals[entry].X_op = O_constant; |
3573 | pool->literals[entry].X_add_number = imm1; | |
e2b0ab59 | 3574 | pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned; |
8335d6aa | 3575 | pool->literals[entry++].X_md = 4; |
e2b0ab59 | 3576 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3577 | pool->literals[entry].X_op = O_constant; |
3578 | pool->literals[entry].X_add_number = imm2; | |
e2b0ab59 | 3579 | pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned; |
8335d6aa JW |
3580 | pool->literals[entry].X_md = 4; |
3581 | pool->alignment = 3; | |
3582 | pool->next_free_entry += 1; | |
3583 | } | |
3584 | else | |
3585 | { | |
e2b0ab59 | 3586 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3587 | pool->literals[entry].X_md = 4; |
3588 | } | |
3589 | ||
a8040cf2 NC |
3590 | #ifdef OBJ_ELF |
3591 | /* PR ld/12974: Record the location of the first source line to reference | |
3592 | this entry in the literal pool. If it turns out during linking that the | |
3593 | symbol does not exist we will be able to give an accurate line number for | |
3594 | the (first use of the) missing reference. */ | |
3595 | if (debug_type == DEBUG_DWARF2) | |
3596 | dwarf2_where (pool->locs + entry); | |
3597 | #endif | |
c19d1205 ZW |
3598 | pool->next_free_entry += 1; |
3599 | } | |
8335d6aa JW |
3600 | else if (padding_slot_p) |
3601 | { | |
e2b0ab59 | 3602 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3603 | pool->literals[entry].X_md = nbytes; |
3604 | } | |
b99bd4ef | 3605 | |
e2b0ab59 AV |
3606 | inst.relocs[0].exp.X_op = O_symbol; |
3607 | inst.relocs[0].exp.X_add_number = pool_size; | |
3608 | inst.relocs[0].exp.X_add_symbol = pool->symbol; | |
b99bd4ef | 3609 | |
c19d1205 | 3610 | return SUCCESS; |
b99bd4ef NC |
3611 | } |
3612 | ||
2e6976a8 | 3613 | bfd_boolean |
2e57ce7b | 3614 | tc_start_label_without_colon (void) |
2e6976a8 DG |
3615 | { |
3616 | bfd_boolean ret = TRUE; | |
3617 | ||
3618 | if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME) | |
3619 | { | |
2e57ce7b | 3620 | const char *label = input_line_pointer; |
2e6976a8 DG |
3621 | |
3622 | while (!is_end_of_line[(int) label[-1]]) | |
3623 | --label; | |
3624 | ||
3625 | if (*label == '.') | |
3626 | { | |
3627 | as_bad (_("Invalid label '%s'"), label); | |
3628 | ret = FALSE; | |
3629 | } | |
3630 | ||
3631 | asmfunc_debug (label); | |
3632 | ||
3633 | asmfunc_state = WAITING_ENDASMFUNC; | |
3634 | } | |
3635 | ||
3636 | return ret; | |
3637 | } | |
3638 | ||
c19d1205 | 3639 | /* Can't use symbol_new here, so have to create a symbol and then at |
33eaf5de | 3640 | a later date assign it a value. That's what these functions do. */ |
e16bb312 | 3641 | |
c19d1205 ZW |
3642 | static void |
3643 | symbol_locate (symbolS * symbolP, | |
3644 | const char * name, /* It is copied, the caller can modify. */ | |
3645 | segT segment, /* Segment identifier (SEG_<something>). */ | |
3646 | valueT valu, /* Symbol value. */ | |
3647 | fragS * frag) /* Associated fragment. */ | |
3648 | { | |
e57e6ddc | 3649 | size_t name_length; |
c19d1205 | 3650 | char * preserved_copy_of_name; |
e16bb312 | 3651 | |
c19d1205 ZW |
3652 | name_length = strlen (name) + 1; /* +1 for \0. */ |
3653 | obstack_grow (¬es, name, name_length); | |
21d799b5 | 3654 | preserved_copy_of_name = (char *) obstack_finish (¬es); |
e16bb312 | 3655 | |
c19d1205 ZW |
3656 | #ifdef tc_canonicalize_symbol_name |
3657 | preserved_copy_of_name = | |
3658 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
3659 | #endif | |
b99bd4ef | 3660 | |
c19d1205 | 3661 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 3662 | |
c19d1205 ZW |
3663 | S_SET_SEGMENT (symbolP, segment); |
3664 | S_SET_VALUE (symbolP, valu); | |
3665 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 3666 | |
c19d1205 | 3667 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 3668 | |
c19d1205 ZW |
3669 | /* Link to end of symbol chain. */ |
3670 | { | |
3671 | extern int symbol_table_frozen; | |
b99bd4ef | 3672 | |
c19d1205 ZW |
3673 | if (symbol_table_frozen) |
3674 | abort (); | |
3675 | } | |
b99bd4ef | 3676 | |
c19d1205 | 3677 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 3678 | |
c19d1205 | 3679 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 3680 | |
c19d1205 ZW |
3681 | #ifdef tc_symbol_new_hook |
3682 | tc_symbol_new_hook (symbolP); | |
3683 | #endif | |
3684 | ||
3685 | #ifdef DEBUG_SYMS | |
3686 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
3687 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
3688 | } |
3689 | ||
c19d1205 ZW |
3690 | static void |
3691 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 3692 | { |
c19d1205 ZW |
3693 | unsigned int entry; |
3694 | literal_pool * pool; | |
3695 | char sym_name[20]; | |
b99bd4ef | 3696 | |
c19d1205 ZW |
3697 | pool = find_literal_pool (); |
3698 | if (pool == NULL | |
3699 | || pool->symbol == NULL | |
3700 | || pool->next_free_entry == 0) | |
3701 | return; | |
b99bd4ef | 3702 | |
c19d1205 ZW |
3703 | /* Align pool as you have word accesses. |
3704 | Only make a frag if we have to. */ | |
3705 | if (!need_pass_2) | |
8335d6aa | 3706 | frag_align (pool->alignment, 0, 0); |
b99bd4ef | 3707 | |
c19d1205 | 3708 | record_alignment (now_seg, 2); |
b99bd4ef | 3709 | |
aaca88ef | 3710 | #ifdef OBJ_ELF |
47fc6e36 WN |
3711 | seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA; |
3712 | make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now); | |
aaca88ef | 3713 | #endif |
c19d1205 | 3714 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 3715 | |
c19d1205 ZW |
3716 | symbol_locate (pool->symbol, sym_name, now_seg, |
3717 | (valueT) frag_now_fix (), frag_now); | |
3718 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 3719 | |
c19d1205 | 3720 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 3721 | |
c19d1205 ZW |
3722 | #if defined OBJ_COFF || defined OBJ_ELF |
3723 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
3724 | #endif | |
6c43fab6 | 3725 | |
c19d1205 | 3726 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
a8040cf2 NC |
3727 | { |
3728 | #ifdef OBJ_ELF | |
3729 | if (debug_type == DEBUG_DWARF2) | |
3730 | dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry); | |
3731 | #endif | |
3732 | /* First output the expression in the instruction to the pool. */ | |
8335d6aa JW |
3733 | emit_expr (&(pool->literals[entry]), |
3734 | pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK); | |
a8040cf2 | 3735 | } |
b99bd4ef | 3736 | |
c19d1205 ZW |
3737 | /* Mark the pool as empty. */ |
3738 | pool->next_free_entry = 0; | |
3739 | pool->symbol = NULL; | |
b99bd4ef NC |
3740 | } |
3741 | ||
c19d1205 ZW |
3742 | #ifdef OBJ_ELF |
3743 | /* Forward declarations for functions below, in the MD interface | |
3744 | section. */ | |
3745 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
3746 | static valueT create_unwind_entry (int); | |
3747 | static void start_unwind_section (const segT, int); | |
3748 | static void add_unwind_opcode (valueT, int); | |
3749 | static void flush_pending_unwind (void); | |
b99bd4ef | 3750 | |
c19d1205 | 3751 | /* Directives: Data. */ |
b99bd4ef | 3752 | |
c19d1205 ZW |
3753 | static void |
3754 | s_arm_elf_cons (int nbytes) | |
3755 | { | |
3756 | expressionS exp; | |
b99bd4ef | 3757 | |
c19d1205 ZW |
3758 | #ifdef md_flush_pending_output |
3759 | md_flush_pending_output (); | |
3760 | #endif | |
b99bd4ef | 3761 | |
c19d1205 | 3762 | if (is_it_end_of_statement ()) |
b99bd4ef | 3763 | { |
c19d1205 ZW |
3764 | demand_empty_rest_of_line (); |
3765 | return; | |
b99bd4ef NC |
3766 | } |
3767 | ||
c19d1205 ZW |
3768 | #ifdef md_cons_align |
3769 | md_cons_align (nbytes); | |
3770 | #endif | |
b99bd4ef | 3771 | |
c19d1205 ZW |
3772 | mapping_state (MAP_DATA); |
3773 | do | |
b99bd4ef | 3774 | { |
c19d1205 ZW |
3775 | int reloc; |
3776 | char *base = input_line_pointer; | |
b99bd4ef | 3777 | |
c19d1205 | 3778 | expression (& exp); |
b99bd4ef | 3779 | |
c19d1205 ZW |
3780 | if (exp.X_op != O_symbol) |
3781 | emit_expr (&exp, (unsigned int) nbytes); | |
3782 | else | |
3783 | { | |
3784 | char *before_reloc = input_line_pointer; | |
3785 | reloc = parse_reloc (&input_line_pointer); | |
3786 | if (reloc == -1) | |
3787 | { | |
3788 | as_bad (_("unrecognized relocation suffix")); | |
3789 | ignore_rest_of_line (); | |
3790 | return; | |
3791 | } | |
3792 | else if (reloc == BFD_RELOC_UNUSED) | |
3793 | emit_expr (&exp, (unsigned int) nbytes); | |
3794 | else | |
3795 | { | |
21d799b5 | 3796 | reloc_howto_type *howto = (reloc_howto_type *) |
477330fc RM |
3797 | bfd_reloc_type_lookup (stdoutput, |
3798 | (bfd_reloc_code_real_type) reloc); | |
c19d1205 | 3799 | int size = bfd_get_reloc_size (howto); |
b99bd4ef | 3800 | |
2fc8bdac ZW |
3801 | if (reloc == BFD_RELOC_ARM_PLT32) |
3802 | { | |
3803 | as_bad (_("(plt) is only valid on branch targets")); | |
3804 | reloc = BFD_RELOC_UNUSED; | |
3805 | size = 0; | |
3806 | } | |
3807 | ||
c19d1205 | 3808 | if (size > nbytes) |
992a06ee AM |
3809 | as_bad (ngettext ("%s relocations do not fit in %d byte", |
3810 | "%s relocations do not fit in %d bytes", | |
3811 | nbytes), | |
c19d1205 ZW |
3812 | howto->name, nbytes); |
3813 | else | |
3814 | { | |
3815 | /* We've parsed an expression stopping at O_symbol. | |
3816 | But there may be more expression left now that we | |
3817 | have parsed the relocation marker. Parse it again. | |
3818 | XXX Surely there is a cleaner way to do this. */ | |
3819 | char *p = input_line_pointer; | |
3820 | int offset; | |
325801bd | 3821 | char *save_buf = XNEWVEC (char, input_line_pointer - base); |
e1fa0163 | 3822 | |
c19d1205 ZW |
3823 | memcpy (save_buf, base, input_line_pointer - base); |
3824 | memmove (base + (input_line_pointer - before_reloc), | |
3825 | base, before_reloc - base); | |
3826 | ||
3827 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
3828 | expression (&exp); | |
3829 | memcpy (base, save_buf, p - base); | |
3830 | ||
3831 | offset = nbytes - size; | |
4b1a927e AM |
3832 | p = frag_more (nbytes); |
3833 | memset (p, 0, nbytes); | |
c19d1205 | 3834 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, |
21d799b5 | 3835 | size, &exp, 0, (enum bfd_reloc_code_real) reloc); |
e1fa0163 | 3836 | free (save_buf); |
c19d1205 ZW |
3837 | } |
3838 | } | |
3839 | } | |
b99bd4ef | 3840 | } |
c19d1205 | 3841 | while (*input_line_pointer++ == ','); |
b99bd4ef | 3842 | |
c19d1205 ZW |
3843 | /* Put terminator back into stream. */ |
3844 | input_line_pointer --; | |
3845 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
3846 | } |
3847 | ||
c921be7d NC |
3848 | /* Emit an expression containing a 32-bit thumb instruction. |
3849 | Implementation based on put_thumb32_insn. */ | |
3850 | ||
3851 | static void | |
3852 | emit_thumb32_expr (expressionS * exp) | |
3853 | { | |
3854 | expressionS exp_high = *exp; | |
3855 | ||
3856 | exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16; | |
3857 | emit_expr (& exp_high, (unsigned int) THUMB_SIZE); | |
3858 | exp->X_add_number &= 0xffff; | |
3859 | emit_expr (exp, (unsigned int) THUMB_SIZE); | |
3860 | } | |
3861 | ||
3862 | /* Guess the instruction size based on the opcode. */ | |
3863 | ||
3864 | static int | |
3865 | thumb_insn_size (int opcode) | |
3866 | { | |
3867 | if ((unsigned int) opcode < 0xe800u) | |
3868 | return 2; | |
3869 | else if ((unsigned int) opcode >= 0xe8000000u) | |
3870 | return 4; | |
3871 | else | |
3872 | return 0; | |
3873 | } | |
3874 | ||
3875 | static bfd_boolean | |
3876 | emit_insn (expressionS *exp, int nbytes) | |
3877 | { | |
3878 | int size = 0; | |
3879 | ||
3880 | if (exp->X_op == O_constant) | |
3881 | { | |
3882 | size = nbytes; | |
3883 | ||
3884 | if (size == 0) | |
3885 | size = thumb_insn_size (exp->X_add_number); | |
3886 | ||
3887 | if (size != 0) | |
3888 | { | |
3889 | if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu) | |
3890 | { | |
3891 | as_bad (_(".inst.n operand too big. "\ | |
3892 | "Use .inst.w instead")); | |
3893 | size = 0; | |
3894 | } | |
3895 | else | |
3896 | { | |
5ee91343 AV |
3897 | if (now_pred.state == AUTOMATIC_PRED_BLOCK) |
3898 | set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0); | |
c921be7d | 3899 | else |
5ee91343 | 3900 | set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0); |
c921be7d NC |
3901 | |
3902 | if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian) | |
3903 | emit_thumb32_expr (exp); | |
3904 | else | |
3905 | emit_expr (exp, (unsigned int) size); | |
3906 | ||
3907 | it_fsm_post_encode (); | |
3908 | } | |
3909 | } | |
3910 | else | |
3911 | as_bad (_("cannot determine Thumb instruction size. " \ | |
3912 | "Use .inst.n/.inst.w instead")); | |
3913 | } | |
3914 | else | |
3915 | as_bad (_("constant expression required")); | |
3916 | ||
3917 | return (size != 0); | |
3918 | } | |
3919 | ||
3920 | /* Like s_arm_elf_cons but do not use md_cons_align and | |
3921 | set the mapping state to MAP_ARM/MAP_THUMB. */ | |
3922 | ||
3923 | static void | |
3924 | s_arm_elf_inst (int nbytes) | |
3925 | { | |
3926 | if (is_it_end_of_statement ()) | |
3927 | { | |
3928 | demand_empty_rest_of_line (); | |
3929 | return; | |
3930 | } | |
3931 | ||
3932 | /* Calling mapping_state () here will not change ARM/THUMB, | |
3933 | but will ensure not to be in DATA state. */ | |
3934 | ||
3935 | if (thumb_mode) | |
3936 | mapping_state (MAP_THUMB); | |
3937 | else | |
3938 | { | |
3939 | if (nbytes != 0) | |
3940 | { | |
3941 | as_bad (_("width suffixes are invalid in ARM mode")); | |
3942 | ignore_rest_of_line (); | |
3943 | return; | |
3944 | } | |
3945 | ||
3946 | nbytes = 4; | |
3947 | ||
3948 | mapping_state (MAP_ARM); | |
3949 | } | |
3950 | ||
3951 | do | |
3952 | { | |
3953 | expressionS exp; | |
3954 | ||
3955 | expression (& exp); | |
3956 | ||
3957 | if (! emit_insn (& exp, nbytes)) | |
3958 | { | |
3959 | ignore_rest_of_line (); | |
3960 | return; | |
3961 | } | |
3962 | } | |
3963 | while (*input_line_pointer++ == ','); | |
3964 | ||
3965 | /* Put terminator back into stream. */ | |
3966 | input_line_pointer --; | |
3967 | demand_empty_rest_of_line (); | |
3968 | } | |
b99bd4ef | 3969 | |
c19d1205 | 3970 | /* Parse a .rel31 directive. */ |
b99bd4ef | 3971 | |
c19d1205 ZW |
3972 | static void |
3973 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
3974 | { | |
3975 | expressionS exp; | |
3976 | char *p; | |
3977 | valueT highbit; | |
b99bd4ef | 3978 | |
c19d1205 ZW |
3979 | highbit = 0; |
3980 | if (*input_line_pointer == '1') | |
3981 | highbit = 0x80000000; | |
3982 | else if (*input_line_pointer != '0') | |
3983 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 3984 | |
c19d1205 ZW |
3985 | input_line_pointer++; |
3986 | if (*input_line_pointer != ',') | |
3987 | as_bad (_("missing comma")); | |
3988 | input_line_pointer++; | |
b99bd4ef | 3989 | |
c19d1205 ZW |
3990 | #ifdef md_flush_pending_output |
3991 | md_flush_pending_output (); | |
3992 | #endif | |
b99bd4ef | 3993 | |
c19d1205 ZW |
3994 | #ifdef md_cons_align |
3995 | md_cons_align (4); | |
3996 | #endif | |
b99bd4ef | 3997 | |
c19d1205 | 3998 | mapping_state (MAP_DATA); |
b99bd4ef | 3999 | |
c19d1205 | 4000 | expression (&exp); |
b99bd4ef | 4001 | |
c19d1205 ZW |
4002 | p = frag_more (4); |
4003 | md_number_to_chars (p, highbit, 4); | |
4004 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
4005 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 4006 | |
c19d1205 | 4007 | demand_empty_rest_of_line (); |
b99bd4ef NC |
4008 | } |
4009 | ||
c19d1205 | 4010 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 4011 | |
c19d1205 | 4012 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 4013 | |
c19d1205 ZW |
4014 | static void |
4015 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
4016 | { | |
4017 | demand_empty_rest_of_line (); | |
921e5f0a PB |
4018 | if (unwind.proc_start) |
4019 | { | |
c921be7d | 4020 | as_bad (_("duplicate .fnstart directive")); |
921e5f0a PB |
4021 | return; |
4022 | } | |
4023 | ||
c19d1205 ZW |
4024 | /* Mark the start of the function. */ |
4025 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 4026 | |
c19d1205 ZW |
4027 | /* Reset the rest of the unwind info. */ |
4028 | unwind.opcode_count = 0; | |
4029 | unwind.table_entry = NULL; | |
4030 | unwind.personality_routine = NULL; | |
4031 | unwind.personality_index = -1; | |
4032 | unwind.frame_size = 0; | |
4033 | unwind.fp_offset = 0; | |
fdfde340 | 4034 | unwind.fp_reg = REG_SP; |
c19d1205 ZW |
4035 | unwind.fp_used = 0; |
4036 | unwind.sp_restored = 0; | |
4037 | } | |
b99bd4ef | 4038 | |
b99bd4ef | 4039 | |
c19d1205 ZW |
4040 | /* Parse a handlerdata directive. Creates the exception handling table entry |
4041 | for the function. */ | |
b99bd4ef | 4042 | |
c19d1205 ZW |
4043 | static void |
4044 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
4045 | { | |
4046 | demand_empty_rest_of_line (); | |
921e5f0a | 4047 | if (!unwind.proc_start) |
c921be7d | 4048 | as_bad (MISSING_FNSTART); |
921e5f0a | 4049 | |
c19d1205 | 4050 | if (unwind.table_entry) |
6decc662 | 4051 | as_bad (_("duplicate .handlerdata directive")); |
f02232aa | 4052 | |
c19d1205 ZW |
4053 | create_unwind_entry (1); |
4054 | } | |
a737bd4d | 4055 | |
c19d1205 | 4056 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 4057 | |
c19d1205 ZW |
4058 | static void |
4059 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
4060 | { | |
4061 | long where; | |
4062 | char *ptr; | |
4063 | valueT val; | |
940b5ce0 | 4064 | unsigned int marked_pr_dependency; |
f02232aa | 4065 | |
c19d1205 | 4066 | demand_empty_rest_of_line (); |
f02232aa | 4067 | |
921e5f0a PB |
4068 | if (!unwind.proc_start) |
4069 | { | |
c921be7d | 4070 | as_bad (_(".fnend directive without .fnstart")); |
921e5f0a PB |
4071 | return; |
4072 | } | |
4073 | ||
c19d1205 ZW |
4074 | /* Add eh table entry. */ |
4075 | if (unwind.table_entry == NULL) | |
4076 | val = create_unwind_entry (0); | |
4077 | else | |
4078 | val = 0; | |
f02232aa | 4079 | |
c19d1205 ZW |
4080 | /* Add index table entry. This is two words. */ |
4081 | start_unwind_section (unwind.saved_seg, 1); | |
4082 | frag_align (2, 0, 0); | |
4083 | record_alignment (now_seg, 2); | |
b99bd4ef | 4084 | |
c19d1205 | 4085 | ptr = frag_more (8); |
5011093d | 4086 | memset (ptr, 0, 8); |
c19d1205 | 4087 | where = frag_now_fix () - 8; |
f02232aa | 4088 | |
c19d1205 ZW |
4089 | /* Self relative offset of the function start. */ |
4090 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
4091 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 4092 | |
c19d1205 ZW |
4093 | /* Indicate dependency on EHABI-defined personality routines to the |
4094 | linker, if it hasn't been done already. */ | |
940b5ce0 DJ |
4095 | marked_pr_dependency |
4096 | = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency; | |
c19d1205 ZW |
4097 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 |
4098 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
4099 | { | |
5f4273c7 NC |
4100 | static const char *const name[] = |
4101 | { | |
4102 | "__aeabi_unwind_cpp_pr0", | |
4103 | "__aeabi_unwind_cpp_pr1", | |
4104 | "__aeabi_unwind_cpp_pr2" | |
4105 | }; | |
c19d1205 ZW |
4106 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); |
4107 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
c19d1205 | 4108 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency |
940b5ce0 | 4109 | |= 1 << unwind.personality_index; |
c19d1205 | 4110 | } |
f02232aa | 4111 | |
c19d1205 ZW |
4112 | if (val) |
4113 | /* Inline exception table entry. */ | |
4114 | md_number_to_chars (ptr + 4, val, 4); | |
4115 | else | |
4116 | /* Self relative offset of the table entry. */ | |
4117 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
4118 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 4119 | |
c19d1205 ZW |
4120 | /* Restore the original section. */ |
4121 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
921e5f0a PB |
4122 | |
4123 | unwind.proc_start = NULL; | |
c19d1205 | 4124 | } |
f02232aa | 4125 | |
f02232aa | 4126 | |
c19d1205 | 4127 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 4128 | |
c19d1205 ZW |
4129 | static void |
4130 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
4131 | { | |
4132 | demand_empty_rest_of_line (); | |
921e5f0a | 4133 | if (!unwind.proc_start) |
c921be7d | 4134 | as_bad (MISSING_FNSTART); |
921e5f0a | 4135 | |
c19d1205 ZW |
4136 | if (unwind.personality_routine || unwind.personality_index != -1) |
4137 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 4138 | |
c19d1205 ZW |
4139 | unwind.personality_index = -2; |
4140 | } | |
b99bd4ef | 4141 | |
b99bd4ef | 4142 | |
c19d1205 | 4143 | /* Parse a personalityindex directive. */ |
b99bd4ef | 4144 | |
c19d1205 ZW |
4145 | static void |
4146 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
4147 | { | |
4148 | expressionS exp; | |
b99bd4ef | 4149 | |
921e5f0a | 4150 | if (!unwind.proc_start) |
c921be7d | 4151 | as_bad (MISSING_FNSTART); |
921e5f0a | 4152 | |
c19d1205 ZW |
4153 | if (unwind.personality_routine || unwind.personality_index != -1) |
4154 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 4155 | |
c19d1205 | 4156 | expression (&exp); |
b99bd4ef | 4157 | |
c19d1205 ZW |
4158 | if (exp.X_op != O_constant |
4159 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 4160 | { |
c19d1205 ZW |
4161 | as_bad (_("bad personality routine number")); |
4162 | ignore_rest_of_line (); | |
4163 | return; | |
b99bd4ef NC |
4164 | } |
4165 | ||
c19d1205 | 4166 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 4167 | |
c19d1205 ZW |
4168 | demand_empty_rest_of_line (); |
4169 | } | |
e16bb312 | 4170 | |
e16bb312 | 4171 | |
c19d1205 | 4172 | /* Parse a personality directive. */ |
e16bb312 | 4173 | |
c19d1205 ZW |
4174 | static void |
4175 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
4176 | { | |
4177 | char *name, *p, c; | |
a737bd4d | 4178 | |
921e5f0a | 4179 | if (!unwind.proc_start) |
c921be7d | 4180 | as_bad (MISSING_FNSTART); |
921e5f0a | 4181 | |
c19d1205 ZW |
4182 | if (unwind.personality_routine || unwind.personality_index != -1) |
4183 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 4184 | |
d02603dc | 4185 | c = get_symbol_name (& name); |
c19d1205 | 4186 | p = input_line_pointer; |
d02603dc NC |
4187 | if (c == '"') |
4188 | ++ input_line_pointer; | |
c19d1205 ZW |
4189 | unwind.personality_routine = symbol_find_or_make (name); |
4190 | *p = c; | |
4191 | demand_empty_rest_of_line (); | |
4192 | } | |
e16bb312 | 4193 | |
e16bb312 | 4194 | |
c19d1205 | 4195 | /* Parse a directive saving core registers. */ |
e16bb312 | 4196 | |
c19d1205 ZW |
4197 | static void |
4198 | s_arm_unwind_save_core (void) | |
e16bb312 | 4199 | { |
c19d1205 ZW |
4200 | valueT op; |
4201 | long range; | |
4202 | int n; | |
e16bb312 | 4203 | |
4b5a202f | 4204 | range = parse_reg_list (&input_line_pointer, REGLIST_RN); |
c19d1205 | 4205 | if (range == FAIL) |
e16bb312 | 4206 | { |
c19d1205 ZW |
4207 | as_bad (_("expected register list")); |
4208 | ignore_rest_of_line (); | |
4209 | return; | |
4210 | } | |
e16bb312 | 4211 | |
c19d1205 | 4212 | demand_empty_rest_of_line (); |
e16bb312 | 4213 | |
c19d1205 ZW |
4214 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
4215 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
4216 | ip because it is clobbered by calls. */ | |
4217 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
4218 | && (range & 0x3000) == 0x1000) | |
4219 | { | |
4220 | unwind.opcode_count--; | |
4221 | unwind.sp_restored = 0; | |
4222 | range = (range | 0x2000) & ~0x1000; | |
4223 | unwind.pending_offset = 0; | |
4224 | } | |
e16bb312 | 4225 | |
01ae4198 DJ |
4226 | /* Pop r4-r15. */ |
4227 | if (range & 0xfff0) | |
c19d1205 | 4228 | { |
01ae4198 DJ |
4229 | /* See if we can use the short opcodes. These pop a block of up to 8 |
4230 | registers starting with r4, plus maybe r14. */ | |
4231 | for (n = 0; n < 8; n++) | |
4232 | { | |
4233 | /* Break at the first non-saved register. */ | |
4234 | if ((range & (1 << (n + 4))) == 0) | |
4235 | break; | |
4236 | } | |
4237 | /* See if there are any other bits set. */ | |
4238 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
4239 | { | |
4240 | /* Use the long form. */ | |
4241 | op = 0x8000 | ((range >> 4) & 0xfff); | |
4242 | add_unwind_opcode (op, 2); | |
4243 | } | |
0dd132b6 | 4244 | else |
01ae4198 DJ |
4245 | { |
4246 | /* Use the short form. */ | |
4247 | if (range & 0x4000) | |
4248 | op = 0xa8; /* Pop r14. */ | |
4249 | else | |
4250 | op = 0xa0; /* Do not pop r14. */ | |
4251 | op |= (n - 1); | |
4252 | add_unwind_opcode (op, 1); | |
4253 | } | |
c19d1205 | 4254 | } |
0dd132b6 | 4255 | |
c19d1205 ZW |
4256 | /* Pop r0-r3. */ |
4257 | if (range & 0xf) | |
4258 | { | |
4259 | op = 0xb100 | (range & 0xf); | |
4260 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
4261 | } |
4262 | ||
c19d1205 ZW |
4263 | /* Record the number of bytes pushed. */ |
4264 | for (n = 0; n < 16; n++) | |
4265 | { | |
4266 | if (range & (1 << n)) | |
4267 | unwind.frame_size += 4; | |
4268 | } | |
0dd132b6 NC |
4269 | } |
4270 | ||
c19d1205 ZW |
4271 | |
4272 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
4273 | |
4274 | static void | |
c19d1205 | 4275 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 4276 | { |
c19d1205 ZW |
4277 | expressionS exp; |
4278 | int num_regs; | |
4279 | valueT op; | |
b99bd4ef | 4280 | |
c19d1205 ZW |
4281 | /* Get Number of registers to transfer. */ |
4282 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4283 | expression (&exp); | |
4284 | else | |
4285 | exp.X_op = O_illegal; | |
b99bd4ef | 4286 | |
c19d1205 | 4287 | if (exp.X_op != O_constant) |
b99bd4ef | 4288 | { |
c19d1205 ZW |
4289 | as_bad (_("expected , <constant>")); |
4290 | ignore_rest_of_line (); | |
b99bd4ef NC |
4291 | return; |
4292 | } | |
4293 | ||
c19d1205 ZW |
4294 | num_regs = exp.X_add_number; |
4295 | ||
4296 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 4297 | { |
c19d1205 ZW |
4298 | as_bad (_("number of registers must be in the range [1:4]")); |
4299 | ignore_rest_of_line (); | |
b99bd4ef NC |
4300 | return; |
4301 | } | |
4302 | ||
c19d1205 | 4303 | demand_empty_rest_of_line (); |
b99bd4ef | 4304 | |
c19d1205 ZW |
4305 | if (reg == 4) |
4306 | { | |
4307 | /* Short form. */ | |
4308 | op = 0xb4 | (num_regs - 1); | |
4309 | add_unwind_opcode (op, 1); | |
4310 | } | |
b99bd4ef NC |
4311 | else |
4312 | { | |
c19d1205 ZW |
4313 | /* Long form. */ |
4314 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
4315 | add_unwind_opcode (op, 2); | |
b99bd4ef | 4316 | } |
c19d1205 | 4317 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
4318 | } |
4319 | ||
c19d1205 | 4320 | |
fa073d69 MS |
4321 | /* Parse a directive saving VFP registers for ARMv6 and above. */ |
4322 | ||
4323 | static void | |
4324 | s_arm_unwind_save_vfp_armv6 (void) | |
4325 | { | |
4326 | int count; | |
4327 | unsigned int start; | |
4328 | valueT op; | |
4329 | int num_vfpv3_regs = 0; | |
4330 | int num_regs_below_16; | |
efd6b359 | 4331 | bfd_boolean partial_match; |
fa073d69 | 4332 | |
efd6b359 AV |
4333 | count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D, |
4334 | &partial_match); | |
fa073d69 MS |
4335 | if (count == FAIL) |
4336 | { | |
4337 | as_bad (_("expected register list")); | |
4338 | ignore_rest_of_line (); | |
4339 | return; | |
4340 | } | |
4341 | ||
4342 | demand_empty_rest_of_line (); | |
4343 | ||
4344 | /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather | |
4345 | than FSTMX/FLDMX-style ones). */ | |
4346 | ||
4347 | /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */ | |
4348 | if (start >= 16) | |
4349 | num_vfpv3_regs = count; | |
4350 | else if (start + count > 16) | |
4351 | num_vfpv3_regs = start + count - 16; | |
4352 | ||
4353 | if (num_vfpv3_regs > 0) | |
4354 | { | |
4355 | int start_offset = start > 16 ? start - 16 : 0; | |
4356 | op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1); | |
4357 | add_unwind_opcode (op, 2); | |
4358 | } | |
4359 | ||
4360 | /* Generate opcode for registers numbered in the range 0 .. 15. */ | |
4361 | num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count; | |
9c2799c2 | 4362 | gas_assert (num_regs_below_16 + num_vfpv3_regs == count); |
fa073d69 MS |
4363 | if (num_regs_below_16 > 0) |
4364 | { | |
4365 | op = 0xc900 | (start << 4) | (num_regs_below_16 - 1); | |
4366 | add_unwind_opcode (op, 2); | |
4367 | } | |
4368 | ||
4369 | unwind.frame_size += count * 8; | |
4370 | } | |
4371 | ||
4372 | ||
4373 | /* Parse a directive saving VFP registers for pre-ARMv6. */ | |
b99bd4ef NC |
4374 | |
4375 | static void | |
c19d1205 | 4376 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 4377 | { |
c19d1205 | 4378 | int count; |
ca3f61f7 | 4379 | unsigned int reg; |
c19d1205 | 4380 | valueT op; |
efd6b359 | 4381 | bfd_boolean partial_match; |
b99bd4ef | 4382 | |
efd6b359 AV |
4383 | count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D, |
4384 | &partial_match); | |
c19d1205 | 4385 | if (count == FAIL) |
b99bd4ef | 4386 | { |
c19d1205 ZW |
4387 | as_bad (_("expected register list")); |
4388 | ignore_rest_of_line (); | |
b99bd4ef NC |
4389 | return; |
4390 | } | |
4391 | ||
c19d1205 | 4392 | demand_empty_rest_of_line (); |
b99bd4ef | 4393 | |
c19d1205 | 4394 | if (reg == 8) |
b99bd4ef | 4395 | { |
c19d1205 ZW |
4396 | /* Short form. */ |
4397 | op = 0xb8 | (count - 1); | |
4398 | add_unwind_opcode (op, 1); | |
b99bd4ef | 4399 | } |
c19d1205 | 4400 | else |
b99bd4ef | 4401 | { |
c19d1205 ZW |
4402 | /* Long form. */ |
4403 | op = 0xb300 | (reg << 4) | (count - 1); | |
4404 | add_unwind_opcode (op, 2); | |
b99bd4ef | 4405 | } |
c19d1205 ZW |
4406 | unwind.frame_size += count * 8 + 4; |
4407 | } | |
b99bd4ef | 4408 | |
b99bd4ef | 4409 | |
c19d1205 ZW |
4410 | /* Parse a directive saving iWMMXt data registers. */ |
4411 | ||
4412 | static void | |
4413 | s_arm_unwind_save_mmxwr (void) | |
4414 | { | |
4415 | int reg; | |
4416 | int hi_reg; | |
4417 | int i; | |
4418 | unsigned mask = 0; | |
4419 | valueT op; | |
b99bd4ef | 4420 | |
c19d1205 ZW |
4421 | if (*input_line_pointer == '{') |
4422 | input_line_pointer++; | |
b99bd4ef | 4423 | |
c19d1205 | 4424 | do |
b99bd4ef | 4425 | { |
dcbf9037 | 4426 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 4427 | |
c19d1205 | 4428 | if (reg == FAIL) |
b99bd4ef | 4429 | { |
9b7132d3 | 4430 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 | 4431 | goto error; |
b99bd4ef NC |
4432 | } |
4433 | ||
c19d1205 ZW |
4434 | if (mask >> reg) |
4435 | as_tsktsk (_("register list not in ascending order")); | |
4436 | mask |= 1 << reg; | |
b99bd4ef | 4437 | |
c19d1205 ZW |
4438 | if (*input_line_pointer == '-') |
4439 | { | |
4440 | input_line_pointer++; | |
dcbf9037 | 4441 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
c19d1205 ZW |
4442 | if (hi_reg == FAIL) |
4443 | { | |
9b7132d3 | 4444 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 ZW |
4445 | goto error; |
4446 | } | |
4447 | else if (reg >= hi_reg) | |
4448 | { | |
4449 | as_bad (_("bad register range")); | |
4450 | goto error; | |
4451 | } | |
4452 | for (; reg < hi_reg; reg++) | |
4453 | mask |= 1 << reg; | |
4454 | } | |
4455 | } | |
4456 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 4457 | |
d996d970 | 4458 | skip_past_char (&input_line_pointer, '}'); |
b99bd4ef | 4459 | |
c19d1205 | 4460 | demand_empty_rest_of_line (); |
b99bd4ef | 4461 | |
708587a4 | 4462 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
4463 | the list. */ |
4464 | flush_pending_unwind (); | |
b99bd4ef | 4465 | |
c19d1205 | 4466 | for (i = 0; i < 16; i++) |
b99bd4ef | 4467 | { |
c19d1205 ZW |
4468 | if (mask & (1 << i)) |
4469 | unwind.frame_size += 8; | |
b99bd4ef NC |
4470 | } |
4471 | ||
c19d1205 ZW |
4472 | /* Attempt to combine with a previous opcode. We do this because gcc |
4473 | likes to output separate unwind directives for a single block of | |
4474 | registers. */ | |
4475 | if (unwind.opcode_count > 0) | |
b99bd4ef | 4476 | { |
c19d1205 ZW |
4477 | i = unwind.opcodes[unwind.opcode_count - 1]; |
4478 | if ((i & 0xf8) == 0xc0) | |
4479 | { | |
4480 | i &= 7; | |
4481 | /* Only merge if the blocks are contiguous. */ | |
4482 | if (i < 6) | |
4483 | { | |
4484 | if ((mask & 0xfe00) == (1 << 9)) | |
4485 | { | |
4486 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
4487 | unwind.opcode_count--; | |
4488 | } | |
4489 | } | |
4490 | else if (i == 6 && unwind.opcode_count >= 2) | |
4491 | { | |
4492 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
4493 | reg = i >> 4; | |
4494 | i &= 0xf; | |
b99bd4ef | 4495 | |
c19d1205 ZW |
4496 | op = 0xffff << (reg - 1); |
4497 | if (reg > 0 | |
87a1fd79 | 4498 | && ((mask & op) == (1u << (reg - 1)))) |
c19d1205 ZW |
4499 | { |
4500 | op = (1 << (reg + i + 1)) - 1; | |
4501 | op &= ~((1 << reg) - 1); | |
4502 | mask |= op; | |
4503 | unwind.opcode_count -= 2; | |
4504 | } | |
4505 | } | |
4506 | } | |
b99bd4ef NC |
4507 | } |
4508 | ||
c19d1205 ZW |
4509 | hi_reg = 15; |
4510 | /* We want to generate opcodes in the order the registers have been | |
4511 | saved, ie. descending order. */ | |
4512 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 4513 | { |
c19d1205 ZW |
4514 | /* Save registers in blocks. */ |
4515 | if (reg < 0 | |
4516 | || !(mask & (1 << reg))) | |
4517 | { | |
4518 | /* We found an unsaved reg. Generate opcodes to save the | |
5f4273c7 | 4519 | preceding block. */ |
c19d1205 ZW |
4520 | if (reg != hi_reg) |
4521 | { | |
4522 | if (reg == 9) | |
4523 | { | |
4524 | /* Short form. */ | |
4525 | op = 0xc0 | (hi_reg - 10); | |
4526 | add_unwind_opcode (op, 1); | |
4527 | } | |
4528 | else | |
4529 | { | |
4530 | /* Long form. */ | |
4531 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
4532 | add_unwind_opcode (op, 2); | |
4533 | } | |
4534 | } | |
4535 | hi_reg = reg - 1; | |
4536 | } | |
b99bd4ef NC |
4537 | } |
4538 | ||
c19d1205 ZW |
4539 | return; |
4540 | error: | |
4541 | ignore_rest_of_line (); | |
b99bd4ef NC |
4542 | } |
4543 | ||
4544 | static void | |
c19d1205 | 4545 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 4546 | { |
c19d1205 ZW |
4547 | int reg; |
4548 | int hi_reg; | |
4549 | unsigned mask = 0; | |
4550 | valueT op; | |
b99bd4ef | 4551 | |
c19d1205 ZW |
4552 | if (*input_line_pointer == '{') |
4553 | input_line_pointer++; | |
b99bd4ef | 4554 | |
477330fc RM |
4555 | skip_whitespace (input_line_pointer); |
4556 | ||
c19d1205 | 4557 | do |
b99bd4ef | 4558 | { |
dcbf9037 | 4559 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 4560 | |
c19d1205 ZW |
4561 | if (reg == FAIL) |
4562 | { | |
9b7132d3 | 4563 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
4564 | goto error; |
4565 | } | |
b99bd4ef | 4566 | |
c19d1205 ZW |
4567 | reg -= 8; |
4568 | if (mask >> reg) | |
4569 | as_tsktsk (_("register list not in ascending order")); | |
4570 | mask |= 1 << reg; | |
b99bd4ef | 4571 | |
c19d1205 ZW |
4572 | if (*input_line_pointer == '-') |
4573 | { | |
4574 | input_line_pointer++; | |
dcbf9037 | 4575 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
c19d1205 ZW |
4576 | if (hi_reg == FAIL) |
4577 | { | |
9b7132d3 | 4578 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
4579 | goto error; |
4580 | } | |
4581 | else if (reg >= hi_reg) | |
4582 | { | |
4583 | as_bad (_("bad register range")); | |
4584 | goto error; | |
4585 | } | |
4586 | for (; reg < hi_reg; reg++) | |
4587 | mask |= 1 << reg; | |
4588 | } | |
b99bd4ef | 4589 | } |
c19d1205 | 4590 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 4591 | |
d996d970 | 4592 | skip_past_char (&input_line_pointer, '}'); |
b99bd4ef | 4593 | |
c19d1205 ZW |
4594 | demand_empty_rest_of_line (); |
4595 | ||
708587a4 | 4596 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
4597 | the list. */ |
4598 | flush_pending_unwind (); | |
b99bd4ef | 4599 | |
c19d1205 | 4600 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 4601 | { |
c19d1205 ZW |
4602 | if (mask & (1 << reg)) |
4603 | unwind.frame_size += 4; | |
b99bd4ef | 4604 | } |
c19d1205 ZW |
4605 | op = 0xc700 | mask; |
4606 | add_unwind_opcode (op, 2); | |
4607 | return; | |
4608 | error: | |
4609 | ignore_rest_of_line (); | |
b99bd4ef NC |
4610 | } |
4611 | ||
c19d1205 | 4612 | |
fa073d69 MS |
4613 | /* Parse an unwind_save directive. |
4614 | If the argument is non-zero, this is a .vsave directive. */ | |
c19d1205 | 4615 | |
b99bd4ef | 4616 | static void |
fa073d69 | 4617 | s_arm_unwind_save (int arch_v6) |
b99bd4ef | 4618 | { |
c19d1205 ZW |
4619 | char *peek; |
4620 | struct reg_entry *reg; | |
4621 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 4622 | |
921e5f0a | 4623 | if (!unwind.proc_start) |
c921be7d | 4624 | as_bad (MISSING_FNSTART); |
921e5f0a | 4625 | |
c19d1205 ZW |
4626 | /* Figure out what sort of save we have. */ |
4627 | peek = input_line_pointer; | |
b99bd4ef | 4628 | |
c19d1205 | 4629 | if (*peek == '{') |
b99bd4ef | 4630 | { |
c19d1205 ZW |
4631 | had_brace = TRUE; |
4632 | peek++; | |
b99bd4ef NC |
4633 | } |
4634 | ||
c19d1205 | 4635 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 4636 | |
c19d1205 | 4637 | if (!reg) |
b99bd4ef | 4638 | { |
c19d1205 ZW |
4639 | as_bad (_("register expected")); |
4640 | ignore_rest_of_line (); | |
b99bd4ef NC |
4641 | return; |
4642 | } | |
4643 | ||
c19d1205 | 4644 | switch (reg->type) |
b99bd4ef | 4645 | { |
c19d1205 ZW |
4646 | case REG_TYPE_FN: |
4647 | if (had_brace) | |
4648 | { | |
4649 | as_bad (_("FPA .unwind_save does not take a register list")); | |
4650 | ignore_rest_of_line (); | |
4651 | return; | |
4652 | } | |
93ac2687 | 4653 | input_line_pointer = peek; |
c19d1205 | 4654 | s_arm_unwind_save_fpa (reg->number); |
b99bd4ef | 4655 | return; |
c19d1205 | 4656 | |
1f5afe1c NC |
4657 | case REG_TYPE_RN: |
4658 | s_arm_unwind_save_core (); | |
4659 | return; | |
4660 | ||
fa073d69 MS |
4661 | case REG_TYPE_VFD: |
4662 | if (arch_v6) | |
477330fc | 4663 | s_arm_unwind_save_vfp_armv6 (); |
fa073d69 | 4664 | else |
477330fc | 4665 | s_arm_unwind_save_vfp (); |
fa073d69 | 4666 | return; |
1f5afe1c NC |
4667 | |
4668 | case REG_TYPE_MMXWR: | |
4669 | s_arm_unwind_save_mmxwr (); | |
4670 | return; | |
4671 | ||
4672 | case REG_TYPE_MMXWCG: | |
4673 | s_arm_unwind_save_mmxwcg (); | |
4674 | return; | |
c19d1205 ZW |
4675 | |
4676 | default: | |
4677 | as_bad (_(".unwind_save does not support this kind of register")); | |
4678 | ignore_rest_of_line (); | |
b99bd4ef | 4679 | } |
c19d1205 | 4680 | } |
b99bd4ef | 4681 | |
b99bd4ef | 4682 | |
c19d1205 ZW |
4683 | /* Parse an unwind_movsp directive. */ |
4684 | ||
4685 | static void | |
4686 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
4687 | { | |
4688 | int reg; | |
4689 | valueT op; | |
4fa3602b | 4690 | int offset; |
c19d1205 | 4691 | |
921e5f0a | 4692 | if (!unwind.proc_start) |
c921be7d | 4693 | as_bad (MISSING_FNSTART); |
921e5f0a | 4694 | |
dcbf9037 | 4695 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 | 4696 | if (reg == FAIL) |
b99bd4ef | 4697 | { |
9b7132d3 | 4698 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 | 4699 | ignore_rest_of_line (); |
b99bd4ef NC |
4700 | return; |
4701 | } | |
4fa3602b PB |
4702 | |
4703 | /* Optional constant. */ | |
4704 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4705 | { | |
4706 | if (immediate_for_directive (&offset) == FAIL) | |
4707 | return; | |
4708 | } | |
4709 | else | |
4710 | offset = 0; | |
4711 | ||
c19d1205 | 4712 | demand_empty_rest_of_line (); |
b99bd4ef | 4713 | |
c19d1205 | 4714 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 4715 | { |
c19d1205 | 4716 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
4717 | return; |
4718 | } | |
4719 | ||
c19d1205 ZW |
4720 | if (unwind.fp_reg != REG_SP) |
4721 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 4722 | |
c19d1205 ZW |
4723 | /* Generate opcode to restore the value. */ |
4724 | op = 0x90 | reg; | |
4725 | add_unwind_opcode (op, 1); | |
4726 | ||
4727 | /* Record the information for later. */ | |
4728 | unwind.fp_reg = reg; | |
4fa3602b | 4729 | unwind.fp_offset = unwind.frame_size - offset; |
c19d1205 | 4730 | unwind.sp_restored = 1; |
b05fe5cf ZW |
4731 | } |
4732 | ||
c19d1205 ZW |
4733 | /* Parse an unwind_pad directive. */ |
4734 | ||
b05fe5cf | 4735 | static void |
c19d1205 | 4736 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 4737 | { |
c19d1205 | 4738 | int offset; |
b05fe5cf | 4739 | |
921e5f0a | 4740 | if (!unwind.proc_start) |
c921be7d | 4741 | as_bad (MISSING_FNSTART); |
921e5f0a | 4742 | |
c19d1205 ZW |
4743 | if (immediate_for_directive (&offset) == FAIL) |
4744 | return; | |
b99bd4ef | 4745 | |
c19d1205 ZW |
4746 | if (offset & 3) |
4747 | { | |
4748 | as_bad (_("stack increment must be multiple of 4")); | |
4749 | ignore_rest_of_line (); | |
4750 | return; | |
4751 | } | |
b99bd4ef | 4752 | |
c19d1205 ZW |
4753 | /* Don't generate any opcodes, just record the details for later. */ |
4754 | unwind.frame_size += offset; | |
4755 | unwind.pending_offset += offset; | |
4756 | ||
4757 | demand_empty_rest_of_line (); | |
4758 | } | |
4759 | ||
4760 | /* Parse an unwind_setfp directive. */ | |
4761 | ||
4762 | static void | |
4763 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 4764 | { |
c19d1205 ZW |
4765 | int sp_reg; |
4766 | int fp_reg; | |
4767 | int offset; | |
4768 | ||
921e5f0a | 4769 | if (!unwind.proc_start) |
c921be7d | 4770 | as_bad (MISSING_FNSTART); |
921e5f0a | 4771 | |
dcbf9037 | 4772 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 ZW |
4773 | if (skip_past_comma (&input_line_pointer) == FAIL) |
4774 | sp_reg = FAIL; | |
4775 | else | |
dcbf9037 | 4776 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
b99bd4ef | 4777 | |
c19d1205 ZW |
4778 | if (fp_reg == FAIL || sp_reg == FAIL) |
4779 | { | |
4780 | as_bad (_("expected <reg>, <reg>")); | |
4781 | ignore_rest_of_line (); | |
4782 | return; | |
4783 | } | |
b99bd4ef | 4784 | |
c19d1205 ZW |
4785 | /* Optional constant. */ |
4786 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4787 | { | |
4788 | if (immediate_for_directive (&offset) == FAIL) | |
4789 | return; | |
4790 | } | |
4791 | else | |
4792 | offset = 0; | |
a737bd4d | 4793 | |
c19d1205 | 4794 | demand_empty_rest_of_line (); |
a737bd4d | 4795 | |
fdfde340 | 4796 | if (sp_reg != REG_SP && sp_reg != unwind.fp_reg) |
a737bd4d | 4797 | { |
c19d1205 ZW |
4798 | as_bad (_("register must be either sp or set by a previous" |
4799 | "unwind_movsp directive")); | |
4800 | return; | |
a737bd4d NC |
4801 | } |
4802 | ||
c19d1205 ZW |
4803 | /* Don't generate any opcodes, just record the information for later. */ |
4804 | unwind.fp_reg = fp_reg; | |
4805 | unwind.fp_used = 1; | |
fdfde340 | 4806 | if (sp_reg == REG_SP) |
c19d1205 ZW |
4807 | unwind.fp_offset = unwind.frame_size - offset; |
4808 | else | |
4809 | unwind.fp_offset -= offset; | |
a737bd4d NC |
4810 | } |
4811 | ||
c19d1205 ZW |
4812 | /* Parse an unwind_raw directive. */ |
4813 | ||
4814 | static void | |
4815 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 4816 | { |
c19d1205 | 4817 | expressionS exp; |
708587a4 | 4818 | /* This is an arbitrary limit. */ |
c19d1205 ZW |
4819 | unsigned char op[16]; |
4820 | int count; | |
a737bd4d | 4821 | |
921e5f0a | 4822 | if (!unwind.proc_start) |
c921be7d | 4823 | as_bad (MISSING_FNSTART); |
921e5f0a | 4824 | |
c19d1205 ZW |
4825 | expression (&exp); |
4826 | if (exp.X_op == O_constant | |
4827 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 4828 | { |
c19d1205 ZW |
4829 | unwind.frame_size += exp.X_add_number; |
4830 | expression (&exp); | |
4831 | } | |
4832 | else | |
4833 | exp.X_op = O_illegal; | |
a737bd4d | 4834 | |
c19d1205 ZW |
4835 | if (exp.X_op != O_constant) |
4836 | { | |
4837 | as_bad (_("expected <offset>, <opcode>")); | |
4838 | ignore_rest_of_line (); | |
4839 | return; | |
4840 | } | |
a737bd4d | 4841 | |
c19d1205 | 4842 | count = 0; |
a737bd4d | 4843 | |
c19d1205 ZW |
4844 | /* Parse the opcode. */ |
4845 | for (;;) | |
4846 | { | |
4847 | if (count >= 16) | |
4848 | { | |
4849 | as_bad (_("unwind opcode too long")); | |
4850 | ignore_rest_of_line (); | |
a737bd4d | 4851 | } |
c19d1205 | 4852 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 4853 | { |
c19d1205 ZW |
4854 | as_bad (_("invalid unwind opcode")); |
4855 | ignore_rest_of_line (); | |
4856 | return; | |
a737bd4d | 4857 | } |
c19d1205 | 4858 | op[count++] = exp.X_add_number; |
a737bd4d | 4859 | |
c19d1205 ZW |
4860 | /* Parse the next byte. */ |
4861 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
4862 | break; | |
a737bd4d | 4863 | |
c19d1205 ZW |
4864 | expression (&exp); |
4865 | } | |
b99bd4ef | 4866 | |
c19d1205 ZW |
4867 | /* Add the opcode bytes in reverse order. */ |
4868 | while (count--) | |
4869 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 4870 | |
c19d1205 | 4871 | demand_empty_rest_of_line (); |
b99bd4ef | 4872 | } |
ee065d83 PB |
4873 | |
4874 | ||
4875 | /* Parse a .eabi_attribute directive. */ | |
4876 | ||
4877 | static void | |
4878 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
4879 | { | |
0420f52b | 4880 | int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC); |
ee3c0378 | 4881 | |
3076e594 | 4882 | if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES) |
ee3c0378 | 4883 | attributes_set_explicitly[tag] = 1; |
ee065d83 PB |
4884 | } |
4885 | ||
0855e32b NS |
4886 | /* Emit a tls fix for the symbol. */ |
4887 | ||
4888 | static void | |
4889 | s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED) | |
4890 | { | |
4891 | char *p; | |
4892 | expressionS exp; | |
4893 | #ifdef md_flush_pending_output | |
4894 | md_flush_pending_output (); | |
4895 | #endif | |
4896 | ||
4897 | #ifdef md_cons_align | |
4898 | md_cons_align (4); | |
4899 | #endif | |
4900 | ||
4901 | /* Since we're just labelling the code, there's no need to define a | |
4902 | mapping symbol. */ | |
4903 | expression (&exp); | |
4904 | p = obstack_next_free (&frchain_now->frch_obstack); | |
4905 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0, | |
4906 | thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ | |
4907 | : BFD_RELOC_ARM_TLS_DESCSEQ); | |
4908 | } | |
cdf9ccec | 4909 | #endif /* OBJ_ELF */ |
0855e32b | 4910 | |
ee065d83 | 4911 | static void s_arm_arch (int); |
7a1d4c38 | 4912 | static void s_arm_object_arch (int); |
ee065d83 PB |
4913 | static void s_arm_cpu (int); |
4914 | static void s_arm_fpu (int); | |
69133863 | 4915 | static void s_arm_arch_extension (int); |
b99bd4ef | 4916 | |
f0927246 NC |
4917 | #ifdef TE_PE |
4918 | ||
4919 | static void | |
5f4273c7 | 4920 | pe_directive_secrel (int dummy ATTRIBUTE_UNUSED) |
f0927246 NC |
4921 | { |
4922 | expressionS exp; | |
4923 | ||
4924 | do | |
4925 | { | |
4926 | expression (&exp); | |
4927 | if (exp.X_op == O_symbol) | |
4928 | exp.X_op = O_secrel; | |
4929 | ||
4930 | emit_expr (&exp, 4); | |
4931 | } | |
4932 | while (*input_line_pointer++ == ','); | |
4933 | ||
4934 | input_line_pointer--; | |
4935 | demand_empty_rest_of_line (); | |
4936 | } | |
4937 | #endif /* TE_PE */ | |
4938 | ||
5312fe52 BW |
4939 | int |
4940 | arm_is_largest_exponent_ok (int precision) | |
4941 | { | |
4942 | /* precision == 1 ensures that this will only return | |
4943 | true for 16 bit floats. */ | |
4944 | return (precision == 1) && (fp16_format == ARM_FP16_FORMAT_ALTERNATIVE); | |
4945 | } | |
4946 | ||
4947 | static void | |
4948 | set_fp16_format (int dummy ATTRIBUTE_UNUSED) | |
4949 | { | |
4950 | char saved_char; | |
4951 | char* name; | |
4952 | enum fp_16bit_format new_format; | |
4953 | ||
4954 | new_format = ARM_FP16_FORMAT_DEFAULT; | |
4955 | ||
4956 | name = input_line_pointer; | |
4957 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) | |
4958 | input_line_pointer++; | |
4959 | ||
4960 | saved_char = *input_line_pointer; | |
4961 | *input_line_pointer = 0; | |
4962 | ||
4963 | if (strcasecmp (name, "ieee") == 0) | |
4964 | new_format = ARM_FP16_FORMAT_IEEE; | |
4965 | else if (strcasecmp (name, "alternative") == 0) | |
4966 | new_format = ARM_FP16_FORMAT_ALTERNATIVE; | |
4967 | else | |
4968 | { | |
4969 | as_bad (_("unrecognised float16 format \"%s\""), name); | |
4970 | goto cleanup; | |
4971 | } | |
4972 | ||
4973 | /* Only set fp16_format if it is still the default (aka not already | |
4974 | been set yet). */ | |
4975 | if (fp16_format == ARM_FP16_FORMAT_DEFAULT) | |
4976 | fp16_format = new_format; | |
4977 | else | |
4978 | { | |
4979 | if (new_format != fp16_format) | |
4980 | as_warn (_("float16 format cannot be set more than once, ignoring.")); | |
4981 | } | |
4982 | ||
4983 | cleanup: | |
4984 | *input_line_pointer = saved_char; | |
4985 | ignore_rest_of_line (); | |
4986 | } | |
4987 | ||
c19d1205 ZW |
4988 | /* This table describes all the machine specific pseudo-ops the assembler |
4989 | has to support. The fields are: | |
4990 | pseudo-op name without dot | |
4991 | function to call to execute this pseudo-op | |
4992 | Integer arg to pass to the function. */ | |
b99bd4ef | 4993 | |
c19d1205 | 4994 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 4995 | { |
c19d1205 ZW |
4996 | /* Never called because '.req' does not start a line. */ |
4997 | { "req", s_req, 0 }, | |
dcbf9037 JB |
4998 | /* Following two are likewise never called. */ |
4999 | { "dn", s_dn, 0 }, | |
5000 | { "qn", s_qn, 0 }, | |
c19d1205 ZW |
5001 | { "unreq", s_unreq, 0 }, |
5002 | { "bss", s_bss, 0 }, | |
db2ed2e0 | 5003 | { "align", s_align_ptwo, 2 }, |
c19d1205 ZW |
5004 | { "arm", s_arm, 0 }, |
5005 | { "thumb", s_thumb, 0 }, | |
5006 | { "code", s_code, 0 }, | |
5007 | { "force_thumb", s_force_thumb, 0 }, | |
5008 | { "thumb_func", s_thumb_func, 0 }, | |
5009 | { "thumb_set", s_thumb_set, 0 }, | |
5010 | { "even", s_even, 0 }, | |
5011 | { "ltorg", s_ltorg, 0 }, | |
5012 | { "pool", s_ltorg, 0 }, | |
5013 | { "syntax", s_syntax, 0 }, | |
8463be01 PB |
5014 | { "cpu", s_arm_cpu, 0 }, |
5015 | { "arch", s_arm_arch, 0 }, | |
7a1d4c38 | 5016 | { "object_arch", s_arm_object_arch, 0 }, |
8463be01 | 5017 | { "fpu", s_arm_fpu, 0 }, |
69133863 | 5018 | { "arch_extension", s_arm_arch_extension, 0 }, |
c19d1205 | 5019 | #ifdef OBJ_ELF |
c921be7d NC |
5020 | { "word", s_arm_elf_cons, 4 }, |
5021 | { "long", s_arm_elf_cons, 4 }, | |
5022 | { "inst.n", s_arm_elf_inst, 2 }, | |
5023 | { "inst.w", s_arm_elf_inst, 4 }, | |
5024 | { "inst", s_arm_elf_inst, 0 }, | |
5025 | { "rel31", s_arm_rel31, 0 }, | |
c19d1205 ZW |
5026 | { "fnstart", s_arm_unwind_fnstart, 0 }, |
5027 | { "fnend", s_arm_unwind_fnend, 0 }, | |
5028 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
5029 | { "personality", s_arm_unwind_personality, 0 }, | |
5030 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
5031 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
5032 | { "save", s_arm_unwind_save, 0 }, | |
fa073d69 | 5033 | { "vsave", s_arm_unwind_save, 1 }, |
c19d1205 ZW |
5034 | { "movsp", s_arm_unwind_movsp, 0 }, |
5035 | { "pad", s_arm_unwind_pad, 0 }, | |
5036 | { "setfp", s_arm_unwind_setfp, 0 }, | |
5037 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 | 5038 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
0855e32b | 5039 | { "tlsdescseq", s_arm_tls_descseq, 0 }, |
c19d1205 ZW |
5040 | #else |
5041 | { "word", cons, 4}, | |
f0927246 NC |
5042 | |
5043 | /* These are used for dwarf. */ | |
5044 | {"2byte", cons, 2}, | |
5045 | {"4byte", cons, 4}, | |
5046 | {"8byte", cons, 8}, | |
5047 | /* These are used for dwarf2. */ | |
68d20676 | 5048 | { "file", dwarf2_directive_file, 0 }, |
f0927246 NC |
5049 | { "loc", dwarf2_directive_loc, 0 }, |
5050 | { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 }, | |
c19d1205 ZW |
5051 | #endif |
5052 | { "extend", float_cons, 'x' }, | |
5053 | { "ldouble", float_cons, 'x' }, | |
5054 | { "packed", float_cons, 'p' }, | |
f0927246 NC |
5055 | #ifdef TE_PE |
5056 | {"secrel32", pe_directive_secrel, 0}, | |
5057 | #endif | |
2e6976a8 DG |
5058 | |
5059 | /* These are for compatibility with CodeComposer Studio. */ | |
5060 | {"ref", s_ccs_ref, 0}, | |
5061 | {"def", s_ccs_def, 0}, | |
5062 | {"asmfunc", s_ccs_asmfunc, 0}, | |
5063 | {"endasmfunc", s_ccs_endasmfunc, 0}, | |
5064 | ||
5312fe52 BW |
5065 | {"float16", float_cons, 'h' }, |
5066 | {"float16_format", set_fp16_format, 0 }, | |
5067 | ||
c19d1205 ZW |
5068 | { 0, 0, 0 } |
5069 | }; | |
5312fe52 | 5070 | |
c19d1205 | 5071 | /* Parser functions used exclusively in instruction operands. */ |
b99bd4ef | 5072 | |
c19d1205 ZW |
5073 | /* Generic immediate-value read function for use in insn parsing. |
5074 | STR points to the beginning of the immediate (the leading #); | |
5075 | VAL receives the value; if the value is outside [MIN, MAX] | |
5076 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
5077 | optional. */ | |
b99bd4ef | 5078 | |
c19d1205 ZW |
5079 | static int |
5080 | parse_immediate (char **str, int *val, int min, int max, | |
5081 | bfd_boolean prefix_opt) | |
5082 | { | |
5083 | expressionS exp; | |
0198d5e6 | 5084 | |
c19d1205 ZW |
5085 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); |
5086 | if (exp.X_op != O_constant) | |
b99bd4ef | 5087 | { |
c19d1205 ZW |
5088 | inst.error = _("constant expression required"); |
5089 | return FAIL; | |
5090 | } | |
b99bd4ef | 5091 | |
c19d1205 ZW |
5092 | if (exp.X_add_number < min || exp.X_add_number > max) |
5093 | { | |
5094 | inst.error = _("immediate value out of range"); | |
5095 | return FAIL; | |
5096 | } | |
b99bd4ef | 5097 | |
c19d1205 ZW |
5098 | *val = exp.X_add_number; |
5099 | return SUCCESS; | |
5100 | } | |
b99bd4ef | 5101 | |
5287ad62 | 5102 | /* Less-generic immediate-value read function with the possibility of loading a |
036dc3f7 | 5103 | big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate |
5287ad62 JB |
5104 | instructions. Puts the result directly in inst.operands[i]. */ |
5105 | ||
5106 | static int | |
8335d6aa JW |
5107 | parse_big_immediate (char **str, int i, expressionS *in_exp, |
5108 | bfd_boolean allow_symbol_p) | |
5287ad62 JB |
5109 | { |
5110 | expressionS exp; | |
8335d6aa | 5111 | expressionS *exp_p = in_exp ? in_exp : &exp; |
5287ad62 JB |
5112 | char *ptr = *str; |
5113 | ||
8335d6aa | 5114 | my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG); |
5287ad62 | 5115 | |
8335d6aa | 5116 | if (exp_p->X_op == O_constant) |
036dc3f7 | 5117 | { |
8335d6aa | 5118 | inst.operands[i].imm = exp_p->X_add_number & 0xffffffff; |
036dc3f7 PB |
5119 | /* If we're on a 64-bit host, then a 64-bit number can be returned using |
5120 | O_constant. We have to be careful not to break compilation for | |
5121 | 32-bit X_add_number, though. */ | |
8335d6aa | 5122 | if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0) |
036dc3f7 | 5123 | { |
8335d6aa JW |
5124 | /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */ |
5125 | inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16) | |
5126 | & 0xffffffff); | |
036dc3f7 PB |
5127 | inst.operands[i].regisimm = 1; |
5128 | } | |
5129 | } | |
8335d6aa JW |
5130 | else if (exp_p->X_op == O_big |
5131 | && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32) | |
5287ad62 JB |
5132 | { |
5133 | unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0; | |
95b75c01 | 5134 | |
5287ad62 | 5135 | /* Bignums have their least significant bits in |
477330fc RM |
5136 | generic_bignum[0]. Make sure we put 32 bits in imm and |
5137 | 32 bits in reg, in a (hopefully) portable way. */ | |
9c2799c2 | 5138 | gas_assert (parts != 0); |
95b75c01 NC |
5139 | |
5140 | /* Make sure that the number is not too big. | |
5141 | PR 11972: Bignums can now be sign-extended to the | |
5142 | size of a .octa so check that the out of range bits | |
5143 | are all zero or all one. */ | |
8335d6aa | 5144 | if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64) |
95b75c01 NC |
5145 | { |
5146 | LITTLENUM_TYPE m = -1; | |
5147 | ||
5148 | if (generic_bignum[parts * 2] != 0 | |
5149 | && generic_bignum[parts * 2] != m) | |
5150 | return FAIL; | |
5151 | ||
8335d6aa | 5152 | for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++) |
95b75c01 NC |
5153 | if (generic_bignum[j] != generic_bignum[j-1]) |
5154 | return FAIL; | |
5155 | } | |
5156 | ||
5287ad62 JB |
5157 | inst.operands[i].imm = 0; |
5158 | for (j = 0; j < parts; j++, idx++) | |
477330fc RM |
5159 | inst.operands[i].imm |= generic_bignum[idx] |
5160 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
5287ad62 JB |
5161 | inst.operands[i].reg = 0; |
5162 | for (j = 0; j < parts; j++, idx++) | |
477330fc RM |
5163 | inst.operands[i].reg |= generic_bignum[idx] |
5164 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
5287ad62 JB |
5165 | inst.operands[i].regisimm = 1; |
5166 | } | |
8335d6aa | 5167 | else if (!(exp_p->X_op == O_symbol && allow_symbol_p)) |
5287ad62 | 5168 | return FAIL; |
5f4273c7 | 5169 | |
5287ad62 JB |
5170 | *str = ptr; |
5171 | ||
5172 | return SUCCESS; | |
5173 | } | |
5174 | ||
c19d1205 ZW |
5175 | /* Returns the pseudo-register number of an FPA immediate constant, |
5176 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 5177 | |
c19d1205 ZW |
5178 | static int |
5179 | parse_fpa_immediate (char ** str) | |
5180 | { | |
5181 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
5182 | char * save_in; | |
5183 | expressionS exp; | |
5184 | int i; | |
5185 | int j; | |
b99bd4ef | 5186 | |
c19d1205 ZW |
5187 | /* First try and match exact strings, this is to guarantee |
5188 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 5189 | |
c19d1205 ZW |
5190 | for (i = 0; fp_const[i]; i++) |
5191 | { | |
5192 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 5193 | { |
c19d1205 | 5194 | char *start = *str; |
b99bd4ef | 5195 | |
c19d1205 ZW |
5196 | *str += strlen (fp_const[i]); |
5197 | if (is_end_of_line[(unsigned char) **str]) | |
5198 | return i + 8; | |
5199 | *str = start; | |
5200 | } | |
5201 | } | |
b99bd4ef | 5202 | |
c19d1205 ZW |
5203 | /* Just because we didn't get a match doesn't mean that the constant |
5204 | isn't valid, just that it is in a format that we don't | |
5205 | automatically recognize. Try parsing it with the standard | |
5206 | expression routines. */ | |
b99bd4ef | 5207 | |
c19d1205 | 5208 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 5209 | |
c19d1205 ZW |
5210 | /* Look for a raw floating point number. */ |
5211 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
5212 | && is_end_of_line[(unsigned char) *save_in]) | |
5213 | { | |
5214 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
5215 | { | |
5216 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 5217 | { |
c19d1205 ZW |
5218 | if (words[j] != fp_values[i][j]) |
5219 | break; | |
b99bd4ef NC |
5220 | } |
5221 | ||
c19d1205 | 5222 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 5223 | { |
c19d1205 ZW |
5224 | *str = save_in; |
5225 | return i + 8; | |
b99bd4ef NC |
5226 | } |
5227 | } | |
5228 | } | |
b99bd4ef | 5229 | |
c19d1205 ZW |
5230 | /* Try and parse a more complex expression, this will probably fail |
5231 | unless the code uses a floating point prefix (eg "0f"). */ | |
5232 | save_in = input_line_pointer; | |
5233 | input_line_pointer = *str; | |
5234 | if (expression (&exp) == absolute_section | |
5235 | && exp.X_op == O_big | |
5236 | && exp.X_add_number < 0) | |
5237 | { | |
5238 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
5239 | Ditto for 15. */ | |
ba592044 AM |
5240 | #define X_PRECISION 5 |
5241 | #define E_PRECISION 15L | |
5242 | if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0) | |
c19d1205 ZW |
5243 | { |
5244 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
5245 | { | |
5246 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
5247 | { | |
5248 | if (words[j] != fp_values[i][j]) | |
5249 | break; | |
5250 | } | |
b99bd4ef | 5251 | |
c19d1205 ZW |
5252 | if (j == MAX_LITTLENUMS) |
5253 | { | |
5254 | *str = input_line_pointer; | |
5255 | input_line_pointer = save_in; | |
5256 | return i + 8; | |
5257 | } | |
5258 | } | |
5259 | } | |
b99bd4ef NC |
5260 | } |
5261 | ||
c19d1205 ZW |
5262 | *str = input_line_pointer; |
5263 | input_line_pointer = save_in; | |
5264 | inst.error = _("invalid FPA immediate expression"); | |
5265 | return FAIL; | |
b99bd4ef NC |
5266 | } |
5267 | ||
136da414 JB |
5268 | /* Returns 1 if a number has "quarter-precision" float format |
5269 | 0baBbbbbbc defgh000 00000000 00000000. */ | |
5270 | ||
5271 | static int | |
5272 | is_quarter_float (unsigned imm) | |
5273 | { | |
5274 | int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000; | |
5275 | return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0; | |
5276 | } | |
5277 | ||
aacf0b33 KT |
5278 | |
5279 | /* Detect the presence of a floating point or integer zero constant, | |
5280 | i.e. #0.0 or #0. */ | |
5281 | ||
5282 | static bfd_boolean | |
5283 | parse_ifimm_zero (char **in) | |
5284 | { | |
5285 | int error_code; | |
5286 | ||
5287 | if (!is_immediate_prefix (**in)) | |
3c6452ae TP |
5288 | { |
5289 | /* In unified syntax, all prefixes are optional. */ | |
5290 | if (!unified_syntax) | |
5291 | return FALSE; | |
5292 | } | |
5293 | else | |
5294 | ++*in; | |
0900a05b JW |
5295 | |
5296 | /* Accept #0x0 as a synonym for #0. */ | |
5297 | if (strncmp (*in, "0x", 2) == 0) | |
5298 | { | |
5299 | int val; | |
5300 | if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL) | |
5301 | return FALSE; | |
5302 | return TRUE; | |
5303 | } | |
5304 | ||
aacf0b33 KT |
5305 | error_code = atof_generic (in, ".", EXP_CHARS, |
5306 | &generic_floating_point_number); | |
5307 | ||
5308 | if (!error_code | |
5309 | && generic_floating_point_number.sign == '+' | |
5310 | && (generic_floating_point_number.low | |
5311 | > generic_floating_point_number.leader)) | |
5312 | return TRUE; | |
5313 | ||
5314 | return FALSE; | |
5315 | } | |
5316 | ||
136da414 JB |
5317 | /* Parse an 8-bit "quarter-precision" floating point number of the form: |
5318 | 0baBbbbbbc defgh000 00000000 00000000. | |
c96612cc JB |
5319 | The zero and minus-zero cases need special handling, since they can't be |
5320 | encoded in the "quarter-precision" float format, but can nonetheless be | |
5321 | loaded as integer constants. */ | |
136da414 JB |
5322 | |
5323 | static unsigned | |
5324 | parse_qfloat_immediate (char **ccp, int *immed) | |
5325 | { | |
5326 | char *str = *ccp; | |
c96612cc | 5327 | char *fpnum; |
136da414 | 5328 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; |
c96612cc | 5329 | int found_fpchar = 0; |
5f4273c7 | 5330 | |
136da414 | 5331 | skip_past_char (&str, '#'); |
5f4273c7 | 5332 | |
c96612cc JB |
5333 | /* We must not accidentally parse an integer as a floating-point number. Make |
5334 | sure that the value we parse is not an integer by checking for special | |
5335 | characters '.' or 'e'. | |
5336 | FIXME: This is a horrible hack, but doing better is tricky because type | |
5337 | information isn't in a very usable state at parse time. */ | |
5338 | fpnum = str; | |
5339 | skip_whitespace (fpnum); | |
5340 | ||
5341 | if (strncmp (fpnum, "0x", 2) == 0) | |
5342 | return FAIL; | |
5343 | else | |
5344 | { | |
5345 | for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++) | |
477330fc RM |
5346 | if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E') |
5347 | { | |
5348 | found_fpchar = 1; | |
5349 | break; | |
5350 | } | |
c96612cc JB |
5351 | |
5352 | if (!found_fpchar) | |
477330fc | 5353 | return FAIL; |
c96612cc | 5354 | } |
5f4273c7 | 5355 | |
136da414 JB |
5356 | if ((str = atof_ieee (str, 's', words)) != NULL) |
5357 | { | |
5358 | unsigned fpword = 0; | |
5359 | int i; | |
5f4273c7 | 5360 | |
136da414 JB |
5361 | /* Our FP word must be 32 bits (single-precision FP). */ |
5362 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
477330fc RM |
5363 | { |
5364 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
5365 | fpword |= words[i]; | |
5366 | } | |
5f4273c7 | 5367 | |
c96612cc | 5368 | if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0) |
477330fc | 5369 | *immed = fpword; |
136da414 | 5370 | else |
477330fc | 5371 | return FAIL; |
136da414 JB |
5372 | |
5373 | *ccp = str; | |
5f4273c7 | 5374 | |
136da414 JB |
5375 | return SUCCESS; |
5376 | } | |
5f4273c7 | 5377 | |
136da414 JB |
5378 | return FAIL; |
5379 | } | |
5380 | ||
c19d1205 ZW |
5381 | /* Shift operands. */ |
5382 | enum shift_kind | |
b99bd4ef | 5383 | { |
f5f10c66 | 5384 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW |
c19d1205 | 5385 | }; |
b99bd4ef | 5386 | |
c19d1205 ZW |
5387 | struct asm_shift_name |
5388 | { | |
5389 | const char *name; | |
5390 | enum shift_kind kind; | |
5391 | }; | |
b99bd4ef | 5392 | |
c19d1205 ZW |
5393 | /* Third argument to parse_shift. */ |
5394 | enum parse_shift_mode | |
5395 | { | |
5396 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
5397 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
5398 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
5399 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
5400 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
f5f10c66 | 5401 | SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */ |
c19d1205 | 5402 | }; |
b99bd4ef | 5403 | |
c19d1205 ZW |
5404 | /* Parse a <shift> specifier on an ARM data processing instruction. |
5405 | This has three forms: | |
b99bd4ef | 5406 | |
c19d1205 ZW |
5407 | (LSL|LSR|ASL|ASR|ROR) Rs |
5408 | (LSL|LSR|ASL|ASR|ROR) #imm | |
5409 | RRX | |
b99bd4ef | 5410 | |
c19d1205 ZW |
5411 | Note that ASL is assimilated to LSL in the instruction encoding, and |
5412 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 5413 | |
c19d1205 ZW |
5414 | static int |
5415 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 5416 | { |
c19d1205 ZW |
5417 | const struct asm_shift_name *shift_name; |
5418 | enum shift_kind shift; | |
5419 | char *s = *str; | |
5420 | char *p = s; | |
5421 | int reg; | |
b99bd4ef | 5422 | |
c19d1205 ZW |
5423 | for (p = *str; ISALPHA (*p); p++) |
5424 | ; | |
b99bd4ef | 5425 | |
c19d1205 | 5426 | if (p == *str) |
b99bd4ef | 5427 | { |
c19d1205 ZW |
5428 | inst.error = _("shift expression expected"); |
5429 | return FAIL; | |
b99bd4ef NC |
5430 | } |
5431 | ||
21d799b5 | 5432 | shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str, |
477330fc | 5433 | p - *str); |
c19d1205 ZW |
5434 | |
5435 | if (shift_name == NULL) | |
b99bd4ef | 5436 | { |
c19d1205 ZW |
5437 | inst.error = _("shift expression expected"); |
5438 | return FAIL; | |
b99bd4ef NC |
5439 | } |
5440 | ||
c19d1205 | 5441 | shift = shift_name->kind; |
b99bd4ef | 5442 | |
c19d1205 ZW |
5443 | switch (mode) |
5444 | { | |
5445 | case NO_SHIFT_RESTRICT: | |
f5f10c66 AV |
5446 | case SHIFT_IMMEDIATE: |
5447 | if (shift == SHIFT_UXTW) | |
5448 | { | |
5449 | inst.error = _("'UXTW' not allowed here"); | |
5450 | return FAIL; | |
5451 | } | |
5452 | break; | |
b99bd4ef | 5453 | |
c19d1205 ZW |
5454 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
5455 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
5456 | { | |
5457 | inst.error = _("'LSL' or 'ASR' required"); | |
5458 | return FAIL; | |
5459 | } | |
5460 | break; | |
b99bd4ef | 5461 | |
c19d1205 ZW |
5462 | case SHIFT_LSL_IMMEDIATE: |
5463 | if (shift != SHIFT_LSL) | |
5464 | { | |
5465 | inst.error = _("'LSL' required"); | |
5466 | return FAIL; | |
5467 | } | |
5468 | break; | |
b99bd4ef | 5469 | |
c19d1205 ZW |
5470 | case SHIFT_ASR_IMMEDIATE: |
5471 | if (shift != SHIFT_ASR) | |
5472 | { | |
5473 | inst.error = _("'ASR' required"); | |
5474 | return FAIL; | |
5475 | } | |
5476 | break; | |
f5f10c66 AV |
5477 | case SHIFT_UXTW_IMMEDIATE: |
5478 | if (shift != SHIFT_UXTW) | |
5479 | { | |
5480 | inst.error = _("'UXTW' required"); | |
5481 | return FAIL; | |
5482 | } | |
5483 | break; | |
b99bd4ef | 5484 | |
c19d1205 ZW |
5485 | default: abort (); |
5486 | } | |
b99bd4ef | 5487 | |
c19d1205 ZW |
5488 | if (shift != SHIFT_RRX) |
5489 | { | |
5490 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
5491 | skip_whitespace (p); | |
b99bd4ef | 5492 | |
c19d1205 | 5493 | if (mode == NO_SHIFT_RESTRICT |
dcbf9037 | 5494 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
5495 | { |
5496 | inst.operands[i].imm = reg; | |
5497 | inst.operands[i].immisreg = 1; | |
5498 | } | |
e2b0ab59 | 5499 | else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX)) |
c19d1205 ZW |
5500 | return FAIL; |
5501 | } | |
5502 | inst.operands[i].shift_kind = shift; | |
5503 | inst.operands[i].shifted = 1; | |
5504 | *str = p; | |
5505 | return SUCCESS; | |
b99bd4ef NC |
5506 | } |
5507 | ||
c19d1205 | 5508 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 5509 | |
c19d1205 ZW |
5510 | #<immediate> |
5511 | #<immediate>, <rotate> | |
5512 | <Rm> | |
5513 | <Rm>, <shift> | |
b99bd4ef | 5514 | |
c19d1205 ZW |
5515 | where <shift> is defined by parse_shift above, and <rotate> is a |
5516 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 5517 | is deferred to md_apply_fix. */ |
b99bd4ef | 5518 | |
c19d1205 ZW |
5519 | static int |
5520 | parse_shifter_operand (char **str, int i) | |
5521 | { | |
5522 | int value; | |
91d6fa6a | 5523 | expressionS exp; |
b99bd4ef | 5524 | |
dcbf9037 | 5525 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
5526 | { |
5527 | inst.operands[i].reg = value; | |
5528 | inst.operands[i].isreg = 1; | |
b99bd4ef | 5529 | |
c19d1205 | 5530 | /* parse_shift will override this if appropriate */ |
e2b0ab59 AV |
5531 | inst.relocs[0].exp.X_op = O_constant; |
5532 | inst.relocs[0].exp.X_add_number = 0; | |
b99bd4ef | 5533 | |
c19d1205 ZW |
5534 | if (skip_past_comma (str) == FAIL) |
5535 | return SUCCESS; | |
b99bd4ef | 5536 | |
c19d1205 ZW |
5537 | /* Shift operation on register. */ |
5538 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
5539 | } |
5540 | ||
e2b0ab59 | 5541 | if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX)) |
c19d1205 | 5542 | return FAIL; |
b99bd4ef | 5543 | |
c19d1205 | 5544 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 5545 | { |
c19d1205 | 5546 | /* #x, y -- ie explicit rotation by Y. */ |
91d6fa6a | 5547 | if (my_get_expression (&exp, str, GE_NO_PREFIX)) |
c19d1205 | 5548 | return FAIL; |
b99bd4ef | 5549 | |
e2b0ab59 | 5550 | if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant) |
c19d1205 ZW |
5551 | { |
5552 | inst.error = _("constant expression expected"); | |
5553 | return FAIL; | |
5554 | } | |
b99bd4ef | 5555 | |
91d6fa6a | 5556 | value = exp.X_add_number; |
c19d1205 ZW |
5557 | if (value < 0 || value > 30 || value % 2 != 0) |
5558 | { | |
5559 | inst.error = _("invalid rotation"); | |
5560 | return FAIL; | |
5561 | } | |
e2b0ab59 AV |
5562 | if (inst.relocs[0].exp.X_add_number < 0 |
5563 | || inst.relocs[0].exp.X_add_number > 255) | |
c19d1205 ZW |
5564 | { |
5565 | inst.error = _("invalid constant"); | |
5566 | return FAIL; | |
5567 | } | |
09d92015 | 5568 | |
a415b1cd | 5569 | /* Encode as specified. */ |
e2b0ab59 | 5570 | inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7; |
a415b1cd | 5571 | return SUCCESS; |
09d92015 MM |
5572 | } |
5573 | ||
e2b0ab59 AV |
5574 | inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE; |
5575 | inst.relocs[0].pc_rel = 0; | |
c19d1205 | 5576 | return SUCCESS; |
09d92015 MM |
5577 | } |
5578 | ||
4962c51a MS |
5579 | /* Group relocation information. Each entry in the table contains the |
5580 | textual name of the relocation as may appear in assembler source | |
5581 | and must end with a colon. | |
5582 | Along with this textual name are the relocation codes to be used if | |
5583 | the corresponding instruction is an ALU instruction (ADD or SUB only), | |
5584 | an LDR, an LDRS, or an LDC. */ | |
5585 | ||
5586 | struct group_reloc_table_entry | |
5587 | { | |
5588 | const char *name; | |
5589 | int alu_code; | |
5590 | int ldr_code; | |
5591 | int ldrs_code; | |
5592 | int ldc_code; | |
5593 | }; | |
5594 | ||
5595 | typedef enum | |
5596 | { | |
5597 | /* Varieties of non-ALU group relocation. */ | |
5598 | ||
5599 | GROUP_LDR, | |
5600 | GROUP_LDRS, | |
35c228db AV |
5601 | GROUP_LDC, |
5602 | GROUP_MVE | |
4962c51a MS |
5603 | } group_reloc_type; |
5604 | ||
5605 | static struct group_reloc_table_entry group_reloc_table[] = | |
5606 | { /* Program counter relative: */ | |
5607 | { "pc_g0_nc", | |
5608 | BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */ | |
5609 | 0, /* LDR */ | |
5610 | 0, /* LDRS */ | |
5611 | 0 }, /* LDC */ | |
5612 | { "pc_g0", | |
5613 | BFD_RELOC_ARM_ALU_PC_G0, /* ALU */ | |
5614 | BFD_RELOC_ARM_LDR_PC_G0, /* LDR */ | |
5615 | BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */ | |
5616 | BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */ | |
5617 | { "pc_g1_nc", | |
5618 | BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */ | |
5619 | 0, /* LDR */ | |
5620 | 0, /* LDRS */ | |
5621 | 0 }, /* LDC */ | |
5622 | { "pc_g1", | |
5623 | BFD_RELOC_ARM_ALU_PC_G1, /* ALU */ | |
5624 | BFD_RELOC_ARM_LDR_PC_G1, /* LDR */ | |
5625 | BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */ | |
5626 | BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */ | |
5627 | { "pc_g2", | |
5628 | BFD_RELOC_ARM_ALU_PC_G2, /* ALU */ | |
5629 | BFD_RELOC_ARM_LDR_PC_G2, /* LDR */ | |
5630 | BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */ | |
5631 | BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */ | |
5632 | /* Section base relative */ | |
5633 | { "sb_g0_nc", | |
5634 | BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */ | |
5635 | 0, /* LDR */ | |
5636 | 0, /* LDRS */ | |
5637 | 0 }, /* LDC */ | |
5638 | { "sb_g0", | |
5639 | BFD_RELOC_ARM_ALU_SB_G0, /* ALU */ | |
5640 | BFD_RELOC_ARM_LDR_SB_G0, /* LDR */ | |
5641 | BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */ | |
5642 | BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */ | |
5643 | { "sb_g1_nc", | |
5644 | BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */ | |
5645 | 0, /* LDR */ | |
5646 | 0, /* LDRS */ | |
5647 | 0 }, /* LDC */ | |
5648 | { "sb_g1", | |
5649 | BFD_RELOC_ARM_ALU_SB_G1, /* ALU */ | |
5650 | BFD_RELOC_ARM_LDR_SB_G1, /* LDR */ | |
5651 | BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */ | |
5652 | BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */ | |
5653 | { "sb_g2", | |
5654 | BFD_RELOC_ARM_ALU_SB_G2, /* ALU */ | |
5655 | BFD_RELOC_ARM_LDR_SB_G2, /* LDR */ | |
5656 | BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */ | |
72d98d16 MG |
5657 | BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */ |
5658 | /* Absolute thumb alu relocations. */ | |
5659 | { "lower0_7", | |
5660 | BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */ | |
5661 | 0, /* LDR. */ | |
5662 | 0, /* LDRS. */ | |
5663 | 0 }, /* LDC. */ | |
5664 | { "lower8_15", | |
5665 | BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */ | |
5666 | 0, /* LDR. */ | |
5667 | 0, /* LDRS. */ | |
5668 | 0 }, /* LDC. */ | |
5669 | { "upper0_7", | |
5670 | BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */ | |
5671 | 0, /* LDR. */ | |
5672 | 0, /* LDRS. */ | |
5673 | 0 }, /* LDC. */ | |
5674 | { "upper8_15", | |
5675 | BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */ | |
5676 | 0, /* LDR. */ | |
5677 | 0, /* LDRS. */ | |
5678 | 0 } }; /* LDC. */ | |
4962c51a MS |
5679 | |
5680 | /* Given the address of a pointer pointing to the textual name of a group | |
5681 | relocation as may appear in assembler source, attempt to find its details | |
5682 | in group_reloc_table. The pointer will be updated to the character after | |
5683 | the trailing colon. On failure, FAIL will be returned; SUCCESS | |
5684 | otherwise. On success, *entry will be updated to point at the relevant | |
5685 | group_reloc_table entry. */ | |
5686 | ||
5687 | static int | |
5688 | find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out) | |
5689 | { | |
5690 | unsigned int i; | |
5691 | for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++) | |
5692 | { | |
5693 | int length = strlen (group_reloc_table[i].name); | |
5694 | ||
5f4273c7 NC |
5695 | if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 |
5696 | && (*str)[length] == ':') | |
477330fc RM |
5697 | { |
5698 | *out = &group_reloc_table[i]; | |
5699 | *str += (length + 1); | |
5700 | return SUCCESS; | |
5701 | } | |
4962c51a MS |
5702 | } |
5703 | ||
5704 | return FAIL; | |
5705 | } | |
5706 | ||
5707 | /* Parse a <shifter_operand> for an ARM data processing instruction | |
5708 | (as for parse_shifter_operand) where group relocations are allowed: | |
5709 | ||
5710 | #<immediate> | |
5711 | #<immediate>, <rotate> | |
5712 | #:<group_reloc>:<expression> | |
5713 | <Rm> | |
5714 | <Rm>, <shift> | |
5715 | ||
5716 | where <group_reloc> is one of the strings defined in group_reloc_table. | |
5717 | The hashes are optional. | |
5718 | ||
5719 | Everything else is as for parse_shifter_operand. */ | |
5720 | ||
5721 | static parse_operand_result | |
5722 | parse_shifter_operand_group_reloc (char **str, int i) | |
5723 | { | |
5724 | /* Determine if we have the sequence of characters #: or just : | |
5725 | coming next. If we do, then we check for a group relocation. | |
5726 | If we don't, punt the whole lot to parse_shifter_operand. */ | |
5727 | ||
5728 | if (((*str)[0] == '#' && (*str)[1] == ':') | |
5729 | || (*str)[0] == ':') | |
5730 | { | |
5731 | struct group_reloc_table_entry *entry; | |
5732 | ||
5733 | if ((*str)[0] == '#') | |
477330fc | 5734 | (*str) += 2; |
4962c51a | 5735 | else |
477330fc | 5736 | (*str)++; |
4962c51a MS |
5737 | |
5738 | /* Try to parse a group relocation. Anything else is an error. */ | |
5739 | if (find_group_reloc_table_entry (str, &entry) == FAIL) | |
477330fc RM |
5740 | { |
5741 | inst.error = _("unknown group relocation"); | |
5742 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5743 | } | |
4962c51a MS |
5744 | |
5745 | /* We now have the group relocation table entry corresponding to | |
477330fc | 5746 | the name in the assembler source. Next, we parse the expression. */ |
e2b0ab59 | 5747 | if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX)) |
477330fc | 5748 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; |
4962c51a MS |
5749 | |
5750 | /* Record the relocation type (always the ALU variant here). */ | |
e2b0ab59 AV |
5751 | inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code; |
5752 | gas_assert (inst.relocs[0].type != 0); | |
4962c51a MS |
5753 | |
5754 | return PARSE_OPERAND_SUCCESS; | |
5755 | } | |
5756 | else | |
5757 | return parse_shifter_operand (str, i) == SUCCESS | |
477330fc | 5758 | ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL; |
4962c51a MS |
5759 | |
5760 | /* Never reached. */ | |
5761 | } | |
5762 | ||
8e560766 MGD |
5763 | /* Parse a Neon alignment expression. Information is written to |
5764 | inst.operands[i]. We assume the initial ':' has been skipped. | |
fa94de6b | 5765 | |
8e560766 MGD |
5766 | align .imm = align << 8, .immisalign=1, .preind=0 */ |
5767 | static parse_operand_result | |
5768 | parse_neon_alignment (char **str, int i) | |
5769 | { | |
5770 | char *p = *str; | |
5771 | expressionS exp; | |
5772 | ||
5773 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
5774 | ||
5775 | if (exp.X_op != O_constant) | |
5776 | { | |
5777 | inst.error = _("alignment must be constant"); | |
5778 | return PARSE_OPERAND_FAIL; | |
5779 | } | |
5780 | ||
5781 | inst.operands[i].imm = exp.X_add_number << 8; | |
5782 | inst.operands[i].immisalign = 1; | |
5783 | /* Alignments are not pre-indexes. */ | |
5784 | inst.operands[i].preind = 0; | |
5785 | ||
5786 | *str = p; | |
5787 | return PARSE_OPERAND_SUCCESS; | |
5788 | } | |
5789 | ||
c19d1205 | 5790 | /* Parse all forms of an ARM address expression. Information is written |
e2b0ab59 | 5791 | to inst.operands[i] and/or inst.relocs[0]. |
09d92015 | 5792 | |
c19d1205 | 5793 | Preindexed addressing (.preind=1): |
09d92015 | 5794 | |
e2b0ab59 | 5795 | [Rn, #offset] .reg=Rn .relocs[0].exp=offset |
c19d1205 ZW |
5796 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 |
5797 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
e2b0ab59 | 5798 | .shift_kind=shift .relocs[0].exp=shift_imm |
09d92015 | 5799 | |
c19d1205 | 5800 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 5801 | |
c19d1205 | 5802 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 5803 | |
e2b0ab59 | 5804 | [Rn], #offset .reg=Rn .relocs[0].exp=offset |
c19d1205 ZW |
5805 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 |
5806 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
e2b0ab59 | 5807 | .shift_kind=shift .relocs[0].exp=shift_imm |
09d92015 | 5808 | |
c19d1205 | 5809 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 5810 | |
c19d1205 | 5811 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 5812 | |
c19d1205 | 5813 | Other: |
09d92015 | 5814 | |
c19d1205 | 5815 | [Rn]{!} shorthand for [Rn,#0]{!} |
e2b0ab59 AV |
5816 | =immediate .isreg=0 .relocs[0].exp=immediate |
5817 | label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label | |
09d92015 | 5818 | |
c19d1205 | 5819 | It is the caller's responsibility to check for addressing modes not |
e2b0ab59 | 5820 | supported by the instruction, and to set inst.relocs[0].type. */ |
c19d1205 | 5821 | |
4962c51a MS |
5822 | static parse_operand_result |
5823 | parse_address_main (char **str, int i, int group_relocations, | |
477330fc | 5824 | group_reloc_type group_type) |
09d92015 | 5825 | { |
c19d1205 ZW |
5826 | char *p = *str; |
5827 | int reg; | |
09d92015 | 5828 | |
c19d1205 | 5829 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 5830 | { |
c19d1205 ZW |
5831 | if (skip_past_char (&p, '=') == FAIL) |
5832 | { | |
974da60d | 5833 | /* Bare address - translate to PC-relative offset. */ |
e2b0ab59 | 5834 | inst.relocs[0].pc_rel = 1; |
c19d1205 ZW |
5835 | inst.operands[i].reg = REG_PC; |
5836 | inst.operands[i].isreg = 1; | |
5837 | inst.operands[i].preind = 1; | |
09d92015 | 5838 | |
e2b0ab59 | 5839 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG)) |
8335d6aa JW |
5840 | return PARSE_OPERAND_FAIL; |
5841 | } | |
e2b0ab59 | 5842 | else if (parse_big_immediate (&p, i, &inst.relocs[0].exp, |
8335d6aa | 5843 | /*allow_symbol_p=*/TRUE)) |
4962c51a | 5844 | return PARSE_OPERAND_FAIL; |
09d92015 | 5845 | |
c19d1205 | 5846 | *str = p; |
4962c51a | 5847 | return PARSE_OPERAND_SUCCESS; |
09d92015 MM |
5848 | } |
5849 | ||
8ab8155f NC |
5850 | /* PR gas/14887: Allow for whitespace after the opening bracket. */ |
5851 | skip_whitespace (p); | |
5852 | ||
f5f10c66 AV |
5853 | if (group_type == GROUP_MVE) |
5854 | { | |
5855 | enum arm_reg_type rtype = REG_TYPE_MQ; | |
5856 | struct neon_type_el et; | |
5857 | if ((reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL) | |
5858 | { | |
5859 | inst.operands[i].isquad = 1; | |
5860 | } | |
5861 | else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) | |
5862 | { | |
5863 | inst.error = BAD_ADDR_MODE; | |
5864 | return PARSE_OPERAND_FAIL; | |
5865 | } | |
5866 | } | |
5867 | else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) | |
09d92015 | 5868 | { |
35c228db AV |
5869 | if (group_type == GROUP_MVE) |
5870 | inst.error = BAD_ADDR_MODE; | |
5871 | else | |
5872 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
4962c51a | 5873 | return PARSE_OPERAND_FAIL; |
09d92015 | 5874 | } |
c19d1205 ZW |
5875 | inst.operands[i].reg = reg; |
5876 | inst.operands[i].isreg = 1; | |
09d92015 | 5877 | |
c19d1205 | 5878 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5879 | { |
c19d1205 | 5880 | inst.operands[i].preind = 1; |
09d92015 | 5881 | |
c19d1205 ZW |
5882 | if (*p == '+') p++; |
5883 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
5884 | ||
f5f10c66 AV |
5885 | enum arm_reg_type rtype = REG_TYPE_MQ; |
5886 | struct neon_type_el et; | |
5887 | if (group_type == GROUP_MVE | |
5888 | && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL) | |
5889 | { | |
5890 | inst.operands[i].immisreg = 2; | |
5891 | inst.operands[i].imm = reg; | |
5892 | ||
5893 | if (skip_past_comma (&p) == SUCCESS) | |
5894 | { | |
5895 | if (parse_shift (&p, i, SHIFT_UXTW_IMMEDIATE) == SUCCESS) | |
5896 | { | |
5897 | inst.operands[i].imm |= inst.relocs[0].exp.X_add_number << 5; | |
5898 | inst.relocs[0].exp.X_add_number = 0; | |
5899 | } | |
5900 | else | |
5901 | return PARSE_OPERAND_FAIL; | |
5902 | } | |
5903 | } | |
5904 | else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) | |
09d92015 | 5905 | { |
c19d1205 ZW |
5906 | inst.operands[i].imm = reg; |
5907 | inst.operands[i].immisreg = 1; | |
5908 | ||
5909 | if (skip_past_comma (&p) == SUCCESS) | |
5910 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5911 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5912 | } |
5287ad62 | 5913 | else if (skip_past_char (&p, ':') == SUCCESS) |
8e560766 MGD |
5914 | { |
5915 | /* FIXME: '@' should be used here, but it's filtered out by generic | |
5916 | code before we get to see it here. This may be subject to | |
5917 | change. */ | |
5918 | parse_operand_result result = parse_neon_alignment (&p, i); | |
fa94de6b | 5919 | |
8e560766 MGD |
5920 | if (result != PARSE_OPERAND_SUCCESS) |
5921 | return result; | |
5922 | } | |
c19d1205 ZW |
5923 | else |
5924 | { | |
5925 | if (inst.operands[i].negative) | |
5926 | { | |
5927 | inst.operands[i].negative = 0; | |
5928 | p--; | |
5929 | } | |
4962c51a | 5930 | |
5f4273c7 NC |
5931 | if (group_relocations |
5932 | && ((*p == '#' && *(p + 1) == ':') || *p == ':')) | |
4962c51a MS |
5933 | { |
5934 | struct group_reloc_table_entry *entry; | |
5935 | ||
477330fc RM |
5936 | /* Skip over the #: or : sequence. */ |
5937 | if (*p == '#') | |
5938 | p += 2; | |
5939 | else | |
5940 | p++; | |
4962c51a MS |
5941 | |
5942 | /* Try to parse a group relocation. Anything else is an | |
477330fc | 5943 | error. */ |
4962c51a MS |
5944 | if (find_group_reloc_table_entry (&p, &entry) == FAIL) |
5945 | { | |
5946 | inst.error = _("unknown group relocation"); | |
5947 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5948 | } | |
5949 | ||
5950 | /* We now have the group relocation table entry corresponding to | |
5951 | the name in the assembler source. Next, we parse the | |
477330fc | 5952 | expression. */ |
e2b0ab59 | 5953 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX)) |
4962c51a MS |
5954 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; |
5955 | ||
5956 | /* Record the relocation type. */ | |
477330fc RM |
5957 | switch (group_type) |
5958 | { | |
5959 | case GROUP_LDR: | |
e2b0ab59 AV |
5960 | inst.relocs[0].type |
5961 | = (bfd_reloc_code_real_type) entry->ldr_code; | |
477330fc | 5962 | break; |
4962c51a | 5963 | |
477330fc | 5964 | case GROUP_LDRS: |
e2b0ab59 AV |
5965 | inst.relocs[0].type |
5966 | = (bfd_reloc_code_real_type) entry->ldrs_code; | |
477330fc | 5967 | break; |
4962c51a | 5968 | |
477330fc | 5969 | case GROUP_LDC: |
e2b0ab59 AV |
5970 | inst.relocs[0].type |
5971 | = (bfd_reloc_code_real_type) entry->ldc_code; | |
477330fc | 5972 | break; |
4962c51a | 5973 | |
477330fc RM |
5974 | default: |
5975 | gas_assert (0); | |
5976 | } | |
4962c51a | 5977 | |
e2b0ab59 | 5978 | if (inst.relocs[0].type == 0) |
4962c51a MS |
5979 | { |
5980 | inst.error = _("this group relocation is not allowed on this instruction"); | |
5981 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5982 | } | |
477330fc RM |
5983 | } |
5984 | else | |
26d97720 NS |
5985 | { |
5986 | char *q = p; | |
0198d5e6 | 5987 | |
e2b0ab59 | 5988 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX)) |
26d97720 NS |
5989 | return PARSE_OPERAND_FAIL; |
5990 | /* If the offset is 0, find out if it's a +0 or -0. */ | |
e2b0ab59 AV |
5991 | if (inst.relocs[0].exp.X_op == O_constant |
5992 | && inst.relocs[0].exp.X_add_number == 0) | |
26d97720 NS |
5993 | { |
5994 | skip_whitespace (q); | |
5995 | if (*q == '#') | |
5996 | { | |
5997 | q++; | |
5998 | skip_whitespace (q); | |
5999 | } | |
6000 | if (*q == '-') | |
6001 | inst.operands[i].negative = 1; | |
6002 | } | |
6003 | } | |
09d92015 MM |
6004 | } |
6005 | } | |
8e560766 MGD |
6006 | else if (skip_past_char (&p, ':') == SUCCESS) |
6007 | { | |
6008 | /* FIXME: '@' should be used here, but it's filtered out by generic code | |
6009 | before we get to see it here. This may be subject to change. */ | |
6010 | parse_operand_result result = parse_neon_alignment (&p, i); | |
fa94de6b | 6011 | |
8e560766 MGD |
6012 | if (result != PARSE_OPERAND_SUCCESS) |
6013 | return result; | |
6014 | } | |
09d92015 | 6015 | |
c19d1205 | 6016 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 6017 | { |
c19d1205 | 6018 | inst.error = _("']' expected"); |
4962c51a | 6019 | return PARSE_OPERAND_FAIL; |
09d92015 MM |
6020 | } |
6021 | ||
c19d1205 ZW |
6022 | if (skip_past_char (&p, '!') == SUCCESS) |
6023 | inst.operands[i].writeback = 1; | |
09d92015 | 6024 | |
c19d1205 | 6025 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 6026 | { |
c19d1205 ZW |
6027 | if (skip_past_char (&p, '{') == SUCCESS) |
6028 | { | |
6029 | /* [Rn], {expr} - unindexed, with option */ | |
6030 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 6031 | 0, 255, TRUE) == FAIL) |
4962c51a | 6032 | return PARSE_OPERAND_FAIL; |
09d92015 | 6033 | |
c19d1205 ZW |
6034 | if (skip_past_char (&p, '}') == FAIL) |
6035 | { | |
6036 | inst.error = _("'}' expected at end of 'option' field"); | |
4962c51a | 6037 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
6038 | } |
6039 | if (inst.operands[i].preind) | |
6040 | { | |
6041 | inst.error = _("cannot combine index with option"); | |
4962c51a | 6042 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
6043 | } |
6044 | *str = p; | |
4962c51a | 6045 | return PARSE_OPERAND_SUCCESS; |
09d92015 | 6046 | } |
c19d1205 ZW |
6047 | else |
6048 | { | |
6049 | inst.operands[i].postind = 1; | |
6050 | inst.operands[i].writeback = 1; | |
09d92015 | 6051 | |
c19d1205 ZW |
6052 | if (inst.operands[i].preind) |
6053 | { | |
6054 | inst.error = _("cannot combine pre- and post-indexing"); | |
4962c51a | 6055 | return PARSE_OPERAND_FAIL; |
c19d1205 | 6056 | } |
09d92015 | 6057 | |
c19d1205 ZW |
6058 | if (*p == '+') p++; |
6059 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 6060 | |
f5f10c66 AV |
6061 | enum arm_reg_type rtype = REG_TYPE_MQ; |
6062 | struct neon_type_el et; | |
6063 | if (group_type == GROUP_MVE | |
6064 | && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL) | |
6065 | { | |
6066 | inst.operands[i].immisreg = 2; | |
6067 | inst.operands[i].imm = reg; | |
6068 | } | |
6069 | else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) | |
c19d1205 | 6070 | { |
477330fc RM |
6071 | /* We might be using the immediate for alignment already. If we |
6072 | are, OR the register number into the low-order bits. */ | |
6073 | if (inst.operands[i].immisalign) | |
6074 | inst.operands[i].imm |= reg; | |
6075 | else | |
6076 | inst.operands[i].imm = reg; | |
c19d1205 | 6077 | inst.operands[i].immisreg = 1; |
a737bd4d | 6078 | |
c19d1205 ZW |
6079 | if (skip_past_comma (&p) == SUCCESS) |
6080 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 6081 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
6082 | } |
6083 | else | |
6084 | { | |
26d97720 | 6085 | char *q = p; |
0198d5e6 | 6086 | |
c19d1205 ZW |
6087 | if (inst.operands[i].negative) |
6088 | { | |
6089 | inst.operands[i].negative = 0; | |
6090 | p--; | |
6091 | } | |
e2b0ab59 | 6092 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX)) |
4962c51a | 6093 | return PARSE_OPERAND_FAIL; |
26d97720 | 6094 | /* If the offset is 0, find out if it's a +0 or -0. */ |
e2b0ab59 AV |
6095 | if (inst.relocs[0].exp.X_op == O_constant |
6096 | && inst.relocs[0].exp.X_add_number == 0) | |
26d97720 NS |
6097 | { |
6098 | skip_whitespace (q); | |
6099 | if (*q == '#') | |
6100 | { | |
6101 | q++; | |
6102 | skip_whitespace (q); | |
6103 | } | |
6104 | if (*q == '-') | |
6105 | inst.operands[i].negative = 1; | |
6106 | } | |
c19d1205 ZW |
6107 | } |
6108 | } | |
a737bd4d NC |
6109 | } |
6110 | ||
c19d1205 ZW |
6111 | /* If at this point neither .preind nor .postind is set, we have a |
6112 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
6113 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
6114 | { | |
6115 | inst.operands[i].preind = 1; | |
e2b0ab59 AV |
6116 | inst.relocs[0].exp.X_op = O_constant; |
6117 | inst.relocs[0].exp.X_add_number = 0; | |
c19d1205 ZW |
6118 | } |
6119 | *str = p; | |
4962c51a MS |
6120 | return PARSE_OPERAND_SUCCESS; |
6121 | } | |
6122 | ||
6123 | static int | |
6124 | parse_address (char **str, int i) | |
6125 | { | |
21d799b5 | 6126 | return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS |
477330fc | 6127 | ? SUCCESS : FAIL; |
4962c51a MS |
6128 | } |
6129 | ||
6130 | static parse_operand_result | |
6131 | parse_address_group_reloc (char **str, int i, group_reloc_type type) | |
6132 | { | |
6133 | return parse_address_main (str, i, 1, type); | |
a737bd4d NC |
6134 | } |
6135 | ||
b6895b4f PB |
6136 | /* Parse an operand for a MOVW or MOVT instruction. */ |
6137 | static int | |
6138 | parse_half (char **str) | |
6139 | { | |
6140 | char * p; | |
5f4273c7 | 6141 | |
b6895b4f PB |
6142 | p = *str; |
6143 | skip_past_char (&p, '#'); | |
5f4273c7 | 6144 | if (strncasecmp (p, ":lower16:", 9) == 0) |
e2b0ab59 | 6145 | inst.relocs[0].type = BFD_RELOC_ARM_MOVW; |
b6895b4f | 6146 | else if (strncasecmp (p, ":upper16:", 9) == 0) |
e2b0ab59 | 6147 | inst.relocs[0].type = BFD_RELOC_ARM_MOVT; |
b6895b4f | 6148 | |
e2b0ab59 | 6149 | if (inst.relocs[0].type != BFD_RELOC_UNUSED) |
b6895b4f PB |
6150 | { |
6151 | p += 9; | |
5f4273c7 | 6152 | skip_whitespace (p); |
b6895b4f PB |
6153 | } |
6154 | ||
e2b0ab59 | 6155 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX)) |
b6895b4f PB |
6156 | return FAIL; |
6157 | ||
e2b0ab59 | 6158 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
b6895b4f | 6159 | { |
e2b0ab59 | 6160 | if (inst.relocs[0].exp.X_op != O_constant) |
b6895b4f PB |
6161 | { |
6162 | inst.error = _("constant expression expected"); | |
6163 | return FAIL; | |
6164 | } | |
e2b0ab59 AV |
6165 | if (inst.relocs[0].exp.X_add_number < 0 |
6166 | || inst.relocs[0].exp.X_add_number > 0xffff) | |
b6895b4f PB |
6167 | { |
6168 | inst.error = _("immediate value out of range"); | |
6169 | return FAIL; | |
6170 | } | |
6171 | } | |
6172 | *str = p; | |
6173 | return SUCCESS; | |
6174 | } | |
6175 | ||
c19d1205 | 6176 | /* Miscellaneous. */ |
a737bd4d | 6177 | |
c19d1205 ZW |
6178 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
6179 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
6180 | static int | |
d2cd1205 | 6181 | parse_psr (char **str, bfd_boolean lhs) |
09d92015 | 6182 | { |
c19d1205 ZW |
6183 | char *p; |
6184 | unsigned long psr_field; | |
62b3e311 PB |
6185 | const struct asm_psr *psr; |
6186 | char *start; | |
d2cd1205 | 6187 | bfd_boolean is_apsr = FALSE; |
ac7f631b | 6188 | bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m); |
09d92015 | 6189 | |
a4482bb6 NC |
6190 | /* PR gas/12698: If the user has specified -march=all then m_profile will |
6191 | be TRUE, but we want to ignore it in this case as we are building for any | |
6192 | CPU type, including non-m variants. */ | |
823d2571 | 6193 | if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any)) |
a4482bb6 NC |
6194 | m_profile = FALSE; |
6195 | ||
c19d1205 ZW |
6196 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
6197 | feature for ease of use and backwards compatibility. */ | |
6198 | p = *str; | |
62b3e311 | 6199 | if (strncasecmp (p, "SPSR", 4) == 0) |
d2cd1205 JB |
6200 | { |
6201 | if (m_profile) | |
6202 | goto unsupported_psr; | |
fa94de6b | 6203 | |
d2cd1205 JB |
6204 | psr_field = SPSR_BIT; |
6205 | } | |
6206 | else if (strncasecmp (p, "CPSR", 4) == 0) | |
6207 | { | |
6208 | if (m_profile) | |
6209 | goto unsupported_psr; | |
6210 | ||
6211 | psr_field = 0; | |
6212 | } | |
6213 | else if (strncasecmp (p, "APSR", 4) == 0) | |
6214 | { | |
6215 | /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A | |
6216 | and ARMv7-R architecture CPUs. */ | |
6217 | is_apsr = TRUE; | |
6218 | psr_field = 0; | |
6219 | } | |
6220 | else if (m_profile) | |
62b3e311 PB |
6221 | { |
6222 | start = p; | |
6223 | do | |
6224 | p++; | |
6225 | while (ISALNUM (*p) || *p == '_'); | |
6226 | ||
d2cd1205 JB |
6227 | if (strncasecmp (start, "iapsr", 5) == 0 |
6228 | || strncasecmp (start, "eapsr", 5) == 0 | |
6229 | || strncasecmp (start, "xpsr", 4) == 0 | |
6230 | || strncasecmp (start, "psr", 3) == 0) | |
6231 | p = start + strcspn (start, "rR") + 1; | |
6232 | ||
21d799b5 | 6233 | psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start, |
477330fc | 6234 | p - start); |
d2cd1205 | 6235 | |
62b3e311 PB |
6236 | if (!psr) |
6237 | return FAIL; | |
09d92015 | 6238 | |
d2cd1205 JB |
6239 | /* If APSR is being written, a bitfield may be specified. Note that |
6240 | APSR itself is handled above. */ | |
6241 | if (psr->field <= 3) | |
6242 | { | |
6243 | psr_field = psr->field; | |
6244 | is_apsr = TRUE; | |
6245 | goto check_suffix; | |
6246 | } | |
6247 | ||
62b3e311 | 6248 | *str = p; |
d2cd1205 JB |
6249 | /* M-profile MSR instructions have the mask field set to "10", except |
6250 | *PSR variants which modify APSR, which may use a different mask (and | |
6251 | have been handled already). Do that by setting the PSR_f field | |
6252 | here. */ | |
6253 | return psr->field | (lhs ? PSR_f : 0); | |
62b3e311 | 6254 | } |
d2cd1205 JB |
6255 | else |
6256 | goto unsupported_psr; | |
09d92015 | 6257 | |
62b3e311 | 6258 | p += 4; |
d2cd1205 | 6259 | check_suffix: |
c19d1205 ZW |
6260 | if (*p == '_') |
6261 | { | |
6262 | /* A suffix follows. */ | |
c19d1205 ZW |
6263 | p++; |
6264 | start = p; | |
a737bd4d | 6265 | |
c19d1205 ZW |
6266 | do |
6267 | p++; | |
6268 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 6269 | |
d2cd1205 JB |
6270 | if (is_apsr) |
6271 | { | |
6272 | /* APSR uses a notation for bits, rather than fields. */ | |
6273 | unsigned int nzcvq_bits = 0; | |
6274 | unsigned int g_bit = 0; | |
6275 | char *bit; | |
fa94de6b | 6276 | |
d2cd1205 JB |
6277 | for (bit = start; bit != p; bit++) |
6278 | { | |
6279 | switch (TOLOWER (*bit)) | |
477330fc | 6280 | { |
d2cd1205 JB |
6281 | case 'n': |
6282 | nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01; | |
6283 | break; | |
6284 | ||
6285 | case 'z': | |
6286 | nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02; | |
6287 | break; | |
6288 | ||
6289 | case 'c': | |
6290 | nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04; | |
6291 | break; | |
6292 | ||
6293 | case 'v': | |
6294 | nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08; | |
6295 | break; | |
fa94de6b | 6296 | |
d2cd1205 JB |
6297 | case 'q': |
6298 | nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10; | |
6299 | break; | |
fa94de6b | 6300 | |
d2cd1205 JB |
6301 | case 'g': |
6302 | g_bit |= (g_bit & 0x1) ? 0x2 : 0x1; | |
6303 | break; | |
fa94de6b | 6304 | |
d2cd1205 JB |
6305 | default: |
6306 | inst.error = _("unexpected bit specified after APSR"); | |
6307 | return FAIL; | |
6308 | } | |
6309 | } | |
fa94de6b | 6310 | |
d2cd1205 JB |
6311 | if (nzcvq_bits == 0x1f) |
6312 | psr_field |= PSR_f; | |
fa94de6b | 6313 | |
d2cd1205 JB |
6314 | if (g_bit == 0x1) |
6315 | { | |
6316 | if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)) | |
477330fc | 6317 | { |
d2cd1205 JB |
6318 | inst.error = _("selected processor does not " |
6319 | "support DSP extension"); | |
6320 | return FAIL; | |
6321 | } | |
6322 | ||
6323 | psr_field |= PSR_s; | |
6324 | } | |
fa94de6b | 6325 | |
d2cd1205 JB |
6326 | if ((nzcvq_bits & 0x20) != 0 |
6327 | || (nzcvq_bits != 0x1f && nzcvq_bits != 0) | |
6328 | || (g_bit & 0x2) != 0) | |
6329 | { | |
6330 | inst.error = _("bad bitmask specified after APSR"); | |
6331 | return FAIL; | |
6332 | } | |
6333 | } | |
6334 | else | |
477330fc | 6335 | { |
d2cd1205 | 6336 | psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start, |
477330fc | 6337 | p - start); |
d2cd1205 | 6338 | if (!psr) |
477330fc | 6339 | goto error; |
a737bd4d | 6340 | |
d2cd1205 JB |
6341 | psr_field |= psr->field; |
6342 | } | |
a737bd4d | 6343 | } |
c19d1205 | 6344 | else |
a737bd4d | 6345 | { |
c19d1205 ZW |
6346 | if (ISALNUM (*p)) |
6347 | goto error; /* Garbage after "[CS]PSR". */ | |
6348 | ||
d2cd1205 | 6349 | /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This |
477330fc | 6350 | is deprecated, but allow it anyway. */ |
d2cd1205 JB |
6351 | if (is_apsr && lhs) |
6352 | { | |
6353 | psr_field |= PSR_f; | |
6354 | as_tsktsk (_("writing to APSR without specifying a bitmask is " | |
6355 | "deprecated")); | |
6356 | } | |
6357 | else if (!m_profile) | |
6358 | /* These bits are never right for M-profile devices: don't set them | |
6359 | (only code paths which read/write APSR reach here). */ | |
6360 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 6361 | } |
c19d1205 ZW |
6362 | *str = p; |
6363 | return psr_field; | |
a737bd4d | 6364 | |
d2cd1205 JB |
6365 | unsupported_psr: |
6366 | inst.error = _("selected processor does not support requested special " | |
6367 | "purpose register"); | |
6368 | return FAIL; | |
6369 | ||
c19d1205 ZW |
6370 | error: |
6371 | inst.error = _("flag for {c}psr instruction expected"); | |
6372 | return FAIL; | |
a737bd4d NC |
6373 | } |
6374 | ||
32c36c3c AV |
6375 | static int |
6376 | parse_sys_vldr_vstr (char **str) | |
6377 | { | |
6378 | unsigned i; | |
6379 | int val = FAIL; | |
6380 | struct { | |
6381 | const char *name; | |
6382 | int regl; | |
6383 | int regh; | |
6384 | } sysregs[] = { | |
6385 | {"FPSCR", 0x1, 0x0}, | |
6386 | {"FPSCR_nzcvqc", 0x2, 0x0}, | |
6387 | {"VPR", 0x4, 0x1}, | |
6388 | {"P0", 0x5, 0x1}, | |
6389 | {"FPCXTNS", 0x6, 0x1}, | |
6390 | {"FPCXTS", 0x7, 0x1} | |
6391 | }; | |
6392 | char *op_end = strchr (*str, ','); | |
6393 | size_t op_strlen = op_end - *str; | |
6394 | ||
6395 | for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++) | |
6396 | { | |
6397 | if (!strncmp (*str, sysregs[i].name, op_strlen)) | |
6398 | { | |
6399 | val = sysregs[i].regl | (sysregs[i].regh << 3); | |
6400 | *str = op_end; | |
6401 | break; | |
6402 | } | |
6403 | } | |
6404 | ||
6405 | return val; | |
6406 | } | |
6407 | ||
c19d1205 ZW |
6408 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
6409 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 6410 | |
c19d1205 ZW |
6411 | static int |
6412 | parse_cps_flags (char **str) | |
a737bd4d | 6413 | { |
c19d1205 ZW |
6414 | int val = 0; |
6415 | int saw_a_flag = 0; | |
6416 | char *s = *str; | |
a737bd4d | 6417 | |
c19d1205 ZW |
6418 | for (;;) |
6419 | switch (*s++) | |
6420 | { | |
6421 | case '\0': case ',': | |
6422 | goto done; | |
a737bd4d | 6423 | |
c19d1205 ZW |
6424 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
6425 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
6426 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 6427 | |
c19d1205 ZW |
6428 | default: |
6429 | inst.error = _("unrecognized CPS flag"); | |
6430 | return FAIL; | |
6431 | } | |
a737bd4d | 6432 | |
c19d1205 ZW |
6433 | done: |
6434 | if (saw_a_flag == 0) | |
a737bd4d | 6435 | { |
c19d1205 ZW |
6436 | inst.error = _("missing CPS flags"); |
6437 | return FAIL; | |
a737bd4d | 6438 | } |
a737bd4d | 6439 | |
c19d1205 ZW |
6440 | *str = s - 1; |
6441 | return val; | |
a737bd4d NC |
6442 | } |
6443 | ||
c19d1205 ZW |
6444 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
6445 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
6446 | |
6447 | static int | |
c19d1205 | 6448 | parse_endian_specifier (char **str) |
a737bd4d | 6449 | { |
c19d1205 ZW |
6450 | int little_endian; |
6451 | char *s = *str; | |
a737bd4d | 6452 | |
c19d1205 ZW |
6453 | if (strncasecmp (s, "BE", 2)) |
6454 | little_endian = 0; | |
6455 | else if (strncasecmp (s, "LE", 2)) | |
6456 | little_endian = 1; | |
6457 | else | |
a737bd4d | 6458 | { |
c19d1205 | 6459 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
6460 | return FAIL; |
6461 | } | |
6462 | ||
c19d1205 | 6463 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 6464 | { |
c19d1205 | 6465 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
6466 | return FAIL; |
6467 | } | |
6468 | ||
c19d1205 ZW |
6469 | *str = s + 2; |
6470 | return little_endian; | |
6471 | } | |
a737bd4d | 6472 | |
c19d1205 ZW |
6473 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
6474 | value suitable for poking into the rotate field of an sxt or sxta | |
6475 | instruction, or FAIL on error. */ | |
6476 | ||
6477 | static int | |
6478 | parse_ror (char **str) | |
6479 | { | |
6480 | int rot; | |
6481 | char *s = *str; | |
6482 | ||
6483 | if (strncasecmp (s, "ROR", 3) == 0) | |
6484 | s += 3; | |
6485 | else | |
a737bd4d | 6486 | { |
c19d1205 | 6487 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
6488 | return FAIL; |
6489 | } | |
c19d1205 ZW |
6490 | |
6491 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
6492 | return FAIL; | |
6493 | ||
6494 | switch (rot) | |
a737bd4d | 6495 | { |
c19d1205 ZW |
6496 | case 0: *str = s; return 0x0; |
6497 | case 8: *str = s; return 0x1; | |
6498 | case 16: *str = s; return 0x2; | |
6499 | case 24: *str = s; return 0x3; | |
6500 | ||
6501 | default: | |
6502 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
6503 | return FAIL; |
6504 | } | |
c19d1205 | 6505 | } |
a737bd4d | 6506 | |
c19d1205 ZW |
6507 | /* Parse a conditional code (from conds[] below). The value returned is in the |
6508 | range 0 .. 14, or FAIL. */ | |
6509 | static int | |
6510 | parse_cond (char **str) | |
6511 | { | |
c462b453 | 6512 | char *q; |
c19d1205 | 6513 | const struct asm_cond *c; |
c462b453 PB |
6514 | int n; |
6515 | /* Condition codes are always 2 characters, so matching up to | |
6516 | 3 characters is sufficient. */ | |
6517 | char cond[3]; | |
a737bd4d | 6518 | |
c462b453 PB |
6519 | q = *str; |
6520 | n = 0; | |
6521 | while (ISALPHA (*q) && n < 3) | |
6522 | { | |
e07e6e58 | 6523 | cond[n] = TOLOWER (*q); |
c462b453 PB |
6524 | q++; |
6525 | n++; | |
6526 | } | |
a737bd4d | 6527 | |
21d799b5 | 6528 | c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n); |
c19d1205 | 6529 | if (!c) |
a737bd4d | 6530 | { |
c19d1205 | 6531 | inst.error = _("condition required"); |
a737bd4d NC |
6532 | return FAIL; |
6533 | } | |
6534 | ||
c19d1205 ZW |
6535 | *str = q; |
6536 | return c->value; | |
6537 | } | |
6538 | ||
62b3e311 PB |
6539 | /* Parse an option for a barrier instruction. Returns the encoding for the |
6540 | option, or FAIL. */ | |
6541 | static int | |
6542 | parse_barrier (char **str) | |
6543 | { | |
6544 | char *p, *q; | |
6545 | const struct asm_barrier_opt *o; | |
6546 | ||
6547 | p = q = *str; | |
6548 | while (ISALPHA (*q)) | |
6549 | q++; | |
6550 | ||
21d799b5 | 6551 | o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p, |
477330fc | 6552 | q - p); |
62b3e311 PB |
6553 | if (!o) |
6554 | return FAIL; | |
6555 | ||
e797f7e0 MGD |
6556 | if (!mark_feature_used (&o->arch)) |
6557 | return FAIL; | |
6558 | ||
62b3e311 PB |
6559 | *str = q; |
6560 | return o->value; | |
6561 | } | |
6562 | ||
92e90b6e PB |
6563 | /* Parse the operands of a table branch instruction. Similar to a memory |
6564 | operand. */ | |
6565 | static int | |
6566 | parse_tb (char **str) | |
6567 | { | |
6568 | char * p = *str; | |
6569 | int reg; | |
6570 | ||
6571 | if (skip_past_char (&p, '[') == FAIL) | |
ab1eb5fe PB |
6572 | { |
6573 | inst.error = _("'[' expected"); | |
6574 | return FAIL; | |
6575 | } | |
92e90b6e | 6576 | |
dcbf9037 | 6577 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
6578 | { |
6579 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
6580 | return FAIL; | |
6581 | } | |
6582 | inst.operands[0].reg = reg; | |
6583 | ||
6584 | if (skip_past_comma (&p) == FAIL) | |
ab1eb5fe PB |
6585 | { |
6586 | inst.error = _("',' expected"); | |
6587 | return FAIL; | |
6588 | } | |
5f4273c7 | 6589 | |
dcbf9037 | 6590 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
6591 | { |
6592 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
6593 | return FAIL; | |
6594 | } | |
6595 | inst.operands[0].imm = reg; | |
6596 | ||
6597 | if (skip_past_comma (&p) == SUCCESS) | |
6598 | { | |
6599 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
6600 | return FAIL; | |
e2b0ab59 | 6601 | if (inst.relocs[0].exp.X_add_number != 1) |
92e90b6e PB |
6602 | { |
6603 | inst.error = _("invalid shift"); | |
6604 | return FAIL; | |
6605 | } | |
6606 | inst.operands[0].shifted = 1; | |
6607 | } | |
6608 | ||
6609 | if (skip_past_char (&p, ']') == FAIL) | |
6610 | { | |
6611 | inst.error = _("']' expected"); | |
6612 | return FAIL; | |
6613 | } | |
6614 | *str = p; | |
6615 | return SUCCESS; | |
6616 | } | |
6617 | ||
5287ad62 JB |
6618 | /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more |
6619 | information on the types the operands can take and how they are encoded. | |
037e8744 JB |
6620 | Up to four operands may be read; this function handles setting the |
6621 | ".present" field for each read operand itself. | |
5287ad62 JB |
6622 | Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS, |
6623 | else returns FAIL. */ | |
6624 | ||
6625 | static int | |
6626 | parse_neon_mov (char **str, int *which_operand) | |
6627 | { | |
6628 | int i = *which_operand, val; | |
6629 | enum arm_reg_type rtype; | |
6630 | char *ptr = *str; | |
dcbf9037 | 6631 | struct neon_type_el optype; |
5f4273c7 | 6632 | |
57785aa2 AV |
6633 | if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL) |
6634 | { | |
6635 | /* Cases 17 or 19. */ | |
6636 | inst.operands[i].reg = val; | |
6637 | inst.operands[i].isvec = 1; | |
6638 | inst.operands[i].isscalar = 2; | |
6639 | inst.operands[i].vectype = optype; | |
6640 | inst.operands[i++].present = 1; | |
6641 | ||
6642 | if (skip_past_comma (&ptr) == FAIL) | |
6643 | goto wanted_comma; | |
6644 | ||
6645 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) | |
6646 | { | |
6647 | /* Case 17: VMOV<c>.<dt> <Qd[idx]>, <Rt> */ | |
6648 | inst.operands[i].reg = val; | |
6649 | inst.operands[i].isreg = 1; | |
6650 | inst.operands[i].present = 1; | |
6651 | } | |
6652 | else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL) | |
6653 | { | |
6654 | /* Case 19: VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> */ | |
6655 | inst.operands[i].reg = val; | |
6656 | inst.operands[i].isvec = 1; | |
6657 | inst.operands[i].isscalar = 2; | |
6658 | inst.operands[i].vectype = optype; | |
6659 | inst.operands[i++].present = 1; | |
6660 | ||
6661 | if (skip_past_comma (&ptr) == FAIL) | |
6662 | goto wanted_comma; | |
6663 | ||
6664 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6665 | goto wanted_arm; | |
6666 | ||
6667 | inst.operands[i].reg = val; | |
6668 | inst.operands[i].isreg = 1; | |
6669 | inst.operands[i++].present = 1; | |
6670 | ||
6671 | if (skip_past_comma (&ptr) == FAIL) | |
6672 | goto wanted_comma; | |
6673 | ||
6674 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6675 | goto wanted_arm; | |
6676 | ||
6677 | inst.operands[i].reg = val; | |
6678 | inst.operands[i].isreg = 1; | |
6679 | inst.operands[i].present = 1; | |
6680 | } | |
6681 | else | |
6682 | { | |
6683 | first_error (_("expected ARM or MVE vector register")); | |
6684 | return FAIL; | |
6685 | } | |
6686 | } | |
6687 | else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL) | |
5287ad62 JB |
6688 | { |
6689 | /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */ | |
6690 | inst.operands[i].reg = val; | |
6691 | inst.operands[i].isscalar = 1; | |
dcbf9037 | 6692 | inst.operands[i].vectype = optype; |
5287ad62 JB |
6693 | inst.operands[i++].present = 1; |
6694 | ||
6695 | if (skip_past_comma (&ptr) == FAIL) | |
477330fc | 6696 | goto wanted_comma; |
5f4273c7 | 6697 | |
dcbf9037 | 6698 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
477330fc | 6699 | goto wanted_arm; |
5f4273c7 | 6700 | |
5287ad62 JB |
6701 | inst.operands[i].reg = val; |
6702 | inst.operands[i].isreg = 1; | |
6703 | inst.operands[i].present = 1; | |
6704 | } | |
57785aa2 AV |
6705 | else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype)) |
6706 | != FAIL) | |
6707 | || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, &optype)) | |
6708 | != FAIL)) | |
5287ad62 JB |
6709 | { |
6710 | /* Cases 0, 1, 2, 3, 5 (D only). */ | |
6711 | if (skip_past_comma (&ptr) == FAIL) | |
477330fc | 6712 | goto wanted_comma; |
5f4273c7 | 6713 | |
5287ad62 JB |
6714 | inst.operands[i].reg = val; |
6715 | inst.operands[i].isreg = 1; | |
6716 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
6717 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
6718 | inst.operands[i].isvec = 1; | |
dcbf9037 | 6719 | inst.operands[i].vectype = optype; |
5287ad62 JB |
6720 | inst.operands[i++].present = 1; |
6721 | ||
dcbf9037 | 6722 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
477330fc RM |
6723 | { |
6724 | /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>. | |
6725 | Case 13: VMOV <Sd>, <Rm> */ | |
6726 | inst.operands[i].reg = val; | |
6727 | inst.operands[i].isreg = 1; | |
6728 | inst.operands[i].present = 1; | |
6729 | ||
6730 | if (rtype == REG_TYPE_NQ) | |
6731 | { | |
6732 | first_error (_("can't use Neon quad register here")); | |
6733 | return FAIL; | |
6734 | } | |
6735 | else if (rtype != REG_TYPE_VFS) | |
6736 | { | |
6737 | i++; | |
6738 | if (skip_past_comma (&ptr) == FAIL) | |
6739 | goto wanted_comma; | |
6740 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6741 | goto wanted_arm; | |
6742 | inst.operands[i].reg = val; | |
6743 | inst.operands[i].isreg = 1; | |
6744 | inst.operands[i].present = 1; | |
6745 | } | |
6746 | } | |
c4a23bf8 SP |
6747 | else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, |
6748 | &optype)) != FAIL) | |
6749 | || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, | |
6750 | &optype)) != FAIL)) | |
477330fc RM |
6751 | { |
6752 | /* Case 0: VMOV<c><q> <Qd>, <Qm> | |
6753 | Case 1: VMOV<c><q> <Dd>, <Dm> | |
6754 | Case 8: VMOV.F32 <Sd>, <Sm> | |
6755 | Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */ | |
6756 | ||
6757 | inst.operands[i].reg = val; | |
6758 | inst.operands[i].isreg = 1; | |
6759 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
6760 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
6761 | inst.operands[i].isvec = 1; | |
6762 | inst.operands[i].vectype = optype; | |
6763 | inst.operands[i].present = 1; | |
6764 | ||
6765 | if (skip_past_comma (&ptr) == SUCCESS) | |
6766 | { | |
6767 | /* Case 15. */ | |
6768 | i++; | |
6769 | ||
6770 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6771 | goto wanted_arm; | |
6772 | ||
6773 | inst.operands[i].reg = val; | |
6774 | inst.operands[i].isreg = 1; | |
6775 | inst.operands[i++].present = 1; | |
6776 | ||
6777 | if (skip_past_comma (&ptr) == FAIL) | |
6778 | goto wanted_comma; | |
6779 | ||
6780 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6781 | goto wanted_arm; | |
6782 | ||
6783 | inst.operands[i].reg = val; | |
6784 | inst.operands[i].isreg = 1; | |
6785 | inst.operands[i].present = 1; | |
6786 | } | |
6787 | } | |
4641781c | 6788 | else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS) |
477330fc RM |
6789 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm> |
6790 | Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm> | |
6791 | Case 10: VMOV.F32 <Sd>, #<imm> | |
6792 | Case 11: VMOV.F64 <Dd>, #<imm> */ | |
6793 | inst.operands[i].immisfloat = 1; | |
8335d6aa JW |
6794 | else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE) |
6795 | == SUCCESS) | |
477330fc RM |
6796 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm> |
6797 | Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */ | |
6798 | ; | |
5287ad62 | 6799 | else |
477330fc RM |
6800 | { |
6801 | first_error (_("expected <Rm> or <Dm> or <Qm> operand")); | |
6802 | return FAIL; | |
6803 | } | |
5287ad62 | 6804 | } |
dcbf9037 | 6805 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 | 6806 | { |
57785aa2 | 6807 | /* Cases 6, 7, 16, 18. */ |
5287ad62 JB |
6808 | inst.operands[i].reg = val; |
6809 | inst.operands[i].isreg = 1; | |
6810 | inst.operands[i++].present = 1; | |
5f4273c7 | 6811 | |
5287ad62 | 6812 | if (skip_past_comma (&ptr) == FAIL) |
477330fc | 6813 | goto wanted_comma; |
5f4273c7 | 6814 | |
57785aa2 AV |
6815 | if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL) |
6816 | { | |
6817 | /* Case 18: VMOV<c>.<dt> <Rt>, <Qn[idx]> */ | |
6818 | inst.operands[i].reg = val; | |
6819 | inst.operands[i].isscalar = 2; | |
6820 | inst.operands[i].present = 1; | |
6821 | inst.operands[i].vectype = optype; | |
6822 | } | |
6823 | else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL) | |
477330fc RM |
6824 | { |
6825 | /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */ | |
6826 | inst.operands[i].reg = val; | |
6827 | inst.operands[i].isscalar = 1; | |
6828 | inst.operands[i].present = 1; | |
6829 | inst.operands[i].vectype = optype; | |
6830 | } | |
dcbf9037 | 6831 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
477330fc | 6832 | { |
477330fc RM |
6833 | inst.operands[i].reg = val; |
6834 | inst.operands[i].isreg = 1; | |
6835 | inst.operands[i++].present = 1; | |
6836 | ||
6837 | if (skip_past_comma (&ptr) == FAIL) | |
6838 | goto wanted_comma; | |
6839 | ||
6840 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype)) | |
57785aa2 | 6841 | != FAIL) |
477330fc | 6842 | { |
57785aa2 | 6843 | /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */ |
477330fc | 6844 | |
477330fc RM |
6845 | inst.operands[i].reg = val; |
6846 | inst.operands[i].isreg = 1; | |
6847 | inst.operands[i].isvec = 1; | |
57785aa2 | 6848 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
477330fc RM |
6849 | inst.operands[i].vectype = optype; |
6850 | inst.operands[i].present = 1; | |
57785aa2 AV |
6851 | |
6852 | if (rtype == REG_TYPE_VFS) | |
6853 | { | |
6854 | /* Case 14. */ | |
6855 | i++; | |
6856 | if (skip_past_comma (&ptr) == FAIL) | |
6857 | goto wanted_comma; | |
6858 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, | |
6859 | &optype)) == FAIL) | |
6860 | { | |
6861 | first_error (_(reg_expected_msgs[REG_TYPE_VFS])); | |
6862 | return FAIL; | |
6863 | } | |
6864 | inst.operands[i].reg = val; | |
6865 | inst.operands[i].isreg = 1; | |
6866 | inst.operands[i].isvec = 1; | |
6867 | inst.operands[i].issingle = 1; | |
6868 | inst.operands[i].vectype = optype; | |
6869 | inst.operands[i].present = 1; | |
6870 | } | |
6871 | } | |
6872 | else | |
6873 | { | |
6874 | if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) | |
6875 | != FAIL) | |
6876 | { | |
6877 | /* Case 16: VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> */ | |
6878 | inst.operands[i].reg = val; | |
6879 | inst.operands[i].isvec = 1; | |
6880 | inst.operands[i].isscalar = 2; | |
6881 | inst.operands[i].vectype = optype; | |
6882 | inst.operands[i++].present = 1; | |
6883 | ||
6884 | if (skip_past_comma (&ptr) == FAIL) | |
6885 | goto wanted_comma; | |
6886 | ||
6887 | if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) | |
6888 | == FAIL) | |
6889 | { | |
6890 | first_error (_(reg_expected_msgs[REG_TYPE_MQ])); | |
6891 | return FAIL; | |
6892 | } | |
6893 | inst.operands[i].reg = val; | |
6894 | inst.operands[i].isvec = 1; | |
6895 | inst.operands[i].isscalar = 2; | |
6896 | inst.operands[i].vectype = optype; | |
6897 | inst.operands[i].present = 1; | |
6898 | } | |
6899 | else | |
6900 | { | |
6901 | first_error (_("VFP single, double or MVE vector register" | |
6902 | " expected")); | |
6903 | return FAIL; | |
6904 | } | |
477330fc RM |
6905 | } |
6906 | } | |
037e8744 | 6907 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype)) |
477330fc RM |
6908 | != FAIL) |
6909 | { | |
6910 | /* Case 13. */ | |
6911 | inst.operands[i].reg = val; | |
6912 | inst.operands[i].isreg = 1; | |
6913 | inst.operands[i].isvec = 1; | |
6914 | inst.operands[i].issingle = 1; | |
6915 | inst.operands[i].vectype = optype; | |
6916 | inst.operands[i].present = 1; | |
6917 | } | |
5287ad62 JB |
6918 | } |
6919 | else | |
6920 | { | |
dcbf9037 | 6921 | first_error (_("parse error")); |
5287ad62 JB |
6922 | return FAIL; |
6923 | } | |
6924 | ||
6925 | /* Successfully parsed the operands. Update args. */ | |
6926 | *which_operand = i; | |
6927 | *str = ptr; | |
6928 | return SUCCESS; | |
6929 | ||
5f4273c7 | 6930 | wanted_comma: |
dcbf9037 | 6931 | first_error (_("expected comma")); |
5287ad62 | 6932 | return FAIL; |
5f4273c7 NC |
6933 | |
6934 | wanted_arm: | |
dcbf9037 | 6935 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
5287ad62 | 6936 | return FAIL; |
5287ad62 JB |
6937 | } |
6938 | ||
5be8be5d DG |
6939 | /* Use this macro when the operand constraints are different |
6940 | for ARM and THUMB (e.g. ldrd). */ | |
6941 | #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \ | |
6942 | ((arm_operand) | ((thumb_operand) << 16)) | |
6943 | ||
c19d1205 ZW |
6944 | /* Matcher codes for parse_operands. */ |
6945 | enum operand_parse_code | |
6946 | { | |
6947 | OP_stop, /* end of line */ | |
6948 | ||
6949 | OP_RR, /* ARM register */ | |
6950 | OP_RRnpc, /* ARM register, not r15 */ | |
5be8be5d | 6951 | OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */ |
c19d1205 | 6952 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ |
fa94de6b | 6953 | OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback, |
55881a11 | 6954 | optional trailing ! */ |
c19d1205 ZW |
6955 | OP_RRw, /* ARM register, not r15, optional trailing ! */ |
6956 | OP_RCP, /* Coprocessor number */ | |
6957 | OP_RCN, /* Coprocessor register */ | |
6958 | OP_RF, /* FPA register */ | |
6959 | OP_RVS, /* VFP single precision register */ | |
5287ad62 JB |
6960 | OP_RVD, /* VFP double precision register (0..15) */ |
6961 | OP_RND, /* Neon double precision register (0..31) */ | |
5ee91343 AV |
6962 | OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */ |
6963 | OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register. | |
6964 | */ | |
5287ad62 | 6965 | OP_RNQ, /* Neon quad precision register */ |
5ee91343 | 6966 | OP_RNQMQ, /* Neon quad or MVE vector register. */ |
037e8744 | 6967 | OP_RVSD, /* VFP single or double precision register */ |
1b883319 | 6968 | OP_RVSD_COND, /* VFP single, double precision register or condition code. */ |
dd9634d9 | 6969 | OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */ |
dec41383 | 6970 | OP_RNSD, /* Neon single or double precision register */ |
5287ad62 | 6971 | OP_RNDQ, /* Neon double or quad precision register */ |
5ee91343 | 6972 | OP_RNDQMQ, /* Neon double, quad or MVE vector register. */ |
7df54120 | 6973 | OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */ |
037e8744 | 6974 | OP_RNSDQ, /* Neon single, double or quad precision register */ |
5287ad62 | 6975 | OP_RNSC, /* Neon scalar D[X] */ |
c19d1205 ZW |
6976 | OP_RVC, /* VFP control register */ |
6977 | OP_RMF, /* Maverick F register */ | |
6978 | OP_RMD, /* Maverick D register */ | |
6979 | OP_RMFX, /* Maverick FX register */ | |
6980 | OP_RMDX, /* Maverick DX register */ | |
6981 | OP_RMAX, /* Maverick AX register */ | |
6982 | OP_RMDS, /* Maverick DSPSC register */ | |
6983 | OP_RIWR, /* iWMMXt wR register */ | |
6984 | OP_RIWC, /* iWMMXt wC register */ | |
6985 | OP_RIWG, /* iWMMXt wCG register */ | |
6986 | OP_RXA, /* XScale accumulator register */ | |
6987 | ||
5ee91343 AV |
6988 | OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register |
6989 | */ | |
6990 | OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or | |
6991 | GPR (no SP/SP) */ | |
a302e574 | 6992 | OP_RMQ, /* MVE vector register. */ |
1b883319 | 6993 | OP_RMQRZ, /* MVE vector or ARM register including ZR. */ |
35d1cfc2 | 6994 | OP_RMQRR, /* MVE vector or ARM register. */ |
a302e574 | 6995 | |
60f993ce AV |
6996 | /* New operands for Armv8.1-M Mainline. */ |
6997 | OP_LR, /* ARM LR register */ | |
a302e574 AV |
6998 | OP_RRe, /* ARM register, only even numbered. */ |
6999 | OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */ | |
60f993ce | 7000 | OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */ |
e39c1607 | 7001 | OP_RR_ZR, /* ARM register or ZR but no PC */ |
60f993ce | 7002 | |
c19d1205 | 7003 | OP_REGLST, /* ARM register list */ |
4b5a202f | 7004 | OP_CLRMLST, /* CLRM register list */ |
c19d1205 ZW |
7005 | OP_VRSLST, /* VFP single-precision register list */ |
7006 | OP_VRDLST, /* VFP double-precision register list */ | |
037e8744 | 7007 | OP_VRSDLST, /* VFP single or double-precision register list (& quad) */ |
5287ad62 JB |
7008 | OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */ |
7009 | OP_NSTRLST, /* Neon element/structure list */ | |
efd6b359 | 7010 | OP_VRSDVLST, /* VFP single or double-precision register list and VPR */ |
35c228db AV |
7011 | OP_MSTRLST2, /* MVE vector list with two elements. */ |
7012 | OP_MSTRLST4, /* MVE vector list with four elements. */ | |
5287ad62 | 7013 | |
5287ad62 | 7014 | OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */ |
037e8744 | 7015 | OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */ |
aacf0b33 | 7016 | OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */ |
1b883319 AV |
7017 | OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate |
7018 | zero. */ | |
5287ad62 | 7019 | OP_RR_RNSC, /* ARM reg or Neon scalar. */ |
dec41383 | 7020 | OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */ |
037e8744 | 7021 | OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */ |
886e1c73 AV |
7022 | OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register. |
7023 | */ | |
a8465a06 AV |
7024 | OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon |
7025 | scalar, or ARM register. */ | |
5287ad62 | 7026 | OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */ |
42b16635 AV |
7027 | OP_RNDQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, or ARM register. */ |
7028 | OP_RNDQMQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, MVE vector or ARM | |
7029 | register. */ | |
5d281bf0 | 7030 | OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */ |
5287ad62 JB |
7031 | OP_RND_RNSC, /* Neon D reg, or Neon scalar. */ |
7032 | OP_VMOV, /* Neon VMOV operands. */ | |
4316f0d2 | 7033 | OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */ |
f601a00c AV |
7034 | /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */ |
7035 | OP_RNDQMQ_Ibig, | |
5287ad62 | 7036 | OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */ |
5150f0d8 AV |
7037 | OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or |
7038 | ARM register. */ | |
2d447fca | 7039 | OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */ |
32c36c3c | 7040 | OP_VLDR, /* VLDR operand. */ |
5287ad62 JB |
7041 | |
7042 | OP_I0, /* immediate zero */ | |
c19d1205 ZW |
7043 | OP_I7, /* immediate value 0 .. 7 */ |
7044 | OP_I15, /* 0 .. 15 */ | |
7045 | OP_I16, /* 1 .. 16 */ | |
5287ad62 | 7046 | OP_I16z, /* 0 .. 16 */ |
c19d1205 ZW |
7047 | OP_I31, /* 0 .. 31 */ |
7048 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
7049 | OP_I32, /* 1 .. 32 */ | |
5287ad62 | 7050 | OP_I32z, /* 0 .. 32 */ |
08132bdd | 7051 | OP_I48_I64, /* 48 or 64 */ |
5287ad62 | 7052 | OP_I63, /* 0 .. 63 */ |
c19d1205 | 7053 | OP_I63s, /* -64 .. 63 */ |
5287ad62 JB |
7054 | OP_I64, /* 1 .. 64 */ |
7055 | OP_I64z, /* 0 .. 64 */ | |
c19d1205 | 7056 | OP_I255, /* 0 .. 255 */ |
c19d1205 ZW |
7057 | |
7058 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
7059 | OP_I7b, /* 0 .. 7 */ | |
7060 | OP_I15b, /* 0 .. 15 */ | |
7061 | OP_I31b, /* 0 .. 31 */ | |
7062 | ||
7063 | OP_SH, /* shifter operand */ | |
4962c51a | 7064 | OP_SHG, /* shifter operand with possible group relocation */ |
c19d1205 | 7065 | OP_ADDR, /* Memory address expression (any mode) */ |
35c228db | 7066 | OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */ |
4962c51a MS |
7067 | OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */ |
7068 | OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */ | |
7069 | OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */ | |
c19d1205 ZW |
7070 | OP_EXP, /* arbitrary expression */ |
7071 | OP_EXPi, /* same, with optional immediate prefix */ | |
7072 | OP_EXPr, /* same, with optional relocation suffix */ | |
e2b0ab59 | 7073 | OP_EXPs, /* same, with optional non-first operand relocation suffix */ |
b6895b4f | 7074 | OP_HALF, /* 0 .. 65535 or low/high reloc. */ |
c28eeff2 SN |
7075 | OP_IROT1, /* VCADD rotate immediate: 90, 270. */ |
7076 | OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */ | |
c19d1205 ZW |
7077 | |
7078 | OP_CPSF, /* CPS flags */ | |
7079 | OP_ENDI, /* Endianness specifier */ | |
d2cd1205 JB |
7080 | OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */ |
7081 | OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */ | |
c19d1205 | 7082 | OP_COND, /* conditional code */ |
92e90b6e | 7083 | OP_TB, /* Table branch. */ |
c19d1205 | 7084 | |
037e8744 JB |
7085 | OP_APSR_RR, /* ARM register or "APSR_nzcv". */ |
7086 | ||
c19d1205 | 7087 | OP_RRnpc_I0, /* ARM register or literal 0 */ |
33eaf5de | 7088 | OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */ |
c19d1205 ZW |
7089 | OP_RR_EXi, /* ARM register or expression with imm prefix */ |
7090 | OP_RF_IF, /* FPA register or immediate */ | |
7091 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
41adaa5c | 7092 | OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */ |
c19d1205 ZW |
7093 | |
7094 | /* Optional operands. */ | |
7095 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
7096 | OP_oI31b, /* 0 .. 31 */ | |
5287ad62 | 7097 | OP_oI32b, /* 1 .. 32 */ |
5f1af56b | 7098 | OP_oI32z, /* 0 .. 32 */ |
c19d1205 ZW |
7099 | OP_oIffffb, /* 0 .. 65535 */ |
7100 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
7101 | ||
7102 | OP_oRR, /* ARM register */ | |
60f993ce | 7103 | OP_oLR, /* ARM LR register */ |
c19d1205 | 7104 | OP_oRRnpc, /* ARM register, not the PC */ |
5be8be5d | 7105 | OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */ |
b6702015 | 7106 | OP_oRRw, /* ARM register, not r15, optional trailing ! */ |
5287ad62 JB |
7107 | OP_oRND, /* Optional Neon double precision register */ |
7108 | OP_oRNQ, /* Optional Neon quad precision register */ | |
5ee91343 | 7109 | OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */ |
5287ad62 | 7110 | OP_oRNDQ, /* Optional Neon double or quad precision register */ |
037e8744 | 7111 | OP_oRNSDQ, /* Optional single, double or quad precision vector register */ |
5ee91343 AV |
7112 | OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector |
7113 | register. */ | |
c19d1205 ZW |
7114 | OP_oSHll, /* LSL immediate */ |
7115 | OP_oSHar, /* ASR immediate */ | |
7116 | OP_oSHllar, /* LSL or ASR immediate */ | |
7117 | OP_oROR, /* ROR 0/8/16/24 */ | |
52e7f43d | 7118 | OP_oBARRIER_I15, /* Option argument for a barrier instruction. */ |
c19d1205 | 7119 | |
1b883319 AV |
7120 | OP_oRMQRZ, /* optional MVE vector or ARM register including ZR. */ |
7121 | ||
5be8be5d DG |
7122 | /* Some pre-defined mixed (ARM/THUMB) operands. */ |
7123 | OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp), | |
7124 | OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp), | |
7125 | OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp), | |
7126 | ||
c19d1205 ZW |
7127 | OP_FIRST_OPTIONAL = OP_oI7b |
7128 | }; | |
a737bd4d | 7129 | |
c19d1205 ZW |
7130 | /* Generic instruction operand parser. This does no encoding and no |
7131 | semantic validation; it merely squirrels values away in the inst | |
7132 | structure. Returns SUCCESS or FAIL depending on whether the | |
7133 | specified grammar matched. */ | |
7134 | static int | |
5be8be5d | 7135 | parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb) |
c19d1205 | 7136 | { |
5be8be5d | 7137 | unsigned const int *upat = pattern; |
c19d1205 ZW |
7138 | char *backtrack_pos = 0; |
7139 | const char *backtrack_error = 0; | |
99aad254 | 7140 | int i, val = 0, backtrack_index = 0; |
5287ad62 | 7141 | enum arm_reg_type rtype; |
4962c51a | 7142 | parse_operand_result result; |
5be8be5d | 7143 | unsigned int op_parse_code; |
efd6b359 | 7144 | bfd_boolean partial_match; |
c19d1205 | 7145 | |
e07e6e58 NC |
7146 | #define po_char_or_fail(chr) \ |
7147 | do \ | |
7148 | { \ | |
7149 | if (skip_past_char (&str, chr) == FAIL) \ | |
477330fc | 7150 | goto bad_args; \ |
e07e6e58 NC |
7151 | } \ |
7152 | while (0) | |
c19d1205 | 7153 | |
e07e6e58 NC |
7154 | #define po_reg_or_fail(regtype) \ |
7155 | do \ | |
dcbf9037 | 7156 | { \ |
e07e6e58 | 7157 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ |
477330fc | 7158 | & inst.operands[i].vectype); \ |
e07e6e58 | 7159 | if (val == FAIL) \ |
477330fc RM |
7160 | { \ |
7161 | first_error (_(reg_expected_msgs[regtype])); \ | |
7162 | goto failure; \ | |
7163 | } \ | |
e07e6e58 NC |
7164 | inst.operands[i].reg = val; \ |
7165 | inst.operands[i].isreg = 1; \ | |
7166 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
7167 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
7168 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
477330fc RM |
7169 | || rtype == REG_TYPE_VFD \ |
7170 | || rtype == REG_TYPE_NQ); \ | |
1b883319 | 7171 | inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \ |
dcbf9037 | 7172 | } \ |
e07e6e58 NC |
7173 | while (0) |
7174 | ||
7175 | #define po_reg_or_goto(regtype, label) \ | |
7176 | do \ | |
7177 | { \ | |
7178 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ | |
7179 | & inst.operands[i].vectype); \ | |
7180 | if (val == FAIL) \ | |
7181 | goto label; \ | |
dcbf9037 | 7182 | \ |
e07e6e58 NC |
7183 | inst.operands[i].reg = val; \ |
7184 | inst.operands[i].isreg = 1; \ | |
7185 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
7186 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
7187 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
477330fc | 7188 | || rtype == REG_TYPE_VFD \ |
e07e6e58 | 7189 | || rtype == REG_TYPE_NQ); \ |
1b883319 | 7190 | inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \ |
e07e6e58 NC |
7191 | } \ |
7192 | while (0) | |
7193 | ||
7194 | #define po_imm_or_fail(min, max, popt) \ | |
7195 | do \ | |
7196 | { \ | |
7197 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
7198 | goto failure; \ | |
7199 | inst.operands[i].imm = val; \ | |
7200 | } \ | |
7201 | while (0) | |
7202 | ||
08132bdd SP |
7203 | #define po_imm1_or_imm2_or_fail(imm1, imm2, popt) \ |
7204 | do \ | |
7205 | { \ | |
7206 | expressionS exp; \ | |
7207 | my_get_expression (&exp, &str, popt); \ | |
7208 | if (exp.X_op != O_constant) \ | |
7209 | { \ | |
7210 | inst.error = _("constant expression required"); \ | |
7211 | goto failure; \ | |
7212 | } \ | |
7213 | if (exp.X_add_number != imm1 && exp.X_add_number != imm2) \ | |
7214 | { \ | |
7215 | inst.error = _("immediate value 48 or 64 expected"); \ | |
7216 | goto failure; \ | |
7217 | } \ | |
7218 | inst.operands[i].imm = exp.X_add_number; \ | |
7219 | } \ | |
7220 | while (0) | |
7221 | ||
57785aa2 | 7222 | #define po_scalar_or_goto(elsz, label, reg_type) \ |
e07e6e58 NC |
7223 | do \ |
7224 | { \ | |
57785aa2 AV |
7225 | val = parse_scalar (& str, elsz, & inst.operands[i].vectype, \ |
7226 | reg_type); \ | |
e07e6e58 NC |
7227 | if (val == FAIL) \ |
7228 | goto label; \ | |
7229 | inst.operands[i].reg = val; \ | |
7230 | inst.operands[i].isscalar = 1; \ | |
7231 | } \ | |
7232 | while (0) | |
7233 | ||
7234 | #define po_misc_or_fail(expr) \ | |
7235 | do \ | |
7236 | { \ | |
7237 | if (expr) \ | |
7238 | goto failure; \ | |
7239 | } \ | |
7240 | while (0) | |
7241 | ||
7242 | #define po_misc_or_fail_no_backtrack(expr) \ | |
7243 | do \ | |
7244 | { \ | |
7245 | result = expr; \ | |
7246 | if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \ | |
7247 | backtrack_pos = 0; \ | |
7248 | if (result != PARSE_OPERAND_SUCCESS) \ | |
7249 | goto failure; \ | |
7250 | } \ | |
7251 | while (0) | |
4962c51a | 7252 | |
52e7f43d RE |
7253 | #define po_barrier_or_imm(str) \ |
7254 | do \ | |
7255 | { \ | |
7256 | val = parse_barrier (&str); \ | |
ccb84d65 JB |
7257 | if (val == FAIL && ! ISALPHA (*str)) \ |
7258 | goto immediate; \ | |
7259 | if (val == FAIL \ | |
7260 | /* ISB can only take SY as an option. */ \ | |
7261 | || ((inst.instruction & 0xf0) == 0x60 \ | |
7262 | && val != 0xf)) \ | |
52e7f43d | 7263 | { \ |
ccb84d65 JB |
7264 | inst.error = _("invalid barrier type"); \ |
7265 | backtrack_pos = 0; \ | |
7266 | goto failure; \ | |
52e7f43d RE |
7267 | } \ |
7268 | } \ | |
7269 | while (0) | |
7270 | ||
c19d1205 ZW |
7271 | skip_whitespace (str); |
7272 | ||
7273 | for (i = 0; upat[i] != OP_stop; i++) | |
7274 | { | |
5be8be5d DG |
7275 | op_parse_code = upat[i]; |
7276 | if (op_parse_code >= 1<<16) | |
7277 | op_parse_code = thumb ? (op_parse_code >> 16) | |
7278 | : (op_parse_code & ((1<<16)-1)); | |
7279 | ||
7280 | if (op_parse_code >= OP_FIRST_OPTIONAL) | |
c19d1205 ZW |
7281 | { |
7282 | /* Remember where we are in case we need to backtrack. */ | |
c19d1205 ZW |
7283 | backtrack_pos = str; |
7284 | backtrack_error = inst.error; | |
7285 | backtrack_index = i; | |
7286 | } | |
7287 | ||
b6702015 | 7288 | if (i > 0 && (i > 1 || inst.operands[0].present)) |
c19d1205 ZW |
7289 | po_char_or_fail (','); |
7290 | ||
5be8be5d | 7291 | switch (op_parse_code) |
c19d1205 ZW |
7292 | { |
7293 | /* Registers */ | |
7294 | case OP_oRRnpc: | |
5be8be5d | 7295 | case OP_oRRnpcsp: |
c19d1205 | 7296 | case OP_RRnpc: |
5be8be5d | 7297 | case OP_RRnpcsp: |
c19d1205 | 7298 | case OP_oRR: |
a302e574 AV |
7299 | case OP_RRe: |
7300 | case OP_RRo: | |
60f993ce AV |
7301 | case OP_LR: |
7302 | case OP_oLR: | |
c19d1205 ZW |
7303 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; |
7304 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
7305 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
7306 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
7307 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
7308 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
477330fc | 7309 | case OP_oRND: |
5ee91343 AV |
7310 | case OP_RNDMQR: |
7311 | po_reg_or_goto (REG_TYPE_RN, try_rndmq); | |
7312 | break; | |
7313 | try_rndmq: | |
7314 | case OP_RNDMQ: | |
7315 | po_reg_or_goto (REG_TYPE_MQ, try_rnd); | |
7316 | break; | |
7317 | try_rnd: | |
5287ad62 | 7318 | case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break; |
cd2cf30b PB |
7319 | case OP_RVC: |
7320 | po_reg_or_goto (REG_TYPE_VFC, coproc_reg); | |
7321 | break; | |
7322 | /* Also accept generic coprocessor regs for unknown registers. */ | |
7323 | coproc_reg: | |
ba6cd17f SD |
7324 | po_reg_or_goto (REG_TYPE_CN, vpr_po); |
7325 | break; | |
7326 | /* Also accept P0 or p0 for VPR.P0. Since P0 is already an | |
7327 | existing register with a value of 0, this seems like the | |
7328 | best way to parse P0. */ | |
7329 | vpr_po: | |
7330 | if (strncasecmp (str, "P0", 2) == 0) | |
7331 | { | |
7332 | str += 2; | |
7333 | inst.operands[i].isreg = 1; | |
7334 | inst.operands[i].reg = 13; | |
7335 | } | |
7336 | else | |
7337 | goto failure; | |
cd2cf30b | 7338 | break; |
c19d1205 ZW |
7339 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; |
7340 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
7341 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
7342 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
7343 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
7344 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
7345 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
7346 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
7347 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
7348 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
477330fc | 7349 | case OP_oRNQ: |
5ee91343 AV |
7350 | case OP_RNQMQ: |
7351 | po_reg_or_goto (REG_TYPE_MQ, try_nq); | |
7352 | break; | |
7353 | try_nq: | |
5287ad62 | 7354 | case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break; |
dec41383 | 7355 | case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break; |
7df54120 AV |
7356 | case OP_RNDQMQR: |
7357 | po_reg_or_goto (REG_TYPE_RN, try_rndqmq); | |
7358 | break; | |
7359 | try_rndqmq: | |
5ee91343 AV |
7360 | case OP_oRNDQMQ: |
7361 | case OP_RNDQMQ: | |
7362 | po_reg_or_goto (REG_TYPE_MQ, try_rndq); | |
7363 | break; | |
7364 | try_rndq: | |
477330fc | 7365 | case OP_oRNDQ: |
5287ad62 | 7366 | case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break; |
dd9634d9 AV |
7367 | case OP_RVSDMQ: |
7368 | po_reg_or_goto (REG_TYPE_MQ, try_rvsd); | |
7369 | break; | |
7370 | try_rvsd: | |
477330fc | 7371 | case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break; |
1b883319 AV |
7372 | case OP_RVSD_COND: |
7373 | po_reg_or_goto (REG_TYPE_VFSD, try_cond); | |
7374 | break; | |
477330fc RM |
7375 | case OP_oRNSDQ: |
7376 | case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break; | |
5ee91343 AV |
7377 | case OP_RNSDQMQR: |
7378 | po_reg_or_goto (REG_TYPE_RN, try_mq); | |
7379 | break; | |
7380 | try_mq: | |
7381 | case OP_oRNSDQMQ: | |
7382 | case OP_RNSDQMQ: | |
7383 | po_reg_or_goto (REG_TYPE_MQ, try_nsdq2); | |
7384 | break; | |
7385 | try_nsdq2: | |
7386 | po_reg_or_fail (REG_TYPE_NSDQ); | |
7387 | inst.error = 0; | |
7388 | break; | |
35d1cfc2 AV |
7389 | case OP_RMQRR: |
7390 | po_reg_or_goto (REG_TYPE_RN, try_rmq); | |
7391 | break; | |
7392 | try_rmq: | |
a302e574 AV |
7393 | case OP_RMQ: |
7394 | po_reg_or_fail (REG_TYPE_MQ); | |
7395 | break; | |
477330fc RM |
7396 | /* Neon scalar. Using an element size of 8 means that some invalid |
7397 | scalars are accepted here, so deal with those in later code. */ | |
57785aa2 | 7398 | case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break; |
477330fc RM |
7399 | |
7400 | case OP_RNDQ_I0: | |
7401 | { | |
7402 | po_reg_or_goto (REG_TYPE_NDQ, try_imm0); | |
7403 | break; | |
7404 | try_imm0: | |
7405 | po_imm_or_fail (0, 0, TRUE); | |
7406 | } | |
7407 | break; | |
7408 | ||
7409 | case OP_RVSD_I0: | |
7410 | po_reg_or_goto (REG_TYPE_VFSD, try_imm0); | |
7411 | break; | |
7412 | ||
1b883319 AV |
7413 | case OP_RSVDMQ_FI0: |
7414 | po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0); | |
7415 | break; | |
7416 | try_rsvd_fi0: | |
aacf0b33 KT |
7417 | case OP_RSVD_FI0: |
7418 | { | |
7419 | po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0); | |
7420 | break; | |
7421 | try_ifimm0: | |
7422 | if (parse_ifimm_zero (&str)) | |
7423 | inst.operands[i].imm = 0; | |
7424 | else | |
7425 | { | |
7426 | inst.error | |
7427 | = _("only floating point zero is allowed as immediate value"); | |
7428 | goto failure; | |
7429 | } | |
7430 | } | |
7431 | break; | |
7432 | ||
477330fc RM |
7433 | case OP_RR_RNSC: |
7434 | { | |
57785aa2 | 7435 | po_scalar_or_goto (8, try_rr, REG_TYPE_VFD); |
477330fc RM |
7436 | break; |
7437 | try_rr: | |
7438 | po_reg_or_fail (REG_TYPE_RN); | |
7439 | } | |
7440 | break; | |
7441 | ||
a8465a06 AV |
7442 | case OP_RNSDQ_RNSC_MQ_RR: |
7443 | po_reg_or_goto (REG_TYPE_RN, try_rnsdq_rnsc_mq); | |
7444 | break; | |
7445 | try_rnsdq_rnsc_mq: | |
886e1c73 AV |
7446 | case OP_RNSDQ_RNSC_MQ: |
7447 | po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc); | |
7448 | break; | |
7449 | try_rnsdq_rnsc: | |
477330fc RM |
7450 | case OP_RNSDQ_RNSC: |
7451 | { | |
57785aa2 AV |
7452 | po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD); |
7453 | inst.error = 0; | |
477330fc RM |
7454 | break; |
7455 | try_nsdq: | |
7456 | po_reg_or_fail (REG_TYPE_NSDQ); | |
57785aa2 | 7457 | inst.error = 0; |
477330fc RM |
7458 | } |
7459 | break; | |
7460 | ||
dec41383 JW |
7461 | case OP_RNSD_RNSC: |
7462 | { | |
57785aa2 | 7463 | po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD); |
dec41383 JW |
7464 | break; |
7465 | try_s_scalar: | |
57785aa2 | 7466 | po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS); |
dec41383 JW |
7467 | break; |
7468 | try_nsd: | |
7469 | po_reg_or_fail (REG_TYPE_NSD); | |
7470 | } | |
7471 | break; | |
7472 | ||
42b16635 AV |
7473 | case OP_RNDQMQ_RNSC_RR: |
7474 | po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc_rr); | |
7475 | break; | |
7476 | try_rndq_rnsc_rr: | |
7477 | case OP_RNDQ_RNSC_RR: | |
7478 | po_reg_or_goto (REG_TYPE_RN, try_rndq_rnsc); | |
7479 | break; | |
5d281bf0 AV |
7480 | case OP_RNDQMQ_RNSC: |
7481 | po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc); | |
7482 | break; | |
7483 | try_rndq_rnsc: | |
477330fc RM |
7484 | case OP_RNDQ_RNSC: |
7485 | { | |
57785aa2 | 7486 | po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD); |
477330fc RM |
7487 | break; |
7488 | try_ndq: | |
7489 | po_reg_or_fail (REG_TYPE_NDQ); | |
7490 | } | |
7491 | break; | |
7492 | ||
7493 | case OP_RND_RNSC: | |
7494 | { | |
57785aa2 | 7495 | po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD); |
477330fc RM |
7496 | break; |
7497 | try_vfd: | |
7498 | po_reg_or_fail (REG_TYPE_VFD); | |
7499 | } | |
7500 | break; | |
7501 | ||
7502 | case OP_VMOV: | |
7503 | /* WARNING: parse_neon_mov can move the operand counter, i. If we're | |
7504 | not careful then bad things might happen. */ | |
7505 | po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL); | |
7506 | break; | |
7507 | ||
f601a00c AV |
7508 | case OP_RNDQMQ_Ibig: |
7509 | po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig); | |
7510 | break; | |
7511 | try_rndq_ibig: | |
477330fc RM |
7512 | case OP_RNDQ_Ibig: |
7513 | { | |
7514 | po_reg_or_goto (REG_TYPE_NDQ, try_immbig); | |
7515 | break; | |
7516 | try_immbig: | |
7517 | /* There's a possibility of getting a 64-bit immediate here, so | |
7518 | we need special handling. */ | |
8335d6aa JW |
7519 | if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE) |
7520 | == FAIL) | |
477330fc RM |
7521 | { |
7522 | inst.error = _("immediate value is out of range"); | |
7523 | goto failure; | |
7524 | } | |
7525 | } | |
7526 | break; | |
7527 | ||
5150f0d8 AV |
7528 | case OP_RNDQMQ_I63b_RR: |
7529 | po_reg_or_goto (REG_TYPE_MQ, try_rndq_i63b_rr); | |
7530 | break; | |
7531 | try_rndq_i63b_rr: | |
7532 | po_reg_or_goto (REG_TYPE_RN, try_rndq_i63b); | |
7533 | break; | |
7534 | try_rndq_i63b: | |
477330fc RM |
7535 | case OP_RNDQ_I63b: |
7536 | { | |
7537 | po_reg_or_goto (REG_TYPE_NDQ, try_shimm); | |
7538 | break; | |
7539 | try_shimm: | |
7540 | po_imm_or_fail (0, 63, TRUE); | |
7541 | } | |
7542 | break; | |
c19d1205 ZW |
7543 | |
7544 | case OP_RRnpcb: | |
7545 | po_char_or_fail ('['); | |
7546 | po_reg_or_fail (REG_TYPE_RN); | |
7547 | po_char_or_fail (']'); | |
7548 | break; | |
a737bd4d | 7549 | |
55881a11 | 7550 | case OP_RRnpctw: |
c19d1205 | 7551 | case OP_RRw: |
b6702015 | 7552 | case OP_oRRw: |
c19d1205 ZW |
7553 | po_reg_or_fail (REG_TYPE_RN); |
7554 | if (skip_past_char (&str, '!') == SUCCESS) | |
7555 | inst.operands[i].writeback = 1; | |
7556 | break; | |
7557 | ||
7558 | /* Immediates */ | |
7559 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
7560 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
7561 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
477330fc | 7562 | case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break; |
c19d1205 ZW |
7563 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; |
7564 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
477330fc | 7565 | case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break; |
08132bdd | 7566 | case OP_I48_I64: po_imm1_or_imm2_or_fail (48, 64, FALSE); break; |
c19d1205 | 7567 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; |
477330fc RM |
7568 | case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break; |
7569 | case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break; | |
7570 | case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break; | |
c19d1205 | 7571 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; |
c19d1205 ZW |
7572 | |
7573 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
7574 | case OP_oI7b: | |
7575 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
7576 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
7577 | case OP_oI31b: | |
7578 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
477330fc RM |
7579 | case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break; |
7580 | case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break; | |
c19d1205 ZW |
7581 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; |
7582 | ||
7583 | /* Immediate variants */ | |
7584 | case OP_oI255c: | |
7585 | po_char_or_fail ('{'); | |
7586 | po_imm_or_fail (0, 255, TRUE); | |
7587 | po_char_or_fail ('}'); | |
7588 | break; | |
7589 | ||
7590 | case OP_I31w: | |
7591 | /* The expression parser chokes on a trailing !, so we have | |
7592 | to find it first and zap it. */ | |
7593 | { | |
7594 | char *s = str; | |
7595 | while (*s && *s != ',') | |
7596 | s++; | |
7597 | if (s[-1] == '!') | |
7598 | { | |
7599 | s[-1] = '\0'; | |
7600 | inst.operands[i].writeback = 1; | |
7601 | } | |
7602 | po_imm_or_fail (0, 31, TRUE); | |
7603 | if (str == s - 1) | |
7604 | str = s; | |
7605 | } | |
7606 | break; | |
7607 | ||
7608 | /* Expressions */ | |
7609 | case OP_EXPi: EXPi: | |
e2b0ab59 | 7610 | po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str, |
c19d1205 ZW |
7611 | GE_OPT_PREFIX)); |
7612 | break; | |
7613 | ||
7614 | case OP_EXP: | |
e2b0ab59 | 7615 | po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str, |
c19d1205 ZW |
7616 | GE_NO_PREFIX)); |
7617 | break; | |
7618 | ||
7619 | case OP_EXPr: EXPr: | |
e2b0ab59 | 7620 | po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str, |
c19d1205 | 7621 | GE_NO_PREFIX)); |
e2b0ab59 | 7622 | if (inst.relocs[0].exp.X_op == O_symbol) |
a737bd4d | 7623 | { |
c19d1205 ZW |
7624 | val = parse_reloc (&str); |
7625 | if (val == -1) | |
7626 | { | |
7627 | inst.error = _("unrecognized relocation suffix"); | |
7628 | goto failure; | |
7629 | } | |
7630 | else if (val != BFD_RELOC_UNUSED) | |
7631 | { | |
7632 | inst.operands[i].imm = val; | |
7633 | inst.operands[i].hasreloc = 1; | |
7634 | } | |
a737bd4d | 7635 | } |
c19d1205 | 7636 | break; |
a737bd4d | 7637 | |
e2b0ab59 AV |
7638 | case OP_EXPs: |
7639 | po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str, | |
7640 | GE_NO_PREFIX)); | |
7641 | if (inst.relocs[i].exp.X_op == O_symbol) | |
7642 | { | |
7643 | inst.operands[i].hasreloc = 1; | |
7644 | } | |
7645 | else if (inst.relocs[i].exp.X_op == O_constant) | |
7646 | { | |
7647 | inst.operands[i].imm = inst.relocs[i].exp.X_add_number; | |
7648 | inst.operands[i].hasreloc = 0; | |
7649 | } | |
7650 | break; | |
7651 | ||
b6895b4f PB |
7652 | /* Operand for MOVW or MOVT. */ |
7653 | case OP_HALF: | |
7654 | po_misc_or_fail (parse_half (&str)); | |
7655 | break; | |
7656 | ||
e07e6e58 | 7657 | /* Register or expression. */ |
c19d1205 ZW |
7658 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; |
7659 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 7660 | |
e07e6e58 | 7661 | /* Register or immediate. */ |
c19d1205 ZW |
7662 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; |
7663 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 7664 | |
23d00a41 SD |
7665 | case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break; |
7666 | I32: po_imm_or_fail (1, 32, FALSE); break; | |
7667 | ||
c19d1205 ZW |
7668 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
7669 | IF: | |
7670 | if (!is_immediate_prefix (*str)) | |
7671 | goto bad_args; | |
7672 | str++; | |
7673 | val = parse_fpa_immediate (&str); | |
7674 | if (val == FAIL) | |
7675 | goto failure; | |
7676 | /* FPA immediates are encoded as registers 8-15. | |
7677 | parse_fpa_immediate has already applied the offset. */ | |
7678 | inst.operands[i].reg = val; | |
7679 | inst.operands[i].isreg = 1; | |
7680 | break; | |
09d92015 | 7681 | |
2d447fca JM |
7682 | case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break; |
7683 | I32z: po_imm_or_fail (0, 32, FALSE); break; | |
7684 | ||
e07e6e58 | 7685 | /* Two kinds of register. */ |
c19d1205 ZW |
7686 | case OP_RIWR_RIWC: |
7687 | { | |
7688 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
97f87066 JM |
7689 | if (!rege |
7690 | || (rege->type != REG_TYPE_MMXWR | |
7691 | && rege->type != REG_TYPE_MMXWC | |
7692 | && rege->type != REG_TYPE_MMXWCG)) | |
c19d1205 ZW |
7693 | { |
7694 | inst.error = _("iWMMXt data or control register expected"); | |
7695 | goto failure; | |
7696 | } | |
7697 | inst.operands[i].reg = rege->number; | |
7698 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
7699 | } | |
7700 | break; | |
09d92015 | 7701 | |
41adaa5c JM |
7702 | case OP_RIWC_RIWG: |
7703 | { | |
7704 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
7705 | if (!rege | |
7706 | || (rege->type != REG_TYPE_MMXWC | |
7707 | && rege->type != REG_TYPE_MMXWCG)) | |
7708 | { | |
7709 | inst.error = _("iWMMXt control register expected"); | |
7710 | goto failure; | |
7711 | } | |
7712 | inst.operands[i].reg = rege->number; | |
7713 | inst.operands[i].isreg = 1; | |
7714 | } | |
7715 | break; | |
7716 | ||
c19d1205 ZW |
7717 | /* Misc */ |
7718 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
7719 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
7720 | case OP_oROR: val = parse_ror (&str); break; | |
1b883319 | 7721 | try_cond: |
c19d1205 | 7722 | case OP_COND: val = parse_cond (&str); break; |
52e7f43d RE |
7723 | case OP_oBARRIER_I15: |
7724 | po_barrier_or_imm (str); break; | |
7725 | immediate: | |
7726 | if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL) | |
477330fc | 7727 | goto failure; |
52e7f43d | 7728 | break; |
c19d1205 | 7729 | |
fa94de6b | 7730 | case OP_wPSR: |
d2cd1205 | 7731 | case OP_rPSR: |
90ec0d68 MGD |
7732 | po_reg_or_goto (REG_TYPE_RNB, try_psr); |
7733 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt)) | |
7734 | { | |
7735 | inst.error = _("Banked registers are not available with this " | |
7736 | "architecture."); | |
7737 | goto failure; | |
7738 | } | |
7739 | break; | |
d2cd1205 JB |
7740 | try_psr: |
7741 | val = parse_psr (&str, op_parse_code == OP_wPSR); | |
7742 | break; | |
037e8744 | 7743 | |
32c36c3c AV |
7744 | case OP_VLDR: |
7745 | po_reg_or_goto (REG_TYPE_VFSD, try_sysreg); | |
7746 | break; | |
7747 | try_sysreg: | |
7748 | val = parse_sys_vldr_vstr (&str); | |
7749 | break; | |
7750 | ||
477330fc RM |
7751 | case OP_APSR_RR: |
7752 | po_reg_or_goto (REG_TYPE_RN, try_apsr); | |
7753 | break; | |
7754 | try_apsr: | |
7755 | /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS | |
7756 | instruction). */ | |
7757 | if (strncasecmp (str, "APSR_", 5) == 0) | |
7758 | { | |
7759 | unsigned found = 0; | |
7760 | str += 5; | |
7761 | while (found < 15) | |
7762 | switch (*str++) | |
7763 | { | |
7764 | case 'c': found = (found & 1) ? 16 : found | 1; break; | |
7765 | case 'n': found = (found & 2) ? 16 : found | 2; break; | |
7766 | case 'z': found = (found & 4) ? 16 : found | 4; break; | |
7767 | case 'v': found = (found & 8) ? 16 : found | 8; break; | |
7768 | default: found = 16; | |
7769 | } | |
7770 | if (found != 15) | |
7771 | goto failure; | |
7772 | inst.operands[i].isvec = 1; | |
f7c21dc7 NC |
7773 | /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */ |
7774 | inst.operands[i].reg = REG_PC; | |
477330fc RM |
7775 | } |
7776 | else | |
7777 | goto failure; | |
7778 | break; | |
037e8744 | 7779 | |
92e90b6e PB |
7780 | case OP_TB: |
7781 | po_misc_or_fail (parse_tb (&str)); | |
7782 | break; | |
7783 | ||
e07e6e58 | 7784 | /* Register lists. */ |
c19d1205 | 7785 | case OP_REGLST: |
4b5a202f | 7786 | val = parse_reg_list (&str, REGLIST_RN); |
c19d1205 ZW |
7787 | if (*str == '^') |
7788 | { | |
5e0d7f77 | 7789 | inst.operands[i].writeback = 1; |
c19d1205 ZW |
7790 | str++; |
7791 | } | |
7792 | break; | |
09d92015 | 7793 | |
4b5a202f AV |
7794 | case OP_CLRMLST: |
7795 | val = parse_reg_list (&str, REGLIST_CLRM); | |
7796 | break; | |
7797 | ||
c19d1205 | 7798 | case OP_VRSLST: |
efd6b359 AV |
7799 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S, |
7800 | &partial_match); | |
c19d1205 | 7801 | break; |
09d92015 | 7802 | |
c19d1205 | 7803 | case OP_VRDLST: |
efd6b359 AV |
7804 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D, |
7805 | &partial_match); | |
c19d1205 | 7806 | break; |
a737bd4d | 7807 | |
477330fc RM |
7808 | case OP_VRSDLST: |
7809 | /* Allow Q registers too. */ | |
7810 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
efd6b359 | 7811 | REGLIST_NEON_D, &partial_match); |
477330fc RM |
7812 | if (val == FAIL) |
7813 | { | |
7814 | inst.error = NULL; | |
7815 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
efd6b359 AV |
7816 | REGLIST_VFP_S, &partial_match); |
7817 | inst.operands[i].issingle = 1; | |
7818 | } | |
7819 | break; | |
7820 | ||
7821 | case OP_VRSDVLST: | |
7822 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
7823 | REGLIST_VFP_D_VPR, &partial_match); | |
7824 | if (val == FAIL && !partial_match) | |
7825 | { | |
7826 | inst.error = NULL; | |
7827 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
7828 | REGLIST_VFP_S_VPR, &partial_match); | |
477330fc RM |
7829 | inst.operands[i].issingle = 1; |
7830 | } | |
7831 | break; | |
7832 | ||
7833 | case OP_NRDLST: | |
7834 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
efd6b359 | 7835 | REGLIST_NEON_D, &partial_match); |
477330fc | 7836 | break; |
5287ad62 | 7837 | |
35c228db AV |
7838 | case OP_MSTRLST4: |
7839 | case OP_MSTRLST2: | |
7840 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, | |
7841 | 1, &inst.operands[i].vectype); | |
7842 | if (val != (((op_parse_code == OP_MSTRLST2) ? 3 : 7) << 5 | 0xe)) | |
7843 | goto failure; | |
7844 | break; | |
5287ad62 | 7845 | case OP_NSTRLST: |
477330fc | 7846 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, |
35c228db | 7847 | 0, &inst.operands[i].vectype); |
477330fc | 7848 | break; |
5287ad62 | 7849 | |
c19d1205 | 7850 | /* Addressing modes */ |
35c228db AV |
7851 | case OP_ADDRMVE: |
7852 | po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE)); | |
7853 | break; | |
7854 | ||
c19d1205 ZW |
7855 | case OP_ADDR: |
7856 | po_misc_or_fail (parse_address (&str, i)); | |
7857 | break; | |
09d92015 | 7858 | |
4962c51a MS |
7859 | case OP_ADDRGLDR: |
7860 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7861 | parse_address_group_reloc (&str, i, GROUP_LDR)); |
4962c51a MS |
7862 | break; |
7863 | ||
7864 | case OP_ADDRGLDRS: | |
7865 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7866 | parse_address_group_reloc (&str, i, GROUP_LDRS)); |
4962c51a MS |
7867 | break; |
7868 | ||
7869 | case OP_ADDRGLDC: | |
7870 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7871 | parse_address_group_reloc (&str, i, GROUP_LDC)); |
4962c51a MS |
7872 | break; |
7873 | ||
c19d1205 ZW |
7874 | case OP_SH: |
7875 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
7876 | break; | |
09d92015 | 7877 | |
4962c51a MS |
7878 | case OP_SHG: |
7879 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7880 | parse_shifter_operand_group_reloc (&str, i)); |
4962c51a MS |
7881 | break; |
7882 | ||
c19d1205 ZW |
7883 | case OP_oSHll: |
7884 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
7885 | break; | |
09d92015 | 7886 | |
c19d1205 ZW |
7887 | case OP_oSHar: |
7888 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
7889 | break; | |
09d92015 | 7890 | |
c19d1205 ZW |
7891 | case OP_oSHllar: |
7892 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
7893 | break; | |
09d92015 | 7894 | |
1b883319 AV |
7895 | case OP_RMQRZ: |
7896 | case OP_oRMQRZ: | |
7897 | po_reg_or_goto (REG_TYPE_MQ, try_rr_zr); | |
7898 | break; | |
e39c1607 SD |
7899 | |
7900 | case OP_RR_ZR: | |
1b883319 AV |
7901 | try_rr_zr: |
7902 | po_reg_or_goto (REG_TYPE_RN, ZR); | |
7903 | break; | |
7904 | ZR: | |
7905 | po_reg_or_fail (REG_TYPE_ZR); | |
7906 | break; | |
7907 | ||
c19d1205 | 7908 | default: |
5be8be5d | 7909 | as_fatal (_("unhandled operand code %d"), op_parse_code); |
c19d1205 | 7910 | } |
09d92015 | 7911 | |
c19d1205 ZW |
7912 | /* Various value-based sanity checks and shared operations. We |
7913 | do not signal immediate failures for the register constraints; | |
7914 | this allows a syntax error to take precedence. */ | |
5be8be5d | 7915 | switch (op_parse_code) |
c19d1205 ZW |
7916 | { |
7917 | case OP_oRRnpc: | |
7918 | case OP_RRnpc: | |
7919 | case OP_RRnpcb: | |
7920 | case OP_RRw: | |
b6702015 | 7921 | case OP_oRRw: |
c19d1205 ZW |
7922 | case OP_RRnpc_I0: |
7923 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
7924 | inst.error = BAD_PC; | |
7925 | break; | |
09d92015 | 7926 | |
5be8be5d DG |
7927 | case OP_oRRnpcsp: |
7928 | case OP_RRnpcsp: | |
23d00a41 | 7929 | case OP_RRnpcsp_I32: |
5be8be5d DG |
7930 | if (inst.operands[i].isreg) |
7931 | { | |
7932 | if (inst.operands[i].reg == REG_PC) | |
7933 | inst.error = BAD_PC; | |
5c8ed6a4 JW |
7934 | else if (inst.operands[i].reg == REG_SP |
7935 | /* The restriction on Rd/Rt/Rt2 on Thumb mode has been | |
7936 | relaxed since ARMv8-A. */ | |
7937 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
7938 | { | |
7939 | gas_assert (thumb); | |
7940 | inst.error = BAD_SP; | |
7941 | } | |
5be8be5d DG |
7942 | } |
7943 | break; | |
7944 | ||
55881a11 | 7945 | case OP_RRnpctw: |
fa94de6b RM |
7946 | if (inst.operands[i].isreg |
7947 | && inst.operands[i].reg == REG_PC | |
55881a11 MGD |
7948 | && (inst.operands[i].writeback || thumb)) |
7949 | inst.error = BAD_PC; | |
7950 | break; | |
7951 | ||
1b883319 | 7952 | case OP_RVSD_COND: |
32c36c3c AV |
7953 | case OP_VLDR: |
7954 | if (inst.operands[i].isreg) | |
7955 | break; | |
7956 | /* fall through. */ | |
1b883319 | 7957 | |
c19d1205 ZW |
7958 | case OP_CPSF: |
7959 | case OP_ENDI: | |
7960 | case OP_oROR: | |
d2cd1205 JB |
7961 | case OP_wPSR: |
7962 | case OP_rPSR: | |
c19d1205 | 7963 | case OP_COND: |
52e7f43d | 7964 | case OP_oBARRIER_I15: |
c19d1205 | 7965 | case OP_REGLST: |
4b5a202f | 7966 | case OP_CLRMLST: |
c19d1205 ZW |
7967 | case OP_VRSLST: |
7968 | case OP_VRDLST: | |
477330fc | 7969 | case OP_VRSDLST: |
efd6b359 | 7970 | case OP_VRSDVLST: |
477330fc RM |
7971 | case OP_NRDLST: |
7972 | case OP_NSTRLST: | |
35c228db AV |
7973 | case OP_MSTRLST2: |
7974 | case OP_MSTRLST4: | |
c19d1205 ZW |
7975 | if (val == FAIL) |
7976 | goto failure; | |
7977 | inst.operands[i].imm = val; | |
7978 | break; | |
a737bd4d | 7979 | |
60f993ce AV |
7980 | case OP_LR: |
7981 | case OP_oLR: | |
7982 | if (inst.operands[i].reg != REG_LR) | |
7983 | inst.error = _("operand must be LR register"); | |
7984 | break; | |
7985 | ||
1b883319 AV |
7986 | case OP_RMQRZ: |
7987 | case OP_oRMQRZ: | |
e39c1607 | 7988 | case OP_RR_ZR: |
1b883319 AV |
7989 | if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC) |
7990 | inst.error = BAD_PC; | |
7991 | break; | |
7992 | ||
a302e574 AV |
7993 | case OP_RRe: |
7994 | if (inst.operands[i].isreg | |
7995 | && (inst.operands[i].reg & 0x00000001) != 0) | |
7996 | inst.error = BAD_ODD; | |
7997 | break; | |
7998 | ||
7999 | case OP_RRo: | |
8000 | if (inst.operands[i].isreg) | |
8001 | { | |
8002 | if ((inst.operands[i].reg & 0x00000001) != 1) | |
8003 | inst.error = BAD_EVEN; | |
8004 | else if (inst.operands[i].reg == REG_SP) | |
8005 | as_tsktsk (MVE_BAD_SP); | |
8006 | else if (inst.operands[i].reg == REG_PC) | |
8007 | inst.error = BAD_PC; | |
8008 | } | |
8009 | break; | |
8010 | ||
c19d1205 ZW |
8011 | default: |
8012 | break; | |
8013 | } | |
09d92015 | 8014 | |
c19d1205 ZW |
8015 | /* If we get here, this operand was successfully parsed. */ |
8016 | inst.operands[i].present = 1; | |
8017 | continue; | |
09d92015 | 8018 | |
c19d1205 | 8019 | bad_args: |
09d92015 | 8020 | inst.error = BAD_ARGS; |
c19d1205 ZW |
8021 | |
8022 | failure: | |
8023 | if (!backtrack_pos) | |
d252fdde PB |
8024 | { |
8025 | /* The parse routine should already have set inst.error, but set a | |
5f4273c7 | 8026 | default here just in case. */ |
d252fdde | 8027 | if (!inst.error) |
5ee91343 | 8028 | inst.error = BAD_SYNTAX; |
d252fdde PB |
8029 | return FAIL; |
8030 | } | |
c19d1205 ZW |
8031 | |
8032 | /* Do not backtrack over a trailing optional argument that | |
8033 | absorbed some text. We will only fail again, with the | |
8034 | 'garbage following instruction' error message, which is | |
8035 | probably less helpful than the current one. */ | |
8036 | if (backtrack_index == i && backtrack_pos != str | |
8037 | && upat[i+1] == OP_stop) | |
d252fdde PB |
8038 | { |
8039 | if (!inst.error) | |
5ee91343 | 8040 | inst.error = BAD_SYNTAX; |
d252fdde PB |
8041 | return FAIL; |
8042 | } | |
c19d1205 ZW |
8043 | |
8044 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
8045 | str = backtrack_pos; | |
8046 | inst.error = backtrack_error; | |
8047 | inst.operands[backtrack_index].present = 0; | |
8048 | i = backtrack_index; | |
8049 | backtrack_pos = 0; | |
09d92015 | 8050 | } |
09d92015 | 8051 | |
c19d1205 ZW |
8052 | /* Check that we have parsed all the arguments. */ |
8053 | if (*str != '\0' && !inst.error) | |
8054 | inst.error = _("garbage following instruction"); | |
09d92015 | 8055 | |
c19d1205 | 8056 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
8057 | } |
8058 | ||
c19d1205 ZW |
8059 | #undef po_char_or_fail |
8060 | #undef po_reg_or_fail | |
8061 | #undef po_reg_or_goto | |
8062 | #undef po_imm_or_fail | |
5287ad62 | 8063 | #undef po_scalar_or_fail |
52e7f43d | 8064 | #undef po_barrier_or_imm |
e07e6e58 | 8065 | |
c19d1205 | 8066 | /* Shorthand macro for instruction encoding functions issuing errors. */ |
e07e6e58 NC |
8067 | #define constraint(expr, err) \ |
8068 | do \ | |
c19d1205 | 8069 | { \ |
e07e6e58 NC |
8070 | if (expr) \ |
8071 | { \ | |
8072 | inst.error = err; \ | |
8073 | return; \ | |
8074 | } \ | |
c19d1205 | 8075 | } \ |
e07e6e58 | 8076 | while (0) |
c19d1205 | 8077 | |
fdfde340 JM |
8078 | /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2 |
8079 | instructions are unpredictable if these registers are used. This | |
5c8ed6a4 JW |
8080 | is the BadReg predicate in ARM's Thumb-2 documentation. |
8081 | ||
8082 | Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few | |
8083 | places, while the restriction on REG_SP was relaxed since ARMv8-A. */ | |
8084 | #define reject_bad_reg(reg) \ | |
8085 | do \ | |
8086 | if (reg == REG_PC) \ | |
8087 | { \ | |
8088 | inst.error = BAD_PC; \ | |
8089 | return; \ | |
8090 | } \ | |
8091 | else if (reg == REG_SP \ | |
8092 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \ | |
8093 | { \ | |
8094 | inst.error = BAD_SP; \ | |
8095 | return; \ | |
8096 | } \ | |
fdfde340 JM |
8097 | while (0) |
8098 | ||
94206790 MM |
8099 | /* If REG is R13 (the stack pointer), warn that its use is |
8100 | deprecated. */ | |
8101 | #define warn_deprecated_sp(reg) \ | |
8102 | do \ | |
8103 | if (warn_on_deprecated && reg == REG_SP) \ | |
5c3696f8 | 8104 | as_tsktsk (_("use of r13 is deprecated")); \ |
94206790 MM |
8105 | while (0) |
8106 | ||
c19d1205 ZW |
8107 | /* Functions for operand encoding. ARM, then Thumb. */ |
8108 | ||
d840c081 | 8109 | #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31)) |
c19d1205 | 8110 | |
9db2f6b4 RL |
8111 | /* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding. |
8112 | ||
8113 | The only binary encoding difference is the Coprocessor number. Coprocessor | |
8114 | 9 is used for half-precision calculations or conversions. The format of the | |
2b0f3761 | 8115 | instruction is the same as the equivalent Coprocessor 10 instruction that |
9db2f6b4 RL |
8116 | exists for Single-Precision operation. */ |
8117 | ||
8118 | static void | |
8119 | do_scalar_fp16_v82_encode (void) | |
8120 | { | |
5ee91343 | 8121 | if (inst.cond < COND_ALWAYS) |
9db2f6b4 RL |
8122 | as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional," |
8123 | " the behaviour is UNPREDICTABLE")); | |
8124 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16), | |
8125 | _(BAD_FP16)); | |
8126 | ||
8127 | inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900; | |
8128 | mark_feature_used (&arm_ext_fp16); | |
8129 | } | |
8130 | ||
c19d1205 ZW |
8131 | /* If VAL can be encoded in the immediate field of an ARM instruction, |
8132 | return the encoded form. Otherwise, return FAIL. */ | |
8133 | ||
8134 | static unsigned int | |
8135 | encode_arm_immediate (unsigned int val) | |
09d92015 | 8136 | { |
c19d1205 ZW |
8137 | unsigned int a, i; |
8138 | ||
4f1d6205 L |
8139 | if (val <= 0xff) |
8140 | return val; | |
8141 | ||
8142 | for (i = 2; i < 32; i += 2) | |
c19d1205 ZW |
8143 | if ((a = rotate_left (val, i)) <= 0xff) |
8144 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
8145 | ||
8146 | return FAIL; | |
09d92015 MM |
8147 | } |
8148 | ||
c19d1205 ZW |
8149 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
8150 | return the encoded form. Otherwise, return FAIL. */ | |
8151 | static unsigned int | |
8152 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 8153 | { |
c19d1205 | 8154 | unsigned int a, i; |
09d92015 | 8155 | |
9c3c69f2 | 8156 | if (val <= 0xff) |
c19d1205 | 8157 | return val; |
a737bd4d | 8158 | |
9c3c69f2 | 8159 | for (i = 1; i <= 24; i++) |
09d92015 | 8160 | { |
9c3c69f2 PB |
8161 | a = val >> i; |
8162 | if ((val & ~(0xff << i)) == 0) | |
8163 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 8164 | } |
a737bd4d | 8165 | |
c19d1205 ZW |
8166 | a = val & 0xff; |
8167 | if (val == ((a << 16) | a)) | |
8168 | return 0x100 | a; | |
8169 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
8170 | return 0x300 | a; | |
09d92015 | 8171 | |
c19d1205 ZW |
8172 | a = val & 0xff00; |
8173 | if (val == ((a << 16) | a)) | |
8174 | return 0x200 | (a >> 8); | |
a737bd4d | 8175 | |
c19d1205 | 8176 | return FAIL; |
09d92015 | 8177 | } |
5287ad62 | 8178 | /* Encode a VFP SP or DP register number into inst.instruction. */ |
09d92015 MM |
8179 | |
8180 | static void | |
5287ad62 JB |
8181 | encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos) |
8182 | { | |
8183 | if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm) | |
8184 | && reg > 15) | |
8185 | { | |
b1cc4aeb | 8186 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) |
477330fc RM |
8187 | { |
8188 | if (thumb_mode) | |
8189 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
8190 | fpu_vfp_ext_d32); | |
8191 | else | |
8192 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
8193 | fpu_vfp_ext_d32); | |
8194 | } | |
5287ad62 | 8195 | else |
477330fc RM |
8196 | { |
8197 | first_error (_("D register out of range for selected VFP version")); | |
8198 | return; | |
8199 | } | |
5287ad62 JB |
8200 | } |
8201 | ||
c19d1205 | 8202 | switch (pos) |
09d92015 | 8203 | { |
c19d1205 ZW |
8204 | case VFP_REG_Sd: |
8205 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
8206 | break; | |
8207 | ||
8208 | case VFP_REG_Sn: | |
8209 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
8210 | break; | |
8211 | ||
8212 | case VFP_REG_Sm: | |
8213 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
8214 | break; | |
8215 | ||
5287ad62 JB |
8216 | case VFP_REG_Dd: |
8217 | inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22); | |
8218 | break; | |
5f4273c7 | 8219 | |
5287ad62 JB |
8220 | case VFP_REG_Dn: |
8221 | inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7); | |
8222 | break; | |
5f4273c7 | 8223 | |
5287ad62 JB |
8224 | case VFP_REG_Dm: |
8225 | inst.instruction |= (reg & 15) | ((reg >> 4) << 5); | |
8226 | break; | |
8227 | ||
c19d1205 ZW |
8228 | default: |
8229 | abort (); | |
09d92015 | 8230 | } |
09d92015 MM |
8231 | } |
8232 | ||
c19d1205 | 8233 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 8234 | if any, is handled by md_apply_fix. */ |
09d92015 | 8235 | static void |
c19d1205 | 8236 | encode_arm_shift (int i) |
09d92015 | 8237 | { |
008a97ef RL |
8238 | /* register-shifted register. */ |
8239 | if (inst.operands[i].immisreg) | |
8240 | { | |
bf355b69 MR |
8241 | int op_index; |
8242 | for (op_index = 0; op_index <= i; ++op_index) | |
008a97ef | 8243 | { |
5689c942 RL |
8244 | /* Check the operand only when it's presented. In pre-UAL syntax, |
8245 | if the destination register is the same as the first operand, two | |
8246 | register form of the instruction can be used. */ | |
bf355b69 MR |
8247 | if (inst.operands[op_index].present && inst.operands[op_index].isreg |
8248 | && inst.operands[op_index].reg == REG_PC) | |
008a97ef RL |
8249 | as_warn (UNPRED_REG ("r15")); |
8250 | } | |
8251 | ||
8252 | if (inst.operands[i].imm == REG_PC) | |
8253 | as_warn (UNPRED_REG ("r15")); | |
8254 | } | |
8255 | ||
c19d1205 ZW |
8256 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
8257 | inst.instruction |= SHIFT_ROR << 5; | |
8258 | else | |
09d92015 | 8259 | { |
c19d1205 ZW |
8260 | inst.instruction |= inst.operands[i].shift_kind << 5; |
8261 | if (inst.operands[i].immisreg) | |
8262 | { | |
8263 | inst.instruction |= SHIFT_BY_REG; | |
8264 | inst.instruction |= inst.operands[i].imm << 8; | |
8265 | } | |
8266 | else | |
e2b0ab59 | 8267 | inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM; |
09d92015 | 8268 | } |
c19d1205 | 8269 | } |
09d92015 | 8270 | |
c19d1205 ZW |
8271 | static void |
8272 | encode_arm_shifter_operand (int i) | |
8273 | { | |
8274 | if (inst.operands[i].isreg) | |
09d92015 | 8275 | { |
c19d1205 ZW |
8276 | inst.instruction |= inst.operands[i].reg; |
8277 | encode_arm_shift (i); | |
09d92015 | 8278 | } |
c19d1205 | 8279 | else |
a415b1cd JB |
8280 | { |
8281 | inst.instruction |= INST_IMMEDIATE; | |
e2b0ab59 | 8282 | if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE) |
a415b1cd JB |
8283 | inst.instruction |= inst.operands[i].imm; |
8284 | } | |
09d92015 MM |
8285 | } |
8286 | ||
c19d1205 | 8287 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 8288 | static void |
c19d1205 | 8289 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 8290 | { |
2b2f5df9 NC |
8291 | /* PR 14260: |
8292 | Generate an error if the operand is not a register. */ | |
8293 | constraint (!inst.operands[i].isreg, | |
8294 | _("Instruction does not support =N addresses")); | |
8295 | ||
c19d1205 | 8296 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 8297 | |
c19d1205 | 8298 | if (inst.operands[i].preind) |
09d92015 | 8299 | { |
c19d1205 ZW |
8300 | if (is_t) |
8301 | { | |
8302 | inst.error = _("instruction does not accept preindexed addressing"); | |
8303 | return; | |
8304 | } | |
8305 | inst.instruction |= PRE_INDEX; | |
8306 | if (inst.operands[i].writeback) | |
8307 | inst.instruction |= WRITE_BACK; | |
09d92015 | 8308 | |
c19d1205 ZW |
8309 | } |
8310 | else if (inst.operands[i].postind) | |
8311 | { | |
9c2799c2 | 8312 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
8313 | if (is_t) |
8314 | inst.instruction |= WRITE_BACK; | |
8315 | } | |
8316 | else /* unindexed - only for coprocessor */ | |
09d92015 | 8317 | { |
c19d1205 | 8318 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
8319 | return; |
8320 | } | |
8321 | ||
c19d1205 ZW |
8322 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
8323 | && (((inst.instruction & 0x000f0000) >> 16) | |
8324 | == ((inst.instruction & 0x0000f000) >> 12))) | |
8325 | as_warn ((inst.instruction & LOAD_BIT) | |
8326 | ? _("destination register same as write-back base") | |
8327 | : _("source register same as write-back base")); | |
09d92015 MM |
8328 | } |
8329 | ||
c19d1205 ZW |
8330 | /* inst.operands[i] was set up by parse_address. Encode it into an |
8331 | ARM-format mode 2 load or store instruction. If is_t is true, | |
8332 | reject forms that cannot be used with a T instruction (i.e. not | |
8333 | post-indexed). */ | |
a737bd4d | 8334 | static void |
c19d1205 | 8335 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 8336 | { |
5be8be5d DG |
8337 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
8338 | ||
c19d1205 | 8339 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 8340 | |
c19d1205 | 8341 | if (inst.operands[i].immisreg) |
09d92015 | 8342 | { |
5be8be5d DG |
8343 | constraint ((inst.operands[i].imm == REG_PC |
8344 | || (is_pc && inst.operands[i].writeback)), | |
8345 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
8346 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
8347 | inst.instruction |= inst.operands[i].imm; | |
8348 | if (!inst.operands[i].negative) | |
8349 | inst.instruction |= INDEX_UP; | |
8350 | if (inst.operands[i].shifted) | |
8351 | { | |
8352 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
8353 | inst.instruction |= SHIFT_ROR << 5; | |
8354 | else | |
8355 | { | |
8356 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
e2b0ab59 | 8357 | inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM; |
c19d1205 ZW |
8358 | } |
8359 | } | |
09d92015 | 8360 | } |
e2b0ab59 | 8361 | else /* immediate offset in inst.relocs[0] */ |
09d92015 | 8362 | { |
e2b0ab59 | 8363 | if (is_pc && !inst.relocs[0].pc_rel) |
5be8be5d DG |
8364 | { |
8365 | const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0); | |
23a10334 JZ |
8366 | |
8367 | /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt | |
8368 | cannot use PC in addressing. | |
8369 | PC cannot be used in writeback addressing, either. */ | |
8370 | constraint ((is_t || inst.operands[i].writeback), | |
5be8be5d | 8371 | BAD_PC_ADDRESSING); |
23a10334 | 8372 | |
dc5ec521 | 8373 | /* Use of PC in str is deprecated for ARMv7. */ |
23a10334 JZ |
8374 | if (warn_on_deprecated |
8375 | && !is_load | |
8376 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7)) | |
5c3696f8 | 8377 | as_tsktsk (_("use of PC in this instruction is deprecated")); |
5be8be5d DG |
8378 | } |
8379 | ||
e2b0ab59 | 8380 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
26d97720 NS |
8381 | { |
8382 | /* Prefer + for zero encoded value. */ | |
8383 | if (!inst.operands[i].negative) | |
8384 | inst.instruction |= INDEX_UP; | |
e2b0ab59 | 8385 | inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM; |
26d97720 | 8386 | } |
09d92015 | 8387 | } |
09d92015 MM |
8388 | } |
8389 | ||
c19d1205 ZW |
8390 | /* inst.operands[i] was set up by parse_address. Encode it into an |
8391 | ARM-format mode 3 load or store instruction. Reject forms that | |
8392 | cannot be used with such instructions. If is_t is true, reject | |
8393 | forms that cannot be used with a T instruction (i.e. not | |
8394 | post-indexed). */ | |
8395 | static void | |
8396 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 8397 | { |
c19d1205 | 8398 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 8399 | { |
c19d1205 ZW |
8400 | inst.error = _("instruction does not accept scaled register index"); |
8401 | return; | |
09d92015 | 8402 | } |
a737bd4d | 8403 | |
c19d1205 | 8404 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 8405 | |
c19d1205 ZW |
8406 | if (inst.operands[i].immisreg) |
8407 | { | |
5be8be5d | 8408 | constraint ((inst.operands[i].imm == REG_PC |
eb9f3f00 | 8409 | || (is_t && inst.operands[i].reg == REG_PC)), |
5be8be5d | 8410 | BAD_PC_ADDRESSING); |
eb9f3f00 JB |
8411 | constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback, |
8412 | BAD_PC_WRITEBACK); | |
c19d1205 ZW |
8413 | inst.instruction |= inst.operands[i].imm; |
8414 | if (!inst.operands[i].negative) | |
8415 | inst.instruction |= INDEX_UP; | |
8416 | } | |
e2b0ab59 | 8417 | else /* immediate offset in inst.relocs[0] */ |
c19d1205 | 8418 | { |
e2b0ab59 | 8419 | constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel |
5be8be5d DG |
8420 | && inst.operands[i].writeback), |
8421 | BAD_PC_WRITEBACK); | |
c19d1205 | 8422 | inst.instruction |= HWOFFSET_IMM; |
e2b0ab59 | 8423 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
26d97720 NS |
8424 | { |
8425 | /* Prefer + for zero encoded value. */ | |
8426 | if (!inst.operands[i].negative) | |
8427 | inst.instruction |= INDEX_UP; | |
8428 | ||
e2b0ab59 | 8429 | inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8; |
26d97720 | 8430 | } |
c19d1205 | 8431 | } |
a737bd4d NC |
8432 | } |
8433 | ||
8335d6aa JW |
8434 | /* Write immediate bits [7:0] to the following locations: |
8435 | ||
8436 | |28/24|23 19|18 16|15 4|3 0| | |
8437 | | 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| | |
8438 | ||
8439 | This function is used by VMOV/VMVN/VORR/VBIC. */ | |
8440 | ||
8441 | static void | |
8442 | neon_write_immbits (unsigned immbits) | |
8443 | { | |
8444 | inst.instruction |= immbits & 0xf; | |
8445 | inst.instruction |= ((immbits >> 4) & 0x7) << 16; | |
8446 | inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24); | |
8447 | } | |
8448 | ||
8449 | /* Invert low-order SIZE bits of XHI:XLO. */ | |
8450 | ||
8451 | static void | |
8452 | neon_invert_size (unsigned *xlo, unsigned *xhi, int size) | |
8453 | { | |
8454 | unsigned immlo = xlo ? *xlo : 0; | |
8455 | unsigned immhi = xhi ? *xhi : 0; | |
8456 | ||
8457 | switch (size) | |
8458 | { | |
8459 | case 8: | |
8460 | immlo = (~immlo) & 0xff; | |
8461 | break; | |
8462 | ||
8463 | case 16: | |
8464 | immlo = (~immlo) & 0xffff; | |
8465 | break; | |
8466 | ||
8467 | case 64: | |
8468 | immhi = (~immhi) & 0xffffffff; | |
8469 | /* fall through. */ | |
8470 | ||
8471 | case 32: | |
8472 | immlo = (~immlo) & 0xffffffff; | |
8473 | break; | |
8474 | ||
8475 | default: | |
8476 | abort (); | |
8477 | } | |
8478 | ||
8479 | if (xlo) | |
8480 | *xlo = immlo; | |
8481 | ||
8482 | if (xhi) | |
8483 | *xhi = immhi; | |
8484 | } | |
8485 | ||
8486 | /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits | |
8487 | A, B, C, D. */ | |
09d92015 | 8488 | |
c19d1205 | 8489 | static int |
8335d6aa | 8490 | neon_bits_same_in_bytes (unsigned imm) |
09d92015 | 8491 | { |
8335d6aa JW |
8492 | return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff) |
8493 | && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00) | |
8494 | && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000) | |
8495 | && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000); | |
8496 | } | |
a737bd4d | 8497 | |
8335d6aa | 8498 | /* For immediate of above form, return 0bABCD. */ |
09d92015 | 8499 | |
8335d6aa JW |
8500 | static unsigned |
8501 | neon_squash_bits (unsigned imm) | |
8502 | { | |
8503 | return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14) | |
8504 | | ((imm & 0x01000000) >> 21); | |
8505 | } | |
8506 | ||
8507 | /* Compress quarter-float representation to 0b...000 abcdefgh. */ | |
8508 | ||
8509 | static unsigned | |
8510 | neon_qfloat_bits (unsigned imm) | |
8511 | { | |
8512 | return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80); | |
8513 | } | |
8514 | ||
8515 | /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into | |
8516 | the instruction. *OP is passed as the initial value of the op field, and | |
8517 | may be set to a different value depending on the constant (i.e. | |
8518 | "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not | |
8519 | MVN). If the immediate looks like a repeated pattern then also | |
8520 | try smaller element sizes. */ | |
8521 | ||
8522 | static int | |
8523 | neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p, | |
8524 | unsigned *immbits, int *op, int size, | |
8525 | enum neon_el_type type) | |
8526 | { | |
8527 | /* Only permit float immediates (including 0.0/-0.0) if the operand type is | |
8528 | float. */ | |
8529 | if (type == NT_float && !float_p) | |
8530 | return FAIL; | |
8531 | ||
8532 | if (type == NT_float && is_quarter_float (immlo) && immhi == 0) | |
09d92015 | 8533 | { |
8335d6aa JW |
8534 | if (size != 32 || *op == 1) |
8535 | return FAIL; | |
8536 | *immbits = neon_qfloat_bits (immlo); | |
8537 | return 0xf; | |
8538 | } | |
8539 | ||
8540 | if (size == 64) | |
8541 | { | |
8542 | if (neon_bits_same_in_bytes (immhi) | |
8543 | && neon_bits_same_in_bytes (immlo)) | |
c19d1205 | 8544 | { |
8335d6aa JW |
8545 | if (*op == 1) |
8546 | return FAIL; | |
8547 | *immbits = (neon_squash_bits (immhi) << 4) | |
8548 | | neon_squash_bits (immlo); | |
8549 | *op = 1; | |
8550 | return 0xe; | |
c19d1205 | 8551 | } |
a737bd4d | 8552 | |
8335d6aa JW |
8553 | if (immhi != immlo) |
8554 | return FAIL; | |
8555 | } | |
a737bd4d | 8556 | |
8335d6aa | 8557 | if (size >= 32) |
09d92015 | 8558 | { |
8335d6aa | 8559 | if (immlo == (immlo & 0x000000ff)) |
c19d1205 | 8560 | { |
8335d6aa JW |
8561 | *immbits = immlo; |
8562 | return 0x0; | |
c19d1205 | 8563 | } |
8335d6aa | 8564 | else if (immlo == (immlo & 0x0000ff00)) |
c19d1205 | 8565 | { |
8335d6aa JW |
8566 | *immbits = immlo >> 8; |
8567 | return 0x2; | |
c19d1205 | 8568 | } |
8335d6aa JW |
8569 | else if (immlo == (immlo & 0x00ff0000)) |
8570 | { | |
8571 | *immbits = immlo >> 16; | |
8572 | return 0x4; | |
8573 | } | |
8574 | else if (immlo == (immlo & 0xff000000)) | |
8575 | { | |
8576 | *immbits = immlo >> 24; | |
8577 | return 0x6; | |
8578 | } | |
8579 | else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff)) | |
8580 | { | |
8581 | *immbits = (immlo >> 8) & 0xff; | |
8582 | return 0xc; | |
8583 | } | |
8584 | else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff)) | |
8585 | { | |
8586 | *immbits = (immlo >> 16) & 0xff; | |
8587 | return 0xd; | |
8588 | } | |
8589 | ||
8590 | if ((immlo & 0xffff) != (immlo >> 16)) | |
8591 | return FAIL; | |
8592 | immlo &= 0xffff; | |
09d92015 | 8593 | } |
a737bd4d | 8594 | |
8335d6aa | 8595 | if (size >= 16) |
4962c51a | 8596 | { |
8335d6aa JW |
8597 | if (immlo == (immlo & 0x000000ff)) |
8598 | { | |
8599 | *immbits = immlo; | |
8600 | return 0x8; | |
8601 | } | |
8602 | else if (immlo == (immlo & 0x0000ff00)) | |
8603 | { | |
8604 | *immbits = immlo >> 8; | |
8605 | return 0xa; | |
8606 | } | |
8607 | ||
8608 | if ((immlo & 0xff) != (immlo >> 8)) | |
8609 | return FAIL; | |
8610 | immlo &= 0xff; | |
4962c51a MS |
8611 | } |
8612 | ||
8335d6aa JW |
8613 | if (immlo == (immlo & 0x000000ff)) |
8614 | { | |
8615 | /* Don't allow MVN with 8-bit immediate. */ | |
8616 | if (*op == 1) | |
8617 | return FAIL; | |
8618 | *immbits = immlo; | |
8619 | return 0xe; | |
8620 | } | |
26d97720 | 8621 | |
8335d6aa | 8622 | return FAIL; |
c19d1205 | 8623 | } |
a737bd4d | 8624 | |
5fc177c8 | 8625 | #if defined BFD_HOST_64_BIT |
ba592044 AM |
8626 | /* Returns TRUE if double precision value V may be cast |
8627 | to single precision without loss of accuracy. */ | |
8628 | ||
8629 | static bfd_boolean | |
5fc177c8 | 8630 | is_double_a_single (bfd_int64_t v) |
ba592044 | 8631 | { |
5fc177c8 | 8632 | int exp = (int)((v >> 52) & 0x7FF); |
8fe3f3d6 | 8633 | bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL); |
ba592044 AM |
8634 | |
8635 | return (exp == 0 || exp == 0x7FF | |
8636 | || (exp >= 1023 - 126 && exp <= 1023 + 127)) | |
8637 | && (mantissa & 0x1FFFFFFFl) == 0; | |
8638 | } | |
8639 | ||
3739860c | 8640 | /* Returns a double precision value casted to single precision |
ba592044 AM |
8641 | (ignoring the least significant bits in exponent and mantissa). */ |
8642 | ||
8643 | static int | |
5fc177c8 | 8644 | double_to_single (bfd_int64_t v) |
ba592044 AM |
8645 | { |
8646 | int sign = (int) ((v >> 63) & 1l); | |
5fc177c8 | 8647 | int exp = (int) ((v >> 52) & 0x7FF); |
8fe3f3d6 | 8648 | bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL); |
ba592044 AM |
8649 | |
8650 | if (exp == 0x7FF) | |
8651 | exp = 0xFF; | |
8652 | else | |
8653 | { | |
8654 | exp = exp - 1023 + 127; | |
8655 | if (exp >= 0xFF) | |
8656 | { | |
8657 | /* Infinity. */ | |
8658 | exp = 0x7F; | |
8659 | mantissa = 0; | |
8660 | } | |
8661 | else if (exp < 0) | |
8662 | { | |
8663 | /* No denormalized numbers. */ | |
8664 | exp = 0; | |
8665 | mantissa = 0; | |
8666 | } | |
8667 | } | |
8668 | mantissa >>= 29; | |
8669 | return (sign << 31) | (exp << 23) | mantissa; | |
8670 | } | |
5fc177c8 | 8671 | #endif /* BFD_HOST_64_BIT */ |
ba592044 | 8672 | |
8335d6aa JW |
8673 | enum lit_type |
8674 | { | |
8675 | CONST_THUMB, | |
8676 | CONST_ARM, | |
8677 | CONST_VEC | |
8678 | }; | |
8679 | ||
ba592044 AM |
8680 | static void do_vfp_nsyn_opcode (const char *); |
8681 | ||
e2b0ab59 | 8682 | /* inst.relocs[0].exp describes an "=expr" load pseudo-operation. |
c19d1205 ZW |
8683 | Determine whether it can be performed with a move instruction; if |
8684 | it can, convert inst.instruction to that move instruction and | |
c921be7d NC |
8685 | return TRUE; if it can't, convert inst.instruction to a literal-pool |
8686 | load and return FALSE. If this is not a valid thing to do in the | |
8687 | current context, set inst.error and return TRUE. | |
a737bd4d | 8688 | |
c19d1205 ZW |
8689 | inst.operands[i] describes the destination register. */ |
8690 | ||
c921be7d | 8691 | static bfd_boolean |
8335d6aa | 8692 | move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3) |
c19d1205 | 8693 | { |
53365c0d | 8694 | unsigned long tbit; |
8335d6aa JW |
8695 | bfd_boolean thumb_p = (t == CONST_THUMB); |
8696 | bfd_boolean arm_p = (t == CONST_ARM); | |
53365c0d PB |
8697 | |
8698 | if (thumb_p) | |
8699 | tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT; | |
8700 | else | |
8701 | tbit = LOAD_BIT; | |
8702 | ||
8703 | if ((inst.instruction & tbit) == 0) | |
09d92015 | 8704 | { |
c19d1205 | 8705 | inst.error = _("invalid pseudo operation"); |
c921be7d | 8706 | return TRUE; |
09d92015 | 8707 | } |
ba592044 | 8708 | |
e2b0ab59 AV |
8709 | if (inst.relocs[0].exp.X_op != O_constant |
8710 | && inst.relocs[0].exp.X_op != O_symbol | |
8711 | && inst.relocs[0].exp.X_op != O_big) | |
09d92015 MM |
8712 | { |
8713 | inst.error = _("constant expression expected"); | |
c921be7d | 8714 | return TRUE; |
09d92015 | 8715 | } |
ba592044 | 8716 | |
e2b0ab59 AV |
8717 | if (inst.relocs[0].exp.X_op == O_constant |
8718 | || inst.relocs[0].exp.X_op == O_big) | |
8335d6aa | 8719 | { |
5fc177c8 NC |
8720 | #if defined BFD_HOST_64_BIT |
8721 | bfd_int64_t v; | |
8722 | #else | |
ba592044 | 8723 | offsetT v; |
5fc177c8 | 8724 | #endif |
e2b0ab59 | 8725 | if (inst.relocs[0].exp.X_op == O_big) |
8335d6aa | 8726 | { |
ba592044 AM |
8727 | LITTLENUM_TYPE w[X_PRECISION]; |
8728 | LITTLENUM_TYPE * l; | |
8729 | ||
e2b0ab59 | 8730 | if (inst.relocs[0].exp.X_add_number == -1) |
8335d6aa | 8731 | { |
ba592044 AM |
8732 | gen_to_words (w, X_PRECISION, E_PRECISION); |
8733 | l = w; | |
8734 | /* FIXME: Should we check words w[2..5] ? */ | |
8335d6aa | 8735 | } |
ba592044 AM |
8736 | else |
8737 | l = generic_bignum; | |
3739860c | 8738 | |
5fc177c8 NC |
8739 | #if defined BFD_HOST_64_BIT |
8740 | v = | |
8741 | ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK) | |
8742 | << LITTLENUM_NUMBER_OF_BITS) | |
8743 | | ((bfd_int64_t) l[2] & LITTLENUM_MASK)) | |
8744 | << LITTLENUM_NUMBER_OF_BITS) | |
8745 | | ((bfd_int64_t) l[1] & LITTLENUM_MASK)) | |
8746 | << LITTLENUM_NUMBER_OF_BITS) | |
8747 | | ((bfd_int64_t) l[0] & LITTLENUM_MASK)); | |
8748 | #else | |
ba592044 AM |
8749 | v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS) |
8750 | | (l[0] & LITTLENUM_MASK); | |
5fc177c8 | 8751 | #endif |
8335d6aa | 8752 | } |
ba592044 | 8753 | else |
e2b0ab59 | 8754 | v = inst.relocs[0].exp.X_add_number; |
ba592044 AM |
8755 | |
8756 | if (!inst.operands[i].issingle) | |
8335d6aa | 8757 | { |
12569877 | 8758 | if (thumb_p) |
8335d6aa | 8759 | { |
53445554 TP |
8760 | /* LDR should not use lead in a flag-setting instruction being |
8761 | chosen so we do not check whether movs can be used. */ | |
12569877 | 8762 | |
53445554 | 8763 | if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2) |
ff8646ee | 8764 | || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)) |
53445554 TP |
8765 | && inst.operands[i].reg != 13 |
8766 | && inst.operands[i].reg != 15) | |
12569877 | 8767 | { |
fc289b0a TP |
8768 | /* Check if on thumb2 it can be done with a mov.w, mvn or |
8769 | movw instruction. */ | |
12569877 AM |
8770 | unsigned int newimm; |
8771 | bfd_boolean isNegated; | |
8772 | ||
8773 | newimm = encode_thumb32_immediate (v); | |
8774 | if (newimm != (unsigned int) FAIL) | |
8775 | isNegated = FALSE; | |
8776 | else | |
8777 | { | |
582cfe03 | 8778 | newimm = encode_thumb32_immediate (~v); |
12569877 AM |
8779 | if (newimm != (unsigned int) FAIL) |
8780 | isNegated = TRUE; | |
8781 | } | |
8782 | ||
fc289b0a TP |
8783 | /* The number can be loaded with a mov.w or mvn |
8784 | instruction. */ | |
ff8646ee TP |
8785 | if (newimm != (unsigned int) FAIL |
8786 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) | |
12569877 | 8787 | { |
fc289b0a | 8788 | inst.instruction = (0xf04f0000 /* MOV.W. */ |
582cfe03 | 8789 | | (inst.operands[i].reg << 8)); |
fc289b0a | 8790 | /* Change to MOVN. */ |
582cfe03 | 8791 | inst.instruction |= (isNegated ? 0x200000 : 0); |
12569877 AM |
8792 | inst.instruction |= (newimm & 0x800) << 15; |
8793 | inst.instruction |= (newimm & 0x700) << 4; | |
8794 | inst.instruction |= (newimm & 0x0ff); | |
8795 | return TRUE; | |
8796 | } | |
fc289b0a | 8797 | /* The number can be loaded with a movw instruction. */ |
ff8646ee TP |
8798 | else if ((v & ~0xFFFF) == 0 |
8799 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)) | |
3739860c | 8800 | { |
582cfe03 | 8801 | int imm = v & 0xFFFF; |
12569877 | 8802 | |
582cfe03 | 8803 | inst.instruction = 0xf2400000; /* MOVW. */ |
12569877 AM |
8804 | inst.instruction |= (inst.operands[i].reg << 8); |
8805 | inst.instruction |= (imm & 0xf000) << 4; | |
8806 | inst.instruction |= (imm & 0x0800) << 15; | |
8807 | inst.instruction |= (imm & 0x0700) << 4; | |
8808 | inst.instruction |= (imm & 0x00ff); | |
8fe9a076 AV |
8809 | /* In case this replacement is being done on Armv8-M |
8810 | Baseline we need to make sure to disable the | |
8811 | instruction size check, as otherwise GAS will reject | |
8812 | the use of this T32 instruction. */ | |
8813 | inst.size_req = 0; | |
12569877 AM |
8814 | return TRUE; |
8815 | } | |
8816 | } | |
8335d6aa | 8817 | } |
12569877 | 8818 | else if (arm_p) |
ba592044 AM |
8819 | { |
8820 | int value = encode_arm_immediate (v); | |
12569877 | 8821 | |
ba592044 AM |
8822 | if (value != FAIL) |
8823 | { | |
8824 | /* This can be done with a mov instruction. */ | |
8825 | inst.instruction &= LITERAL_MASK; | |
8826 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
8827 | inst.instruction |= value & 0xfff; | |
8828 | return TRUE; | |
8829 | } | |
8335d6aa | 8830 | |
ba592044 AM |
8831 | value = encode_arm_immediate (~ v); |
8832 | if (value != FAIL) | |
8833 | { | |
8834 | /* This can be done with a mvn instruction. */ | |
8835 | inst.instruction &= LITERAL_MASK; | |
8836 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
8837 | inst.instruction |= value & 0xfff; | |
8838 | return TRUE; | |
8839 | } | |
8840 | } | |
934c2632 | 8841 | else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)) |
8335d6aa | 8842 | { |
ba592044 AM |
8843 | int op = 0; |
8844 | unsigned immbits = 0; | |
8845 | unsigned immlo = inst.operands[1].imm; | |
8846 | unsigned immhi = inst.operands[1].regisimm | |
8847 | ? inst.operands[1].reg | |
e2b0ab59 | 8848 | : inst.relocs[0].exp.X_unsigned |
ba592044 AM |
8849 | ? 0 |
8850 | : ((bfd_int64_t)((int) immlo)) >> 32; | |
8851 | int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits, | |
8852 | &op, 64, NT_invtype); | |
8853 | ||
8854 | if (cmode == FAIL) | |
8855 | { | |
8856 | neon_invert_size (&immlo, &immhi, 64); | |
8857 | op = !op; | |
8858 | cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits, | |
8859 | &op, 64, NT_invtype); | |
8860 | } | |
8861 | ||
8862 | if (cmode != FAIL) | |
8863 | { | |
8864 | inst.instruction = (inst.instruction & VLDR_VMOV_SAME) | |
8865 | | (1 << 23) | |
8866 | | (cmode << 8) | |
8867 | | (op << 5) | |
8868 | | (1 << 4); | |
8869 | ||
8870 | /* Fill other bits in vmov encoding for both thumb and arm. */ | |
8871 | if (thumb_mode) | |
eff0bc54 | 8872 | inst.instruction |= (0x7U << 29) | (0xF << 24); |
ba592044 | 8873 | else |
eff0bc54 | 8874 | inst.instruction |= (0xFU << 28) | (0x1 << 25); |
ba592044 AM |
8875 | neon_write_immbits (immbits); |
8876 | return TRUE; | |
8877 | } | |
8335d6aa JW |
8878 | } |
8879 | } | |
8335d6aa | 8880 | |
ba592044 AM |
8881 | if (t == CONST_VEC) |
8882 | { | |
8883 | /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */ | |
8884 | if (inst.operands[i].issingle | |
8885 | && is_quarter_float (inst.operands[1].imm) | |
8886 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd)) | |
8335d6aa | 8887 | { |
ba592044 AM |
8888 | inst.operands[1].imm = |
8889 | neon_qfloat_bits (v); | |
8890 | do_vfp_nsyn_opcode ("fconsts"); | |
8891 | return TRUE; | |
8335d6aa | 8892 | } |
5fc177c8 NC |
8893 | |
8894 | /* If our host does not support a 64-bit type then we cannot perform | |
8895 | the following optimization. This mean that there will be a | |
8896 | discrepancy between the output produced by an assembler built for | |
8897 | a 32-bit-only host and the output produced from a 64-bit host, but | |
8898 | this cannot be helped. */ | |
8899 | #if defined BFD_HOST_64_BIT | |
ba592044 AM |
8900 | else if (!inst.operands[1].issingle |
8901 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3)) | |
8335d6aa | 8902 | { |
ba592044 AM |
8903 | if (is_double_a_single (v) |
8904 | && is_quarter_float (double_to_single (v))) | |
8905 | { | |
8906 | inst.operands[1].imm = | |
8907 | neon_qfloat_bits (double_to_single (v)); | |
8908 | do_vfp_nsyn_opcode ("fconstd"); | |
8909 | return TRUE; | |
8910 | } | |
8335d6aa | 8911 | } |
5fc177c8 | 8912 | #endif |
8335d6aa JW |
8913 | } |
8914 | } | |
8915 | ||
8916 | if (add_to_lit_pool ((!inst.operands[i].isvec | |
8917 | || inst.operands[i].issingle) ? 4 : 8) == FAIL) | |
8918 | return TRUE; | |
8919 | ||
8920 | inst.operands[1].reg = REG_PC; | |
8921 | inst.operands[1].isreg = 1; | |
8922 | inst.operands[1].preind = 1; | |
e2b0ab59 AV |
8923 | inst.relocs[0].pc_rel = 1; |
8924 | inst.relocs[0].type = (thumb_p | |
8335d6aa JW |
8925 | ? BFD_RELOC_ARM_THUMB_OFFSET |
8926 | : (mode_3 | |
8927 | ? BFD_RELOC_ARM_HWLITERAL | |
8928 | : BFD_RELOC_ARM_LITERAL)); | |
8929 | return FALSE; | |
8930 | } | |
8931 | ||
8932 | /* inst.operands[i] was set up by parse_address. Encode it into an | |
8933 | ARM-format instruction. Reject all forms which cannot be encoded | |
8934 | into a coprocessor load/store instruction. If wb_ok is false, | |
8935 | reject use of writeback; if unind_ok is false, reject use of | |
8936 | unindexed addressing. If reloc_override is not 0, use it instead | |
8937 | of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one | |
8938 | (in which case it is preserved). */ | |
8939 | ||
8940 | static int | |
8941 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
8942 | { | |
8943 | if (!inst.operands[i].isreg) | |
8944 | { | |
99b2a2dd NC |
8945 | /* PR 18256 */ |
8946 | if (! inst.operands[0].isvec) | |
8947 | { | |
8948 | inst.error = _("invalid co-processor operand"); | |
8949 | return FAIL; | |
8950 | } | |
8335d6aa JW |
8951 | if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE)) |
8952 | return SUCCESS; | |
8953 | } | |
8954 | ||
8955 | inst.instruction |= inst.operands[i].reg << 16; | |
8956 | ||
8957 | gas_assert (!(inst.operands[i].preind && inst.operands[i].postind)); | |
8958 | ||
8959 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ | |
8960 | { | |
8961 | gas_assert (!inst.operands[i].writeback); | |
8962 | if (!unind_ok) | |
8963 | { | |
8964 | inst.error = _("instruction does not support unindexed addressing"); | |
8965 | return FAIL; | |
8966 | } | |
8967 | inst.instruction |= inst.operands[i].imm; | |
8968 | inst.instruction |= INDEX_UP; | |
8969 | return SUCCESS; | |
8970 | } | |
8971 | ||
8972 | if (inst.operands[i].preind) | |
8973 | inst.instruction |= PRE_INDEX; | |
8974 | ||
8975 | if (inst.operands[i].writeback) | |
09d92015 | 8976 | { |
8335d6aa | 8977 | if (inst.operands[i].reg == REG_PC) |
c19d1205 | 8978 | { |
8335d6aa JW |
8979 | inst.error = _("pc may not be used with write-back"); |
8980 | return FAIL; | |
c19d1205 | 8981 | } |
8335d6aa | 8982 | if (!wb_ok) |
c19d1205 | 8983 | { |
8335d6aa JW |
8984 | inst.error = _("instruction does not support writeback"); |
8985 | return FAIL; | |
c19d1205 | 8986 | } |
8335d6aa | 8987 | inst.instruction |= WRITE_BACK; |
09d92015 MM |
8988 | } |
8989 | ||
8335d6aa | 8990 | if (reloc_override) |
e2b0ab59 AV |
8991 | inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override; |
8992 | else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC | |
8993 | || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2) | |
8994 | && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0) | |
c19d1205 | 8995 | { |
8335d6aa | 8996 | if (thumb_mode) |
e2b0ab59 | 8997 | inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM; |
8335d6aa | 8998 | else |
e2b0ab59 | 8999 | inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM; |
c19d1205 | 9000 | } |
8335d6aa JW |
9001 | |
9002 | /* Prefer + for zero encoded value. */ | |
9003 | if (!inst.operands[i].negative) | |
9004 | inst.instruction |= INDEX_UP; | |
9005 | ||
9006 | return SUCCESS; | |
09d92015 MM |
9007 | } |
9008 | ||
5f4273c7 | 9009 | /* Functions for instruction encoding, sorted by sub-architecture. |
c19d1205 ZW |
9010 | First some generics; their names are taken from the conventional |
9011 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 9012 | |
a737bd4d | 9013 | static void |
c19d1205 | 9014 | do_noargs (void) |
09d92015 | 9015 | { |
c19d1205 | 9016 | } |
a737bd4d | 9017 | |
c19d1205 ZW |
9018 | static void |
9019 | do_rd (void) | |
9020 | { | |
9021 | inst.instruction |= inst.operands[0].reg << 12; | |
9022 | } | |
a737bd4d | 9023 | |
16a1fa25 TP |
9024 | static void |
9025 | do_rn (void) | |
9026 | { | |
9027 | inst.instruction |= inst.operands[0].reg << 16; | |
9028 | } | |
9029 | ||
c19d1205 ZW |
9030 | static void |
9031 | do_rd_rm (void) | |
9032 | { | |
9033 | inst.instruction |= inst.operands[0].reg << 12; | |
9034 | inst.instruction |= inst.operands[1].reg; | |
9035 | } | |
09d92015 | 9036 | |
9eb6c0f1 MGD |
9037 | static void |
9038 | do_rm_rn (void) | |
9039 | { | |
9040 | inst.instruction |= inst.operands[0].reg; | |
9041 | inst.instruction |= inst.operands[1].reg << 16; | |
9042 | } | |
9043 | ||
c19d1205 ZW |
9044 | static void |
9045 | do_rd_rn (void) | |
9046 | { | |
9047 | inst.instruction |= inst.operands[0].reg << 12; | |
9048 | inst.instruction |= inst.operands[1].reg << 16; | |
9049 | } | |
a737bd4d | 9050 | |
c19d1205 ZW |
9051 | static void |
9052 | do_rn_rd (void) | |
9053 | { | |
9054 | inst.instruction |= inst.operands[0].reg << 16; | |
9055 | inst.instruction |= inst.operands[1].reg << 12; | |
9056 | } | |
09d92015 | 9057 | |
4ed7ed8d TP |
9058 | static void |
9059 | do_tt (void) | |
9060 | { | |
9061 | inst.instruction |= inst.operands[0].reg << 8; | |
9062 | inst.instruction |= inst.operands[1].reg << 16; | |
9063 | } | |
9064 | ||
59d09be6 MGD |
9065 | static bfd_boolean |
9066 | check_obsolete (const arm_feature_set *feature, const char *msg) | |
9067 | { | |
9068 | if (ARM_CPU_IS_ANY (cpu_variant)) | |
9069 | { | |
5c3696f8 | 9070 | as_tsktsk ("%s", msg); |
59d09be6 MGD |
9071 | return TRUE; |
9072 | } | |
9073 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) | |
9074 | { | |
9075 | as_bad ("%s", msg); | |
9076 | return TRUE; | |
9077 | } | |
9078 | ||
9079 | return FALSE; | |
9080 | } | |
9081 | ||
c19d1205 ZW |
9082 | static void |
9083 | do_rd_rm_rn (void) | |
9084 | { | |
9a64e435 | 9085 | unsigned Rn = inst.operands[2].reg; |
708587a4 | 9086 | /* Enforce restrictions on SWP instruction. */ |
9a64e435 | 9087 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) |
56adecf4 DG |
9088 | { |
9089 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
9090 | _("Rn must not overlap other operands")); | |
9091 | ||
59d09be6 MGD |
9092 | /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7. |
9093 | */ | |
9094 | if (!check_obsolete (&arm_ext_v8, | |
9095 | _("swp{b} use is obsoleted for ARMv8 and later")) | |
9096 | && warn_on_deprecated | |
9097 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6)) | |
5c3696f8 | 9098 | as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7")); |
56adecf4 | 9099 | } |
59d09be6 | 9100 | |
c19d1205 ZW |
9101 | inst.instruction |= inst.operands[0].reg << 12; |
9102 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 9103 | inst.instruction |= Rn << 16; |
c19d1205 | 9104 | } |
09d92015 | 9105 | |
c19d1205 ZW |
9106 | static void |
9107 | do_rd_rn_rm (void) | |
9108 | { | |
9109 | inst.instruction |= inst.operands[0].reg << 12; | |
9110 | inst.instruction |= inst.operands[1].reg << 16; | |
9111 | inst.instruction |= inst.operands[2].reg; | |
9112 | } | |
a737bd4d | 9113 | |
c19d1205 ZW |
9114 | static void |
9115 | do_rm_rd_rn (void) | |
9116 | { | |
5be8be5d | 9117 | constraint ((inst.operands[2].reg == REG_PC), BAD_PC); |
e2b0ab59 AV |
9118 | constraint (((inst.relocs[0].exp.X_op != O_constant |
9119 | && inst.relocs[0].exp.X_op != O_illegal) | |
9120 | || inst.relocs[0].exp.X_add_number != 0), | |
5be8be5d | 9121 | BAD_ADDR_MODE); |
c19d1205 ZW |
9122 | inst.instruction |= inst.operands[0].reg; |
9123 | inst.instruction |= inst.operands[1].reg << 12; | |
9124 | inst.instruction |= inst.operands[2].reg << 16; | |
9125 | } | |
09d92015 | 9126 | |
c19d1205 ZW |
9127 | static void |
9128 | do_imm0 (void) | |
9129 | { | |
9130 | inst.instruction |= inst.operands[0].imm; | |
9131 | } | |
09d92015 | 9132 | |
c19d1205 ZW |
9133 | static void |
9134 | do_rd_cpaddr (void) | |
9135 | { | |
9136 | inst.instruction |= inst.operands[0].reg << 12; | |
9137 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 9138 | } |
a737bd4d | 9139 | |
c19d1205 ZW |
9140 | /* ARM instructions, in alphabetical order by function name (except |
9141 | that wrapper functions appear immediately after the function they | |
9142 | wrap). */ | |
09d92015 | 9143 | |
c19d1205 ZW |
9144 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
9145 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
9146 | |
9147 | static void | |
c19d1205 | 9148 | do_adr (void) |
09d92015 | 9149 | { |
c19d1205 | 9150 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 9151 | |
c19d1205 ZW |
9152 | /* Frag hacking will turn this into a sub instruction if the offset turns |
9153 | out to be negative. */ | |
e2b0ab59 AV |
9154 | inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE; |
9155 | inst.relocs[0].pc_rel = 1; | |
9156 | inst.relocs[0].exp.X_add_number -= 8; | |
52a86f84 | 9157 | |
fc6141f0 | 9158 | if (support_interwork |
e2b0ab59 AV |
9159 | && inst.relocs[0].exp.X_op == O_symbol |
9160 | && inst.relocs[0].exp.X_add_symbol != NULL | |
9161 | && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol) | |
9162 | && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol)) | |
9163 | inst.relocs[0].exp.X_add_number |= 1; | |
c19d1205 | 9164 | } |
b99bd4ef | 9165 | |
c19d1205 ZW |
9166 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
9167 | into a relative address of the form: | |
9168 | add rd, pc, #low(label-.-8)" | |
9169 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 9170 | |
c19d1205 ZW |
9171 | static void |
9172 | do_adrl (void) | |
9173 | { | |
9174 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 9175 | |
c19d1205 ZW |
9176 | /* Frag hacking will turn this into a sub instruction if the offset turns |
9177 | out to be negative. */ | |
e2b0ab59 AV |
9178 | inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE; |
9179 | inst.relocs[0].pc_rel = 1; | |
c19d1205 | 9180 | inst.size = INSN_SIZE * 2; |
e2b0ab59 | 9181 | inst.relocs[0].exp.X_add_number -= 8; |
52a86f84 | 9182 | |
fc6141f0 | 9183 | if (support_interwork |
e2b0ab59 AV |
9184 | && inst.relocs[0].exp.X_op == O_symbol |
9185 | && inst.relocs[0].exp.X_add_symbol != NULL | |
9186 | && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol) | |
9187 | && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol)) | |
9188 | inst.relocs[0].exp.X_add_number |= 1; | |
b99bd4ef NC |
9189 | } |
9190 | ||
b99bd4ef | 9191 | static void |
c19d1205 | 9192 | do_arit (void) |
b99bd4ef | 9193 | { |
e2b0ab59 AV |
9194 | constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
9195 | && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC , | |
a9f02af8 | 9196 | THUMB1_RELOC_ONLY); |
c19d1205 ZW |
9197 | if (!inst.operands[1].present) |
9198 | inst.operands[1].reg = inst.operands[0].reg; | |
9199 | inst.instruction |= inst.operands[0].reg << 12; | |
9200 | inst.instruction |= inst.operands[1].reg << 16; | |
9201 | encode_arm_shifter_operand (2); | |
9202 | } | |
b99bd4ef | 9203 | |
62b3e311 PB |
9204 | static void |
9205 | do_barrier (void) | |
9206 | { | |
9207 | if (inst.operands[0].present) | |
ccb84d65 | 9208 | inst.instruction |= inst.operands[0].imm; |
62b3e311 PB |
9209 | else |
9210 | inst.instruction |= 0xf; | |
9211 | } | |
9212 | ||
c19d1205 ZW |
9213 | static void |
9214 | do_bfc (void) | |
9215 | { | |
9216 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
9217 | constraint (msb > 32, _("bit-field extends past end of register")); | |
9218 | /* The instruction encoding stores the LSB and MSB, | |
9219 | not the LSB and width. */ | |
9220 | inst.instruction |= inst.operands[0].reg << 12; | |
9221 | inst.instruction |= inst.operands[1].imm << 7; | |
9222 | inst.instruction |= (msb - 1) << 16; | |
9223 | } | |
b99bd4ef | 9224 | |
c19d1205 ZW |
9225 | static void |
9226 | do_bfi (void) | |
9227 | { | |
9228 | unsigned int msb; | |
b99bd4ef | 9229 | |
c19d1205 ZW |
9230 | /* #0 in second position is alternative syntax for bfc, which is |
9231 | the same instruction but with REG_PC in the Rm field. */ | |
9232 | if (!inst.operands[1].isreg) | |
9233 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 9234 | |
c19d1205 ZW |
9235 | msb = inst.operands[2].imm + inst.operands[3].imm; |
9236 | constraint (msb > 32, _("bit-field extends past end of register")); | |
9237 | /* The instruction encoding stores the LSB and MSB, | |
9238 | not the LSB and width. */ | |
9239 | inst.instruction |= inst.operands[0].reg << 12; | |
9240 | inst.instruction |= inst.operands[1].reg; | |
9241 | inst.instruction |= inst.operands[2].imm << 7; | |
9242 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
9243 | } |
9244 | ||
b99bd4ef | 9245 | static void |
c19d1205 | 9246 | do_bfx (void) |
b99bd4ef | 9247 | { |
c19d1205 ZW |
9248 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
9249 | _("bit-field extends past end of register")); | |
9250 | inst.instruction |= inst.operands[0].reg << 12; | |
9251 | inst.instruction |= inst.operands[1].reg; | |
9252 | inst.instruction |= inst.operands[2].imm << 7; | |
9253 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
9254 | } | |
09d92015 | 9255 | |
c19d1205 ZW |
9256 | /* ARM V5 breakpoint instruction (argument parse) |
9257 | BKPT <16 bit unsigned immediate> | |
9258 | Instruction is not conditional. | |
9259 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
9260 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 9261 | |
c19d1205 ZW |
9262 | static void |
9263 | do_bkpt (void) | |
9264 | { | |
9265 | /* Top 12 of 16 bits to bits 19:8. */ | |
9266 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 9267 | |
c19d1205 ZW |
9268 | /* Bottom 4 of 16 bits to bits 3:0. */ |
9269 | inst.instruction |= inst.operands[0].imm & 0xf; | |
9270 | } | |
09d92015 | 9271 | |
c19d1205 ZW |
9272 | static void |
9273 | encode_branch (int default_reloc) | |
9274 | { | |
9275 | if (inst.operands[0].hasreloc) | |
9276 | { | |
0855e32b NS |
9277 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32 |
9278 | && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL, | |
9279 | _("the only valid suffixes here are '(plt)' and '(tlscall)'")); | |
e2b0ab59 | 9280 | inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32 |
0855e32b NS |
9281 | ? BFD_RELOC_ARM_PLT32 |
9282 | : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL; | |
c19d1205 | 9283 | } |
b99bd4ef | 9284 | else |
e2b0ab59 AV |
9285 | inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc; |
9286 | inst.relocs[0].pc_rel = 1; | |
b99bd4ef NC |
9287 | } |
9288 | ||
b99bd4ef | 9289 | static void |
c19d1205 | 9290 | do_branch (void) |
b99bd4ef | 9291 | { |
39b41c9c PB |
9292 | #ifdef OBJ_ELF |
9293 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
9294 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
9295 | else | |
9296 | #endif | |
9297 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
9298 | } | |
9299 | ||
9300 | static void | |
9301 | do_bl (void) | |
9302 | { | |
9303 | #ifdef OBJ_ELF | |
9304 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
9305 | { | |
9306 | if (inst.cond == COND_ALWAYS) | |
9307 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
9308 | else | |
9309 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
9310 | } | |
9311 | else | |
9312 | #endif | |
9313 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 9314 | } |
b99bd4ef | 9315 | |
c19d1205 ZW |
9316 | /* ARM V5 branch-link-exchange instruction (argument parse) |
9317 | BLX <target_addr> ie BLX(1) | |
9318 | BLX{<condition>} <Rm> ie BLX(2) | |
9319 | Unfortunately, there are two different opcodes for this mnemonic. | |
9320 | So, the insns[].value is not used, and the code here zaps values | |
9321 | into inst.instruction. | |
9322 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 9323 | |
c19d1205 ZW |
9324 | static void |
9325 | do_blx (void) | |
9326 | { | |
9327 | if (inst.operands[0].isreg) | |
b99bd4ef | 9328 | { |
c19d1205 ZW |
9329 | /* Arg is a register; the opcode provided by insns[] is correct. |
9330 | It is not illegal to do "blx pc", just useless. */ | |
9331 | if (inst.operands[0].reg == REG_PC) | |
9332 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 9333 | |
c19d1205 ZW |
9334 | inst.instruction |= inst.operands[0].reg; |
9335 | } | |
9336 | else | |
b99bd4ef | 9337 | { |
c19d1205 | 9338 | /* Arg is an address; this instruction cannot be executed |
267bf995 RR |
9339 | conditionally, and the opcode must be adjusted. |
9340 | We retain the BFD_RELOC_ARM_PCREL_BLX till the very end | |
9341 | where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */ | |
c19d1205 | 9342 | constraint (inst.cond != COND_ALWAYS, BAD_COND); |
2fc8bdac | 9343 | inst.instruction = 0xfa000000; |
267bf995 | 9344 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); |
b99bd4ef | 9345 | } |
c19d1205 ZW |
9346 | } |
9347 | ||
9348 | static void | |
9349 | do_bx (void) | |
9350 | { | |
845b51d6 PB |
9351 | bfd_boolean want_reloc; |
9352 | ||
c19d1205 ZW |
9353 | if (inst.operands[0].reg == REG_PC) |
9354 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 9355 | |
c19d1205 | 9356 | inst.instruction |= inst.operands[0].reg; |
845b51d6 PB |
9357 | /* Output R_ARM_V4BX relocations if is an EABI object that looks like |
9358 | it is for ARMv4t or earlier. */ | |
9359 | want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5); | |
4d354d8b TP |
9360 | if (!ARM_FEATURE_ZERO (selected_object_arch) |
9361 | && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5)) | |
845b51d6 PB |
9362 | want_reloc = TRUE; |
9363 | ||
5ad34203 | 9364 | #ifdef OBJ_ELF |
845b51d6 | 9365 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
5ad34203 | 9366 | #endif |
584206db | 9367 | want_reloc = FALSE; |
845b51d6 PB |
9368 | |
9369 | if (want_reloc) | |
e2b0ab59 | 9370 | inst.relocs[0].type = BFD_RELOC_ARM_V4BX; |
09d92015 MM |
9371 | } |
9372 | ||
c19d1205 ZW |
9373 | |
9374 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
9375 | |
9376 | static void | |
c19d1205 | 9377 | do_bxj (void) |
a737bd4d | 9378 | { |
c19d1205 ZW |
9379 | if (inst.operands[0].reg == REG_PC) |
9380 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
9381 | ||
9382 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
9383 | } |
9384 | ||
c19d1205 ZW |
9385 | /* Co-processor data operation: |
9386 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
9387 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
9388 | static void | |
9389 | do_cdp (void) | |
9390 | { | |
9391 | inst.instruction |= inst.operands[0].reg << 8; | |
9392 | inst.instruction |= inst.operands[1].imm << 20; | |
9393 | inst.instruction |= inst.operands[2].reg << 12; | |
9394 | inst.instruction |= inst.operands[3].reg << 16; | |
9395 | inst.instruction |= inst.operands[4].reg; | |
9396 | inst.instruction |= inst.operands[5].imm << 5; | |
9397 | } | |
a737bd4d NC |
9398 | |
9399 | static void | |
c19d1205 | 9400 | do_cmp (void) |
a737bd4d | 9401 | { |
c19d1205 ZW |
9402 | inst.instruction |= inst.operands[0].reg << 16; |
9403 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
9404 | } |
9405 | ||
c19d1205 ZW |
9406 | /* Transfer between coprocessor and ARM registers. |
9407 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
9408 | MRC2 | |
9409 | MCR{cond} | |
9410 | MCR2 | |
9411 | ||
9412 | No special properties. */ | |
09d92015 | 9413 | |
dcbd0d71 MGD |
9414 | struct deprecated_coproc_regs_s |
9415 | { | |
9416 | unsigned cp; | |
9417 | int opc1; | |
9418 | unsigned crn; | |
9419 | unsigned crm; | |
9420 | int opc2; | |
9421 | arm_feature_set deprecated; | |
9422 | arm_feature_set obsoleted; | |
9423 | const char *dep_msg; | |
9424 | const char *obs_msg; | |
9425 | }; | |
9426 | ||
9427 | #define DEPR_ACCESS_V8 \ | |
9428 | N_("This coprocessor register access is deprecated in ARMv8") | |
9429 | ||
9430 | /* Table of all deprecated coprocessor registers. */ | |
9431 | static struct deprecated_coproc_regs_s deprecated_coproc_regs[] = | |
9432 | { | |
9433 | {15, 0, 7, 10, 5, /* CP15DMB. */ | |
823d2571 | 9434 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
9435 | DEPR_ACCESS_V8, NULL}, |
9436 | {15, 0, 7, 10, 4, /* CP15DSB. */ | |
823d2571 | 9437 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
9438 | DEPR_ACCESS_V8, NULL}, |
9439 | {15, 0, 7, 5, 4, /* CP15ISB. */ | |
823d2571 | 9440 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
9441 | DEPR_ACCESS_V8, NULL}, |
9442 | {14, 6, 1, 0, 0, /* TEEHBR. */ | |
823d2571 | 9443 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
9444 | DEPR_ACCESS_V8, NULL}, |
9445 | {14, 6, 0, 0, 0, /* TEECR. */ | |
823d2571 | 9446 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
9447 | DEPR_ACCESS_V8, NULL}, |
9448 | }; | |
9449 | ||
9450 | #undef DEPR_ACCESS_V8 | |
9451 | ||
9452 | static const size_t deprecated_coproc_reg_count = | |
9453 | sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]); | |
9454 | ||
09d92015 | 9455 | static void |
c19d1205 | 9456 | do_co_reg (void) |
09d92015 | 9457 | { |
fdfde340 | 9458 | unsigned Rd; |
dcbd0d71 | 9459 | size_t i; |
fdfde340 JM |
9460 | |
9461 | Rd = inst.operands[2].reg; | |
9462 | if (thumb_mode) | |
9463 | { | |
9464 | if (inst.instruction == 0xee000010 | |
9465 | || inst.instruction == 0xfe000010) | |
9466 | /* MCR, MCR2 */ | |
9467 | reject_bad_reg (Rd); | |
5c8ed6a4 | 9468 | else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
fdfde340 JM |
9469 | /* MRC, MRC2 */ |
9470 | constraint (Rd == REG_SP, BAD_SP); | |
9471 | } | |
9472 | else | |
9473 | { | |
9474 | /* MCR */ | |
9475 | if (inst.instruction == 0xe000010) | |
9476 | constraint (Rd == REG_PC, BAD_PC); | |
9477 | } | |
9478 | ||
dcbd0d71 MGD |
9479 | for (i = 0; i < deprecated_coproc_reg_count; ++i) |
9480 | { | |
9481 | const struct deprecated_coproc_regs_s *r = | |
9482 | deprecated_coproc_regs + i; | |
9483 | ||
9484 | if (inst.operands[0].reg == r->cp | |
9485 | && inst.operands[1].imm == r->opc1 | |
9486 | && inst.operands[3].reg == r->crn | |
9487 | && inst.operands[4].reg == r->crm | |
9488 | && inst.operands[5].imm == r->opc2) | |
9489 | { | |
b10bf8c5 | 9490 | if (! ARM_CPU_IS_ANY (cpu_variant) |
477330fc | 9491 | && warn_on_deprecated |
dcbd0d71 | 9492 | && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated)) |
5c3696f8 | 9493 | as_tsktsk ("%s", r->dep_msg); |
dcbd0d71 MGD |
9494 | } |
9495 | } | |
fdfde340 | 9496 | |
c19d1205 ZW |
9497 | inst.instruction |= inst.operands[0].reg << 8; |
9498 | inst.instruction |= inst.operands[1].imm << 21; | |
fdfde340 | 9499 | inst.instruction |= Rd << 12; |
c19d1205 ZW |
9500 | inst.instruction |= inst.operands[3].reg << 16; |
9501 | inst.instruction |= inst.operands[4].reg; | |
9502 | inst.instruction |= inst.operands[5].imm << 5; | |
9503 | } | |
09d92015 | 9504 | |
c19d1205 ZW |
9505 | /* Transfer between coprocessor register and pair of ARM registers. |
9506 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
9507 | MCRR2 | |
9508 | MRRC{cond} | |
9509 | MRRC2 | |
b99bd4ef | 9510 | |
c19d1205 | 9511 | Two XScale instructions are special cases of these: |
09d92015 | 9512 | |
c19d1205 ZW |
9513 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
9514 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 9515 | |
5f4273c7 | 9516 | Result unpredictable if Rd or Rn is R15. */ |
a737bd4d | 9517 | |
c19d1205 ZW |
9518 | static void |
9519 | do_co_reg2c (void) | |
9520 | { | |
fdfde340 JM |
9521 | unsigned Rd, Rn; |
9522 | ||
9523 | Rd = inst.operands[2].reg; | |
9524 | Rn = inst.operands[3].reg; | |
9525 | ||
9526 | if (thumb_mode) | |
9527 | { | |
9528 | reject_bad_reg (Rd); | |
9529 | reject_bad_reg (Rn); | |
9530 | } | |
9531 | else | |
9532 | { | |
9533 | constraint (Rd == REG_PC, BAD_PC); | |
9534 | constraint (Rn == REG_PC, BAD_PC); | |
9535 | } | |
9536 | ||
873f10f0 TC |
9537 | /* Only check the MRRC{2} variants. */ |
9538 | if ((inst.instruction & 0x0FF00000) == 0x0C500000) | |
9539 | { | |
9540 | /* If Rd == Rn, error that the operation is | |
9541 | unpredictable (example MRRC p3,#1,r1,r1,c4). */ | |
9542 | constraint (Rd == Rn, BAD_OVERLAP); | |
9543 | } | |
9544 | ||
c19d1205 ZW |
9545 | inst.instruction |= inst.operands[0].reg << 8; |
9546 | inst.instruction |= inst.operands[1].imm << 4; | |
fdfde340 JM |
9547 | inst.instruction |= Rd << 12; |
9548 | inst.instruction |= Rn << 16; | |
c19d1205 | 9549 | inst.instruction |= inst.operands[4].reg; |
b99bd4ef NC |
9550 | } |
9551 | ||
c19d1205 ZW |
9552 | static void |
9553 | do_cpsi (void) | |
9554 | { | |
9555 | inst.instruction |= inst.operands[0].imm << 6; | |
a028a6f5 PB |
9556 | if (inst.operands[1].present) |
9557 | { | |
9558 | inst.instruction |= CPSI_MMOD; | |
9559 | inst.instruction |= inst.operands[1].imm; | |
9560 | } | |
c19d1205 | 9561 | } |
b99bd4ef | 9562 | |
62b3e311 PB |
9563 | static void |
9564 | do_dbg (void) | |
9565 | { | |
9566 | inst.instruction |= inst.operands[0].imm; | |
9567 | } | |
9568 | ||
eea54501 MGD |
9569 | static void |
9570 | do_div (void) | |
9571 | { | |
9572 | unsigned Rd, Rn, Rm; | |
9573 | ||
9574 | Rd = inst.operands[0].reg; | |
9575 | Rn = (inst.operands[1].present | |
9576 | ? inst.operands[1].reg : Rd); | |
9577 | Rm = inst.operands[2].reg; | |
9578 | ||
9579 | constraint ((Rd == REG_PC), BAD_PC); | |
9580 | constraint ((Rn == REG_PC), BAD_PC); | |
9581 | constraint ((Rm == REG_PC), BAD_PC); | |
9582 | ||
9583 | inst.instruction |= Rd << 16; | |
9584 | inst.instruction |= Rn << 0; | |
9585 | inst.instruction |= Rm << 8; | |
9586 | } | |
9587 | ||
b99bd4ef | 9588 | static void |
c19d1205 | 9589 | do_it (void) |
b99bd4ef | 9590 | { |
c19d1205 | 9591 | /* There is no IT instruction in ARM mode. We |
e07e6e58 NC |
9592 | process it to do the validation as if in |
9593 | thumb mode, just in case the code gets | |
9594 | assembled for thumb using the unified syntax. */ | |
9595 | ||
c19d1205 | 9596 | inst.size = 0; |
e07e6e58 NC |
9597 | if (unified_syntax) |
9598 | { | |
5ee91343 AV |
9599 | set_pred_insn_type (IT_INSN); |
9600 | now_pred.mask = (inst.instruction & 0xf) | 0x10; | |
9601 | now_pred.cc = inst.operands[0].imm; | |
e07e6e58 | 9602 | } |
09d92015 | 9603 | } |
b99bd4ef | 9604 | |
6530b175 NC |
9605 | /* If there is only one register in the register list, |
9606 | then return its register number. Otherwise return -1. */ | |
9607 | static int | |
9608 | only_one_reg_in_list (int range) | |
9609 | { | |
9610 | int i = ffs (range) - 1; | |
9611 | return (i > 15 || range != (1 << i)) ? -1 : i; | |
9612 | } | |
9613 | ||
09d92015 | 9614 | static void |
6530b175 | 9615 | encode_ldmstm(int from_push_pop_mnem) |
ea6ef066 | 9616 | { |
c19d1205 ZW |
9617 | int base_reg = inst.operands[0].reg; |
9618 | int range = inst.operands[1].imm; | |
6530b175 | 9619 | int one_reg; |
ea6ef066 | 9620 | |
c19d1205 ZW |
9621 | inst.instruction |= base_reg << 16; |
9622 | inst.instruction |= range; | |
ea6ef066 | 9623 | |
c19d1205 ZW |
9624 | if (inst.operands[1].writeback) |
9625 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 9626 | |
c19d1205 | 9627 | if (inst.operands[0].writeback) |
ea6ef066 | 9628 | { |
c19d1205 ZW |
9629 | inst.instruction |= WRITE_BACK; |
9630 | /* Check for unpredictable uses of writeback. */ | |
9631 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 9632 | { |
c19d1205 ZW |
9633 | /* Not allowed in LDM type 2. */ |
9634 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
9635 | && ((range & (1 << REG_PC)) == 0)) | |
9636 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
9637 | /* Only allowed if base reg not in list for other types. */ | |
9638 | else if (range & (1 << base_reg)) | |
9639 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
9640 | } | |
9641 | else /* STM. */ | |
9642 | { | |
9643 | /* Not allowed for type 2. */ | |
9644 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
9645 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
9646 | /* Only allowed if base reg not in list, or first in list. */ | |
9647 | else if ((range & (1 << base_reg)) | |
9648 | && (range & ((1 << base_reg) - 1))) | |
9649 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 9650 | } |
ea6ef066 | 9651 | } |
6530b175 NC |
9652 | |
9653 | /* If PUSH/POP has only one register, then use the A2 encoding. */ | |
9654 | one_reg = only_one_reg_in_list (range); | |
9655 | if (from_push_pop_mnem && one_reg >= 0) | |
9656 | { | |
9657 | int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH; | |
9658 | ||
4f588891 NC |
9659 | if (is_push && one_reg == 13 /* SP */) |
9660 | /* PR 22483: The A2 encoding cannot be used when | |
9661 | pushing the stack pointer as this is UNPREDICTABLE. */ | |
9662 | return; | |
9663 | ||
6530b175 NC |
9664 | inst.instruction &= A_COND_MASK; |
9665 | inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP; | |
9666 | inst.instruction |= one_reg << 12; | |
9667 | } | |
9668 | } | |
9669 | ||
9670 | static void | |
9671 | do_ldmstm (void) | |
9672 | { | |
9673 | encode_ldmstm (/*from_push_pop_mnem=*/FALSE); | |
a737bd4d NC |
9674 | } |
9675 | ||
c19d1205 ZW |
9676 | /* ARMv5TE load-consecutive (argument parse) |
9677 | Mode is like LDRH. | |
9678 | ||
9679 | LDRccD R, mode | |
9680 | STRccD R, mode. */ | |
9681 | ||
a737bd4d | 9682 | static void |
c19d1205 | 9683 | do_ldrd (void) |
a737bd4d | 9684 | { |
c19d1205 | 9685 | constraint (inst.operands[0].reg % 2 != 0, |
c56791bb | 9686 | _("first transfer register must be even")); |
c19d1205 ZW |
9687 | constraint (inst.operands[1].present |
9688 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
c56791bb | 9689 | _("can only transfer two consecutive registers")); |
c19d1205 ZW |
9690 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); |
9691 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 9692 | |
c19d1205 ZW |
9693 | if (!inst.operands[1].present) |
9694 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
5f4273c7 | 9695 | |
c56791bb RE |
9696 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
9697 | register and the first register written; we have to diagnose | |
9698 | overlap between the base and the second register written here. */ | |
ea6ef066 | 9699 | |
c56791bb RE |
9700 | if (inst.operands[2].reg == inst.operands[1].reg |
9701 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
9702 | as_warn (_("base register written back, and overlaps " | |
9703 | "second transfer register")); | |
b05fe5cf | 9704 | |
c56791bb RE |
9705 | if (!(inst.instruction & V4_STR_BIT)) |
9706 | { | |
c19d1205 | 9707 | /* For an index-register load, the index register must not overlap the |
c56791bb RE |
9708 | destination (even if not write-back). */ |
9709 | if (inst.operands[2].immisreg | |
9710 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg | |
9711 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
9712 | as_warn (_("index register overlaps transfer register")); | |
b05fe5cf | 9713 | } |
c19d1205 ZW |
9714 | inst.instruction |= inst.operands[0].reg << 12; |
9715 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
9716 | } |
9717 | ||
9718 | static void | |
c19d1205 | 9719 | do_ldrex (void) |
b05fe5cf | 9720 | { |
c19d1205 ZW |
9721 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
9722 | || inst.operands[1].postind || inst.operands[1].writeback | |
9723 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
9724 | || inst.operands[1].negative |
9725 | /* This can arise if the programmer has written | |
9726 | strex rN, rM, foo | |
9727 | or if they have mistakenly used a register name as the last | |
9728 | operand, eg: | |
9729 | strex rN, rM, rX | |
9730 | It is very difficult to distinguish between these two cases | |
9731 | because "rX" might actually be a label. ie the register | |
9732 | name has been occluded by a symbol of the same name. So we | |
9733 | just generate a general 'bad addressing mode' type error | |
9734 | message and leave it up to the programmer to discover the | |
9735 | true cause and fix their mistake. */ | |
9736 | || (inst.operands[1].reg == REG_PC), | |
9737 | BAD_ADDR_MODE); | |
b05fe5cf | 9738 | |
e2b0ab59 AV |
9739 | constraint (inst.relocs[0].exp.X_op != O_constant |
9740 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9741 | _("offset must be zero in ARM encoding")); |
b05fe5cf | 9742 | |
5be8be5d DG |
9743 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
9744 | ||
c19d1205 ZW |
9745 | inst.instruction |= inst.operands[0].reg << 12; |
9746 | inst.instruction |= inst.operands[1].reg << 16; | |
e2b0ab59 | 9747 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
b05fe5cf ZW |
9748 | } |
9749 | ||
9750 | static void | |
c19d1205 | 9751 | do_ldrexd (void) |
b05fe5cf | 9752 | { |
c19d1205 ZW |
9753 | constraint (inst.operands[0].reg % 2 != 0, |
9754 | _("even register required")); | |
9755 | constraint (inst.operands[1].present | |
9756 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
9757 | _("can only load two consecutive registers")); | |
9758 | /* If op 1 were present and equal to PC, this function wouldn't | |
9759 | have been called in the first place. */ | |
9760 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 9761 | |
c19d1205 ZW |
9762 | inst.instruction |= inst.operands[0].reg << 12; |
9763 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
9764 | } |
9765 | ||
1be5fd2e NC |
9766 | /* In both ARM and thumb state 'ldr pc, #imm' with an immediate |
9767 | which is not a multiple of four is UNPREDICTABLE. */ | |
9768 | static void | |
9769 | check_ldr_r15_aligned (void) | |
9770 | { | |
9771 | constraint (!(inst.operands[1].immisreg) | |
9772 | && (inst.operands[0].reg == REG_PC | |
9773 | && inst.operands[1].reg == REG_PC | |
e2b0ab59 | 9774 | && (inst.relocs[0].exp.X_add_number & 0x3)), |
de194d85 | 9775 | _("ldr to register 15 must be 4-byte aligned")); |
1be5fd2e NC |
9776 | } |
9777 | ||
b05fe5cf | 9778 | static void |
c19d1205 | 9779 | do_ldst (void) |
b05fe5cf | 9780 | { |
c19d1205 ZW |
9781 | inst.instruction |= inst.operands[0].reg << 12; |
9782 | if (!inst.operands[1].isreg) | |
8335d6aa | 9783 | if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE)) |
b05fe5cf | 9784 | return; |
c19d1205 | 9785 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
1be5fd2e | 9786 | check_ldr_r15_aligned (); |
b05fe5cf ZW |
9787 | } |
9788 | ||
9789 | static void | |
c19d1205 | 9790 | do_ldstt (void) |
b05fe5cf | 9791 | { |
c19d1205 ZW |
9792 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
9793 | reject [Rn,...]. */ | |
9794 | if (inst.operands[1].preind) | |
b05fe5cf | 9795 | { |
e2b0ab59 AV |
9796 | constraint (inst.relocs[0].exp.X_op != O_constant |
9797 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9798 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 9799 | |
c19d1205 ZW |
9800 | inst.operands[1].preind = 0; |
9801 | inst.operands[1].postind = 1; | |
9802 | inst.operands[1].writeback = 1; | |
b05fe5cf | 9803 | } |
c19d1205 ZW |
9804 | inst.instruction |= inst.operands[0].reg << 12; |
9805 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
9806 | } | |
b05fe5cf | 9807 | |
c19d1205 | 9808 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 9809 | |
c19d1205 ZW |
9810 | static void |
9811 | do_ldstv4 (void) | |
9812 | { | |
ff4a8d2b | 9813 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 ZW |
9814 | inst.instruction |= inst.operands[0].reg << 12; |
9815 | if (!inst.operands[1].isreg) | |
8335d6aa | 9816 | if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE)) |
b05fe5cf | 9817 | return; |
c19d1205 | 9818 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
9819 | } |
9820 | ||
9821 | static void | |
c19d1205 | 9822 | do_ldsttv4 (void) |
b05fe5cf | 9823 | { |
c19d1205 ZW |
9824 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
9825 | reject [Rn,...]. */ | |
9826 | if (inst.operands[1].preind) | |
b05fe5cf | 9827 | { |
e2b0ab59 AV |
9828 | constraint (inst.relocs[0].exp.X_op != O_constant |
9829 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9830 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 9831 | |
c19d1205 ZW |
9832 | inst.operands[1].preind = 0; |
9833 | inst.operands[1].postind = 1; | |
9834 | inst.operands[1].writeback = 1; | |
b05fe5cf | 9835 | } |
c19d1205 ZW |
9836 | inst.instruction |= inst.operands[0].reg << 12; |
9837 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
9838 | } | |
b05fe5cf | 9839 | |
c19d1205 ZW |
9840 | /* Co-processor register load/store. |
9841 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
9842 | static void | |
9843 | do_lstc (void) | |
9844 | { | |
9845 | inst.instruction |= inst.operands[0].reg << 8; | |
9846 | inst.instruction |= inst.operands[1].reg << 12; | |
9847 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
9848 | } |
9849 | ||
b05fe5cf | 9850 | static void |
c19d1205 | 9851 | do_mlas (void) |
b05fe5cf | 9852 | { |
8fb9d7b9 | 9853 | /* This restriction does not apply to mls (nor to mla in v6 or later). */ |
c19d1205 | 9854 | if (inst.operands[0].reg == inst.operands[1].reg |
8fb9d7b9 | 9855 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6) |
c19d1205 | 9856 | && !(inst.instruction & 0x00400000)) |
8fb9d7b9 | 9857 | as_tsktsk (_("Rd and Rm should be different in mla")); |
b05fe5cf | 9858 | |
c19d1205 ZW |
9859 | inst.instruction |= inst.operands[0].reg << 16; |
9860 | inst.instruction |= inst.operands[1].reg; | |
9861 | inst.instruction |= inst.operands[2].reg << 8; | |
9862 | inst.instruction |= inst.operands[3].reg << 12; | |
c19d1205 | 9863 | } |
b05fe5cf | 9864 | |
c19d1205 ZW |
9865 | static void |
9866 | do_mov (void) | |
9867 | { | |
e2b0ab59 AV |
9868 | constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
9869 | && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC , | |
a9f02af8 | 9870 | THUMB1_RELOC_ONLY); |
c19d1205 ZW |
9871 | inst.instruction |= inst.operands[0].reg << 12; |
9872 | encode_arm_shifter_operand (1); | |
9873 | } | |
b05fe5cf | 9874 | |
c19d1205 ZW |
9875 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
9876 | static void | |
9877 | do_mov16 (void) | |
9878 | { | |
b6895b4f PB |
9879 | bfd_vma imm; |
9880 | bfd_boolean top; | |
9881 | ||
9882 | top = (inst.instruction & 0x00400000) != 0; | |
e2b0ab59 | 9883 | constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW, |
33eaf5de | 9884 | _(":lower16: not allowed in this instruction")); |
e2b0ab59 | 9885 | constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT, |
33eaf5de | 9886 | _(":upper16: not allowed in this instruction")); |
c19d1205 | 9887 | inst.instruction |= inst.operands[0].reg << 12; |
e2b0ab59 | 9888 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
b6895b4f | 9889 | { |
e2b0ab59 | 9890 | imm = inst.relocs[0].exp.X_add_number; |
b6895b4f PB |
9891 | /* The value is in two pieces: 0:11, 16:19. */ |
9892 | inst.instruction |= (imm & 0x00000fff); | |
9893 | inst.instruction |= (imm & 0x0000f000) << 4; | |
9894 | } | |
b05fe5cf | 9895 | } |
b99bd4ef | 9896 | |
037e8744 JB |
9897 | static int |
9898 | do_vfp_nsyn_mrs (void) | |
9899 | { | |
9900 | if (inst.operands[0].isvec) | |
9901 | { | |
9902 | if (inst.operands[1].reg != 1) | |
477330fc | 9903 | first_error (_("operand 1 must be FPSCR")); |
037e8744 JB |
9904 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); |
9905 | memset (&inst.operands[1], '\0', sizeof (inst.operands[1])); | |
9906 | do_vfp_nsyn_opcode ("fmstat"); | |
9907 | } | |
9908 | else if (inst.operands[1].isvec) | |
9909 | do_vfp_nsyn_opcode ("fmrx"); | |
9910 | else | |
9911 | return FAIL; | |
5f4273c7 | 9912 | |
037e8744 JB |
9913 | return SUCCESS; |
9914 | } | |
9915 | ||
9916 | static int | |
9917 | do_vfp_nsyn_msr (void) | |
9918 | { | |
9919 | if (inst.operands[0].isvec) | |
9920 | do_vfp_nsyn_opcode ("fmxr"); | |
9921 | else | |
9922 | return FAIL; | |
9923 | ||
9924 | return SUCCESS; | |
9925 | } | |
9926 | ||
f7c21dc7 NC |
9927 | static void |
9928 | do_vmrs (void) | |
9929 | { | |
9930 | unsigned Rt = inst.operands[0].reg; | |
fa94de6b | 9931 | |
16d02dc9 | 9932 | if (thumb_mode && Rt == REG_SP) |
f7c21dc7 NC |
9933 | { |
9934 | inst.error = BAD_SP; | |
9935 | return; | |
9936 | } | |
9937 | ||
ba6cd17f SD |
9938 | switch (inst.operands[1].reg) |
9939 | { | |
9940 | /* MVFR2 is only valid for Armv8-A. */ | |
9941 | case 5: | |
9942 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
9943 | _(BAD_FPU)); | |
9944 | break; | |
9945 | ||
9946 | /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */ | |
9947 | case 1: /* fpscr. */ | |
9948 | constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) | |
9949 | || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)), | |
9950 | _(BAD_FPU)); | |
9951 | break; | |
9952 | ||
9953 | case 14: /* fpcxt_ns. */ | |
9954 | case 15: /* fpcxt_s. */ | |
9955 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main), | |
9956 | _("selected processor does not support instruction")); | |
9957 | break; | |
9958 | ||
9959 | case 2: /* fpscr_nzcvqc. */ | |
9960 | case 12: /* vpr. */ | |
9961 | case 13: /* p0. */ | |
9962 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main) | |
9963 | || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) | |
9964 | && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)), | |
9965 | _("selected processor does not support instruction")); | |
9966 | if (inst.operands[0].reg != 2 | |
9967 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
9968 | as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE")); | |
9969 | break; | |
9970 | ||
9971 | default: | |
9972 | break; | |
9973 | } | |
40c7d507 | 9974 | |
f7c21dc7 | 9975 | /* APSR_ sets isvec. All other refs to PC are illegal. */ |
16d02dc9 | 9976 | if (!inst.operands[0].isvec && Rt == REG_PC) |
f7c21dc7 NC |
9977 | { |
9978 | inst.error = BAD_PC; | |
9979 | return; | |
9980 | } | |
9981 | ||
16d02dc9 JB |
9982 | /* If we get through parsing the register name, we just insert the number |
9983 | generated into the instruction without further validation. */ | |
9984 | inst.instruction |= (inst.operands[1].reg << 16); | |
f7c21dc7 NC |
9985 | inst.instruction |= (Rt << 12); |
9986 | } | |
9987 | ||
9988 | static void | |
9989 | do_vmsr (void) | |
9990 | { | |
9991 | unsigned Rt = inst.operands[1].reg; | |
fa94de6b | 9992 | |
f7c21dc7 NC |
9993 | if (thumb_mode) |
9994 | reject_bad_reg (Rt); | |
9995 | else if (Rt == REG_PC) | |
9996 | { | |
9997 | inst.error = BAD_PC; | |
9998 | return; | |
9999 | } | |
10000 | ||
ba6cd17f SD |
10001 | switch (inst.operands[0].reg) |
10002 | { | |
10003 | /* MVFR2 is only valid for Armv8-A. */ | |
10004 | case 5: | |
10005 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
10006 | _(BAD_FPU)); | |
10007 | break; | |
10008 | ||
10009 | /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */ | |
10010 | case 1: /* fpcr. */ | |
10011 | constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) | |
10012 | || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)), | |
10013 | _(BAD_FPU)); | |
10014 | break; | |
10015 | ||
10016 | case 14: /* fpcxt_ns. */ | |
10017 | case 15: /* fpcxt_s. */ | |
10018 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main), | |
10019 | _("selected processor does not support instruction")); | |
10020 | break; | |
10021 | ||
10022 | case 2: /* fpscr_nzcvqc. */ | |
10023 | case 12: /* vpr. */ | |
10024 | case 13: /* p0. */ | |
10025 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main) | |
10026 | || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) | |
10027 | && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)), | |
10028 | _("selected processor does not support instruction")); | |
10029 | if (inst.operands[0].reg != 2 | |
10030 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
10031 | as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE")); | |
10032 | break; | |
10033 | ||
10034 | default: | |
10035 | break; | |
10036 | } | |
40c7d507 | 10037 | |
16d02dc9 JB |
10038 | /* If we get through parsing the register name, we just insert the number |
10039 | generated into the instruction without further validation. */ | |
10040 | inst.instruction |= (inst.operands[0].reg << 16); | |
f7c21dc7 NC |
10041 | inst.instruction |= (Rt << 12); |
10042 | } | |
10043 | ||
b99bd4ef | 10044 | static void |
c19d1205 | 10045 | do_mrs (void) |
b99bd4ef | 10046 | { |
90ec0d68 MGD |
10047 | unsigned br; |
10048 | ||
037e8744 JB |
10049 | if (do_vfp_nsyn_mrs () == SUCCESS) |
10050 | return; | |
10051 | ||
ff4a8d2b | 10052 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 | 10053 | inst.instruction |= inst.operands[0].reg << 12; |
90ec0d68 MGD |
10054 | |
10055 | if (inst.operands[1].isreg) | |
10056 | { | |
10057 | br = inst.operands[1].reg; | |
806ab1c0 | 10058 | if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000)) |
90ec0d68 MGD |
10059 | as_bad (_("bad register for mrs")); |
10060 | } | |
10061 | else | |
10062 | { | |
10063 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ | |
10064 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
10065 | != (PSR_c|PSR_f), | |
d2cd1205 | 10066 | _("'APSR', 'CPSR' or 'SPSR' expected")); |
90ec0d68 MGD |
10067 | br = (15<<16) | (inst.operands[1].imm & SPSR_BIT); |
10068 | } | |
10069 | ||
10070 | inst.instruction |= br; | |
c19d1205 | 10071 | } |
b99bd4ef | 10072 | |
c19d1205 ZW |
10073 | /* Two possible forms: |
10074 | "{C|S}PSR_<field>, Rm", | |
10075 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 10076 | |
c19d1205 ZW |
10077 | static void |
10078 | do_msr (void) | |
10079 | { | |
037e8744 JB |
10080 | if (do_vfp_nsyn_msr () == SUCCESS) |
10081 | return; | |
10082 | ||
c19d1205 ZW |
10083 | inst.instruction |= inst.operands[0].imm; |
10084 | if (inst.operands[1].isreg) | |
10085 | inst.instruction |= inst.operands[1].reg; | |
10086 | else | |
b99bd4ef | 10087 | { |
c19d1205 | 10088 | inst.instruction |= INST_IMMEDIATE; |
e2b0ab59 AV |
10089 | inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE; |
10090 | inst.relocs[0].pc_rel = 0; | |
b99bd4ef | 10091 | } |
b99bd4ef NC |
10092 | } |
10093 | ||
c19d1205 ZW |
10094 | static void |
10095 | do_mul (void) | |
a737bd4d | 10096 | { |
ff4a8d2b NC |
10097 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
10098 | ||
c19d1205 ZW |
10099 | if (!inst.operands[2].present) |
10100 | inst.operands[2].reg = inst.operands[0].reg; | |
10101 | inst.instruction |= inst.operands[0].reg << 16; | |
10102 | inst.instruction |= inst.operands[1].reg; | |
10103 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 10104 | |
8fb9d7b9 MS |
10105 | if (inst.operands[0].reg == inst.operands[1].reg |
10106 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) | |
10107 | as_tsktsk (_("Rd and Rm should be different in mul")); | |
a737bd4d NC |
10108 | } |
10109 | ||
c19d1205 ZW |
10110 | /* Long Multiply Parser |
10111 | UMULL RdLo, RdHi, Rm, Rs | |
10112 | SMULL RdLo, RdHi, Rm, Rs | |
10113 | UMLAL RdLo, RdHi, Rm, Rs | |
10114 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
10115 | |
10116 | static void | |
c19d1205 | 10117 | do_mull (void) |
b99bd4ef | 10118 | { |
c19d1205 ZW |
10119 | inst.instruction |= inst.operands[0].reg << 12; |
10120 | inst.instruction |= inst.operands[1].reg << 16; | |
10121 | inst.instruction |= inst.operands[2].reg; | |
10122 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 10123 | |
682b27ad PB |
10124 | /* rdhi and rdlo must be different. */ |
10125 | if (inst.operands[0].reg == inst.operands[1].reg) | |
10126 | as_tsktsk (_("rdhi and rdlo must be different")); | |
10127 | ||
10128 | /* rdhi, rdlo and rm must all be different before armv6. */ | |
10129 | if ((inst.operands[0].reg == inst.operands[2].reg | |
c19d1205 | 10130 | || inst.operands[1].reg == inst.operands[2].reg) |
682b27ad | 10131 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) |
c19d1205 ZW |
10132 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); |
10133 | } | |
b99bd4ef | 10134 | |
c19d1205 ZW |
10135 | static void |
10136 | do_nop (void) | |
10137 | { | |
e7495e45 NS |
10138 | if (inst.operands[0].present |
10139 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k)) | |
c19d1205 ZW |
10140 | { |
10141 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
10142 | inst.instruction &= 0xf0000000; | |
e7495e45 NS |
10143 | inst.instruction |= 0x0320f000; |
10144 | if (inst.operands[0].present) | |
10145 | inst.instruction |= inst.operands[0].imm; | |
c19d1205 | 10146 | } |
b99bd4ef NC |
10147 | } |
10148 | ||
c19d1205 ZW |
10149 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
10150 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
10151 | Condition defaults to COND_ALWAYS. | |
10152 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
10153 | |
10154 | static void | |
c19d1205 | 10155 | do_pkhbt (void) |
b99bd4ef | 10156 | { |
c19d1205 ZW |
10157 | inst.instruction |= inst.operands[0].reg << 12; |
10158 | inst.instruction |= inst.operands[1].reg << 16; | |
10159 | inst.instruction |= inst.operands[2].reg; | |
10160 | if (inst.operands[3].present) | |
10161 | encode_arm_shift (3); | |
10162 | } | |
b99bd4ef | 10163 | |
c19d1205 | 10164 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 10165 | |
c19d1205 ZW |
10166 | static void |
10167 | do_pkhtb (void) | |
10168 | { | |
10169 | if (!inst.operands[3].present) | |
b99bd4ef | 10170 | { |
c19d1205 ZW |
10171 | /* If the shift specifier is omitted, turn the instruction |
10172 | into pkhbt rd, rm, rn. */ | |
10173 | inst.instruction &= 0xfff00010; | |
10174 | inst.instruction |= inst.operands[0].reg << 12; | |
10175 | inst.instruction |= inst.operands[1].reg; | |
10176 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
10177 | } |
10178 | else | |
10179 | { | |
c19d1205 ZW |
10180 | inst.instruction |= inst.operands[0].reg << 12; |
10181 | inst.instruction |= inst.operands[1].reg << 16; | |
10182 | inst.instruction |= inst.operands[2].reg; | |
10183 | encode_arm_shift (3); | |
b99bd4ef NC |
10184 | } |
10185 | } | |
10186 | ||
c19d1205 | 10187 | /* ARMv5TE: Preload-Cache |
60e5ef9f | 10188 | MP Extensions: Preload for write |
c19d1205 | 10189 | |
60e5ef9f | 10190 | PLD(W) <addr_mode> |
c19d1205 ZW |
10191 | |
10192 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
10193 | |
10194 | static void | |
c19d1205 | 10195 | do_pld (void) |
b99bd4ef | 10196 | { |
c19d1205 ZW |
10197 | constraint (!inst.operands[0].isreg, |
10198 | _("'[' expected after PLD mnemonic")); | |
10199 | constraint (inst.operands[0].postind, | |
10200 | _("post-indexed expression used in preload instruction")); | |
10201 | constraint (inst.operands[0].writeback, | |
10202 | _("writeback used in preload instruction")); | |
10203 | constraint (!inst.operands[0].preind, | |
10204 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
10205 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
10206 | } | |
b99bd4ef | 10207 | |
62b3e311 PB |
10208 | /* ARMv7: PLI <addr_mode> */ |
10209 | static void | |
10210 | do_pli (void) | |
10211 | { | |
10212 | constraint (!inst.operands[0].isreg, | |
10213 | _("'[' expected after PLI mnemonic")); | |
10214 | constraint (inst.operands[0].postind, | |
10215 | _("post-indexed expression used in preload instruction")); | |
10216 | constraint (inst.operands[0].writeback, | |
10217 | _("writeback used in preload instruction")); | |
10218 | constraint (!inst.operands[0].preind, | |
10219 | _("unindexed addressing used in preload instruction")); | |
10220 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); | |
10221 | inst.instruction &= ~PRE_INDEX; | |
10222 | } | |
10223 | ||
c19d1205 ZW |
10224 | static void |
10225 | do_push_pop (void) | |
10226 | { | |
5e0d7f77 MP |
10227 | constraint (inst.operands[0].writeback, |
10228 | _("push/pop do not support {reglist}^")); | |
c19d1205 ZW |
10229 | inst.operands[1] = inst.operands[0]; |
10230 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
10231 | inst.operands[0].isreg = 1; | |
10232 | inst.operands[0].writeback = 1; | |
10233 | inst.operands[0].reg = REG_SP; | |
6530b175 | 10234 | encode_ldmstm (/*from_push_pop_mnem=*/TRUE); |
c19d1205 | 10235 | } |
b99bd4ef | 10236 | |
c19d1205 ZW |
10237 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
10238 | word at the specified address and the following word | |
10239 | respectively. | |
10240 | Unconditionally executed. | |
10241 | Error if Rn is R15. */ | |
b99bd4ef | 10242 | |
c19d1205 ZW |
10243 | static void |
10244 | do_rfe (void) | |
10245 | { | |
10246 | inst.instruction |= inst.operands[0].reg << 16; | |
10247 | if (inst.operands[0].writeback) | |
10248 | inst.instruction |= WRITE_BACK; | |
10249 | } | |
b99bd4ef | 10250 | |
c19d1205 | 10251 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 10252 | |
c19d1205 ZW |
10253 | static void |
10254 | do_ssat (void) | |
10255 | { | |
10256 | inst.instruction |= inst.operands[0].reg << 12; | |
10257 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
10258 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 10259 | |
c19d1205 ZW |
10260 | if (inst.operands[3].present) |
10261 | encode_arm_shift (3); | |
b99bd4ef NC |
10262 | } |
10263 | ||
c19d1205 | 10264 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
10265 | |
10266 | static void | |
c19d1205 | 10267 | do_usat (void) |
b99bd4ef | 10268 | { |
c19d1205 ZW |
10269 | inst.instruction |= inst.operands[0].reg << 12; |
10270 | inst.instruction |= inst.operands[1].imm << 16; | |
10271 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 10272 | |
c19d1205 ZW |
10273 | if (inst.operands[3].present) |
10274 | encode_arm_shift (3); | |
b99bd4ef NC |
10275 | } |
10276 | ||
c19d1205 | 10277 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
10278 | |
10279 | static void | |
c19d1205 | 10280 | do_ssat16 (void) |
09d92015 | 10281 | { |
c19d1205 ZW |
10282 | inst.instruction |= inst.operands[0].reg << 12; |
10283 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
10284 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
10285 | } |
10286 | ||
c19d1205 ZW |
10287 | static void |
10288 | do_usat16 (void) | |
a737bd4d | 10289 | { |
c19d1205 ZW |
10290 | inst.instruction |= inst.operands[0].reg << 12; |
10291 | inst.instruction |= inst.operands[1].imm << 16; | |
10292 | inst.instruction |= inst.operands[2].reg; | |
10293 | } | |
a737bd4d | 10294 | |
c19d1205 ZW |
10295 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
10296 | preserving the other bits. | |
a737bd4d | 10297 | |
c19d1205 ZW |
10298 | setend <endian_specifier>, where <endian_specifier> is either |
10299 | BE or LE. */ | |
a737bd4d | 10300 | |
c19d1205 ZW |
10301 | static void |
10302 | do_setend (void) | |
10303 | { | |
12e37cbc MGD |
10304 | if (warn_on_deprecated |
10305 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
5c3696f8 | 10306 | as_tsktsk (_("setend use is deprecated for ARMv8")); |
12e37cbc | 10307 | |
c19d1205 ZW |
10308 | if (inst.operands[0].imm) |
10309 | inst.instruction |= 0x200; | |
a737bd4d NC |
10310 | } |
10311 | ||
10312 | static void | |
c19d1205 | 10313 | do_shift (void) |
a737bd4d | 10314 | { |
c19d1205 ZW |
10315 | unsigned int Rm = (inst.operands[1].present |
10316 | ? inst.operands[1].reg | |
10317 | : inst.operands[0].reg); | |
a737bd4d | 10318 | |
c19d1205 ZW |
10319 | inst.instruction |= inst.operands[0].reg << 12; |
10320 | inst.instruction |= Rm; | |
10321 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 10322 | { |
c19d1205 ZW |
10323 | inst.instruction |= inst.operands[2].reg << 8; |
10324 | inst.instruction |= SHIFT_BY_REG; | |
94342ec3 NC |
10325 | /* PR 12854: Error on extraneous shifts. */ |
10326 | constraint (inst.operands[2].shifted, | |
10327 | _("extraneous shift as part of operand to shift insn")); | |
a737bd4d NC |
10328 | } |
10329 | else | |
e2b0ab59 | 10330 | inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
10331 | } |
10332 | ||
09d92015 | 10333 | static void |
3eb17e6b | 10334 | do_smc (void) |
09d92015 | 10335 | { |
ba85f98c BW |
10336 | unsigned int value = inst.relocs[0].exp.X_add_number; |
10337 | constraint (value > 0xf, _("immediate too large (bigger than 0xF)")); | |
10338 | ||
e2b0ab59 AV |
10339 | inst.relocs[0].type = BFD_RELOC_ARM_SMC; |
10340 | inst.relocs[0].pc_rel = 0; | |
09d92015 MM |
10341 | } |
10342 | ||
90ec0d68 MGD |
10343 | static void |
10344 | do_hvc (void) | |
10345 | { | |
e2b0ab59 AV |
10346 | inst.relocs[0].type = BFD_RELOC_ARM_HVC; |
10347 | inst.relocs[0].pc_rel = 0; | |
90ec0d68 MGD |
10348 | } |
10349 | ||
09d92015 | 10350 | static void |
c19d1205 | 10351 | do_swi (void) |
09d92015 | 10352 | { |
e2b0ab59 AV |
10353 | inst.relocs[0].type = BFD_RELOC_ARM_SWI; |
10354 | inst.relocs[0].pc_rel = 0; | |
09d92015 MM |
10355 | } |
10356 | ||
ddfded2f MW |
10357 | static void |
10358 | do_setpan (void) | |
10359 | { | |
10360 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan), | |
10361 | _("selected processor does not support SETPAN instruction")); | |
10362 | ||
10363 | inst.instruction |= ((inst.operands[0].imm & 1) << 9); | |
10364 | } | |
10365 | ||
10366 | static void | |
10367 | do_t_setpan (void) | |
10368 | { | |
10369 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan), | |
10370 | _("selected processor does not support SETPAN instruction")); | |
10371 | ||
10372 | inst.instruction |= (inst.operands[0].imm << 3); | |
10373 | } | |
10374 | ||
c19d1205 ZW |
10375 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
10376 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
10377 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
10378 | Error if any register is R15. */ | |
e16bb312 | 10379 | |
c19d1205 ZW |
10380 | static void |
10381 | do_smla (void) | |
e16bb312 | 10382 | { |
c19d1205 ZW |
10383 | inst.instruction |= inst.operands[0].reg << 16; |
10384 | inst.instruction |= inst.operands[1].reg; | |
10385 | inst.instruction |= inst.operands[2].reg << 8; | |
10386 | inst.instruction |= inst.operands[3].reg << 12; | |
10387 | } | |
a737bd4d | 10388 | |
c19d1205 ZW |
10389 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
10390 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
10391 | Error if any register is R15. | |
10392 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 10393 | |
c19d1205 ZW |
10394 | static void |
10395 | do_smlal (void) | |
10396 | { | |
10397 | inst.instruction |= inst.operands[0].reg << 12; | |
10398 | inst.instruction |= inst.operands[1].reg << 16; | |
10399 | inst.instruction |= inst.operands[2].reg; | |
10400 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 10401 | |
c19d1205 ZW |
10402 | if (inst.operands[0].reg == inst.operands[1].reg) |
10403 | as_tsktsk (_("rdhi and rdlo must be different")); | |
10404 | } | |
a737bd4d | 10405 | |
c19d1205 ZW |
10406 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
10407 | SMULxy{cond} Rd,Rm,Rs | |
10408 | Error if any register is R15. */ | |
a737bd4d | 10409 | |
c19d1205 ZW |
10410 | static void |
10411 | do_smul (void) | |
10412 | { | |
10413 | inst.instruction |= inst.operands[0].reg << 16; | |
10414 | inst.instruction |= inst.operands[1].reg; | |
10415 | inst.instruction |= inst.operands[2].reg << 8; | |
10416 | } | |
a737bd4d | 10417 | |
b6702015 PB |
10418 | /* ARM V6 srs (argument parse). The variable fields in the encoding are |
10419 | the same for both ARM and Thumb-2. */ | |
a737bd4d | 10420 | |
c19d1205 ZW |
10421 | static void |
10422 | do_srs (void) | |
10423 | { | |
b6702015 PB |
10424 | int reg; |
10425 | ||
10426 | if (inst.operands[0].present) | |
10427 | { | |
10428 | reg = inst.operands[0].reg; | |
fdfde340 | 10429 | constraint (reg != REG_SP, _("SRS base register must be r13")); |
b6702015 PB |
10430 | } |
10431 | else | |
fdfde340 | 10432 | reg = REG_SP; |
b6702015 PB |
10433 | |
10434 | inst.instruction |= reg << 16; | |
10435 | inst.instruction |= inst.operands[1].imm; | |
10436 | if (inst.operands[0].writeback || inst.operands[1].writeback) | |
c19d1205 ZW |
10437 | inst.instruction |= WRITE_BACK; |
10438 | } | |
a737bd4d | 10439 | |
c19d1205 | 10440 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 10441 | |
c19d1205 ZW |
10442 | static void |
10443 | do_strex (void) | |
10444 | { | |
10445 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
10446 | || inst.operands[2].postind || inst.operands[2].writeback | |
10447 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
10448 | || inst.operands[2].negative |
10449 | /* See comment in do_ldrex(). */ | |
10450 | || (inst.operands[2].reg == REG_PC), | |
10451 | BAD_ADDR_MODE); | |
a737bd4d | 10452 | |
c19d1205 ZW |
10453 | constraint (inst.operands[0].reg == inst.operands[1].reg |
10454 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 10455 | |
e2b0ab59 AV |
10456 | constraint (inst.relocs[0].exp.X_op != O_constant |
10457 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 10458 | _("offset must be zero in ARM encoding")); |
a737bd4d | 10459 | |
c19d1205 ZW |
10460 | inst.instruction |= inst.operands[0].reg << 12; |
10461 | inst.instruction |= inst.operands[1].reg; | |
10462 | inst.instruction |= inst.operands[2].reg << 16; | |
e2b0ab59 | 10463 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
e16bb312 NC |
10464 | } |
10465 | ||
877807f8 NC |
10466 | static void |
10467 | do_t_strexbh (void) | |
10468 | { | |
10469 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
10470 | || inst.operands[2].postind || inst.operands[2].writeback | |
10471 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
10472 | || inst.operands[2].negative, | |
10473 | BAD_ADDR_MODE); | |
10474 | ||
10475 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
10476 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
10477 | ||
10478 | do_rm_rd_rn (); | |
10479 | } | |
10480 | ||
e16bb312 | 10481 | static void |
c19d1205 | 10482 | do_strexd (void) |
e16bb312 | 10483 | { |
c19d1205 ZW |
10484 | constraint (inst.operands[1].reg % 2 != 0, |
10485 | _("even register required")); | |
10486 | constraint (inst.operands[2].present | |
10487 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
10488 | _("can only store two consecutive registers")); | |
10489 | /* If op 2 were present and equal to PC, this function wouldn't | |
10490 | have been called in the first place. */ | |
10491 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 10492 | |
c19d1205 ZW |
10493 | constraint (inst.operands[0].reg == inst.operands[1].reg |
10494 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
10495 | || inst.operands[0].reg == inst.operands[3].reg, | |
10496 | BAD_OVERLAP); | |
e16bb312 | 10497 | |
c19d1205 ZW |
10498 | inst.instruction |= inst.operands[0].reg << 12; |
10499 | inst.instruction |= inst.operands[1].reg; | |
10500 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
10501 | } |
10502 | ||
9eb6c0f1 MGD |
10503 | /* ARM V8 STRL. */ |
10504 | static void | |
4b8c8c02 | 10505 | do_stlex (void) |
9eb6c0f1 MGD |
10506 | { |
10507 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
10508 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
10509 | ||
10510 | do_rd_rm_rn (); | |
10511 | } | |
10512 | ||
10513 | static void | |
4b8c8c02 | 10514 | do_t_stlex (void) |
9eb6c0f1 MGD |
10515 | { |
10516 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
10517 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
10518 | ||
10519 | do_rm_rd_rn (); | |
10520 | } | |
10521 | ||
c19d1205 ZW |
10522 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
10523 | extends it to 32-bits, and adds the result to a value in another | |
10524 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
10525 | before extracting the 16-bit value. | |
10526 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
10527 | Condition defaults to COND_ALWAYS. | |
10528 | Error if any register uses R15. */ | |
10529 | ||
e16bb312 | 10530 | static void |
c19d1205 | 10531 | do_sxtah (void) |
e16bb312 | 10532 | { |
c19d1205 ZW |
10533 | inst.instruction |= inst.operands[0].reg << 12; |
10534 | inst.instruction |= inst.operands[1].reg << 16; | |
10535 | inst.instruction |= inst.operands[2].reg; | |
10536 | inst.instruction |= inst.operands[3].imm << 10; | |
10537 | } | |
e16bb312 | 10538 | |
c19d1205 | 10539 | /* ARM V6 SXTH. |
e16bb312 | 10540 | |
c19d1205 ZW |
10541 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
10542 | Condition defaults to COND_ALWAYS. | |
10543 | Error if any register uses R15. */ | |
e16bb312 NC |
10544 | |
10545 | static void | |
c19d1205 | 10546 | do_sxth (void) |
e16bb312 | 10547 | { |
c19d1205 ZW |
10548 | inst.instruction |= inst.operands[0].reg << 12; |
10549 | inst.instruction |= inst.operands[1].reg; | |
10550 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 10551 | } |
c19d1205 ZW |
10552 | \f |
10553 | /* VFP instructions. In a logical order: SP variant first, monad | |
10554 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
10555 | |
10556 | static void | |
c19d1205 | 10557 | do_vfp_sp_monadic (void) |
e16bb312 | 10558 | { |
57785aa2 AV |
10559 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd) |
10560 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
10561 | _(BAD_FPU)); | |
10562 | ||
5287ad62 JB |
10563 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
10564 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
10565 | } |
10566 | ||
10567 | static void | |
c19d1205 | 10568 | do_vfp_sp_dyadic (void) |
e16bb312 | 10569 | { |
5287ad62 JB |
10570 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
10571 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
10572 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
10573 | } |
10574 | ||
10575 | static void | |
c19d1205 | 10576 | do_vfp_sp_compare_z (void) |
e16bb312 | 10577 | { |
5287ad62 | 10578 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
10579 | } |
10580 | ||
10581 | static void | |
c19d1205 | 10582 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 10583 | { |
5287ad62 JB |
10584 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
10585 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
10586 | } |
10587 | ||
10588 | static void | |
c19d1205 | 10589 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 10590 | { |
5287ad62 JB |
10591 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
10592 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
e16bb312 NC |
10593 | } |
10594 | ||
10595 | static void | |
c19d1205 | 10596 | do_vfp_reg_from_sp (void) |
e16bb312 | 10597 | { |
57785aa2 AV |
10598 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd) |
10599 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
10600 | _(BAD_FPU)); | |
10601 | ||
c19d1205 | 10602 | inst.instruction |= inst.operands[0].reg << 12; |
5287ad62 | 10603 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); |
e16bb312 NC |
10604 | } |
10605 | ||
10606 | static void | |
c19d1205 | 10607 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 10608 | { |
c19d1205 ZW |
10609 | constraint (inst.operands[2].imm != 2, |
10610 | _("only two consecutive VFP SP registers allowed here")); | |
10611 | inst.instruction |= inst.operands[0].reg << 12; | |
10612 | inst.instruction |= inst.operands[1].reg << 16; | |
5287ad62 | 10613 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); |
e16bb312 NC |
10614 | } |
10615 | ||
10616 | static void | |
c19d1205 | 10617 | do_vfp_sp_from_reg (void) |
e16bb312 | 10618 | { |
57785aa2 AV |
10619 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd) |
10620 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
10621 | _(BAD_FPU)); | |
10622 | ||
5287ad62 | 10623 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn); |
c19d1205 | 10624 | inst.instruction |= inst.operands[1].reg << 12; |
e16bb312 NC |
10625 | } |
10626 | ||
10627 | static void | |
c19d1205 | 10628 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 10629 | { |
c19d1205 ZW |
10630 | constraint (inst.operands[0].imm != 2, |
10631 | _("only two consecutive VFP SP registers allowed here")); | |
5287ad62 | 10632 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm); |
c19d1205 ZW |
10633 | inst.instruction |= inst.operands[1].reg << 12; |
10634 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
10635 | } |
10636 | ||
10637 | static void | |
c19d1205 | 10638 | do_vfp_sp_ldst (void) |
e16bb312 | 10639 | { |
5287ad62 | 10640 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
c19d1205 | 10641 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
10642 | } |
10643 | ||
10644 | static void | |
c19d1205 | 10645 | do_vfp_dp_ldst (void) |
e16bb312 | 10646 | { |
5287ad62 | 10647 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
c19d1205 | 10648 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
10649 | } |
10650 | ||
c19d1205 | 10651 | |
e16bb312 | 10652 | static void |
c19d1205 | 10653 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 10654 | { |
c19d1205 ZW |
10655 | if (inst.operands[0].writeback) |
10656 | inst.instruction |= WRITE_BACK; | |
10657 | else | |
10658 | constraint (ldstm_type != VFP_LDSTMIA, | |
10659 | _("this addressing mode requires base-register writeback")); | |
10660 | inst.instruction |= inst.operands[0].reg << 16; | |
5287ad62 | 10661 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd); |
c19d1205 | 10662 | inst.instruction |= inst.operands[1].imm; |
e16bb312 NC |
10663 | } |
10664 | ||
10665 | static void | |
c19d1205 | 10666 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 10667 | { |
c19d1205 | 10668 | int count; |
e16bb312 | 10669 | |
c19d1205 ZW |
10670 | if (inst.operands[0].writeback) |
10671 | inst.instruction |= WRITE_BACK; | |
10672 | else | |
10673 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
10674 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 10675 | |
c19d1205 | 10676 | inst.instruction |= inst.operands[0].reg << 16; |
5287ad62 | 10677 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); |
e16bb312 | 10678 | |
c19d1205 ZW |
10679 | count = inst.operands[1].imm << 1; |
10680 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
10681 | count += 1; | |
e16bb312 | 10682 | |
c19d1205 | 10683 | inst.instruction |= count; |
e16bb312 NC |
10684 | } |
10685 | ||
10686 | static void | |
c19d1205 | 10687 | do_vfp_sp_ldstmia (void) |
e16bb312 | 10688 | { |
c19d1205 | 10689 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
10690 | } |
10691 | ||
10692 | static void | |
c19d1205 | 10693 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 10694 | { |
c19d1205 | 10695 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
10696 | } |
10697 | ||
10698 | static void | |
c19d1205 | 10699 | do_vfp_dp_ldstmia (void) |
e16bb312 | 10700 | { |
c19d1205 | 10701 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
10702 | } |
10703 | ||
10704 | static void | |
c19d1205 | 10705 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 10706 | { |
c19d1205 | 10707 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
10708 | } |
10709 | ||
10710 | static void | |
c19d1205 | 10711 | do_vfp_xp_ldstmia (void) |
e16bb312 | 10712 | { |
c19d1205 ZW |
10713 | vfp_dp_ldstm (VFP_LDSTMIAX); |
10714 | } | |
e16bb312 | 10715 | |
c19d1205 ZW |
10716 | static void |
10717 | do_vfp_xp_ldstmdb (void) | |
10718 | { | |
10719 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 10720 | } |
5287ad62 JB |
10721 | |
10722 | static void | |
10723 | do_vfp_dp_rd_rm (void) | |
10724 | { | |
57785aa2 AV |
10725 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1) |
10726 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
10727 | _(BAD_FPU)); | |
10728 | ||
5287ad62 JB |
10729 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
10730 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
10731 | } | |
10732 | ||
10733 | static void | |
10734 | do_vfp_dp_rn_rd (void) | |
10735 | { | |
10736 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn); | |
10737 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
10738 | } | |
10739 | ||
10740 | static void | |
10741 | do_vfp_dp_rd_rn (void) | |
10742 | { | |
10743 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
10744 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
10745 | } | |
10746 | ||
10747 | static void | |
10748 | do_vfp_dp_rd_rn_rm (void) | |
10749 | { | |
57785aa2 AV |
10750 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2) |
10751 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
10752 | _(BAD_FPU)); | |
10753 | ||
5287ad62 JB |
10754 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
10755 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
10756 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm); | |
10757 | } | |
10758 | ||
10759 | static void | |
10760 | do_vfp_dp_rd (void) | |
10761 | { | |
10762 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
10763 | } | |
10764 | ||
10765 | static void | |
10766 | do_vfp_dp_rm_rd_rn (void) | |
10767 | { | |
57785aa2 AV |
10768 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2) |
10769 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
10770 | _(BAD_FPU)); | |
10771 | ||
5287ad62 JB |
10772 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm); |
10773 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
10774 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn); | |
10775 | } | |
10776 | ||
10777 | /* VFPv3 instructions. */ | |
10778 | static void | |
10779 | do_vfp_sp_const (void) | |
10780 | { | |
10781 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
00249aaa PB |
10782 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
10783 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
10784 | } |
10785 | ||
10786 | static void | |
10787 | do_vfp_dp_const (void) | |
10788 | { | |
10789 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
00249aaa PB |
10790 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
10791 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
10792 | } |
10793 | ||
10794 | static void | |
10795 | vfp_conv (int srcsize) | |
10796 | { | |
5f1af56b MGD |
10797 | int immbits = srcsize - inst.operands[1].imm; |
10798 | ||
fa94de6b RM |
10799 | if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize)) |
10800 | { | |
5f1af56b | 10801 | /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16. |
477330fc | 10802 | i.e. immbits must be in range 0 - 16. */ |
5f1af56b MGD |
10803 | inst.error = _("immediate value out of range, expected range [0, 16]"); |
10804 | return; | |
10805 | } | |
fa94de6b | 10806 | else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize)) |
5f1af56b MGD |
10807 | { |
10808 | /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32. | |
477330fc | 10809 | i.e. immbits must be in range 0 - 31. */ |
5f1af56b MGD |
10810 | inst.error = _("immediate value out of range, expected range [1, 32]"); |
10811 | return; | |
10812 | } | |
10813 | ||
5287ad62 JB |
10814 | inst.instruction |= (immbits & 1) << 5; |
10815 | inst.instruction |= (immbits >> 1); | |
10816 | } | |
10817 | ||
10818 | static void | |
10819 | do_vfp_sp_conv_16 (void) | |
10820 | { | |
10821 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
10822 | vfp_conv (16); | |
10823 | } | |
10824 | ||
10825 | static void | |
10826 | do_vfp_dp_conv_16 (void) | |
10827 | { | |
10828 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
10829 | vfp_conv (16); | |
10830 | } | |
10831 | ||
10832 | static void | |
10833 | do_vfp_sp_conv_32 (void) | |
10834 | { | |
10835 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
10836 | vfp_conv (32); | |
10837 | } | |
10838 | ||
10839 | static void | |
10840 | do_vfp_dp_conv_32 (void) | |
10841 | { | |
10842 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
10843 | vfp_conv (32); | |
10844 | } | |
c19d1205 ZW |
10845 | \f |
10846 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 10847 | |
c19d1205 ZW |
10848 | static void |
10849 | do_fpa_cmp (void) | |
10850 | { | |
10851 | inst.instruction |= inst.operands[0].reg << 16; | |
10852 | inst.instruction |= inst.operands[1].reg; | |
10853 | } | |
b99bd4ef NC |
10854 | |
10855 | static void | |
c19d1205 | 10856 | do_fpa_ldmstm (void) |
b99bd4ef | 10857 | { |
c19d1205 ZW |
10858 | inst.instruction |= inst.operands[0].reg << 12; |
10859 | switch (inst.operands[1].imm) | |
10860 | { | |
10861 | case 1: inst.instruction |= CP_T_X; break; | |
10862 | case 2: inst.instruction |= CP_T_Y; break; | |
10863 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
10864 | case 4: break; | |
10865 | default: abort (); | |
10866 | } | |
b99bd4ef | 10867 | |
c19d1205 ZW |
10868 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
10869 | { | |
10870 | /* The instruction specified "ea" or "fd", so we can only accept | |
10871 | [Rn]{!}. The instruction does not really support stacking or | |
10872 | unstacking, so we have to emulate these by setting appropriate | |
10873 | bits and offsets. */ | |
e2b0ab59 AV |
10874 | constraint (inst.relocs[0].exp.X_op != O_constant |
10875 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 10876 | _("this instruction does not support indexing")); |
b99bd4ef | 10877 | |
c19d1205 | 10878 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
e2b0ab59 | 10879 | inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm; |
b99bd4ef | 10880 | |
c19d1205 | 10881 | if (!(inst.instruction & INDEX_UP)) |
e2b0ab59 | 10882 | inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number; |
b99bd4ef | 10883 | |
c19d1205 ZW |
10884 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
10885 | { | |
10886 | inst.operands[2].preind = 0; | |
10887 | inst.operands[2].postind = 1; | |
10888 | } | |
10889 | } | |
b99bd4ef | 10890 | |
c19d1205 | 10891 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 10892 | } |
c19d1205 ZW |
10893 | \f |
10894 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 10895 | |
c19d1205 ZW |
10896 | static void |
10897 | do_iwmmxt_tandorc (void) | |
10898 | { | |
10899 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
10900 | } | |
b99bd4ef | 10901 | |
c19d1205 ZW |
10902 | static void |
10903 | do_iwmmxt_textrc (void) | |
10904 | { | |
10905 | inst.instruction |= inst.operands[0].reg << 12; | |
10906 | inst.instruction |= inst.operands[1].imm; | |
10907 | } | |
b99bd4ef NC |
10908 | |
10909 | static void | |
c19d1205 | 10910 | do_iwmmxt_textrm (void) |
b99bd4ef | 10911 | { |
c19d1205 ZW |
10912 | inst.instruction |= inst.operands[0].reg << 12; |
10913 | inst.instruction |= inst.operands[1].reg << 16; | |
10914 | inst.instruction |= inst.operands[2].imm; | |
10915 | } | |
b99bd4ef | 10916 | |
c19d1205 ZW |
10917 | static void |
10918 | do_iwmmxt_tinsr (void) | |
10919 | { | |
10920 | inst.instruction |= inst.operands[0].reg << 16; | |
10921 | inst.instruction |= inst.operands[1].reg << 12; | |
10922 | inst.instruction |= inst.operands[2].imm; | |
10923 | } | |
b99bd4ef | 10924 | |
c19d1205 ZW |
10925 | static void |
10926 | do_iwmmxt_tmia (void) | |
10927 | { | |
10928 | inst.instruction |= inst.operands[0].reg << 5; | |
10929 | inst.instruction |= inst.operands[1].reg; | |
10930 | inst.instruction |= inst.operands[2].reg << 12; | |
10931 | } | |
b99bd4ef | 10932 | |
c19d1205 ZW |
10933 | static void |
10934 | do_iwmmxt_waligni (void) | |
10935 | { | |
10936 | inst.instruction |= inst.operands[0].reg << 12; | |
10937 | inst.instruction |= inst.operands[1].reg << 16; | |
10938 | inst.instruction |= inst.operands[2].reg; | |
10939 | inst.instruction |= inst.operands[3].imm << 20; | |
10940 | } | |
b99bd4ef | 10941 | |
2d447fca JM |
10942 | static void |
10943 | do_iwmmxt_wmerge (void) | |
10944 | { | |
10945 | inst.instruction |= inst.operands[0].reg << 12; | |
10946 | inst.instruction |= inst.operands[1].reg << 16; | |
10947 | inst.instruction |= inst.operands[2].reg; | |
10948 | inst.instruction |= inst.operands[3].imm << 21; | |
10949 | } | |
10950 | ||
c19d1205 ZW |
10951 | static void |
10952 | do_iwmmxt_wmov (void) | |
10953 | { | |
10954 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
10955 | inst.instruction |= inst.operands[0].reg << 12; | |
10956 | inst.instruction |= inst.operands[1].reg << 16; | |
10957 | inst.instruction |= inst.operands[1].reg; | |
10958 | } | |
b99bd4ef | 10959 | |
c19d1205 ZW |
10960 | static void |
10961 | do_iwmmxt_wldstbh (void) | |
10962 | { | |
8f06b2d8 | 10963 | int reloc; |
c19d1205 | 10964 | inst.instruction |= inst.operands[0].reg << 12; |
8f06b2d8 PB |
10965 | if (thumb_mode) |
10966 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
10967 | else | |
10968 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
10969 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
10970 | } |
10971 | ||
c19d1205 ZW |
10972 | static void |
10973 | do_iwmmxt_wldstw (void) | |
10974 | { | |
10975 | /* RIWR_RIWC clears .isreg for a control register. */ | |
10976 | if (!inst.operands[0].isreg) | |
10977 | { | |
10978 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
10979 | inst.instruction |= 0xf0000000; | |
10980 | } | |
b99bd4ef | 10981 | |
c19d1205 ZW |
10982 | inst.instruction |= inst.operands[0].reg << 12; |
10983 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
10984 | } | |
b99bd4ef NC |
10985 | |
10986 | static void | |
c19d1205 | 10987 | do_iwmmxt_wldstd (void) |
b99bd4ef | 10988 | { |
c19d1205 | 10989 | inst.instruction |= inst.operands[0].reg << 12; |
2d447fca JM |
10990 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2) |
10991 | && inst.operands[1].immisreg) | |
10992 | { | |
10993 | inst.instruction &= ~0x1a000ff; | |
eff0bc54 | 10994 | inst.instruction |= (0xfU << 28); |
2d447fca JM |
10995 | if (inst.operands[1].preind) |
10996 | inst.instruction |= PRE_INDEX; | |
10997 | if (!inst.operands[1].negative) | |
10998 | inst.instruction |= INDEX_UP; | |
10999 | if (inst.operands[1].writeback) | |
11000 | inst.instruction |= WRITE_BACK; | |
11001 | inst.instruction |= inst.operands[1].reg << 16; | |
e2b0ab59 | 11002 | inst.instruction |= inst.relocs[0].exp.X_add_number << 4; |
2d447fca JM |
11003 | inst.instruction |= inst.operands[1].imm; |
11004 | } | |
11005 | else | |
11006 | encode_arm_cp_address (1, TRUE, FALSE, 0); | |
c19d1205 | 11007 | } |
b99bd4ef | 11008 | |
c19d1205 ZW |
11009 | static void |
11010 | do_iwmmxt_wshufh (void) | |
11011 | { | |
11012 | inst.instruction |= inst.operands[0].reg << 12; | |
11013 | inst.instruction |= inst.operands[1].reg << 16; | |
11014 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
11015 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
11016 | } | |
b99bd4ef | 11017 | |
c19d1205 ZW |
11018 | static void |
11019 | do_iwmmxt_wzero (void) | |
11020 | { | |
11021 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
11022 | inst.instruction |= inst.operands[0].reg; | |
11023 | inst.instruction |= inst.operands[0].reg << 12; | |
11024 | inst.instruction |= inst.operands[0].reg << 16; | |
11025 | } | |
2d447fca JM |
11026 | |
11027 | static void | |
11028 | do_iwmmxt_wrwrwr_or_imm5 (void) | |
11029 | { | |
11030 | if (inst.operands[2].isreg) | |
11031 | do_rd_rn_rm (); | |
11032 | else { | |
11033 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2), | |
11034 | _("immediate operand requires iWMMXt2")); | |
11035 | do_rd_rn (); | |
11036 | if (inst.operands[2].imm == 0) | |
11037 | { | |
11038 | switch ((inst.instruction >> 20) & 0xf) | |
11039 | { | |
11040 | case 4: | |
11041 | case 5: | |
11042 | case 6: | |
5f4273c7 | 11043 | case 7: |
2d447fca JM |
11044 | /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */ |
11045 | inst.operands[2].imm = 16; | |
11046 | inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20); | |
11047 | break; | |
11048 | case 8: | |
11049 | case 9: | |
11050 | case 10: | |
11051 | case 11: | |
11052 | /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */ | |
11053 | inst.operands[2].imm = 32; | |
11054 | inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20); | |
11055 | break; | |
11056 | case 12: | |
11057 | case 13: | |
11058 | case 14: | |
11059 | case 15: | |
11060 | { | |
11061 | /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */ | |
11062 | unsigned long wrn; | |
11063 | wrn = (inst.instruction >> 16) & 0xf; | |
11064 | inst.instruction &= 0xff0fff0f; | |
11065 | inst.instruction |= wrn; | |
11066 | /* Bail out here; the instruction is now assembled. */ | |
11067 | return; | |
11068 | } | |
11069 | } | |
11070 | } | |
11071 | /* Map 32 -> 0, etc. */ | |
11072 | inst.operands[2].imm &= 0x1f; | |
eff0bc54 | 11073 | inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf); |
2d447fca JM |
11074 | } |
11075 | } | |
c19d1205 ZW |
11076 | \f |
11077 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
11078 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 11079 | |
c19d1205 | 11080 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 11081 | |
c19d1205 ZW |
11082 | static void |
11083 | do_mav_triple (void) | |
11084 | { | |
11085 | inst.instruction |= inst.operands[0].reg << 16; | |
11086 | inst.instruction |= inst.operands[1].reg; | |
11087 | inst.instruction |= inst.operands[2].reg << 12; | |
11088 | } | |
b99bd4ef | 11089 | |
c19d1205 ZW |
11090 | /* Insns like "foo W,X,Y,Z". |
11091 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 11092 | |
c19d1205 ZW |
11093 | static void |
11094 | do_mav_quad (void) | |
11095 | { | |
11096 | inst.instruction |= inst.operands[0].reg << 5; | |
11097 | inst.instruction |= inst.operands[1].reg << 12; | |
11098 | inst.instruction |= inst.operands[2].reg << 16; | |
11099 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
11100 | } |
11101 | ||
c19d1205 ZW |
11102 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
11103 | static void | |
11104 | do_mav_dspsc (void) | |
a737bd4d | 11105 | { |
c19d1205 ZW |
11106 | inst.instruction |= inst.operands[1].reg << 12; |
11107 | } | |
a737bd4d | 11108 | |
c19d1205 ZW |
11109 | /* Maverick shift immediate instructions. |
11110 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
11111 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 11112 | |
c19d1205 ZW |
11113 | static void |
11114 | do_mav_shift (void) | |
11115 | { | |
11116 | int imm = inst.operands[2].imm; | |
a737bd4d | 11117 | |
c19d1205 ZW |
11118 | inst.instruction |= inst.operands[0].reg << 12; |
11119 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 11120 | |
c19d1205 ZW |
11121 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
11122 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
11123 | Bit 4 should be 0. */ | |
11124 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 11125 | |
c19d1205 ZW |
11126 | inst.instruction |= imm; |
11127 | } | |
11128 | \f | |
11129 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 11130 | |
c19d1205 ZW |
11131 | /* Xscale multiply-accumulate (argument parse) |
11132 | MIAcc acc0,Rm,Rs | |
11133 | MIAPHcc acc0,Rm,Rs | |
11134 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 11135 | |
c19d1205 ZW |
11136 | static void |
11137 | do_xsc_mia (void) | |
11138 | { | |
11139 | inst.instruction |= inst.operands[1].reg; | |
11140 | inst.instruction |= inst.operands[2].reg << 12; | |
11141 | } | |
a737bd4d | 11142 | |
c19d1205 | 11143 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 11144 | |
c19d1205 | 11145 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 11146 | |
c19d1205 ZW |
11147 | static void |
11148 | do_xsc_mar (void) | |
11149 | { | |
11150 | inst.instruction |= inst.operands[1].reg << 12; | |
11151 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
11152 | } |
11153 | ||
c19d1205 | 11154 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 11155 | |
c19d1205 | 11156 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
11157 | |
11158 | static void | |
c19d1205 | 11159 | do_xsc_mra (void) |
b99bd4ef | 11160 | { |
c19d1205 ZW |
11161 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
11162 | inst.instruction |= inst.operands[0].reg << 12; | |
11163 | inst.instruction |= inst.operands[1].reg << 16; | |
11164 | } | |
11165 | \f | |
11166 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 11167 | |
c19d1205 ZW |
11168 | /* inst.operands[i] is a shifted-register operand; encode |
11169 | it into inst.instruction in the format used by Thumb32. */ | |
11170 | ||
11171 | static void | |
11172 | encode_thumb32_shifted_operand (int i) | |
11173 | { | |
e2b0ab59 | 11174 | unsigned int value = inst.relocs[0].exp.X_add_number; |
c19d1205 | 11175 | unsigned int shift = inst.operands[i].shift_kind; |
b99bd4ef | 11176 | |
9c3c69f2 PB |
11177 | constraint (inst.operands[i].immisreg, |
11178 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
11179 | inst.instruction |= inst.operands[i].reg; |
11180 | if (shift == SHIFT_RRX) | |
11181 | inst.instruction |= SHIFT_ROR << 4; | |
11182 | else | |
b99bd4ef | 11183 | { |
e2b0ab59 | 11184 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 ZW |
11185 | _("expression too complex")); |
11186 | ||
11187 | constraint (value > 32 | |
11188 | || (value == 32 && (shift == SHIFT_LSL | |
11189 | || shift == SHIFT_ROR)), | |
11190 | _("shift expression is too large")); | |
11191 | ||
11192 | if (value == 0) | |
11193 | shift = SHIFT_LSL; | |
11194 | else if (value == 32) | |
11195 | value = 0; | |
11196 | ||
11197 | inst.instruction |= shift << 4; | |
11198 | inst.instruction |= (value & 0x1c) << 10; | |
11199 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 11200 | } |
c19d1205 | 11201 | } |
b99bd4ef | 11202 | |
b99bd4ef | 11203 | |
c19d1205 ZW |
11204 | /* inst.operands[i] was set up by parse_address. Encode it into a |
11205 | Thumb32 format load or store instruction. Reject forms that cannot | |
11206 | be used with such instructions. If is_t is true, reject forms that | |
11207 | cannot be used with a T instruction; if is_d is true, reject forms | |
5be8be5d DG |
11208 | that cannot be used with a D instruction. If it is a store insn, |
11209 | reject PC in Rn. */ | |
b99bd4ef | 11210 | |
c19d1205 ZW |
11211 | static void |
11212 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
11213 | { | |
5be8be5d | 11214 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
c19d1205 ZW |
11215 | |
11216 | constraint (!inst.operands[i].isreg, | |
53365c0d | 11217 | _("Instruction does not support =N addresses")); |
b99bd4ef | 11218 | |
c19d1205 ZW |
11219 | inst.instruction |= inst.operands[i].reg << 16; |
11220 | if (inst.operands[i].immisreg) | |
b99bd4ef | 11221 | { |
5be8be5d | 11222 | constraint (is_pc, BAD_PC_ADDRESSING); |
c19d1205 ZW |
11223 | constraint (is_t || is_d, _("cannot use register index with this instruction")); |
11224 | constraint (inst.operands[i].negative, | |
11225 | _("Thumb does not support negative register indexing")); | |
11226 | constraint (inst.operands[i].postind, | |
11227 | _("Thumb does not support register post-indexing")); | |
11228 | constraint (inst.operands[i].writeback, | |
11229 | _("Thumb does not support register indexing with writeback")); | |
11230 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
11231 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 11232 | |
f40d1643 | 11233 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 11234 | if (inst.operands[i].shifted) |
b99bd4ef | 11235 | { |
e2b0ab59 | 11236 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 | 11237 | _("expression too complex")); |
e2b0ab59 AV |
11238 | constraint (inst.relocs[0].exp.X_add_number < 0 |
11239 | || inst.relocs[0].exp.X_add_number > 3, | |
c19d1205 | 11240 | _("shift out of range")); |
e2b0ab59 | 11241 | inst.instruction |= inst.relocs[0].exp.X_add_number << 4; |
c19d1205 | 11242 | } |
e2b0ab59 | 11243 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
c19d1205 ZW |
11244 | } |
11245 | else if (inst.operands[i].preind) | |
11246 | { | |
5be8be5d | 11247 | constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK); |
f40d1643 | 11248 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 | 11249 | _("cannot use writeback with this instruction")); |
4755303e WN |
11250 | constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0), |
11251 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
11252 | |
11253 | if (is_d) | |
11254 | { | |
11255 | inst.instruction |= 0x01000000; | |
11256 | if (inst.operands[i].writeback) | |
11257 | inst.instruction |= 0x00200000; | |
b99bd4ef | 11258 | } |
c19d1205 | 11259 | else |
b99bd4ef | 11260 | { |
c19d1205 ZW |
11261 | inst.instruction |= 0x00000c00; |
11262 | if (inst.operands[i].writeback) | |
11263 | inst.instruction |= 0x00000100; | |
b99bd4ef | 11264 | } |
e2b0ab59 | 11265 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 11266 | } |
c19d1205 | 11267 | else if (inst.operands[i].postind) |
b99bd4ef | 11268 | { |
9c2799c2 | 11269 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
11270 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); |
11271 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
11272 | ||
11273 | if (is_d) | |
11274 | inst.instruction |= 0x00200000; | |
11275 | else | |
11276 | inst.instruction |= 0x00000900; | |
e2b0ab59 | 11277 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
c19d1205 ZW |
11278 | } |
11279 | else /* unindexed - only for coprocessor */ | |
11280 | inst.error = _("instruction does not accept unindexed addressing"); | |
11281 | } | |
11282 | ||
e39c1607 | 11283 | /* Table of Thumb instructions which exist in 16- and/or 32-bit |
c19d1205 ZW |
11284 | encodings (the latter only in post-V6T2 cores). The index is the |
11285 | value used in the insns table below. When there is more than one | |
11286 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
11287 | holds variant (1). |
11288 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 | 11289 | #define T16_32_TAB \ |
21d799b5 NC |
11290 | X(_adc, 4140, eb400000), \ |
11291 | X(_adcs, 4140, eb500000), \ | |
11292 | X(_add, 1c00, eb000000), \ | |
11293 | X(_adds, 1c00, eb100000), \ | |
11294 | X(_addi, 0000, f1000000), \ | |
11295 | X(_addis, 0000, f1100000), \ | |
11296 | X(_add_pc,000f, f20f0000), \ | |
11297 | X(_add_sp,000d, f10d0000), \ | |
11298 | X(_adr, 000f, f20f0000), \ | |
11299 | X(_and, 4000, ea000000), \ | |
11300 | X(_ands, 4000, ea100000), \ | |
11301 | X(_asr, 1000, fa40f000), \ | |
11302 | X(_asrs, 1000, fa50f000), \ | |
11303 | X(_b, e000, f000b000), \ | |
11304 | X(_bcond, d000, f0008000), \ | |
4389b29a | 11305 | X(_bf, 0000, f040e001), \ |
f6b2b12d | 11306 | X(_bfcsel,0000, f000e001), \ |
f1c7f421 | 11307 | X(_bfx, 0000, f060e001), \ |
65d1bc05 | 11308 | X(_bfl, 0000, f000c001), \ |
f1c7f421 | 11309 | X(_bflx, 0000, f070e001), \ |
21d799b5 NC |
11310 | X(_bic, 4380, ea200000), \ |
11311 | X(_bics, 4380, ea300000), \ | |
e39c1607 SD |
11312 | X(_cinc, 0000, ea509000), \ |
11313 | X(_cinv, 0000, ea50a000), \ | |
21d799b5 NC |
11314 | X(_cmn, 42c0, eb100f00), \ |
11315 | X(_cmp, 2800, ebb00f00), \ | |
e39c1607 | 11316 | X(_cneg, 0000, ea50b000), \ |
21d799b5 NC |
11317 | X(_cpsie, b660, f3af8400), \ |
11318 | X(_cpsid, b670, f3af8600), \ | |
11319 | X(_cpy, 4600, ea4f0000), \ | |
e39c1607 SD |
11320 | X(_csel, 0000, ea508000), \ |
11321 | X(_cset, 0000, ea5f900f), \ | |
11322 | X(_csetm, 0000, ea5fa00f), \ | |
11323 | X(_csinc, 0000, ea509000), \ | |
11324 | X(_csinv, 0000, ea50a000), \ | |
11325 | X(_csneg, 0000, ea50b000), \ | |
21d799b5 | 11326 | X(_dec_sp,80dd, f1ad0d00), \ |
60f993ce | 11327 | X(_dls, 0000, f040e001), \ |
1f6234a3 | 11328 | X(_dlstp, 0000, f000e001), \ |
21d799b5 NC |
11329 | X(_eor, 4040, ea800000), \ |
11330 | X(_eors, 4040, ea900000), \ | |
11331 | X(_inc_sp,00dd, f10d0d00), \ | |
1f6234a3 | 11332 | X(_lctp, 0000, f00fe001), \ |
21d799b5 NC |
11333 | X(_ldmia, c800, e8900000), \ |
11334 | X(_ldr, 6800, f8500000), \ | |
11335 | X(_ldrb, 7800, f8100000), \ | |
11336 | X(_ldrh, 8800, f8300000), \ | |
11337 | X(_ldrsb, 5600, f9100000), \ | |
11338 | X(_ldrsh, 5e00, f9300000), \ | |
11339 | X(_ldr_pc,4800, f85f0000), \ | |
11340 | X(_ldr_pc2,4800, f85f0000), \ | |
11341 | X(_ldr_sp,9800, f85d0000), \ | |
60f993ce | 11342 | X(_le, 0000, f00fc001), \ |
1f6234a3 | 11343 | X(_letp, 0000, f01fc001), \ |
21d799b5 NC |
11344 | X(_lsl, 0000, fa00f000), \ |
11345 | X(_lsls, 0000, fa10f000), \ | |
11346 | X(_lsr, 0800, fa20f000), \ | |
11347 | X(_lsrs, 0800, fa30f000), \ | |
11348 | X(_mov, 2000, ea4f0000), \ | |
11349 | X(_movs, 2000, ea5f0000), \ | |
11350 | X(_mul, 4340, fb00f000), \ | |
11351 | X(_muls, 4340, ffffffff), /* no 32b muls */ \ | |
11352 | X(_mvn, 43c0, ea6f0000), \ | |
11353 | X(_mvns, 43c0, ea7f0000), \ | |
11354 | X(_neg, 4240, f1c00000), /* rsb #0 */ \ | |
11355 | X(_negs, 4240, f1d00000), /* rsbs #0 */ \ | |
11356 | X(_orr, 4300, ea400000), \ | |
11357 | X(_orrs, 4300, ea500000), \ | |
11358 | X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \ | |
11359 | X(_push, b400, e92d0000), /* stmdb sp!,... */ \ | |
11360 | X(_rev, ba00, fa90f080), \ | |
11361 | X(_rev16, ba40, fa90f090), \ | |
11362 | X(_revsh, bac0, fa90f0b0), \ | |
11363 | X(_ror, 41c0, fa60f000), \ | |
11364 | X(_rors, 41c0, fa70f000), \ | |
11365 | X(_sbc, 4180, eb600000), \ | |
11366 | X(_sbcs, 4180, eb700000), \ | |
11367 | X(_stmia, c000, e8800000), \ | |
11368 | X(_str, 6000, f8400000), \ | |
11369 | X(_strb, 7000, f8000000), \ | |
11370 | X(_strh, 8000, f8200000), \ | |
11371 | X(_str_sp,9000, f84d0000), \ | |
11372 | X(_sub, 1e00, eba00000), \ | |
11373 | X(_subs, 1e00, ebb00000), \ | |
11374 | X(_subi, 8000, f1a00000), \ | |
11375 | X(_subis, 8000, f1b00000), \ | |
11376 | X(_sxtb, b240, fa4ff080), \ | |
11377 | X(_sxth, b200, fa0ff080), \ | |
11378 | X(_tst, 4200, ea100f00), \ | |
11379 | X(_uxtb, b2c0, fa5ff080), \ | |
11380 | X(_uxth, b280, fa1ff080), \ | |
11381 | X(_nop, bf00, f3af8000), \ | |
11382 | X(_yield, bf10, f3af8001), \ | |
11383 | X(_wfe, bf20, f3af8002), \ | |
11384 | X(_wfi, bf30, f3af8003), \ | |
60f993ce | 11385 | X(_wls, 0000, f040c001), \ |
1f6234a3 | 11386 | X(_wlstp, 0000, f000c001), \ |
53c4b28b | 11387 | X(_sev, bf40, f3af8004), \ |
74db7efb NC |
11388 | X(_sevl, bf50, f3af8005), \ |
11389 | X(_udf, de00, f7f0a000) | |
c19d1205 ZW |
11390 | |
11391 | /* To catch errors in encoding functions, the codes are all offset by | |
11392 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
11393 | as 16-bit instructions. */ | |
21d799b5 | 11394 | #define X(a,b,c) T_MNEM##a |
c19d1205 ZW |
11395 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; |
11396 | #undef X | |
11397 | ||
11398 | #define X(a,b,c) 0x##b | |
11399 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
11400 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
11401 | #undef X | |
11402 | ||
11403 | #define X(a,b,c) 0x##c | |
11404 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
c921be7d NC |
11405 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) |
11406 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
c19d1205 ZW |
11407 | #undef X |
11408 | #undef T16_32_TAB | |
11409 | ||
11410 | /* Thumb instruction encoders, in alphabetical order. */ | |
11411 | ||
92e90b6e | 11412 | /* ADDW or SUBW. */ |
c921be7d | 11413 | |
92e90b6e PB |
11414 | static void |
11415 | do_t_add_sub_w (void) | |
11416 | { | |
11417 | int Rd, Rn; | |
11418 | ||
11419 | Rd = inst.operands[0].reg; | |
11420 | Rn = inst.operands[1].reg; | |
11421 | ||
539d4391 NC |
11422 | /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this |
11423 | is the SP-{plus,minus}-immediate form of the instruction. */ | |
11424 | if (Rn == REG_SP) | |
11425 | constraint (Rd == REG_PC, BAD_PC); | |
11426 | else | |
11427 | reject_bad_reg (Rd); | |
fdfde340 | 11428 | |
92e90b6e | 11429 | inst.instruction |= (Rn << 16) | (Rd << 8); |
e2b0ab59 | 11430 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12; |
92e90b6e PB |
11431 | } |
11432 | ||
c19d1205 | 11433 | /* Parse an add or subtract instruction. We get here with inst.instruction |
33eaf5de | 11434 | equaling any of THUMB_OPCODE_add, adds, sub, or subs. */ |
c19d1205 ZW |
11435 | |
11436 | static void | |
11437 | do_t_add_sub (void) | |
11438 | { | |
11439 | int Rd, Rs, Rn; | |
11440 | ||
11441 | Rd = inst.operands[0].reg; | |
11442 | Rs = (inst.operands[1].present | |
11443 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
11444 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
11445 | ||
e07e6e58 | 11446 | if (Rd == REG_PC) |
5ee91343 | 11447 | set_pred_insn_type_last (); |
e07e6e58 | 11448 | |
c19d1205 ZW |
11449 | if (unified_syntax) |
11450 | { | |
0110f2b8 PB |
11451 | bfd_boolean flags; |
11452 | bfd_boolean narrow; | |
11453 | int opcode; | |
11454 | ||
11455 | flags = (inst.instruction == T_MNEM_adds | |
11456 | || inst.instruction == T_MNEM_subs); | |
11457 | if (flags) | |
5ee91343 | 11458 | narrow = !in_pred_block (); |
0110f2b8 | 11459 | else |
5ee91343 | 11460 | narrow = in_pred_block (); |
c19d1205 | 11461 | if (!inst.operands[2].isreg) |
b99bd4ef | 11462 | { |
16805f35 PB |
11463 | int add; |
11464 | ||
5c8ed6a4 JW |
11465 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
11466 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
fdfde340 | 11467 | |
16805f35 PB |
11468 | add = (inst.instruction == T_MNEM_add |
11469 | || inst.instruction == T_MNEM_adds); | |
0110f2b8 PB |
11470 | opcode = 0; |
11471 | if (inst.size_req != 4) | |
11472 | { | |
0110f2b8 | 11473 | /* Attempt to use a narrow opcode, with relaxation if |
477330fc | 11474 | appropriate. */ |
0110f2b8 PB |
11475 | if (Rd == REG_SP && Rs == REG_SP && !flags) |
11476 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
11477 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
11478 | opcode = T_MNEM_add_sp; | |
11479 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
11480 | opcode = T_MNEM_add_pc; | |
11481 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
11482 | { | |
11483 | if (flags) | |
11484 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
11485 | else | |
11486 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
11487 | } | |
11488 | if (opcode) | |
11489 | { | |
11490 | inst.instruction = THUMB_OP16(opcode); | |
11491 | inst.instruction |= (Rd << 4) | Rs; | |
e2b0ab59 AV |
11492 | if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
11493 | || (inst.relocs[0].type | |
11494 | > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)) | |
a9f02af8 MG |
11495 | { |
11496 | if (inst.size_req == 2) | |
e2b0ab59 | 11497 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD; |
a9f02af8 MG |
11498 | else |
11499 | inst.relax = opcode; | |
11500 | } | |
0110f2b8 PB |
11501 | } |
11502 | else | |
11503 | constraint (inst.size_req == 2, BAD_HIREG); | |
11504 | } | |
11505 | if (inst.size_req == 4 | |
11506 | || (inst.size_req != 2 && !opcode)) | |
11507 | { | |
e2b0ab59 AV |
11508 | constraint ((inst.relocs[0].type |
11509 | >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC) | |
11510 | && (inst.relocs[0].type | |
11511 | <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) , | |
a9f02af8 | 11512 | THUMB1_RELOC_ONLY); |
efd81785 PB |
11513 | if (Rd == REG_PC) |
11514 | { | |
fdfde340 | 11515 | constraint (add, BAD_PC); |
efd81785 PB |
11516 | constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs, |
11517 | _("only SUBS PC, LR, #const allowed")); | |
e2b0ab59 | 11518 | constraint (inst.relocs[0].exp.X_op != O_constant, |
efd81785 | 11519 | _("expression too complex")); |
e2b0ab59 AV |
11520 | constraint (inst.relocs[0].exp.X_add_number < 0 |
11521 | || inst.relocs[0].exp.X_add_number > 0xff, | |
efd81785 PB |
11522 | _("immediate value out of range")); |
11523 | inst.instruction = T2_SUBS_PC_LR | |
e2b0ab59 AV |
11524 | | inst.relocs[0].exp.X_add_number; |
11525 | inst.relocs[0].type = BFD_RELOC_UNUSED; | |
efd81785 PB |
11526 | return; |
11527 | } | |
11528 | else if (Rs == REG_PC) | |
16805f35 PB |
11529 | { |
11530 | /* Always use addw/subw. */ | |
11531 | inst.instruction = add ? 0xf20f0000 : 0xf2af0000; | |
e2b0ab59 | 11532 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12; |
16805f35 PB |
11533 | } |
11534 | else | |
11535 | { | |
11536 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11537 | inst.instruction = (inst.instruction & 0xe1ffffff) | |
11538 | | 0x10000000; | |
11539 | if (flags) | |
e2b0ab59 | 11540 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
16805f35 | 11541 | else |
e2b0ab59 | 11542 | inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM; |
16805f35 | 11543 | } |
dc4503c6 PB |
11544 | inst.instruction |= Rd << 8; |
11545 | inst.instruction |= Rs << 16; | |
0110f2b8 | 11546 | } |
b99bd4ef | 11547 | } |
c19d1205 ZW |
11548 | else |
11549 | { | |
e2b0ab59 | 11550 | unsigned int value = inst.relocs[0].exp.X_add_number; |
5f4cb198 NC |
11551 | unsigned int shift = inst.operands[2].shift_kind; |
11552 | ||
c19d1205 ZW |
11553 | Rn = inst.operands[2].reg; |
11554 | /* See if we can do this with a 16-bit instruction. */ | |
11555 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
11556 | { | |
e27ec89e PB |
11557 | if (Rd > 7 || Rs > 7 || Rn > 7) |
11558 | narrow = FALSE; | |
11559 | ||
11560 | if (narrow) | |
c19d1205 | 11561 | { |
e27ec89e PB |
11562 | inst.instruction = ((inst.instruction == T_MNEM_adds |
11563 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
11564 | ? T_OPCODE_ADD_R3 |
11565 | : T_OPCODE_SUB_R3); | |
11566 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
11567 | return; | |
11568 | } | |
b99bd4ef | 11569 | |
7e806470 | 11570 | if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn)) |
c19d1205 | 11571 | { |
7e806470 PB |
11572 | /* Thumb-1 cores (except v6-M) require at least one high |
11573 | register in a narrow non flag setting add. */ | |
11574 | if (Rd > 7 || Rn > 7 | |
11575 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2) | |
11576 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr)) | |
c19d1205 | 11577 | { |
7e806470 PB |
11578 | if (Rd == Rn) |
11579 | { | |
11580 | Rn = Rs; | |
11581 | Rs = Rd; | |
11582 | } | |
c19d1205 ZW |
11583 | inst.instruction = T_OPCODE_ADD_HI; |
11584 | inst.instruction |= (Rd & 8) << 4; | |
11585 | inst.instruction |= (Rd & 7); | |
11586 | inst.instruction |= Rn << 3; | |
11587 | return; | |
11588 | } | |
c19d1205 ZW |
11589 | } |
11590 | } | |
c921be7d | 11591 | |
fdfde340 | 11592 | constraint (Rd == REG_PC, BAD_PC); |
5c8ed6a4 JW |
11593 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
11594 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
fdfde340 JM |
11595 | constraint (Rs == REG_PC, BAD_PC); |
11596 | reject_bad_reg (Rn); | |
11597 | ||
c19d1205 ZW |
11598 | /* If we get here, it can't be done in 16 bits. */ |
11599 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
11600 | _("shift must be constant")); | |
11601 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11602 | inst.instruction |= Rd << 8; | |
11603 | inst.instruction |= Rs << 16; | |
5f4cb198 NC |
11604 | constraint (Rd == REG_SP && Rs == REG_SP && value > 3, |
11605 | _("shift value over 3 not allowed in thumb mode")); | |
11606 | constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL, | |
11607 | _("only LSL shift allowed in thumb mode")); | |
c19d1205 ZW |
11608 | encode_thumb32_shifted_operand (2); |
11609 | } | |
11610 | } | |
11611 | else | |
11612 | { | |
11613 | constraint (inst.instruction == T_MNEM_adds | |
11614 | || inst.instruction == T_MNEM_subs, | |
11615 | BAD_THUMB32); | |
b99bd4ef | 11616 | |
c19d1205 | 11617 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 11618 | { |
c19d1205 ZW |
11619 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
11620 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
11621 | BAD_HIREG); | |
11622 | ||
11623 | inst.instruction = (inst.instruction == T_MNEM_add | |
11624 | ? 0x0000 : 0x8000); | |
11625 | inst.instruction |= (Rd << 4) | Rs; | |
e2b0ab59 | 11626 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD; |
b99bd4ef NC |
11627 | return; |
11628 | } | |
11629 | ||
c19d1205 ZW |
11630 | Rn = inst.operands[2].reg; |
11631 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 11632 | |
c19d1205 ZW |
11633 | /* We now have Rd, Rs, and Rn set to registers. */ |
11634 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 11635 | { |
c19d1205 ZW |
11636 | /* Can't do this for SUB. */ |
11637 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
11638 | inst.instruction = T_OPCODE_ADD_HI; | |
11639 | inst.instruction |= (Rd & 8) << 4; | |
11640 | inst.instruction |= (Rd & 7); | |
11641 | if (Rs == Rd) | |
11642 | inst.instruction |= Rn << 3; | |
11643 | else if (Rn == Rd) | |
11644 | inst.instruction |= Rs << 3; | |
11645 | else | |
11646 | constraint (1, _("dest must overlap one source register")); | |
11647 | } | |
11648 | else | |
11649 | { | |
11650 | inst.instruction = (inst.instruction == T_MNEM_add | |
11651 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
11652 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 11653 | } |
b99bd4ef | 11654 | } |
b99bd4ef NC |
11655 | } |
11656 | ||
c19d1205 ZW |
11657 | static void |
11658 | do_t_adr (void) | |
11659 | { | |
fdfde340 JM |
11660 | unsigned Rd; |
11661 | ||
11662 | Rd = inst.operands[0].reg; | |
11663 | reject_bad_reg (Rd); | |
11664 | ||
11665 | if (unified_syntax && inst.size_req == 0 && Rd <= 7) | |
0110f2b8 PB |
11666 | { |
11667 | /* Defer to section relaxation. */ | |
11668 | inst.relax = inst.instruction; | |
11669 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 | 11670 | inst.instruction |= Rd << 4; |
0110f2b8 PB |
11671 | } |
11672 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 11673 | { |
0110f2b8 | 11674 | /* Generate a 32-bit opcode. */ |
e9f89963 | 11675 | inst.instruction = THUMB_OP32 (inst.instruction); |
fdfde340 | 11676 | inst.instruction |= Rd << 8; |
e2b0ab59 AV |
11677 | inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12; |
11678 | inst.relocs[0].pc_rel = 1; | |
e9f89963 PB |
11679 | } |
11680 | else | |
11681 | { | |
0110f2b8 | 11682 | /* Generate a 16-bit opcode. */ |
e9f89963 | 11683 | inst.instruction = THUMB_OP16 (inst.instruction); |
e2b0ab59 AV |
11684 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD; |
11685 | inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */ | |
11686 | inst.relocs[0].pc_rel = 1; | |
fdfde340 | 11687 | inst.instruction |= Rd << 4; |
e9f89963 | 11688 | } |
52a86f84 | 11689 | |
e2b0ab59 AV |
11690 | if (inst.relocs[0].exp.X_op == O_symbol |
11691 | && inst.relocs[0].exp.X_add_symbol != NULL | |
11692 | && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol) | |
11693 | && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol)) | |
11694 | inst.relocs[0].exp.X_add_number += 1; | |
c19d1205 | 11695 | } |
b99bd4ef | 11696 | |
c19d1205 ZW |
11697 | /* Arithmetic instructions for which there is just one 16-bit |
11698 | instruction encoding, and it allows only two low registers. | |
11699 | For maximal compatibility with ARM syntax, we allow three register | |
11700 | operands even when Thumb-32 instructions are not available, as long | |
11701 | as the first two are identical. For instance, both "sbc r0,r1" and | |
11702 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 11703 | static void |
c19d1205 | 11704 | do_t_arit3 (void) |
b99bd4ef | 11705 | { |
c19d1205 | 11706 | int Rd, Rs, Rn; |
b99bd4ef | 11707 | |
c19d1205 ZW |
11708 | Rd = inst.operands[0].reg; |
11709 | Rs = (inst.operands[1].present | |
11710 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
11711 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
11712 | Rn = inst.operands[2].reg; | |
b99bd4ef | 11713 | |
fdfde340 JM |
11714 | reject_bad_reg (Rd); |
11715 | reject_bad_reg (Rs); | |
11716 | if (inst.operands[2].isreg) | |
11717 | reject_bad_reg (Rn); | |
11718 | ||
c19d1205 | 11719 | if (unified_syntax) |
b99bd4ef | 11720 | { |
c19d1205 ZW |
11721 | if (!inst.operands[2].isreg) |
11722 | { | |
11723 | /* For an immediate, we always generate a 32-bit opcode; | |
11724 | section relaxation will shrink it later if possible. */ | |
11725 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11726 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
11727 | inst.instruction |= Rd << 8; | |
11728 | inst.instruction |= Rs << 16; | |
e2b0ab59 | 11729 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
c19d1205 ZW |
11730 | } |
11731 | else | |
11732 | { | |
e27ec89e PB |
11733 | bfd_boolean narrow; |
11734 | ||
c19d1205 | 11735 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 11736 | if (THUMB_SETS_FLAGS (inst.instruction)) |
5ee91343 | 11737 | narrow = !in_pred_block (); |
e27ec89e | 11738 | else |
5ee91343 | 11739 | narrow = in_pred_block (); |
e27ec89e PB |
11740 | |
11741 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
11742 | narrow = FALSE; | |
11743 | if (inst.operands[2].shifted) | |
11744 | narrow = FALSE; | |
11745 | if (inst.size_req == 4) | |
11746 | narrow = FALSE; | |
11747 | ||
11748 | if (narrow | |
c19d1205 ZW |
11749 | && Rd == Rs) |
11750 | { | |
11751 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11752 | inst.instruction |= Rd; | |
11753 | inst.instruction |= Rn << 3; | |
11754 | return; | |
11755 | } | |
b99bd4ef | 11756 | |
c19d1205 ZW |
11757 | /* If we get here, it can't be done in 16 bits. */ |
11758 | constraint (inst.operands[2].shifted | |
11759 | && inst.operands[2].immisreg, | |
11760 | _("shift must be constant")); | |
11761 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11762 | inst.instruction |= Rd << 8; | |
11763 | inst.instruction |= Rs << 16; | |
11764 | encode_thumb32_shifted_operand (2); | |
11765 | } | |
a737bd4d | 11766 | } |
c19d1205 | 11767 | else |
b99bd4ef | 11768 | { |
c19d1205 ZW |
11769 | /* On its face this is a lie - the instruction does set the |
11770 | flags. However, the only supported mnemonic in this mode | |
11771 | says it doesn't. */ | |
11772 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 11773 | |
c19d1205 ZW |
11774 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
11775 | _("unshifted register required")); | |
11776 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
11777 | constraint (Rd != Rs, | |
11778 | _("dest and source1 must be the same register")); | |
a737bd4d | 11779 | |
c19d1205 ZW |
11780 | inst.instruction = THUMB_OP16 (inst.instruction); |
11781 | inst.instruction |= Rd; | |
11782 | inst.instruction |= Rn << 3; | |
b99bd4ef | 11783 | } |
a737bd4d | 11784 | } |
b99bd4ef | 11785 | |
c19d1205 ZW |
11786 | /* Similarly, but for instructions where the arithmetic operation is |
11787 | commutative, so we can allow either of them to be different from | |
11788 | the destination operand in a 16-bit instruction. For instance, all | |
11789 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
11790 | accepted. */ | |
11791 | static void | |
11792 | do_t_arit3c (void) | |
a737bd4d | 11793 | { |
c19d1205 | 11794 | int Rd, Rs, Rn; |
b99bd4ef | 11795 | |
c19d1205 ZW |
11796 | Rd = inst.operands[0].reg; |
11797 | Rs = (inst.operands[1].present | |
11798 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
11799 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
11800 | Rn = inst.operands[2].reg; | |
c921be7d | 11801 | |
fdfde340 JM |
11802 | reject_bad_reg (Rd); |
11803 | reject_bad_reg (Rs); | |
11804 | if (inst.operands[2].isreg) | |
11805 | reject_bad_reg (Rn); | |
a737bd4d | 11806 | |
c19d1205 | 11807 | if (unified_syntax) |
a737bd4d | 11808 | { |
c19d1205 | 11809 | if (!inst.operands[2].isreg) |
b99bd4ef | 11810 | { |
c19d1205 ZW |
11811 | /* For an immediate, we always generate a 32-bit opcode; |
11812 | section relaxation will shrink it later if possible. */ | |
11813 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11814 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
11815 | inst.instruction |= Rd << 8; | |
11816 | inst.instruction |= Rs << 16; | |
e2b0ab59 | 11817 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 11818 | } |
c19d1205 | 11819 | else |
a737bd4d | 11820 | { |
e27ec89e PB |
11821 | bfd_boolean narrow; |
11822 | ||
c19d1205 | 11823 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 11824 | if (THUMB_SETS_FLAGS (inst.instruction)) |
5ee91343 | 11825 | narrow = !in_pred_block (); |
e27ec89e | 11826 | else |
5ee91343 | 11827 | narrow = in_pred_block (); |
e27ec89e PB |
11828 | |
11829 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
11830 | narrow = FALSE; | |
11831 | if (inst.operands[2].shifted) | |
11832 | narrow = FALSE; | |
11833 | if (inst.size_req == 4) | |
11834 | narrow = FALSE; | |
11835 | ||
11836 | if (narrow) | |
a737bd4d | 11837 | { |
c19d1205 | 11838 | if (Rd == Rs) |
a737bd4d | 11839 | { |
c19d1205 ZW |
11840 | inst.instruction = THUMB_OP16 (inst.instruction); |
11841 | inst.instruction |= Rd; | |
11842 | inst.instruction |= Rn << 3; | |
11843 | return; | |
a737bd4d | 11844 | } |
c19d1205 | 11845 | if (Rd == Rn) |
a737bd4d | 11846 | { |
c19d1205 ZW |
11847 | inst.instruction = THUMB_OP16 (inst.instruction); |
11848 | inst.instruction |= Rd; | |
11849 | inst.instruction |= Rs << 3; | |
11850 | return; | |
a737bd4d NC |
11851 | } |
11852 | } | |
c19d1205 ZW |
11853 | |
11854 | /* If we get here, it can't be done in 16 bits. */ | |
11855 | constraint (inst.operands[2].shifted | |
11856 | && inst.operands[2].immisreg, | |
11857 | _("shift must be constant")); | |
11858 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11859 | inst.instruction |= Rd << 8; | |
11860 | inst.instruction |= Rs << 16; | |
11861 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 11862 | } |
b99bd4ef | 11863 | } |
c19d1205 ZW |
11864 | else |
11865 | { | |
11866 | /* On its face this is a lie - the instruction does set the | |
11867 | flags. However, the only supported mnemonic in this mode | |
11868 | says it doesn't. */ | |
11869 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 11870 | |
c19d1205 ZW |
11871 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
11872 | _("unshifted register required")); | |
11873 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
11874 | ||
11875 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11876 | inst.instruction |= Rd; | |
11877 | ||
11878 | if (Rd == Rs) | |
11879 | inst.instruction |= Rn << 3; | |
11880 | else if (Rd == Rn) | |
11881 | inst.instruction |= Rs << 3; | |
11882 | else | |
11883 | constraint (1, _("dest must overlap one source register")); | |
11884 | } | |
a737bd4d NC |
11885 | } |
11886 | ||
c19d1205 ZW |
11887 | static void |
11888 | do_t_bfc (void) | |
a737bd4d | 11889 | { |
fdfde340 | 11890 | unsigned Rd; |
c19d1205 ZW |
11891 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
11892 | constraint (msb > 32, _("bit-field extends past end of register")); | |
11893 | /* The instruction encoding stores the LSB and MSB, | |
11894 | not the LSB and width. */ | |
fdfde340 JM |
11895 | Rd = inst.operands[0].reg; |
11896 | reject_bad_reg (Rd); | |
11897 | inst.instruction |= Rd << 8; | |
c19d1205 ZW |
11898 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; |
11899 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
11900 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
11901 | } |
11902 | ||
c19d1205 ZW |
11903 | static void |
11904 | do_t_bfi (void) | |
b99bd4ef | 11905 | { |
fdfde340 | 11906 | int Rd, Rn; |
c19d1205 | 11907 | unsigned int msb; |
b99bd4ef | 11908 | |
fdfde340 JM |
11909 | Rd = inst.operands[0].reg; |
11910 | reject_bad_reg (Rd); | |
11911 | ||
c19d1205 ZW |
11912 | /* #0 in second position is alternative syntax for bfc, which is |
11913 | the same instruction but with REG_PC in the Rm field. */ | |
11914 | if (!inst.operands[1].isreg) | |
fdfde340 JM |
11915 | Rn = REG_PC; |
11916 | else | |
11917 | { | |
11918 | Rn = inst.operands[1].reg; | |
11919 | reject_bad_reg (Rn); | |
11920 | } | |
b99bd4ef | 11921 | |
c19d1205 ZW |
11922 | msb = inst.operands[2].imm + inst.operands[3].imm; |
11923 | constraint (msb > 32, _("bit-field extends past end of register")); | |
11924 | /* The instruction encoding stores the LSB and MSB, | |
11925 | not the LSB and width. */ | |
fdfde340 JM |
11926 | inst.instruction |= Rd << 8; |
11927 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
11928 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
11929 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
11930 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
11931 | } |
11932 | ||
c19d1205 ZW |
11933 | static void |
11934 | do_t_bfx (void) | |
b99bd4ef | 11935 | { |
fdfde340 JM |
11936 | unsigned Rd, Rn; |
11937 | ||
11938 | Rd = inst.operands[0].reg; | |
11939 | Rn = inst.operands[1].reg; | |
11940 | ||
11941 | reject_bad_reg (Rd); | |
11942 | reject_bad_reg (Rn); | |
11943 | ||
c19d1205 ZW |
11944 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
11945 | _("bit-field extends past end of register")); | |
fdfde340 JM |
11946 | inst.instruction |= Rd << 8; |
11947 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
11948 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
11949 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
11950 | inst.instruction |= inst.operands[3].imm - 1; | |
11951 | } | |
b99bd4ef | 11952 | |
c19d1205 ZW |
11953 | /* ARM V5 Thumb BLX (argument parse) |
11954 | BLX <target_addr> which is BLX(1) | |
11955 | BLX <Rm> which is BLX(2) | |
11956 | Unfortunately, there are two different opcodes for this mnemonic. | |
11957 | So, the insns[].value is not used, and the code here zaps values | |
11958 | into inst.instruction. | |
b99bd4ef | 11959 | |
c19d1205 ZW |
11960 | ??? How to take advantage of the additional two bits of displacement |
11961 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 11962 | |
c19d1205 ZW |
11963 | static void |
11964 | do_t_blx (void) | |
11965 | { | |
5ee91343 | 11966 | set_pred_insn_type_last (); |
e07e6e58 | 11967 | |
c19d1205 | 11968 | if (inst.operands[0].isreg) |
fdfde340 JM |
11969 | { |
11970 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); | |
11971 | /* We have a register, so this is BLX(2). */ | |
11972 | inst.instruction |= inst.operands[0].reg << 3; | |
11973 | } | |
b99bd4ef NC |
11974 | else |
11975 | { | |
c19d1205 | 11976 | /* No register. This must be BLX(1). */ |
2fc8bdac | 11977 | inst.instruction = 0xf000e800; |
0855e32b | 11978 | encode_branch (BFD_RELOC_THUMB_PCREL_BLX); |
b99bd4ef NC |
11979 | } |
11980 | } | |
11981 | ||
c19d1205 ZW |
11982 | static void |
11983 | do_t_branch (void) | |
b99bd4ef | 11984 | { |
0110f2b8 | 11985 | int opcode; |
dfa9f0d5 | 11986 | int cond; |
2fe88214 | 11987 | bfd_reloc_code_real_type reloc; |
dfa9f0d5 | 11988 | |
e07e6e58 | 11989 | cond = inst.cond; |
5ee91343 | 11990 | set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); |
e07e6e58 | 11991 | |
5ee91343 | 11992 | if (in_pred_block ()) |
dfa9f0d5 PB |
11993 | { |
11994 | /* Conditional branches inside IT blocks are encoded as unconditional | |
477330fc | 11995 | branches. */ |
dfa9f0d5 | 11996 | cond = COND_ALWAYS; |
dfa9f0d5 PB |
11997 | } |
11998 | else | |
11999 | cond = inst.cond; | |
12000 | ||
12001 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
12002 | opcode = T_MNEM_bcond; |
12003 | else | |
12004 | opcode = inst.instruction; | |
12005 | ||
12d6b0b7 RS |
12006 | if (unified_syntax |
12007 | && (inst.size_req == 4 | |
10960bfb PB |
12008 | || (inst.size_req != 2 |
12009 | && (inst.operands[0].hasreloc | |
e2b0ab59 | 12010 | || inst.relocs[0].exp.X_op == O_constant)))) |
c19d1205 | 12011 | { |
0110f2b8 | 12012 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 12013 | if (cond == COND_ALWAYS) |
9ae92b05 | 12014 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
12015 | else |
12016 | { | |
ff8646ee TP |
12017 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2), |
12018 | _("selected architecture does not support " | |
12019 | "wide conditional branch instruction")); | |
12020 | ||
9c2799c2 | 12021 | gas_assert (cond != 0xF); |
dfa9f0d5 | 12022 | inst.instruction |= cond << 22; |
9ae92b05 | 12023 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH20; |
c19d1205 ZW |
12024 | } |
12025 | } | |
b99bd4ef NC |
12026 | else |
12027 | { | |
0110f2b8 | 12028 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 12029 | if (cond == COND_ALWAYS) |
9ae92b05 | 12030 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH12; |
c19d1205 | 12031 | else |
b99bd4ef | 12032 | { |
dfa9f0d5 | 12033 | inst.instruction |= cond << 8; |
9ae92b05 | 12034 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 12035 | } |
0110f2b8 PB |
12036 | /* Allow section relaxation. */ |
12037 | if (unified_syntax && inst.size_req != 2) | |
12038 | inst.relax = opcode; | |
b99bd4ef | 12039 | } |
e2b0ab59 AV |
12040 | inst.relocs[0].type = reloc; |
12041 | inst.relocs[0].pc_rel = 1; | |
b99bd4ef NC |
12042 | } |
12043 | ||
8884b720 | 12044 | /* Actually do the work for Thumb state bkpt and hlt. The only difference |
bacebabc | 12045 | between the two is the maximum immediate allowed - which is passed in |
8884b720 | 12046 | RANGE. */ |
b99bd4ef | 12047 | static void |
8884b720 | 12048 | do_t_bkpt_hlt1 (int range) |
b99bd4ef | 12049 | { |
dfa9f0d5 PB |
12050 | constraint (inst.cond != COND_ALWAYS, |
12051 | _("instruction is always unconditional")); | |
c19d1205 | 12052 | if (inst.operands[0].present) |
b99bd4ef | 12053 | { |
8884b720 | 12054 | constraint (inst.operands[0].imm > range, |
c19d1205 ZW |
12055 | _("immediate value out of range")); |
12056 | inst.instruction |= inst.operands[0].imm; | |
b99bd4ef | 12057 | } |
8884b720 | 12058 | |
5ee91343 | 12059 | set_pred_insn_type (NEUTRAL_IT_INSN); |
8884b720 MGD |
12060 | } |
12061 | ||
12062 | static void | |
12063 | do_t_hlt (void) | |
12064 | { | |
12065 | do_t_bkpt_hlt1 (63); | |
12066 | } | |
12067 | ||
12068 | static void | |
12069 | do_t_bkpt (void) | |
12070 | { | |
12071 | do_t_bkpt_hlt1 (255); | |
b99bd4ef NC |
12072 | } |
12073 | ||
12074 | static void | |
c19d1205 | 12075 | do_t_branch23 (void) |
b99bd4ef | 12076 | { |
5ee91343 | 12077 | set_pred_insn_type_last (); |
0855e32b | 12078 | encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23); |
fa94de6b | 12079 | |
0855e32b NS |
12080 | /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in |
12081 | this file. We used to simply ignore the PLT reloc type here -- | |
12082 | the branch encoding is now needed to deal with TLSCALL relocs. | |
12083 | So if we see a PLT reloc now, put it back to how it used to be to | |
12084 | keep the preexisting behaviour. */ | |
e2b0ab59 AV |
12085 | if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32) |
12086 | inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
90e4755a | 12087 | |
4343666d | 12088 | #if defined(OBJ_COFF) |
c19d1205 ZW |
12089 | /* If the destination of the branch is a defined symbol which does not have |
12090 | the THUMB_FUNC attribute, then we must be calling a function which has | |
12091 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
12092 | function and change the branch to refer to that function instead. */ | |
e2b0ab59 AV |
12093 | if ( inst.relocs[0].exp.X_op == O_symbol |
12094 | && inst.relocs[0].exp.X_add_symbol != NULL | |
12095 | && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol) | |
12096 | && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol)) | |
12097 | inst.relocs[0].exp.X_add_symbol | |
12098 | = find_real_start (inst.relocs[0].exp.X_add_symbol); | |
4343666d | 12099 | #endif |
90e4755a RE |
12100 | } |
12101 | ||
12102 | static void | |
c19d1205 | 12103 | do_t_bx (void) |
90e4755a | 12104 | { |
5ee91343 | 12105 | set_pred_insn_type_last (); |
c19d1205 ZW |
12106 | inst.instruction |= inst.operands[0].reg << 3; |
12107 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
12108 | should cause the alignment to be checked once it is known. This is | |
12109 | because BX PC only works if the instruction is word aligned. */ | |
12110 | } | |
90e4755a | 12111 | |
c19d1205 ZW |
12112 | static void |
12113 | do_t_bxj (void) | |
12114 | { | |
fdfde340 | 12115 | int Rm; |
90e4755a | 12116 | |
5ee91343 | 12117 | set_pred_insn_type_last (); |
fdfde340 JM |
12118 | Rm = inst.operands[0].reg; |
12119 | reject_bad_reg (Rm); | |
12120 | inst.instruction |= Rm << 16; | |
90e4755a RE |
12121 | } |
12122 | ||
12123 | static void | |
c19d1205 | 12124 | do_t_clz (void) |
90e4755a | 12125 | { |
fdfde340 JM |
12126 | unsigned Rd; |
12127 | unsigned Rm; | |
12128 | ||
12129 | Rd = inst.operands[0].reg; | |
12130 | Rm = inst.operands[1].reg; | |
12131 | ||
12132 | reject_bad_reg (Rd); | |
12133 | reject_bad_reg (Rm); | |
12134 | ||
12135 | inst.instruction |= Rd << 8; | |
12136 | inst.instruction |= Rm << 16; | |
12137 | inst.instruction |= Rm; | |
c19d1205 | 12138 | } |
90e4755a | 12139 | |
e39c1607 SD |
12140 | /* For the Armv8.1-M conditional instructions. */ |
12141 | static void | |
12142 | do_t_cond (void) | |
12143 | { | |
12144 | unsigned Rd, Rn, Rm; | |
12145 | signed int cond; | |
12146 | ||
12147 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
12148 | ||
12149 | Rd = inst.operands[0].reg; | |
12150 | switch (inst.instruction) | |
12151 | { | |
12152 | case T_MNEM_csinc: | |
12153 | case T_MNEM_csinv: | |
12154 | case T_MNEM_csneg: | |
12155 | case T_MNEM_csel: | |
12156 | Rn = inst.operands[1].reg; | |
12157 | Rm = inst.operands[2].reg; | |
12158 | cond = inst.operands[3].imm; | |
12159 | constraint (Rn == REG_SP, BAD_SP); | |
12160 | constraint (Rm == REG_SP, BAD_SP); | |
12161 | break; | |
12162 | ||
12163 | case T_MNEM_cinc: | |
12164 | case T_MNEM_cinv: | |
12165 | case T_MNEM_cneg: | |
12166 | Rn = inst.operands[1].reg; | |
12167 | cond = inst.operands[2].imm; | |
12168 | /* Invert the last bit to invert the cond. */ | |
12169 | cond = TOGGLE_BIT (cond, 0); | |
12170 | constraint (Rn == REG_SP, BAD_SP); | |
12171 | Rm = Rn; | |
12172 | break; | |
12173 | ||
12174 | case T_MNEM_csetm: | |
12175 | case T_MNEM_cset: | |
12176 | cond = inst.operands[1].imm; | |
12177 | /* Invert the last bit to invert the cond. */ | |
12178 | cond = TOGGLE_BIT (cond, 0); | |
12179 | Rn = REG_PC; | |
12180 | Rm = REG_PC; | |
12181 | break; | |
12182 | ||
12183 | default: abort (); | |
12184 | } | |
12185 | ||
12186 | set_pred_insn_type (OUTSIDE_PRED_INSN); | |
12187 | inst.instruction = THUMB_OP32 (inst.instruction); | |
12188 | inst.instruction |= Rd << 8; | |
12189 | inst.instruction |= Rn << 16; | |
12190 | inst.instruction |= Rm; | |
12191 | inst.instruction |= cond << 4; | |
12192 | } | |
12193 | ||
91d8b670 JG |
12194 | static void |
12195 | do_t_csdb (void) | |
12196 | { | |
5ee91343 | 12197 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
91d8b670 JG |
12198 | } |
12199 | ||
dfa9f0d5 PB |
12200 | static void |
12201 | do_t_cps (void) | |
12202 | { | |
5ee91343 | 12203 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
dfa9f0d5 PB |
12204 | inst.instruction |= inst.operands[0].imm; |
12205 | } | |
12206 | ||
c19d1205 ZW |
12207 | static void |
12208 | do_t_cpsi (void) | |
12209 | { | |
5ee91343 | 12210 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
c19d1205 | 12211 | if (unified_syntax |
62b3e311 PB |
12212 | && (inst.operands[1].present || inst.size_req == 4) |
12213 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 12214 | { |
c19d1205 ZW |
12215 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
12216 | inst.instruction = 0xf3af8000; | |
12217 | inst.instruction |= imod << 9; | |
12218 | inst.instruction |= inst.operands[0].imm << 5; | |
12219 | if (inst.operands[1].present) | |
12220 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 12221 | } |
c19d1205 | 12222 | else |
90e4755a | 12223 | { |
62b3e311 PB |
12224 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1) |
12225 | && (inst.operands[0].imm & 4), | |
12226 | _("selected processor does not support 'A' form " | |
12227 | "of this instruction")); | |
12228 | constraint (inst.operands[1].present || inst.size_req == 4, | |
c19d1205 ZW |
12229 | _("Thumb does not support the 2-argument " |
12230 | "form of this instruction")); | |
12231 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 12232 | } |
90e4755a RE |
12233 | } |
12234 | ||
c19d1205 ZW |
12235 | /* THUMB CPY instruction (argument parse). */ |
12236 | ||
90e4755a | 12237 | static void |
c19d1205 | 12238 | do_t_cpy (void) |
90e4755a | 12239 | { |
c19d1205 | 12240 | if (inst.size_req == 4) |
90e4755a | 12241 | { |
c19d1205 ZW |
12242 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
12243 | inst.instruction |= inst.operands[0].reg << 8; | |
12244 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 12245 | } |
c19d1205 | 12246 | else |
90e4755a | 12247 | { |
c19d1205 ZW |
12248 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
12249 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
12250 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 12251 | } |
90e4755a RE |
12252 | } |
12253 | ||
90e4755a | 12254 | static void |
25fe350b | 12255 | do_t_cbz (void) |
90e4755a | 12256 | { |
5ee91343 | 12257 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
c19d1205 ZW |
12258 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
12259 | inst.instruction |= inst.operands[0].reg; | |
e2b0ab59 AV |
12260 | inst.relocs[0].pc_rel = 1; |
12261 | inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
c19d1205 | 12262 | } |
90e4755a | 12263 | |
62b3e311 PB |
12264 | static void |
12265 | do_t_dbg (void) | |
12266 | { | |
12267 | inst.instruction |= inst.operands[0].imm; | |
12268 | } | |
12269 | ||
12270 | static void | |
12271 | do_t_div (void) | |
12272 | { | |
fdfde340 JM |
12273 | unsigned Rd, Rn, Rm; |
12274 | ||
12275 | Rd = inst.operands[0].reg; | |
12276 | Rn = (inst.operands[1].present | |
12277 | ? inst.operands[1].reg : Rd); | |
12278 | Rm = inst.operands[2].reg; | |
12279 | ||
12280 | reject_bad_reg (Rd); | |
12281 | reject_bad_reg (Rn); | |
12282 | reject_bad_reg (Rm); | |
12283 | ||
12284 | inst.instruction |= Rd << 8; | |
12285 | inst.instruction |= Rn << 16; | |
12286 | inst.instruction |= Rm; | |
62b3e311 PB |
12287 | } |
12288 | ||
c19d1205 ZW |
12289 | static void |
12290 | do_t_hint (void) | |
12291 | { | |
12292 | if (unified_syntax && inst.size_req == 4) | |
12293 | inst.instruction = THUMB_OP32 (inst.instruction); | |
12294 | else | |
12295 | inst.instruction = THUMB_OP16 (inst.instruction); | |
12296 | } | |
90e4755a | 12297 | |
c19d1205 ZW |
12298 | static void |
12299 | do_t_it (void) | |
12300 | { | |
12301 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 12302 | |
5ee91343 AV |
12303 | set_pred_insn_type (IT_INSN); |
12304 | now_pred.mask = (inst.instruction & 0xf) | 0x10; | |
12305 | now_pred.cc = cond; | |
12306 | now_pred.warn_deprecated = FALSE; | |
12307 | now_pred.type = SCALAR_PRED; | |
e27ec89e PB |
12308 | |
12309 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 12310 | if ((cond & 0x1) == 0x0) |
90e4755a | 12311 | { |
c19d1205 | 12312 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 12313 | |
c19d1205 | 12314 | if ((mask & 0x7) == 0) |
5a01bb1d MGD |
12315 | { |
12316 | /* No conversion needed. */ | |
5ee91343 | 12317 | now_pred.block_length = 1; |
5a01bb1d | 12318 | } |
c19d1205 | 12319 | else if ((mask & 0x3) == 0) |
5a01bb1d MGD |
12320 | { |
12321 | mask ^= 0x8; | |
5ee91343 | 12322 | now_pred.block_length = 2; |
5a01bb1d | 12323 | } |
e27ec89e | 12324 | else if ((mask & 0x1) == 0) |
5a01bb1d MGD |
12325 | { |
12326 | mask ^= 0xC; | |
5ee91343 | 12327 | now_pred.block_length = 3; |
5a01bb1d | 12328 | } |
c19d1205 | 12329 | else |
5a01bb1d MGD |
12330 | { |
12331 | mask ^= 0xE; | |
5ee91343 | 12332 | now_pred.block_length = 4; |
5a01bb1d | 12333 | } |
90e4755a | 12334 | |
e27ec89e PB |
12335 | inst.instruction &= 0xfff0; |
12336 | inst.instruction |= mask; | |
c19d1205 | 12337 | } |
90e4755a | 12338 | |
c19d1205 ZW |
12339 | inst.instruction |= cond << 4; |
12340 | } | |
90e4755a | 12341 | |
3c707909 PB |
12342 | /* Helper function used for both push/pop and ldm/stm. */ |
12343 | static void | |
4b5a202f AV |
12344 | encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask, |
12345 | bfd_boolean writeback) | |
3c707909 | 12346 | { |
4b5a202f | 12347 | bfd_boolean load, store; |
3c707909 | 12348 | |
4b5a202f AV |
12349 | gas_assert (base != -1 || !do_io); |
12350 | load = do_io && ((inst.instruction & (1 << 20)) != 0); | |
12351 | store = do_io && !load; | |
3c707909 PB |
12352 | |
12353 | if (mask & (1 << 13)) | |
12354 | inst.error = _("SP not allowed in register list"); | |
1e5b0379 | 12355 | |
4b5a202f | 12356 | if (do_io && (mask & (1 << base)) != 0 |
1e5b0379 NC |
12357 | && writeback) |
12358 | inst.error = _("having the base register in the register list when " | |
12359 | "using write back is UNPREDICTABLE"); | |
12360 | ||
3c707909 PB |
12361 | if (load) |
12362 | { | |
e07e6e58 | 12363 | if (mask & (1 << 15)) |
477330fc RM |
12364 | { |
12365 | if (mask & (1 << 14)) | |
12366 | inst.error = _("LR and PC should not both be in register list"); | |
12367 | else | |
5ee91343 | 12368 | set_pred_insn_type_last (); |
477330fc | 12369 | } |
3c707909 | 12370 | } |
4b5a202f | 12371 | else if (store) |
3c707909 PB |
12372 | { |
12373 | if (mask & (1 << 15)) | |
12374 | inst.error = _("PC not allowed in register list"); | |
3c707909 PB |
12375 | } |
12376 | ||
4b5a202f | 12377 | if (do_io && ((mask & (mask - 1)) == 0)) |
3c707909 PB |
12378 | { |
12379 | /* Single register transfers implemented as str/ldr. */ | |
12380 | if (writeback) | |
12381 | { | |
12382 | if (inst.instruction & (1 << 23)) | |
12383 | inst.instruction = 0x00000b04; /* ia! -> [base], #4 */ | |
12384 | else | |
12385 | inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */ | |
12386 | } | |
12387 | else | |
12388 | { | |
12389 | if (inst.instruction & (1 << 23)) | |
12390 | inst.instruction = 0x00800000; /* ia -> [base] */ | |
12391 | else | |
12392 | inst.instruction = 0x00000c04; /* db -> [base, #-4] */ | |
12393 | } | |
12394 | ||
12395 | inst.instruction |= 0xf8400000; | |
12396 | if (load) | |
12397 | inst.instruction |= 0x00100000; | |
12398 | ||
5f4273c7 | 12399 | mask = ffs (mask) - 1; |
3c707909 PB |
12400 | mask <<= 12; |
12401 | } | |
12402 | else if (writeback) | |
12403 | inst.instruction |= WRITE_BACK; | |
12404 | ||
12405 | inst.instruction |= mask; | |
4b5a202f AV |
12406 | if (do_io) |
12407 | inst.instruction |= base << 16; | |
3c707909 PB |
12408 | } |
12409 | ||
c19d1205 ZW |
12410 | static void |
12411 | do_t_ldmstm (void) | |
12412 | { | |
12413 | /* This really doesn't seem worth it. */ | |
e2b0ab59 | 12414 | constraint (inst.relocs[0].type != BFD_RELOC_UNUSED, |
c19d1205 ZW |
12415 | _("expression too complex")); |
12416 | constraint (inst.operands[1].writeback, | |
12417 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 12418 | |
c19d1205 ZW |
12419 | if (unified_syntax) |
12420 | { | |
3c707909 PB |
12421 | bfd_boolean narrow; |
12422 | unsigned mask; | |
12423 | ||
12424 | narrow = FALSE; | |
c19d1205 ZW |
12425 | /* See if we can use a 16-bit instruction. */ |
12426 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
12427 | && inst.size_req != 4 | |
3c707909 | 12428 | && !(inst.operands[1].imm & ~0xff)) |
90e4755a | 12429 | { |
3c707909 | 12430 | mask = 1 << inst.operands[0].reg; |
90e4755a | 12431 | |
eab4f823 | 12432 | if (inst.operands[0].reg <= 7) |
90e4755a | 12433 | { |
3c707909 | 12434 | if (inst.instruction == T_MNEM_stmia |
eab4f823 MGD |
12435 | ? inst.operands[0].writeback |
12436 | : (inst.operands[0].writeback | |
12437 | == !(inst.operands[1].imm & mask))) | |
477330fc | 12438 | { |
eab4f823 MGD |
12439 | if (inst.instruction == T_MNEM_stmia |
12440 | && (inst.operands[1].imm & mask) | |
12441 | && (inst.operands[1].imm & (mask - 1))) | |
12442 | as_warn (_("value stored for r%d is UNKNOWN"), | |
12443 | inst.operands[0].reg); | |
3c707909 | 12444 | |
eab4f823 MGD |
12445 | inst.instruction = THUMB_OP16 (inst.instruction); |
12446 | inst.instruction |= inst.operands[0].reg << 8; | |
12447 | inst.instruction |= inst.operands[1].imm; | |
12448 | narrow = TRUE; | |
12449 | } | |
12450 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
12451 | { | |
12452 | /* This means 1 register in reg list one of 3 situations: | |
12453 | 1. Instruction is stmia, but without writeback. | |
12454 | 2. lmdia without writeback, but with Rn not in | |
477330fc | 12455 | reglist. |
eab4f823 MGD |
12456 | 3. ldmia with writeback, but with Rn in reglist. |
12457 | Case 3 is UNPREDICTABLE behaviour, so we handle | |
12458 | case 1 and 2 which can be converted into a 16-bit | |
12459 | str or ldr. The SP cases are handled below. */ | |
12460 | unsigned long opcode; | |
12461 | /* First, record an error for Case 3. */ | |
12462 | if (inst.operands[1].imm & mask | |
12463 | && inst.operands[0].writeback) | |
fa94de6b | 12464 | inst.error = |
eab4f823 MGD |
12465 | _("having the base register in the register list when " |
12466 | "using write back is UNPREDICTABLE"); | |
fa94de6b RM |
12467 | |
12468 | opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str | |
eab4f823 MGD |
12469 | : T_MNEM_ldr); |
12470 | inst.instruction = THUMB_OP16 (opcode); | |
12471 | inst.instruction |= inst.operands[0].reg << 3; | |
12472 | inst.instruction |= (ffs (inst.operands[1].imm)-1); | |
12473 | narrow = TRUE; | |
12474 | } | |
90e4755a | 12475 | } |
eab4f823 | 12476 | else if (inst.operands[0] .reg == REG_SP) |
90e4755a | 12477 | { |
eab4f823 MGD |
12478 | if (inst.operands[0].writeback) |
12479 | { | |
fa94de6b | 12480 | inst.instruction = |
eab4f823 | 12481 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
477330fc | 12482 | ? T_MNEM_push : T_MNEM_pop); |
eab4f823 | 12483 | inst.instruction |= inst.operands[1].imm; |
477330fc | 12484 | narrow = TRUE; |
eab4f823 MGD |
12485 | } |
12486 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
12487 | { | |
fa94de6b | 12488 | inst.instruction = |
eab4f823 | 12489 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
477330fc | 12490 | ? T_MNEM_str_sp : T_MNEM_ldr_sp); |
eab4f823 | 12491 | inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8); |
477330fc | 12492 | narrow = TRUE; |
eab4f823 | 12493 | } |
90e4755a | 12494 | } |
3c707909 PB |
12495 | } |
12496 | ||
12497 | if (!narrow) | |
12498 | { | |
c19d1205 ZW |
12499 | if (inst.instruction < 0xffff) |
12500 | inst.instruction = THUMB_OP32 (inst.instruction); | |
3c707909 | 12501 | |
4b5a202f AV |
12502 | encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg, |
12503 | inst.operands[1].imm, | |
12504 | inst.operands[0].writeback); | |
90e4755a RE |
12505 | } |
12506 | } | |
c19d1205 | 12507 | else |
90e4755a | 12508 | { |
c19d1205 ZW |
12509 | constraint (inst.operands[0].reg > 7 |
12510 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
1198ca51 PB |
12511 | constraint (inst.instruction != T_MNEM_ldmia |
12512 | && inst.instruction != T_MNEM_stmia, | |
12513 | _("Thumb-2 instruction only valid in unified syntax")); | |
c19d1205 | 12514 | if (inst.instruction == T_MNEM_stmia) |
f03698e6 | 12515 | { |
c19d1205 ZW |
12516 | if (!inst.operands[0].writeback) |
12517 | as_warn (_("this instruction will write back the base register")); | |
12518 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
12519 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
1e5b0379 | 12520 | as_warn (_("value stored for r%d is UNKNOWN"), |
c19d1205 | 12521 | inst.operands[0].reg); |
f03698e6 | 12522 | } |
c19d1205 | 12523 | else |
90e4755a | 12524 | { |
c19d1205 ZW |
12525 | if (!inst.operands[0].writeback |
12526 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
12527 | as_warn (_("this instruction will write back the base register")); | |
12528 | else if (inst.operands[0].writeback | |
12529 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
12530 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
12531 | } |
12532 | ||
c19d1205 ZW |
12533 | inst.instruction = THUMB_OP16 (inst.instruction); |
12534 | inst.instruction |= inst.operands[0].reg << 8; | |
12535 | inst.instruction |= inst.operands[1].imm; | |
12536 | } | |
12537 | } | |
e28cd48c | 12538 | |
c19d1205 ZW |
12539 | static void |
12540 | do_t_ldrex (void) | |
12541 | { | |
12542 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
12543 | || inst.operands[1].postind || inst.operands[1].writeback | |
12544 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
12545 | || inst.operands[1].negative, | |
01cfc07f | 12546 | BAD_ADDR_MODE); |
e28cd48c | 12547 | |
5be8be5d DG |
12548 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
12549 | ||
c19d1205 ZW |
12550 | inst.instruction |= inst.operands[0].reg << 12; |
12551 | inst.instruction |= inst.operands[1].reg << 16; | |
e2b0ab59 | 12552 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8; |
c19d1205 | 12553 | } |
e28cd48c | 12554 | |
c19d1205 ZW |
12555 | static void |
12556 | do_t_ldrexd (void) | |
12557 | { | |
12558 | if (!inst.operands[1].present) | |
1cac9012 | 12559 | { |
c19d1205 ZW |
12560 | constraint (inst.operands[0].reg == REG_LR, |
12561 | _("r14 not allowed as first register " | |
12562 | "when second register is omitted")); | |
12563 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 12564 | } |
c19d1205 ZW |
12565 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
12566 | BAD_OVERLAP); | |
b99bd4ef | 12567 | |
c19d1205 ZW |
12568 | inst.instruction |= inst.operands[0].reg << 12; |
12569 | inst.instruction |= inst.operands[1].reg << 8; | |
12570 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
12571 | } |
12572 | ||
12573 | static void | |
c19d1205 | 12574 | do_t_ldst (void) |
b99bd4ef | 12575 | { |
0110f2b8 PB |
12576 | unsigned long opcode; |
12577 | int Rn; | |
12578 | ||
e07e6e58 NC |
12579 | if (inst.operands[0].isreg |
12580 | && !inst.operands[0].preind | |
12581 | && inst.operands[0].reg == REG_PC) | |
5ee91343 | 12582 | set_pred_insn_type_last (); |
e07e6e58 | 12583 | |
0110f2b8 | 12584 | opcode = inst.instruction; |
c19d1205 | 12585 | if (unified_syntax) |
b99bd4ef | 12586 | { |
53365c0d PB |
12587 | if (!inst.operands[1].isreg) |
12588 | { | |
12589 | if (opcode <= 0xffff) | |
12590 | inst.instruction = THUMB_OP32 (opcode); | |
8335d6aa | 12591 | if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE)) |
53365c0d PB |
12592 | return; |
12593 | } | |
0110f2b8 PB |
12594 | if (inst.operands[1].isreg |
12595 | && !inst.operands[1].writeback | |
c19d1205 ZW |
12596 | && !inst.operands[1].shifted && !inst.operands[1].postind |
12597 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
12598 | && opcode <= 0xffff |
12599 | && inst.size_req != 4) | |
c19d1205 | 12600 | { |
0110f2b8 PB |
12601 | /* Insn may have a 16-bit form. */ |
12602 | Rn = inst.operands[1].reg; | |
12603 | if (inst.operands[1].immisreg) | |
12604 | { | |
12605 | inst.instruction = THUMB_OP16 (opcode); | |
5f4273c7 | 12606 | /* [Rn, Rik] */ |
0110f2b8 PB |
12607 | if (Rn <= 7 && inst.operands[1].imm <= 7) |
12608 | goto op16; | |
5be8be5d DG |
12609 | else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str) |
12610 | reject_bad_reg (inst.operands[1].imm); | |
0110f2b8 PB |
12611 | } |
12612 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
12613 | && opcode != T_MNEM_ldrsb) | |
12614 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
12615 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
12616 | { | |
12617 | /* [Rn, #const] */ | |
12618 | if (Rn > 7) | |
12619 | { | |
12620 | if (Rn == REG_PC) | |
12621 | { | |
e2b0ab59 | 12622 | if (inst.relocs[0].pc_rel) |
0110f2b8 PB |
12623 | opcode = T_MNEM_ldr_pc2; |
12624 | else | |
12625 | opcode = T_MNEM_ldr_pc; | |
12626 | } | |
12627 | else | |
12628 | { | |
12629 | if (opcode == T_MNEM_ldr) | |
12630 | opcode = T_MNEM_ldr_sp; | |
12631 | else | |
12632 | opcode = T_MNEM_str_sp; | |
12633 | } | |
12634 | inst.instruction = inst.operands[0].reg << 8; | |
12635 | } | |
12636 | else | |
12637 | { | |
12638 | inst.instruction = inst.operands[0].reg; | |
12639 | inst.instruction |= inst.operands[1].reg << 3; | |
12640 | } | |
12641 | inst.instruction |= THUMB_OP16 (opcode); | |
12642 | if (inst.size_req == 2) | |
e2b0ab59 | 12643 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET; |
0110f2b8 PB |
12644 | else |
12645 | inst.relax = opcode; | |
12646 | return; | |
12647 | } | |
c19d1205 | 12648 | } |
0110f2b8 | 12649 | /* Definitely a 32-bit variant. */ |
5be8be5d | 12650 | |
8d67f500 NC |
12651 | /* Warning for Erratum 752419. */ |
12652 | if (opcode == T_MNEM_ldr | |
12653 | && inst.operands[0].reg == REG_SP | |
12654 | && inst.operands[1].writeback == 1 | |
12655 | && !inst.operands[1].immisreg) | |
12656 | { | |
12657 | if (no_cpu_selected () | |
12658 | || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7) | |
477330fc RM |
12659 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a) |
12660 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r))) | |
8d67f500 NC |
12661 | as_warn (_("This instruction may be unpredictable " |
12662 | "if executed on M-profile cores " | |
12663 | "with interrupts enabled.")); | |
12664 | } | |
12665 | ||
5be8be5d | 12666 | /* Do some validations regarding addressing modes. */ |
1be5fd2e | 12667 | if (inst.operands[1].immisreg) |
5be8be5d DG |
12668 | reject_bad_reg (inst.operands[1].imm); |
12669 | ||
1be5fd2e NC |
12670 | constraint (inst.operands[1].writeback == 1 |
12671 | && inst.operands[0].reg == inst.operands[1].reg, | |
12672 | BAD_OVERLAP); | |
12673 | ||
0110f2b8 | 12674 | inst.instruction = THUMB_OP32 (opcode); |
c19d1205 ZW |
12675 | inst.instruction |= inst.operands[0].reg << 12; |
12676 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
1be5fd2e | 12677 | check_ldr_r15_aligned (); |
b99bd4ef NC |
12678 | return; |
12679 | } | |
12680 | ||
c19d1205 ZW |
12681 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
12682 | ||
12683 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 12684 | { |
c19d1205 ZW |
12685 | /* Only [Rn,Rm] is acceptable. */ |
12686 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
12687 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
12688 | || inst.operands[1].postind || inst.operands[1].shifted | |
12689 | || inst.operands[1].negative, | |
12690 | _("Thumb does not support this addressing mode")); | |
12691 | inst.instruction = THUMB_OP16 (inst.instruction); | |
12692 | goto op16; | |
b99bd4ef | 12693 | } |
5f4273c7 | 12694 | |
c19d1205 ZW |
12695 | inst.instruction = THUMB_OP16 (inst.instruction); |
12696 | if (!inst.operands[1].isreg) | |
8335d6aa | 12697 | if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE)) |
c19d1205 | 12698 | return; |
b99bd4ef | 12699 | |
c19d1205 ZW |
12700 | constraint (!inst.operands[1].preind |
12701 | || inst.operands[1].shifted | |
12702 | || inst.operands[1].writeback, | |
12703 | _("Thumb does not support this addressing mode")); | |
12704 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 12705 | { |
c19d1205 ZW |
12706 | constraint (inst.instruction & 0x0600, |
12707 | _("byte or halfword not valid for base register")); | |
12708 | constraint (inst.operands[1].reg == REG_PC | |
12709 | && !(inst.instruction & THUMB_LOAD_BIT), | |
12710 | _("r15 based store not allowed")); | |
12711 | constraint (inst.operands[1].immisreg, | |
12712 | _("invalid base register for register offset")); | |
b99bd4ef | 12713 | |
c19d1205 ZW |
12714 | if (inst.operands[1].reg == REG_PC) |
12715 | inst.instruction = T_OPCODE_LDR_PC; | |
12716 | else if (inst.instruction & THUMB_LOAD_BIT) | |
12717 | inst.instruction = T_OPCODE_LDR_SP; | |
12718 | else | |
12719 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 12720 | |
c19d1205 | 12721 | inst.instruction |= inst.operands[0].reg << 8; |
e2b0ab59 | 12722 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET; |
c19d1205 ZW |
12723 | return; |
12724 | } | |
90e4755a | 12725 | |
c19d1205 ZW |
12726 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
12727 | if (!inst.operands[1].immisreg) | |
12728 | { | |
12729 | /* Immediate offset. */ | |
12730 | inst.instruction |= inst.operands[0].reg; | |
12731 | inst.instruction |= inst.operands[1].reg << 3; | |
e2b0ab59 | 12732 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET; |
c19d1205 ZW |
12733 | return; |
12734 | } | |
90e4755a | 12735 | |
c19d1205 ZW |
12736 | /* Register offset. */ |
12737 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
12738 | constraint (inst.operands[1].negative, | |
12739 | _("Thumb does not support this addressing mode")); | |
90e4755a | 12740 | |
c19d1205 ZW |
12741 | op16: |
12742 | switch (inst.instruction) | |
12743 | { | |
12744 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
12745 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
12746 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
12747 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
12748 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
12749 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
12750 | case 0x5600 /* ldrsb */: | |
12751 | case 0x5e00 /* ldrsh */: break; | |
12752 | default: abort (); | |
12753 | } | |
90e4755a | 12754 | |
c19d1205 ZW |
12755 | inst.instruction |= inst.operands[0].reg; |
12756 | inst.instruction |= inst.operands[1].reg << 3; | |
12757 | inst.instruction |= inst.operands[1].imm << 6; | |
12758 | } | |
90e4755a | 12759 | |
c19d1205 ZW |
12760 | static void |
12761 | do_t_ldstd (void) | |
12762 | { | |
12763 | if (!inst.operands[1].present) | |
b99bd4ef | 12764 | { |
c19d1205 ZW |
12765 | inst.operands[1].reg = inst.operands[0].reg + 1; |
12766 | constraint (inst.operands[0].reg == REG_LR, | |
12767 | _("r14 not allowed here")); | |
bd340a04 | 12768 | constraint (inst.operands[0].reg == REG_R12, |
477330fc | 12769 | _("r12 not allowed here")); |
b99bd4ef | 12770 | } |
bd340a04 MGD |
12771 | |
12772 | if (inst.operands[2].writeback | |
12773 | && (inst.operands[0].reg == inst.operands[2].reg | |
12774 | || inst.operands[1].reg == inst.operands[2].reg)) | |
12775 | as_warn (_("base register written back, and overlaps " | |
477330fc | 12776 | "one of transfer registers")); |
bd340a04 | 12777 | |
c19d1205 ZW |
12778 | inst.instruction |= inst.operands[0].reg << 12; |
12779 | inst.instruction |= inst.operands[1].reg << 8; | |
12780 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
b99bd4ef NC |
12781 | } |
12782 | ||
c19d1205 ZW |
12783 | static void |
12784 | do_t_ldstt (void) | |
12785 | { | |
12786 | inst.instruction |= inst.operands[0].reg << 12; | |
12787 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
12788 | } | |
a737bd4d | 12789 | |
b99bd4ef | 12790 | static void |
c19d1205 | 12791 | do_t_mla (void) |
b99bd4ef | 12792 | { |
fdfde340 | 12793 | unsigned Rd, Rn, Rm, Ra; |
c921be7d | 12794 | |
fdfde340 JM |
12795 | Rd = inst.operands[0].reg; |
12796 | Rn = inst.operands[1].reg; | |
12797 | Rm = inst.operands[2].reg; | |
12798 | Ra = inst.operands[3].reg; | |
12799 | ||
12800 | reject_bad_reg (Rd); | |
12801 | reject_bad_reg (Rn); | |
12802 | reject_bad_reg (Rm); | |
12803 | reject_bad_reg (Ra); | |
12804 | ||
12805 | inst.instruction |= Rd << 8; | |
12806 | inst.instruction |= Rn << 16; | |
12807 | inst.instruction |= Rm; | |
12808 | inst.instruction |= Ra << 12; | |
c19d1205 | 12809 | } |
b99bd4ef | 12810 | |
c19d1205 ZW |
12811 | static void |
12812 | do_t_mlal (void) | |
12813 | { | |
fdfde340 JM |
12814 | unsigned RdLo, RdHi, Rn, Rm; |
12815 | ||
12816 | RdLo = inst.operands[0].reg; | |
12817 | RdHi = inst.operands[1].reg; | |
12818 | Rn = inst.operands[2].reg; | |
12819 | Rm = inst.operands[3].reg; | |
12820 | ||
12821 | reject_bad_reg (RdLo); | |
12822 | reject_bad_reg (RdHi); | |
12823 | reject_bad_reg (Rn); | |
12824 | reject_bad_reg (Rm); | |
12825 | ||
12826 | inst.instruction |= RdLo << 12; | |
12827 | inst.instruction |= RdHi << 8; | |
12828 | inst.instruction |= Rn << 16; | |
12829 | inst.instruction |= Rm; | |
c19d1205 | 12830 | } |
b99bd4ef | 12831 | |
c19d1205 ZW |
12832 | static void |
12833 | do_t_mov_cmp (void) | |
12834 | { | |
fdfde340 JM |
12835 | unsigned Rn, Rm; |
12836 | ||
12837 | Rn = inst.operands[0].reg; | |
12838 | Rm = inst.operands[1].reg; | |
12839 | ||
e07e6e58 | 12840 | if (Rn == REG_PC) |
5ee91343 | 12841 | set_pred_insn_type_last (); |
e07e6e58 | 12842 | |
c19d1205 | 12843 | if (unified_syntax) |
b99bd4ef | 12844 | { |
c19d1205 ZW |
12845 | int r0off = (inst.instruction == T_MNEM_mov |
12846 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 12847 | unsigned long opcode; |
3d388997 PB |
12848 | bfd_boolean narrow; |
12849 | bfd_boolean low_regs; | |
12850 | ||
fdfde340 | 12851 | low_regs = (Rn <= 7 && Rm <= 7); |
0110f2b8 | 12852 | opcode = inst.instruction; |
5ee91343 | 12853 | if (in_pred_block ()) |
0110f2b8 | 12854 | narrow = opcode != T_MNEM_movs; |
3d388997 | 12855 | else |
0110f2b8 | 12856 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
12857 | if (inst.size_req == 4 |
12858 | || inst.operands[1].shifted) | |
12859 | narrow = FALSE; | |
12860 | ||
efd81785 PB |
12861 | /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */ |
12862 | if (opcode == T_MNEM_movs && inst.operands[1].isreg | |
12863 | && !inst.operands[1].shifted | |
fdfde340 JM |
12864 | && Rn == REG_PC |
12865 | && Rm == REG_LR) | |
efd81785 PB |
12866 | { |
12867 | inst.instruction = T2_SUBS_PC_LR; | |
12868 | return; | |
12869 | } | |
12870 | ||
fdfde340 JM |
12871 | if (opcode == T_MNEM_cmp) |
12872 | { | |
12873 | constraint (Rn == REG_PC, BAD_PC); | |
94206790 MM |
12874 | if (narrow) |
12875 | { | |
12876 | /* In the Thumb-2 ISA, use of R13 as Rm is deprecated, | |
12877 | but valid. */ | |
12878 | warn_deprecated_sp (Rm); | |
12879 | /* R15 was documented as a valid choice for Rm in ARMv6, | |
12880 | but as UNPREDICTABLE in ARMv7. ARM's proprietary | |
12881 | tools reject R15, so we do too. */ | |
12882 | constraint (Rm == REG_PC, BAD_PC); | |
12883 | } | |
12884 | else | |
12885 | reject_bad_reg (Rm); | |
fdfde340 JM |
12886 | } |
12887 | else if (opcode == T_MNEM_mov | |
12888 | || opcode == T_MNEM_movs) | |
12889 | { | |
12890 | if (inst.operands[1].isreg) | |
12891 | { | |
12892 | if (opcode == T_MNEM_movs) | |
12893 | { | |
12894 | reject_bad_reg (Rn); | |
12895 | reject_bad_reg (Rm); | |
12896 | } | |
76fa04a4 MGD |
12897 | else if (narrow) |
12898 | { | |
12899 | /* This is mov.n. */ | |
12900 | if ((Rn == REG_SP || Rn == REG_PC) | |
12901 | && (Rm == REG_SP || Rm == REG_PC)) | |
12902 | { | |
5c3696f8 | 12903 | as_tsktsk (_("Use of r%u as a source register is " |
76fa04a4 MGD |
12904 | "deprecated when r%u is the destination " |
12905 | "register."), Rm, Rn); | |
12906 | } | |
12907 | } | |
12908 | else | |
12909 | { | |
12910 | /* This is mov.w. */ | |
12911 | constraint (Rn == REG_PC, BAD_PC); | |
12912 | constraint (Rm == REG_PC, BAD_PC); | |
5c8ed6a4 JW |
12913 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
12914 | constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP); | |
76fa04a4 | 12915 | } |
fdfde340 JM |
12916 | } |
12917 | else | |
12918 | reject_bad_reg (Rn); | |
12919 | } | |
12920 | ||
c19d1205 ZW |
12921 | if (!inst.operands[1].isreg) |
12922 | { | |
0110f2b8 | 12923 | /* Immediate operand. */ |
5ee91343 | 12924 | if (!in_pred_block () && opcode == T_MNEM_mov) |
0110f2b8 PB |
12925 | narrow = 0; |
12926 | if (low_regs && narrow) | |
12927 | { | |
12928 | inst.instruction = THUMB_OP16 (opcode); | |
fdfde340 | 12929 | inst.instruction |= Rn << 8; |
e2b0ab59 AV |
12930 | if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
12931 | || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) | |
72d98d16 | 12932 | { |
a9f02af8 | 12933 | if (inst.size_req == 2) |
e2b0ab59 | 12934 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM; |
a9f02af8 MG |
12935 | else |
12936 | inst.relax = opcode; | |
72d98d16 | 12937 | } |
0110f2b8 PB |
12938 | } |
12939 | else | |
12940 | { | |
e2b0ab59 AV |
12941 | constraint ((inst.relocs[0].type |
12942 | >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC) | |
12943 | && (inst.relocs[0].type | |
12944 | <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) , | |
a9f02af8 MG |
12945 | THUMB1_RELOC_ONLY); |
12946 | ||
0110f2b8 PB |
12947 | inst.instruction = THUMB_OP32 (inst.instruction); |
12948 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 12949 | inst.instruction |= Rn << r0off; |
e2b0ab59 | 12950 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
0110f2b8 | 12951 | } |
c19d1205 | 12952 | } |
728ca7c9 PB |
12953 | else if (inst.operands[1].shifted && inst.operands[1].immisreg |
12954 | && (inst.instruction == T_MNEM_mov | |
12955 | || inst.instruction == T_MNEM_movs)) | |
12956 | { | |
12957 | /* Register shifts are encoded as separate shift instructions. */ | |
12958 | bfd_boolean flags = (inst.instruction == T_MNEM_movs); | |
12959 | ||
5ee91343 | 12960 | if (in_pred_block ()) |
728ca7c9 PB |
12961 | narrow = !flags; |
12962 | else | |
12963 | narrow = flags; | |
12964 | ||
12965 | if (inst.size_req == 4) | |
12966 | narrow = FALSE; | |
12967 | ||
12968 | if (!low_regs || inst.operands[1].imm > 7) | |
12969 | narrow = FALSE; | |
12970 | ||
fdfde340 | 12971 | if (Rn != Rm) |
728ca7c9 PB |
12972 | narrow = FALSE; |
12973 | ||
12974 | switch (inst.operands[1].shift_kind) | |
12975 | { | |
12976 | case SHIFT_LSL: | |
12977 | opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl); | |
12978 | break; | |
12979 | case SHIFT_ASR: | |
12980 | opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr); | |
12981 | break; | |
12982 | case SHIFT_LSR: | |
12983 | opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr); | |
12984 | break; | |
12985 | case SHIFT_ROR: | |
12986 | opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror); | |
12987 | break; | |
12988 | default: | |
5f4273c7 | 12989 | abort (); |
728ca7c9 PB |
12990 | } |
12991 | ||
12992 | inst.instruction = opcode; | |
12993 | if (narrow) | |
12994 | { | |
fdfde340 | 12995 | inst.instruction |= Rn; |
728ca7c9 PB |
12996 | inst.instruction |= inst.operands[1].imm << 3; |
12997 | } | |
12998 | else | |
12999 | { | |
13000 | if (flags) | |
13001 | inst.instruction |= CONDS_BIT; | |
13002 | ||
fdfde340 JM |
13003 | inst.instruction |= Rn << 8; |
13004 | inst.instruction |= Rm << 16; | |
728ca7c9 PB |
13005 | inst.instruction |= inst.operands[1].imm; |
13006 | } | |
13007 | } | |
3d388997 | 13008 | else if (!narrow) |
c19d1205 | 13009 | { |
728ca7c9 PB |
13010 | /* Some mov with immediate shift have narrow variants. |
13011 | Register shifts are handled above. */ | |
13012 | if (low_regs && inst.operands[1].shifted | |
13013 | && (inst.instruction == T_MNEM_mov | |
13014 | || inst.instruction == T_MNEM_movs)) | |
13015 | { | |
5ee91343 | 13016 | if (in_pred_block ()) |
728ca7c9 PB |
13017 | narrow = (inst.instruction == T_MNEM_mov); |
13018 | else | |
13019 | narrow = (inst.instruction == T_MNEM_movs); | |
13020 | } | |
13021 | ||
13022 | if (narrow) | |
13023 | { | |
13024 | switch (inst.operands[1].shift_kind) | |
13025 | { | |
13026 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
13027 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
13028 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; | |
13029 | default: narrow = FALSE; break; | |
13030 | } | |
13031 | } | |
13032 | ||
13033 | if (narrow) | |
13034 | { | |
fdfde340 JM |
13035 | inst.instruction |= Rn; |
13036 | inst.instruction |= Rm << 3; | |
e2b0ab59 | 13037 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT; |
728ca7c9 PB |
13038 | } |
13039 | else | |
13040 | { | |
13041 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 13042 | inst.instruction |= Rn << r0off; |
728ca7c9 PB |
13043 | encode_thumb32_shifted_operand (1); |
13044 | } | |
c19d1205 ZW |
13045 | } |
13046 | else | |
13047 | switch (inst.instruction) | |
13048 | { | |
13049 | case T_MNEM_mov: | |
837b3435 | 13050 | /* In v4t or v5t a move of two lowregs produces unpredictable |
c6400f8a MGD |
13051 | results. Don't allow this. */ |
13052 | if (low_regs) | |
13053 | { | |
13054 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6), | |
13055 | "MOV Rd, Rs with two low registers is not " | |
13056 | "permitted on this architecture"); | |
fa94de6b | 13057 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
c6400f8a MGD |
13058 | arm_ext_v6); |
13059 | } | |
13060 | ||
c19d1205 | 13061 | inst.instruction = T_OPCODE_MOV_HR; |
fdfde340 JM |
13062 | inst.instruction |= (Rn & 0x8) << 4; |
13063 | inst.instruction |= (Rn & 0x7); | |
13064 | inst.instruction |= Rm << 3; | |
c19d1205 | 13065 | break; |
b99bd4ef | 13066 | |
c19d1205 ZW |
13067 | case T_MNEM_movs: |
13068 | /* We know we have low registers at this point. | |
941a8a52 MGD |
13069 | Generate LSLS Rd, Rs, #0. */ |
13070 | inst.instruction = T_OPCODE_LSL_I; | |
fdfde340 JM |
13071 | inst.instruction |= Rn; |
13072 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
13073 | break; |
13074 | ||
13075 | case T_MNEM_cmp: | |
3d388997 | 13076 | if (low_regs) |
c19d1205 ZW |
13077 | { |
13078 | inst.instruction = T_OPCODE_CMP_LR; | |
fdfde340 JM |
13079 | inst.instruction |= Rn; |
13080 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
13081 | } |
13082 | else | |
13083 | { | |
13084 | inst.instruction = T_OPCODE_CMP_HR; | |
fdfde340 JM |
13085 | inst.instruction |= (Rn & 0x8) << 4; |
13086 | inst.instruction |= (Rn & 0x7); | |
13087 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
13088 | } |
13089 | break; | |
13090 | } | |
b99bd4ef NC |
13091 | return; |
13092 | } | |
13093 | ||
c19d1205 | 13094 | inst.instruction = THUMB_OP16 (inst.instruction); |
539d4391 NC |
13095 | |
13096 | /* PR 10443: Do not silently ignore shifted operands. */ | |
13097 | constraint (inst.operands[1].shifted, | |
13098 | _("shifts in CMP/MOV instructions are only supported in unified syntax")); | |
13099 | ||
c19d1205 | 13100 | if (inst.operands[1].isreg) |
b99bd4ef | 13101 | { |
fdfde340 | 13102 | if (Rn < 8 && Rm < 8) |
b99bd4ef | 13103 | { |
c19d1205 ZW |
13104 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
13105 | since a MOV instruction produces unpredictable results. */ | |
13106 | if (inst.instruction == T_OPCODE_MOV_I8) | |
13107 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 13108 | else |
c19d1205 | 13109 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 13110 | |
fdfde340 JM |
13111 | inst.instruction |= Rn; |
13112 | inst.instruction |= Rm << 3; | |
b99bd4ef NC |
13113 | } |
13114 | else | |
13115 | { | |
c19d1205 ZW |
13116 | if (inst.instruction == T_OPCODE_MOV_I8) |
13117 | inst.instruction = T_OPCODE_MOV_HR; | |
13118 | else | |
13119 | inst.instruction = T_OPCODE_CMP_HR; | |
13120 | do_t_cpy (); | |
b99bd4ef NC |
13121 | } |
13122 | } | |
c19d1205 | 13123 | else |
b99bd4ef | 13124 | { |
fdfde340 | 13125 | constraint (Rn > 7, |
c19d1205 | 13126 | _("only lo regs allowed with immediate")); |
fdfde340 | 13127 | inst.instruction |= Rn << 8; |
e2b0ab59 | 13128 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM; |
c19d1205 ZW |
13129 | } |
13130 | } | |
b99bd4ef | 13131 | |
c19d1205 ZW |
13132 | static void |
13133 | do_t_mov16 (void) | |
13134 | { | |
fdfde340 | 13135 | unsigned Rd; |
b6895b4f PB |
13136 | bfd_vma imm; |
13137 | bfd_boolean top; | |
13138 | ||
13139 | top = (inst.instruction & 0x00800000) != 0; | |
e2b0ab59 | 13140 | if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW) |
b6895b4f | 13141 | { |
33eaf5de | 13142 | constraint (top, _(":lower16: not allowed in this instruction")); |
e2b0ab59 | 13143 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW; |
b6895b4f | 13144 | } |
e2b0ab59 | 13145 | else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT) |
b6895b4f | 13146 | { |
33eaf5de | 13147 | constraint (!top, _(":upper16: not allowed in this instruction")); |
e2b0ab59 | 13148 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT; |
b6895b4f PB |
13149 | } |
13150 | ||
fdfde340 JM |
13151 | Rd = inst.operands[0].reg; |
13152 | reject_bad_reg (Rd); | |
13153 | ||
13154 | inst.instruction |= Rd << 8; | |
e2b0ab59 | 13155 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
b6895b4f | 13156 | { |
e2b0ab59 | 13157 | imm = inst.relocs[0].exp.X_add_number; |
b6895b4f PB |
13158 | inst.instruction |= (imm & 0xf000) << 4; |
13159 | inst.instruction |= (imm & 0x0800) << 15; | |
13160 | inst.instruction |= (imm & 0x0700) << 4; | |
13161 | inst.instruction |= (imm & 0x00ff); | |
13162 | } | |
c19d1205 | 13163 | } |
b99bd4ef | 13164 | |
c19d1205 ZW |
13165 | static void |
13166 | do_t_mvn_tst (void) | |
13167 | { | |
fdfde340 | 13168 | unsigned Rn, Rm; |
c921be7d | 13169 | |
fdfde340 JM |
13170 | Rn = inst.operands[0].reg; |
13171 | Rm = inst.operands[1].reg; | |
13172 | ||
13173 | if (inst.instruction == T_MNEM_cmp | |
13174 | || inst.instruction == T_MNEM_cmn) | |
13175 | constraint (Rn == REG_PC, BAD_PC); | |
13176 | else | |
13177 | reject_bad_reg (Rn); | |
13178 | reject_bad_reg (Rm); | |
13179 | ||
c19d1205 ZW |
13180 | if (unified_syntax) |
13181 | { | |
13182 | int r0off = (inst.instruction == T_MNEM_mvn | |
13183 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
13184 | bfd_boolean narrow; |
13185 | ||
13186 | if (inst.size_req == 4 | |
13187 | || inst.instruction > 0xffff | |
13188 | || inst.operands[1].shifted | |
fdfde340 | 13189 | || Rn > 7 || Rm > 7) |
3d388997 | 13190 | narrow = FALSE; |
fe8b4cc3 KT |
13191 | else if (inst.instruction == T_MNEM_cmn |
13192 | || inst.instruction == T_MNEM_tst) | |
3d388997 PB |
13193 | narrow = TRUE; |
13194 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
5ee91343 | 13195 | narrow = !in_pred_block (); |
3d388997 | 13196 | else |
5ee91343 | 13197 | narrow = in_pred_block (); |
3d388997 | 13198 | |
c19d1205 | 13199 | if (!inst.operands[1].isreg) |
b99bd4ef | 13200 | { |
c19d1205 ZW |
13201 | /* For an immediate, we always generate a 32-bit opcode; |
13202 | section relaxation will shrink it later if possible. */ | |
13203 | if (inst.instruction < 0xffff) | |
13204 | inst.instruction = THUMB_OP32 (inst.instruction); | |
13205 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 13206 | inst.instruction |= Rn << r0off; |
e2b0ab59 | 13207 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 13208 | } |
c19d1205 | 13209 | else |
b99bd4ef | 13210 | { |
c19d1205 | 13211 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 13212 | if (narrow) |
b99bd4ef | 13213 | { |
c19d1205 | 13214 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
13215 | inst.instruction |= Rn; |
13216 | inst.instruction |= Rm << 3; | |
b99bd4ef | 13217 | } |
c19d1205 | 13218 | else |
b99bd4ef | 13219 | { |
c19d1205 ZW |
13220 | constraint (inst.operands[1].shifted |
13221 | && inst.operands[1].immisreg, | |
13222 | _("shift must be constant")); | |
13223 | if (inst.instruction < 0xffff) | |
13224 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 13225 | inst.instruction |= Rn << r0off; |
c19d1205 | 13226 | encode_thumb32_shifted_operand (1); |
b99bd4ef | 13227 | } |
b99bd4ef NC |
13228 | } |
13229 | } | |
13230 | else | |
13231 | { | |
c19d1205 ZW |
13232 | constraint (inst.instruction > 0xffff |
13233 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
13234 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
13235 | _("unshifted register required")); | |
fdfde340 | 13236 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 13237 | BAD_HIREG); |
b99bd4ef | 13238 | |
c19d1205 | 13239 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
13240 | inst.instruction |= Rn; |
13241 | inst.instruction |= Rm << 3; | |
b99bd4ef | 13242 | } |
b99bd4ef NC |
13243 | } |
13244 | ||
b05fe5cf | 13245 | static void |
c19d1205 | 13246 | do_t_mrs (void) |
b05fe5cf | 13247 | { |
fdfde340 | 13248 | unsigned Rd; |
037e8744 JB |
13249 | |
13250 | if (do_vfp_nsyn_mrs () == SUCCESS) | |
13251 | return; | |
13252 | ||
90ec0d68 MGD |
13253 | Rd = inst.operands[0].reg; |
13254 | reject_bad_reg (Rd); | |
13255 | inst.instruction |= Rd << 8; | |
13256 | ||
13257 | if (inst.operands[1].isreg) | |
62b3e311 | 13258 | { |
90ec0d68 MGD |
13259 | unsigned br = inst.operands[1].reg; |
13260 | if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000)) | |
13261 | as_bad (_("bad register for mrs")); | |
13262 | ||
13263 | inst.instruction |= br & (0xf << 16); | |
13264 | inst.instruction |= (br & 0x300) >> 4; | |
13265 | inst.instruction |= (br & SPSR_BIT) >> 2; | |
62b3e311 PB |
13266 | } |
13267 | else | |
13268 | { | |
90ec0d68 | 13269 | int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
5f4273c7 | 13270 | |
d2cd1205 | 13271 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
1a43faaf NC |
13272 | { |
13273 | /* PR gas/12698: The constraint is only applied for m_profile. | |
13274 | If the user has specified -march=all, we want to ignore it as | |
13275 | we are building for any CPU type, including non-m variants. */ | |
823d2571 TG |
13276 | bfd_boolean m_profile = |
13277 | !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any); | |
1a43faaf NC |
13278 | constraint ((flags != 0) && m_profile, _("selected processor does " |
13279 | "not support requested special purpose register")); | |
13280 | } | |
90ec0d68 | 13281 | else |
d2cd1205 JB |
13282 | /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile |
13283 | devices). */ | |
13284 | constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f), | |
13285 | _("'APSR', 'CPSR' or 'SPSR' expected")); | |
fdfde340 | 13286 | |
90ec0d68 MGD |
13287 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
13288 | inst.instruction |= inst.operands[1].imm & 0xff; | |
13289 | inst.instruction |= 0xf0000; | |
13290 | } | |
c19d1205 | 13291 | } |
b05fe5cf | 13292 | |
c19d1205 ZW |
13293 | static void |
13294 | do_t_msr (void) | |
13295 | { | |
62b3e311 | 13296 | int flags; |
fdfde340 | 13297 | unsigned Rn; |
62b3e311 | 13298 | |
037e8744 JB |
13299 | if (do_vfp_nsyn_msr () == SUCCESS) |
13300 | return; | |
13301 | ||
c19d1205 ZW |
13302 | constraint (!inst.operands[1].isreg, |
13303 | _("Thumb encoding does not support an immediate here")); | |
90ec0d68 MGD |
13304 | |
13305 | if (inst.operands[0].isreg) | |
13306 | flags = (int)(inst.operands[0].reg); | |
13307 | else | |
13308 | flags = inst.operands[0].imm; | |
13309 | ||
d2cd1205 | 13310 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
62b3e311 | 13311 | { |
d2cd1205 JB |
13312 | int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
13313 | ||
1a43faaf | 13314 | /* PR gas/12698: The constraint is only applied for m_profile. |
477330fc RM |
13315 | If the user has specified -march=all, we want to ignore it as |
13316 | we are building for any CPU type, including non-m variants. */ | |
823d2571 TG |
13317 | bfd_boolean m_profile = |
13318 | !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any); | |
1a43faaf | 13319 | constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp) |
477330fc RM |
13320 | && (bits & ~(PSR_s | PSR_f)) != 0) |
13321 | || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp) | |
13322 | && bits != PSR_f)) && m_profile, | |
13323 | _("selected processor does not support requested special " | |
13324 | "purpose register")); | |
62b3e311 PB |
13325 | } |
13326 | else | |
d2cd1205 JB |
13327 | constraint ((flags & 0xff) != 0, _("selected processor does not support " |
13328 | "requested special purpose register")); | |
c921be7d | 13329 | |
fdfde340 JM |
13330 | Rn = inst.operands[1].reg; |
13331 | reject_bad_reg (Rn); | |
13332 | ||
62b3e311 | 13333 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
90ec0d68 MGD |
13334 | inst.instruction |= (flags & 0xf0000) >> 8; |
13335 | inst.instruction |= (flags & 0x300) >> 4; | |
62b3e311 | 13336 | inst.instruction |= (flags & 0xff); |
fdfde340 | 13337 | inst.instruction |= Rn << 16; |
c19d1205 | 13338 | } |
b05fe5cf | 13339 | |
c19d1205 ZW |
13340 | static void |
13341 | do_t_mul (void) | |
13342 | { | |
17828f45 | 13343 | bfd_boolean narrow; |
fdfde340 | 13344 | unsigned Rd, Rn, Rm; |
17828f45 | 13345 | |
c19d1205 ZW |
13346 | if (!inst.operands[2].present) |
13347 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 13348 | |
fdfde340 JM |
13349 | Rd = inst.operands[0].reg; |
13350 | Rn = inst.operands[1].reg; | |
13351 | Rm = inst.operands[2].reg; | |
13352 | ||
17828f45 | 13353 | if (unified_syntax) |
b05fe5cf | 13354 | { |
17828f45 | 13355 | if (inst.size_req == 4 |
fdfde340 JM |
13356 | || (Rd != Rn |
13357 | && Rd != Rm) | |
13358 | || Rn > 7 | |
13359 | || Rm > 7) | |
17828f45 JM |
13360 | narrow = FALSE; |
13361 | else if (inst.instruction == T_MNEM_muls) | |
5ee91343 | 13362 | narrow = !in_pred_block (); |
17828f45 | 13363 | else |
5ee91343 | 13364 | narrow = in_pred_block (); |
b05fe5cf | 13365 | } |
c19d1205 | 13366 | else |
b05fe5cf | 13367 | { |
17828f45 | 13368 | constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32); |
fdfde340 | 13369 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 13370 | BAD_HIREG); |
17828f45 JM |
13371 | narrow = TRUE; |
13372 | } | |
b05fe5cf | 13373 | |
17828f45 JM |
13374 | if (narrow) |
13375 | { | |
13376 | /* 16-bit MULS/Conditional MUL. */ | |
c19d1205 | 13377 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 | 13378 | inst.instruction |= Rd; |
b05fe5cf | 13379 | |
fdfde340 JM |
13380 | if (Rd == Rn) |
13381 | inst.instruction |= Rm << 3; | |
13382 | else if (Rd == Rm) | |
13383 | inst.instruction |= Rn << 3; | |
c19d1205 ZW |
13384 | else |
13385 | constraint (1, _("dest must overlap one source register")); | |
13386 | } | |
17828f45 JM |
13387 | else |
13388 | { | |
e07e6e58 NC |
13389 | constraint (inst.instruction != T_MNEM_mul, |
13390 | _("Thumb-2 MUL must not set flags")); | |
17828f45 JM |
13391 | /* 32-bit MUL. */ |
13392 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
13393 | inst.instruction |= Rd << 8; |
13394 | inst.instruction |= Rn << 16; | |
13395 | inst.instruction |= Rm << 0; | |
13396 | ||
13397 | reject_bad_reg (Rd); | |
13398 | reject_bad_reg (Rn); | |
13399 | reject_bad_reg (Rm); | |
17828f45 | 13400 | } |
c19d1205 | 13401 | } |
b05fe5cf | 13402 | |
c19d1205 ZW |
13403 | static void |
13404 | do_t_mull (void) | |
13405 | { | |
fdfde340 | 13406 | unsigned RdLo, RdHi, Rn, Rm; |
b05fe5cf | 13407 | |
fdfde340 JM |
13408 | RdLo = inst.operands[0].reg; |
13409 | RdHi = inst.operands[1].reg; | |
13410 | Rn = inst.operands[2].reg; | |
13411 | Rm = inst.operands[3].reg; | |
13412 | ||
13413 | reject_bad_reg (RdLo); | |
13414 | reject_bad_reg (RdHi); | |
13415 | reject_bad_reg (Rn); | |
13416 | reject_bad_reg (Rm); | |
13417 | ||
13418 | inst.instruction |= RdLo << 12; | |
13419 | inst.instruction |= RdHi << 8; | |
13420 | inst.instruction |= Rn << 16; | |
13421 | inst.instruction |= Rm; | |
13422 | ||
13423 | if (RdLo == RdHi) | |
c19d1205 ZW |
13424 | as_tsktsk (_("rdhi and rdlo must be different")); |
13425 | } | |
b05fe5cf | 13426 | |
c19d1205 ZW |
13427 | static void |
13428 | do_t_nop (void) | |
13429 | { | |
5ee91343 | 13430 | set_pred_insn_type (NEUTRAL_IT_INSN); |
e07e6e58 | 13431 | |
c19d1205 ZW |
13432 | if (unified_syntax) |
13433 | { | |
13434 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 13435 | { |
c19d1205 ZW |
13436 | inst.instruction = THUMB_OP32 (inst.instruction); |
13437 | inst.instruction |= inst.operands[0].imm; | |
13438 | } | |
13439 | else | |
13440 | { | |
bc2d1808 NC |
13441 | /* PR9722: Check for Thumb2 availability before |
13442 | generating a thumb2 nop instruction. */ | |
afa62d5e | 13443 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
bc2d1808 NC |
13444 | { |
13445 | inst.instruction = THUMB_OP16 (inst.instruction); | |
13446 | inst.instruction |= inst.operands[0].imm << 4; | |
13447 | } | |
13448 | else | |
13449 | inst.instruction = 0x46c0; | |
c19d1205 ZW |
13450 | } |
13451 | } | |
13452 | else | |
13453 | { | |
13454 | constraint (inst.operands[0].present, | |
13455 | _("Thumb does not support NOP with hints")); | |
13456 | inst.instruction = 0x46c0; | |
13457 | } | |
13458 | } | |
b05fe5cf | 13459 | |
c19d1205 ZW |
13460 | static void |
13461 | do_t_neg (void) | |
13462 | { | |
13463 | if (unified_syntax) | |
13464 | { | |
3d388997 PB |
13465 | bfd_boolean narrow; |
13466 | ||
13467 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
5ee91343 | 13468 | narrow = !in_pred_block (); |
3d388997 | 13469 | else |
5ee91343 | 13470 | narrow = in_pred_block (); |
3d388997 PB |
13471 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
13472 | narrow = FALSE; | |
13473 | if (inst.size_req == 4) | |
13474 | narrow = FALSE; | |
13475 | ||
13476 | if (!narrow) | |
c19d1205 ZW |
13477 | { |
13478 | inst.instruction = THUMB_OP32 (inst.instruction); | |
13479 | inst.instruction |= inst.operands[0].reg << 8; | |
13480 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
13481 | } |
13482 | else | |
13483 | { | |
c19d1205 ZW |
13484 | inst.instruction = THUMB_OP16 (inst.instruction); |
13485 | inst.instruction |= inst.operands[0].reg; | |
13486 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
13487 | } |
13488 | } | |
13489 | else | |
13490 | { | |
c19d1205 ZW |
13491 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
13492 | BAD_HIREG); | |
13493 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
13494 | ||
13495 | inst.instruction = THUMB_OP16 (inst.instruction); | |
13496 | inst.instruction |= inst.operands[0].reg; | |
13497 | inst.instruction |= inst.operands[1].reg << 3; | |
13498 | } | |
13499 | } | |
13500 | ||
1c444d06 JM |
13501 | static void |
13502 | do_t_orn (void) | |
13503 | { | |
13504 | unsigned Rd, Rn; | |
13505 | ||
13506 | Rd = inst.operands[0].reg; | |
13507 | Rn = inst.operands[1].present ? inst.operands[1].reg : Rd; | |
13508 | ||
fdfde340 JM |
13509 | reject_bad_reg (Rd); |
13510 | /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */ | |
13511 | reject_bad_reg (Rn); | |
13512 | ||
1c444d06 JM |
13513 | inst.instruction |= Rd << 8; |
13514 | inst.instruction |= Rn << 16; | |
13515 | ||
13516 | if (!inst.operands[2].isreg) | |
13517 | { | |
13518 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
e2b0ab59 | 13519 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
1c444d06 JM |
13520 | } |
13521 | else | |
13522 | { | |
13523 | unsigned Rm; | |
13524 | ||
13525 | Rm = inst.operands[2].reg; | |
fdfde340 | 13526 | reject_bad_reg (Rm); |
1c444d06 JM |
13527 | |
13528 | constraint (inst.operands[2].shifted | |
13529 | && inst.operands[2].immisreg, | |
13530 | _("shift must be constant")); | |
13531 | encode_thumb32_shifted_operand (2); | |
13532 | } | |
13533 | } | |
13534 | ||
c19d1205 ZW |
13535 | static void |
13536 | do_t_pkhbt (void) | |
13537 | { | |
fdfde340 JM |
13538 | unsigned Rd, Rn, Rm; |
13539 | ||
13540 | Rd = inst.operands[0].reg; | |
13541 | Rn = inst.operands[1].reg; | |
13542 | Rm = inst.operands[2].reg; | |
13543 | ||
13544 | reject_bad_reg (Rd); | |
13545 | reject_bad_reg (Rn); | |
13546 | reject_bad_reg (Rm); | |
13547 | ||
13548 | inst.instruction |= Rd << 8; | |
13549 | inst.instruction |= Rn << 16; | |
13550 | inst.instruction |= Rm; | |
c19d1205 ZW |
13551 | if (inst.operands[3].present) |
13552 | { | |
e2b0ab59 AV |
13553 | unsigned int val = inst.relocs[0].exp.X_add_number; |
13554 | constraint (inst.relocs[0].exp.X_op != O_constant, | |
c19d1205 ZW |
13555 | _("expression too complex")); |
13556 | inst.instruction |= (val & 0x1c) << 10; | |
13557 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 13558 | } |
c19d1205 | 13559 | } |
b05fe5cf | 13560 | |
c19d1205 ZW |
13561 | static void |
13562 | do_t_pkhtb (void) | |
13563 | { | |
13564 | if (!inst.operands[3].present) | |
1ef52f49 NC |
13565 | { |
13566 | unsigned Rtmp; | |
13567 | ||
13568 | inst.instruction &= ~0x00000020; | |
13569 | ||
13570 | /* PR 10168. Swap the Rm and Rn registers. */ | |
13571 | Rtmp = inst.operands[1].reg; | |
13572 | inst.operands[1].reg = inst.operands[2].reg; | |
13573 | inst.operands[2].reg = Rtmp; | |
13574 | } | |
c19d1205 | 13575 | do_t_pkhbt (); |
b05fe5cf ZW |
13576 | } |
13577 | ||
c19d1205 ZW |
13578 | static void |
13579 | do_t_pld (void) | |
13580 | { | |
fdfde340 JM |
13581 | if (inst.operands[0].immisreg) |
13582 | reject_bad_reg (inst.operands[0].imm); | |
13583 | ||
c19d1205 ZW |
13584 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); |
13585 | } | |
b05fe5cf | 13586 | |
c19d1205 ZW |
13587 | static void |
13588 | do_t_push_pop (void) | |
b99bd4ef | 13589 | { |
e9f89963 | 13590 | unsigned mask; |
5f4273c7 | 13591 | |
c19d1205 ZW |
13592 | constraint (inst.operands[0].writeback, |
13593 | _("push/pop do not support {reglist}^")); | |
e2b0ab59 | 13594 | constraint (inst.relocs[0].type != BFD_RELOC_UNUSED, |
c19d1205 | 13595 | _("expression too complex")); |
b99bd4ef | 13596 | |
e9f89963 | 13597 | mask = inst.operands[0].imm; |
d3bfe16e | 13598 | if (inst.size_req != 4 && (mask & ~0xff) == 0) |
3c707909 | 13599 | inst.instruction = THUMB_OP16 (inst.instruction) | mask; |
d3bfe16e | 13600 | else if (inst.size_req != 4 |
c6025a80 | 13601 | && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push |
d3bfe16e | 13602 | ? REG_LR : REG_PC))) |
b99bd4ef | 13603 | { |
c19d1205 ZW |
13604 | inst.instruction = THUMB_OP16 (inst.instruction); |
13605 | inst.instruction |= THUMB_PP_PC_LR; | |
3c707909 | 13606 | inst.instruction |= mask & 0xff; |
c19d1205 ZW |
13607 | } |
13608 | else if (unified_syntax) | |
13609 | { | |
3c707909 | 13610 | inst.instruction = THUMB_OP32 (inst.instruction); |
4b5a202f AV |
13611 | encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE); |
13612 | } | |
13613 | else | |
13614 | { | |
13615 | inst.error = _("invalid register list to push/pop instruction"); | |
13616 | return; | |
c19d1205 | 13617 | } |
4b5a202f AV |
13618 | } |
13619 | ||
13620 | static void | |
13621 | do_t_clrm (void) | |
13622 | { | |
13623 | if (unified_syntax) | |
13624 | encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE); | |
c19d1205 ZW |
13625 | else |
13626 | { | |
13627 | inst.error = _("invalid register list to push/pop instruction"); | |
13628 | return; | |
13629 | } | |
c19d1205 | 13630 | } |
b99bd4ef | 13631 | |
efd6b359 AV |
13632 | static void |
13633 | do_t_vscclrm (void) | |
13634 | { | |
13635 | if (inst.operands[0].issingle) | |
13636 | { | |
13637 | inst.instruction |= (inst.operands[0].reg & 0x1) << 22; | |
13638 | inst.instruction |= (inst.operands[0].reg & 0x1e) << 11; | |
13639 | inst.instruction |= inst.operands[0].imm; | |
13640 | } | |
13641 | else | |
13642 | { | |
13643 | inst.instruction |= (inst.operands[0].reg & 0x10) << 18; | |
13644 | inst.instruction |= (inst.operands[0].reg & 0xf) << 12; | |
13645 | inst.instruction |= 1 << 8; | |
13646 | inst.instruction |= inst.operands[0].imm << 1; | |
13647 | } | |
13648 | } | |
13649 | ||
c19d1205 ZW |
13650 | static void |
13651 | do_t_rbit (void) | |
13652 | { | |
fdfde340 JM |
13653 | unsigned Rd, Rm; |
13654 | ||
13655 | Rd = inst.operands[0].reg; | |
13656 | Rm = inst.operands[1].reg; | |
13657 | ||
13658 | reject_bad_reg (Rd); | |
13659 | reject_bad_reg (Rm); | |
13660 | ||
13661 | inst.instruction |= Rd << 8; | |
13662 | inst.instruction |= Rm << 16; | |
13663 | inst.instruction |= Rm; | |
c19d1205 | 13664 | } |
b99bd4ef | 13665 | |
c19d1205 ZW |
13666 | static void |
13667 | do_t_rev (void) | |
13668 | { | |
fdfde340 JM |
13669 | unsigned Rd, Rm; |
13670 | ||
13671 | Rd = inst.operands[0].reg; | |
13672 | Rm = inst.operands[1].reg; | |
13673 | ||
13674 | reject_bad_reg (Rd); | |
13675 | reject_bad_reg (Rm); | |
13676 | ||
13677 | if (Rd <= 7 && Rm <= 7 | |
c19d1205 ZW |
13678 | && inst.size_req != 4) |
13679 | { | |
13680 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 JM |
13681 | inst.instruction |= Rd; |
13682 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
13683 | } |
13684 | else if (unified_syntax) | |
13685 | { | |
13686 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
13687 | inst.instruction |= Rd << 8; |
13688 | inst.instruction |= Rm << 16; | |
13689 | inst.instruction |= Rm; | |
c19d1205 ZW |
13690 | } |
13691 | else | |
13692 | inst.error = BAD_HIREG; | |
13693 | } | |
b99bd4ef | 13694 | |
1c444d06 JM |
13695 | static void |
13696 | do_t_rrx (void) | |
13697 | { | |
13698 | unsigned Rd, Rm; | |
13699 | ||
13700 | Rd = inst.operands[0].reg; | |
13701 | Rm = inst.operands[1].reg; | |
13702 | ||
fdfde340 JM |
13703 | reject_bad_reg (Rd); |
13704 | reject_bad_reg (Rm); | |
c921be7d | 13705 | |
1c444d06 JM |
13706 | inst.instruction |= Rd << 8; |
13707 | inst.instruction |= Rm; | |
13708 | } | |
13709 | ||
c19d1205 ZW |
13710 | static void |
13711 | do_t_rsb (void) | |
13712 | { | |
fdfde340 | 13713 | unsigned Rd, Rs; |
b99bd4ef | 13714 | |
c19d1205 ZW |
13715 | Rd = inst.operands[0].reg; |
13716 | Rs = (inst.operands[1].present | |
13717 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
13718 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 13719 | |
fdfde340 JM |
13720 | reject_bad_reg (Rd); |
13721 | reject_bad_reg (Rs); | |
13722 | if (inst.operands[2].isreg) | |
13723 | reject_bad_reg (inst.operands[2].reg); | |
13724 | ||
c19d1205 ZW |
13725 | inst.instruction |= Rd << 8; |
13726 | inst.instruction |= Rs << 16; | |
13727 | if (!inst.operands[2].isreg) | |
13728 | { | |
026d3abb PB |
13729 | bfd_boolean narrow; |
13730 | ||
13731 | if ((inst.instruction & 0x00100000) != 0) | |
5ee91343 | 13732 | narrow = !in_pred_block (); |
026d3abb | 13733 | else |
5ee91343 | 13734 | narrow = in_pred_block (); |
026d3abb PB |
13735 | |
13736 | if (Rd > 7 || Rs > 7) | |
13737 | narrow = FALSE; | |
13738 | ||
13739 | if (inst.size_req == 4 || !unified_syntax) | |
13740 | narrow = FALSE; | |
13741 | ||
e2b0ab59 AV |
13742 | if (inst.relocs[0].exp.X_op != O_constant |
13743 | || inst.relocs[0].exp.X_add_number != 0) | |
026d3abb PB |
13744 | narrow = FALSE; |
13745 | ||
13746 | /* Turn rsb #0 into 16-bit neg. We should probably do this via | |
477330fc | 13747 | relaxation, but it doesn't seem worth the hassle. */ |
026d3abb PB |
13748 | if (narrow) |
13749 | { | |
e2b0ab59 | 13750 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
026d3abb PB |
13751 | inst.instruction = THUMB_OP16 (T_MNEM_negs); |
13752 | inst.instruction |= Rs << 3; | |
13753 | inst.instruction |= Rd; | |
13754 | } | |
13755 | else | |
13756 | { | |
13757 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
e2b0ab59 | 13758 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
026d3abb | 13759 | } |
c19d1205 ZW |
13760 | } |
13761 | else | |
13762 | encode_thumb32_shifted_operand (2); | |
13763 | } | |
b99bd4ef | 13764 | |
c19d1205 ZW |
13765 | static void |
13766 | do_t_setend (void) | |
13767 | { | |
12e37cbc MGD |
13768 | if (warn_on_deprecated |
13769 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
5c3696f8 | 13770 | as_tsktsk (_("setend use is deprecated for ARMv8")); |
12e37cbc | 13771 | |
5ee91343 | 13772 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
c19d1205 ZW |
13773 | if (inst.operands[0].imm) |
13774 | inst.instruction |= 0x8; | |
13775 | } | |
b99bd4ef | 13776 | |
c19d1205 ZW |
13777 | static void |
13778 | do_t_shift (void) | |
13779 | { | |
13780 | if (!inst.operands[1].present) | |
13781 | inst.operands[1].reg = inst.operands[0].reg; | |
13782 | ||
13783 | if (unified_syntax) | |
13784 | { | |
3d388997 PB |
13785 | bfd_boolean narrow; |
13786 | int shift_kind; | |
13787 | ||
13788 | switch (inst.instruction) | |
13789 | { | |
13790 | case T_MNEM_asr: | |
13791 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
13792 | case T_MNEM_lsl: | |
13793 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
13794 | case T_MNEM_lsr: | |
13795 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
13796 | case T_MNEM_ror: | |
13797 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
13798 | default: abort (); | |
13799 | } | |
13800 | ||
13801 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
5ee91343 | 13802 | narrow = !in_pred_block (); |
3d388997 | 13803 | else |
5ee91343 | 13804 | narrow = in_pred_block (); |
3d388997 PB |
13805 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
13806 | narrow = FALSE; | |
13807 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
13808 | narrow = FALSE; | |
13809 | if (inst.operands[2].isreg | |
13810 | && (inst.operands[1].reg != inst.operands[0].reg | |
13811 | || inst.operands[2].reg > 7)) | |
13812 | narrow = FALSE; | |
13813 | if (inst.size_req == 4) | |
13814 | narrow = FALSE; | |
13815 | ||
fdfde340 JM |
13816 | reject_bad_reg (inst.operands[0].reg); |
13817 | reject_bad_reg (inst.operands[1].reg); | |
c921be7d | 13818 | |
3d388997 | 13819 | if (!narrow) |
c19d1205 ZW |
13820 | { |
13821 | if (inst.operands[2].isreg) | |
b99bd4ef | 13822 | { |
fdfde340 | 13823 | reject_bad_reg (inst.operands[2].reg); |
c19d1205 ZW |
13824 | inst.instruction = THUMB_OP32 (inst.instruction); |
13825 | inst.instruction |= inst.operands[0].reg << 8; | |
13826 | inst.instruction |= inst.operands[1].reg << 16; | |
13827 | inst.instruction |= inst.operands[2].reg; | |
94342ec3 NC |
13828 | |
13829 | /* PR 12854: Error on extraneous shifts. */ | |
13830 | constraint (inst.operands[2].shifted, | |
13831 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
13832 | } |
13833 | else | |
13834 | { | |
13835 | inst.operands[1].shifted = 1; | |
3d388997 | 13836 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
13837 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
13838 | ? T_MNEM_movs : T_MNEM_mov); | |
13839 | inst.instruction |= inst.operands[0].reg << 8; | |
13840 | encode_thumb32_shifted_operand (1); | |
13841 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
e2b0ab59 | 13842 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
b99bd4ef NC |
13843 | } |
13844 | } | |
13845 | else | |
13846 | { | |
c19d1205 | 13847 | if (inst.operands[2].isreg) |
b99bd4ef | 13848 | { |
3d388997 | 13849 | switch (shift_kind) |
b99bd4ef | 13850 | { |
3d388997 PB |
13851 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
13852 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
13853 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
13854 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 13855 | default: abort (); |
b99bd4ef | 13856 | } |
5f4273c7 | 13857 | |
c19d1205 ZW |
13858 | inst.instruction |= inst.operands[0].reg; |
13859 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
13860 | |
13861 | /* PR 12854: Error on extraneous shifts. */ | |
13862 | constraint (inst.operands[2].shifted, | |
13863 | _("extraneous shift as part of operand to shift insn")); | |
b99bd4ef NC |
13864 | } |
13865 | else | |
13866 | { | |
3d388997 | 13867 | switch (shift_kind) |
b99bd4ef | 13868 | { |
3d388997 PB |
13869 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
13870 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
13871 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 13872 | default: abort (); |
b99bd4ef | 13873 | } |
e2b0ab59 | 13874 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT; |
c19d1205 ZW |
13875 | inst.instruction |= inst.operands[0].reg; |
13876 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
13877 | } |
13878 | } | |
c19d1205 ZW |
13879 | } |
13880 | else | |
13881 | { | |
13882 | constraint (inst.operands[0].reg > 7 | |
13883 | || inst.operands[1].reg > 7, BAD_HIREG); | |
13884 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 13885 | |
c19d1205 ZW |
13886 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
13887 | { | |
13888 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
13889 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
13890 | _("source1 and dest must be same register")); | |
b99bd4ef | 13891 | |
c19d1205 ZW |
13892 | switch (inst.instruction) |
13893 | { | |
13894 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
13895 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
13896 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
13897 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
13898 | default: abort (); | |
13899 | } | |
5f4273c7 | 13900 | |
c19d1205 ZW |
13901 | inst.instruction |= inst.operands[0].reg; |
13902 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
13903 | |
13904 | /* PR 12854: Error on extraneous shifts. */ | |
13905 | constraint (inst.operands[2].shifted, | |
13906 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
13907 | } |
13908 | else | |
b99bd4ef | 13909 | { |
c19d1205 ZW |
13910 | switch (inst.instruction) |
13911 | { | |
13912 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
13913 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
13914 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
13915 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
13916 | default: abort (); | |
13917 | } | |
e2b0ab59 | 13918 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT; |
c19d1205 ZW |
13919 | inst.instruction |= inst.operands[0].reg; |
13920 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
13921 | } |
13922 | } | |
b99bd4ef NC |
13923 | } |
13924 | ||
13925 | static void | |
c19d1205 | 13926 | do_t_simd (void) |
b99bd4ef | 13927 | { |
fdfde340 JM |
13928 | unsigned Rd, Rn, Rm; |
13929 | ||
13930 | Rd = inst.operands[0].reg; | |
13931 | Rn = inst.operands[1].reg; | |
13932 | Rm = inst.operands[2].reg; | |
13933 | ||
13934 | reject_bad_reg (Rd); | |
13935 | reject_bad_reg (Rn); | |
13936 | reject_bad_reg (Rm); | |
13937 | ||
13938 | inst.instruction |= Rd << 8; | |
13939 | inst.instruction |= Rn << 16; | |
13940 | inst.instruction |= Rm; | |
c19d1205 | 13941 | } |
b99bd4ef | 13942 | |
03ee1b7f NC |
13943 | static void |
13944 | do_t_simd2 (void) | |
13945 | { | |
13946 | unsigned Rd, Rn, Rm; | |
13947 | ||
13948 | Rd = inst.operands[0].reg; | |
13949 | Rm = inst.operands[1].reg; | |
13950 | Rn = inst.operands[2].reg; | |
13951 | ||
13952 | reject_bad_reg (Rd); | |
13953 | reject_bad_reg (Rn); | |
13954 | reject_bad_reg (Rm); | |
13955 | ||
13956 | inst.instruction |= Rd << 8; | |
13957 | inst.instruction |= Rn << 16; | |
13958 | inst.instruction |= Rm; | |
13959 | } | |
13960 | ||
c19d1205 | 13961 | static void |
3eb17e6b | 13962 | do_t_smc (void) |
c19d1205 | 13963 | { |
e2b0ab59 | 13964 | unsigned int value = inst.relocs[0].exp.X_add_number; |
f4c65163 MGD |
13965 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a), |
13966 | _("SMC is not permitted on this architecture")); | |
e2b0ab59 | 13967 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 | 13968 | _("expression too complex")); |
ba85f98c BW |
13969 | constraint (value > 0xf, _("immediate too large (bigger than 0xF)")); |
13970 | ||
e2b0ab59 | 13971 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
c19d1205 | 13972 | inst.instruction |= (value & 0x000f) << 16; |
ba85f98c | 13973 | |
24382199 | 13974 | /* PR gas/15623: SMC instructions must be last in an IT block. */ |
5ee91343 | 13975 | set_pred_insn_type_last (); |
c19d1205 | 13976 | } |
b99bd4ef | 13977 | |
90ec0d68 MGD |
13978 | static void |
13979 | do_t_hvc (void) | |
13980 | { | |
e2b0ab59 | 13981 | unsigned int value = inst.relocs[0].exp.X_add_number; |
90ec0d68 | 13982 | |
e2b0ab59 | 13983 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
90ec0d68 MGD |
13984 | inst.instruction |= (value & 0x0fff); |
13985 | inst.instruction |= (value & 0xf000) << 4; | |
13986 | } | |
13987 | ||
c19d1205 | 13988 | static void |
3a21c15a | 13989 | do_t_ssat_usat (int bias) |
c19d1205 | 13990 | { |
fdfde340 JM |
13991 | unsigned Rd, Rn; |
13992 | ||
13993 | Rd = inst.operands[0].reg; | |
13994 | Rn = inst.operands[2].reg; | |
13995 | ||
13996 | reject_bad_reg (Rd); | |
13997 | reject_bad_reg (Rn); | |
13998 | ||
13999 | inst.instruction |= Rd << 8; | |
3a21c15a | 14000 | inst.instruction |= inst.operands[1].imm - bias; |
fdfde340 | 14001 | inst.instruction |= Rn << 16; |
b99bd4ef | 14002 | |
c19d1205 | 14003 | if (inst.operands[3].present) |
b99bd4ef | 14004 | { |
e2b0ab59 | 14005 | offsetT shift_amount = inst.relocs[0].exp.X_add_number; |
3a21c15a | 14006 | |
e2b0ab59 | 14007 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
3a21c15a | 14008 | |
e2b0ab59 | 14009 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 | 14010 | _("expression too complex")); |
b99bd4ef | 14011 | |
3a21c15a | 14012 | if (shift_amount != 0) |
6189168b | 14013 | { |
3a21c15a NC |
14014 | constraint (shift_amount > 31, |
14015 | _("shift expression is too large")); | |
14016 | ||
c19d1205 | 14017 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
3a21c15a NC |
14018 | inst.instruction |= 0x00200000; /* sh bit. */ |
14019 | ||
14020 | inst.instruction |= (shift_amount & 0x1c) << 10; | |
14021 | inst.instruction |= (shift_amount & 0x03) << 6; | |
6189168b NC |
14022 | } |
14023 | } | |
b99bd4ef | 14024 | } |
c921be7d | 14025 | |
3a21c15a NC |
14026 | static void |
14027 | do_t_ssat (void) | |
14028 | { | |
14029 | do_t_ssat_usat (1); | |
14030 | } | |
b99bd4ef | 14031 | |
0dd132b6 | 14032 | static void |
c19d1205 | 14033 | do_t_ssat16 (void) |
0dd132b6 | 14034 | { |
fdfde340 JM |
14035 | unsigned Rd, Rn; |
14036 | ||
14037 | Rd = inst.operands[0].reg; | |
14038 | Rn = inst.operands[2].reg; | |
14039 | ||
14040 | reject_bad_reg (Rd); | |
14041 | reject_bad_reg (Rn); | |
14042 | ||
14043 | inst.instruction |= Rd << 8; | |
c19d1205 | 14044 | inst.instruction |= inst.operands[1].imm - 1; |
fdfde340 | 14045 | inst.instruction |= Rn << 16; |
c19d1205 | 14046 | } |
0dd132b6 | 14047 | |
c19d1205 ZW |
14048 | static void |
14049 | do_t_strex (void) | |
14050 | { | |
14051 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
14052 | || inst.operands[2].postind || inst.operands[2].writeback | |
14053 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
14054 | || inst.operands[2].negative, | |
01cfc07f | 14055 | BAD_ADDR_MODE); |
0dd132b6 | 14056 | |
5be8be5d DG |
14057 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
14058 | ||
c19d1205 ZW |
14059 | inst.instruction |= inst.operands[0].reg << 8; |
14060 | inst.instruction |= inst.operands[1].reg << 12; | |
14061 | inst.instruction |= inst.operands[2].reg << 16; | |
e2b0ab59 | 14062 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8; |
0dd132b6 NC |
14063 | } |
14064 | ||
b99bd4ef | 14065 | static void |
c19d1205 | 14066 | do_t_strexd (void) |
b99bd4ef | 14067 | { |
c19d1205 ZW |
14068 | if (!inst.operands[2].present) |
14069 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 14070 | |
c19d1205 ZW |
14071 | constraint (inst.operands[0].reg == inst.operands[1].reg |
14072 | || inst.operands[0].reg == inst.operands[2].reg | |
f8a8e9d6 | 14073 | || inst.operands[0].reg == inst.operands[3].reg, |
c19d1205 | 14074 | BAD_OVERLAP); |
b99bd4ef | 14075 | |
c19d1205 ZW |
14076 | inst.instruction |= inst.operands[0].reg; |
14077 | inst.instruction |= inst.operands[1].reg << 12; | |
14078 | inst.instruction |= inst.operands[2].reg << 8; | |
14079 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
14080 | } |
14081 | ||
14082 | static void | |
c19d1205 | 14083 | do_t_sxtah (void) |
b99bd4ef | 14084 | { |
fdfde340 JM |
14085 | unsigned Rd, Rn, Rm; |
14086 | ||
14087 | Rd = inst.operands[0].reg; | |
14088 | Rn = inst.operands[1].reg; | |
14089 | Rm = inst.operands[2].reg; | |
14090 | ||
14091 | reject_bad_reg (Rd); | |
14092 | reject_bad_reg (Rn); | |
14093 | reject_bad_reg (Rm); | |
14094 | ||
14095 | inst.instruction |= Rd << 8; | |
14096 | inst.instruction |= Rn << 16; | |
14097 | inst.instruction |= Rm; | |
c19d1205 ZW |
14098 | inst.instruction |= inst.operands[3].imm << 4; |
14099 | } | |
b99bd4ef | 14100 | |
c19d1205 ZW |
14101 | static void |
14102 | do_t_sxth (void) | |
14103 | { | |
fdfde340 JM |
14104 | unsigned Rd, Rm; |
14105 | ||
14106 | Rd = inst.operands[0].reg; | |
14107 | Rm = inst.operands[1].reg; | |
14108 | ||
14109 | reject_bad_reg (Rd); | |
14110 | reject_bad_reg (Rm); | |
c921be7d NC |
14111 | |
14112 | if (inst.instruction <= 0xffff | |
14113 | && inst.size_req != 4 | |
fdfde340 | 14114 | && Rd <= 7 && Rm <= 7 |
c19d1205 | 14115 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) |
b99bd4ef | 14116 | { |
c19d1205 | 14117 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
14118 | inst.instruction |= Rd; |
14119 | inst.instruction |= Rm << 3; | |
b99bd4ef | 14120 | } |
c19d1205 | 14121 | else if (unified_syntax) |
b99bd4ef | 14122 | { |
c19d1205 ZW |
14123 | if (inst.instruction <= 0xffff) |
14124 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
14125 | inst.instruction |= Rd << 8; |
14126 | inst.instruction |= Rm; | |
c19d1205 | 14127 | inst.instruction |= inst.operands[2].imm << 4; |
b99bd4ef | 14128 | } |
c19d1205 | 14129 | else |
b99bd4ef | 14130 | { |
c19d1205 ZW |
14131 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
14132 | _("Thumb encoding does not support rotation")); | |
14133 | constraint (1, BAD_HIREG); | |
b99bd4ef | 14134 | } |
c19d1205 | 14135 | } |
b99bd4ef | 14136 | |
c19d1205 ZW |
14137 | static void |
14138 | do_t_swi (void) | |
14139 | { | |
e2b0ab59 | 14140 | inst.relocs[0].type = BFD_RELOC_ARM_SWI; |
c19d1205 | 14141 | } |
b99bd4ef | 14142 | |
92e90b6e PB |
14143 | static void |
14144 | do_t_tb (void) | |
14145 | { | |
fdfde340 | 14146 | unsigned Rn, Rm; |
92e90b6e PB |
14147 | int half; |
14148 | ||
14149 | half = (inst.instruction & 0x10) != 0; | |
5ee91343 | 14150 | set_pred_insn_type_last (); |
dfa9f0d5 PB |
14151 | constraint (inst.operands[0].immisreg, |
14152 | _("instruction requires register index")); | |
fdfde340 JM |
14153 | |
14154 | Rn = inst.operands[0].reg; | |
14155 | Rm = inst.operands[0].imm; | |
c921be7d | 14156 | |
5c8ed6a4 JW |
14157 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
14158 | constraint (Rn == REG_SP, BAD_SP); | |
fdfde340 JM |
14159 | reject_bad_reg (Rm); |
14160 | ||
92e90b6e PB |
14161 | constraint (!half && inst.operands[0].shifted, |
14162 | _("instruction does not allow shifted index")); | |
fdfde340 | 14163 | inst.instruction |= (Rn << 16) | Rm; |
92e90b6e PB |
14164 | } |
14165 | ||
74db7efb NC |
14166 | static void |
14167 | do_t_udf (void) | |
14168 | { | |
14169 | if (!inst.operands[0].present) | |
14170 | inst.operands[0].imm = 0; | |
14171 | ||
14172 | if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4) | |
14173 | { | |
14174 | constraint (inst.size_req == 2, | |
14175 | _("immediate value out of range")); | |
14176 | inst.instruction = THUMB_OP32 (inst.instruction); | |
14177 | inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4; | |
14178 | inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0; | |
14179 | } | |
14180 | else | |
14181 | { | |
14182 | inst.instruction = THUMB_OP16 (inst.instruction); | |
14183 | inst.instruction |= inst.operands[0].imm; | |
14184 | } | |
14185 | ||
5ee91343 | 14186 | set_pred_insn_type (NEUTRAL_IT_INSN); |
74db7efb NC |
14187 | } |
14188 | ||
14189 | ||
c19d1205 ZW |
14190 | static void |
14191 | do_t_usat (void) | |
14192 | { | |
3a21c15a | 14193 | do_t_ssat_usat (0); |
b99bd4ef NC |
14194 | } |
14195 | ||
14196 | static void | |
c19d1205 | 14197 | do_t_usat16 (void) |
b99bd4ef | 14198 | { |
fdfde340 JM |
14199 | unsigned Rd, Rn; |
14200 | ||
14201 | Rd = inst.operands[0].reg; | |
14202 | Rn = inst.operands[2].reg; | |
14203 | ||
14204 | reject_bad_reg (Rd); | |
14205 | reject_bad_reg (Rn); | |
14206 | ||
14207 | inst.instruction |= Rd << 8; | |
c19d1205 | 14208 | inst.instruction |= inst.operands[1].imm; |
fdfde340 | 14209 | inst.instruction |= Rn << 16; |
b99bd4ef | 14210 | } |
c19d1205 | 14211 | |
e12437dc AV |
14212 | /* Checking the range of the branch offset (VAL) with NBITS bits |
14213 | and IS_SIGNED signedness. Also checks the LSB to be 0. */ | |
14214 | static int | |
14215 | v8_1_branch_value_check (int val, int nbits, int is_signed) | |
14216 | { | |
14217 | gas_assert (nbits > 0 && nbits <= 32); | |
14218 | if (is_signed) | |
14219 | { | |
14220 | int cmp = (1 << (nbits - 1)); | |
14221 | if ((val < -cmp) || (val >= cmp) || (val & 0x01)) | |
14222 | return FAIL; | |
14223 | } | |
14224 | else | |
14225 | { | |
14226 | if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1)) | |
14227 | return FAIL; | |
14228 | } | |
14229 | return SUCCESS; | |
14230 | } | |
14231 | ||
4389b29a AV |
14232 | /* For branches in Armv8.1-M Mainline. */ |
14233 | static void | |
14234 | do_t_branch_future (void) | |
14235 | { | |
14236 | unsigned long insn = inst.instruction; | |
14237 | ||
14238 | inst.instruction = THUMB_OP32 (inst.instruction); | |
14239 | if (inst.operands[0].hasreloc == 0) | |
14240 | { | |
14241 | if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL) | |
14242 | as_bad (BAD_BRANCH_OFF); | |
14243 | ||
14244 | inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23; | |
14245 | } | |
14246 | else | |
14247 | { | |
14248 | inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5; | |
14249 | inst.relocs[0].pc_rel = 1; | |
14250 | } | |
14251 | ||
14252 | switch (insn) | |
14253 | { | |
14254 | case T_MNEM_bf: | |
14255 | if (inst.operands[1].hasreloc == 0) | |
14256 | { | |
14257 | int val = inst.operands[1].imm; | |
14258 | if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL) | |
14259 | as_bad (BAD_BRANCH_OFF); | |
14260 | ||
14261 | int immA = (val & 0x0001f000) >> 12; | |
14262 | int immB = (val & 0x00000ffc) >> 2; | |
14263 | int immC = (val & 0x00000002) >> 1; | |
14264 | inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11); | |
14265 | } | |
14266 | else | |
14267 | { | |
14268 | inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17; | |
14269 | inst.relocs[1].pc_rel = 1; | |
14270 | } | |
14271 | break; | |
14272 | ||
65d1bc05 AV |
14273 | case T_MNEM_bfl: |
14274 | if (inst.operands[1].hasreloc == 0) | |
14275 | { | |
14276 | int val = inst.operands[1].imm; | |
14277 | if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL) | |
14278 | as_bad (BAD_BRANCH_OFF); | |
14279 | ||
14280 | int immA = (val & 0x0007f000) >> 12; | |
14281 | int immB = (val & 0x00000ffc) >> 2; | |
14282 | int immC = (val & 0x00000002) >> 1; | |
14283 | inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11); | |
14284 | } | |
14285 | else | |
14286 | { | |
14287 | inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19; | |
14288 | inst.relocs[1].pc_rel = 1; | |
14289 | } | |
14290 | break; | |
14291 | ||
f6b2b12d AV |
14292 | case T_MNEM_bfcsel: |
14293 | /* Operand 1. */ | |
14294 | if (inst.operands[1].hasreloc == 0) | |
14295 | { | |
14296 | int val = inst.operands[1].imm; | |
14297 | int immA = (val & 0x00001000) >> 12; | |
14298 | int immB = (val & 0x00000ffc) >> 2; | |
14299 | int immC = (val & 0x00000002) >> 1; | |
14300 | inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11); | |
14301 | } | |
14302 | else | |
14303 | { | |
14304 | inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13; | |
14305 | inst.relocs[1].pc_rel = 1; | |
14306 | } | |
14307 | ||
14308 | /* Operand 2. */ | |
14309 | if (inst.operands[2].hasreloc == 0) | |
14310 | { | |
14311 | constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS); | |
14312 | int val2 = inst.operands[2].imm; | |
14313 | int val0 = inst.operands[0].imm & 0x1f; | |
14314 | int diff = val2 - val0; | |
14315 | if (diff == 4) | |
14316 | inst.instruction |= 1 << 17; /* T bit. */ | |
14317 | else if (diff != 2) | |
14318 | as_bad (_("out of range label-relative fixup value")); | |
14319 | } | |
14320 | else | |
14321 | { | |
14322 | constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS); | |
14323 | inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL; | |
14324 | inst.relocs[2].pc_rel = 1; | |
14325 | } | |
14326 | ||
14327 | /* Operand 3. */ | |
14328 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
14329 | inst.instruction |= (inst.operands[3].imm & 0xf) << 18; | |
14330 | break; | |
14331 | ||
f1c7f421 AV |
14332 | case T_MNEM_bfx: |
14333 | case T_MNEM_bflx: | |
14334 | inst.instruction |= inst.operands[1].reg << 16; | |
14335 | break; | |
14336 | ||
4389b29a AV |
14337 | default: abort (); |
14338 | } | |
14339 | } | |
14340 | ||
60f993ce AV |
14341 | /* Helper function for do_t_loloop to handle relocations. */ |
14342 | static void | |
14343 | v8_1_loop_reloc (int is_le) | |
14344 | { | |
14345 | if (inst.relocs[0].exp.X_op == O_constant) | |
14346 | { | |
14347 | int value = inst.relocs[0].exp.X_add_number; | |
14348 | value = (is_le) ? -value : value; | |
14349 | ||
14350 | if (v8_1_branch_value_check (value, 12, FALSE) == FAIL) | |
14351 | as_bad (BAD_BRANCH_OFF); | |
14352 | ||
14353 | int imml, immh; | |
14354 | ||
14355 | immh = (value & 0x00000ffc) >> 2; | |
14356 | imml = (value & 0x00000002) >> 1; | |
14357 | ||
14358 | inst.instruction |= (imml << 11) | (immh << 1); | |
14359 | } | |
14360 | else | |
14361 | { | |
14362 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12; | |
14363 | inst.relocs[0].pc_rel = 1; | |
14364 | } | |
14365 | } | |
14366 | ||
08132bdd SP |
14367 | /* For shifts with four operands in MVE. */ |
14368 | static void | |
14369 | do_mve_scalar_shift1 (void) | |
14370 | { | |
14371 | unsigned int value = inst.operands[2].imm; | |
14372 | ||
14373 | inst.instruction |= inst.operands[0].reg << 16; | |
14374 | inst.instruction |= inst.operands[1].reg << 8; | |
14375 | ||
14376 | /* Setting the bit for saturation. */ | |
14377 | inst.instruction |= ((value == 64) ? 0: 1) << 7; | |
14378 | ||
14379 | /* Assuming Rm is already checked not to be 11x1. */ | |
14380 | constraint (inst.operands[3].reg == inst.operands[0].reg, BAD_OVERLAP); | |
14381 | constraint (inst.operands[3].reg == inst.operands[1].reg, BAD_OVERLAP); | |
14382 | inst.instruction |= inst.operands[3].reg << 12; | |
14383 | } | |
14384 | ||
23d00a41 SD |
14385 | /* For shifts in MVE. */ |
14386 | static void | |
14387 | do_mve_scalar_shift (void) | |
14388 | { | |
14389 | if (!inst.operands[2].present) | |
14390 | { | |
14391 | inst.operands[2] = inst.operands[1]; | |
14392 | inst.operands[1].reg = 0xf; | |
14393 | } | |
14394 | ||
14395 | inst.instruction |= inst.operands[0].reg << 16; | |
14396 | inst.instruction |= inst.operands[1].reg << 8; | |
14397 | ||
14398 | if (inst.operands[2].isreg) | |
14399 | { | |
14400 | /* Assuming Rm is already checked not to be 11x1. */ | |
14401 | constraint (inst.operands[2].reg == inst.operands[0].reg, BAD_OVERLAP); | |
14402 | constraint (inst.operands[2].reg == inst.operands[1].reg, BAD_OVERLAP); | |
14403 | inst.instruction |= inst.operands[2].reg << 12; | |
14404 | } | |
14405 | else | |
14406 | { | |
14407 | /* Assuming imm is already checked as [1,32]. */ | |
14408 | unsigned int value = inst.operands[2].imm; | |
14409 | inst.instruction |= (value & 0x1c) << 10; | |
14410 | inst.instruction |= (value & 0x03) << 6; | |
14411 | /* Change last 4 bits from 0xd to 0xf. */ | |
14412 | inst.instruction |= 0x2; | |
14413 | } | |
14414 | } | |
14415 | ||
a302e574 AV |
14416 | /* MVE instruction encoder helpers. */ |
14417 | #define M_MNEM_vabav 0xee800f01 | |
14418 | #define M_MNEM_vmladav 0xeef00e00 | |
14419 | #define M_MNEM_vmladava 0xeef00e20 | |
14420 | #define M_MNEM_vmladavx 0xeef01e00 | |
14421 | #define M_MNEM_vmladavax 0xeef01e20 | |
14422 | #define M_MNEM_vmlsdav 0xeef00e01 | |
14423 | #define M_MNEM_vmlsdava 0xeef00e21 | |
14424 | #define M_MNEM_vmlsdavx 0xeef01e01 | |
14425 | #define M_MNEM_vmlsdavax 0xeef01e21 | |
886e1c73 AV |
14426 | #define M_MNEM_vmullt 0xee011e00 |
14427 | #define M_MNEM_vmullb 0xee010e00 | |
efd0b310 | 14428 | #define M_MNEM_vctp 0xf000e801 |
35c228db AV |
14429 | #define M_MNEM_vst20 0xfc801e00 |
14430 | #define M_MNEM_vst21 0xfc801e20 | |
14431 | #define M_MNEM_vst40 0xfc801e01 | |
14432 | #define M_MNEM_vst41 0xfc801e21 | |
14433 | #define M_MNEM_vst42 0xfc801e41 | |
14434 | #define M_MNEM_vst43 0xfc801e61 | |
14435 | #define M_MNEM_vld20 0xfc901e00 | |
14436 | #define M_MNEM_vld21 0xfc901e20 | |
14437 | #define M_MNEM_vld40 0xfc901e01 | |
14438 | #define M_MNEM_vld41 0xfc901e21 | |
14439 | #define M_MNEM_vld42 0xfc901e41 | |
14440 | #define M_MNEM_vld43 0xfc901e61 | |
f5f10c66 AV |
14441 | #define M_MNEM_vstrb 0xec000e00 |
14442 | #define M_MNEM_vstrh 0xec000e10 | |
14443 | #define M_MNEM_vstrw 0xec000e40 | |
14444 | #define M_MNEM_vstrd 0xec000e50 | |
14445 | #define M_MNEM_vldrb 0xec100e00 | |
14446 | #define M_MNEM_vldrh 0xec100e10 | |
14447 | #define M_MNEM_vldrw 0xec100e40 | |
14448 | #define M_MNEM_vldrd 0xec100e50 | |
57785aa2 AV |
14449 | #define M_MNEM_vmovlt 0xeea01f40 |
14450 | #define M_MNEM_vmovlb 0xeea00f40 | |
14451 | #define M_MNEM_vmovnt 0xfe311e81 | |
14452 | #define M_MNEM_vmovnb 0xfe310e81 | |
c2dafc2a AV |
14453 | #define M_MNEM_vadc 0xee300f00 |
14454 | #define M_MNEM_vadci 0xee301f00 | |
14455 | #define M_MNEM_vbrsr 0xfe011e60 | |
26c1e780 AV |
14456 | #define M_MNEM_vaddlv 0xee890f00 |
14457 | #define M_MNEM_vaddlva 0xee890f20 | |
14458 | #define M_MNEM_vaddv 0xeef10f00 | |
14459 | #define M_MNEM_vaddva 0xeef10f20 | |
b409bdb6 AV |
14460 | #define M_MNEM_vddup 0xee011f6e |
14461 | #define M_MNEM_vdwdup 0xee011f60 | |
14462 | #define M_MNEM_vidup 0xee010f6e | |
14463 | #define M_MNEM_viwdup 0xee010f60 | |
13ccd4c0 AV |
14464 | #define M_MNEM_vmaxv 0xeee20f00 |
14465 | #define M_MNEM_vmaxav 0xeee00f00 | |
14466 | #define M_MNEM_vminv 0xeee20f80 | |
14467 | #define M_MNEM_vminav 0xeee00f80 | |
93925576 AV |
14468 | #define M_MNEM_vmlaldav 0xee800e00 |
14469 | #define M_MNEM_vmlaldava 0xee800e20 | |
14470 | #define M_MNEM_vmlaldavx 0xee801e00 | |
14471 | #define M_MNEM_vmlaldavax 0xee801e20 | |
14472 | #define M_MNEM_vmlsldav 0xee800e01 | |
14473 | #define M_MNEM_vmlsldava 0xee800e21 | |
14474 | #define M_MNEM_vmlsldavx 0xee801e01 | |
14475 | #define M_MNEM_vmlsldavax 0xee801e21 | |
14476 | #define M_MNEM_vrmlaldavhx 0xee801f00 | |
14477 | #define M_MNEM_vrmlaldavhax 0xee801f20 | |
14478 | #define M_MNEM_vrmlsldavh 0xfe800e01 | |
14479 | #define M_MNEM_vrmlsldavha 0xfe800e21 | |
14480 | #define M_MNEM_vrmlsldavhx 0xfe801e01 | |
14481 | #define M_MNEM_vrmlsldavhax 0xfe801e21 | |
1be7aba3 AV |
14482 | #define M_MNEM_vqmovnt 0xee331e01 |
14483 | #define M_MNEM_vqmovnb 0xee330e01 | |
14484 | #define M_MNEM_vqmovunt 0xee311e81 | |
14485 | #define M_MNEM_vqmovunb 0xee310e81 | |
4aa88b50 AV |
14486 | #define M_MNEM_vshrnt 0xee801fc1 |
14487 | #define M_MNEM_vshrnb 0xee800fc1 | |
14488 | #define M_MNEM_vrshrnt 0xfe801fc1 | |
14489 | #define M_MNEM_vqshrnt 0xee801f40 | |
14490 | #define M_MNEM_vqshrnb 0xee800f40 | |
14491 | #define M_MNEM_vqshrunt 0xee801fc0 | |
14492 | #define M_MNEM_vqshrunb 0xee800fc0 | |
14493 | #define M_MNEM_vrshrnb 0xfe800fc1 | |
14494 | #define M_MNEM_vqrshrnt 0xee801f41 | |
14495 | #define M_MNEM_vqrshrnb 0xee800f41 | |
14496 | #define M_MNEM_vqrshrunt 0xfe801fc0 | |
14497 | #define M_MNEM_vqrshrunb 0xfe800fc0 | |
a302e574 | 14498 | |
5287ad62 | 14499 | /* Neon instruction encoder helpers. */ |
5f4273c7 | 14500 | |
5287ad62 | 14501 | /* Encodings for the different types for various Neon opcodes. */ |
b99bd4ef | 14502 | |
5287ad62 JB |
14503 | /* An "invalid" code for the following tables. */ |
14504 | #define N_INV -1u | |
14505 | ||
14506 | struct neon_tab_entry | |
b99bd4ef | 14507 | { |
5287ad62 JB |
14508 | unsigned integer; |
14509 | unsigned float_or_poly; | |
14510 | unsigned scalar_or_imm; | |
14511 | }; | |
5f4273c7 | 14512 | |
5287ad62 JB |
14513 | /* Map overloaded Neon opcodes to their respective encodings. */ |
14514 | #define NEON_ENC_TAB \ | |
14515 | X(vabd, 0x0000700, 0x1200d00, N_INV), \ | |
5ee91343 | 14516 | X(vabdl, 0x0800700, N_INV, N_INV), \ |
5287ad62 JB |
14517 | X(vmax, 0x0000600, 0x0000f00, N_INV), \ |
14518 | X(vmin, 0x0000610, 0x0200f00, N_INV), \ | |
14519 | X(vpadd, 0x0000b10, 0x1000d00, N_INV), \ | |
14520 | X(vpmax, 0x0000a00, 0x1000f00, N_INV), \ | |
14521 | X(vpmin, 0x0000a10, 0x1200f00, N_INV), \ | |
14522 | X(vadd, 0x0000800, 0x0000d00, N_INV), \ | |
5ee91343 | 14523 | X(vaddl, 0x0800000, N_INV, N_INV), \ |
5287ad62 | 14524 | X(vsub, 0x1000800, 0x0200d00, N_INV), \ |
5ee91343 | 14525 | X(vsubl, 0x0800200, N_INV, N_INV), \ |
5287ad62 JB |
14526 | X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \ |
14527 | X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \ | |
14528 | X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \ | |
14529 | /* Register variants of the following two instructions are encoded as | |
e07e6e58 | 14530 | vcge / vcgt with the operands reversed. */ \ |
92559b5b PB |
14531 | X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \ |
14532 | X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \ | |
62f3b8c8 PB |
14533 | X(vfma, N_INV, 0x0000c10, N_INV), \ |
14534 | X(vfms, N_INV, 0x0200c10, N_INV), \ | |
5287ad62 JB |
14535 | X(vmla, 0x0000900, 0x0000d10, 0x0800040), \ |
14536 | X(vmls, 0x1000900, 0x0200d10, 0x0800440), \ | |
14537 | X(vmul, 0x0000910, 0x1000d10, 0x0800840), \ | |
14538 | X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \ | |
14539 | X(vmlal, 0x0800800, N_INV, 0x0800240), \ | |
14540 | X(vmlsl, 0x0800a00, N_INV, 0x0800640), \ | |
14541 | X(vqdmlal, 0x0800900, N_INV, 0x0800340), \ | |
14542 | X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \ | |
14543 | X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \ | |
14544 | X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \ | |
14545 | X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \ | |
d6b4b13e MW |
14546 | X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \ |
14547 | X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \ | |
5287ad62 JB |
14548 | X(vshl, 0x0000400, N_INV, 0x0800510), \ |
14549 | X(vqshl, 0x0000410, N_INV, 0x0800710), \ | |
14550 | X(vand, 0x0000110, N_INV, 0x0800030), \ | |
14551 | X(vbic, 0x0100110, N_INV, 0x0800030), \ | |
14552 | X(veor, 0x1000110, N_INV, N_INV), \ | |
14553 | X(vorn, 0x0300110, N_INV, 0x0800010), \ | |
14554 | X(vorr, 0x0200110, N_INV, 0x0800010), \ | |
14555 | X(vmvn, 0x1b00580, N_INV, 0x0800030), \ | |
14556 | X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \ | |
14557 | X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \ | |
14558 | X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \ | |
14559 | X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \ | |
14560 | X(vst1, 0x0000000, 0x0800000, N_INV), \ | |
14561 | X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \ | |
14562 | X(vst2, 0x0000100, 0x0800100, N_INV), \ | |
14563 | X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \ | |
14564 | X(vst3, 0x0000200, 0x0800200, N_INV), \ | |
14565 | X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \ | |
14566 | X(vst4, 0x0000300, 0x0800300, N_INV), \ | |
14567 | X(vmovn, 0x1b20200, N_INV, N_INV), \ | |
14568 | X(vtrn, 0x1b20080, N_INV, N_INV), \ | |
14569 | X(vqmovn, 0x1b20200, N_INV, N_INV), \ | |
037e8744 JB |
14570 | X(vqmovun, 0x1b20240, N_INV, N_INV), \ |
14571 | X(vnmul, 0xe200a40, 0xe200b40, N_INV), \ | |
e6655fda PB |
14572 | X(vnmla, 0xe100a40, 0xe100b40, N_INV), \ |
14573 | X(vnmls, 0xe100a00, 0xe100b00, N_INV), \ | |
62f3b8c8 PB |
14574 | X(vfnma, 0xe900a40, 0xe900b40, N_INV), \ |
14575 | X(vfnms, 0xe900a00, 0xe900b00, N_INV), \ | |
037e8744 JB |
14576 | X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \ |
14577 | X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \ | |
14578 | X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \ | |
33399f07 MGD |
14579 | X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \ |
14580 | X(vseleq, 0xe000a00, N_INV, N_INV), \ | |
14581 | X(vselvs, 0xe100a00, N_INV, N_INV), \ | |
14582 | X(vselge, 0xe200a00, N_INV, N_INV), \ | |
73924fbc MGD |
14583 | X(vselgt, 0xe300a00, N_INV, N_INV), \ |
14584 | X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \ | |
7e8e6784 | 14585 | X(vminnm, 0xe800a40, 0x3200f10, N_INV), \ |
30bdf752 MGD |
14586 | X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \ |
14587 | X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \ | |
91ff7894 | 14588 | X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \ |
48adcd8e | 14589 | X(aes, 0x3b00300, N_INV, N_INV), \ |
3c9017d2 MGD |
14590 | X(sha3op, 0x2000c00, N_INV, N_INV), \ |
14591 | X(sha1h, 0x3b902c0, N_INV, N_INV), \ | |
14592 | X(sha2op, 0x3ba0380, N_INV, N_INV) | |
5287ad62 JB |
14593 | |
14594 | enum neon_opc | |
14595 | { | |
14596 | #define X(OPC,I,F,S) N_MNEM_##OPC | |
14597 | NEON_ENC_TAB | |
14598 | #undef X | |
14599 | }; | |
b99bd4ef | 14600 | |
5287ad62 JB |
14601 | static const struct neon_tab_entry neon_enc_tab[] = |
14602 | { | |
14603 | #define X(OPC,I,F,S) { (I), (F), (S) } | |
14604 | NEON_ENC_TAB | |
14605 | #undef X | |
14606 | }; | |
b99bd4ef | 14607 | |
88714cb8 DG |
14608 | /* Do not use these macros; instead, use NEON_ENCODE defined below. */ |
14609 | #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
14610 | #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
14611 | #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
14612 | #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
14613 | #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
14614 | #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
14615 | #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
14616 | #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
14617 | #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
14618 | #define NEON_ENC_SINGLE_(X) \ | |
037e8744 | 14619 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000)) |
88714cb8 | 14620 | #define NEON_ENC_DOUBLE_(X) \ |
037e8744 | 14621 | ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000)) |
33399f07 MGD |
14622 | #define NEON_ENC_FPV8_(X) \ |
14623 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000)) | |
5287ad62 | 14624 | |
88714cb8 DG |
14625 | #define NEON_ENCODE(type, inst) \ |
14626 | do \ | |
14627 | { \ | |
14628 | inst.instruction = NEON_ENC_##type##_ (inst.instruction); \ | |
14629 | inst.is_neon = 1; \ | |
14630 | } \ | |
14631 | while (0) | |
14632 | ||
14633 | #define check_neon_suffixes \ | |
14634 | do \ | |
14635 | { \ | |
14636 | if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \ | |
14637 | { \ | |
14638 | as_bad (_("invalid neon suffix for non neon instruction")); \ | |
14639 | return; \ | |
14640 | } \ | |
14641 | } \ | |
14642 | while (0) | |
14643 | ||
037e8744 JB |
14644 | /* Define shapes for instruction operands. The following mnemonic characters |
14645 | are used in this table: | |
5287ad62 | 14646 | |
037e8744 | 14647 | F - VFP S<n> register |
5287ad62 JB |
14648 | D - Neon D<n> register |
14649 | Q - Neon Q<n> register | |
14650 | I - Immediate | |
14651 | S - Scalar | |
14652 | R - ARM register | |
14653 | L - D<n> register list | |
5f4273c7 | 14654 | |
037e8744 JB |
14655 | This table is used to generate various data: |
14656 | - enumerations of the form NS_DDR to be used as arguments to | |
14657 | neon_select_shape. | |
14658 | - a table classifying shapes into single, double, quad, mixed. | |
5f4273c7 | 14659 | - a table used to drive neon_select_shape. */ |
b99bd4ef | 14660 | |
037e8744 | 14661 | #define NEON_SHAPE_DEF \ |
93925576 | 14662 | X(4, (R, R, Q, Q), QUAD), \ |
b409bdb6 | 14663 | X(4, (Q, R, R, I), QUAD), \ |
57785aa2 AV |
14664 | X(4, (R, R, S, S), QUAD), \ |
14665 | X(4, (S, S, R, R), QUAD), \ | |
b409bdb6 | 14666 | X(3, (Q, R, I), QUAD), \ |
1b883319 AV |
14667 | X(3, (I, Q, Q), QUAD), \ |
14668 | X(3, (I, Q, R), QUAD), \ | |
a302e574 | 14669 | X(3, (R, Q, Q), QUAD), \ |
037e8744 JB |
14670 | X(3, (D, D, D), DOUBLE), \ |
14671 | X(3, (Q, Q, Q), QUAD), \ | |
14672 | X(3, (D, D, I), DOUBLE), \ | |
14673 | X(3, (Q, Q, I), QUAD), \ | |
14674 | X(3, (D, D, S), DOUBLE), \ | |
14675 | X(3, (Q, Q, S), QUAD), \ | |
5ee91343 | 14676 | X(3, (Q, Q, R), QUAD), \ |
26c1e780 AV |
14677 | X(3, (R, R, Q), QUAD), \ |
14678 | X(2, (R, Q), QUAD), \ | |
037e8744 JB |
14679 | X(2, (D, D), DOUBLE), \ |
14680 | X(2, (Q, Q), QUAD), \ | |
14681 | X(2, (D, S), DOUBLE), \ | |
14682 | X(2, (Q, S), QUAD), \ | |
14683 | X(2, (D, R), DOUBLE), \ | |
14684 | X(2, (Q, R), QUAD), \ | |
14685 | X(2, (D, I), DOUBLE), \ | |
14686 | X(2, (Q, I), QUAD), \ | |
14687 | X(3, (D, L, D), DOUBLE), \ | |
14688 | X(2, (D, Q), MIXED), \ | |
14689 | X(2, (Q, D), MIXED), \ | |
14690 | X(3, (D, Q, I), MIXED), \ | |
14691 | X(3, (Q, D, I), MIXED), \ | |
14692 | X(3, (Q, D, D), MIXED), \ | |
14693 | X(3, (D, Q, Q), MIXED), \ | |
14694 | X(3, (Q, Q, D), MIXED), \ | |
14695 | X(3, (Q, D, S), MIXED), \ | |
14696 | X(3, (D, Q, S), MIXED), \ | |
14697 | X(4, (D, D, D, I), DOUBLE), \ | |
14698 | X(4, (Q, Q, Q, I), QUAD), \ | |
c28eeff2 SN |
14699 | X(4, (D, D, S, I), DOUBLE), \ |
14700 | X(4, (Q, Q, S, I), QUAD), \ | |
037e8744 JB |
14701 | X(2, (F, F), SINGLE), \ |
14702 | X(3, (F, F, F), SINGLE), \ | |
14703 | X(2, (F, I), SINGLE), \ | |
14704 | X(2, (F, D), MIXED), \ | |
14705 | X(2, (D, F), MIXED), \ | |
14706 | X(3, (F, F, I), MIXED), \ | |
14707 | X(4, (R, R, F, F), SINGLE), \ | |
14708 | X(4, (F, F, R, R), SINGLE), \ | |
14709 | X(3, (D, R, R), DOUBLE), \ | |
14710 | X(3, (R, R, D), DOUBLE), \ | |
14711 | X(2, (S, R), SINGLE), \ | |
14712 | X(2, (R, S), SINGLE), \ | |
14713 | X(2, (F, R), SINGLE), \ | |
d54af2d0 | 14714 | X(2, (R, F), SINGLE), \ |
1f6234a3 AV |
14715 | /* Used for MVE tail predicated loop instructions. */\ |
14716 | X(2, (R, R), QUAD), \ | |
d54af2d0 RL |
14717 | /* Half float shape supported so far. */\ |
14718 | X (2, (H, D), MIXED), \ | |
14719 | X (2, (D, H), MIXED), \ | |
14720 | X (2, (H, F), MIXED), \ | |
14721 | X (2, (F, H), MIXED), \ | |
14722 | X (2, (H, H), HALF), \ | |
14723 | X (2, (H, R), HALF), \ | |
14724 | X (2, (R, H), HALF), \ | |
14725 | X (2, (H, I), HALF), \ | |
14726 | X (3, (H, H, H), HALF), \ | |
14727 | X (3, (H, F, I), MIXED), \ | |
dec41383 JW |
14728 | X (3, (F, H, I), MIXED), \ |
14729 | X (3, (D, H, H), MIXED), \ | |
14730 | X (3, (D, H, S), MIXED) | |
037e8744 JB |
14731 | |
14732 | #define S2(A,B) NS_##A##B | |
14733 | #define S3(A,B,C) NS_##A##B##C | |
14734 | #define S4(A,B,C,D) NS_##A##B##C##D | |
14735 | ||
14736 | #define X(N, L, C) S##N L | |
14737 | ||
5287ad62 JB |
14738 | enum neon_shape |
14739 | { | |
037e8744 JB |
14740 | NEON_SHAPE_DEF, |
14741 | NS_NULL | |
5287ad62 | 14742 | }; |
b99bd4ef | 14743 | |
037e8744 JB |
14744 | #undef X |
14745 | #undef S2 | |
14746 | #undef S3 | |
14747 | #undef S4 | |
14748 | ||
14749 | enum neon_shape_class | |
14750 | { | |
d54af2d0 | 14751 | SC_HALF, |
037e8744 JB |
14752 | SC_SINGLE, |
14753 | SC_DOUBLE, | |
14754 | SC_QUAD, | |
14755 | SC_MIXED | |
14756 | }; | |
14757 | ||
14758 | #define X(N, L, C) SC_##C | |
14759 | ||
14760 | static enum neon_shape_class neon_shape_class[] = | |
14761 | { | |
14762 | NEON_SHAPE_DEF | |
14763 | }; | |
14764 | ||
14765 | #undef X | |
14766 | ||
14767 | enum neon_shape_el | |
14768 | { | |
d54af2d0 | 14769 | SE_H, |
037e8744 JB |
14770 | SE_F, |
14771 | SE_D, | |
14772 | SE_Q, | |
14773 | SE_I, | |
14774 | SE_S, | |
14775 | SE_R, | |
14776 | SE_L | |
14777 | }; | |
14778 | ||
14779 | /* Register widths of above. */ | |
14780 | static unsigned neon_shape_el_size[] = | |
14781 | { | |
d54af2d0 | 14782 | 16, |
037e8744 JB |
14783 | 32, |
14784 | 64, | |
14785 | 128, | |
14786 | 0, | |
14787 | 32, | |
14788 | 32, | |
14789 | 0 | |
14790 | }; | |
14791 | ||
14792 | struct neon_shape_info | |
14793 | { | |
14794 | unsigned els; | |
14795 | enum neon_shape_el el[NEON_MAX_TYPE_ELS]; | |
14796 | }; | |
14797 | ||
14798 | #define S2(A,B) { SE_##A, SE_##B } | |
14799 | #define S3(A,B,C) { SE_##A, SE_##B, SE_##C } | |
14800 | #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D } | |
14801 | ||
14802 | #define X(N, L, C) { N, S##N L } | |
14803 | ||
14804 | static struct neon_shape_info neon_shape_tab[] = | |
14805 | { | |
14806 | NEON_SHAPE_DEF | |
14807 | }; | |
14808 | ||
14809 | #undef X | |
14810 | #undef S2 | |
14811 | #undef S3 | |
14812 | #undef S4 | |
14813 | ||
5287ad62 JB |
14814 | /* Bit masks used in type checking given instructions. |
14815 | 'N_EQK' means the type must be the same as (or based on in some way) the key | |
14816 | type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is | |
14817 | set, various other bits can be set as well in order to modify the meaning of | |
14818 | the type constraint. */ | |
14819 | ||
14820 | enum neon_type_mask | |
14821 | { | |
8e79c3df CM |
14822 | N_S8 = 0x0000001, |
14823 | N_S16 = 0x0000002, | |
14824 | N_S32 = 0x0000004, | |
14825 | N_S64 = 0x0000008, | |
14826 | N_U8 = 0x0000010, | |
14827 | N_U16 = 0x0000020, | |
14828 | N_U32 = 0x0000040, | |
14829 | N_U64 = 0x0000080, | |
14830 | N_I8 = 0x0000100, | |
14831 | N_I16 = 0x0000200, | |
14832 | N_I32 = 0x0000400, | |
14833 | N_I64 = 0x0000800, | |
14834 | N_8 = 0x0001000, | |
14835 | N_16 = 0x0002000, | |
14836 | N_32 = 0x0004000, | |
14837 | N_64 = 0x0008000, | |
14838 | N_P8 = 0x0010000, | |
14839 | N_P16 = 0x0020000, | |
14840 | N_F16 = 0x0040000, | |
14841 | N_F32 = 0x0080000, | |
14842 | N_F64 = 0x0100000, | |
4f51b4bd | 14843 | N_P64 = 0x0200000, |
c921be7d NC |
14844 | N_KEY = 0x1000000, /* Key element (main type specifier). */ |
14845 | N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */ | |
8e79c3df | 14846 | N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */ |
91ff7894 | 14847 | N_UNT = 0x8000000, /* Must be explicitly untyped. */ |
c921be7d NC |
14848 | N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */ |
14849 | N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */ | |
14850 | N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */ | |
14851 | N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */ | |
14852 | N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */ | |
14853 | N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */ | |
14854 | N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */ | |
5287ad62 | 14855 | N_UTYP = 0, |
4f51b4bd | 14856 | N_MAX_NONSPECIAL = N_P64 |
5287ad62 JB |
14857 | }; |
14858 | ||
dcbf9037 JB |
14859 | #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ) |
14860 | ||
5287ad62 JB |
14861 | #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64) |
14862 | #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32) | |
14863 | #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64) | |
cc933301 JW |
14864 | #define N_S_32 (N_S8 | N_S16 | N_S32) |
14865 | #define N_F_16_32 (N_F16 | N_F32) | |
14866 | #define N_SUF_32 (N_SU_32 | N_F_16_32) | |
5287ad62 | 14867 | #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64) |
cc933301 | 14868 | #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32) |
d54af2d0 | 14869 | #define N_F_ALL (N_F16 | N_F32 | N_F64) |
5ee91343 AV |
14870 | #define N_I_MVE (N_I8 | N_I16 | N_I32) |
14871 | #define N_F_MVE (N_F16 | N_F32) | |
14872 | #define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32) | |
5287ad62 JB |
14873 | |
14874 | /* Pass this as the first type argument to neon_check_type to ignore types | |
14875 | altogether. */ | |
14876 | #define N_IGNORE_TYPE (N_KEY | N_EQK) | |
14877 | ||
037e8744 JB |
14878 | /* Select a "shape" for the current instruction (describing register types or |
14879 | sizes) from a list of alternatives. Return NS_NULL if the current instruction | |
14880 | doesn't fit. For non-polymorphic shapes, checking is usually done as a | |
14881 | function of operand parsing, so this function doesn't need to be called. | |
14882 | Shapes should be listed in order of decreasing length. */ | |
5287ad62 JB |
14883 | |
14884 | static enum neon_shape | |
037e8744 | 14885 | neon_select_shape (enum neon_shape shape, ...) |
5287ad62 | 14886 | { |
037e8744 JB |
14887 | va_list ap; |
14888 | enum neon_shape first_shape = shape; | |
5287ad62 JB |
14889 | |
14890 | /* Fix missing optional operands. FIXME: we don't know at this point how | |
14891 | many arguments we should have, so this makes the assumption that we have | |
14892 | > 1. This is true of all current Neon opcodes, I think, but may not be | |
14893 | true in the future. */ | |
14894 | if (!inst.operands[1].present) | |
14895 | inst.operands[1] = inst.operands[0]; | |
14896 | ||
037e8744 | 14897 | va_start (ap, shape); |
5f4273c7 | 14898 | |
21d799b5 | 14899 | for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int)) |
037e8744 JB |
14900 | { |
14901 | unsigned j; | |
14902 | int matches = 1; | |
14903 | ||
14904 | for (j = 0; j < neon_shape_tab[shape].els; j++) | |
477330fc RM |
14905 | { |
14906 | if (!inst.operands[j].present) | |
14907 | { | |
14908 | matches = 0; | |
14909 | break; | |
14910 | } | |
14911 | ||
14912 | switch (neon_shape_tab[shape].el[j]) | |
14913 | { | |
d54af2d0 RL |
14914 | /* If a .f16, .16, .u16, .s16 type specifier is given over |
14915 | a VFP single precision register operand, it's essentially | |
14916 | means only half of the register is used. | |
14917 | ||
14918 | If the type specifier is given after the mnemonics, the | |
14919 | information is stored in inst.vectype. If the type specifier | |
14920 | is given after register operand, the information is stored | |
14921 | in inst.operands[].vectype. | |
14922 | ||
14923 | When there is only one type specifier, and all the register | |
14924 | operands are the same type of hardware register, the type | |
14925 | specifier applies to all register operands. | |
14926 | ||
14927 | If no type specifier is given, the shape is inferred from | |
14928 | operand information. | |
14929 | ||
14930 | for example: | |
14931 | vadd.f16 s0, s1, s2: NS_HHH | |
14932 | vabs.f16 s0, s1: NS_HH | |
14933 | vmov.f16 s0, r1: NS_HR | |
14934 | vmov.f16 r0, s1: NS_RH | |
14935 | vcvt.f16 r0, s1: NS_RH | |
14936 | vcvt.f16.s32 s2, s2, #29: NS_HFI | |
14937 | vcvt.f16.s32 s2, s2: NS_HF | |
14938 | */ | |
14939 | case SE_H: | |
14940 | if (!(inst.operands[j].isreg | |
14941 | && inst.operands[j].isvec | |
14942 | && inst.operands[j].issingle | |
14943 | && !inst.operands[j].isquad | |
14944 | && ((inst.vectype.elems == 1 | |
14945 | && inst.vectype.el[0].size == 16) | |
14946 | || (inst.vectype.elems > 1 | |
14947 | && inst.vectype.el[j].size == 16) | |
14948 | || (inst.vectype.elems == 0 | |
14949 | && inst.operands[j].vectype.type != NT_invtype | |
14950 | && inst.operands[j].vectype.size == 16)))) | |
14951 | matches = 0; | |
14952 | break; | |
14953 | ||
477330fc RM |
14954 | case SE_F: |
14955 | if (!(inst.operands[j].isreg | |
14956 | && inst.operands[j].isvec | |
14957 | && inst.operands[j].issingle | |
d54af2d0 RL |
14958 | && !inst.operands[j].isquad |
14959 | && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32) | |
14960 | || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32) | |
14961 | || (inst.vectype.elems == 0 | |
14962 | && (inst.operands[j].vectype.size == 32 | |
14963 | || inst.operands[j].vectype.type == NT_invtype))))) | |
477330fc RM |
14964 | matches = 0; |
14965 | break; | |
14966 | ||
14967 | case SE_D: | |
14968 | if (!(inst.operands[j].isreg | |
14969 | && inst.operands[j].isvec | |
14970 | && !inst.operands[j].isquad | |
14971 | && !inst.operands[j].issingle)) | |
14972 | matches = 0; | |
14973 | break; | |
14974 | ||
14975 | case SE_R: | |
14976 | if (!(inst.operands[j].isreg | |
14977 | && !inst.operands[j].isvec)) | |
14978 | matches = 0; | |
14979 | break; | |
14980 | ||
14981 | case SE_Q: | |
14982 | if (!(inst.operands[j].isreg | |
14983 | && inst.operands[j].isvec | |
14984 | && inst.operands[j].isquad | |
14985 | && !inst.operands[j].issingle)) | |
14986 | matches = 0; | |
14987 | break; | |
14988 | ||
14989 | case SE_I: | |
14990 | if (!(!inst.operands[j].isreg | |
14991 | && !inst.operands[j].isscalar)) | |
14992 | matches = 0; | |
14993 | break; | |
14994 | ||
14995 | case SE_S: | |
14996 | if (!(!inst.operands[j].isreg | |
14997 | && inst.operands[j].isscalar)) | |
14998 | matches = 0; | |
14999 | break; | |
15000 | ||
15001 | case SE_L: | |
15002 | break; | |
15003 | } | |
3fde54a2 JZ |
15004 | if (!matches) |
15005 | break; | |
477330fc | 15006 | } |
ad6cec43 MGD |
15007 | if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present)) |
15008 | /* We've matched all the entries in the shape table, and we don't | |
15009 | have any left over operands which have not been matched. */ | |
477330fc | 15010 | break; |
037e8744 | 15011 | } |
5f4273c7 | 15012 | |
037e8744 | 15013 | va_end (ap); |
5287ad62 | 15014 | |
037e8744 JB |
15015 | if (shape == NS_NULL && first_shape != NS_NULL) |
15016 | first_error (_("invalid instruction shape")); | |
5287ad62 | 15017 | |
037e8744 JB |
15018 | return shape; |
15019 | } | |
5287ad62 | 15020 | |
037e8744 JB |
15021 | /* True if SHAPE is predominantly a quadword operation (most of the time, this |
15022 | means the Q bit should be set). */ | |
15023 | ||
15024 | static int | |
15025 | neon_quad (enum neon_shape shape) | |
15026 | { | |
15027 | return neon_shape_class[shape] == SC_QUAD; | |
5287ad62 | 15028 | } |
037e8744 | 15029 | |
5287ad62 JB |
15030 | static void |
15031 | neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type, | |
477330fc | 15032 | unsigned *g_size) |
5287ad62 JB |
15033 | { |
15034 | /* Allow modification to be made to types which are constrained to be | |
15035 | based on the key element, based on bits set alongside N_EQK. */ | |
15036 | if ((typebits & N_EQK) != 0) | |
15037 | { | |
15038 | if ((typebits & N_HLF) != 0) | |
15039 | *g_size /= 2; | |
15040 | else if ((typebits & N_DBL) != 0) | |
15041 | *g_size *= 2; | |
15042 | if ((typebits & N_SGN) != 0) | |
15043 | *g_type = NT_signed; | |
15044 | else if ((typebits & N_UNS) != 0) | |
477330fc | 15045 | *g_type = NT_unsigned; |
5287ad62 | 15046 | else if ((typebits & N_INT) != 0) |
477330fc | 15047 | *g_type = NT_integer; |
5287ad62 | 15048 | else if ((typebits & N_FLT) != 0) |
477330fc | 15049 | *g_type = NT_float; |
dcbf9037 | 15050 | else if ((typebits & N_SIZ) != 0) |
477330fc | 15051 | *g_type = NT_untyped; |
5287ad62 JB |
15052 | } |
15053 | } | |
5f4273c7 | 15054 | |
5287ad62 JB |
15055 | /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key" |
15056 | operand type, i.e. the single type specified in a Neon instruction when it | |
15057 | is the only one given. */ | |
15058 | ||
15059 | static struct neon_type_el | |
15060 | neon_type_promote (struct neon_type_el *key, unsigned thisarg) | |
15061 | { | |
15062 | struct neon_type_el dest = *key; | |
5f4273c7 | 15063 | |
9c2799c2 | 15064 | gas_assert ((thisarg & N_EQK) != 0); |
5f4273c7 | 15065 | |
5287ad62 JB |
15066 | neon_modify_type_size (thisarg, &dest.type, &dest.size); |
15067 | ||
15068 | return dest; | |
15069 | } | |
15070 | ||
15071 | /* Convert Neon type and size into compact bitmask representation. */ | |
15072 | ||
15073 | static enum neon_type_mask | |
15074 | type_chk_of_el_type (enum neon_el_type type, unsigned size) | |
15075 | { | |
15076 | switch (type) | |
15077 | { | |
15078 | case NT_untyped: | |
15079 | switch (size) | |
477330fc RM |
15080 | { |
15081 | case 8: return N_8; | |
15082 | case 16: return N_16; | |
15083 | case 32: return N_32; | |
15084 | case 64: return N_64; | |
15085 | default: ; | |
15086 | } | |
5287ad62 JB |
15087 | break; |
15088 | ||
15089 | case NT_integer: | |
15090 | switch (size) | |
477330fc RM |
15091 | { |
15092 | case 8: return N_I8; | |
15093 | case 16: return N_I16; | |
15094 | case 32: return N_I32; | |
15095 | case 64: return N_I64; | |
15096 | default: ; | |
15097 | } | |
5287ad62 JB |
15098 | break; |
15099 | ||
15100 | case NT_float: | |
037e8744 | 15101 | switch (size) |
477330fc | 15102 | { |
8e79c3df | 15103 | case 16: return N_F16; |
477330fc RM |
15104 | case 32: return N_F32; |
15105 | case 64: return N_F64; | |
15106 | default: ; | |
15107 | } | |
5287ad62 JB |
15108 | break; |
15109 | ||
15110 | case NT_poly: | |
15111 | switch (size) | |
477330fc RM |
15112 | { |
15113 | case 8: return N_P8; | |
15114 | case 16: return N_P16; | |
4f51b4bd | 15115 | case 64: return N_P64; |
477330fc RM |
15116 | default: ; |
15117 | } | |
5287ad62 JB |
15118 | break; |
15119 | ||
15120 | case NT_signed: | |
15121 | switch (size) | |
477330fc RM |
15122 | { |
15123 | case 8: return N_S8; | |
15124 | case 16: return N_S16; | |
15125 | case 32: return N_S32; | |
15126 | case 64: return N_S64; | |
15127 | default: ; | |
15128 | } | |
5287ad62 JB |
15129 | break; |
15130 | ||
15131 | case NT_unsigned: | |
15132 | switch (size) | |
477330fc RM |
15133 | { |
15134 | case 8: return N_U8; | |
15135 | case 16: return N_U16; | |
15136 | case 32: return N_U32; | |
15137 | case 64: return N_U64; | |
15138 | default: ; | |
15139 | } | |
5287ad62 JB |
15140 | break; |
15141 | ||
15142 | default: ; | |
15143 | } | |
5f4273c7 | 15144 | |
5287ad62 JB |
15145 | return N_UTYP; |
15146 | } | |
15147 | ||
15148 | /* Convert compact Neon bitmask type representation to a type and size. Only | |
15149 | handles the case where a single bit is set in the mask. */ | |
15150 | ||
dcbf9037 | 15151 | static int |
5287ad62 | 15152 | el_type_of_type_chk (enum neon_el_type *type, unsigned *size, |
477330fc | 15153 | enum neon_type_mask mask) |
5287ad62 | 15154 | { |
dcbf9037 JB |
15155 | if ((mask & N_EQK) != 0) |
15156 | return FAIL; | |
15157 | ||
5287ad62 JB |
15158 | if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0) |
15159 | *size = 8; | |
c70a8987 | 15160 | else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0) |
5287ad62 | 15161 | *size = 16; |
dcbf9037 | 15162 | else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0) |
5287ad62 | 15163 | *size = 32; |
4f51b4bd | 15164 | else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0) |
5287ad62 | 15165 | *size = 64; |
dcbf9037 JB |
15166 | else |
15167 | return FAIL; | |
15168 | ||
5287ad62 JB |
15169 | if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0) |
15170 | *type = NT_signed; | |
dcbf9037 | 15171 | else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0) |
5287ad62 | 15172 | *type = NT_unsigned; |
dcbf9037 | 15173 | else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0) |
5287ad62 | 15174 | *type = NT_integer; |
dcbf9037 | 15175 | else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0) |
5287ad62 | 15176 | *type = NT_untyped; |
4f51b4bd | 15177 | else if ((mask & (N_P8 | N_P16 | N_P64)) != 0) |
5287ad62 | 15178 | *type = NT_poly; |
d54af2d0 | 15179 | else if ((mask & (N_F_ALL)) != 0) |
5287ad62 | 15180 | *type = NT_float; |
dcbf9037 JB |
15181 | else |
15182 | return FAIL; | |
5f4273c7 | 15183 | |
dcbf9037 | 15184 | return SUCCESS; |
5287ad62 JB |
15185 | } |
15186 | ||
15187 | /* Modify a bitmask of allowed types. This is only needed for type | |
15188 | relaxation. */ | |
15189 | ||
15190 | static unsigned | |
15191 | modify_types_allowed (unsigned allowed, unsigned mods) | |
15192 | { | |
15193 | unsigned size; | |
15194 | enum neon_el_type type; | |
15195 | unsigned destmask; | |
15196 | int i; | |
5f4273c7 | 15197 | |
5287ad62 | 15198 | destmask = 0; |
5f4273c7 | 15199 | |
5287ad62 JB |
15200 | for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1) |
15201 | { | |
21d799b5 | 15202 | if (el_type_of_type_chk (&type, &size, |
477330fc RM |
15203 | (enum neon_type_mask) (allowed & i)) == SUCCESS) |
15204 | { | |
15205 | neon_modify_type_size (mods, &type, &size); | |
15206 | destmask |= type_chk_of_el_type (type, size); | |
15207 | } | |
5287ad62 | 15208 | } |
5f4273c7 | 15209 | |
5287ad62 JB |
15210 | return destmask; |
15211 | } | |
15212 | ||
15213 | /* Check type and return type classification. | |
15214 | The manual states (paraphrase): If one datatype is given, it indicates the | |
15215 | type given in: | |
15216 | - the second operand, if there is one | |
15217 | - the operand, if there is no second operand | |
15218 | - the result, if there are no operands. | |
15219 | This isn't quite good enough though, so we use a concept of a "key" datatype | |
15220 | which is set on a per-instruction basis, which is the one which matters when | |
15221 | only one data type is written. | |
15222 | Note: this function has side-effects (e.g. filling in missing operands). All | |
037e8744 | 15223 | Neon instructions should call it before performing bit encoding. */ |
5287ad62 JB |
15224 | |
15225 | static struct neon_type_el | |
15226 | neon_check_type (unsigned els, enum neon_shape ns, ...) | |
15227 | { | |
15228 | va_list ap; | |
15229 | unsigned i, pass, key_el = 0; | |
15230 | unsigned types[NEON_MAX_TYPE_ELS]; | |
15231 | enum neon_el_type k_type = NT_invtype; | |
15232 | unsigned k_size = -1u; | |
15233 | struct neon_type_el badtype = {NT_invtype, -1}; | |
15234 | unsigned key_allowed = 0; | |
15235 | ||
15236 | /* Optional registers in Neon instructions are always (not) in operand 1. | |
15237 | Fill in the missing operand here, if it was omitted. */ | |
15238 | if (els > 1 && !inst.operands[1].present) | |
15239 | inst.operands[1] = inst.operands[0]; | |
15240 | ||
15241 | /* Suck up all the varargs. */ | |
15242 | va_start (ap, ns); | |
15243 | for (i = 0; i < els; i++) | |
15244 | { | |
15245 | unsigned thisarg = va_arg (ap, unsigned); | |
15246 | if (thisarg == N_IGNORE_TYPE) | |
477330fc RM |
15247 | { |
15248 | va_end (ap); | |
15249 | return badtype; | |
15250 | } | |
5287ad62 JB |
15251 | types[i] = thisarg; |
15252 | if ((thisarg & N_KEY) != 0) | |
477330fc | 15253 | key_el = i; |
5287ad62 JB |
15254 | } |
15255 | va_end (ap); | |
15256 | ||
dcbf9037 JB |
15257 | if (inst.vectype.elems > 0) |
15258 | for (i = 0; i < els; i++) | |
15259 | if (inst.operands[i].vectype.type != NT_invtype) | |
477330fc RM |
15260 | { |
15261 | first_error (_("types specified in both the mnemonic and operands")); | |
15262 | return badtype; | |
15263 | } | |
dcbf9037 | 15264 | |
5287ad62 JB |
15265 | /* Duplicate inst.vectype elements here as necessary. |
15266 | FIXME: No idea if this is exactly the same as the ARM assembler, | |
15267 | particularly when an insn takes one register and one non-register | |
15268 | operand. */ | |
15269 | if (inst.vectype.elems == 1 && els > 1) | |
15270 | { | |
15271 | unsigned j; | |
15272 | inst.vectype.elems = els; | |
15273 | inst.vectype.el[key_el] = inst.vectype.el[0]; | |
15274 | for (j = 0; j < els; j++) | |
477330fc RM |
15275 | if (j != key_el) |
15276 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
15277 | types[j]); | |
dcbf9037 JB |
15278 | } |
15279 | else if (inst.vectype.elems == 0 && els > 0) | |
15280 | { | |
15281 | unsigned j; | |
15282 | /* No types were given after the mnemonic, so look for types specified | |
477330fc RM |
15283 | after each operand. We allow some flexibility here; as long as the |
15284 | "key" operand has a type, we can infer the others. */ | |
dcbf9037 | 15285 | for (j = 0; j < els; j++) |
477330fc RM |
15286 | if (inst.operands[j].vectype.type != NT_invtype) |
15287 | inst.vectype.el[j] = inst.operands[j].vectype; | |
dcbf9037 JB |
15288 | |
15289 | if (inst.operands[key_el].vectype.type != NT_invtype) | |
477330fc RM |
15290 | { |
15291 | for (j = 0; j < els; j++) | |
15292 | if (inst.operands[j].vectype.type == NT_invtype) | |
15293 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
15294 | types[j]); | |
15295 | } | |
dcbf9037 | 15296 | else |
477330fc RM |
15297 | { |
15298 | first_error (_("operand types can't be inferred")); | |
15299 | return badtype; | |
15300 | } | |
5287ad62 JB |
15301 | } |
15302 | else if (inst.vectype.elems != els) | |
15303 | { | |
dcbf9037 | 15304 | first_error (_("type specifier has the wrong number of parts")); |
5287ad62 JB |
15305 | return badtype; |
15306 | } | |
15307 | ||
15308 | for (pass = 0; pass < 2; pass++) | |
15309 | { | |
15310 | for (i = 0; i < els; i++) | |
477330fc RM |
15311 | { |
15312 | unsigned thisarg = types[i]; | |
15313 | unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0) | |
15314 | ? modify_types_allowed (key_allowed, thisarg) : thisarg; | |
15315 | enum neon_el_type g_type = inst.vectype.el[i].type; | |
15316 | unsigned g_size = inst.vectype.el[i].size; | |
15317 | ||
15318 | /* Decay more-specific signed & unsigned types to sign-insensitive | |
5287ad62 | 15319 | integer types if sign-specific variants are unavailable. */ |
477330fc | 15320 | if ((g_type == NT_signed || g_type == NT_unsigned) |
5287ad62 JB |
15321 | && (types_allowed & N_SU_ALL) == 0) |
15322 | g_type = NT_integer; | |
15323 | ||
477330fc | 15324 | /* If only untyped args are allowed, decay any more specific types to |
5287ad62 JB |
15325 | them. Some instructions only care about signs for some element |
15326 | sizes, so handle that properly. */ | |
477330fc | 15327 | if (((types_allowed & N_UNT) == 0) |
91ff7894 MGD |
15328 | && ((g_size == 8 && (types_allowed & N_8) != 0) |
15329 | || (g_size == 16 && (types_allowed & N_16) != 0) | |
15330 | || (g_size == 32 && (types_allowed & N_32) != 0) | |
15331 | || (g_size == 64 && (types_allowed & N_64) != 0))) | |
5287ad62 JB |
15332 | g_type = NT_untyped; |
15333 | ||
477330fc RM |
15334 | if (pass == 0) |
15335 | { | |
15336 | if ((thisarg & N_KEY) != 0) | |
15337 | { | |
15338 | k_type = g_type; | |
15339 | k_size = g_size; | |
15340 | key_allowed = thisarg & ~N_KEY; | |
cc933301 JW |
15341 | |
15342 | /* Check architecture constraint on FP16 extension. */ | |
15343 | if (k_size == 16 | |
15344 | && k_type == NT_float | |
15345 | && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)) | |
15346 | { | |
15347 | inst.error = _(BAD_FP16); | |
15348 | return badtype; | |
15349 | } | |
477330fc RM |
15350 | } |
15351 | } | |
15352 | else | |
15353 | { | |
15354 | if ((thisarg & N_VFP) != 0) | |
15355 | { | |
15356 | enum neon_shape_el regshape; | |
15357 | unsigned regwidth, match; | |
99b253c5 NC |
15358 | |
15359 | /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */ | |
15360 | if (ns == NS_NULL) | |
15361 | { | |
15362 | first_error (_("invalid instruction shape")); | |
15363 | return badtype; | |
15364 | } | |
477330fc RM |
15365 | regshape = neon_shape_tab[ns].el[i]; |
15366 | regwidth = neon_shape_el_size[regshape]; | |
15367 | ||
15368 | /* In VFP mode, operands must match register widths. If we | |
15369 | have a key operand, use its width, else use the width of | |
15370 | the current operand. */ | |
15371 | if (k_size != -1u) | |
15372 | match = k_size; | |
15373 | else | |
15374 | match = g_size; | |
15375 | ||
9db2f6b4 RL |
15376 | /* FP16 will use a single precision register. */ |
15377 | if (regwidth == 32 && match == 16) | |
15378 | { | |
15379 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)) | |
15380 | match = regwidth; | |
15381 | else | |
15382 | { | |
15383 | inst.error = _(BAD_FP16); | |
15384 | return badtype; | |
15385 | } | |
15386 | } | |
15387 | ||
477330fc RM |
15388 | if (regwidth != match) |
15389 | { | |
15390 | first_error (_("operand size must match register width")); | |
15391 | return badtype; | |
15392 | } | |
15393 | } | |
15394 | ||
15395 | if ((thisarg & N_EQK) == 0) | |
15396 | { | |
15397 | unsigned given_type = type_chk_of_el_type (g_type, g_size); | |
15398 | ||
15399 | if ((given_type & types_allowed) == 0) | |
15400 | { | |
a302e574 | 15401 | first_error (BAD_SIMD_TYPE); |
477330fc RM |
15402 | return badtype; |
15403 | } | |
15404 | } | |
15405 | else | |
15406 | { | |
15407 | enum neon_el_type mod_k_type = k_type; | |
15408 | unsigned mod_k_size = k_size; | |
15409 | neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size); | |
15410 | if (g_type != mod_k_type || g_size != mod_k_size) | |
15411 | { | |
15412 | first_error (_("inconsistent types in Neon instruction")); | |
15413 | return badtype; | |
15414 | } | |
15415 | } | |
15416 | } | |
15417 | } | |
5287ad62 JB |
15418 | } |
15419 | ||
15420 | return inst.vectype.el[key_el]; | |
15421 | } | |
15422 | ||
037e8744 | 15423 | /* Neon-style VFP instruction forwarding. */ |
5287ad62 | 15424 | |
037e8744 JB |
15425 | /* Thumb VFP instructions have 0xE in the condition field. */ |
15426 | ||
15427 | static void | |
15428 | do_vfp_cond_or_thumb (void) | |
5287ad62 | 15429 | { |
88714cb8 DG |
15430 | inst.is_neon = 1; |
15431 | ||
5287ad62 | 15432 | if (thumb_mode) |
037e8744 | 15433 | inst.instruction |= 0xe0000000; |
5287ad62 | 15434 | else |
037e8744 | 15435 | inst.instruction |= inst.cond << 28; |
5287ad62 JB |
15436 | } |
15437 | ||
037e8744 JB |
15438 | /* Look up and encode a simple mnemonic, for use as a helper function for the |
15439 | Neon-style VFP syntax. This avoids duplication of bits of the insns table, | |
15440 | etc. It is assumed that operand parsing has already been done, and that the | |
15441 | operands are in the form expected by the given opcode (this isn't necessarily | |
15442 | the same as the form in which they were parsed, hence some massaging must | |
15443 | take place before this function is called). | |
15444 | Checks current arch version against that in the looked-up opcode. */ | |
5287ad62 | 15445 | |
037e8744 JB |
15446 | static void |
15447 | do_vfp_nsyn_opcode (const char *opname) | |
5287ad62 | 15448 | { |
037e8744 | 15449 | const struct asm_opcode *opcode; |
5f4273c7 | 15450 | |
21d799b5 | 15451 | opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname); |
5287ad62 | 15452 | |
037e8744 JB |
15453 | if (!opcode) |
15454 | abort (); | |
5287ad62 | 15455 | |
037e8744 | 15456 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, |
477330fc RM |
15457 | thumb_mode ? *opcode->tvariant : *opcode->avariant), |
15458 | _(BAD_FPU)); | |
5287ad62 | 15459 | |
88714cb8 DG |
15460 | inst.is_neon = 1; |
15461 | ||
037e8744 JB |
15462 | if (thumb_mode) |
15463 | { | |
15464 | inst.instruction = opcode->tvalue; | |
15465 | opcode->tencode (); | |
15466 | } | |
15467 | else | |
15468 | { | |
15469 | inst.instruction = (inst.cond << 28) | opcode->avalue; | |
15470 | opcode->aencode (); | |
15471 | } | |
15472 | } | |
5287ad62 JB |
15473 | |
15474 | static void | |
037e8744 | 15475 | do_vfp_nsyn_add_sub (enum neon_shape rs) |
5287ad62 | 15476 | { |
037e8744 JB |
15477 | int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd; |
15478 | ||
9db2f6b4 | 15479 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 JB |
15480 | { |
15481 | if (is_add) | |
477330fc | 15482 | do_vfp_nsyn_opcode ("fadds"); |
037e8744 | 15483 | else |
477330fc | 15484 | do_vfp_nsyn_opcode ("fsubs"); |
9db2f6b4 RL |
15485 | |
15486 | /* ARMv8.2 fp16 instruction. */ | |
15487 | if (rs == NS_HHH) | |
15488 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
15489 | } |
15490 | else | |
15491 | { | |
15492 | if (is_add) | |
477330fc | 15493 | do_vfp_nsyn_opcode ("faddd"); |
037e8744 | 15494 | else |
477330fc | 15495 | do_vfp_nsyn_opcode ("fsubd"); |
037e8744 JB |
15496 | } |
15497 | } | |
15498 | ||
15499 | /* Check operand types to see if this is a VFP instruction, and if so call | |
15500 | PFN (). */ | |
15501 | ||
15502 | static int | |
15503 | try_vfp_nsyn (int args, void (*pfn) (enum neon_shape)) | |
15504 | { | |
15505 | enum neon_shape rs; | |
15506 | struct neon_type_el et; | |
15507 | ||
15508 | switch (args) | |
15509 | { | |
15510 | case 2: | |
9db2f6b4 RL |
15511 | rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL); |
15512 | et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP); | |
037e8744 | 15513 | break; |
5f4273c7 | 15514 | |
037e8744 | 15515 | case 3: |
9db2f6b4 RL |
15516 | rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
15517 | et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
15518 | N_F_ALL | N_KEY | N_VFP); | |
037e8744 JB |
15519 | break; |
15520 | ||
15521 | default: | |
15522 | abort (); | |
15523 | } | |
15524 | ||
15525 | if (et.type != NT_invtype) | |
15526 | { | |
15527 | pfn (rs); | |
15528 | return SUCCESS; | |
15529 | } | |
037e8744 | 15530 | |
99b253c5 | 15531 | inst.error = NULL; |
037e8744 JB |
15532 | return FAIL; |
15533 | } | |
15534 | ||
15535 | static void | |
15536 | do_vfp_nsyn_mla_mls (enum neon_shape rs) | |
15537 | { | |
15538 | int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla; | |
5f4273c7 | 15539 | |
9db2f6b4 | 15540 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 JB |
15541 | { |
15542 | if (is_mla) | |
477330fc | 15543 | do_vfp_nsyn_opcode ("fmacs"); |
037e8744 | 15544 | else |
477330fc | 15545 | do_vfp_nsyn_opcode ("fnmacs"); |
9db2f6b4 RL |
15546 | |
15547 | /* ARMv8.2 fp16 instruction. */ | |
15548 | if (rs == NS_HHH) | |
15549 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
15550 | } |
15551 | else | |
15552 | { | |
15553 | if (is_mla) | |
477330fc | 15554 | do_vfp_nsyn_opcode ("fmacd"); |
037e8744 | 15555 | else |
477330fc | 15556 | do_vfp_nsyn_opcode ("fnmacd"); |
037e8744 JB |
15557 | } |
15558 | } | |
15559 | ||
62f3b8c8 PB |
15560 | static void |
15561 | do_vfp_nsyn_fma_fms (enum neon_shape rs) | |
15562 | { | |
15563 | int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma; | |
15564 | ||
9db2f6b4 | 15565 | if (rs == NS_FFF || rs == NS_HHH) |
62f3b8c8 PB |
15566 | { |
15567 | if (is_fma) | |
477330fc | 15568 | do_vfp_nsyn_opcode ("ffmas"); |
62f3b8c8 | 15569 | else |
477330fc | 15570 | do_vfp_nsyn_opcode ("ffnmas"); |
9db2f6b4 RL |
15571 | |
15572 | /* ARMv8.2 fp16 instruction. */ | |
15573 | if (rs == NS_HHH) | |
15574 | do_scalar_fp16_v82_encode (); | |
62f3b8c8 PB |
15575 | } |
15576 | else | |
15577 | { | |
15578 | if (is_fma) | |
477330fc | 15579 | do_vfp_nsyn_opcode ("ffmad"); |
62f3b8c8 | 15580 | else |
477330fc | 15581 | do_vfp_nsyn_opcode ("ffnmad"); |
62f3b8c8 PB |
15582 | } |
15583 | } | |
15584 | ||
037e8744 JB |
15585 | static void |
15586 | do_vfp_nsyn_mul (enum neon_shape rs) | |
15587 | { | |
9db2f6b4 RL |
15588 | if (rs == NS_FFF || rs == NS_HHH) |
15589 | { | |
15590 | do_vfp_nsyn_opcode ("fmuls"); | |
15591 | ||
15592 | /* ARMv8.2 fp16 instruction. */ | |
15593 | if (rs == NS_HHH) | |
15594 | do_scalar_fp16_v82_encode (); | |
15595 | } | |
037e8744 JB |
15596 | else |
15597 | do_vfp_nsyn_opcode ("fmuld"); | |
15598 | } | |
15599 | ||
15600 | static void | |
15601 | do_vfp_nsyn_abs_neg (enum neon_shape rs) | |
15602 | { | |
15603 | int is_neg = (inst.instruction & 0x80) != 0; | |
9db2f6b4 | 15604 | neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY); |
037e8744 | 15605 | |
9db2f6b4 | 15606 | if (rs == NS_FF || rs == NS_HH) |
037e8744 JB |
15607 | { |
15608 | if (is_neg) | |
477330fc | 15609 | do_vfp_nsyn_opcode ("fnegs"); |
037e8744 | 15610 | else |
477330fc | 15611 | do_vfp_nsyn_opcode ("fabss"); |
9db2f6b4 RL |
15612 | |
15613 | /* ARMv8.2 fp16 instruction. */ | |
15614 | if (rs == NS_HH) | |
15615 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
15616 | } |
15617 | else | |
15618 | { | |
15619 | if (is_neg) | |
477330fc | 15620 | do_vfp_nsyn_opcode ("fnegd"); |
037e8744 | 15621 | else |
477330fc | 15622 | do_vfp_nsyn_opcode ("fabsd"); |
037e8744 JB |
15623 | } |
15624 | } | |
15625 | ||
15626 | /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision | |
15627 | insns belong to Neon, and are handled elsewhere. */ | |
15628 | ||
15629 | static void | |
15630 | do_vfp_nsyn_ldm_stm (int is_dbmode) | |
15631 | { | |
15632 | int is_ldm = (inst.instruction & (1 << 20)) != 0; | |
15633 | if (is_ldm) | |
15634 | { | |
15635 | if (is_dbmode) | |
477330fc | 15636 | do_vfp_nsyn_opcode ("fldmdbs"); |
037e8744 | 15637 | else |
477330fc | 15638 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 JB |
15639 | } |
15640 | else | |
15641 | { | |
15642 | if (is_dbmode) | |
477330fc | 15643 | do_vfp_nsyn_opcode ("fstmdbs"); |
037e8744 | 15644 | else |
477330fc | 15645 | do_vfp_nsyn_opcode ("fstmias"); |
037e8744 JB |
15646 | } |
15647 | } | |
15648 | ||
037e8744 JB |
15649 | static void |
15650 | do_vfp_nsyn_sqrt (void) | |
15651 | { | |
9db2f6b4 RL |
15652 | enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL); |
15653 | neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP); | |
5f4273c7 | 15654 | |
9db2f6b4 RL |
15655 | if (rs == NS_FF || rs == NS_HH) |
15656 | { | |
15657 | do_vfp_nsyn_opcode ("fsqrts"); | |
15658 | ||
15659 | /* ARMv8.2 fp16 instruction. */ | |
15660 | if (rs == NS_HH) | |
15661 | do_scalar_fp16_v82_encode (); | |
15662 | } | |
037e8744 JB |
15663 | else |
15664 | do_vfp_nsyn_opcode ("fsqrtd"); | |
15665 | } | |
15666 | ||
15667 | static void | |
15668 | do_vfp_nsyn_div (void) | |
15669 | { | |
9db2f6b4 | 15670 | enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
037e8744 | 15671 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, |
9db2f6b4 | 15672 | N_F_ALL | N_KEY | N_VFP); |
5f4273c7 | 15673 | |
9db2f6b4 RL |
15674 | if (rs == NS_FFF || rs == NS_HHH) |
15675 | { | |
15676 | do_vfp_nsyn_opcode ("fdivs"); | |
15677 | ||
15678 | /* ARMv8.2 fp16 instruction. */ | |
15679 | if (rs == NS_HHH) | |
15680 | do_scalar_fp16_v82_encode (); | |
15681 | } | |
037e8744 JB |
15682 | else |
15683 | do_vfp_nsyn_opcode ("fdivd"); | |
15684 | } | |
15685 | ||
15686 | static void | |
15687 | do_vfp_nsyn_nmul (void) | |
15688 | { | |
9db2f6b4 | 15689 | enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
037e8744 | 15690 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, |
9db2f6b4 | 15691 | N_F_ALL | N_KEY | N_VFP); |
5f4273c7 | 15692 | |
9db2f6b4 | 15693 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 | 15694 | { |
88714cb8 | 15695 | NEON_ENCODE (SINGLE, inst); |
037e8744 | 15696 | do_vfp_sp_dyadic (); |
9db2f6b4 RL |
15697 | |
15698 | /* ARMv8.2 fp16 instruction. */ | |
15699 | if (rs == NS_HHH) | |
15700 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
15701 | } |
15702 | else | |
15703 | { | |
88714cb8 | 15704 | NEON_ENCODE (DOUBLE, inst); |
037e8744 JB |
15705 | do_vfp_dp_rd_rn_rm (); |
15706 | } | |
15707 | do_vfp_cond_or_thumb (); | |
9db2f6b4 | 15708 | |
037e8744 JB |
15709 | } |
15710 | ||
1b883319 AV |
15711 | /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3 |
15712 | (0, 1, 2, 3). */ | |
15713 | ||
15714 | static unsigned | |
15715 | neon_logbits (unsigned x) | |
15716 | { | |
15717 | return ffs (x) - 4; | |
15718 | } | |
15719 | ||
15720 | #define LOW4(R) ((R) & 0xf) | |
15721 | #define HI1(R) (((R) >> 4) & 1) | |
15722 | ||
15723 | static unsigned | |
15724 | mve_get_vcmp_vpt_cond (struct neon_type_el et) | |
15725 | { | |
15726 | switch (et.type) | |
15727 | { | |
15728 | default: | |
15729 | first_error (BAD_EL_TYPE); | |
15730 | return 0; | |
15731 | case NT_float: | |
15732 | switch (inst.operands[0].imm) | |
15733 | { | |
15734 | default: | |
15735 | first_error (_("invalid condition")); | |
15736 | return 0; | |
15737 | case 0x0: | |
15738 | /* eq. */ | |
15739 | return 0; | |
15740 | case 0x1: | |
15741 | /* ne. */ | |
15742 | return 1; | |
15743 | case 0xa: | |
15744 | /* ge/ */ | |
15745 | return 4; | |
15746 | case 0xb: | |
15747 | /* lt. */ | |
15748 | return 5; | |
15749 | case 0xc: | |
15750 | /* gt. */ | |
15751 | return 6; | |
15752 | case 0xd: | |
15753 | /* le. */ | |
15754 | return 7; | |
15755 | } | |
15756 | case NT_integer: | |
15757 | /* only accept eq and ne. */ | |
15758 | if (inst.operands[0].imm > 1) | |
15759 | { | |
15760 | first_error (_("invalid condition")); | |
15761 | return 0; | |
15762 | } | |
15763 | return inst.operands[0].imm; | |
15764 | case NT_unsigned: | |
15765 | if (inst.operands[0].imm == 0x2) | |
15766 | return 2; | |
15767 | else if (inst.operands[0].imm == 0x8) | |
15768 | return 3; | |
15769 | else | |
15770 | { | |
15771 | first_error (_("invalid condition")); | |
15772 | return 0; | |
15773 | } | |
15774 | case NT_signed: | |
15775 | switch (inst.operands[0].imm) | |
15776 | { | |
15777 | default: | |
15778 | first_error (_("invalid condition")); | |
15779 | return 0; | |
15780 | case 0xa: | |
15781 | /* ge. */ | |
15782 | return 4; | |
15783 | case 0xb: | |
15784 | /* lt. */ | |
15785 | return 5; | |
15786 | case 0xc: | |
15787 | /* gt. */ | |
15788 | return 6; | |
15789 | case 0xd: | |
15790 | /* le. */ | |
15791 | return 7; | |
15792 | } | |
15793 | } | |
15794 | /* Should be unreachable. */ | |
15795 | abort (); | |
15796 | } | |
15797 | ||
efd0b310 SP |
15798 | /* For VCTP (create vector tail predicate) in MVE. */ |
15799 | static void | |
15800 | do_mve_vctp (void) | |
15801 | { | |
15802 | int dt = 0; | |
15803 | unsigned size = 0x0; | |
15804 | ||
15805 | if (inst.cond > COND_ALWAYS) | |
15806 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
15807 | else | |
15808 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
15809 | ||
15810 | /* This is a typical MVE instruction which has no type but have size 8, 16, | |
15811 | 32 and 64. For instructions with no type, inst.vectype.el[j].type is set | |
15812 | to NT_untyped and size is updated in inst.vectype.el[j].size. */ | |
15813 | if ((inst.operands[0].present) && (inst.vectype.el[0].type == NT_untyped)) | |
15814 | dt = inst.vectype.el[0].size; | |
15815 | ||
15816 | /* Setting this does not indicate an actual NEON instruction, but only | |
15817 | indicates that the mnemonic accepts neon-style type suffixes. */ | |
15818 | inst.is_neon = 1; | |
15819 | ||
15820 | switch (dt) | |
15821 | { | |
15822 | case 8: | |
15823 | break; | |
15824 | case 16: | |
15825 | size = 0x1; break; | |
15826 | case 32: | |
15827 | size = 0x2; break; | |
15828 | case 64: | |
15829 | size = 0x3; break; | |
15830 | default: | |
15831 | first_error (_("Type is not allowed for this instruction")); | |
15832 | } | |
15833 | inst.instruction |= size << 20; | |
15834 | inst.instruction |= inst.operands[0].reg << 16; | |
15835 | } | |
15836 | ||
1b883319 AV |
15837 | static void |
15838 | do_mve_vpt (void) | |
15839 | { | |
15840 | /* We are dealing with a vector predicated block. */ | |
15841 | if (inst.operands[0].present) | |
15842 | { | |
15843 | enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL); | |
15844 | struct neon_type_el et | |
15845 | = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32, | |
15846 | N_EQK); | |
15847 | ||
15848 | unsigned fcond = mve_get_vcmp_vpt_cond (et); | |
15849 | ||
15850 | constraint (inst.operands[1].reg > 14, MVE_BAD_QREG); | |
15851 | ||
15852 | if (et.type == NT_invtype) | |
15853 | return; | |
15854 | ||
15855 | if (et.type == NT_float) | |
15856 | { | |
15857 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext), | |
15858 | BAD_FPU); | |
15859 | constraint (et.size != 16 && et.size != 32, BAD_EL_TYPE); | |
15860 | inst.instruction |= (et.size == 16) << 28; | |
15861 | inst.instruction |= 0x3 << 20; | |
15862 | } | |
15863 | else | |
15864 | { | |
15865 | constraint (et.size != 8 && et.size != 16 && et.size != 32, | |
15866 | BAD_EL_TYPE); | |
15867 | inst.instruction |= 1 << 28; | |
15868 | inst.instruction |= neon_logbits (et.size) << 20; | |
15869 | } | |
15870 | ||
15871 | if (inst.operands[2].isquad) | |
15872 | { | |
15873 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
15874 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
15875 | inst.instruction |= (fcond & 0x2) >> 1; | |
15876 | } | |
15877 | else | |
15878 | { | |
15879 | if (inst.operands[2].reg == REG_SP) | |
15880 | as_tsktsk (MVE_BAD_SP); | |
15881 | inst.instruction |= 1 << 6; | |
15882 | inst.instruction |= (fcond & 0x2) << 4; | |
15883 | inst.instruction |= inst.operands[2].reg; | |
15884 | } | |
15885 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
15886 | inst.instruction |= (fcond & 0x4) << 10; | |
15887 | inst.instruction |= (fcond & 0x1) << 7; | |
15888 | ||
15889 | } | |
15890 | set_pred_insn_type (VPT_INSN); | |
15891 | now_pred.cc = 0; | |
15892 | now_pred.mask = ((inst.instruction & 0x00400000) >> 19) | |
15893 | | ((inst.instruction & 0xe000) >> 13); | |
15894 | now_pred.warn_deprecated = FALSE; | |
15895 | now_pred.type = VECTOR_PRED; | |
15896 | inst.is_neon = 1; | |
15897 | } | |
15898 | ||
15899 | static void | |
15900 | do_mve_vcmp (void) | |
15901 | { | |
15902 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU); | |
15903 | if (!inst.operands[1].isreg || !inst.operands[1].isquad) | |
15904 | first_error (_(reg_expected_msgs[REG_TYPE_MQ])); | |
15905 | if (!inst.operands[2].present) | |
15906 | first_error (_("MVE vector or ARM register expected")); | |
15907 | constraint (inst.operands[1].reg > 14, MVE_BAD_QREG); | |
15908 | ||
15909 | /* Deal with 'else' conditional MVE's vcmp, it will be parsed as vcmpe. */ | |
15910 | if ((inst.instruction & 0xffffffff) == N_MNEM_vcmpe | |
15911 | && inst.operands[1].isquad) | |
15912 | { | |
15913 | inst.instruction = N_MNEM_vcmp; | |
15914 | inst.cond = 0x10; | |
15915 | } | |
15916 | ||
15917 | if (inst.cond > COND_ALWAYS) | |
15918 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
15919 | else | |
15920 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
15921 | ||
15922 | enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL); | |
15923 | struct neon_type_el et | |
15924 | = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32, | |
15925 | N_EQK); | |
15926 | ||
15927 | constraint (rs == NS_IQR && inst.operands[2].reg == REG_PC | |
15928 | && !inst.operands[2].iszr, BAD_PC); | |
15929 | ||
15930 | unsigned fcond = mve_get_vcmp_vpt_cond (et); | |
15931 | ||
15932 | inst.instruction = 0xee010f00; | |
15933 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
15934 | inst.instruction |= (fcond & 0x4) << 10; | |
15935 | inst.instruction |= (fcond & 0x1) << 7; | |
15936 | if (et.type == NT_float) | |
15937 | { | |
15938 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext), | |
15939 | BAD_FPU); | |
15940 | inst.instruction |= (et.size == 16) << 28; | |
15941 | inst.instruction |= 0x3 << 20; | |
15942 | } | |
15943 | else | |
15944 | { | |
15945 | inst.instruction |= 1 << 28; | |
15946 | inst.instruction |= neon_logbits (et.size) << 20; | |
15947 | } | |
15948 | if (inst.operands[2].isquad) | |
15949 | { | |
15950 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
15951 | inst.instruction |= (fcond & 0x2) >> 1; | |
15952 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
15953 | } | |
15954 | else | |
15955 | { | |
15956 | if (inst.operands[2].reg == REG_SP) | |
15957 | as_tsktsk (MVE_BAD_SP); | |
15958 | inst.instruction |= 1 << 6; | |
15959 | inst.instruction |= (fcond & 0x2) << 4; | |
15960 | inst.instruction |= inst.operands[2].reg; | |
15961 | } | |
15962 | ||
15963 | inst.is_neon = 1; | |
15964 | return; | |
15965 | } | |
15966 | ||
935295b5 AV |
15967 | static void |
15968 | do_mve_vmaxa_vmina (void) | |
15969 | { | |
15970 | if (inst.cond > COND_ALWAYS) | |
15971 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
15972 | else | |
15973 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
15974 | ||
15975 | enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL); | |
15976 | struct neon_type_el et | |
15977 | = neon_check_type (2, rs, N_EQK, N_KEY | N_S8 | N_S16 | N_S32); | |
15978 | ||
15979 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15980 | inst.instruction |= neon_logbits (et.size) << 18; | |
15981 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15982 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15983 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15984 | inst.is_neon = 1; | |
15985 | } | |
15986 | ||
f30ee27c AV |
15987 | static void |
15988 | do_mve_vfmas (void) | |
15989 | { | |
15990 | enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL); | |
15991 | struct neon_type_el et | |
15992 | = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, N_EQK); | |
15993 | ||
15994 | if (inst.cond > COND_ALWAYS) | |
15995 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
15996 | else | |
15997 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
15998 | ||
15999 | if (inst.operands[2].reg == REG_SP) | |
16000 | as_tsktsk (MVE_BAD_SP); | |
16001 | else if (inst.operands[2].reg == REG_PC) | |
16002 | as_tsktsk (MVE_BAD_PC); | |
16003 | ||
16004 | inst.instruction |= (et.size == 16) << 28; | |
16005 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16006 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16007 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16008 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16009 | inst.instruction |= inst.operands[2].reg; | |
16010 | inst.is_neon = 1; | |
16011 | } | |
16012 | ||
b409bdb6 AV |
16013 | static void |
16014 | do_mve_viddup (void) | |
16015 | { | |
16016 | if (inst.cond > COND_ALWAYS) | |
16017 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
16018 | else | |
16019 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
16020 | ||
16021 | unsigned imm = inst.relocs[0].exp.X_add_number; | |
16022 | constraint (imm != 1 && imm != 2 && imm != 4 && imm != 8, | |
16023 | _("immediate must be either 1, 2, 4 or 8")); | |
16024 | ||
16025 | enum neon_shape rs; | |
16026 | struct neon_type_el et; | |
16027 | unsigned Rm; | |
16028 | if (inst.instruction == M_MNEM_vddup || inst.instruction == M_MNEM_vidup) | |
16029 | { | |
16030 | rs = neon_select_shape (NS_QRI, NS_NULL); | |
16031 | et = neon_check_type (2, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK); | |
16032 | Rm = 7; | |
16033 | } | |
16034 | else | |
16035 | { | |
16036 | constraint ((inst.operands[2].reg % 2) != 1, BAD_EVEN); | |
16037 | if (inst.operands[2].reg == REG_SP) | |
16038 | as_tsktsk (MVE_BAD_SP); | |
16039 | else if (inst.operands[2].reg == REG_PC) | |
16040 | first_error (BAD_PC); | |
16041 | ||
16042 | rs = neon_select_shape (NS_QRRI, NS_NULL); | |
16043 | et = neon_check_type (3, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK, N_EQK); | |
16044 | Rm = inst.operands[2].reg >> 1; | |
16045 | } | |
16046 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16047 | inst.instruction |= neon_logbits (et.size) << 20; | |
16048 | inst.instruction |= inst.operands[1].reg << 16; | |
16049 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16050 | inst.instruction |= (imm > 2) << 7; | |
16051 | inst.instruction |= Rm << 1; | |
16052 | inst.instruction |= (imm == 2 || imm == 8); | |
16053 | inst.is_neon = 1; | |
16054 | } | |
16055 | ||
2d78f95b AV |
16056 | static void |
16057 | do_mve_vmlas (void) | |
16058 | { | |
16059 | enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL); | |
16060 | struct neon_type_el et | |
16061 | = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY); | |
16062 | ||
16063 | if (inst.operands[2].reg == REG_PC) | |
16064 | as_tsktsk (MVE_BAD_PC); | |
16065 | else if (inst.operands[2].reg == REG_SP) | |
16066 | as_tsktsk (MVE_BAD_SP); | |
16067 | ||
16068 | if (inst.cond > COND_ALWAYS) | |
16069 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
16070 | else | |
16071 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
16072 | ||
16073 | inst.instruction |= (et.type == NT_unsigned) << 28; | |
16074 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16075 | inst.instruction |= neon_logbits (et.size) << 20; | |
16076 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16077 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16078 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16079 | inst.instruction |= inst.operands[2].reg; | |
16080 | inst.is_neon = 1; | |
16081 | } | |
16082 | ||
acca5630 AV |
16083 | static void |
16084 | do_mve_vshll (void) | |
16085 | { | |
16086 | struct neon_type_el et | |
16087 | = neon_check_type (2, NS_QQI, N_EQK, N_S8 | N_U8 | N_S16 | N_U16 | N_KEY); | |
16088 | ||
16089 | if (inst.cond > COND_ALWAYS) | |
16090 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
16091 | else | |
16092 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
16093 | ||
16094 | int imm = inst.operands[2].imm; | |
16095 | constraint (imm < 1 || (unsigned)imm > et.size, | |
16096 | _("immediate value out of range")); | |
16097 | ||
16098 | if ((unsigned)imm == et.size) | |
16099 | { | |
16100 | inst.instruction |= neon_logbits (et.size) << 18; | |
16101 | inst.instruction |= 0x110001; | |
16102 | } | |
16103 | else | |
16104 | { | |
16105 | inst.instruction |= (et.size + imm) << 16; | |
16106 | inst.instruction |= 0x800140; | |
16107 | } | |
16108 | ||
16109 | inst.instruction |= (et.type == NT_unsigned) << 28; | |
16110 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16111 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16112 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16113 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16114 | inst.is_neon = 1; | |
16115 | } | |
16116 | ||
16117 | static void | |
16118 | do_mve_vshlc (void) | |
16119 | { | |
16120 | if (inst.cond > COND_ALWAYS) | |
16121 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
16122 | else | |
16123 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
16124 | ||
16125 | if (inst.operands[1].reg == REG_PC) | |
16126 | as_tsktsk (MVE_BAD_PC); | |
16127 | else if (inst.operands[1].reg == REG_SP) | |
16128 | as_tsktsk (MVE_BAD_SP); | |
16129 | ||
16130 | int imm = inst.operands[2].imm; | |
16131 | constraint (imm < 1 || imm > 32, _("immediate value out of range")); | |
16132 | ||
16133 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16134 | inst.instruction |= (imm & 0x1f) << 16; | |
16135 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16136 | inst.instruction |= inst.operands[1].reg; | |
16137 | inst.is_neon = 1; | |
16138 | } | |
16139 | ||
4aa88b50 AV |
16140 | static void |
16141 | do_mve_vshrn (void) | |
16142 | { | |
16143 | unsigned types; | |
16144 | switch (inst.instruction) | |
16145 | { | |
16146 | case M_MNEM_vshrnt: | |
16147 | case M_MNEM_vshrnb: | |
16148 | case M_MNEM_vrshrnt: | |
16149 | case M_MNEM_vrshrnb: | |
16150 | types = N_I16 | N_I32; | |
16151 | break; | |
16152 | case M_MNEM_vqshrnt: | |
16153 | case M_MNEM_vqshrnb: | |
16154 | case M_MNEM_vqrshrnt: | |
16155 | case M_MNEM_vqrshrnb: | |
16156 | types = N_U16 | N_U32 | N_S16 | N_S32; | |
16157 | break; | |
16158 | case M_MNEM_vqshrunt: | |
16159 | case M_MNEM_vqshrunb: | |
16160 | case M_MNEM_vqrshrunt: | |
16161 | case M_MNEM_vqrshrunb: | |
16162 | types = N_S16 | N_S32; | |
16163 | break; | |
16164 | default: | |
16165 | abort (); | |
16166 | } | |
16167 | ||
16168 | struct neon_type_el et = neon_check_type (2, NS_QQI, N_EQK, types | N_KEY); | |
16169 | ||
16170 | if (inst.cond > COND_ALWAYS) | |
16171 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
16172 | else | |
16173 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
16174 | ||
16175 | unsigned Qd = inst.operands[0].reg; | |
16176 | unsigned Qm = inst.operands[1].reg; | |
16177 | unsigned imm = inst.operands[2].imm; | |
16178 | constraint (imm < 1 || ((unsigned) imm) > (et.size / 2), | |
16179 | et.size == 16 | |
16180 | ? _("immediate operand expected in the range [1,8]") | |
16181 | : _("immediate operand expected in the range [1,16]")); | |
16182 | ||
16183 | inst.instruction |= (et.type == NT_unsigned) << 28; | |
16184 | inst.instruction |= HI1 (Qd) << 22; | |
16185 | inst.instruction |= (et.size - imm) << 16; | |
16186 | inst.instruction |= LOW4 (Qd) << 12; | |
16187 | inst.instruction |= HI1 (Qm) << 5; | |
16188 | inst.instruction |= LOW4 (Qm); | |
16189 | inst.is_neon = 1; | |
16190 | } | |
16191 | ||
1be7aba3 AV |
16192 | static void |
16193 | do_mve_vqmovn (void) | |
16194 | { | |
16195 | struct neon_type_el et; | |
16196 | if (inst.instruction == M_MNEM_vqmovnt | |
16197 | || inst.instruction == M_MNEM_vqmovnb) | |
16198 | et = neon_check_type (2, NS_QQ, N_EQK, | |
16199 | N_U16 | N_U32 | N_S16 | N_S32 | N_KEY); | |
16200 | else | |
16201 | et = neon_check_type (2, NS_QQ, N_EQK, N_S16 | N_S32 | N_KEY); | |
16202 | ||
16203 | if (inst.cond > COND_ALWAYS) | |
16204 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
16205 | else | |
16206 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
16207 | ||
16208 | inst.instruction |= (et.type == NT_unsigned) << 28; | |
16209 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16210 | inst.instruction |= (et.size == 32) << 18; | |
16211 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16212 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16213 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16214 | inst.is_neon = 1; | |
16215 | } | |
16216 | ||
3063888e AV |
16217 | static void |
16218 | do_mve_vpsel (void) | |
16219 | { | |
16220 | neon_select_shape (NS_QQQ, NS_NULL); | |
16221 | ||
16222 | if (inst.cond > COND_ALWAYS) | |
16223 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
16224 | else | |
16225 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
16226 | ||
16227 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16228 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16229 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16230 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16231 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
16232 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16233 | inst.is_neon = 1; | |
16234 | } | |
16235 | ||
16236 | static void | |
16237 | do_mve_vpnot (void) | |
16238 | { | |
16239 | if (inst.cond > COND_ALWAYS) | |
16240 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
16241 | else | |
16242 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
16243 | } | |
16244 | ||
935295b5 AV |
16245 | static void |
16246 | do_mve_vmaxnma_vminnma (void) | |
16247 | { | |
16248 | enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL); | |
16249 | struct neon_type_el et | |
16250 | = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY); | |
16251 | ||
16252 | if (inst.cond > COND_ALWAYS) | |
16253 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
16254 | else | |
16255 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
16256 | ||
16257 | inst.instruction |= (et.size == 16) << 28; | |
16258 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16259 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16260 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16261 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16262 | inst.is_neon = 1; | |
16263 | } | |
16264 | ||
5d281bf0 AV |
16265 | static void |
16266 | do_mve_vcmul (void) | |
16267 | { | |
16268 | enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL); | |
16269 | struct neon_type_el et | |
16270 | = neon_check_type (3, rs, N_EQK, N_EQK, N_F_MVE | N_KEY); | |
16271 | ||
16272 | if (inst.cond > COND_ALWAYS) | |
16273 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
16274 | else | |
16275 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
16276 | ||
16277 | unsigned rot = inst.relocs[0].exp.X_add_number; | |
16278 | constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270, | |
16279 | _("immediate out of range")); | |
16280 | ||
16281 | if (et.size == 32 && (inst.operands[0].reg == inst.operands[1].reg | |
16282 | || inst.operands[0].reg == inst.operands[2].reg)) | |
16283 | as_tsktsk (BAD_MVE_SRCDEST); | |
16284 | ||
16285 | inst.instruction |= (et.size == 32) << 28; | |
16286 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16287 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16288 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16289 | inst.instruction |= (rot > 90) << 12; | |
16290 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16291 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
16292 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16293 | inst.instruction |= (rot == 90 || rot == 270); | |
16294 | inst.is_neon = 1; | |
16295 | } | |
16296 | ||
1f6234a3 AV |
16297 | /* To handle the Low Overhead Loop instructions |
16298 | in Armv8.1-M Mainline and MVE. */ | |
16299 | static void | |
16300 | do_t_loloop (void) | |
16301 | { | |
16302 | unsigned long insn = inst.instruction; | |
16303 | ||
16304 | inst.instruction = THUMB_OP32 (inst.instruction); | |
16305 | ||
16306 | if (insn == T_MNEM_lctp) | |
16307 | return; | |
16308 | ||
16309 | set_pred_insn_type (MVE_OUTSIDE_PRED_INSN); | |
16310 | ||
16311 | if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp) | |
16312 | { | |
16313 | struct neon_type_el et | |
16314 | = neon_check_type (2, NS_RR, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
16315 | inst.instruction |= neon_logbits (et.size) << 20; | |
16316 | inst.is_neon = 1; | |
16317 | } | |
16318 | ||
16319 | switch (insn) | |
16320 | { | |
16321 | case T_MNEM_letp: | |
16322 | constraint (!inst.operands[0].present, | |
16323 | _("expected LR")); | |
16324 | /* fall through. */ | |
16325 | case T_MNEM_le: | |
16326 | /* le <label>. */ | |
16327 | if (!inst.operands[0].present) | |
16328 | inst.instruction |= 1 << 21; | |
16329 | ||
16330 | v8_1_loop_reloc (TRUE); | |
16331 | break; | |
16332 | ||
16333 | case T_MNEM_wls: | |
16334 | case T_MNEM_wlstp: | |
16335 | v8_1_loop_reloc (FALSE); | |
16336 | /* fall through. */ | |
16337 | case T_MNEM_dlstp: | |
16338 | case T_MNEM_dls: | |
16339 | constraint (inst.operands[1].isreg != 1, BAD_ARGS); | |
16340 | ||
16341 | if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp) | |
16342 | constraint (inst.operands[1].reg == REG_PC, BAD_PC); | |
16343 | else if (inst.operands[1].reg == REG_PC) | |
16344 | as_tsktsk (MVE_BAD_PC); | |
16345 | if (inst.operands[1].reg == REG_SP) | |
16346 | as_tsktsk (MVE_BAD_SP); | |
16347 | ||
16348 | inst.instruction |= (inst.operands[1].reg << 16); | |
16349 | break; | |
16350 | ||
16351 | default: | |
16352 | abort (); | |
16353 | } | |
16354 | } | |
16355 | ||
16356 | ||
037e8744 JB |
16357 | static void |
16358 | do_vfp_nsyn_cmp (void) | |
16359 | { | |
9db2f6b4 | 16360 | enum neon_shape rs; |
1b883319 AV |
16361 | if (!inst.operands[0].isreg) |
16362 | { | |
16363 | do_mve_vcmp (); | |
16364 | return; | |
16365 | } | |
16366 | else | |
16367 | { | |
16368 | constraint (inst.operands[2].present, BAD_SYNTAX); | |
16369 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd), | |
16370 | BAD_FPU); | |
16371 | } | |
16372 | ||
037e8744 JB |
16373 | if (inst.operands[1].isreg) |
16374 | { | |
9db2f6b4 RL |
16375 | rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL); |
16376 | neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP); | |
5f4273c7 | 16377 | |
9db2f6b4 | 16378 | if (rs == NS_FF || rs == NS_HH) |
477330fc RM |
16379 | { |
16380 | NEON_ENCODE (SINGLE, inst); | |
16381 | do_vfp_sp_monadic (); | |
16382 | } | |
037e8744 | 16383 | else |
477330fc RM |
16384 | { |
16385 | NEON_ENCODE (DOUBLE, inst); | |
16386 | do_vfp_dp_rd_rm (); | |
16387 | } | |
037e8744 JB |
16388 | } |
16389 | else | |
16390 | { | |
9db2f6b4 RL |
16391 | rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL); |
16392 | neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK); | |
037e8744 JB |
16393 | |
16394 | switch (inst.instruction & 0x0fffffff) | |
477330fc RM |
16395 | { |
16396 | case N_MNEM_vcmp: | |
16397 | inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp; | |
16398 | break; | |
16399 | case N_MNEM_vcmpe: | |
16400 | inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe; | |
16401 | break; | |
16402 | default: | |
16403 | abort (); | |
16404 | } | |
5f4273c7 | 16405 | |
9db2f6b4 | 16406 | if (rs == NS_FI || rs == NS_HI) |
477330fc RM |
16407 | { |
16408 | NEON_ENCODE (SINGLE, inst); | |
16409 | do_vfp_sp_compare_z (); | |
16410 | } | |
037e8744 | 16411 | else |
477330fc RM |
16412 | { |
16413 | NEON_ENCODE (DOUBLE, inst); | |
16414 | do_vfp_dp_rd (); | |
16415 | } | |
037e8744 JB |
16416 | } |
16417 | do_vfp_cond_or_thumb (); | |
9db2f6b4 RL |
16418 | |
16419 | /* ARMv8.2 fp16 instruction. */ | |
16420 | if (rs == NS_HI || rs == NS_HH) | |
16421 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
16422 | } |
16423 | ||
16424 | static void | |
16425 | nsyn_insert_sp (void) | |
16426 | { | |
16427 | inst.operands[1] = inst.operands[0]; | |
16428 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
fdfde340 | 16429 | inst.operands[0].reg = REG_SP; |
037e8744 JB |
16430 | inst.operands[0].isreg = 1; |
16431 | inst.operands[0].writeback = 1; | |
16432 | inst.operands[0].present = 1; | |
16433 | } | |
16434 | ||
16435 | static void | |
16436 | do_vfp_nsyn_push (void) | |
16437 | { | |
16438 | nsyn_insert_sp (); | |
b126985e NC |
16439 | |
16440 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
16441 | _("register list must contain at least 1 and at most 16 " | |
16442 | "registers")); | |
16443 | ||
037e8744 JB |
16444 | if (inst.operands[1].issingle) |
16445 | do_vfp_nsyn_opcode ("fstmdbs"); | |
16446 | else | |
16447 | do_vfp_nsyn_opcode ("fstmdbd"); | |
16448 | } | |
16449 | ||
16450 | static void | |
16451 | do_vfp_nsyn_pop (void) | |
16452 | { | |
16453 | nsyn_insert_sp (); | |
b126985e NC |
16454 | |
16455 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
16456 | _("register list must contain at least 1 and at most 16 " | |
16457 | "registers")); | |
16458 | ||
037e8744 | 16459 | if (inst.operands[1].issingle) |
22b5b651 | 16460 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 | 16461 | else |
22b5b651 | 16462 | do_vfp_nsyn_opcode ("fldmiad"); |
037e8744 JB |
16463 | } |
16464 | ||
16465 | /* Fix up Neon data-processing instructions, ORing in the correct bits for | |
16466 | ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */ | |
16467 | ||
88714cb8 DG |
16468 | static void |
16469 | neon_dp_fixup (struct arm_it* insn) | |
037e8744 | 16470 | { |
88714cb8 DG |
16471 | unsigned int i = insn->instruction; |
16472 | insn->is_neon = 1; | |
16473 | ||
037e8744 JB |
16474 | if (thumb_mode) |
16475 | { | |
16476 | /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */ | |
16477 | if (i & (1 << 24)) | |
477330fc | 16478 | i |= 1 << 28; |
5f4273c7 | 16479 | |
037e8744 | 16480 | i &= ~(1 << 24); |
5f4273c7 | 16481 | |
037e8744 JB |
16482 | i |= 0xef000000; |
16483 | } | |
16484 | else | |
16485 | i |= 0xf2000000; | |
5f4273c7 | 16486 | |
88714cb8 | 16487 | insn->instruction = i; |
037e8744 JB |
16488 | } |
16489 | ||
5ee91343 | 16490 | static void |
7df54120 | 16491 | mve_encode_qqr (int size, int U, int fp) |
5ee91343 AV |
16492 | { |
16493 | if (inst.operands[2].reg == REG_SP) | |
16494 | as_tsktsk (MVE_BAD_SP); | |
16495 | else if (inst.operands[2].reg == REG_PC) | |
16496 | as_tsktsk (MVE_BAD_PC); | |
16497 | ||
16498 | if (fp) | |
16499 | { | |
16500 | /* vadd. */ | |
16501 | if (((unsigned)inst.instruction) == 0xd00) | |
16502 | inst.instruction = 0xee300f40; | |
16503 | /* vsub. */ | |
16504 | else if (((unsigned)inst.instruction) == 0x200d00) | |
16505 | inst.instruction = 0xee301f40; | |
a8465a06 AV |
16506 | /* vmul. */ |
16507 | else if (((unsigned)inst.instruction) == 0x1000d10) | |
16508 | inst.instruction = 0xee310e60; | |
5ee91343 AV |
16509 | |
16510 | /* Setting size which is 1 for F16 and 0 for F32. */ | |
16511 | inst.instruction |= (size == 16) << 28; | |
16512 | } | |
16513 | else | |
16514 | { | |
16515 | /* vadd. */ | |
16516 | if (((unsigned)inst.instruction) == 0x800) | |
16517 | inst.instruction = 0xee010f40; | |
16518 | /* vsub. */ | |
16519 | else if (((unsigned)inst.instruction) == 0x1000800) | |
16520 | inst.instruction = 0xee011f40; | |
7df54120 AV |
16521 | /* vhadd. */ |
16522 | else if (((unsigned)inst.instruction) == 0) | |
16523 | inst.instruction = 0xee000f40; | |
16524 | /* vhsub. */ | |
16525 | else if (((unsigned)inst.instruction) == 0x200) | |
16526 | inst.instruction = 0xee001f40; | |
a8465a06 AV |
16527 | /* vmla. */ |
16528 | else if (((unsigned)inst.instruction) == 0x900) | |
16529 | inst.instruction = 0xee010e40; | |
16530 | /* vmul. */ | |
16531 | else if (((unsigned)inst.instruction) == 0x910) | |
16532 | inst.instruction = 0xee011e60; | |
16533 | /* vqadd. */ | |
16534 | else if (((unsigned)inst.instruction) == 0x10) | |
16535 | inst.instruction = 0xee000f60; | |
16536 | /* vqsub. */ | |
16537 | else if (((unsigned)inst.instruction) == 0x210) | |
16538 | inst.instruction = 0xee001f60; | |
42b16635 AV |
16539 | /* vqrdmlah. */ |
16540 | else if (((unsigned)inst.instruction) == 0x3000b10) | |
16541 | inst.instruction = 0xee000e40; | |
16542 | /* vqdmulh. */ | |
16543 | else if (((unsigned)inst.instruction) == 0x0000b00) | |
16544 | inst.instruction = 0xee010e60; | |
16545 | /* vqrdmulh. */ | |
16546 | else if (((unsigned)inst.instruction) == 0x1000b00) | |
16547 | inst.instruction = 0xfe010e60; | |
7df54120 AV |
16548 | |
16549 | /* Set U-bit. */ | |
16550 | inst.instruction |= U << 28; | |
16551 | ||
5ee91343 AV |
16552 | /* Setting bits for size. */ |
16553 | inst.instruction |= neon_logbits (size) << 20; | |
16554 | } | |
16555 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16556 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16557 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16558 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16559 | inst.instruction |= inst.operands[2].reg; | |
16560 | inst.is_neon = 1; | |
16561 | } | |
16562 | ||
a302e574 AV |
16563 | static void |
16564 | mve_encode_rqq (unsigned bit28, unsigned size) | |
16565 | { | |
16566 | inst.instruction |= bit28 << 28; | |
16567 | inst.instruction |= neon_logbits (size) << 20; | |
16568 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16569 | inst.instruction |= inst.operands[0].reg << 12; | |
16570 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16571 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
16572 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16573 | inst.is_neon = 1; | |
16574 | } | |
16575 | ||
886e1c73 AV |
16576 | static void |
16577 | mve_encode_qqq (int ubit, int size) | |
16578 | { | |
16579 | ||
16580 | inst.instruction |= (ubit != 0) << 28; | |
16581 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16582 | inst.instruction |= neon_logbits (size) << 20; | |
16583 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16584 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16585 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16586 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
16587 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16588 | ||
16589 | inst.is_neon = 1; | |
16590 | } | |
16591 | ||
26c1e780 AV |
16592 | static void |
16593 | mve_encode_rq (unsigned bit28, unsigned size) | |
16594 | { | |
16595 | inst.instruction |= bit28 << 28; | |
16596 | inst.instruction |= neon_logbits (size) << 18; | |
16597 | inst.instruction |= inst.operands[0].reg << 12; | |
16598 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16599 | inst.is_neon = 1; | |
16600 | } | |
886e1c73 | 16601 | |
93925576 AV |
16602 | static void |
16603 | mve_encode_rrqq (unsigned U, unsigned size) | |
16604 | { | |
16605 | constraint (inst.operands[3].reg > 14, MVE_BAD_QREG); | |
16606 | ||
16607 | inst.instruction |= U << 28; | |
16608 | inst.instruction |= (inst.operands[1].reg >> 1) << 20; | |
16609 | inst.instruction |= LOW4 (inst.operands[2].reg) << 16; | |
16610 | inst.instruction |= (size == 32) << 16; | |
16611 | inst.instruction |= inst.operands[0].reg << 12; | |
16612 | inst.instruction |= HI1 (inst.operands[2].reg) << 7; | |
16613 | inst.instruction |= inst.operands[3].reg; | |
16614 | inst.is_neon = 1; | |
16615 | } | |
16616 | ||
037e8744 JB |
16617 | /* Encode insns with bit pattern: |
16618 | ||
16619 | |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
16620 | | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm | | |
5f4273c7 | 16621 | |
037e8744 JB |
16622 | SIZE is passed in bits. -1 means size field isn't changed, in case it has a |
16623 | different meaning for some instruction. */ | |
16624 | ||
16625 | static void | |
16626 | neon_three_same (int isquad, int ubit, int size) | |
16627 | { | |
16628 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16629 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16630 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16631 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16632 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16633 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
16634 | inst.instruction |= (isquad != 0) << 6; | |
16635 | inst.instruction |= (ubit != 0) << 24; | |
16636 | if (size != -1) | |
16637 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 16638 | |
88714cb8 | 16639 | neon_dp_fixup (&inst); |
037e8744 JB |
16640 | } |
16641 | ||
16642 | /* Encode instructions of the form: | |
16643 | ||
16644 | |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0| | |
16645 | | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm | | |
5287ad62 JB |
16646 | |
16647 | Don't write size if SIZE == -1. */ | |
16648 | ||
16649 | static void | |
16650 | neon_two_same (int qbit, int ubit, int size) | |
16651 | { | |
16652 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16653 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16654 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16655 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16656 | inst.instruction |= (qbit != 0) << 6; | |
16657 | inst.instruction |= (ubit != 0) << 24; | |
16658 | ||
16659 | if (size != -1) | |
16660 | inst.instruction |= neon_logbits (size) << 18; | |
16661 | ||
88714cb8 | 16662 | neon_dp_fixup (&inst); |
5287ad62 JB |
16663 | } |
16664 | ||
7df54120 AV |
16665 | enum vfp_or_neon_is_neon_bits |
16666 | { | |
16667 | NEON_CHECK_CC = 1, | |
16668 | NEON_CHECK_ARCH = 2, | |
16669 | NEON_CHECK_ARCH8 = 4 | |
16670 | }; | |
16671 | ||
16672 | /* Call this function if an instruction which may have belonged to the VFP or | |
16673 | Neon instruction sets, but turned out to be a Neon instruction (due to the | |
16674 | operand types involved, etc.). We have to check and/or fix-up a couple of | |
16675 | things: | |
16676 | ||
16677 | - Make sure the user hasn't attempted to make a Neon instruction | |
16678 | conditional. | |
16679 | - Alter the value in the condition code field if necessary. | |
16680 | - Make sure that the arch supports Neon instructions. | |
16681 | ||
16682 | Which of these operations take place depends on bits from enum | |
16683 | vfp_or_neon_is_neon_bits. | |
16684 | ||
16685 | WARNING: This function has side effects! If NEON_CHECK_CC is used and the | |
16686 | current instruction's condition is COND_ALWAYS, the condition field is | |
16687 | changed to inst.uncond_value. This is necessary because instructions shared | |
16688 | between VFP and Neon may be conditional for the VFP variants only, and the | |
16689 | unconditional Neon version must have, e.g., 0xF in the condition field. */ | |
16690 | ||
16691 | static int | |
16692 | vfp_or_neon_is_neon (unsigned check) | |
16693 | { | |
16694 | /* Conditions are always legal in Thumb mode (IT blocks). */ | |
16695 | if (!thumb_mode && (check & NEON_CHECK_CC)) | |
16696 | { | |
16697 | if (inst.cond != COND_ALWAYS) | |
16698 | { | |
16699 | first_error (_(BAD_COND)); | |
16700 | return FAIL; | |
16701 | } | |
16702 | if (inst.uncond_value != -1) | |
16703 | inst.instruction |= inst.uncond_value << 28; | |
16704 | } | |
16705 | ||
16706 | ||
16707 | if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1)) | |
16708 | || ((check & NEON_CHECK_ARCH8) | |
16709 | && !mark_feature_used (&fpu_neon_ext_armv8))) | |
16710 | { | |
16711 | first_error (_(BAD_FPU)); | |
16712 | return FAIL; | |
16713 | } | |
16714 | ||
16715 | return SUCCESS; | |
16716 | } | |
16717 | ||
64c350f2 AV |
16718 | |
16719 | /* Return TRUE if the SIMD instruction is available for the current | |
16720 | cpu_variant. FP is set to TRUE if this is a SIMD floating-point | |
16721 | instruction. CHECK contains th. CHECK contains the set of bits to pass to | |
16722 | vfp_or_neon_is_neon for the NEON specific checks. */ | |
16723 | ||
16724 | static bfd_boolean | |
7df54120 AV |
16725 | check_simd_pred_availability (int fp, unsigned check) |
16726 | { | |
16727 | if (inst.cond > COND_ALWAYS) | |
16728 | { | |
16729 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
16730 | { | |
16731 | inst.error = BAD_FPU; | |
64c350f2 | 16732 | return FALSE; |
7df54120 AV |
16733 | } |
16734 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
16735 | } | |
16736 | else if (inst.cond < COND_ALWAYS) | |
16737 | { | |
16738 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
16739 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
16740 | else if (vfp_or_neon_is_neon (check) == FAIL) | |
64c350f2 | 16741 | return FALSE; |
7df54120 AV |
16742 | } |
16743 | else | |
16744 | { | |
16745 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext) | |
16746 | && vfp_or_neon_is_neon (check) == FAIL) | |
64c350f2 | 16747 | return FALSE; |
7df54120 AV |
16748 | |
16749 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
16750 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
16751 | } | |
64c350f2 | 16752 | return TRUE; |
7df54120 AV |
16753 | } |
16754 | ||
5287ad62 JB |
16755 | /* Neon instruction encoders, in approximate order of appearance. */ |
16756 | ||
16757 | static void | |
16758 | do_neon_dyadic_i_su (void) | |
16759 | { | |
64c350f2 | 16760 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
7df54120 AV |
16761 | return; |
16762 | ||
16763 | enum neon_shape rs; | |
16764 | struct neon_type_el et; | |
16765 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
16766 | rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL); | |
16767 | else | |
16768 | rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
16769 | ||
16770 | et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_32 | N_KEY); | |
16771 | ||
16772 | ||
16773 | if (rs != NS_QQR) | |
16774 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
16775 | else | |
16776 | mve_encode_qqr (et.size, et.type == NT_unsigned, 0); | |
5287ad62 JB |
16777 | } |
16778 | ||
16779 | static void | |
16780 | do_neon_dyadic_i64_su (void) | |
16781 | { | |
64c350f2 | 16782 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH)) |
a8465a06 AV |
16783 | return; |
16784 | enum neon_shape rs; | |
16785 | struct neon_type_el et; | |
16786 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
16787 | { | |
16788 | rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL); | |
16789 | et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY); | |
16790 | } | |
16791 | else | |
16792 | { | |
16793 | rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
16794 | et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
16795 | } | |
16796 | if (rs == NS_QQR) | |
16797 | mve_encode_qqr (et.size, et.type == NT_unsigned, 0); | |
16798 | else | |
16799 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
5287ad62 JB |
16800 | } |
16801 | ||
16802 | static void | |
16803 | neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et, | |
477330fc | 16804 | unsigned immbits) |
5287ad62 JB |
16805 | { |
16806 | unsigned size = et.size >> 3; | |
16807 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16808 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16809 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16810 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16811 | inst.instruction |= (isquad != 0) << 6; | |
16812 | inst.instruction |= immbits << 16; | |
16813 | inst.instruction |= (size >> 3) << 7; | |
16814 | inst.instruction |= (size & 0x7) << 19; | |
16815 | if (write_ubit) | |
16816 | inst.instruction |= (uval != 0) << 24; | |
16817 | ||
88714cb8 | 16818 | neon_dp_fixup (&inst); |
5287ad62 JB |
16819 | } |
16820 | ||
16821 | static void | |
5150f0d8 | 16822 | do_neon_shl (void) |
5287ad62 | 16823 | { |
64c350f2 | 16824 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
5150f0d8 AV |
16825 | return; |
16826 | ||
5287ad62 JB |
16827 | if (!inst.operands[2].isreg) |
16828 | { | |
5150f0d8 AV |
16829 | enum neon_shape rs; |
16830 | struct neon_type_el et; | |
16831 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
16832 | { | |
16833 | rs = neon_select_shape (NS_QQI, NS_NULL); | |
16834 | et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_MVE); | |
16835 | } | |
16836 | else | |
16837 | { | |
16838 | rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); | |
16839 | et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL); | |
16840 | } | |
cb3b1e65 JB |
16841 | int imm = inst.operands[2].imm; |
16842 | ||
16843 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
16844 | _("immediate out of range for shift")); | |
88714cb8 | 16845 | NEON_ENCODE (IMMED, inst); |
cb3b1e65 | 16846 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
16847 | } |
16848 | else | |
16849 | { | |
5150f0d8 AV |
16850 | enum neon_shape rs; |
16851 | struct neon_type_el et; | |
16852 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
16853 | { | |
16854 | rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL); | |
16855 | et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK); | |
16856 | } | |
16857 | else | |
16858 | { | |
16859 | rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
16860 | et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
16861 | } | |
16862 | ||
16863 | ||
16864 | if (rs == NS_QQR) | |
16865 | { | |
16866 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
16867 | _("invalid instruction shape")); | |
16868 | if (inst.operands[2].reg == REG_SP) | |
16869 | as_tsktsk (MVE_BAD_SP); | |
16870 | else if (inst.operands[2].reg == REG_PC) | |
16871 | as_tsktsk (MVE_BAD_PC); | |
16872 | ||
16873 | inst.instruction = 0xee311e60; | |
16874 | inst.instruction |= (et.type == NT_unsigned) << 28; | |
16875 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16876 | inst.instruction |= neon_logbits (et.size) << 18; | |
16877 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16878 | inst.instruction |= inst.operands[2].reg; | |
16879 | inst.is_neon = 1; | |
16880 | } | |
16881 | else | |
16882 | { | |
16883 | unsigned int tmp; | |
16884 | ||
16885 | /* VSHL/VQSHL 3-register variants have syntax such as: | |
16886 | vshl.xx Dd, Dm, Dn | |
16887 | whereas other 3-register operations encoded by neon_three_same have | |
16888 | syntax like: | |
16889 | vadd.xx Dd, Dn, Dm | |
16890 | (i.e. with Dn & Dm reversed). Swap operands[1].reg and | |
16891 | operands[2].reg here. */ | |
16892 | tmp = inst.operands[2].reg; | |
16893 | inst.operands[2].reg = inst.operands[1].reg; | |
16894 | inst.operands[1].reg = tmp; | |
16895 | NEON_ENCODE (INTEGER, inst); | |
16896 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
16897 | } | |
5287ad62 JB |
16898 | } |
16899 | } | |
16900 | ||
16901 | static void | |
5150f0d8 | 16902 | do_neon_qshl (void) |
5287ad62 | 16903 | { |
64c350f2 | 16904 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
5150f0d8 AV |
16905 | return; |
16906 | ||
5287ad62 JB |
16907 | if (!inst.operands[2].isreg) |
16908 | { | |
5150f0d8 AV |
16909 | enum neon_shape rs; |
16910 | struct neon_type_el et; | |
16911 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
16912 | { | |
16913 | rs = neon_select_shape (NS_QQI, NS_NULL); | |
16914 | et = neon_check_type (2, rs, N_EQK, N_KEY | N_SU_MVE); | |
16915 | } | |
16916 | else | |
16917 | { | |
16918 | rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); | |
16919 | et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); | |
16920 | } | |
cb3b1e65 | 16921 | int imm = inst.operands[2].imm; |
627907b7 | 16922 | |
cb3b1e65 JB |
16923 | constraint (imm < 0 || (unsigned)imm >= et.size, |
16924 | _("immediate out of range for shift")); | |
88714cb8 | 16925 | NEON_ENCODE (IMMED, inst); |
cb3b1e65 | 16926 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm); |
5287ad62 JB |
16927 | } |
16928 | else | |
16929 | { | |
5150f0d8 AV |
16930 | enum neon_shape rs; |
16931 | struct neon_type_el et; | |
627907b7 | 16932 | |
5150f0d8 AV |
16933 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) |
16934 | { | |
16935 | rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL); | |
16936 | et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK); | |
16937 | } | |
16938 | else | |
16939 | { | |
16940 | rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
16941 | et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); | |
16942 | } | |
16943 | ||
16944 | if (rs == NS_QQR) | |
16945 | { | |
16946 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
16947 | _("invalid instruction shape")); | |
16948 | if (inst.operands[2].reg == REG_SP) | |
16949 | as_tsktsk (MVE_BAD_SP); | |
16950 | else if (inst.operands[2].reg == REG_PC) | |
16951 | as_tsktsk (MVE_BAD_PC); | |
16952 | ||
16953 | inst.instruction = 0xee311ee0; | |
16954 | inst.instruction |= (et.type == NT_unsigned) << 28; | |
16955 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16956 | inst.instruction |= neon_logbits (et.size) << 18; | |
16957 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16958 | inst.instruction |= inst.operands[2].reg; | |
16959 | inst.is_neon = 1; | |
16960 | } | |
16961 | else | |
16962 | { | |
16963 | unsigned int tmp; | |
16964 | ||
16965 | /* See note in do_neon_shl. */ | |
16966 | tmp = inst.operands[2].reg; | |
16967 | inst.operands[2].reg = inst.operands[1].reg; | |
16968 | inst.operands[1].reg = tmp; | |
16969 | NEON_ENCODE (INTEGER, inst); | |
16970 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
16971 | } | |
5287ad62 JB |
16972 | } |
16973 | } | |
16974 | ||
627907b7 JB |
16975 | static void |
16976 | do_neon_rshl (void) | |
16977 | { | |
64c350f2 | 16978 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
1be7aba3 AV |
16979 | return; |
16980 | ||
16981 | enum neon_shape rs; | |
16982 | struct neon_type_el et; | |
16983 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
16984 | { | |
16985 | rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL); | |
16986 | et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY); | |
16987 | } | |
16988 | else | |
16989 | { | |
16990 | rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
16991 | et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
16992 | } | |
16993 | ||
627907b7 JB |
16994 | unsigned int tmp; |
16995 | ||
1be7aba3 AV |
16996 | if (rs == NS_QQR) |
16997 | { | |
16998 | if (inst.operands[2].reg == REG_PC) | |
16999 | as_tsktsk (MVE_BAD_PC); | |
17000 | else if (inst.operands[2].reg == REG_SP) | |
17001 | as_tsktsk (MVE_BAD_SP); | |
17002 | ||
17003 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
17004 | _("invalid instruction shape")); | |
17005 | ||
17006 | if (inst.instruction == 0x0000510) | |
17007 | /* We are dealing with vqrshl. */ | |
17008 | inst.instruction = 0xee331ee0; | |
17009 | else | |
17010 | /* We are dealing with vrshl. */ | |
17011 | inst.instruction = 0xee331e60; | |
17012 | ||
17013 | inst.instruction |= (et.type == NT_unsigned) << 28; | |
17014 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17015 | inst.instruction |= neon_logbits (et.size) << 18; | |
17016 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17017 | inst.instruction |= inst.operands[2].reg; | |
17018 | inst.is_neon = 1; | |
17019 | } | |
17020 | else | |
17021 | { | |
17022 | tmp = inst.operands[2].reg; | |
17023 | inst.operands[2].reg = inst.operands[1].reg; | |
17024 | inst.operands[1].reg = tmp; | |
17025 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
17026 | } | |
627907b7 JB |
17027 | } |
17028 | ||
5287ad62 JB |
17029 | static int |
17030 | neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size) | |
17031 | { | |
036dc3f7 PB |
17032 | /* Handle .I8 pseudo-instructions. */ |
17033 | if (size == 8) | |
5287ad62 | 17034 | { |
5287ad62 | 17035 | /* Unfortunately, this will make everything apart from zero out-of-range. |
477330fc RM |
17036 | FIXME is this the intended semantics? There doesn't seem much point in |
17037 | accepting .I8 if so. */ | |
5287ad62 JB |
17038 | immediate |= immediate << 8; |
17039 | size = 16; | |
036dc3f7 PB |
17040 | } |
17041 | ||
17042 | if (size >= 32) | |
17043 | { | |
17044 | if (immediate == (immediate & 0x000000ff)) | |
17045 | { | |
17046 | *immbits = immediate; | |
17047 | return 0x1; | |
17048 | } | |
17049 | else if (immediate == (immediate & 0x0000ff00)) | |
17050 | { | |
17051 | *immbits = immediate >> 8; | |
17052 | return 0x3; | |
17053 | } | |
17054 | else if (immediate == (immediate & 0x00ff0000)) | |
17055 | { | |
17056 | *immbits = immediate >> 16; | |
17057 | return 0x5; | |
17058 | } | |
17059 | else if (immediate == (immediate & 0xff000000)) | |
17060 | { | |
17061 | *immbits = immediate >> 24; | |
17062 | return 0x7; | |
17063 | } | |
17064 | if ((immediate & 0xffff) != (immediate >> 16)) | |
17065 | goto bad_immediate; | |
17066 | immediate &= 0xffff; | |
5287ad62 JB |
17067 | } |
17068 | ||
17069 | if (immediate == (immediate & 0x000000ff)) | |
17070 | { | |
17071 | *immbits = immediate; | |
036dc3f7 | 17072 | return 0x9; |
5287ad62 JB |
17073 | } |
17074 | else if (immediate == (immediate & 0x0000ff00)) | |
17075 | { | |
17076 | *immbits = immediate >> 8; | |
036dc3f7 | 17077 | return 0xb; |
5287ad62 JB |
17078 | } |
17079 | ||
17080 | bad_immediate: | |
dcbf9037 | 17081 | first_error (_("immediate value out of range")); |
5287ad62 JB |
17082 | return FAIL; |
17083 | } | |
17084 | ||
5287ad62 JB |
17085 | static void |
17086 | do_neon_logic (void) | |
17087 | { | |
17088 | if (inst.operands[2].present && inst.operands[2].isreg) | |
17089 | { | |
037e8744 | 17090 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
f601a00c | 17091 | if (rs == NS_QQQ |
64c350f2 AV |
17092 | && !check_simd_pred_availability (FALSE, |
17093 | NEON_CHECK_ARCH | NEON_CHECK_CC)) | |
f601a00c AV |
17094 | return; |
17095 | else if (rs != NS_QQQ | |
17096 | && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)) | |
17097 | first_error (BAD_FPU); | |
17098 | ||
5287ad62 JB |
17099 | neon_check_type (3, rs, N_IGNORE_TYPE); |
17100 | /* U bit and size field were set as part of the bitmask. */ | |
88714cb8 | 17101 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 17102 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
17103 | } |
17104 | else | |
17105 | { | |
4316f0d2 DG |
17106 | const int three_ops_form = (inst.operands[2].present |
17107 | && !inst.operands[2].isreg); | |
17108 | const int immoperand = (three_ops_form ? 2 : 1); | |
17109 | enum neon_shape rs = (three_ops_form | |
17110 | ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL) | |
17111 | : neon_select_shape (NS_DI, NS_QI, NS_NULL)); | |
f601a00c AV |
17112 | /* Because neon_select_shape makes the second operand a copy of the first |
17113 | if the second operand is not present. */ | |
17114 | if (rs == NS_QQI | |
64c350f2 AV |
17115 | && !check_simd_pred_availability (FALSE, |
17116 | NEON_CHECK_ARCH | NEON_CHECK_CC)) | |
f601a00c AV |
17117 | return; |
17118 | else if (rs != NS_QQI | |
17119 | && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)) | |
17120 | first_error (BAD_FPU); | |
17121 | ||
17122 | struct neon_type_el et; | |
17123 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
17124 | et = neon_check_type (2, rs, N_I32 | N_I16 | N_KEY, N_EQK); | |
17125 | else | |
17126 | et = neon_check_type (2, rs, N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | |
17127 | | N_KEY, N_EQK); | |
17128 | ||
17129 | if (et.type == NT_invtype) | |
17130 | return; | |
21d799b5 | 17131 | enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff; |
5287ad62 JB |
17132 | unsigned immbits; |
17133 | int cmode; | |
5f4273c7 | 17134 | |
5f4273c7 | 17135 | |
4316f0d2 DG |
17136 | if (three_ops_form) |
17137 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
17138 | _("first and second operands shall be the same register")); | |
17139 | ||
88714cb8 | 17140 | NEON_ENCODE (IMMED, inst); |
5287ad62 | 17141 | |
4316f0d2 | 17142 | immbits = inst.operands[immoperand].imm; |
036dc3f7 PB |
17143 | if (et.size == 64) |
17144 | { | |
17145 | /* .i64 is a pseudo-op, so the immediate must be a repeating | |
17146 | pattern. */ | |
4316f0d2 DG |
17147 | if (immbits != (inst.operands[immoperand].regisimm ? |
17148 | inst.operands[immoperand].reg : 0)) | |
036dc3f7 PB |
17149 | { |
17150 | /* Set immbits to an invalid constant. */ | |
17151 | immbits = 0xdeadbeef; | |
17152 | } | |
17153 | } | |
17154 | ||
5287ad62 | 17155 | switch (opcode) |
477330fc RM |
17156 | { |
17157 | case N_MNEM_vbic: | |
17158 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
17159 | break; | |
17160 | ||
17161 | case N_MNEM_vorr: | |
17162 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
17163 | break; | |
17164 | ||
17165 | case N_MNEM_vand: | |
17166 | /* Pseudo-instruction for VBIC. */ | |
17167 | neon_invert_size (&immbits, 0, et.size); | |
17168 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
17169 | break; | |
17170 | ||
17171 | case N_MNEM_vorn: | |
17172 | /* Pseudo-instruction for VORR. */ | |
17173 | neon_invert_size (&immbits, 0, et.size); | |
17174 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
17175 | break; | |
17176 | ||
17177 | default: | |
17178 | abort (); | |
17179 | } | |
5287ad62 JB |
17180 | |
17181 | if (cmode == FAIL) | |
477330fc | 17182 | return; |
5287ad62 | 17183 | |
037e8744 | 17184 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
17185 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
17186 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17187 | inst.instruction |= cmode << 8; | |
17188 | neon_write_immbits (immbits); | |
5f4273c7 | 17189 | |
88714cb8 | 17190 | neon_dp_fixup (&inst); |
5287ad62 JB |
17191 | } |
17192 | } | |
17193 | ||
17194 | static void | |
17195 | do_neon_bitfield (void) | |
17196 | { | |
037e8744 | 17197 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 17198 | neon_check_type (3, rs, N_IGNORE_TYPE); |
037e8744 | 17199 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
17200 | } |
17201 | ||
17202 | static void | |
dcbf9037 | 17203 | neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types, |
477330fc | 17204 | unsigned destbits) |
5287ad62 | 17205 | { |
5ee91343 | 17206 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL); |
dcbf9037 | 17207 | struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK, |
477330fc | 17208 | types | N_KEY); |
5287ad62 JB |
17209 | if (et.type == NT_float) |
17210 | { | |
88714cb8 | 17211 | NEON_ENCODE (FLOAT, inst); |
5ee91343 | 17212 | if (rs == NS_QQR) |
7df54120 | 17213 | mve_encode_qqr (et.size, 0, 1); |
5ee91343 AV |
17214 | else |
17215 | neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1); | |
5287ad62 JB |
17216 | } |
17217 | else | |
17218 | { | |
88714cb8 | 17219 | NEON_ENCODE (INTEGER, inst); |
5ee91343 | 17220 | if (rs == NS_QQR) |
a8465a06 | 17221 | mve_encode_qqr (et.size, et.type == ubit_meaning, 0); |
5ee91343 AV |
17222 | else |
17223 | neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size); | |
5287ad62 JB |
17224 | } |
17225 | } | |
17226 | ||
5287ad62 JB |
17227 | |
17228 | static void | |
17229 | do_neon_dyadic_if_su_d (void) | |
17230 | { | |
17231 | /* This version only allow D registers, but that constraint is enforced during | |
17232 | operand parsing so we don't need to do anything extra here. */ | |
dcbf9037 | 17233 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
17234 | } |
17235 | ||
5287ad62 JB |
17236 | static void |
17237 | do_neon_dyadic_if_i_d (void) | |
17238 | { | |
428e3f1f PB |
17239 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
17240 | affected if we specify unsigned args. */ | |
17241 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
5287ad62 JB |
17242 | } |
17243 | ||
f5f10c66 AV |
17244 | static void |
17245 | do_mve_vstr_vldr_QI (int size, int elsize, int load) | |
17246 | { | |
17247 | constraint (size < 32, BAD_ADDR_MODE); | |
17248 | constraint (size != elsize, BAD_EL_TYPE); | |
17249 | constraint (inst.operands[1].immisreg, BAD_ADDR_MODE); | |
17250 | constraint (!inst.operands[1].preind, BAD_ADDR_MODE); | |
17251 | constraint (load && inst.operands[0].reg == inst.operands[1].reg, | |
17252 | _("destination register and offset register may not be the" | |
17253 | " same")); | |
17254 | ||
17255 | int imm = inst.relocs[0].exp.X_add_number; | |
17256 | int add = 1; | |
17257 | if (imm < 0) | |
17258 | { | |
17259 | add = 0; | |
17260 | imm = -imm; | |
17261 | } | |
17262 | constraint ((imm % (size / 8) != 0) | |
17263 | || imm > (0x7f << neon_logbits (size)), | |
17264 | (size == 32) ? _("immediate must be a multiple of 4 in the" | |
17265 | " range of +/-[0,508]") | |
17266 | : _("immediate must be a multiple of 8 in the" | |
17267 | " range of +/-[0,1016]")); | |
17268 | inst.instruction |= 0x11 << 24; | |
17269 | inst.instruction |= add << 23; | |
17270 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17271 | inst.instruction |= inst.operands[1].writeback << 21; | |
17272 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
17273 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17274 | inst.instruction |= 1 << 12; | |
17275 | inst.instruction |= (size == 64) << 8; | |
17276 | inst.instruction &= 0xffffff00; | |
17277 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
17278 | inst.instruction |= imm >> neon_logbits (size); | |
17279 | } | |
17280 | ||
17281 | static void | |
17282 | do_mve_vstr_vldr_RQ (int size, int elsize, int load) | |
17283 | { | |
17284 | unsigned os = inst.operands[1].imm >> 5; | |
e449ea97 | 17285 | unsigned type = inst.vectype.el[0].type; |
f5f10c66 AV |
17286 | constraint (os != 0 && size == 8, |
17287 | _("can not shift offsets when accessing less than half-word")); | |
17288 | constraint (os && os != neon_logbits (size), | |
17289 | _("shift immediate must be 1, 2 or 3 for half-word, word" | |
17290 | " or double-word accesses respectively")); | |
17291 | if (inst.operands[1].reg == REG_PC) | |
17292 | as_tsktsk (MVE_BAD_PC); | |
17293 | ||
17294 | switch (size) | |
17295 | { | |
17296 | case 8: | |
17297 | constraint (elsize >= 64, BAD_EL_TYPE); | |
17298 | break; | |
17299 | case 16: | |
17300 | constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE); | |
17301 | break; | |
17302 | case 32: | |
17303 | case 64: | |
17304 | constraint (elsize != size, BAD_EL_TYPE); | |
17305 | break; | |
17306 | default: | |
17307 | break; | |
17308 | } | |
17309 | constraint (inst.operands[1].writeback || !inst.operands[1].preind, | |
17310 | BAD_ADDR_MODE); | |
17311 | if (load) | |
17312 | { | |
17313 | constraint (inst.operands[0].reg == (inst.operands[1].imm & 0x1f), | |
17314 | _("destination register and offset register may not be" | |
17315 | " the same")); | |
e449ea97 SP |
17316 | constraint (size == elsize && type == NT_signed, BAD_EL_TYPE); |
17317 | constraint (size != elsize && type != NT_unsigned && type != NT_signed, | |
f5f10c66 | 17318 | BAD_EL_TYPE); |
e449ea97 | 17319 | inst.instruction |= ((size == elsize) || (type == NT_unsigned)) << 28; |
f5f10c66 AV |
17320 | } |
17321 | else | |
17322 | { | |
e449ea97 | 17323 | constraint (type != NT_untyped, BAD_EL_TYPE); |
f5f10c66 AV |
17324 | } |
17325 | ||
17326 | inst.instruction |= 1 << 23; | |
17327 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17328 | inst.instruction |= inst.operands[1].reg << 16; | |
17329 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17330 | inst.instruction |= neon_logbits (elsize) << 7; | |
17331 | inst.instruction |= HI1 (inst.operands[1].imm) << 5; | |
17332 | inst.instruction |= LOW4 (inst.operands[1].imm); | |
17333 | inst.instruction |= !!os; | |
17334 | } | |
17335 | ||
17336 | static void | |
17337 | do_mve_vstr_vldr_RI (int size, int elsize, int load) | |
17338 | { | |
17339 | enum neon_el_type type = inst.vectype.el[0].type; | |
17340 | ||
17341 | constraint (size >= 64, BAD_ADDR_MODE); | |
17342 | switch (size) | |
17343 | { | |
17344 | case 16: | |
17345 | constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE); | |
17346 | break; | |
17347 | case 32: | |
17348 | constraint (elsize != size, BAD_EL_TYPE); | |
17349 | break; | |
17350 | default: | |
17351 | break; | |
17352 | } | |
17353 | if (load) | |
17354 | { | |
17355 | constraint (elsize != size && type != NT_unsigned | |
17356 | && type != NT_signed, BAD_EL_TYPE); | |
17357 | } | |
17358 | else | |
17359 | { | |
17360 | constraint (elsize != size && type != NT_untyped, BAD_EL_TYPE); | |
17361 | } | |
17362 | ||
17363 | int imm = inst.relocs[0].exp.X_add_number; | |
17364 | int add = 1; | |
17365 | if (imm < 0) | |
17366 | { | |
17367 | add = 0; | |
17368 | imm = -imm; | |
17369 | } | |
17370 | ||
17371 | if ((imm % (size / 8) != 0) || imm > (0x7f << neon_logbits (size))) | |
17372 | { | |
17373 | switch (size) | |
17374 | { | |
17375 | case 8: | |
17376 | constraint (1, _("immediate must be in the range of +/-[0,127]")); | |
17377 | break; | |
17378 | case 16: | |
17379 | constraint (1, _("immediate must be a multiple of 2 in the" | |
17380 | " range of +/-[0,254]")); | |
17381 | break; | |
17382 | case 32: | |
17383 | constraint (1, _("immediate must be a multiple of 4 in the" | |
17384 | " range of +/-[0,508]")); | |
17385 | break; | |
17386 | } | |
17387 | } | |
17388 | ||
17389 | if (size != elsize) | |
17390 | { | |
17391 | constraint (inst.operands[1].reg > 7, BAD_HIREG); | |
17392 | constraint (inst.operands[0].reg > 14, | |
17393 | _("MVE vector register in the range [Q0..Q7] expected")); | |
17394 | inst.instruction |= (load && type == NT_unsigned) << 28; | |
17395 | inst.instruction |= (size == 16) << 19; | |
17396 | inst.instruction |= neon_logbits (elsize) << 7; | |
17397 | } | |
17398 | else | |
17399 | { | |
17400 | if (inst.operands[1].reg == REG_PC) | |
17401 | as_tsktsk (MVE_BAD_PC); | |
17402 | else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback) | |
17403 | as_tsktsk (MVE_BAD_SP); | |
17404 | inst.instruction |= 1 << 12; | |
17405 | inst.instruction |= neon_logbits (size) << 7; | |
17406 | } | |
17407 | inst.instruction |= inst.operands[1].preind << 24; | |
17408 | inst.instruction |= add << 23; | |
17409 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17410 | inst.instruction |= inst.operands[1].writeback << 21; | |
17411 | inst.instruction |= inst.operands[1].reg << 16; | |
17412 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17413 | inst.instruction &= 0xffffff80; | |
17414 | inst.instruction |= imm >> neon_logbits (size); | |
17415 | ||
17416 | } | |
17417 | ||
17418 | static void | |
17419 | do_mve_vstr_vldr (void) | |
17420 | { | |
17421 | unsigned size; | |
17422 | int load = 0; | |
17423 | ||
17424 | if (inst.cond > COND_ALWAYS) | |
17425 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
17426 | else | |
17427 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
17428 | ||
17429 | switch (inst.instruction) | |
17430 | { | |
17431 | default: | |
17432 | gas_assert (0); | |
17433 | break; | |
17434 | case M_MNEM_vldrb: | |
17435 | load = 1; | |
17436 | /* fall through. */ | |
17437 | case M_MNEM_vstrb: | |
17438 | size = 8; | |
17439 | break; | |
17440 | case M_MNEM_vldrh: | |
17441 | load = 1; | |
17442 | /* fall through. */ | |
17443 | case M_MNEM_vstrh: | |
17444 | size = 16; | |
17445 | break; | |
17446 | case M_MNEM_vldrw: | |
17447 | load = 1; | |
17448 | /* fall through. */ | |
17449 | case M_MNEM_vstrw: | |
17450 | size = 32; | |
17451 | break; | |
17452 | case M_MNEM_vldrd: | |
17453 | load = 1; | |
17454 | /* fall through. */ | |
17455 | case M_MNEM_vstrd: | |
17456 | size = 64; | |
17457 | break; | |
17458 | } | |
17459 | unsigned elsize = inst.vectype.el[0].size; | |
17460 | ||
17461 | if (inst.operands[1].isquad) | |
17462 | { | |
17463 | /* We are dealing with [Q, imm]{!} cases. */ | |
17464 | do_mve_vstr_vldr_QI (size, elsize, load); | |
17465 | } | |
17466 | else | |
17467 | { | |
17468 | if (inst.operands[1].immisreg == 2) | |
17469 | { | |
17470 | /* We are dealing with [R, Q, {UXTW #os}] cases. */ | |
17471 | do_mve_vstr_vldr_RQ (size, elsize, load); | |
17472 | } | |
17473 | else if (!inst.operands[1].immisreg) | |
17474 | { | |
17475 | /* We are dealing with [R, Imm]{!}/[R], Imm cases. */ | |
17476 | do_mve_vstr_vldr_RI (size, elsize, load); | |
17477 | } | |
17478 | else | |
17479 | constraint (1, BAD_ADDR_MODE); | |
17480 | } | |
17481 | ||
17482 | inst.is_neon = 1; | |
17483 | } | |
17484 | ||
35c228db AV |
17485 | static void |
17486 | do_mve_vst_vld (void) | |
17487 | { | |
17488 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
17489 | return; | |
17490 | ||
17491 | constraint (!inst.operands[1].preind || inst.relocs[0].exp.X_add_symbol != 0 | |
17492 | || inst.relocs[0].exp.X_add_number != 0 | |
17493 | || inst.operands[1].immisreg != 0, | |
17494 | BAD_ADDR_MODE); | |
17495 | constraint (inst.vectype.el[0].size > 32, BAD_EL_TYPE); | |
17496 | if (inst.operands[1].reg == REG_PC) | |
17497 | as_tsktsk (MVE_BAD_PC); | |
17498 | else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback) | |
17499 | as_tsktsk (MVE_BAD_SP); | |
17500 | ||
17501 | ||
17502 | /* These instructions are one of the "exceptions" mentioned in | |
17503 | handle_pred_state. They are MVE instructions that are not VPT compatible | |
17504 | and do not accept a VPT code, thus appending such a code is a syntax | |
17505 | error. */ | |
17506 | if (inst.cond > COND_ALWAYS) | |
17507 | first_error (BAD_SYNTAX); | |
17508 | /* If we append a scalar condition code we can set this to | |
17509 | MVE_OUTSIDE_PRED_INSN as it will also lead to a syntax error. */ | |
17510 | else if (inst.cond < COND_ALWAYS) | |
17511 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
17512 | else | |
17513 | inst.pred_insn_type = MVE_UNPREDICABLE_INSN; | |
17514 | ||
17515 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17516 | inst.instruction |= inst.operands[1].writeback << 21; | |
17517 | inst.instruction |= inst.operands[1].reg << 16; | |
17518 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17519 | inst.instruction |= neon_logbits (inst.vectype.el[0].size) << 7; | |
17520 | inst.is_neon = 1; | |
17521 | } | |
17522 | ||
26c1e780 AV |
17523 | static void |
17524 | do_mve_vaddlv (void) | |
17525 | { | |
17526 | enum neon_shape rs = neon_select_shape (NS_RRQ, NS_NULL); | |
17527 | struct neon_type_el et | |
17528 | = neon_check_type (3, rs, N_EQK, N_EQK, N_S32 | N_U32 | N_KEY); | |
17529 | ||
17530 | if (et.type == NT_invtype) | |
17531 | first_error (BAD_EL_TYPE); | |
17532 | ||
17533 | if (inst.cond > COND_ALWAYS) | |
17534 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
17535 | else | |
17536 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
17537 | ||
17538 | constraint (inst.operands[1].reg > 14, MVE_BAD_QREG); | |
17539 | ||
17540 | inst.instruction |= (et.type == NT_unsigned) << 28; | |
17541 | inst.instruction |= inst.operands[1].reg << 19; | |
17542 | inst.instruction |= inst.operands[0].reg << 12; | |
17543 | inst.instruction |= inst.operands[2].reg; | |
17544 | inst.is_neon = 1; | |
17545 | } | |
17546 | ||
5287ad62 | 17547 | static void |
5ee91343 | 17548 | do_neon_dyadic_if_su (void) |
5287ad62 | 17549 | { |
5ee91343 AV |
17550 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL); |
17551 | struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK, | |
17552 | N_SUF_32 | N_KEY); | |
17553 | ||
935295b5 AV |
17554 | constraint ((inst.instruction == ((unsigned) N_MNEM_vmax) |
17555 | || inst.instruction == ((unsigned) N_MNEM_vmin)) | |
17556 | && et.type == NT_float | |
17557 | && !ARM_CPU_HAS_FEATURE (cpu_variant,fpu_neon_ext_v1), BAD_FPU); | |
17558 | ||
64c350f2 AV |
17559 | if (!check_simd_pred_availability (et.type == NT_float, |
17560 | NEON_CHECK_ARCH | NEON_CHECK_CC)) | |
037e8744 JB |
17561 | return; |
17562 | ||
5ee91343 AV |
17563 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
17564 | } | |
17565 | ||
17566 | static void | |
17567 | do_neon_addsub_if_i (void) | |
17568 | { | |
17569 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd) | |
17570 | && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS) | |
037e8744 JB |
17571 | return; |
17572 | ||
5ee91343 AV |
17573 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL); |
17574 | struct neon_type_el et = neon_check_type (3, rs, N_EQK, | |
17575 | N_EQK, N_IF_32 | N_I64 | N_KEY); | |
17576 | ||
17577 | constraint (rs == NS_QQR && et.size == 64, BAD_FPU); | |
17578 | /* If we are parsing Q registers and the element types match MVE, which NEON | |
17579 | also supports, then we must check whether this is an instruction that can | |
17580 | be used by both MVE/NEON. This distinction can be made based on whether | |
17581 | they are predicated or not. */ | |
17582 | if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64) | |
17583 | { | |
64c350f2 AV |
17584 | if (!check_simd_pred_availability (et.type == NT_float, |
17585 | NEON_CHECK_ARCH | NEON_CHECK_CC)) | |
5ee91343 AV |
17586 | return; |
17587 | } | |
17588 | else | |
17589 | { | |
17590 | /* If they are either in a D register or are using an unsupported. */ | |
17591 | if (rs != NS_QQR | |
17592 | && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
17593 | return; | |
17594 | } | |
17595 | ||
5287ad62 JB |
17596 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
17597 | affected if we specify unsigned args. */ | |
dcbf9037 | 17598 | neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0); |
5287ad62 JB |
17599 | } |
17600 | ||
17601 | /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the | |
17602 | result to be: | |
17603 | V<op> A,B (A is operand 0, B is operand 2) | |
17604 | to mean: | |
17605 | V<op> A,B,A | |
17606 | not: | |
17607 | V<op> A,B,B | |
17608 | so handle that case specially. */ | |
17609 | ||
17610 | static void | |
17611 | neon_exchange_operands (void) | |
17612 | { | |
5287ad62 JB |
17613 | if (inst.operands[1].present) |
17614 | { | |
e1fa0163 NC |
17615 | void *scratch = xmalloc (sizeof (inst.operands[0])); |
17616 | ||
5287ad62 JB |
17617 | /* Swap operands[1] and operands[2]. */ |
17618 | memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0])); | |
17619 | inst.operands[1] = inst.operands[2]; | |
17620 | memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0])); | |
e1fa0163 | 17621 | free (scratch); |
5287ad62 JB |
17622 | } |
17623 | else | |
17624 | { | |
17625 | inst.operands[1] = inst.operands[2]; | |
17626 | inst.operands[2] = inst.operands[0]; | |
17627 | } | |
17628 | } | |
17629 | ||
17630 | static void | |
17631 | neon_compare (unsigned regtypes, unsigned immtypes, int invert) | |
17632 | { | |
17633 | if (inst.operands[2].isreg) | |
17634 | { | |
17635 | if (invert) | |
477330fc | 17636 | neon_exchange_operands (); |
dcbf9037 | 17637 | neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ); |
5287ad62 JB |
17638 | } |
17639 | else | |
17640 | { | |
037e8744 | 17641 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
dcbf9037 | 17642 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 17643 | N_EQK | N_SIZ, immtypes | N_KEY); |
5287ad62 | 17644 | |
88714cb8 | 17645 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
17646 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
17647 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17648 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
17649 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 17650 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
17651 | inst.instruction |= (et.type == NT_float) << 10; |
17652 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 17653 | |
88714cb8 | 17654 | neon_dp_fixup (&inst); |
5287ad62 JB |
17655 | } |
17656 | } | |
17657 | ||
17658 | static void | |
17659 | do_neon_cmp (void) | |
17660 | { | |
cc933301 | 17661 | neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE); |
5287ad62 JB |
17662 | } |
17663 | ||
17664 | static void | |
17665 | do_neon_cmp_inv (void) | |
17666 | { | |
cc933301 | 17667 | neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE); |
5287ad62 JB |
17668 | } |
17669 | ||
17670 | static void | |
17671 | do_neon_ceq (void) | |
17672 | { | |
17673 | neon_compare (N_IF_32, N_IF_32, FALSE); | |
17674 | } | |
17675 | ||
17676 | /* For multiply instructions, we have the possibility of 16-bit or 32-bit | |
17677 | scalars, which are encoded in 5 bits, M : Rm. | |
17678 | For 16-bit scalars, the register is encoded in Rm[2:0] and the index in | |
17679 | M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the | |
c604a79a JW |
17680 | index in M. |
17681 | ||
17682 | Dot Product instructions are similar to multiply instructions except elsize | |
17683 | should always be 32. | |
17684 | ||
17685 | This function translates SCALAR, which is GAS's internal encoding of indexed | |
17686 | scalar register, to raw encoding. There is also register and index range | |
17687 | check based on ELSIZE. */ | |
5287ad62 JB |
17688 | |
17689 | static unsigned | |
17690 | neon_scalar_for_mul (unsigned scalar, unsigned elsize) | |
17691 | { | |
dcbf9037 JB |
17692 | unsigned regno = NEON_SCALAR_REG (scalar); |
17693 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
5287ad62 JB |
17694 | |
17695 | switch (elsize) | |
17696 | { | |
17697 | case 16: | |
17698 | if (regno > 7 || elno > 3) | |
477330fc | 17699 | goto bad_scalar; |
5287ad62 | 17700 | return regno | (elno << 3); |
5f4273c7 | 17701 | |
5287ad62 JB |
17702 | case 32: |
17703 | if (regno > 15 || elno > 1) | |
477330fc | 17704 | goto bad_scalar; |
5287ad62 JB |
17705 | return regno | (elno << 4); |
17706 | ||
17707 | default: | |
17708 | bad_scalar: | |
dcbf9037 | 17709 | first_error (_("scalar out of range for multiply instruction")); |
5287ad62 JB |
17710 | } |
17711 | ||
17712 | return 0; | |
17713 | } | |
17714 | ||
17715 | /* Encode multiply / multiply-accumulate scalar instructions. */ | |
17716 | ||
17717 | static void | |
17718 | neon_mul_mac (struct neon_type_el et, int ubit) | |
17719 | { | |
dcbf9037 JB |
17720 | unsigned scalar; |
17721 | ||
17722 | /* Give a more helpful error message if we have an invalid type. */ | |
17723 | if (et.type == NT_invtype) | |
17724 | return; | |
5f4273c7 | 17725 | |
dcbf9037 | 17726 | scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size); |
5287ad62 JB |
17727 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
17728 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17729 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
17730 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
17731 | inst.instruction |= LOW4 (scalar); | |
17732 | inst.instruction |= HI1 (scalar) << 5; | |
17733 | inst.instruction |= (et.type == NT_float) << 8; | |
17734 | inst.instruction |= neon_logbits (et.size) << 20; | |
17735 | inst.instruction |= (ubit != 0) << 24; | |
17736 | ||
88714cb8 | 17737 | neon_dp_fixup (&inst); |
5287ad62 JB |
17738 | } |
17739 | ||
17740 | static void | |
17741 | do_neon_mac_maybe_scalar (void) | |
17742 | { | |
037e8744 JB |
17743 | if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS) |
17744 | return; | |
17745 | ||
64c350f2 | 17746 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH)) |
037e8744 JB |
17747 | return; |
17748 | ||
5287ad62 JB |
17749 | if (inst.operands[2].isscalar) |
17750 | { | |
a8465a06 | 17751 | constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU); |
037e8744 | 17752 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 | 17753 | struct neon_type_el et = neon_check_type (3, rs, |
589a7d88 | 17754 | N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY); |
88714cb8 | 17755 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 17756 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 | 17757 | } |
a8465a06 AV |
17758 | else if (!inst.operands[2].isvec) |
17759 | { | |
17760 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU); | |
17761 | ||
17762 | enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL); | |
17763 | neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY); | |
17764 | ||
17765 | neon_dyadic_misc (NT_unsigned, N_SU_MVE, 0); | |
17766 | } | |
5287ad62 | 17767 | else |
428e3f1f | 17768 | { |
a8465a06 | 17769 | constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU); |
428e3f1f PB |
17770 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
17771 | affected if we specify unsigned args. */ | |
17772 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
17773 | } | |
5287ad62 JB |
17774 | } |
17775 | ||
62f3b8c8 PB |
17776 | static void |
17777 | do_neon_fmac (void) | |
17778 | { | |
d58196e0 AV |
17779 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma) |
17780 | && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS) | |
62f3b8c8 PB |
17781 | return; |
17782 | ||
64c350f2 | 17783 | if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH)) |
62f3b8c8 PB |
17784 | return; |
17785 | ||
d58196e0 AV |
17786 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)) |
17787 | { | |
17788 | enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL); | |
17789 | struct neon_type_el et = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, | |
17790 | N_EQK); | |
17791 | ||
17792 | if (rs == NS_QQR) | |
17793 | { | |
17794 | if (inst.operands[2].reg == REG_SP) | |
17795 | as_tsktsk (MVE_BAD_SP); | |
17796 | else if (inst.operands[2].reg == REG_PC) | |
17797 | as_tsktsk (MVE_BAD_PC); | |
17798 | ||
17799 | inst.instruction = 0xee310e40; | |
17800 | inst.instruction |= (et.size == 16) << 28; | |
17801 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17802 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
17803 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17804 | inst.instruction |= HI1 (inst.operands[1].reg) << 6; | |
17805 | inst.instruction |= inst.operands[2].reg; | |
17806 | inst.is_neon = 1; | |
17807 | return; | |
17808 | } | |
17809 | } | |
17810 | else | |
17811 | { | |
17812 | constraint (!inst.operands[2].isvec, BAD_FPU); | |
17813 | } | |
17814 | ||
62f3b8c8 PB |
17815 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); |
17816 | } | |
17817 | ||
5287ad62 JB |
17818 | static void |
17819 | do_neon_tst (void) | |
17820 | { | |
037e8744 | 17821 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
17822 | struct neon_type_el et = neon_check_type (3, rs, |
17823 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
037e8744 | 17824 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
17825 | } |
17826 | ||
17827 | /* VMUL with 3 registers allows the P8 type. The scalar version supports the | |
17828 | same types as the MAC equivalents. The polynomial type for this instruction | |
17829 | is encoded the same as the integer type. */ | |
17830 | ||
17831 | static void | |
17832 | do_neon_mul (void) | |
17833 | { | |
037e8744 JB |
17834 | if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS) |
17835 | return; | |
17836 | ||
64c350f2 | 17837 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH)) |
037e8744 JB |
17838 | return; |
17839 | ||
5287ad62 | 17840 | if (inst.operands[2].isscalar) |
a8465a06 AV |
17841 | { |
17842 | constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU); | |
17843 | do_neon_mac_maybe_scalar (); | |
17844 | } | |
5287ad62 | 17845 | else |
a8465a06 AV |
17846 | { |
17847 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
17848 | { | |
17849 | enum neon_shape rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL); | |
17850 | struct neon_type_el et | |
17851 | = neon_check_type (3, rs, N_EQK, N_EQK, N_I_MVE | N_F_MVE | N_KEY); | |
17852 | if (et.type == NT_float) | |
17853 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext), | |
17854 | BAD_FPU); | |
17855 | ||
17856 | neon_dyadic_misc (NT_float, N_I_MVE | N_F_MVE, 0); | |
17857 | } | |
17858 | else | |
17859 | { | |
17860 | constraint (!inst.operands[2].isvec, BAD_FPU); | |
17861 | neon_dyadic_misc (NT_poly, | |
17862 | N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0); | |
17863 | } | |
17864 | } | |
5287ad62 JB |
17865 | } |
17866 | ||
17867 | static void | |
17868 | do_neon_qdmulh (void) | |
17869 | { | |
64c350f2 | 17870 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
42b16635 AV |
17871 | return; |
17872 | ||
5287ad62 JB |
17873 | if (inst.operands[2].isscalar) |
17874 | { | |
42b16635 | 17875 | constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU); |
037e8744 | 17876 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 | 17877 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 17878 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); |
88714cb8 | 17879 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 17880 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
17881 | } |
17882 | else | |
17883 | { | |
42b16635 AV |
17884 | enum neon_shape rs; |
17885 | struct neon_type_el et; | |
17886 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
17887 | { | |
17888 | rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL); | |
17889 | et = neon_check_type (3, rs, | |
17890 | N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
17891 | } | |
17892 | else | |
17893 | { | |
17894 | rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
17895 | et = neon_check_type (3, rs, | |
17896 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
17897 | } | |
17898 | ||
88714cb8 | 17899 | NEON_ENCODE (INTEGER, inst); |
42b16635 AV |
17900 | if (rs == NS_QQR) |
17901 | mve_encode_qqr (et.size, 0, 0); | |
17902 | else | |
17903 | /* The U bit (rounding) comes from bit mask. */ | |
17904 | neon_three_same (neon_quad (rs), 0, et.size); | |
5287ad62 JB |
17905 | } |
17906 | } | |
17907 | ||
26c1e780 AV |
17908 | static void |
17909 | do_mve_vaddv (void) | |
17910 | { | |
17911 | enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL); | |
17912 | struct neon_type_el et | |
17913 | = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY); | |
17914 | ||
17915 | if (et.type == NT_invtype) | |
17916 | first_error (BAD_EL_TYPE); | |
17917 | ||
17918 | if (inst.cond > COND_ALWAYS) | |
17919 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
17920 | else | |
17921 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
17922 | ||
17923 | constraint (inst.operands[1].reg > 14, MVE_BAD_QREG); | |
17924 | ||
17925 | mve_encode_rq (et.type == NT_unsigned, et.size); | |
17926 | } | |
17927 | ||
7df54120 AV |
17928 | static void |
17929 | do_mve_vhcadd (void) | |
17930 | { | |
17931 | enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL); | |
17932 | struct neon_type_el et | |
17933 | = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
17934 | ||
17935 | if (inst.cond > COND_ALWAYS) | |
17936 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
17937 | else | |
17938 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
17939 | ||
17940 | unsigned rot = inst.relocs[0].exp.X_add_number; | |
17941 | constraint (rot != 90 && rot != 270, _("immediate out of range")); | |
17942 | ||
17943 | if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg) | |
17944 | as_tsktsk (_("Warning: 32-bit element size and same first and third " | |
17945 | "operand makes instruction UNPREDICTABLE")); | |
17946 | ||
17947 | mve_encode_qqq (0, et.size); | |
17948 | inst.instruction |= (rot == 270) << 12; | |
17949 | inst.is_neon = 1; | |
17950 | } | |
17951 | ||
35d1cfc2 AV |
17952 | static void |
17953 | do_mve_vqdmull (void) | |
17954 | { | |
17955 | enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL); | |
17956 | struct neon_type_el et | |
17957 | = neon_check_type (3, rs, N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
17958 | ||
17959 | if (et.size == 32 | |
17960 | && (inst.operands[0].reg == inst.operands[1].reg | |
17961 | || (rs == NS_QQQ && inst.operands[0].reg == inst.operands[2].reg))) | |
17962 | as_tsktsk (BAD_MVE_SRCDEST); | |
17963 | ||
17964 | if (inst.cond > COND_ALWAYS) | |
17965 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
17966 | else | |
17967 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
17968 | ||
17969 | if (rs == NS_QQQ) | |
17970 | { | |
17971 | mve_encode_qqq (et.size == 32, 64); | |
17972 | inst.instruction |= 1; | |
17973 | } | |
17974 | else | |
17975 | { | |
17976 | mve_encode_qqr (64, et.size == 32, 0); | |
17977 | inst.instruction |= 0x3 << 5; | |
17978 | } | |
17979 | } | |
17980 | ||
c2dafc2a AV |
17981 | static void |
17982 | do_mve_vadc (void) | |
17983 | { | |
17984 | enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL); | |
17985 | struct neon_type_el et | |
17986 | = neon_check_type (3, rs, N_KEY | N_I32, N_EQK, N_EQK); | |
17987 | ||
17988 | if (et.type == NT_invtype) | |
17989 | first_error (BAD_EL_TYPE); | |
17990 | ||
17991 | if (inst.cond > COND_ALWAYS) | |
17992 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
17993 | else | |
17994 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
17995 | ||
17996 | mve_encode_qqq (0, 64); | |
17997 | } | |
17998 | ||
17999 | static void | |
18000 | do_mve_vbrsr (void) | |
18001 | { | |
18002 | enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL); | |
18003 | struct neon_type_el et | |
18004 | = neon_check_type (3, rs, N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
18005 | ||
18006 | if (inst.cond > COND_ALWAYS) | |
18007 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
18008 | else | |
18009 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
18010 | ||
7df54120 | 18011 | mve_encode_qqr (et.size, 0, 0); |
c2dafc2a AV |
18012 | } |
18013 | ||
18014 | static void | |
18015 | do_mve_vsbc (void) | |
18016 | { | |
18017 | neon_check_type (3, NS_QQQ, N_EQK, N_EQK, N_I32 | N_KEY); | |
18018 | ||
18019 | if (inst.cond > COND_ALWAYS) | |
18020 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
18021 | else | |
18022 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
18023 | ||
18024 | mve_encode_qqq (1, 64); | |
18025 | } | |
18026 | ||
2d78f95b AV |
18027 | static void |
18028 | do_mve_vmulh (void) | |
18029 | { | |
18030 | enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL); | |
18031 | struct neon_type_el et | |
18032 | = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY); | |
18033 | ||
18034 | if (inst.cond > COND_ALWAYS) | |
18035 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
18036 | else | |
18037 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
18038 | ||
18039 | mve_encode_qqq (et.type == NT_unsigned, et.size); | |
18040 | } | |
18041 | ||
42b16635 AV |
18042 | static void |
18043 | do_mve_vqdmlah (void) | |
18044 | { | |
18045 | enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL); | |
18046 | struct neon_type_el et | |
23d188c7 | 18047 | = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY); |
42b16635 AV |
18048 | |
18049 | if (inst.cond > COND_ALWAYS) | |
18050 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
18051 | else | |
18052 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
18053 | ||
18054 | mve_encode_qqr (et.size, et.type == NT_unsigned, 0); | |
18055 | } | |
8b8b22a4 AV |
18056 | |
18057 | static void | |
18058 | do_mve_vqdmladh (void) | |
18059 | { | |
18060 | enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL); | |
18061 | struct neon_type_el et | |
18062 | = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
18063 | ||
18064 | if (inst.cond > COND_ALWAYS) | |
18065 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
18066 | else | |
18067 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
18068 | ||
8b8b22a4 AV |
18069 | mve_encode_qqq (0, et.size); |
18070 | } | |
18071 | ||
18072 | ||
886e1c73 AV |
18073 | static void |
18074 | do_mve_vmull (void) | |
18075 | { | |
18076 | ||
18077 | enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_DDS, | |
18078 | NS_QQS, NS_QQQ, NS_QQR, NS_NULL); | |
18079 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) | |
18080 | && inst.cond == COND_ALWAYS | |
18081 | && ((unsigned)inst.instruction) == M_MNEM_vmullt) | |
18082 | { | |
18083 | if (rs == NS_QQQ) | |
18084 | { | |
18085 | ||
18086 | struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK, | |
18087 | N_SUF_32 | N_F64 | N_P8 | |
18088 | | N_P16 | N_I_MVE | N_KEY); | |
18089 | if (((et.type == NT_poly) && et.size == 8 | |
18090 | && ARM_CPU_IS_ANY (cpu_variant)) | |
18091 | || (et.type == NT_integer) || (et.type == NT_float)) | |
18092 | goto neon_vmul; | |
18093 | } | |
18094 | else | |
18095 | goto neon_vmul; | |
18096 | } | |
18097 | ||
18098 | constraint (rs != NS_QQQ, BAD_FPU); | |
18099 | struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK, | |
18100 | N_SU_32 | N_P8 | N_P16 | N_KEY); | |
18101 | ||
18102 | /* We are dealing with MVE's vmullt. */ | |
18103 | if (et.size == 32 | |
18104 | && (inst.operands[0].reg == inst.operands[1].reg | |
18105 | || inst.operands[0].reg == inst.operands[2].reg)) | |
18106 | as_tsktsk (BAD_MVE_SRCDEST); | |
18107 | ||
18108 | if (inst.cond > COND_ALWAYS) | |
18109 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
18110 | else | |
18111 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
18112 | ||
18113 | if (et.type == NT_poly) | |
18114 | mve_encode_qqq (neon_logbits (et.size), 64); | |
18115 | else | |
18116 | mve_encode_qqq (et.type == NT_unsigned, et.size); | |
18117 | ||
18118 | return; | |
18119 | ||
18120 | neon_vmul: | |
18121 | inst.instruction = N_MNEM_vmul; | |
18122 | inst.cond = 0xb; | |
18123 | if (thumb_mode) | |
18124 | inst.pred_insn_type = INSIDE_IT_INSN; | |
18125 | do_neon_mul (); | |
18126 | } | |
18127 | ||
a302e574 AV |
18128 | static void |
18129 | do_mve_vabav (void) | |
18130 | { | |
18131 | enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL); | |
18132 | ||
18133 | if (rs == NS_NULL) | |
18134 | return; | |
18135 | ||
18136 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
18137 | return; | |
18138 | ||
18139 | struct neon_type_el et = neon_check_type (2, NS_NULL, N_EQK, N_KEY | N_S8 | |
18140 | | N_S16 | N_S32 | N_U8 | N_U16 | |
18141 | | N_U32); | |
18142 | ||
18143 | if (inst.cond > COND_ALWAYS) | |
18144 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
18145 | else | |
18146 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
18147 | ||
18148 | mve_encode_rqq (et.type == NT_unsigned, et.size); | |
18149 | } | |
18150 | ||
18151 | static void | |
18152 | do_mve_vmladav (void) | |
18153 | { | |
18154 | enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL); | |
18155 | struct neon_type_el et = neon_check_type (3, rs, | |
18156 | N_EQK, N_EQK, N_SU_MVE | N_KEY); | |
18157 | ||
18158 | if (et.type == NT_unsigned | |
18159 | && (inst.instruction == M_MNEM_vmladavx | |
18160 | || inst.instruction == M_MNEM_vmladavax | |
18161 | || inst.instruction == M_MNEM_vmlsdav | |
18162 | || inst.instruction == M_MNEM_vmlsdava | |
18163 | || inst.instruction == M_MNEM_vmlsdavx | |
18164 | || inst.instruction == M_MNEM_vmlsdavax)) | |
18165 | first_error (BAD_SIMD_TYPE); | |
18166 | ||
18167 | constraint (inst.operands[2].reg > 14, | |
18168 | _("MVE vector register in the range [Q0..Q7] expected")); | |
18169 | ||
18170 | if (inst.cond > COND_ALWAYS) | |
18171 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
18172 | else | |
18173 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
18174 | ||
18175 | if (inst.instruction == M_MNEM_vmlsdav | |
18176 | || inst.instruction == M_MNEM_vmlsdava | |
18177 | || inst.instruction == M_MNEM_vmlsdavx | |
18178 | || inst.instruction == M_MNEM_vmlsdavax) | |
18179 | inst.instruction |= (et.size == 8) << 28; | |
18180 | else | |
18181 | inst.instruction |= (et.size == 8) << 8; | |
18182 | ||
18183 | mve_encode_rqq (et.type == NT_unsigned, 64); | |
18184 | inst.instruction |= (et.size == 32) << 16; | |
18185 | } | |
18186 | ||
93925576 AV |
18187 | static void |
18188 | do_mve_vmlaldav (void) | |
18189 | { | |
18190 | enum neon_shape rs = neon_select_shape (NS_RRQQ, NS_NULL); | |
18191 | struct neon_type_el et | |
18192 | = neon_check_type (4, rs, N_EQK, N_EQK, N_EQK, | |
18193 | N_S16 | N_S32 | N_U16 | N_U32 | N_KEY); | |
18194 | ||
18195 | if (et.type == NT_unsigned | |
18196 | && (inst.instruction == M_MNEM_vmlsldav | |
18197 | || inst.instruction == M_MNEM_vmlsldava | |
18198 | || inst.instruction == M_MNEM_vmlsldavx | |
18199 | || inst.instruction == M_MNEM_vmlsldavax)) | |
18200 | first_error (BAD_SIMD_TYPE); | |
18201 | ||
18202 | if (inst.cond > COND_ALWAYS) | |
18203 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
18204 | else | |
18205 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
18206 | ||
18207 | mve_encode_rrqq (et.type == NT_unsigned, et.size); | |
18208 | } | |
18209 | ||
18210 | static void | |
18211 | do_mve_vrmlaldavh (void) | |
18212 | { | |
18213 | struct neon_type_el et; | |
18214 | if (inst.instruction == M_MNEM_vrmlsldavh | |
18215 | || inst.instruction == M_MNEM_vrmlsldavha | |
18216 | || inst.instruction == M_MNEM_vrmlsldavhx | |
18217 | || inst.instruction == M_MNEM_vrmlsldavhax) | |
18218 | { | |
18219 | et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY); | |
18220 | if (inst.operands[1].reg == REG_SP) | |
18221 | as_tsktsk (MVE_BAD_SP); | |
18222 | } | |
18223 | else | |
18224 | { | |
18225 | if (inst.instruction == M_MNEM_vrmlaldavhx | |
18226 | || inst.instruction == M_MNEM_vrmlaldavhax) | |
18227 | et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY); | |
18228 | else | |
18229 | et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, | |
18230 | N_U32 | N_S32 | N_KEY); | |
18231 | /* vrmlaldavh's encoding with SP as the second, odd, GPR operand may alias | |
18232 | with vmax/min instructions, making the use of SP in assembly really | |
18233 | nonsensical, so instead of issuing a warning like we do for other uses | |
18234 | of SP for the odd register operand we error out. */ | |
18235 | constraint (inst.operands[1].reg == REG_SP, BAD_SP); | |
18236 | } | |
18237 | ||
18238 | /* Make sure we still check the second operand is an odd one and that PC is | |
18239 | disallowed. This because we are parsing for any GPR operand, to be able | |
18240 | to distinguish between giving a warning or an error for SP as described | |
18241 | above. */ | |
18242 | constraint ((inst.operands[1].reg % 2) != 1, BAD_EVEN); | |
18243 | constraint (inst.operands[1].reg == REG_PC, BAD_PC); | |
18244 | ||
18245 | if (inst.cond > COND_ALWAYS) | |
18246 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
18247 | else | |
18248 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
18249 | ||
18250 | mve_encode_rrqq (et.type == NT_unsigned, 0); | |
18251 | } | |
18252 | ||
18253 | ||
8cd78170 AV |
18254 | static void |
18255 | do_mve_vmaxnmv (void) | |
18256 | { | |
18257 | enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL); | |
18258 | struct neon_type_el et | |
18259 | = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY); | |
18260 | ||
18261 | if (inst.cond > COND_ALWAYS) | |
18262 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
18263 | else | |
18264 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
18265 | ||
18266 | if (inst.operands[0].reg == REG_SP) | |
18267 | as_tsktsk (MVE_BAD_SP); | |
18268 | else if (inst.operands[0].reg == REG_PC) | |
18269 | as_tsktsk (MVE_BAD_PC); | |
18270 | ||
18271 | mve_encode_rq (et.size == 16, 64); | |
18272 | } | |
18273 | ||
13ccd4c0 AV |
18274 | static void |
18275 | do_mve_vmaxv (void) | |
18276 | { | |
18277 | enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL); | |
18278 | struct neon_type_el et; | |
18279 | ||
18280 | if (inst.instruction == M_MNEM_vmaxv || inst.instruction == M_MNEM_vminv) | |
18281 | et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY); | |
18282 | else | |
18283 | et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
18284 | ||
18285 | if (inst.cond > COND_ALWAYS) | |
18286 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
18287 | else | |
18288 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
18289 | ||
18290 | if (inst.operands[0].reg == REG_SP) | |
18291 | as_tsktsk (MVE_BAD_SP); | |
18292 | else if (inst.operands[0].reg == REG_PC) | |
18293 | as_tsktsk (MVE_BAD_PC); | |
18294 | ||
18295 | mve_encode_rq (et.type == NT_unsigned, et.size); | |
18296 | } | |
18297 | ||
18298 | ||
643afb90 MW |
18299 | static void |
18300 | do_neon_qrdmlah (void) | |
18301 | { | |
64c350f2 | 18302 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
42b16635 AV |
18303 | return; |
18304 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
643afb90 | 18305 | { |
42b16635 AV |
18306 | /* Check we're on the correct architecture. */ |
18307 | if (!mark_feature_used (&fpu_neon_ext_armv8)) | |
18308 | inst.error | |
18309 | = _("instruction form not available on this architecture."); | |
18310 | else if (!mark_feature_used (&fpu_neon_ext_v8_1)) | |
18311 | { | |
18312 | as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD.")); | |
18313 | record_feature_use (&fpu_neon_ext_v8_1); | |
18314 | } | |
18315 | if (inst.operands[2].isscalar) | |
18316 | { | |
18317 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); | |
18318 | struct neon_type_el et = neon_check_type (3, rs, | |
18319 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
18320 | NEON_ENCODE (SCALAR, inst); | |
18321 | neon_mul_mac (et, neon_quad (rs)); | |
18322 | } | |
18323 | else | |
18324 | { | |
18325 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
18326 | struct neon_type_el et = neon_check_type (3, rs, | |
18327 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
18328 | NEON_ENCODE (INTEGER, inst); | |
18329 | /* The U bit (rounding) comes from bit mask. */ | |
18330 | neon_three_same (neon_quad (rs), 0, et.size); | |
18331 | } | |
643afb90 MW |
18332 | } |
18333 | else | |
18334 | { | |
42b16635 AV |
18335 | enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL); |
18336 | struct neon_type_el et | |
23d188c7 | 18337 | = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY); |
42b16635 | 18338 | |
643afb90 | 18339 | NEON_ENCODE (INTEGER, inst); |
42b16635 | 18340 | mve_encode_qqr (et.size, et.type == NT_unsigned, 0); |
643afb90 MW |
18341 | } |
18342 | } | |
18343 | ||
5287ad62 JB |
18344 | static void |
18345 | do_neon_fcmp_absolute (void) | |
18346 | { | |
037e8744 | 18347 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
cc933301 JW |
18348 | struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK, |
18349 | N_F_16_32 | N_KEY); | |
5287ad62 | 18350 | /* Size field comes from bit mask. */ |
cc933301 | 18351 | neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1); |
5287ad62 JB |
18352 | } |
18353 | ||
18354 | static void | |
18355 | do_neon_fcmp_absolute_inv (void) | |
18356 | { | |
18357 | neon_exchange_operands (); | |
18358 | do_neon_fcmp_absolute (); | |
18359 | } | |
18360 | ||
18361 | static void | |
18362 | do_neon_step (void) | |
18363 | { | |
037e8744 | 18364 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
cc933301 JW |
18365 | struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK, |
18366 | N_F_16_32 | N_KEY); | |
18367 | neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1); | |
5287ad62 JB |
18368 | } |
18369 | ||
18370 | static void | |
18371 | do_neon_abs_neg (void) | |
18372 | { | |
037e8744 JB |
18373 | enum neon_shape rs; |
18374 | struct neon_type_el et; | |
5f4273c7 | 18375 | |
037e8744 JB |
18376 | if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS) |
18377 | return; | |
18378 | ||
037e8744 | 18379 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
cc933301 | 18380 | et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY); |
5f4273c7 | 18381 | |
64c350f2 AV |
18382 | if (!check_simd_pred_availability (et.type == NT_float, |
18383 | NEON_CHECK_ARCH | NEON_CHECK_CC)) | |
485dee97 AV |
18384 | return; |
18385 | ||
5287ad62 JB |
18386 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
18387 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
18388 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
18389 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 18390 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
18391 | inst.instruction |= (et.type == NT_float) << 10; |
18392 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 18393 | |
88714cb8 | 18394 | neon_dp_fixup (&inst); |
5287ad62 JB |
18395 | } |
18396 | ||
18397 | static void | |
18398 | do_neon_sli (void) | |
18399 | { | |
64c350f2 | 18400 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
4401c241 AV |
18401 | return; |
18402 | ||
18403 | enum neon_shape rs; | |
18404 | struct neon_type_el et; | |
18405 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
18406 | { | |
18407 | rs = neon_select_shape (NS_QQI, NS_NULL); | |
18408 | et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
18409 | } | |
18410 | else | |
18411 | { | |
18412 | rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); | |
18413 | et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
18414 | } | |
18415 | ||
18416 | ||
5287ad62 JB |
18417 | int imm = inst.operands[2].imm; |
18418 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
477330fc | 18419 | _("immediate out of range for insert")); |
037e8744 | 18420 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
18421 | } |
18422 | ||
18423 | static void | |
18424 | do_neon_sri (void) | |
18425 | { | |
64c350f2 | 18426 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
4401c241 AV |
18427 | return; |
18428 | ||
18429 | enum neon_shape rs; | |
18430 | struct neon_type_el et; | |
18431 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
18432 | { | |
18433 | rs = neon_select_shape (NS_QQI, NS_NULL); | |
18434 | et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
18435 | } | |
18436 | else | |
18437 | { | |
18438 | rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); | |
18439 | et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
18440 | } | |
18441 | ||
5287ad62 JB |
18442 | int imm = inst.operands[2].imm; |
18443 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 18444 | _("immediate out of range for insert")); |
037e8744 | 18445 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm); |
5287ad62 JB |
18446 | } |
18447 | ||
18448 | static void | |
18449 | do_neon_qshlu_imm (void) | |
18450 | { | |
64c350f2 | 18451 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
5150f0d8 AV |
18452 | return; |
18453 | ||
18454 | enum neon_shape rs; | |
18455 | struct neon_type_el et; | |
18456 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
18457 | { | |
18458 | rs = neon_select_shape (NS_QQI, NS_NULL); | |
18459 | et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
18460 | } | |
18461 | else | |
18462 | { | |
18463 | rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); | |
18464 | et = neon_check_type (2, rs, N_EQK | N_UNS, | |
18465 | N_S8 | N_S16 | N_S32 | N_S64 | N_KEY); | |
18466 | } | |
18467 | ||
5287ad62 JB |
18468 | int imm = inst.operands[2].imm; |
18469 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
477330fc | 18470 | _("immediate out of range for shift")); |
5287ad62 JB |
18471 | /* Only encodes the 'U present' variant of the instruction. |
18472 | In this case, signed types have OP (bit 8) set to 0. | |
18473 | Unsigned types have OP set to 1. */ | |
18474 | inst.instruction |= (et.type == NT_unsigned) << 8; | |
18475 | /* The rest of the bits are the same as other immediate shifts. */ | |
037e8744 | 18476 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
18477 | } |
18478 | ||
18479 | static void | |
18480 | do_neon_qmovn (void) | |
18481 | { | |
18482 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
18483 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
18484 | /* Saturating move where operands can be signed or unsigned, and the | |
18485 | destination has the same signedness. */ | |
88714cb8 | 18486 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
18487 | if (et.type == NT_unsigned) |
18488 | inst.instruction |= 0xc0; | |
18489 | else | |
18490 | inst.instruction |= 0x80; | |
18491 | neon_two_same (0, 1, et.size / 2); | |
18492 | } | |
18493 | ||
18494 | static void | |
18495 | do_neon_qmovun (void) | |
18496 | { | |
18497 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
18498 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
18499 | /* Saturating move with unsigned results. Operands must be signed. */ | |
88714cb8 | 18500 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
18501 | neon_two_same (0, 1, et.size / 2); |
18502 | } | |
18503 | ||
18504 | static void | |
18505 | do_neon_rshift_sat_narrow (void) | |
18506 | { | |
18507 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
18508 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
18509 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
18510 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
18511 | int imm = inst.operands[2].imm; | |
18512 | /* This gets the bounds check, size encoding and immediate bits calculation | |
18513 | right. */ | |
18514 | et.size /= 2; | |
5f4273c7 | 18515 | |
5287ad62 JB |
18516 | /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for |
18517 | VQMOVN.I<size> <Dd>, <Qm>. */ | |
18518 | if (imm == 0) | |
18519 | { | |
18520 | inst.operands[2].present = 0; | |
18521 | inst.instruction = N_MNEM_vqmovn; | |
18522 | do_neon_qmovn (); | |
18523 | return; | |
18524 | } | |
5f4273c7 | 18525 | |
5287ad62 | 18526 | constraint (imm < 1 || (unsigned)imm > et.size, |
477330fc | 18527 | _("immediate out of range")); |
5287ad62 JB |
18528 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm); |
18529 | } | |
18530 | ||
18531 | static void | |
18532 | do_neon_rshift_sat_narrow_u (void) | |
18533 | { | |
18534 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
18535 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
18536 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
18537 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
18538 | int imm = inst.operands[2].imm; | |
18539 | /* This gets the bounds check, size encoding and immediate bits calculation | |
18540 | right. */ | |
18541 | et.size /= 2; | |
18542 | ||
18543 | /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
18544 | VQMOVUN.I<size> <Dd>, <Qm>. */ | |
18545 | if (imm == 0) | |
18546 | { | |
18547 | inst.operands[2].present = 0; | |
18548 | inst.instruction = N_MNEM_vqmovun; | |
18549 | do_neon_qmovun (); | |
18550 | return; | |
18551 | } | |
18552 | ||
18553 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 18554 | _("immediate out of range")); |
5287ad62 JB |
18555 | /* FIXME: The manual is kind of unclear about what value U should have in |
18556 | VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it | |
18557 | must be 1. */ | |
18558 | neon_imm_shift (TRUE, 1, 0, et, et.size - imm); | |
18559 | } | |
18560 | ||
18561 | static void | |
18562 | do_neon_movn (void) | |
18563 | { | |
18564 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
18565 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
88714cb8 | 18566 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
18567 | neon_two_same (0, 1, et.size / 2); |
18568 | } | |
18569 | ||
18570 | static void | |
18571 | do_neon_rshift_narrow (void) | |
18572 | { | |
18573 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
18574 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
18575 | int imm = inst.operands[2].imm; | |
18576 | /* This gets the bounds check, size encoding and immediate bits calculation | |
18577 | right. */ | |
18578 | et.size /= 2; | |
5f4273c7 | 18579 | |
5287ad62 JB |
18580 | /* If immediate is zero then we are a pseudo-instruction for |
18581 | VMOVN.I<size> <Dd>, <Qm> */ | |
18582 | if (imm == 0) | |
18583 | { | |
18584 | inst.operands[2].present = 0; | |
18585 | inst.instruction = N_MNEM_vmovn; | |
18586 | do_neon_movn (); | |
18587 | return; | |
18588 | } | |
5f4273c7 | 18589 | |
5287ad62 | 18590 | constraint (imm < 1 || (unsigned)imm > et.size, |
477330fc | 18591 | _("immediate out of range for narrowing operation")); |
5287ad62 JB |
18592 | neon_imm_shift (FALSE, 0, 0, et, et.size - imm); |
18593 | } | |
18594 | ||
18595 | static void | |
18596 | do_neon_shll (void) | |
18597 | { | |
18598 | /* FIXME: Type checking when lengthening. */ | |
18599 | struct neon_type_el et = neon_check_type (2, NS_QDI, | |
18600 | N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY); | |
18601 | unsigned imm = inst.operands[2].imm; | |
18602 | ||
18603 | if (imm == et.size) | |
18604 | { | |
18605 | /* Maximum shift variant. */ | |
88714cb8 | 18606 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
18607 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
18608 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
18609 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
18610 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
18611 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 18612 | |
88714cb8 | 18613 | neon_dp_fixup (&inst); |
5287ad62 JB |
18614 | } |
18615 | else | |
18616 | { | |
18617 | /* A more-specific type check for non-max versions. */ | |
18618 | et = neon_check_type (2, NS_QDI, | |
477330fc | 18619 | N_EQK | N_DBL, N_SU_32 | N_KEY); |
88714cb8 | 18620 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
18621 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm); |
18622 | } | |
18623 | } | |
18624 | ||
037e8744 | 18625 | /* Check the various types for the VCVT instruction, and return which version |
5287ad62 JB |
18626 | the current instruction is. */ |
18627 | ||
6b9a8b67 MGD |
18628 | #define CVT_FLAVOUR_VAR \ |
18629 | CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \ | |
18630 | CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \ | |
18631 | CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \ | |
18632 | CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \ | |
18633 | /* Half-precision conversions. */ \ | |
cc933301 JW |
18634 | CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \ |
18635 | CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \ | |
18636 | CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \ | |
18637 | CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \ | |
6b9a8b67 MGD |
18638 | CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \ |
18639 | CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \ | |
9db2f6b4 RL |
18640 | /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \ |
18641 | Compared with single/double precision variants, only the co-processor \ | |
18642 | field is different, so the encoding flow is reused here. */ \ | |
18643 | CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \ | |
18644 | CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \ | |
18645 | CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\ | |
18646 | CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\ | |
6b9a8b67 MGD |
18647 | /* VFP instructions. */ \ |
18648 | CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \ | |
18649 | CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \ | |
18650 | CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \ | |
18651 | CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \ | |
18652 | CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \ | |
18653 | CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \ | |
18654 | /* VFP instructions with bitshift. */ \ | |
18655 | CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \ | |
18656 | CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \ | |
18657 | CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \ | |
18658 | CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \ | |
18659 | CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \ | |
18660 | CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \ | |
18661 | CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \ | |
18662 | CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL) | |
18663 | ||
18664 | #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \ | |
18665 | neon_cvt_flavour_##C, | |
18666 | ||
18667 | /* The different types of conversions we can do. */ | |
18668 | enum neon_cvt_flavour | |
18669 | { | |
18670 | CVT_FLAVOUR_VAR | |
18671 | neon_cvt_flavour_invalid, | |
18672 | neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64 | |
18673 | }; | |
18674 | ||
18675 | #undef CVT_VAR | |
18676 | ||
18677 | static enum neon_cvt_flavour | |
18678 | get_neon_cvt_flavour (enum neon_shape rs) | |
5287ad62 | 18679 | { |
6b9a8b67 MGD |
18680 | #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \ |
18681 | et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \ | |
18682 | if (et.type != NT_invtype) \ | |
18683 | { \ | |
18684 | inst.error = NULL; \ | |
18685 | return (neon_cvt_flavour_##C); \ | |
5287ad62 | 18686 | } |
6b9a8b67 | 18687 | |
5287ad62 | 18688 | struct neon_type_el et; |
037e8744 | 18689 | unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF |
477330fc | 18690 | || rs == NS_FF) ? N_VFP : 0; |
037e8744 JB |
18691 | /* The instruction versions which take an immediate take one register |
18692 | argument, which is extended to the width of the full register. Thus the | |
18693 | "source" and "destination" registers must have the same width. Hack that | |
18694 | here by making the size equal to the key (wider, in this case) operand. */ | |
18695 | unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0; | |
5f4273c7 | 18696 | |
6b9a8b67 MGD |
18697 | CVT_FLAVOUR_VAR; |
18698 | ||
18699 | return neon_cvt_flavour_invalid; | |
5287ad62 JB |
18700 | #undef CVT_VAR |
18701 | } | |
18702 | ||
7e8e6784 MGD |
18703 | enum neon_cvt_mode |
18704 | { | |
18705 | neon_cvt_mode_a, | |
18706 | neon_cvt_mode_n, | |
18707 | neon_cvt_mode_p, | |
18708 | neon_cvt_mode_m, | |
18709 | neon_cvt_mode_z, | |
30bdf752 MGD |
18710 | neon_cvt_mode_x, |
18711 | neon_cvt_mode_r | |
7e8e6784 MGD |
18712 | }; |
18713 | ||
037e8744 JB |
18714 | /* Neon-syntax VFP conversions. */ |
18715 | ||
5287ad62 | 18716 | static void |
6b9a8b67 | 18717 | do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour) |
5287ad62 | 18718 | { |
037e8744 | 18719 | const char *opname = 0; |
5f4273c7 | 18720 | |
d54af2d0 RL |
18721 | if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI |
18722 | || rs == NS_FHI || rs == NS_HFI) | |
5287ad62 | 18723 | { |
037e8744 JB |
18724 | /* Conversions with immediate bitshift. */ |
18725 | const char *enc[] = | |
477330fc | 18726 | { |
6b9a8b67 MGD |
18727 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN, |
18728 | CVT_FLAVOUR_VAR | |
18729 | NULL | |
18730 | #undef CVT_VAR | |
477330fc | 18731 | }; |
037e8744 | 18732 | |
6b9a8b67 | 18733 | if (flavour < (int) ARRAY_SIZE (enc)) |
477330fc RM |
18734 | { |
18735 | opname = enc[flavour]; | |
18736 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
18737 | _("operands 0 and 1 must be the same register")); | |
18738 | inst.operands[1] = inst.operands[2]; | |
18739 | memset (&inst.operands[2], '\0', sizeof (inst.operands[2])); | |
18740 | } | |
5287ad62 JB |
18741 | } |
18742 | else | |
18743 | { | |
037e8744 JB |
18744 | /* Conversions without bitshift. */ |
18745 | const char *enc[] = | |
477330fc | 18746 | { |
6b9a8b67 MGD |
18747 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN, |
18748 | CVT_FLAVOUR_VAR | |
18749 | NULL | |
18750 | #undef CVT_VAR | |
477330fc | 18751 | }; |
037e8744 | 18752 | |
6b9a8b67 | 18753 | if (flavour < (int) ARRAY_SIZE (enc)) |
477330fc | 18754 | opname = enc[flavour]; |
037e8744 JB |
18755 | } |
18756 | ||
18757 | if (opname) | |
18758 | do_vfp_nsyn_opcode (opname); | |
9db2f6b4 RL |
18759 | |
18760 | /* ARMv8.2 fp16 VCVT instruction. */ | |
18761 | if (flavour == neon_cvt_flavour_s32_f16 | |
18762 | || flavour == neon_cvt_flavour_u32_f16 | |
18763 | || flavour == neon_cvt_flavour_f16_u32 | |
18764 | || flavour == neon_cvt_flavour_f16_s32) | |
18765 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
18766 | } |
18767 | ||
18768 | static void | |
18769 | do_vfp_nsyn_cvtz (void) | |
18770 | { | |
d54af2d0 | 18771 | enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL); |
6b9a8b67 | 18772 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 JB |
18773 | const char *enc[] = |
18774 | { | |
6b9a8b67 MGD |
18775 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN, |
18776 | CVT_FLAVOUR_VAR | |
18777 | NULL | |
18778 | #undef CVT_VAR | |
037e8744 JB |
18779 | }; |
18780 | ||
6b9a8b67 | 18781 | if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour]) |
037e8744 JB |
18782 | do_vfp_nsyn_opcode (enc[flavour]); |
18783 | } | |
f31fef98 | 18784 | |
037e8744 | 18785 | static void |
bacebabc | 18786 | do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour, |
7e8e6784 MGD |
18787 | enum neon_cvt_mode mode) |
18788 | { | |
18789 | int sz, op; | |
18790 | int rm; | |
18791 | ||
a715796b TG |
18792 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
18793 | D register operands. */ | |
18794 | if (flavour == neon_cvt_flavour_s32_f64 | |
18795 | || flavour == neon_cvt_flavour_u32_f64) | |
18796 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
18797 | _(BAD_FPU)); | |
18798 | ||
9db2f6b4 RL |
18799 | if (flavour == neon_cvt_flavour_s32_f16 |
18800 | || flavour == neon_cvt_flavour_u32_f16) | |
18801 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16), | |
18802 | _(BAD_FP16)); | |
18803 | ||
5ee91343 | 18804 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
7e8e6784 MGD |
18805 | |
18806 | switch (flavour) | |
18807 | { | |
18808 | case neon_cvt_flavour_s32_f64: | |
18809 | sz = 1; | |
827f64ff | 18810 | op = 1; |
7e8e6784 MGD |
18811 | break; |
18812 | case neon_cvt_flavour_s32_f32: | |
18813 | sz = 0; | |
18814 | op = 1; | |
18815 | break; | |
9db2f6b4 RL |
18816 | case neon_cvt_flavour_s32_f16: |
18817 | sz = 0; | |
18818 | op = 1; | |
18819 | break; | |
7e8e6784 MGD |
18820 | case neon_cvt_flavour_u32_f64: |
18821 | sz = 1; | |
18822 | op = 0; | |
18823 | break; | |
18824 | case neon_cvt_flavour_u32_f32: | |
18825 | sz = 0; | |
18826 | op = 0; | |
18827 | break; | |
9db2f6b4 RL |
18828 | case neon_cvt_flavour_u32_f16: |
18829 | sz = 0; | |
18830 | op = 0; | |
18831 | break; | |
7e8e6784 MGD |
18832 | default: |
18833 | first_error (_("invalid instruction shape")); | |
18834 | return; | |
18835 | } | |
18836 | ||
18837 | switch (mode) | |
18838 | { | |
18839 | case neon_cvt_mode_a: rm = 0; break; | |
18840 | case neon_cvt_mode_n: rm = 1; break; | |
18841 | case neon_cvt_mode_p: rm = 2; break; | |
18842 | case neon_cvt_mode_m: rm = 3; break; | |
18843 | default: first_error (_("invalid rounding mode")); return; | |
18844 | } | |
18845 | ||
18846 | NEON_ENCODE (FPV8, inst); | |
18847 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
18848 | encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm); | |
18849 | inst.instruction |= sz << 8; | |
9db2f6b4 RL |
18850 | |
18851 | /* ARMv8.2 fp16 VCVT instruction. */ | |
18852 | if (flavour == neon_cvt_flavour_s32_f16 | |
18853 | ||flavour == neon_cvt_flavour_u32_f16) | |
18854 | do_scalar_fp16_v82_encode (); | |
7e8e6784 MGD |
18855 | inst.instruction |= op << 7; |
18856 | inst.instruction |= rm << 16; | |
18857 | inst.instruction |= 0xf0000000; | |
18858 | inst.is_neon = TRUE; | |
18859 | } | |
18860 | ||
18861 | static void | |
18862 | do_neon_cvt_1 (enum neon_cvt_mode mode) | |
037e8744 JB |
18863 | { |
18864 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ, | |
d54af2d0 RL |
18865 | NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, |
18866 | NS_FH, NS_HF, NS_FHI, NS_HFI, | |
18867 | NS_NULL); | |
6b9a8b67 | 18868 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 | 18869 | |
cc933301 JW |
18870 | if (flavour == neon_cvt_flavour_invalid) |
18871 | return; | |
18872 | ||
e3e535bc | 18873 | /* PR11109: Handle round-to-zero for VCVT conversions. */ |
7e8e6784 | 18874 | if (mode == neon_cvt_mode_z |
e3e535bc | 18875 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2) |
cc933301 JW |
18876 | && (flavour == neon_cvt_flavour_s16_f16 |
18877 | || flavour == neon_cvt_flavour_u16_f16 | |
18878 | || flavour == neon_cvt_flavour_s32_f32 | |
bacebabc RM |
18879 | || flavour == neon_cvt_flavour_u32_f32 |
18880 | || flavour == neon_cvt_flavour_s32_f64 | |
6b9a8b67 | 18881 | || flavour == neon_cvt_flavour_u32_f64) |
e3e535bc NC |
18882 | && (rs == NS_FD || rs == NS_FF)) |
18883 | { | |
18884 | do_vfp_nsyn_cvtz (); | |
18885 | return; | |
18886 | } | |
18887 | ||
9db2f6b4 RL |
18888 | /* ARMv8.2 fp16 VCVT conversions. */ |
18889 | if (mode == neon_cvt_mode_z | |
18890 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16) | |
18891 | && (flavour == neon_cvt_flavour_s32_f16 | |
18892 | || flavour == neon_cvt_flavour_u32_f16) | |
18893 | && (rs == NS_FH)) | |
18894 | { | |
18895 | do_vfp_nsyn_cvtz (); | |
18896 | do_scalar_fp16_v82_encode (); | |
18897 | return; | |
18898 | } | |
18899 | ||
037e8744 | 18900 | /* VFP rather than Neon conversions. */ |
6b9a8b67 | 18901 | if (flavour >= neon_cvt_flavour_first_fp) |
037e8744 | 18902 | { |
7e8e6784 MGD |
18903 | if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z) |
18904 | do_vfp_nsyn_cvt (rs, flavour); | |
18905 | else | |
18906 | do_vfp_nsyn_cvt_fpv8 (flavour, mode); | |
18907 | ||
037e8744 JB |
18908 | return; |
18909 | } | |
18910 | ||
18911 | switch (rs) | |
18912 | { | |
037e8744 | 18913 | case NS_QQI: |
dd9634d9 AV |
18914 | if (mode == neon_cvt_mode_z |
18915 | && (flavour == neon_cvt_flavour_f16_s16 | |
18916 | || flavour == neon_cvt_flavour_f16_u16 | |
18917 | || flavour == neon_cvt_flavour_s16_f16 | |
18918 | || flavour == neon_cvt_flavour_u16_f16 | |
18919 | || flavour == neon_cvt_flavour_f32_u32 | |
18920 | || flavour == neon_cvt_flavour_f32_s32 | |
18921 | || flavour == neon_cvt_flavour_s32_f32 | |
18922 | || flavour == neon_cvt_flavour_u32_f32)) | |
18923 | { | |
64c350f2 AV |
18924 | if (!check_simd_pred_availability (TRUE, |
18925 | NEON_CHECK_CC | NEON_CHECK_ARCH)) | |
dd9634d9 AV |
18926 | return; |
18927 | } | |
18928 | else if (mode == neon_cvt_mode_n) | |
18929 | { | |
18930 | /* We are dealing with vcvt with the 'ne' condition. */ | |
18931 | inst.cond = 0x1; | |
18932 | inst.instruction = N_MNEM_vcvt; | |
18933 | do_neon_cvt_1 (neon_cvt_mode_z); | |
18934 | return; | |
18935 | } | |
18936 | /* fall through. */ | |
18937 | case NS_DDI: | |
037e8744 | 18938 | { |
477330fc | 18939 | unsigned immbits; |
cc933301 JW |
18940 | unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000, |
18941 | 0x0000100, 0x1000100, 0x0, 0x1000000}; | |
35997600 | 18942 | |
dd9634d9 AV |
18943 | if ((rs != NS_QQI || !ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)) |
18944 | && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
18945 | return; | |
18946 | ||
18947 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)) | |
18948 | { | |
18949 | constraint (inst.operands[2].present && inst.operands[2].imm == 0, | |
18950 | _("immediate value out of range")); | |
18951 | switch (flavour) | |
18952 | { | |
18953 | case neon_cvt_flavour_f16_s16: | |
18954 | case neon_cvt_flavour_f16_u16: | |
18955 | case neon_cvt_flavour_s16_f16: | |
18956 | case neon_cvt_flavour_u16_f16: | |
18957 | constraint (inst.operands[2].imm > 16, | |
18958 | _("immediate value out of range")); | |
18959 | break; | |
18960 | case neon_cvt_flavour_f32_u32: | |
18961 | case neon_cvt_flavour_f32_s32: | |
18962 | case neon_cvt_flavour_s32_f32: | |
18963 | case neon_cvt_flavour_u32_f32: | |
18964 | constraint (inst.operands[2].imm > 32, | |
18965 | _("immediate value out of range")); | |
18966 | break; | |
18967 | default: | |
18968 | inst.error = BAD_FPU; | |
18969 | return; | |
18970 | } | |
18971 | } | |
037e8744 | 18972 | |
477330fc RM |
18973 | /* Fixed-point conversion with #0 immediate is encoded as an |
18974 | integer conversion. */ | |
18975 | if (inst.operands[2].present && inst.operands[2].imm == 0) | |
18976 | goto int_encode; | |
477330fc RM |
18977 | NEON_ENCODE (IMMED, inst); |
18978 | if (flavour != neon_cvt_flavour_invalid) | |
18979 | inst.instruction |= enctab[flavour]; | |
18980 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
18981 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
18982 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
18983 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
18984 | inst.instruction |= neon_quad (rs) << 6; | |
18985 | inst.instruction |= 1 << 21; | |
cc933301 JW |
18986 | if (flavour < neon_cvt_flavour_s16_f16) |
18987 | { | |
18988 | inst.instruction |= 1 << 21; | |
18989 | immbits = 32 - inst.operands[2].imm; | |
18990 | inst.instruction |= immbits << 16; | |
18991 | } | |
18992 | else | |
18993 | { | |
18994 | inst.instruction |= 3 << 20; | |
18995 | immbits = 16 - inst.operands[2].imm; | |
18996 | inst.instruction |= immbits << 16; | |
18997 | inst.instruction &= ~(1 << 9); | |
18998 | } | |
477330fc RM |
18999 | |
19000 | neon_dp_fixup (&inst); | |
037e8744 JB |
19001 | } |
19002 | break; | |
19003 | ||
037e8744 | 19004 | case NS_QQ: |
dd9634d9 AV |
19005 | if ((mode == neon_cvt_mode_a || mode == neon_cvt_mode_n |
19006 | || mode == neon_cvt_mode_m || mode == neon_cvt_mode_p) | |
19007 | && (flavour == neon_cvt_flavour_s16_f16 | |
19008 | || flavour == neon_cvt_flavour_u16_f16 | |
19009 | || flavour == neon_cvt_flavour_s32_f32 | |
19010 | || flavour == neon_cvt_flavour_u32_f32)) | |
19011 | { | |
64c350f2 AV |
19012 | if (!check_simd_pred_availability (TRUE, |
19013 | NEON_CHECK_CC | NEON_CHECK_ARCH8)) | |
dd9634d9 AV |
19014 | return; |
19015 | } | |
19016 | else if (mode == neon_cvt_mode_z | |
19017 | && (flavour == neon_cvt_flavour_f16_s16 | |
19018 | || flavour == neon_cvt_flavour_f16_u16 | |
19019 | || flavour == neon_cvt_flavour_s16_f16 | |
19020 | || flavour == neon_cvt_flavour_u16_f16 | |
19021 | || flavour == neon_cvt_flavour_f32_u32 | |
19022 | || flavour == neon_cvt_flavour_f32_s32 | |
19023 | || flavour == neon_cvt_flavour_s32_f32 | |
19024 | || flavour == neon_cvt_flavour_u32_f32)) | |
19025 | { | |
64c350f2 AV |
19026 | if (!check_simd_pred_availability (TRUE, |
19027 | NEON_CHECK_CC | NEON_CHECK_ARCH)) | |
dd9634d9 AV |
19028 | return; |
19029 | } | |
19030 | /* fall through. */ | |
19031 | case NS_DD: | |
7e8e6784 MGD |
19032 | if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z) |
19033 | { | |
7e8e6784 | 19034 | |
dd9634d9 | 19035 | NEON_ENCODE (FLOAT, inst); |
64c350f2 AV |
19036 | if (!check_simd_pred_availability (TRUE, |
19037 | NEON_CHECK_CC | NEON_CHECK_ARCH8)) | |
7e8e6784 MGD |
19038 | return; |
19039 | ||
19040 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
19041 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
19042 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
19043 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
19044 | inst.instruction |= neon_quad (rs) << 6; | |
cc933301 JW |
19045 | inst.instruction |= (flavour == neon_cvt_flavour_u16_f16 |
19046 | || flavour == neon_cvt_flavour_u32_f32) << 7; | |
7e8e6784 | 19047 | inst.instruction |= mode << 8; |
cc933301 JW |
19048 | if (flavour == neon_cvt_flavour_u16_f16 |
19049 | || flavour == neon_cvt_flavour_s16_f16) | |
19050 | /* Mask off the original size bits and reencode them. */ | |
19051 | inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18)); | |
19052 | ||
7e8e6784 MGD |
19053 | if (thumb_mode) |
19054 | inst.instruction |= 0xfc000000; | |
19055 | else | |
19056 | inst.instruction |= 0xf0000000; | |
19057 | } | |
19058 | else | |
19059 | { | |
037e8744 | 19060 | int_encode: |
7e8e6784 | 19061 | { |
cc933301 JW |
19062 | unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080, |
19063 | 0x100, 0x180, 0x0, 0x080}; | |
037e8744 | 19064 | |
7e8e6784 | 19065 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 19066 | |
dd9634d9 AV |
19067 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)) |
19068 | { | |
19069 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
19070 | return; | |
19071 | } | |
037e8744 | 19072 | |
7e8e6784 MGD |
19073 | if (flavour != neon_cvt_flavour_invalid) |
19074 | inst.instruction |= enctab[flavour]; | |
037e8744 | 19075 | |
7e8e6784 MGD |
19076 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
19077 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
19078 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
19079 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
19080 | inst.instruction |= neon_quad (rs) << 6; | |
cc933301 JW |
19081 | if (flavour >= neon_cvt_flavour_s16_f16 |
19082 | && flavour <= neon_cvt_flavour_f16_u16) | |
19083 | /* Half precision. */ | |
19084 | inst.instruction |= 1 << 18; | |
19085 | else | |
19086 | inst.instruction |= 2 << 18; | |
037e8744 | 19087 | |
7e8e6784 MGD |
19088 | neon_dp_fixup (&inst); |
19089 | } | |
19090 | } | |
19091 | break; | |
037e8744 | 19092 | |
8e79c3df CM |
19093 | /* Half-precision conversions for Advanced SIMD -- neon. */ |
19094 | case NS_QD: | |
19095 | case NS_DQ: | |
bc52d49c MM |
19096 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
19097 | return; | |
8e79c3df CM |
19098 | |
19099 | if ((rs == NS_DQ) | |
19100 | && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32)) | |
19101 | { | |
19102 | as_bad (_("operand size must match register width")); | |
19103 | break; | |
19104 | } | |
19105 | ||
19106 | if ((rs == NS_QD) | |
19107 | && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16))) | |
19108 | { | |
19109 | as_bad (_("operand size must match register width")); | |
19110 | break; | |
19111 | } | |
19112 | ||
19113 | if (rs == NS_DQ) | |
477330fc | 19114 | inst.instruction = 0x3b60600; |
8e79c3df CM |
19115 | else |
19116 | inst.instruction = 0x3b60700; | |
19117 | ||
19118 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
19119 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
19120 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
19121 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
88714cb8 | 19122 | neon_dp_fixup (&inst); |
8e79c3df CM |
19123 | break; |
19124 | ||
037e8744 JB |
19125 | default: |
19126 | /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */ | |
7e8e6784 MGD |
19127 | if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z) |
19128 | do_vfp_nsyn_cvt (rs, flavour); | |
19129 | else | |
19130 | do_vfp_nsyn_cvt_fpv8 (flavour, mode); | |
5287ad62 | 19131 | } |
5287ad62 JB |
19132 | } |
19133 | ||
e3e535bc NC |
19134 | static void |
19135 | do_neon_cvtr (void) | |
19136 | { | |
7e8e6784 | 19137 | do_neon_cvt_1 (neon_cvt_mode_x); |
e3e535bc NC |
19138 | } |
19139 | ||
19140 | static void | |
19141 | do_neon_cvt (void) | |
19142 | { | |
7e8e6784 MGD |
19143 | do_neon_cvt_1 (neon_cvt_mode_z); |
19144 | } | |
19145 | ||
19146 | static void | |
19147 | do_neon_cvta (void) | |
19148 | { | |
19149 | do_neon_cvt_1 (neon_cvt_mode_a); | |
19150 | } | |
19151 | ||
19152 | static void | |
19153 | do_neon_cvtn (void) | |
19154 | { | |
19155 | do_neon_cvt_1 (neon_cvt_mode_n); | |
19156 | } | |
19157 | ||
19158 | static void | |
19159 | do_neon_cvtp (void) | |
19160 | { | |
19161 | do_neon_cvt_1 (neon_cvt_mode_p); | |
19162 | } | |
19163 | ||
19164 | static void | |
19165 | do_neon_cvtm (void) | |
19166 | { | |
19167 | do_neon_cvt_1 (neon_cvt_mode_m); | |
e3e535bc NC |
19168 | } |
19169 | ||
8e79c3df | 19170 | static void |
c70a8987 | 19171 | do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double) |
8e79c3df | 19172 | { |
c70a8987 MGD |
19173 | if (is_double) |
19174 | mark_feature_used (&fpu_vfp_ext_armv8); | |
8e79c3df | 19175 | |
c70a8987 MGD |
19176 | encode_arm_vfp_reg (inst.operands[0].reg, |
19177 | (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd); | |
19178 | encode_arm_vfp_reg (inst.operands[1].reg, | |
19179 | (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm); | |
19180 | inst.instruction |= to ? 0x10000 : 0; | |
19181 | inst.instruction |= t ? 0x80 : 0; | |
19182 | inst.instruction |= is_double ? 0x100 : 0; | |
19183 | do_vfp_cond_or_thumb (); | |
19184 | } | |
8e79c3df | 19185 | |
c70a8987 MGD |
19186 | static void |
19187 | do_neon_cvttb_1 (bfd_boolean t) | |
19188 | { | |
d54af2d0 | 19189 | enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD, |
dd9634d9 | 19190 | NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL); |
8e79c3df | 19191 | |
c70a8987 MGD |
19192 | if (rs == NS_NULL) |
19193 | return; | |
dd9634d9 AV |
19194 | else if (rs == NS_QQ || rs == NS_QQI) |
19195 | { | |
19196 | int single_to_half = 0; | |
64c350f2 | 19197 | if (!check_simd_pred_availability (TRUE, NEON_CHECK_ARCH)) |
dd9634d9 AV |
19198 | return; |
19199 | ||
19200 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); | |
19201 | ||
19202 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) | |
19203 | && (flavour == neon_cvt_flavour_u16_f16 | |
19204 | || flavour == neon_cvt_flavour_s16_f16 | |
19205 | || flavour == neon_cvt_flavour_f16_s16 | |
19206 | || flavour == neon_cvt_flavour_f16_u16 | |
19207 | || flavour == neon_cvt_flavour_u32_f32 | |
19208 | || flavour == neon_cvt_flavour_s32_f32 | |
19209 | || flavour == neon_cvt_flavour_f32_s32 | |
19210 | || flavour == neon_cvt_flavour_f32_u32)) | |
19211 | { | |
19212 | inst.cond = 0xf; | |
19213 | inst.instruction = N_MNEM_vcvt; | |
19214 | set_pred_insn_type (INSIDE_VPT_INSN); | |
19215 | do_neon_cvt_1 (neon_cvt_mode_z); | |
19216 | return; | |
19217 | } | |
19218 | else if (rs == NS_QQ && flavour == neon_cvt_flavour_f32_f16) | |
19219 | single_to_half = 1; | |
19220 | else if (rs == NS_QQ && flavour != neon_cvt_flavour_f16_f32) | |
19221 | { | |
19222 | first_error (BAD_FPU); | |
19223 | return; | |
19224 | } | |
19225 | ||
19226 | inst.instruction = 0xee3f0e01; | |
19227 | inst.instruction |= single_to_half << 28; | |
19228 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
19229 | inst.instruction |= LOW4 (inst.operands[0].reg) << 13; | |
19230 | inst.instruction |= t << 12; | |
19231 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
19232 | inst.instruction |= LOW4 (inst.operands[1].reg) << 1; | |
19233 | inst.is_neon = 1; | |
19234 | } | |
c70a8987 MGD |
19235 | else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype) |
19236 | { | |
19237 | inst.error = NULL; | |
19238 | do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE); | |
19239 | } | |
19240 | else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype) | |
19241 | { | |
19242 | inst.error = NULL; | |
19243 | do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE); | |
19244 | } | |
19245 | else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype) | |
19246 | { | |
a715796b TG |
19247 | /* The VCVTB and VCVTT instructions with D-register operands |
19248 | don't work for SP only targets. */ | |
19249 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
19250 | _(BAD_FPU)); | |
19251 | ||
c70a8987 MGD |
19252 | inst.error = NULL; |
19253 | do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE); | |
19254 | } | |
19255 | else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype) | |
19256 | { | |
a715796b TG |
19257 | /* The VCVTB and VCVTT instructions with D-register operands |
19258 | don't work for SP only targets. */ | |
19259 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
19260 | _(BAD_FPU)); | |
19261 | ||
c70a8987 MGD |
19262 | inst.error = NULL; |
19263 | do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE); | |
19264 | } | |
19265 | else | |
19266 | return; | |
19267 | } | |
19268 | ||
19269 | static void | |
19270 | do_neon_cvtb (void) | |
19271 | { | |
19272 | do_neon_cvttb_1 (FALSE); | |
8e79c3df CM |
19273 | } |
19274 | ||
19275 | ||
19276 | static void | |
19277 | do_neon_cvtt (void) | |
19278 | { | |
c70a8987 | 19279 | do_neon_cvttb_1 (TRUE); |
8e79c3df CM |
19280 | } |
19281 | ||
5287ad62 JB |
19282 | static void |
19283 | neon_move_immediate (void) | |
19284 | { | |
037e8744 JB |
19285 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
19286 | struct neon_type_el et = neon_check_type (2, rs, | |
19287 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 | 19288 | unsigned immlo, immhi = 0, immbits; |
c96612cc | 19289 | int op, cmode, float_p; |
5287ad62 | 19290 | |
037e8744 | 19291 | constraint (et.type == NT_invtype, |
477330fc | 19292 | _("operand size must be specified for immediate VMOV")); |
037e8744 | 19293 | |
5287ad62 JB |
19294 | /* We start out as an MVN instruction if OP = 1, MOV otherwise. */ |
19295 | op = (inst.instruction & (1 << 5)) != 0; | |
19296 | ||
19297 | immlo = inst.operands[1].imm; | |
19298 | if (inst.operands[1].regisimm) | |
19299 | immhi = inst.operands[1].reg; | |
19300 | ||
19301 | constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0, | |
477330fc | 19302 | _("immediate has bits set outside the operand size")); |
5287ad62 | 19303 | |
c96612cc JB |
19304 | float_p = inst.operands[1].immisfloat; |
19305 | ||
19306 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op, | |
477330fc | 19307 | et.size, et.type)) == FAIL) |
5287ad62 JB |
19308 | { |
19309 | /* Invert relevant bits only. */ | |
19310 | neon_invert_size (&immlo, &immhi, et.size); | |
19311 | /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable | |
477330fc RM |
19312 | with one or the other; those cases are caught by |
19313 | neon_cmode_for_move_imm. */ | |
5287ad62 | 19314 | op = !op; |
c96612cc JB |
19315 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, |
19316 | &op, et.size, et.type)) == FAIL) | |
477330fc RM |
19317 | { |
19318 | first_error (_("immediate out of range")); | |
19319 | return; | |
19320 | } | |
5287ad62 JB |
19321 | } |
19322 | ||
19323 | inst.instruction &= ~(1 << 5); | |
19324 | inst.instruction |= op << 5; | |
19325 | ||
19326 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
19327 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
037e8744 | 19328 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
19329 | inst.instruction |= cmode << 8; |
19330 | ||
19331 | neon_write_immbits (immbits); | |
19332 | } | |
19333 | ||
19334 | static void | |
19335 | do_neon_mvn (void) | |
19336 | { | |
64c350f2 | 19337 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH)) |
1a186d29 AV |
19338 | return; |
19339 | ||
5287ad62 JB |
19340 | if (inst.operands[1].isreg) |
19341 | { | |
1a186d29 AV |
19342 | enum neon_shape rs; |
19343 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
19344 | rs = neon_select_shape (NS_QQ, NS_NULL); | |
19345 | else | |
19346 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
5f4273c7 | 19347 | |
88714cb8 | 19348 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
19349 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
19350 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
19351 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
19352 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 19353 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
19354 | } |
19355 | else | |
19356 | { | |
88714cb8 | 19357 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
19358 | neon_move_immediate (); |
19359 | } | |
19360 | ||
88714cb8 | 19361 | neon_dp_fixup (&inst); |
1a186d29 AV |
19362 | |
19363 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
19364 | { | |
19365 | constraint (!inst.operands[1].isreg && !inst.operands[0].isquad, BAD_FPU); | |
19366 | constraint ((inst.instruction & 0xd00) == 0xd00, | |
19367 | _("immediate value out of range")); | |
19368 | } | |
5287ad62 JB |
19369 | } |
19370 | ||
19371 | /* Encode instructions of form: | |
19372 | ||
19373 | |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
5f4273c7 | 19374 | | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */ |
5287ad62 JB |
19375 | |
19376 | static void | |
19377 | neon_mixed_length (struct neon_type_el et, unsigned size) | |
19378 | { | |
19379 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
19380 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
19381 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
19382 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
19383 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
19384 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
19385 | inst.instruction |= (et.type == NT_unsigned) << 24; | |
19386 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 19387 | |
88714cb8 | 19388 | neon_dp_fixup (&inst); |
5287ad62 JB |
19389 | } |
19390 | ||
19391 | static void | |
19392 | do_neon_dyadic_long (void) | |
19393 | { | |
5ee91343 AV |
19394 | enum neon_shape rs = neon_select_shape (NS_QDD, NS_QQQ, NS_QQR, NS_NULL); |
19395 | if (rs == NS_QDD) | |
19396 | { | |
19397 | if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL) | |
19398 | return; | |
19399 | ||
19400 | NEON_ENCODE (INTEGER, inst); | |
19401 | /* FIXME: Type checking for lengthening op. */ | |
19402 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
19403 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
19404 | neon_mixed_length (et, et.size); | |
19405 | } | |
19406 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) | |
19407 | && (inst.cond == 0xf || inst.cond == 0x10)) | |
19408 | { | |
19409 | /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd | |
19410 | in an IT block with le/lt conditions. */ | |
19411 | ||
19412 | if (inst.cond == 0xf) | |
19413 | inst.cond = 0xb; | |
19414 | else if (inst.cond == 0x10) | |
19415 | inst.cond = 0xd; | |
19416 | ||
19417 | inst.pred_insn_type = INSIDE_IT_INSN; | |
19418 | ||
19419 | if (inst.instruction == N_MNEM_vaddl) | |
19420 | { | |
19421 | inst.instruction = N_MNEM_vadd; | |
19422 | do_neon_addsub_if_i (); | |
19423 | } | |
19424 | else if (inst.instruction == N_MNEM_vsubl) | |
19425 | { | |
19426 | inst.instruction = N_MNEM_vsub; | |
19427 | do_neon_addsub_if_i (); | |
19428 | } | |
19429 | else if (inst.instruction == N_MNEM_vabdl) | |
19430 | { | |
19431 | inst.instruction = N_MNEM_vabd; | |
19432 | do_neon_dyadic_if_su (); | |
19433 | } | |
19434 | } | |
19435 | else | |
19436 | first_error (BAD_FPU); | |
5287ad62 JB |
19437 | } |
19438 | ||
19439 | static void | |
19440 | do_neon_abal (void) | |
19441 | { | |
19442 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
19443 | N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
19444 | neon_mixed_length (et, et.size); | |
19445 | } | |
19446 | ||
19447 | static void | |
19448 | neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes) | |
19449 | { | |
19450 | if (inst.operands[2].isscalar) | |
19451 | { | |
dcbf9037 | 19452 | struct neon_type_el et = neon_check_type (3, NS_QDS, |
477330fc | 19453 | N_EQK | N_DBL, N_EQK, regtypes | N_KEY); |
88714cb8 | 19454 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
19455 | neon_mul_mac (et, et.type == NT_unsigned); |
19456 | } | |
19457 | else | |
19458 | { | |
19459 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
477330fc | 19460 | N_EQK | N_DBL, N_EQK, scalartypes | N_KEY); |
88714cb8 | 19461 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
19462 | neon_mixed_length (et, et.size); |
19463 | } | |
19464 | } | |
19465 | ||
19466 | static void | |
19467 | do_neon_mac_maybe_scalar_long (void) | |
19468 | { | |
19469 | neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32); | |
19470 | } | |
19471 | ||
dec41383 JW |
19472 | /* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's |
19473 | internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */ | |
19474 | ||
19475 | static unsigned | |
19476 | neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p) | |
19477 | { | |
19478 | unsigned regno = NEON_SCALAR_REG (scalar); | |
19479 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
19480 | ||
19481 | if (quad_p) | |
19482 | { | |
19483 | if (regno > 7 || elno > 3) | |
19484 | goto bad_scalar; | |
19485 | ||
19486 | return ((regno & 0x7) | |
19487 | | ((elno & 0x1) << 3) | |
19488 | | (((elno >> 1) & 0x1) << 5)); | |
19489 | } | |
19490 | else | |
19491 | { | |
19492 | if (regno > 15 || elno > 1) | |
19493 | goto bad_scalar; | |
19494 | ||
19495 | return (((regno & 0x1) << 5) | |
19496 | | ((regno >> 1) & 0x7) | |
19497 | | ((elno & 0x1) << 3)); | |
19498 | } | |
19499 | ||
19500 | bad_scalar: | |
19501 | first_error (_("scalar out of range for multiply instruction")); | |
19502 | return 0; | |
19503 | } | |
19504 | ||
19505 | static void | |
19506 | do_neon_fmac_maybe_scalar_long (int subtype) | |
19507 | { | |
19508 | enum neon_shape rs; | |
19509 | int high8; | |
19510 | /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size" | |
19511 | field (bits[21:20]) has different meaning. For scalar index variant, it's | |
19512 | used to differentiate add and subtract, otherwise it's with fixed value | |
19513 | 0x2. */ | |
19514 | int size = -1; | |
19515 | ||
19516 | if (inst.cond != COND_ALWAYS) | |
19517 | as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the " | |
19518 | "behaviour is UNPREDICTABLE")); | |
19519 | ||
01f48020 | 19520 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml), |
dec41383 JW |
19521 | _(BAD_FP16)); |
19522 | ||
19523 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8), | |
19524 | _(BAD_FPU)); | |
19525 | ||
19526 | /* vfmal/vfmsl are in three-same D/Q register format or the third operand can | |
19527 | be a scalar index register. */ | |
19528 | if (inst.operands[2].isscalar) | |
19529 | { | |
19530 | high8 = 0xfe000000; | |
19531 | if (subtype) | |
19532 | size = 16; | |
19533 | rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL); | |
19534 | } | |
19535 | else | |
19536 | { | |
19537 | high8 = 0xfc000000; | |
19538 | size = 32; | |
19539 | if (subtype) | |
19540 | inst.instruction |= (0x1 << 23); | |
19541 | rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL); | |
19542 | } | |
19543 | ||
19544 | neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16); | |
19545 | ||
19546 | /* "opcode" from template has included "ubit", so simply pass 0 here. Also, | |
19547 | the "S" bit in size field has been reused to differentiate vfmal and vfmsl, | |
19548 | so we simply pass -1 as size. */ | |
19549 | unsigned quad_p = (rs == NS_QDD || rs == NS_QDS); | |
19550 | neon_three_same (quad_p, 0, size); | |
19551 | ||
19552 | /* Undo neon_dp_fixup. Redo the high eight bits. */ | |
19553 | inst.instruction &= 0x00ffffff; | |
19554 | inst.instruction |= high8; | |
19555 | ||
19556 | #define LOW1(R) ((R) & 0x1) | |
19557 | #define HI4(R) (((R) >> 1) & 0xf) | |
19558 | /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on | |
19559 | whether the instruction is in Q form and whether Vm is a scalar indexed | |
19560 | operand. */ | |
19561 | if (inst.operands[2].isscalar) | |
19562 | { | |
19563 | unsigned rm | |
19564 | = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p); | |
19565 | inst.instruction &= 0xffffffd0; | |
19566 | inst.instruction |= rm; | |
19567 | ||
19568 | if (!quad_p) | |
19569 | { | |
19570 | /* Redo Rn as well. */ | |
19571 | inst.instruction &= 0xfff0ff7f; | |
19572 | inst.instruction |= HI4 (inst.operands[1].reg) << 16; | |
19573 | inst.instruction |= LOW1 (inst.operands[1].reg) << 7; | |
19574 | } | |
19575 | } | |
19576 | else if (!quad_p) | |
19577 | { | |
19578 | /* Redo Rn and Rm. */ | |
19579 | inst.instruction &= 0xfff0ff50; | |
19580 | inst.instruction |= HI4 (inst.operands[1].reg) << 16; | |
19581 | inst.instruction |= LOW1 (inst.operands[1].reg) << 7; | |
19582 | inst.instruction |= HI4 (inst.operands[2].reg); | |
19583 | inst.instruction |= LOW1 (inst.operands[2].reg) << 5; | |
19584 | } | |
19585 | } | |
19586 | ||
19587 | static void | |
19588 | do_neon_vfmal (void) | |
19589 | { | |
19590 | return do_neon_fmac_maybe_scalar_long (0); | |
19591 | } | |
19592 | ||
19593 | static void | |
19594 | do_neon_vfmsl (void) | |
19595 | { | |
19596 | return do_neon_fmac_maybe_scalar_long (1); | |
19597 | } | |
19598 | ||
5287ad62 JB |
19599 | static void |
19600 | do_neon_dyadic_wide (void) | |
19601 | { | |
19602 | struct neon_type_el et = neon_check_type (3, NS_QQD, | |
19603 | N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY); | |
19604 | neon_mixed_length (et, et.size); | |
19605 | } | |
19606 | ||
19607 | static void | |
19608 | do_neon_dyadic_narrow (void) | |
19609 | { | |
19610 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
19611 | N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY); | |
428e3f1f PB |
19612 | /* Operand sign is unimportant, and the U bit is part of the opcode, |
19613 | so force the operand type to integer. */ | |
19614 | et.type = NT_integer; | |
5287ad62 JB |
19615 | neon_mixed_length (et, et.size / 2); |
19616 | } | |
19617 | ||
19618 | static void | |
19619 | do_neon_mul_sat_scalar_long (void) | |
19620 | { | |
19621 | neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32); | |
19622 | } | |
19623 | ||
19624 | static void | |
19625 | do_neon_vmull (void) | |
19626 | { | |
19627 | if (inst.operands[2].isscalar) | |
19628 | do_neon_mac_maybe_scalar_long (); | |
19629 | else | |
19630 | { | |
19631 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
477330fc | 19632 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY); |
4f51b4bd | 19633 | |
5287ad62 | 19634 | if (et.type == NT_poly) |
477330fc | 19635 | NEON_ENCODE (POLY, inst); |
5287ad62 | 19636 | else |
477330fc | 19637 | NEON_ENCODE (INTEGER, inst); |
4f51b4bd MGD |
19638 | |
19639 | /* For polynomial encoding the U bit must be zero, and the size must | |
19640 | be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non | |
19641 | obviously, as 0b10). */ | |
19642 | if (et.size == 64) | |
19643 | { | |
19644 | /* Check we're on the correct architecture. */ | |
19645 | if (!mark_feature_used (&fpu_crypto_ext_armv8)) | |
19646 | inst.error = | |
19647 | _("Instruction form not available on this architecture."); | |
19648 | ||
19649 | et.size = 32; | |
19650 | } | |
19651 | ||
5287ad62 JB |
19652 | neon_mixed_length (et, et.size); |
19653 | } | |
19654 | } | |
19655 | ||
19656 | static void | |
19657 | do_neon_ext (void) | |
19658 | { | |
037e8744 | 19659 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); |
5287ad62 JB |
19660 | struct neon_type_el et = neon_check_type (3, rs, |
19661 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
19662 | unsigned imm = (inst.operands[3].imm * et.size) / 8; | |
35997600 NC |
19663 | |
19664 | constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8), | |
19665 | _("shift out of range")); | |
5287ad62 JB |
19666 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
19667 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
19668 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
19669 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
19670 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
19671 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
037e8744 | 19672 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 | 19673 | inst.instruction |= imm << 8; |
5f4273c7 | 19674 | |
88714cb8 | 19675 | neon_dp_fixup (&inst); |
5287ad62 JB |
19676 | } |
19677 | ||
19678 | static void | |
19679 | do_neon_rev (void) | |
19680 | { | |
64c350f2 | 19681 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
4401c241 AV |
19682 | return; |
19683 | ||
19684 | enum neon_shape rs; | |
19685 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
19686 | rs = neon_select_shape (NS_QQ, NS_NULL); | |
19687 | else | |
19688 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
19689 | ||
5287ad62 JB |
19690 | struct neon_type_el et = neon_check_type (2, rs, |
19691 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
4401c241 | 19692 | |
5287ad62 JB |
19693 | unsigned op = (inst.instruction >> 7) & 3; |
19694 | /* N (width of reversed regions) is encoded as part of the bitmask. We | |
19695 | extract it here to check the elements to be reversed are smaller. | |
19696 | Otherwise we'd get a reserved instruction. */ | |
19697 | unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0; | |
4401c241 AV |
19698 | |
19699 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) && elsize == 64 | |
19700 | && inst.operands[0].reg == inst.operands[1].reg) | |
19701 | as_tsktsk (_("Warning: 64-bit element size and same destination and source" | |
19702 | " operands makes instruction UNPREDICTABLE")); | |
19703 | ||
9c2799c2 | 19704 | gas_assert (elsize != 0); |
5287ad62 | 19705 | constraint (et.size >= elsize, |
477330fc | 19706 | _("elements must be smaller than reversal region")); |
037e8744 | 19707 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
19708 | } |
19709 | ||
19710 | static void | |
19711 | do_neon_dup (void) | |
19712 | { | |
19713 | if (inst.operands[1].isscalar) | |
19714 | { | |
b409bdb6 AV |
19715 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1), |
19716 | BAD_FPU); | |
037e8744 | 19717 | enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL); |
dcbf9037 | 19718 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 19719 | N_EQK, N_8 | N_16 | N_32 | N_KEY); |
5287ad62 | 19720 | unsigned sizebits = et.size >> 3; |
dcbf9037 | 19721 | unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg); |
5287ad62 | 19722 | int logsize = neon_logbits (et.size); |
dcbf9037 | 19723 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize; |
037e8744 JB |
19724 | |
19725 | if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL) | |
477330fc | 19726 | return; |
037e8744 | 19727 | |
88714cb8 | 19728 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
19729 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
19730 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
19731 | inst.instruction |= LOW4 (dm); | |
19732 | inst.instruction |= HI1 (dm) << 5; | |
037e8744 | 19733 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
19734 | inst.instruction |= x << 17; |
19735 | inst.instruction |= sizebits << 16; | |
5f4273c7 | 19736 | |
88714cb8 | 19737 | neon_dp_fixup (&inst); |
5287ad62 JB |
19738 | } |
19739 | else | |
19740 | { | |
037e8744 JB |
19741 | enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL); |
19742 | struct neon_type_el et = neon_check_type (2, rs, | |
477330fc | 19743 | N_8 | N_16 | N_32 | N_KEY, N_EQK); |
b409bdb6 AV |
19744 | if (rs == NS_QR) |
19745 | { | |
64c350f2 | 19746 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH)) |
b409bdb6 AV |
19747 | return; |
19748 | } | |
19749 | else | |
19750 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1), | |
19751 | BAD_FPU); | |
19752 | ||
19753 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
19754 | { | |
19755 | if (inst.operands[1].reg == REG_SP) | |
19756 | as_tsktsk (MVE_BAD_SP); | |
19757 | else if (inst.operands[1].reg == REG_PC) | |
19758 | as_tsktsk (MVE_BAD_PC); | |
19759 | } | |
19760 | ||
5287ad62 | 19761 | /* Duplicate ARM register to lanes of vector. */ |
88714cb8 | 19762 | NEON_ENCODE (ARMREG, inst); |
5287ad62 | 19763 | switch (et.size) |
477330fc RM |
19764 | { |
19765 | case 8: inst.instruction |= 0x400000; break; | |
19766 | case 16: inst.instruction |= 0x000020; break; | |
19767 | case 32: inst.instruction |= 0x000000; break; | |
19768 | default: break; | |
19769 | } | |
5287ad62 JB |
19770 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; |
19771 | inst.instruction |= LOW4 (inst.operands[0].reg) << 16; | |
19772 | inst.instruction |= HI1 (inst.operands[0].reg) << 7; | |
037e8744 | 19773 | inst.instruction |= neon_quad (rs) << 21; |
5287ad62 | 19774 | /* The encoding for this instruction is identical for the ARM and Thumb |
477330fc | 19775 | variants, except for the condition field. */ |
037e8744 | 19776 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
19777 | } |
19778 | } | |
19779 | ||
57785aa2 AV |
19780 | static void |
19781 | do_mve_mov (int toQ) | |
19782 | { | |
19783 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
19784 | return; | |
19785 | if (inst.cond > COND_ALWAYS) | |
19786 | inst.pred_insn_type = MVE_UNPREDICABLE_INSN; | |
19787 | ||
19788 | unsigned Rt = 0, Rt2 = 1, Q0 = 2, Q1 = 3; | |
19789 | if (toQ) | |
19790 | { | |
19791 | Q0 = 0; | |
19792 | Q1 = 1; | |
19793 | Rt = 2; | |
19794 | Rt2 = 3; | |
19795 | } | |
19796 | ||
19797 | constraint (inst.operands[Q0].reg != inst.operands[Q1].reg + 2, | |
19798 | _("Index one must be [2,3] and index two must be two less than" | |
19799 | " index one.")); | |
19800 | constraint (inst.operands[Rt].reg == inst.operands[Rt2].reg, | |
19801 | _("General purpose registers may not be the same")); | |
19802 | constraint (inst.operands[Rt].reg == REG_SP | |
19803 | || inst.operands[Rt2].reg == REG_SP, | |
19804 | BAD_SP); | |
19805 | constraint (inst.operands[Rt].reg == REG_PC | |
19806 | || inst.operands[Rt2].reg == REG_PC, | |
19807 | BAD_PC); | |
19808 | ||
19809 | inst.instruction = 0xec000f00; | |
19810 | inst.instruction |= HI1 (inst.operands[Q1].reg / 32) << 23; | |
19811 | inst.instruction |= !!toQ << 20; | |
19812 | inst.instruction |= inst.operands[Rt2].reg << 16; | |
19813 | inst.instruction |= LOW4 (inst.operands[Q1].reg / 32) << 13; | |
19814 | inst.instruction |= (inst.operands[Q1].reg % 4) << 4; | |
19815 | inst.instruction |= inst.operands[Rt].reg; | |
19816 | } | |
19817 | ||
19818 | static void | |
19819 | do_mve_movn (void) | |
19820 | { | |
19821 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
19822 | return; | |
19823 | ||
19824 | if (inst.cond > COND_ALWAYS) | |
19825 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
19826 | else | |
19827 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
19828 | ||
19829 | struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_I16 | N_I32 | |
19830 | | N_KEY); | |
19831 | ||
19832 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
19833 | inst.instruction |= (neon_logbits (et.size) - 1) << 18; | |
19834 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
19835 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
19836 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
19837 | inst.is_neon = 1; | |
19838 | ||
19839 | } | |
19840 | ||
5287ad62 JB |
19841 | /* VMOV has particularly many variations. It can be one of: |
19842 | 0. VMOV<c><q> <Qd>, <Qm> | |
19843 | 1. VMOV<c><q> <Dd>, <Dm> | |
19844 | (Register operations, which are VORR with Rm = Rn.) | |
19845 | 2. VMOV<c><q>.<dt> <Qd>, #<imm> | |
19846 | 3. VMOV<c><q>.<dt> <Dd>, #<imm> | |
19847 | (Immediate loads.) | |
19848 | 4. VMOV<c><q>.<size> <Dn[x]>, <Rd> | |
19849 | (ARM register to scalar.) | |
19850 | 5. VMOV<c><q> <Dm>, <Rd>, <Rn> | |
19851 | (Two ARM registers to vector.) | |
19852 | 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]> | |
19853 | (Scalar to ARM register.) | |
19854 | 7. VMOV<c><q> <Rd>, <Rn>, <Dm> | |
19855 | (Vector to two ARM registers.) | |
037e8744 JB |
19856 | 8. VMOV.F32 <Sd>, <Sm> |
19857 | 9. VMOV.F64 <Dd>, <Dm> | |
19858 | (VFP register moves.) | |
19859 | 10. VMOV.F32 <Sd>, #imm | |
19860 | 11. VMOV.F64 <Dd>, #imm | |
19861 | (VFP float immediate load.) | |
19862 | 12. VMOV <Rd>, <Sm> | |
19863 | (VFP single to ARM reg.) | |
19864 | 13. VMOV <Sd>, <Rm> | |
19865 | (ARM reg to VFP single.) | |
19866 | 14. VMOV <Rd>, <Re>, <Sn>, <Sm> | |
19867 | (Two ARM regs to two VFP singles.) | |
19868 | 15. VMOV <Sd>, <Se>, <Rn>, <Rm> | |
19869 | (Two VFP singles to two ARM regs.) | |
57785aa2 AV |
19870 | 16. VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> |
19871 | 17. VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> | |
19872 | 18. VMOV<c>.<dt> <Rt>, <Qn[idx]> | |
19873 | 19. VMOV<c>.<dt> <Qd[idx]>, <Rt> | |
5f4273c7 | 19874 | |
037e8744 JB |
19875 | These cases can be disambiguated using neon_select_shape, except cases 1/9 |
19876 | and 3/11 which depend on the operand type too. | |
5f4273c7 | 19877 | |
5287ad62 | 19878 | All the encoded bits are hardcoded by this function. |
5f4273c7 | 19879 | |
b7fc2769 JB |
19880 | Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!). |
19881 | Cases 5, 7 may be used with VFPv2 and above. | |
5f4273c7 | 19882 | |
5287ad62 | 19883 | FIXME: Some of the checking may be a bit sloppy (in a couple of cases you |
5f4273c7 | 19884 | can specify a type where it doesn't make sense to, and is ignored). */ |
5287ad62 JB |
19885 | |
19886 | static void | |
19887 | do_neon_mov (void) | |
19888 | { | |
57785aa2 AV |
19889 | enum neon_shape rs = neon_select_shape (NS_RRSS, NS_SSRR, NS_RRFF, NS_FFRR, |
19890 | NS_DRR, NS_RRD, NS_QQ, NS_DD, NS_QI, | |
19891 | NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, | |
19892 | NS_RF, NS_FR, NS_HR, NS_RH, NS_HI, | |
19893 | NS_NULL); | |
037e8744 JB |
19894 | struct neon_type_el et; |
19895 | const char *ldconst = 0; | |
5287ad62 | 19896 | |
037e8744 | 19897 | switch (rs) |
5287ad62 | 19898 | { |
037e8744 JB |
19899 | case NS_DD: /* case 1/9. */ |
19900 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
19901 | /* It is not an error here if no type is given. */ | |
19902 | inst.error = NULL; | |
1c1e0fe5 SP |
19903 | |
19904 | /* In MVE we interpret the following instructions as same, so ignoring | |
19905 | the following type (float) and size (64) checks. | |
19906 | a: VMOV<c><q> <Dd>, <Dm> | |
19907 | b: VMOV<c><q>.F64 <Dd>, <Dm>. */ | |
19908 | if ((et.type == NT_float && et.size == 64) | |
19909 | || (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))) | |
477330fc RM |
19910 | { |
19911 | do_vfp_nsyn_opcode ("fcpyd"); | |
19912 | break; | |
19913 | } | |
037e8744 | 19914 | /* fall through. */ |
5287ad62 | 19915 | |
037e8744 JB |
19916 | case NS_QQ: /* case 0/1. */ |
19917 | { | |
64c350f2 AV |
19918 | if (!check_simd_pred_availability (FALSE, |
19919 | NEON_CHECK_CC | NEON_CHECK_ARCH)) | |
477330fc RM |
19920 | return; |
19921 | /* The architecture manual I have doesn't explicitly state which | |
19922 | value the U bit should have for register->register moves, but | |
19923 | the equivalent VORR instruction has U = 0, so do that. */ | |
19924 | inst.instruction = 0x0200110; | |
19925 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
19926 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
19927 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
19928 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
19929 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
19930 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
19931 | inst.instruction |= neon_quad (rs) << 6; | |
19932 | ||
19933 | neon_dp_fixup (&inst); | |
037e8744 JB |
19934 | } |
19935 | break; | |
5f4273c7 | 19936 | |
037e8744 JB |
19937 | case NS_DI: /* case 3/11. */ |
19938 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
19939 | inst.error = NULL; | |
19940 | if (et.type == NT_float && et.size == 64) | |
477330fc RM |
19941 | { |
19942 | /* case 11 (fconstd). */ | |
19943 | ldconst = "fconstd"; | |
19944 | goto encode_fconstd; | |
19945 | } | |
037e8744 JB |
19946 | /* fall through. */ |
19947 | ||
19948 | case NS_QI: /* case 2/3. */ | |
64c350f2 AV |
19949 | if (!check_simd_pred_availability (FALSE, |
19950 | NEON_CHECK_CC | NEON_CHECK_ARCH)) | |
477330fc | 19951 | return; |
037e8744 JB |
19952 | inst.instruction = 0x0800010; |
19953 | neon_move_immediate (); | |
88714cb8 | 19954 | neon_dp_fixup (&inst); |
5287ad62 | 19955 | break; |
5f4273c7 | 19956 | |
037e8744 JB |
19957 | case NS_SR: /* case 4. */ |
19958 | { | |
477330fc RM |
19959 | unsigned bcdebits = 0; |
19960 | int logsize; | |
19961 | unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg); | |
19962 | unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg); | |
037e8744 | 19963 | |
05ac0ffb JB |
19964 | /* .<size> is optional here, defaulting to .32. */ |
19965 | if (inst.vectype.elems == 0 | |
19966 | && inst.operands[0].vectype.type == NT_invtype | |
19967 | && inst.operands[1].vectype.type == NT_invtype) | |
19968 | { | |
19969 | inst.vectype.el[0].type = NT_untyped; | |
19970 | inst.vectype.el[0].size = 32; | |
19971 | inst.vectype.elems = 1; | |
19972 | } | |
19973 | ||
477330fc RM |
19974 | et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK); |
19975 | logsize = neon_logbits (et.size); | |
19976 | ||
57785aa2 AV |
19977 | if (et.size != 32) |
19978 | { | |
19979 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) | |
19980 | && vfp_or_neon_is_neon (NEON_CHECK_ARCH) == FAIL) | |
19981 | return; | |
19982 | } | |
19983 | else | |
19984 | { | |
19985 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1) | |
19986 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
19987 | _(BAD_FPU)); | |
19988 | } | |
19989 | ||
19990 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
19991 | { | |
19992 | if (inst.operands[1].reg == REG_SP) | |
19993 | as_tsktsk (MVE_BAD_SP); | |
19994 | else if (inst.operands[1].reg == REG_PC) | |
19995 | as_tsktsk (MVE_BAD_PC); | |
19996 | } | |
19997 | unsigned size = inst.operands[0].isscalar == 1 ? 64 : 128; | |
19998 | ||
477330fc | 19999 | constraint (et.type == NT_invtype, _("bad type for scalar")); |
57785aa2 AV |
20000 | constraint (x >= size / et.size, _("scalar index out of range")); |
20001 | ||
477330fc RM |
20002 | |
20003 | switch (et.size) | |
20004 | { | |
20005 | case 8: bcdebits = 0x8; break; | |
20006 | case 16: bcdebits = 0x1; break; | |
20007 | case 32: bcdebits = 0x0; break; | |
20008 | default: ; | |
20009 | } | |
20010 | ||
57785aa2 | 20011 | bcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize; |
477330fc RM |
20012 | |
20013 | inst.instruction = 0xe000b10; | |
20014 | do_vfp_cond_or_thumb (); | |
20015 | inst.instruction |= LOW4 (dn) << 16; | |
20016 | inst.instruction |= HI1 (dn) << 7; | |
20017 | inst.instruction |= inst.operands[1].reg << 12; | |
20018 | inst.instruction |= (bcdebits & 3) << 5; | |
57785aa2 AV |
20019 | inst.instruction |= ((bcdebits >> 2) & 3) << 21; |
20020 | inst.instruction |= (x >> (3-logsize)) << 16; | |
037e8744 JB |
20021 | } |
20022 | break; | |
5f4273c7 | 20023 | |
037e8744 | 20024 | case NS_DRR: /* case 5 (fmdrr). */ |
57785aa2 AV |
20025 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2) |
20026 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
477330fc | 20027 | _(BAD_FPU)); |
b7fc2769 | 20028 | |
037e8744 JB |
20029 | inst.instruction = 0xc400b10; |
20030 | do_vfp_cond_or_thumb (); | |
20031 | inst.instruction |= LOW4 (inst.operands[0].reg); | |
20032 | inst.instruction |= HI1 (inst.operands[0].reg) << 5; | |
20033 | inst.instruction |= inst.operands[1].reg << 12; | |
20034 | inst.instruction |= inst.operands[2].reg << 16; | |
20035 | break; | |
5f4273c7 | 20036 | |
037e8744 JB |
20037 | case NS_RS: /* case 6. */ |
20038 | { | |
477330fc RM |
20039 | unsigned logsize; |
20040 | unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg); | |
20041 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg); | |
20042 | unsigned abcdebits = 0; | |
037e8744 | 20043 | |
05ac0ffb JB |
20044 | /* .<dt> is optional here, defaulting to .32. */ |
20045 | if (inst.vectype.elems == 0 | |
20046 | && inst.operands[0].vectype.type == NT_invtype | |
20047 | && inst.operands[1].vectype.type == NT_invtype) | |
20048 | { | |
20049 | inst.vectype.el[0].type = NT_untyped; | |
20050 | inst.vectype.el[0].size = 32; | |
20051 | inst.vectype.elems = 1; | |
20052 | } | |
20053 | ||
91d6fa6a NC |
20054 | et = neon_check_type (2, NS_NULL, |
20055 | N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY); | |
477330fc RM |
20056 | logsize = neon_logbits (et.size); |
20057 | ||
57785aa2 AV |
20058 | if (et.size != 32) |
20059 | { | |
20060 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) | |
20061 | && vfp_or_neon_is_neon (NEON_CHECK_CC | |
20062 | | NEON_CHECK_ARCH) == FAIL) | |
20063 | return; | |
20064 | } | |
20065 | else | |
20066 | { | |
20067 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1) | |
20068 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
20069 | _(BAD_FPU)); | |
20070 | } | |
20071 | ||
20072 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
20073 | { | |
20074 | if (inst.operands[0].reg == REG_SP) | |
20075 | as_tsktsk (MVE_BAD_SP); | |
20076 | else if (inst.operands[0].reg == REG_PC) | |
20077 | as_tsktsk (MVE_BAD_PC); | |
20078 | } | |
20079 | ||
20080 | unsigned size = inst.operands[1].isscalar == 1 ? 64 : 128; | |
20081 | ||
477330fc | 20082 | constraint (et.type == NT_invtype, _("bad type for scalar")); |
57785aa2 | 20083 | constraint (x >= size / et.size, _("scalar index out of range")); |
477330fc RM |
20084 | |
20085 | switch (et.size) | |
20086 | { | |
20087 | case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break; | |
20088 | case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break; | |
20089 | case 32: abcdebits = 0x00; break; | |
20090 | default: ; | |
20091 | } | |
20092 | ||
57785aa2 | 20093 | abcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize; |
477330fc RM |
20094 | inst.instruction = 0xe100b10; |
20095 | do_vfp_cond_or_thumb (); | |
20096 | inst.instruction |= LOW4 (dn) << 16; | |
20097 | inst.instruction |= HI1 (dn) << 7; | |
20098 | inst.instruction |= inst.operands[0].reg << 12; | |
20099 | inst.instruction |= (abcdebits & 3) << 5; | |
20100 | inst.instruction |= (abcdebits >> 2) << 21; | |
57785aa2 | 20101 | inst.instruction |= (x >> (3-logsize)) << 16; |
037e8744 JB |
20102 | } |
20103 | break; | |
5f4273c7 | 20104 | |
037e8744 | 20105 | case NS_RRD: /* case 7 (fmrrd). */ |
57785aa2 AV |
20106 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2) |
20107 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
477330fc | 20108 | _(BAD_FPU)); |
037e8744 JB |
20109 | |
20110 | inst.instruction = 0xc500b10; | |
20111 | do_vfp_cond_or_thumb (); | |
20112 | inst.instruction |= inst.operands[0].reg << 12; | |
20113 | inst.instruction |= inst.operands[1].reg << 16; | |
20114 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
20115 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
20116 | break; | |
5f4273c7 | 20117 | |
037e8744 JB |
20118 | case NS_FF: /* case 8 (fcpys). */ |
20119 | do_vfp_nsyn_opcode ("fcpys"); | |
20120 | break; | |
5f4273c7 | 20121 | |
9db2f6b4 | 20122 | case NS_HI: |
037e8744 JB |
20123 | case NS_FI: /* case 10 (fconsts). */ |
20124 | ldconst = "fconsts"; | |
4ef4710f | 20125 | encode_fconstd: |
58ed5c38 TC |
20126 | if (!inst.operands[1].immisfloat) |
20127 | { | |
4ef4710f | 20128 | unsigned new_imm; |
58ed5c38 | 20129 | /* Immediate has to fit in 8 bits so float is enough. */ |
4ef4710f NC |
20130 | float imm = (float) inst.operands[1].imm; |
20131 | memcpy (&new_imm, &imm, sizeof (float)); | |
20132 | /* But the assembly may have been written to provide an integer | |
20133 | bit pattern that equates to a float, so check that the | |
20134 | conversion has worked. */ | |
20135 | if (is_quarter_float (new_imm)) | |
20136 | { | |
20137 | if (is_quarter_float (inst.operands[1].imm)) | |
20138 | as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)")); | |
20139 | ||
20140 | inst.operands[1].imm = new_imm; | |
20141 | inst.operands[1].immisfloat = 1; | |
20142 | } | |
58ed5c38 TC |
20143 | } |
20144 | ||
037e8744 | 20145 | if (is_quarter_float (inst.operands[1].imm)) |
477330fc RM |
20146 | { |
20147 | inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm); | |
20148 | do_vfp_nsyn_opcode (ldconst); | |
9db2f6b4 RL |
20149 | |
20150 | /* ARMv8.2 fp16 vmov.f16 instruction. */ | |
20151 | if (rs == NS_HI) | |
20152 | do_scalar_fp16_v82_encode (); | |
477330fc | 20153 | } |
5287ad62 | 20154 | else |
477330fc | 20155 | first_error (_("immediate out of range")); |
037e8744 | 20156 | break; |
5f4273c7 | 20157 | |
9db2f6b4 | 20158 | case NS_RH: |
037e8744 JB |
20159 | case NS_RF: /* case 12 (fmrs). */ |
20160 | do_vfp_nsyn_opcode ("fmrs"); | |
9db2f6b4 RL |
20161 | /* ARMv8.2 fp16 vmov.f16 instruction. */ |
20162 | if (rs == NS_RH) | |
20163 | do_scalar_fp16_v82_encode (); | |
037e8744 | 20164 | break; |
5f4273c7 | 20165 | |
9db2f6b4 | 20166 | case NS_HR: |
037e8744 JB |
20167 | case NS_FR: /* case 13 (fmsr). */ |
20168 | do_vfp_nsyn_opcode ("fmsr"); | |
9db2f6b4 RL |
20169 | /* ARMv8.2 fp16 vmov.f16 instruction. */ |
20170 | if (rs == NS_HR) | |
20171 | do_scalar_fp16_v82_encode (); | |
037e8744 | 20172 | break; |
5f4273c7 | 20173 | |
57785aa2 AV |
20174 | case NS_RRSS: |
20175 | do_mve_mov (0); | |
20176 | break; | |
20177 | case NS_SSRR: | |
20178 | do_mve_mov (1); | |
20179 | break; | |
20180 | ||
037e8744 JB |
20181 | /* The encoders for the fmrrs and fmsrr instructions expect three operands |
20182 | (one of which is a list), but we have parsed four. Do some fiddling to | |
20183 | make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2 | |
20184 | expect. */ | |
20185 | case NS_RRFF: /* case 14 (fmrrs). */ | |
57785aa2 AV |
20186 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2) |
20187 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
20188 | _(BAD_FPU)); | |
037e8744 | 20189 | constraint (inst.operands[3].reg != inst.operands[2].reg + 1, |
477330fc | 20190 | _("VFP registers must be adjacent")); |
037e8744 JB |
20191 | inst.operands[2].imm = 2; |
20192 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
20193 | do_vfp_nsyn_opcode ("fmrrs"); | |
20194 | break; | |
5f4273c7 | 20195 | |
037e8744 | 20196 | case NS_FFRR: /* case 15 (fmsrr). */ |
57785aa2 AV |
20197 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2) |
20198 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
20199 | _(BAD_FPU)); | |
037e8744 | 20200 | constraint (inst.operands[1].reg != inst.operands[0].reg + 1, |
477330fc | 20201 | _("VFP registers must be adjacent")); |
037e8744 JB |
20202 | inst.operands[1] = inst.operands[2]; |
20203 | inst.operands[2] = inst.operands[3]; | |
20204 | inst.operands[0].imm = 2; | |
20205 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
20206 | do_vfp_nsyn_opcode ("fmsrr"); | |
5287ad62 | 20207 | break; |
5f4273c7 | 20208 | |
4c261dff NC |
20209 | case NS_NULL: |
20210 | /* neon_select_shape has determined that the instruction | |
20211 | shape is wrong and has already set the error message. */ | |
20212 | break; | |
20213 | ||
5287ad62 JB |
20214 | default: |
20215 | abort (); | |
20216 | } | |
20217 | } | |
20218 | ||
57785aa2 AV |
20219 | static void |
20220 | do_mve_movl (void) | |
20221 | { | |
20222 | if (!(inst.operands[0].present && inst.operands[0].isquad | |
20223 | && inst.operands[1].present && inst.operands[1].isquad | |
20224 | && !inst.operands[2].present)) | |
20225 | { | |
20226 | inst.instruction = 0; | |
20227 | inst.cond = 0xb; | |
20228 | if (thumb_mode) | |
20229 | set_pred_insn_type (INSIDE_IT_INSN); | |
20230 | do_neon_mov (); | |
20231 | return; | |
20232 | } | |
20233 | ||
20234 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
20235 | return; | |
20236 | ||
20237 | if (inst.cond != COND_ALWAYS) | |
20238 | inst.pred_insn_type = INSIDE_VPT_INSN; | |
20239 | ||
20240 | struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_S8 | N_U8 | |
20241 | | N_S16 | N_U16 | N_KEY); | |
20242 | ||
20243 | inst.instruction |= (et.type == NT_unsigned) << 28; | |
20244 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
20245 | inst.instruction |= (neon_logbits (et.size) + 1) << 19; | |
20246 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
20247 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
20248 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
20249 | inst.is_neon = 1; | |
20250 | } | |
20251 | ||
5287ad62 JB |
20252 | static void |
20253 | do_neon_rshift_round_imm (void) | |
20254 | { | |
64c350f2 | 20255 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
4401c241 AV |
20256 | return; |
20257 | ||
20258 | enum neon_shape rs; | |
20259 | struct neon_type_el et; | |
20260 | ||
20261 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
20262 | { | |
20263 | rs = neon_select_shape (NS_QQI, NS_NULL); | |
20264 | et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY); | |
20265 | } | |
20266 | else | |
20267 | { | |
20268 | rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); | |
20269 | et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); | |
20270 | } | |
5287ad62 JB |
20271 | int imm = inst.operands[2].imm; |
20272 | ||
20273 | /* imm == 0 case is encoded as VMOV for V{R}SHR. */ | |
20274 | if (imm == 0) | |
20275 | { | |
20276 | inst.operands[2].present = 0; | |
20277 | do_neon_mov (); | |
20278 | return; | |
20279 | } | |
20280 | ||
20281 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 20282 | _("immediate out of range for shift")); |
037e8744 | 20283 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
477330fc | 20284 | et.size - imm); |
5287ad62 JB |
20285 | } |
20286 | ||
9db2f6b4 RL |
20287 | static void |
20288 | do_neon_movhf (void) | |
20289 | { | |
20290 | enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL); | |
20291 | constraint (rs != NS_HH, _("invalid suffix")); | |
20292 | ||
7bdf778b ASDV |
20293 | if (inst.cond != COND_ALWAYS) |
20294 | { | |
20295 | if (thumb_mode) | |
20296 | { | |
20297 | as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional," | |
20298 | " the behaviour is UNPREDICTABLE")); | |
20299 | } | |
20300 | else | |
20301 | { | |
20302 | inst.error = BAD_COND; | |
20303 | return; | |
20304 | } | |
20305 | } | |
20306 | ||
9db2f6b4 RL |
20307 | do_vfp_sp_monadic (); |
20308 | ||
20309 | inst.is_neon = 1; | |
20310 | inst.instruction |= 0xf0000000; | |
20311 | } | |
20312 | ||
5287ad62 JB |
20313 | static void |
20314 | do_neon_movl (void) | |
20315 | { | |
20316 | struct neon_type_el et = neon_check_type (2, NS_QD, | |
20317 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
20318 | unsigned sizebits = et.size >> 3; | |
20319 | inst.instruction |= sizebits << 19; | |
20320 | neon_two_same (0, et.type == NT_unsigned, -1); | |
20321 | } | |
20322 | ||
20323 | static void | |
20324 | do_neon_trn (void) | |
20325 | { | |
037e8744 | 20326 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
20327 | struct neon_type_el et = neon_check_type (2, rs, |
20328 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
88714cb8 | 20329 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 20330 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20331 | } |
20332 | ||
20333 | static void | |
20334 | do_neon_zip_uzp (void) | |
20335 | { | |
037e8744 | 20336 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
20337 | struct neon_type_el et = neon_check_type (2, rs, |
20338 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
20339 | if (rs == NS_DD && et.size == 32) | |
20340 | { | |
20341 | /* Special case: encode as VTRN.32 <Dd>, <Dm>. */ | |
20342 | inst.instruction = N_MNEM_vtrn; | |
20343 | do_neon_trn (); | |
20344 | return; | |
20345 | } | |
037e8744 | 20346 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20347 | } |
20348 | ||
20349 | static void | |
20350 | do_neon_sat_abs_neg (void) | |
20351 | { | |
64c350f2 | 20352 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH)) |
1a186d29 AV |
20353 | return; |
20354 | ||
20355 | enum neon_shape rs; | |
20356 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
20357 | rs = neon_select_shape (NS_QQ, NS_NULL); | |
20358 | else | |
20359 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
5287ad62 JB |
20360 | struct neon_type_el et = neon_check_type (2, rs, |
20361 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 20362 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20363 | } |
20364 | ||
20365 | static void | |
20366 | do_neon_pair_long (void) | |
20367 | { | |
037e8744 | 20368 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
20369 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY); |
20370 | /* Unsigned is encoded in OP field (bit 7) for these instruction. */ | |
20371 | inst.instruction |= (et.type == NT_unsigned) << 7; | |
037e8744 | 20372 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20373 | } |
20374 | ||
20375 | static void | |
20376 | do_neon_recip_est (void) | |
20377 | { | |
037e8744 | 20378 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 | 20379 | struct neon_type_el et = neon_check_type (2, rs, |
cc933301 | 20380 | N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY); |
5287ad62 | 20381 | inst.instruction |= (et.type == NT_float) << 8; |
037e8744 | 20382 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20383 | } |
20384 | ||
20385 | static void | |
20386 | do_neon_cls (void) | |
20387 | { | |
64c350f2 | 20388 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
f30ee27c AV |
20389 | return; |
20390 | ||
20391 | enum neon_shape rs; | |
20392 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
20393 | rs = neon_select_shape (NS_QQ, NS_NULL); | |
20394 | else | |
20395 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
20396 | ||
5287ad62 JB |
20397 | struct neon_type_el et = neon_check_type (2, rs, |
20398 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 20399 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20400 | } |
20401 | ||
20402 | static void | |
20403 | do_neon_clz (void) | |
20404 | { | |
64c350f2 | 20405 | if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
f30ee27c AV |
20406 | return; |
20407 | ||
20408 | enum neon_shape rs; | |
20409 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
20410 | rs = neon_select_shape (NS_QQ, NS_NULL); | |
20411 | else | |
20412 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
20413 | ||
5287ad62 JB |
20414 | struct neon_type_el et = neon_check_type (2, rs, |
20415 | N_EQK, N_I8 | N_I16 | N_I32 | N_KEY); | |
037e8744 | 20416 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20417 | } |
20418 | ||
20419 | static void | |
20420 | do_neon_cnt (void) | |
20421 | { | |
037e8744 | 20422 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
20423 | struct neon_type_el et = neon_check_type (2, rs, |
20424 | N_EQK | N_INT, N_8 | N_KEY); | |
037e8744 | 20425 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20426 | } |
20427 | ||
20428 | static void | |
20429 | do_neon_swp (void) | |
20430 | { | |
037e8744 JB |
20431 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
20432 | neon_two_same (neon_quad (rs), 1, -1); | |
5287ad62 JB |
20433 | } |
20434 | ||
20435 | static void | |
20436 | do_neon_tbl_tbx (void) | |
20437 | { | |
20438 | unsigned listlenbits; | |
dcbf9037 | 20439 | neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY); |
5f4273c7 | 20440 | |
5287ad62 JB |
20441 | if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4) |
20442 | { | |
dcbf9037 | 20443 | first_error (_("bad list length for table lookup")); |
5287ad62 JB |
20444 | return; |
20445 | } | |
5f4273c7 | 20446 | |
5287ad62 JB |
20447 | listlenbits = inst.operands[1].imm - 1; |
20448 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
20449 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
20450 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
20451 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
20452 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
20453 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
20454 | inst.instruction |= listlenbits << 8; | |
5f4273c7 | 20455 | |
88714cb8 | 20456 | neon_dp_fixup (&inst); |
5287ad62 JB |
20457 | } |
20458 | ||
20459 | static void | |
20460 | do_neon_ldm_stm (void) | |
20461 | { | |
20462 | /* P, U and L bits are part of bitmask. */ | |
20463 | int is_dbmode = (inst.instruction & (1 << 24)) != 0; | |
20464 | unsigned offsetbits = inst.operands[1].imm * 2; | |
20465 | ||
037e8744 JB |
20466 | if (inst.operands[1].issingle) |
20467 | { | |
20468 | do_vfp_nsyn_ldm_stm (is_dbmode); | |
20469 | return; | |
20470 | } | |
20471 | ||
5287ad62 | 20472 | constraint (is_dbmode && !inst.operands[0].writeback, |
477330fc | 20473 | _("writeback (!) must be used for VLDMDB and VSTMDB")); |
5287ad62 JB |
20474 | |
20475 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
477330fc RM |
20476 | _("register list must contain at least 1 and at most 16 " |
20477 | "registers")); | |
5287ad62 JB |
20478 | |
20479 | inst.instruction |= inst.operands[0].reg << 16; | |
20480 | inst.instruction |= inst.operands[0].writeback << 21; | |
20481 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
20482 | inst.instruction |= HI1 (inst.operands[1].reg) << 22; | |
20483 | ||
20484 | inst.instruction |= offsetbits; | |
5f4273c7 | 20485 | |
037e8744 | 20486 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
20487 | } |
20488 | ||
20489 | static void | |
20490 | do_neon_ldr_str (void) | |
20491 | { | |
5287ad62 | 20492 | int is_ldr = (inst.instruction & (1 << 20)) != 0; |
5f4273c7 | 20493 | |
6844b2c2 MGD |
20494 | /* Use of PC in vstr in ARM mode is deprecated in ARMv7. |
20495 | And is UNPREDICTABLE in thumb mode. */ | |
fa94de6b | 20496 | if (!is_ldr |
6844b2c2 | 20497 | && inst.operands[1].reg == REG_PC |
ba86b375 | 20498 | && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode)) |
6844b2c2 | 20499 | { |
94dcf8bf | 20500 | if (thumb_mode) |
6844b2c2 | 20501 | inst.error = _("Use of PC here is UNPREDICTABLE"); |
94dcf8bf | 20502 | else if (warn_on_deprecated) |
5c3696f8 | 20503 | as_tsktsk (_("Use of PC here is deprecated")); |
6844b2c2 MGD |
20504 | } |
20505 | ||
037e8744 JB |
20506 | if (inst.operands[0].issingle) |
20507 | { | |
cd2f129f | 20508 | if (is_ldr) |
477330fc | 20509 | do_vfp_nsyn_opcode ("flds"); |
cd2f129f | 20510 | else |
477330fc | 20511 | do_vfp_nsyn_opcode ("fsts"); |
9db2f6b4 RL |
20512 | |
20513 | /* ARMv8.2 vldr.16/vstr.16 instruction. */ | |
20514 | if (inst.vectype.el[0].size == 16) | |
20515 | do_scalar_fp16_v82_encode (); | |
5287ad62 JB |
20516 | } |
20517 | else | |
5287ad62 | 20518 | { |
cd2f129f | 20519 | if (is_ldr) |
477330fc | 20520 | do_vfp_nsyn_opcode ("fldd"); |
5287ad62 | 20521 | else |
477330fc | 20522 | do_vfp_nsyn_opcode ("fstd"); |
5287ad62 | 20523 | } |
5287ad62 JB |
20524 | } |
20525 | ||
32c36c3c AV |
20526 | static void |
20527 | do_t_vldr_vstr_sysreg (void) | |
20528 | { | |
20529 | int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20; | |
20530 | bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0); | |
20531 | ||
20532 | /* Use of PC is UNPREDICTABLE. */ | |
20533 | if (inst.operands[1].reg == REG_PC) | |
20534 | inst.error = _("Use of PC here is UNPREDICTABLE"); | |
20535 | ||
20536 | if (inst.operands[1].immisreg) | |
20537 | inst.error = _("instruction does not accept register index"); | |
20538 | ||
20539 | if (!inst.operands[1].isreg) | |
20540 | inst.error = _("instruction does not accept PC-relative addressing"); | |
20541 | ||
20542 | if (abs (inst.operands[1].imm) >= (1 << 7)) | |
20543 | inst.error = _("immediate value out of range"); | |
20544 | ||
20545 | inst.instruction = 0xec000f80; | |
20546 | if (is_vldr) | |
20547 | inst.instruction |= 1 << sysreg_vldr_bitno; | |
20548 | encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM); | |
20549 | inst.instruction |= (inst.operands[0].imm & 0x7) << 13; | |
20550 | inst.instruction |= (inst.operands[0].imm & 0x8) << 19; | |
20551 | } | |
20552 | ||
20553 | static void | |
20554 | do_vldr_vstr (void) | |
20555 | { | |
20556 | bfd_boolean sysreg_op = !inst.operands[0].isreg; | |
20557 | ||
20558 | /* VLDR/VSTR (System Register). */ | |
20559 | if (sysreg_op) | |
20560 | { | |
20561 | if (!mark_feature_used (&arm_ext_v8_1m_main)) | |
20562 | as_bad (_("Instruction not permitted on this architecture")); | |
20563 | ||
20564 | do_t_vldr_vstr_sysreg (); | |
20565 | } | |
20566 | /* VLDR/VSTR. */ | |
20567 | else | |
20568 | { | |
20569 | if (!mark_feature_used (&fpu_vfp_ext_v1xd)) | |
20570 | as_bad (_("Instruction not permitted on this architecture")); | |
20571 | do_neon_ldr_str (); | |
20572 | } | |
20573 | } | |
20574 | ||
5287ad62 JB |
20575 | /* "interleave" version also handles non-interleaving register VLD1/VST1 |
20576 | instructions. */ | |
20577 | ||
20578 | static void | |
20579 | do_neon_ld_st_interleave (void) | |
20580 | { | |
037e8744 | 20581 | struct neon_type_el et = neon_check_type (1, NS_NULL, |
477330fc | 20582 | N_8 | N_16 | N_32 | N_64); |
5287ad62 JB |
20583 | unsigned alignbits = 0; |
20584 | unsigned idx; | |
20585 | /* The bits in this table go: | |
20586 | 0: register stride of one (0) or two (1) | |
20587 | 1,2: register list length, minus one (1, 2, 3, 4). | |
20588 | 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>). | |
20589 | We use -1 for invalid entries. */ | |
20590 | const int typetable[] = | |
20591 | { | |
20592 | 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */ | |
20593 | -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */ | |
20594 | -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */ | |
20595 | -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */ | |
20596 | }; | |
20597 | int typebits; | |
20598 | ||
dcbf9037 JB |
20599 | if (et.type == NT_invtype) |
20600 | return; | |
20601 | ||
5287ad62 JB |
20602 | if (inst.operands[1].immisalign) |
20603 | switch (inst.operands[1].imm >> 8) | |
20604 | { | |
20605 | case 64: alignbits = 1; break; | |
20606 | case 128: | |
477330fc | 20607 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2 |
e23c0ad8 | 20608 | && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
477330fc RM |
20609 | goto bad_alignment; |
20610 | alignbits = 2; | |
20611 | break; | |
5287ad62 | 20612 | case 256: |
477330fc RM |
20613 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
20614 | goto bad_alignment; | |
20615 | alignbits = 3; | |
20616 | break; | |
5287ad62 JB |
20617 | default: |
20618 | bad_alignment: | |
477330fc RM |
20619 | first_error (_("bad alignment")); |
20620 | return; | |
5287ad62 JB |
20621 | } |
20622 | ||
20623 | inst.instruction |= alignbits << 4; | |
20624 | inst.instruction |= neon_logbits (et.size) << 6; | |
20625 | ||
20626 | /* Bits [4:6] of the immediate in a list specifier encode register stride | |
20627 | (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of | |
20628 | VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look | |
20629 | up the right value for "type" in a table based on this value and the given | |
20630 | list style, then stick it back. */ | |
20631 | idx = ((inst.operands[0].imm >> 4) & 7) | |
477330fc | 20632 | | (((inst.instruction >> 8) & 3) << 3); |
5287ad62 JB |
20633 | |
20634 | typebits = typetable[idx]; | |
5f4273c7 | 20635 | |
5287ad62 | 20636 | constraint (typebits == -1, _("bad list type for instruction")); |
1d50d57c | 20637 | constraint (((inst.instruction >> 8) & 3) && et.size == 64, |
35c228db | 20638 | BAD_EL_TYPE); |
5287ad62 JB |
20639 | |
20640 | inst.instruction &= ~0xf00; | |
20641 | inst.instruction |= typebits << 8; | |
20642 | } | |
20643 | ||
20644 | /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup. | |
20645 | *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0 | |
20646 | otherwise. The variable arguments are a list of pairs of legal (size, align) | |
20647 | values, terminated with -1. */ | |
20648 | ||
20649 | static int | |
aa8a0863 | 20650 | neon_alignment_bit (int size, int align, int *do_alignment, ...) |
5287ad62 JB |
20651 | { |
20652 | va_list ap; | |
20653 | int result = FAIL, thissize, thisalign; | |
5f4273c7 | 20654 | |
5287ad62 JB |
20655 | if (!inst.operands[1].immisalign) |
20656 | { | |
aa8a0863 | 20657 | *do_alignment = 0; |
5287ad62 JB |
20658 | return SUCCESS; |
20659 | } | |
5f4273c7 | 20660 | |
aa8a0863 | 20661 | va_start (ap, do_alignment); |
5287ad62 JB |
20662 | |
20663 | do | |
20664 | { | |
20665 | thissize = va_arg (ap, int); | |
20666 | if (thissize == -1) | |
477330fc | 20667 | break; |
5287ad62 JB |
20668 | thisalign = va_arg (ap, int); |
20669 | ||
20670 | if (size == thissize && align == thisalign) | |
477330fc | 20671 | result = SUCCESS; |
5287ad62 JB |
20672 | } |
20673 | while (result != SUCCESS); | |
20674 | ||
20675 | va_end (ap); | |
20676 | ||
20677 | if (result == SUCCESS) | |
aa8a0863 | 20678 | *do_alignment = 1; |
5287ad62 | 20679 | else |
dcbf9037 | 20680 | first_error (_("unsupported alignment for instruction")); |
5f4273c7 | 20681 | |
5287ad62 JB |
20682 | return result; |
20683 | } | |
20684 | ||
20685 | static void | |
20686 | do_neon_ld_st_lane (void) | |
20687 | { | |
037e8744 | 20688 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
aa8a0863 | 20689 | int align_good, do_alignment = 0; |
5287ad62 JB |
20690 | int logsize = neon_logbits (et.size); |
20691 | int align = inst.operands[1].imm >> 8; | |
20692 | int n = (inst.instruction >> 8) & 3; | |
20693 | int max_el = 64 / et.size; | |
5f4273c7 | 20694 | |
dcbf9037 JB |
20695 | if (et.type == NT_invtype) |
20696 | return; | |
5f4273c7 | 20697 | |
5287ad62 | 20698 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1, |
477330fc | 20699 | _("bad list length")); |
5287ad62 | 20700 | constraint (NEON_LANE (inst.operands[0].imm) >= max_el, |
477330fc | 20701 | _("scalar index out of range")); |
5287ad62 | 20702 | constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2 |
477330fc RM |
20703 | && et.size == 8, |
20704 | _("stride of 2 unavailable when element size is 8")); | |
5f4273c7 | 20705 | |
5287ad62 JB |
20706 | switch (n) |
20707 | { | |
20708 | case 0: /* VLD1 / VST1. */ | |
aa8a0863 | 20709 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16, |
477330fc | 20710 | 32, 32, -1); |
5287ad62 | 20711 | if (align_good == FAIL) |
477330fc | 20712 | return; |
aa8a0863 | 20713 | if (do_alignment) |
477330fc RM |
20714 | { |
20715 | unsigned alignbits = 0; | |
20716 | switch (et.size) | |
20717 | { | |
20718 | case 16: alignbits = 0x1; break; | |
20719 | case 32: alignbits = 0x3; break; | |
20720 | default: ; | |
20721 | } | |
20722 | inst.instruction |= alignbits << 4; | |
20723 | } | |
5287ad62 JB |
20724 | break; |
20725 | ||
20726 | case 1: /* VLD2 / VST2. */ | |
aa8a0863 TS |
20727 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16, |
20728 | 16, 32, 32, 64, -1); | |
5287ad62 | 20729 | if (align_good == FAIL) |
477330fc | 20730 | return; |
aa8a0863 | 20731 | if (do_alignment) |
477330fc | 20732 | inst.instruction |= 1 << 4; |
5287ad62 JB |
20733 | break; |
20734 | ||
20735 | case 2: /* VLD3 / VST3. */ | |
20736 | constraint (inst.operands[1].immisalign, | |
477330fc | 20737 | _("can't use alignment with this instruction")); |
5287ad62 JB |
20738 | break; |
20739 | ||
20740 | case 3: /* VLD4 / VST4. */ | |
aa8a0863 | 20741 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32, |
477330fc | 20742 | 16, 64, 32, 64, 32, 128, -1); |
5287ad62 | 20743 | if (align_good == FAIL) |
477330fc | 20744 | return; |
aa8a0863 | 20745 | if (do_alignment) |
477330fc RM |
20746 | { |
20747 | unsigned alignbits = 0; | |
20748 | switch (et.size) | |
20749 | { | |
20750 | case 8: alignbits = 0x1; break; | |
20751 | case 16: alignbits = 0x1; break; | |
20752 | case 32: alignbits = (align == 64) ? 0x1 : 0x2; break; | |
20753 | default: ; | |
20754 | } | |
20755 | inst.instruction |= alignbits << 4; | |
20756 | } | |
5287ad62 JB |
20757 | break; |
20758 | ||
20759 | default: ; | |
20760 | } | |
20761 | ||
20762 | /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */ | |
20763 | if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
20764 | inst.instruction |= 1 << (4 + logsize); | |
5f4273c7 | 20765 | |
5287ad62 JB |
20766 | inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5); |
20767 | inst.instruction |= logsize << 10; | |
20768 | } | |
20769 | ||
20770 | /* Encode single n-element structure to all lanes VLD<n> instructions. */ | |
20771 | ||
20772 | static void | |
20773 | do_neon_ld_dup (void) | |
20774 | { | |
037e8744 | 20775 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
aa8a0863 | 20776 | int align_good, do_alignment = 0; |
5287ad62 | 20777 | |
dcbf9037 JB |
20778 | if (et.type == NT_invtype) |
20779 | return; | |
20780 | ||
5287ad62 JB |
20781 | switch ((inst.instruction >> 8) & 3) |
20782 | { | |
20783 | case 0: /* VLD1. */ | |
9c2799c2 | 20784 | gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2); |
5287ad62 | 20785 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, |
aa8a0863 | 20786 | &do_alignment, 16, 16, 32, 32, -1); |
5287ad62 | 20787 | if (align_good == FAIL) |
477330fc | 20788 | return; |
5287ad62 | 20789 | switch (NEON_REGLIST_LENGTH (inst.operands[0].imm)) |
477330fc RM |
20790 | { |
20791 | case 1: break; | |
20792 | case 2: inst.instruction |= 1 << 5; break; | |
20793 | default: first_error (_("bad list length")); return; | |
20794 | } | |
5287ad62 JB |
20795 | inst.instruction |= neon_logbits (et.size) << 6; |
20796 | break; | |
20797 | ||
20798 | case 1: /* VLD2. */ | |
20799 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
aa8a0863 TS |
20800 | &do_alignment, 8, 16, 16, 32, 32, 64, |
20801 | -1); | |
5287ad62 | 20802 | if (align_good == FAIL) |
477330fc | 20803 | return; |
5287ad62 | 20804 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2, |
477330fc | 20805 | _("bad list length")); |
5287ad62 | 20806 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) |
477330fc | 20807 | inst.instruction |= 1 << 5; |
5287ad62 JB |
20808 | inst.instruction |= neon_logbits (et.size) << 6; |
20809 | break; | |
20810 | ||
20811 | case 2: /* VLD3. */ | |
20812 | constraint (inst.operands[1].immisalign, | |
477330fc | 20813 | _("can't use alignment with this instruction")); |
5287ad62 | 20814 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3, |
477330fc | 20815 | _("bad list length")); |
5287ad62 | 20816 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) |
477330fc | 20817 | inst.instruction |= 1 << 5; |
5287ad62 JB |
20818 | inst.instruction |= neon_logbits (et.size) << 6; |
20819 | break; | |
20820 | ||
20821 | case 3: /* VLD4. */ | |
20822 | { | |
477330fc | 20823 | int align = inst.operands[1].imm >> 8; |
aa8a0863 | 20824 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32, |
477330fc RM |
20825 | 16, 64, 32, 64, 32, 128, -1); |
20826 | if (align_good == FAIL) | |
20827 | return; | |
20828 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4, | |
20829 | _("bad list length")); | |
20830 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
20831 | inst.instruction |= 1 << 5; | |
20832 | if (et.size == 32 && align == 128) | |
20833 | inst.instruction |= 0x3 << 6; | |
20834 | else | |
20835 | inst.instruction |= neon_logbits (et.size) << 6; | |
5287ad62 JB |
20836 | } |
20837 | break; | |
20838 | ||
20839 | default: ; | |
20840 | } | |
20841 | ||
aa8a0863 | 20842 | inst.instruction |= do_alignment << 4; |
5287ad62 JB |
20843 | } |
20844 | ||
20845 | /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those | |
20846 | apart from bits [11:4]. */ | |
20847 | ||
20848 | static void | |
20849 | do_neon_ldx_stx (void) | |
20850 | { | |
b1a769ed DG |
20851 | if (inst.operands[1].isreg) |
20852 | constraint (inst.operands[1].reg == REG_PC, BAD_PC); | |
20853 | ||
5287ad62 JB |
20854 | switch (NEON_LANE (inst.operands[0].imm)) |
20855 | { | |
20856 | case NEON_INTERLEAVE_LANES: | |
88714cb8 | 20857 | NEON_ENCODE (INTERLV, inst); |
5287ad62 JB |
20858 | do_neon_ld_st_interleave (); |
20859 | break; | |
5f4273c7 | 20860 | |
5287ad62 | 20861 | case NEON_ALL_LANES: |
88714cb8 | 20862 | NEON_ENCODE (DUP, inst); |
2d51fb74 JB |
20863 | if (inst.instruction == N_INV) |
20864 | { | |
20865 | first_error ("only loads support such operands"); | |
20866 | break; | |
20867 | } | |
5287ad62 JB |
20868 | do_neon_ld_dup (); |
20869 | break; | |
5f4273c7 | 20870 | |
5287ad62 | 20871 | default: |
88714cb8 | 20872 | NEON_ENCODE (LANE, inst); |
5287ad62 JB |
20873 | do_neon_ld_st_lane (); |
20874 | } | |
20875 | ||
20876 | /* L bit comes from bit mask. */ | |
20877 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
20878 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
20879 | inst.instruction |= inst.operands[1].reg << 16; | |
5f4273c7 | 20880 | |
5287ad62 JB |
20881 | if (inst.operands[1].postind) |
20882 | { | |
20883 | int postreg = inst.operands[1].imm & 0xf; | |
20884 | constraint (!inst.operands[1].immisreg, | |
477330fc | 20885 | _("post-index must be a register")); |
5287ad62 | 20886 | constraint (postreg == 0xd || postreg == 0xf, |
477330fc | 20887 | _("bad register for post-index")); |
5287ad62 JB |
20888 | inst.instruction |= postreg; |
20889 | } | |
4f2374c7 | 20890 | else |
5287ad62 | 20891 | { |
4f2374c7 | 20892 | constraint (inst.operands[1].immisreg, BAD_ADDR_MODE); |
e2b0ab59 AV |
20893 | constraint (inst.relocs[0].exp.X_op != O_constant |
20894 | || inst.relocs[0].exp.X_add_number != 0, | |
4f2374c7 WN |
20895 | BAD_ADDR_MODE); |
20896 | ||
20897 | if (inst.operands[1].writeback) | |
20898 | { | |
20899 | inst.instruction |= 0xd; | |
20900 | } | |
20901 | else | |
20902 | inst.instruction |= 0xf; | |
5287ad62 | 20903 | } |
5f4273c7 | 20904 | |
5287ad62 JB |
20905 | if (thumb_mode) |
20906 | inst.instruction |= 0xf9000000; | |
20907 | else | |
20908 | inst.instruction |= 0xf4000000; | |
20909 | } | |
33399f07 MGD |
20910 | |
20911 | /* FP v8. */ | |
20912 | static void | |
20913 | do_vfp_nsyn_fpv8 (enum neon_shape rs) | |
20914 | { | |
a715796b TG |
20915 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
20916 | D register operands. */ | |
20917 | if (neon_shape_class[rs] == SC_DOUBLE) | |
20918 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
20919 | _(BAD_FPU)); | |
20920 | ||
33399f07 MGD |
20921 | NEON_ENCODE (FPV8, inst); |
20922 | ||
9db2f6b4 RL |
20923 | if (rs == NS_FFF || rs == NS_HHH) |
20924 | { | |
20925 | do_vfp_sp_dyadic (); | |
20926 | ||
20927 | /* ARMv8.2 fp16 instruction. */ | |
20928 | if (rs == NS_HHH) | |
20929 | do_scalar_fp16_v82_encode (); | |
20930 | } | |
33399f07 MGD |
20931 | else |
20932 | do_vfp_dp_rd_rn_rm (); | |
20933 | ||
20934 | if (rs == NS_DDD) | |
20935 | inst.instruction |= 0x100; | |
20936 | ||
20937 | inst.instruction |= 0xf0000000; | |
20938 | } | |
20939 | ||
20940 | static void | |
20941 | do_vsel (void) | |
20942 | { | |
5ee91343 | 20943 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
33399f07 MGD |
20944 | |
20945 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS) | |
20946 | first_error (_("invalid instruction shape")); | |
20947 | } | |
20948 | ||
73924fbc MGD |
20949 | static void |
20950 | do_vmaxnm (void) | |
20951 | { | |
935295b5 AV |
20952 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) |
20953 | set_pred_insn_type (OUTSIDE_PRED_INSN); | |
73924fbc MGD |
20954 | |
20955 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS) | |
20956 | return; | |
20957 | ||
64c350f2 | 20958 | if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH8)) |
73924fbc MGD |
20959 | return; |
20960 | ||
cc933301 | 20961 | neon_dyadic_misc (NT_untyped, N_F_16_32, 0); |
73924fbc MGD |
20962 | } |
20963 | ||
30bdf752 MGD |
20964 | static void |
20965 | do_vrint_1 (enum neon_cvt_mode mode) | |
20966 | { | |
9db2f6b4 | 20967 | enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL); |
30bdf752 MGD |
20968 | struct neon_type_el et; |
20969 | ||
20970 | if (rs == NS_NULL) | |
20971 | return; | |
20972 | ||
a715796b TG |
20973 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
20974 | D register operands. */ | |
20975 | if (neon_shape_class[rs] == SC_DOUBLE) | |
20976 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
20977 | _(BAD_FPU)); | |
20978 | ||
9db2f6b4 RL |
20979 | et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY |
20980 | | N_VFP); | |
30bdf752 MGD |
20981 | if (et.type != NT_invtype) |
20982 | { | |
20983 | /* VFP encodings. */ | |
20984 | if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n | |
20985 | || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m) | |
5ee91343 | 20986 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
30bdf752 MGD |
20987 | |
20988 | NEON_ENCODE (FPV8, inst); | |
9db2f6b4 | 20989 | if (rs == NS_FF || rs == NS_HH) |
30bdf752 MGD |
20990 | do_vfp_sp_monadic (); |
20991 | else | |
20992 | do_vfp_dp_rd_rm (); | |
20993 | ||
20994 | switch (mode) | |
20995 | { | |
20996 | case neon_cvt_mode_r: inst.instruction |= 0x00000000; break; | |
20997 | case neon_cvt_mode_z: inst.instruction |= 0x00000080; break; | |
20998 | case neon_cvt_mode_x: inst.instruction |= 0x00010000; break; | |
20999 | case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break; | |
21000 | case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break; | |
21001 | case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break; | |
21002 | case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break; | |
21003 | default: abort (); | |
21004 | } | |
21005 | ||
21006 | inst.instruction |= (rs == NS_DD) << 8; | |
21007 | do_vfp_cond_or_thumb (); | |
9db2f6b4 RL |
21008 | |
21009 | /* ARMv8.2 fp16 vrint instruction. */ | |
21010 | if (rs == NS_HH) | |
21011 | do_scalar_fp16_v82_encode (); | |
30bdf752 MGD |
21012 | } |
21013 | else | |
21014 | { | |
21015 | /* Neon encodings (or something broken...). */ | |
21016 | inst.error = NULL; | |
cc933301 | 21017 | et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY); |
30bdf752 MGD |
21018 | |
21019 | if (et.type == NT_invtype) | |
21020 | return; | |
21021 | ||
64c350f2 AV |
21022 | if (!check_simd_pred_availability (TRUE, |
21023 | NEON_CHECK_CC | NEON_CHECK_ARCH8)) | |
30bdf752 MGD |
21024 | return; |
21025 | ||
a710b305 AV |
21026 | NEON_ENCODE (FLOAT, inst); |
21027 | ||
30bdf752 MGD |
21028 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
21029 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
21030 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
21031 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
21032 | inst.instruction |= neon_quad (rs) << 6; | |
cc933301 JW |
21033 | /* Mask off the original size bits and reencode them. */ |
21034 | inst.instruction = ((inst.instruction & 0xfff3ffff) | |
21035 | | neon_logbits (et.size) << 18); | |
21036 | ||
30bdf752 MGD |
21037 | switch (mode) |
21038 | { | |
21039 | case neon_cvt_mode_z: inst.instruction |= 3 << 7; break; | |
21040 | case neon_cvt_mode_x: inst.instruction |= 1 << 7; break; | |
21041 | case neon_cvt_mode_a: inst.instruction |= 2 << 7; break; | |
21042 | case neon_cvt_mode_n: inst.instruction |= 0 << 7; break; | |
21043 | case neon_cvt_mode_p: inst.instruction |= 7 << 7; break; | |
21044 | case neon_cvt_mode_m: inst.instruction |= 5 << 7; break; | |
21045 | case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break; | |
21046 | default: abort (); | |
21047 | } | |
21048 | ||
21049 | if (thumb_mode) | |
21050 | inst.instruction |= 0xfc000000; | |
21051 | else | |
21052 | inst.instruction |= 0xf0000000; | |
21053 | } | |
21054 | } | |
21055 | ||
21056 | static void | |
21057 | do_vrintx (void) | |
21058 | { | |
21059 | do_vrint_1 (neon_cvt_mode_x); | |
21060 | } | |
21061 | ||
21062 | static void | |
21063 | do_vrintz (void) | |
21064 | { | |
21065 | do_vrint_1 (neon_cvt_mode_z); | |
21066 | } | |
21067 | ||
21068 | static void | |
21069 | do_vrintr (void) | |
21070 | { | |
21071 | do_vrint_1 (neon_cvt_mode_r); | |
21072 | } | |
21073 | ||
21074 | static void | |
21075 | do_vrinta (void) | |
21076 | { | |
21077 | do_vrint_1 (neon_cvt_mode_a); | |
21078 | } | |
21079 | ||
21080 | static void | |
21081 | do_vrintn (void) | |
21082 | { | |
21083 | do_vrint_1 (neon_cvt_mode_n); | |
21084 | } | |
21085 | ||
21086 | static void | |
21087 | do_vrintp (void) | |
21088 | { | |
21089 | do_vrint_1 (neon_cvt_mode_p); | |
21090 | } | |
21091 | ||
21092 | static void | |
21093 | do_vrintm (void) | |
21094 | { | |
21095 | do_vrint_1 (neon_cvt_mode_m); | |
21096 | } | |
21097 | ||
c28eeff2 SN |
21098 | static unsigned |
21099 | neon_scalar_for_vcmla (unsigned opnd, unsigned elsize) | |
21100 | { | |
21101 | unsigned regno = NEON_SCALAR_REG (opnd); | |
21102 | unsigned elno = NEON_SCALAR_INDEX (opnd); | |
21103 | ||
21104 | if (elsize == 16 && elno < 2 && regno < 16) | |
21105 | return regno | (elno << 4); | |
21106 | else if (elsize == 32 && elno == 0) | |
21107 | return regno; | |
21108 | ||
21109 | first_error (_("scalar out of range")); | |
21110 | return 0; | |
21111 | } | |
21112 | ||
21113 | static void | |
21114 | do_vcmla (void) | |
21115 | { | |
5d281bf0 AV |
21116 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) |
21117 | && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8) | |
21118 | || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU)); | |
e2b0ab59 AV |
21119 | constraint (inst.relocs[0].exp.X_op != O_constant, |
21120 | _("expression too complex")); | |
21121 | unsigned rot = inst.relocs[0].exp.X_add_number; | |
c28eeff2 SN |
21122 | constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270, |
21123 | _("immediate out of range")); | |
21124 | rot /= 90; | |
5d281bf0 | 21125 | |
64c350f2 AV |
21126 | if (!check_simd_pred_availability (TRUE, |
21127 | NEON_CHECK_ARCH8 | NEON_CHECK_CC)) | |
5d281bf0 AV |
21128 | return; |
21129 | ||
c28eeff2 SN |
21130 | if (inst.operands[2].isscalar) |
21131 | { | |
5d281bf0 AV |
21132 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)) |
21133 | first_error (_("invalid instruction shape")); | |
c28eeff2 SN |
21134 | enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL); |
21135 | unsigned size = neon_check_type (3, rs, N_EQK, N_EQK, | |
21136 | N_KEY | N_F16 | N_F32).size; | |
21137 | unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size); | |
21138 | inst.is_neon = 1; | |
21139 | inst.instruction = 0xfe000800; | |
21140 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
21141 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
21142 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
21143 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
21144 | inst.instruction |= LOW4 (m); | |
21145 | inst.instruction |= HI1 (m) << 5; | |
21146 | inst.instruction |= neon_quad (rs) << 6; | |
21147 | inst.instruction |= rot << 20; | |
21148 | inst.instruction |= (size == 32) << 23; | |
21149 | } | |
21150 | else | |
21151 | { | |
5d281bf0 AV |
21152 | enum neon_shape rs; |
21153 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)) | |
21154 | rs = neon_select_shape (NS_QQQI, NS_NULL); | |
21155 | else | |
21156 | rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); | |
21157 | ||
c28eeff2 SN |
21158 | unsigned size = neon_check_type (3, rs, N_EQK, N_EQK, |
21159 | N_KEY | N_F16 | N_F32).size; | |
5d281bf0 AV |
21160 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) && size == 32 |
21161 | && (inst.operands[0].reg == inst.operands[1].reg | |
21162 | || inst.operands[0].reg == inst.operands[2].reg)) | |
21163 | as_tsktsk (BAD_MVE_SRCDEST); | |
21164 | ||
c28eeff2 SN |
21165 | neon_three_same (neon_quad (rs), 0, -1); |
21166 | inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */ | |
21167 | inst.instruction |= 0xfc200800; | |
21168 | inst.instruction |= rot << 23; | |
21169 | inst.instruction |= (size == 32) << 20; | |
21170 | } | |
21171 | } | |
21172 | ||
21173 | static void | |
21174 | do_vcadd (void) | |
21175 | { | |
5d281bf0 AV |
21176 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) |
21177 | && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8) | |
21178 | || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU)); | |
e2b0ab59 AV |
21179 | constraint (inst.relocs[0].exp.X_op != O_constant, |
21180 | _("expression too complex")); | |
5d281bf0 | 21181 | |
e2b0ab59 | 21182 | unsigned rot = inst.relocs[0].exp.X_add_number; |
c28eeff2 | 21183 | constraint (rot != 90 && rot != 270, _("immediate out of range")); |
5d281bf0 AV |
21184 | enum neon_shape rs; |
21185 | struct neon_type_el et; | |
21186 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
21187 | { | |
21188 | rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); | |
21189 | et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32); | |
21190 | } | |
21191 | else | |
21192 | { | |
21193 | rs = neon_select_shape (NS_QQQI, NS_NULL); | |
21194 | et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32 | N_I8 | |
21195 | | N_I16 | N_I32); | |
21196 | if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg) | |
21197 | as_tsktsk (_("Warning: 32-bit element size and same first and third " | |
21198 | "operand makes instruction UNPREDICTABLE")); | |
21199 | } | |
21200 | ||
21201 | if (et.type == NT_invtype) | |
21202 | return; | |
21203 | ||
64c350f2 AV |
21204 | if (!check_simd_pred_availability (et.type == NT_float, |
21205 | NEON_CHECK_ARCH8 | NEON_CHECK_CC)) | |
5d281bf0 AV |
21206 | return; |
21207 | ||
21208 | if (et.type == NT_float) | |
21209 | { | |
21210 | neon_three_same (neon_quad (rs), 0, -1); | |
21211 | inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */ | |
21212 | inst.instruction |= 0xfc800800; | |
21213 | inst.instruction |= (rot == 270) << 24; | |
21214 | inst.instruction |= (et.size == 32) << 20; | |
21215 | } | |
21216 | else | |
21217 | { | |
21218 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU); | |
21219 | inst.instruction = 0xfe000f00; | |
21220 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
21221 | inst.instruction |= neon_logbits (et.size) << 20; | |
21222 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
21223 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
21224 | inst.instruction |= (rot == 270) << 12; | |
21225 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
21226 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
21227 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
21228 | inst.is_neon = 1; | |
21229 | } | |
c28eeff2 SN |
21230 | } |
21231 | ||
c604a79a JW |
21232 | /* Dot Product instructions encoding support. */ |
21233 | ||
21234 | static void | |
21235 | do_neon_dotproduct (int unsigned_p) | |
21236 | { | |
21237 | enum neon_shape rs; | |
21238 | unsigned scalar_oprd2 = 0; | |
21239 | int high8; | |
21240 | ||
21241 | if (inst.cond != COND_ALWAYS) | |
21242 | as_warn (_("Dot Product instructions cannot be conditional, the behaviour " | |
21243 | "is UNPREDICTABLE")); | |
21244 | ||
21245 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8), | |
21246 | _(BAD_FPU)); | |
21247 | ||
21248 | /* Dot Product instructions are in three-same D/Q register format or the third | |
21249 | operand can be a scalar index register. */ | |
21250 | if (inst.operands[2].isscalar) | |
21251 | { | |
21252 | scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32); | |
21253 | high8 = 0xfe000000; | |
21254 | rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); | |
21255 | } | |
21256 | else | |
21257 | { | |
21258 | high8 = 0xfc000000; | |
21259 | rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
21260 | } | |
21261 | ||
21262 | if (unsigned_p) | |
21263 | neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8); | |
21264 | else | |
21265 | neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8); | |
21266 | ||
21267 | /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot | |
21268 | Product instruction, so we pass 0 as the "ubit" parameter. And the | |
21269 | "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */ | |
21270 | neon_three_same (neon_quad (rs), 0, 32); | |
21271 | ||
21272 | /* Undo neon_dp_fixup. Dot Product instructions are using a slightly | |
21273 | different NEON three-same encoding. */ | |
21274 | inst.instruction &= 0x00ffffff; | |
21275 | inst.instruction |= high8; | |
21276 | /* Encode 'U' bit which indicates signedness. */ | |
21277 | inst.instruction |= (unsigned_p ? 1 : 0) << 4; | |
21278 | /* Re-encode operand2 if it's indexed scalar operand. What has been encoded | |
21279 | from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not | |
21280 | the instruction encoding. */ | |
21281 | if (inst.operands[2].isscalar) | |
21282 | { | |
21283 | inst.instruction &= 0xffffffd0; | |
21284 | inst.instruction |= LOW4 (scalar_oprd2); | |
21285 | inst.instruction |= HI1 (scalar_oprd2) << 5; | |
21286 | } | |
21287 | } | |
21288 | ||
21289 | /* Dot Product instructions for signed integer. */ | |
21290 | ||
21291 | static void | |
21292 | do_neon_dotproduct_s (void) | |
21293 | { | |
21294 | return do_neon_dotproduct (0); | |
21295 | } | |
21296 | ||
21297 | /* Dot Product instructions for unsigned integer. */ | |
21298 | ||
21299 | static void | |
21300 | do_neon_dotproduct_u (void) | |
21301 | { | |
21302 | return do_neon_dotproduct (1); | |
21303 | } | |
21304 | ||
91ff7894 MGD |
21305 | /* Crypto v1 instructions. */ |
21306 | static void | |
21307 | do_crypto_2op_1 (unsigned elttype, int op) | |
21308 | { | |
5ee91343 | 21309 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
91ff7894 MGD |
21310 | |
21311 | if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type | |
21312 | == NT_invtype) | |
21313 | return; | |
21314 | ||
21315 | inst.error = NULL; | |
21316 | ||
21317 | NEON_ENCODE (INTEGER, inst); | |
21318 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
21319 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
21320 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
21321 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
21322 | if (op != -1) | |
21323 | inst.instruction |= op << 6; | |
21324 | ||
21325 | if (thumb_mode) | |
21326 | inst.instruction |= 0xfc000000; | |
21327 | else | |
21328 | inst.instruction |= 0xf0000000; | |
21329 | } | |
21330 | ||
48adcd8e MGD |
21331 | static void |
21332 | do_crypto_3op_1 (int u, int op) | |
21333 | { | |
5ee91343 | 21334 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
48adcd8e MGD |
21335 | |
21336 | if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT, | |
21337 | N_32 | N_UNT | N_KEY).type == NT_invtype) | |
21338 | return; | |
21339 | ||
21340 | inst.error = NULL; | |
21341 | ||
21342 | NEON_ENCODE (INTEGER, inst); | |
21343 | neon_three_same (1, u, 8 << op); | |
21344 | } | |
21345 | ||
91ff7894 MGD |
21346 | static void |
21347 | do_aese (void) | |
21348 | { | |
21349 | do_crypto_2op_1 (N_8, 0); | |
21350 | } | |
21351 | ||
21352 | static void | |
21353 | do_aesd (void) | |
21354 | { | |
21355 | do_crypto_2op_1 (N_8, 1); | |
21356 | } | |
21357 | ||
21358 | static void | |
21359 | do_aesmc (void) | |
21360 | { | |
21361 | do_crypto_2op_1 (N_8, 2); | |
21362 | } | |
21363 | ||
21364 | static void | |
21365 | do_aesimc (void) | |
21366 | { | |
21367 | do_crypto_2op_1 (N_8, 3); | |
21368 | } | |
21369 | ||
48adcd8e MGD |
21370 | static void |
21371 | do_sha1c (void) | |
21372 | { | |
21373 | do_crypto_3op_1 (0, 0); | |
21374 | } | |
21375 | ||
21376 | static void | |
21377 | do_sha1p (void) | |
21378 | { | |
21379 | do_crypto_3op_1 (0, 1); | |
21380 | } | |
21381 | ||
21382 | static void | |
21383 | do_sha1m (void) | |
21384 | { | |
21385 | do_crypto_3op_1 (0, 2); | |
21386 | } | |
21387 | ||
21388 | static void | |
21389 | do_sha1su0 (void) | |
21390 | { | |
21391 | do_crypto_3op_1 (0, 3); | |
21392 | } | |
91ff7894 | 21393 | |
48adcd8e MGD |
21394 | static void |
21395 | do_sha256h (void) | |
21396 | { | |
21397 | do_crypto_3op_1 (1, 0); | |
21398 | } | |
21399 | ||
21400 | static void | |
21401 | do_sha256h2 (void) | |
21402 | { | |
21403 | do_crypto_3op_1 (1, 1); | |
21404 | } | |
21405 | ||
21406 | static void | |
21407 | do_sha256su1 (void) | |
21408 | { | |
21409 | do_crypto_3op_1 (1, 2); | |
21410 | } | |
3c9017d2 MGD |
21411 | |
21412 | static void | |
21413 | do_sha1h (void) | |
21414 | { | |
21415 | do_crypto_2op_1 (N_32, -1); | |
21416 | } | |
21417 | ||
21418 | static void | |
21419 | do_sha1su1 (void) | |
21420 | { | |
21421 | do_crypto_2op_1 (N_32, 0); | |
21422 | } | |
21423 | ||
21424 | static void | |
21425 | do_sha256su0 (void) | |
21426 | { | |
21427 | do_crypto_2op_1 (N_32, 1); | |
21428 | } | |
dd5181d5 KT |
21429 | |
21430 | static void | |
21431 | do_crc32_1 (unsigned int poly, unsigned int sz) | |
21432 | { | |
21433 | unsigned int Rd = inst.operands[0].reg; | |
21434 | unsigned int Rn = inst.operands[1].reg; | |
21435 | unsigned int Rm = inst.operands[2].reg; | |
21436 | ||
5ee91343 | 21437 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
dd5181d5 KT |
21438 | inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12); |
21439 | inst.instruction |= LOW4 (Rn) << 16; | |
21440 | inst.instruction |= LOW4 (Rm); | |
21441 | inst.instruction |= sz << (thumb_mode ? 4 : 21); | |
21442 | inst.instruction |= poly << (thumb_mode ? 20 : 9); | |
21443 | ||
21444 | if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC) | |
21445 | as_warn (UNPRED_REG ("r15")); | |
dd5181d5 KT |
21446 | } |
21447 | ||
21448 | static void | |
21449 | do_crc32b (void) | |
21450 | { | |
21451 | do_crc32_1 (0, 0); | |
21452 | } | |
21453 | ||
21454 | static void | |
21455 | do_crc32h (void) | |
21456 | { | |
21457 | do_crc32_1 (0, 1); | |
21458 | } | |
21459 | ||
21460 | static void | |
21461 | do_crc32w (void) | |
21462 | { | |
21463 | do_crc32_1 (0, 2); | |
21464 | } | |
21465 | ||
21466 | static void | |
21467 | do_crc32cb (void) | |
21468 | { | |
21469 | do_crc32_1 (1, 0); | |
21470 | } | |
21471 | ||
21472 | static void | |
21473 | do_crc32ch (void) | |
21474 | { | |
21475 | do_crc32_1 (1, 1); | |
21476 | } | |
21477 | ||
21478 | static void | |
21479 | do_crc32cw (void) | |
21480 | { | |
21481 | do_crc32_1 (1, 2); | |
21482 | } | |
21483 | ||
49e8a725 SN |
21484 | static void |
21485 | do_vjcvt (void) | |
21486 | { | |
21487 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
21488 | _(BAD_FPU)); | |
21489 | neon_check_type (2, NS_FD, N_S32, N_F64); | |
21490 | do_vfp_sp_dp_cvt (); | |
21491 | do_vfp_cond_or_thumb (); | |
21492 | } | |
21493 | ||
5287ad62 JB |
21494 | \f |
21495 | /* Overall per-instruction processing. */ | |
21496 | ||
21497 | /* We need to be able to fix up arbitrary expressions in some statements. | |
21498 | This is so that we can handle symbols that are an arbitrary distance from | |
21499 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
21500 | which returns part of an address in a form which will be valid for | |
21501 | a data instruction. We do this by pushing the expression into a symbol | |
21502 | in the expr_section, and creating a fix for that. */ | |
21503 | ||
21504 | static void | |
21505 | fix_new_arm (fragS * frag, | |
21506 | int where, | |
21507 | short int size, | |
21508 | expressionS * exp, | |
21509 | int pc_rel, | |
21510 | int reloc) | |
21511 | { | |
21512 | fixS * new_fix; | |
21513 | ||
21514 | switch (exp->X_op) | |
21515 | { | |
21516 | case O_constant: | |
6e7ce2cd PB |
21517 | if (pc_rel) |
21518 | { | |
21519 | /* Create an absolute valued symbol, so we have something to | |
477330fc RM |
21520 | refer to in the object file. Unfortunately for us, gas's |
21521 | generic expression parsing will already have folded out | |
21522 | any use of .set foo/.type foo %function that may have | |
21523 | been used to set type information of the target location, | |
21524 | that's being specified symbolically. We have to presume | |
21525 | the user knows what they are doing. */ | |
6e7ce2cd PB |
21526 | char name[16 + 8]; |
21527 | symbolS *symbol; | |
21528 | ||
21529 | sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number); | |
21530 | ||
21531 | symbol = symbol_find_or_make (name); | |
21532 | S_SET_SEGMENT (symbol, absolute_section); | |
21533 | symbol_set_frag (symbol, &zero_address_frag); | |
21534 | S_SET_VALUE (symbol, exp->X_add_number); | |
21535 | exp->X_op = O_symbol; | |
21536 | exp->X_add_symbol = symbol; | |
21537 | exp->X_add_number = 0; | |
21538 | } | |
21539 | /* FALLTHROUGH */ | |
5287ad62 JB |
21540 | case O_symbol: |
21541 | case O_add: | |
21542 | case O_subtract: | |
21d799b5 | 21543 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, |
477330fc | 21544 | (enum bfd_reloc_code_real) reloc); |
5287ad62 JB |
21545 | break; |
21546 | ||
21547 | default: | |
21d799b5 | 21548 | new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0, |
477330fc | 21549 | pc_rel, (enum bfd_reloc_code_real) reloc); |
5287ad62 JB |
21550 | break; |
21551 | } | |
21552 | ||
21553 | /* Mark whether the fix is to a THUMB instruction, or an ARM | |
21554 | instruction. */ | |
21555 | new_fix->tc_fix_data = thumb_mode; | |
21556 | } | |
21557 | ||
21558 | /* Create a frg for an instruction requiring relaxation. */ | |
21559 | static void | |
21560 | output_relax_insn (void) | |
21561 | { | |
21562 | char * to; | |
21563 | symbolS *sym; | |
0110f2b8 PB |
21564 | int offset; |
21565 | ||
6e1cb1a6 PB |
21566 | /* The size of the instruction is unknown, so tie the debug info to the |
21567 | start of the instruction. */ | |
21568 | dwarf2_emit_insn (0); | |
6e1cb1a6 | 21569 | |
e2b0ab59 | 21570 | switch (inst.relocs[0].exp.X_op) |
0110f2b8 PB |
21571 | { |
21572 | case O_symbol: | |
e2b0ab59 AV |
21573 | sym = inst.relocs[0].exp.X_add_symbol; |
21574 | offset = inst.relocs[0].exp.X_add_number; | |
0110f2b8 PB |
21575 | break; |
21576 | case O_constant: | |
21577 | sym = NULL; | |
e2b0ab59 | 21578 | offset = inst.relocs[0].exp.X_add_number; |
0110f2b8 PB |
21579 | break; |
21580 | default: | |
e2b0ab59 | 21581 | sym = make_expr_symbol (&inst.relocs[0].exp); |
0110f2b8 PB |
21582 | offset = 0; |
21583 | break; | |
21584 | } | |
21585 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
21586 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
21587 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
0110f2b8 PB |
21588 | } |
21589 | ||
21590 | /* Write a 32-bit thumb instruction to buf. */ | |
21591 | static void | |
21592 | put_thumb32_insn (char * buf, unsigned long insn) | |
21593 | { | |
21594 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
21595 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
21596 | } | |
21597 | ||
b99bd4ef | 21598 | static void |
c19d1205 | 21599 | output_inst (const char * str) |
b99bd4ef | 21600 | { |
c19d1205 | 21601 | char * to = NULL; |
b99bd4ef | 21602 | |
c19d1205 | 21603 | if (inst.error) |
b99bd4ef | 21604 | { |
c19d1205 | 21605 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
21606 | return; |
21607 | } | |
5f4273c7 NC |
21608 | if (inst.relax) |
21609 | { | |
21610 | output_relax_insn (); | |
0110f2b8 | 21611 | return; |
5f4273c7 | 21612 | } |
c19d1205 ZW |
21613 | if (inst.size == 0) |
21614 | return; | |
b99bd4ef | 21615 | |
c19d1205 | 21616 | to = frag_more (inst.size); |
8dc2430f NC |
21617 | /* PR 9814: Record the thumb mode into the current frag so that we know |
21618 | what type of NOP padding to use, if necessary. We override any previous | |
21619 | setting so that if the mode has changed then the NOPS that we use will | |
21620 | match the encoding of the last instruction in the frag. */ | |
cd000bff | 21621 | frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
c19d1205 ZW |
21622 | |
21623 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 21624 | { |
9c2799c2 | 21625 | gas_assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 21626 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 21627 | } |
c19d1205 | 21628 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 21629 | { |
9c2799c2 | 21630 | gas_assert (inst.size == (2 * INSN_SIZE)); |
c19d1205 ZW |
21631 | md_number_to_chars (to, inst.instruction, INSN_SIZE); |
21632 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 21633 | } |
c19d1205 ZW |
21634 | else |
21635 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 21636 | |
e2b0ab59 AV |
21637 | int r; |
21638 | for (r = 0; r < ARM_IT_MAX_RELOCS; r++) | |
21639 | { | |
21640 | if (inst.relocs[r].type != BFD_RELOC_UNUSED) | |
21641 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
21642 | inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel, | |
21643 | inst.relocs[r].type); | |
21644 | } | |
b99bd4ef | 21645 | |
c19d1205 | 21646 | dwarf2_emit_insn (inst.size); |
c19d1205 | 21647 | } |
b99bd4ef | 21648 | |
e07e6e58 NC |
21649 | static char * |
21650 | output_it_inst (int cond, int mask, char * to) | |
21651 | { | |
21652 | unsigned long instruction = 0xbf00; | |
21653 | ||
21654 | mask &= 0xf; | |
21655 | instruction |= mask; | |
21656 | instruction |= cond << 4; | |
21657 | ||
21658 | if (to == NULL) | |
21659 | { | |
21660 | to = frag_more (2); | |
21661 | #ifdef OBJ_ELF | |
21662 | dwarf2_emit_insn (2); | |
21663 | #endif | |
21664 | } | |
21665 | ||
21666 | md_number_to_chars (to, instruction, 2); | |
21667 | ||
21668 | return to; | |
21669 | } | |
21670 | ||
c19d1205 ZW |
21671 | /* Tag values used in struct asm_opcode's tag field. */ |
21672 | enum opcode_tag | |
21673 | { | |
21674 | OT_unconditional, /* Instruction cannot be conditionalized. | |
21675 | The ARM condition field is still 0xE. */ | |
21676 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
21677 | and carries 0xF in its ARM condition field. */ | |
21678 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
5ee91343 AV |
21679 | OT_csuffixF, /* Some forms of the instruction take a scalar |
21680 | conditional suffix, others place 0xF where the | |
21681 | condition field would be, others take a vector | |
21682 | conditional suffix. */ | |
c19d1205 ZW |
21683 | OT_cinfix3, /* Instruction takes a conditional infix, |
21684 | beginning at character index 3. (In | |
21685 | unified mode, it becomes a suffix.) */ | |
088fa78e KH |
21686 | OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for |
21687 | tsts, cmps, cmns, and teqs. */ | |
e3cb604e PB |
21688 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
21689 | character index 3, even in unified mode. Used for | |
21690 | legacy instructions where suffix and infix forms | |
21691 | may be ambiguous. */ | |
c19d1205 | 21692 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 21693 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
21694 | OT_odd_infix_unc, /* This is the unconditional variant of an |
21695 | instruction that takes a conditional infix | |
21696 | at an unusual position. In unified mode, | |
21697 | this variant will accept a suffix. */ | |
21698 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
21699 | are the conditional variants of instructions that | |
21700 | take conditional infixes in unusual positions. | |
21701 | The infix appears at character index | |
21702 | (tag - OT_odd_infix_0). These are not accepted | |
21703 | in unified mode. */ | |
21704 | }; | |
b99bd4ef | 21705 | |
c19d1205 ZW |
21706 | /* Subroutine of md_assemble, responsible for looking up the primary |
21707 | opcode from the mnemonic the user wrote. STR points to the | |
21708 | beginning of the mnemonic. | |
21709 | ||
21710 | This is not simply a hash table lookup, because of conditional | |
21711 | variants. Most instructions have conditional variants, which are | |
21712 | expressed with a _conditional affix_ to the mnemonic. If we were | |
21713 | to encode each conditional variant as a literal string in the opcode | |
21714 | table, it would have approximately 20,000 entries. | |
21715 | ||
21716 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
21717 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
21718 | instructions take the affix as an infix, notably the s-variants of | |
21719 | the arithmetic instructions. Of those instructions, all but six | |
21720 | have the infix appear after the third character of the mnemonic. | |
21721 | ||
21722 | Accordingly, the algorithm for looking up primary opcodes given | |
21723 | an identifier is: | |
21724 | ||
21725 | 1. Look up the identifier in the opcode table. | |
21726 | If we find a match, go to step U. | |
21727 | ||
21728 | 2. Look up the last two characters of the identifier in the | |
21729 | conditions table. If we find a match, look up the first N-2 | |
21730 | characters of the identifier in the opcode table. If we | |
21731 | find a match, go to step CE. | |
21732 | ||
21733 | 3. Look up the fourth and fifth characters of the identifier in | |
21734 | the conditions table. If we find a match, extract those | |
21735 | characters from the identifier, and look up the remaining | |
21736 | characters in the opcode table. If we find a match, go | |
21737 | to step CM. | |
21738 | ||
21739 | 4. Fail. | |
21740 | ||
21741 | U. Examine the tag field of the opcode structure, in case this is | |
21742 | one of the six instructions with its conditional infix in an | |
21743 | unusual place. If it is, the tag tells us where to find the | |
21744 | infix; look it up in the conditions table and set inst.cond | |
21745 | accordingly. Otherwise, this is an unconditional instruction. | |
21746 | Again set inst.cond accordingly. Return the opcode structure. | |
21747 | ||
21748 | CE. Examine the tag field to make sure this is an instruction that | |
21749 | should receive a conditional suffix. If it is not, fail. | |
21750 | Otherwise, set inst.cond from the suffix we already looked up, | |
21751 | and return the opcode structure. | |
21752 | ||
21753 | CM. Examine the tag field to make sure this is an instruction that | |
21754 | should receive a conditional infix after the third character. | |
21755 | If it is not, fail. Otherwise, undo the edits to the current | |
21756 | line of input and proceed as for case CE. */ | |
21757 | ||
21758 | static const struct asm_opcode * | |
21759 | opcode_lookup (char **str) | |
21760 | { | |
21761 | char *end, *base; | |
21762 | char *affix; | |
21763 | const struct asm_opcode *opcode; | |
21764 | const struct asm_cond *cond; | |
e3cb604e | 21765 | char save[2]; |
c19d1205 ZW |
21766 | |
21767 | /* Scan up to the end of the mnemonic, which must end in white space, | |
721a8186 | 21768 | '.' (in unified mode, or for Neon/VFP instructions), or end of string. */ |
c19d1205 | 21769 | for (base = end = *str; *end != '\0'; end++) |
721a8186 | 21770 | if (*end == ' ' || *end == '.') |
c19d1205 | 21771 | break; |
b99bd4ef | 21772 | |
c19d1205 | 21773 | if (end == base) |
c921be7d | 21774 | return NULL; |
b99bd4ef | 21775 | |
5287ad62 | 21776 | /* Handle a possible width suffix and/or Neon type suffix. */ |
c19d1205 | 21777 | if (end[0] == '.') |
b99bd4ef | 21778 | { |
5287ad62 | 21779 | int offset = 2; |
5f4273c7 | 21780 | |
267d2029 | 21781 | /* The .w and .n suffixes are only valid if the unified syntax is in |
477330fc | 21782 | use. */ |
267d2029 | 21783 | if (unified_syntax && end[1] == 'w') |
c19d1205 | 21784 | inst.size_req = 4; |
267d2029 | 21785 | else if (unified_syntax && end[1] == 'n') |
c19d1205 ZW |
21786 | inst.size_req = 2; |
21787 | else | |
477330fc | 21788 | offset = 0; |
5287ad62 JB |
21789 | |
21790 | inst.vectype.elems = 0; | |
21791 | ||
21792 | *str = end + offset; | |
b99bd4ef | 21793 | |
5f4273c7 | 21794 | if (end[offset] == '.') |
5287ad62 | 21795 | { |
267d2029 | 21796 | /* See if we have a Neon type suffix (possible in either unified or |
477330fc RM |
21797 | non-unified ARM syntax mode). */ |
21798 | if (parse_neon_type (&inst.vectype, str) == FAIL) | |
c921be7d | 21799 | return NULL; |
477330fc | 21800 | } |
5287ad62 | 21801 | else if (end[offset] != '\0' && end[offset] != ' ') |
477330fc | 21802 | return NULL; |
b99bd4ef | 21803 | } |
c19d1205 ZW |
21804 | else |
21805 | *str = end; | |
b99bd4ef | 21806 | |
c19d1205 | 21807 | /* Look for unaffixed or special-case affixed mnemonic. */ |
21d799b5 | 21808 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
477330fc | 21809 | end - base); |
c19d1205 | 21810 | if (opcode) |
b99bd4ef | 21811 | { |
c19d1205 ZW |
21812 | /* step U */ |
21813 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 21814 | { |
c19d1205 ZW |
21815 | inst.cond = COND_ALWAYS; |
21816 | return opcode; | |
b99bd4ef | 21817 | } |
b99bd4ef | 21818 | |
278df34e | 21819 | if (warn_on_deprecated && unified_syntax) |
5c3696f8 | 21820 | as_tsktsk (_("conditional infixes are deprecated in unified syntax")); |
c19d1205 | 21821 | affix = base + (opcode->tag - OT_odd_infix_0); |
21d799b5 | 21822 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
9c2799c2 | 21823 | gas_assert (cond); |
b99bd4ef | 21824 | |
c19d1205 ZW |
21825 | inst.cond = cond->value; |
21826 | return opcode; | |
21827 | } | |
5ee91343 AV |
21828 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) |
21829 | { | |
21830 | /* Cannot have a conditional suffix on a mnemonic of less than a character. | |
21831 | */ | |
21832 | if (end - base < 2) | |
21833 | return NULL; | |
21834 | affix = end - 1; | |
21835 | cond = (const struct asm_cond *) hash_find_n (arm_vcond_hsh, affix, 1); | |
21836 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, | |
21837 | affix - base); | |
21838 | /* If this opcode can not be vector predicated then don't accept it with a | |
21839 | vector predication code. */ | |
21840 | if (opcode && !opcode->mayBeVecPred) | |
21841 | opcode = NULL; | |
21842 | } | |
21843 | if (!opcode || !cond) | |
21844 | { | |
21845 | /* Cannot have a conditional suffix on a mnemonic of less than two | |
21846 | characters. */ | |
21847 | if (end - base < 3) | |
21848 | return NULL; | |
b99bd4ef | 21849 | |
5ee91343 AV |
21850 | /* Look for suffixed mnemonic. */ |
21851 | affix = end - 2; | |
21852 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); | |
21853 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, | |
21854 | affix - base); | |
21855 | } | |
b99bd4ef | 21856 | |
c19d1205 ZW |
21857 | if (opcode && cond) |
21858 | { | |
21859 | /* step CE */ | |
21860 | switch (opcode->tag) | |
21861 | { | |
e3cb604e PB |
21862 | case OT_cinfix3_legacy: |
21863 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
21864 | break; | |
21865 | ||
c19d1205 | 21866 | case OT_cinfix3: |
088fa78e | 21867 | case OT_cinfix3_deprecated: |
c19d1205 ZW |
21868 | case OT_odd_infix_unc: |
21869 | if (!unified_syntax) | |
0198d5e6 | 21870 | return NULL; |
1a0670f3 | 21871 | /* Fall through. */ |
c19d1205 ZW |
21872 | |
21873 | case OT_csuffix: | |
477330fc | 21874 | case OT_csuffixF: |
c19d1205 ZW |
21875 | case OT_csuf_or_in3: |
21876 | inst.cond = cond->value; | |
21877 | return opcode; | |
21878 | ||
21879 | case OT_unconditional: | |
21880 | case OT_unconditionalF: | |
dfa9f0d5 | 21881 | if (thumb_mode) |
c921be7d | 21882 | inst.cond = cond->value; |
dfa9f0d5 PB |
21883 | else |
21884 | { | |
c921be7d | 21885 | /* Delayed diagnostic. */ |
dfa9f0d5 PB |
21886 | inst.error = BAD_COND; |
21887 | inst.cond = COND_ALWAYS; | |
21888 | } | |
c19d1205 | 21889 | return opcode; |
b99bd4ef | 21890 | |
c19d1205 | 21891 | default: |
c921be7d | 21892 | return NULL; |
c19d1205 ZW |
21893 | } |
21894 | } | |
b99bd4ef | 21895 | |
c19d1205 ZW |
21896 | /* Cannot have a usual-position infix on a mnemonic of less than |
21897 | six characters (five would be a suffix). */ | |
21898 | if (end - base < 6) | |
c921be7d | 21899 | return NULL; |
b99bd4ef | 21900 | |
c19d1205 ZW |
21901 | /* Look for infixed mnemonic in the usual position. */ |
21902 | affix = base + 3; | |
21d799b5 | 21903 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
e3cb604e | 21904 | if (!cond) |
c921be7d | 21905 | return NULL; |
e3cb604e PB |
21906 | |
21907 | memcpy (save, affix, 2); | |
21908 | memmove (affix, affix + 2, (end - affix) - 2); | |
21d799b5 | 21909 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
477330fc | 21910 | (end - base) - 2); |
e3cb604e PB |
21911 | memmove (affix + 2, affix, (end - affix) - 2); |
21912 | memcpy (affix, save, 2); | |
21913 | ||
088fa78e KH |
21914 | if (opcode |
21915 | && (opcode->tag == OT_cinfix3 | |
21916 | || opcode->tag == OT_cinfix3_deprecated | |
21917 | || opcode->tag == OT_csuf_or_in3 | |
21918 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 21919 | { |
c921be7d | 21920 | /* Step CM. */ |
278df34e | 21921 | if (warn_on_deprecated && unified_syntax |
088fa78e KH |
21922 | && (opcode->tag == OT_cinfix3 |
21923 | || opcode->tag == OT_cinfix3_deprecated)) | |
5c3696f8 | 21924 | as_tsktsk (_("conditional infixes are deprecated in unified syntax")); |
c19d1205 ZW |
21925 | |
21926 | inst.cond = cond->value; | |
21927 | return opcode; | |
b99bd4ef NC |
21928 | } |
21929 | ||
c921be7d | 21930 | return NULL; |
b99bd4ef NC |
21931 | } |
21932 | ||
e07e6e58 NC |
21933 | /* This function generates an initial IT instruction, leaving its block |
21934 | virtually open for the new instructions. Eventually, | |
5ee91343 | 21935 | the mask will be updated by now_pred_add_mask () each time |
e07e6e58 NC |
21936 | a new instruction needs to be included in the IT block. |
21937 | Finally, the block is closed with close_automatic_it_block (). | |
21938 | The block closure can be requested either from md_assemble (), | |
21939 | a tencode (), or due to a label hook. */ | |
21940 | ||
21941 | static void | |
21942 | new_automatic_it_block (int cond) | |
21943 | { | |
5ee91343 AV |
21944 | now_pred.state = AUTOMATIC_PRED_BLOCK; |
21945 | now_pred.mask = 0x18; | |
21946 | now_pred.cc = cond; | |
21947 | now_pred.block_length = 1; | |
cd000bff | 21948 | mapping_state (MAP_THUMB); |
5ee91343 AV |
21949 | now_pred.insn = output_it_inst (cond, now_pred.mask, NULL); |
21950 | now_pred.warn_deprecated = FALSE; | |
21951 | now_pred.insn_cond = TRUE; | |
e07e6e58 NC |
21952 | } |
21953 | ||
21954 | /* Close an automatic IT block. | |
21955 | See comments in new_automatic_it_block (). */ | |
21956 | ||
21957 | static void | |
21958 | close_automatic_it_block (void) | |
21959 | { | |
5ee91343 AV |
21960 | now_pred.mask = 0x10; |
21961 | now_pred.block_length = 0; | |
e07e6e58 NC |
21962 | } |
21963 | ||
21964 | /* Update the mask of the current automatically-generated IT | |
21965 | instruction. See comments in new_automatic_it_block (). */ | |
21966 | ||
21967 | static void | |
5ee91343 | 21968 | now_pred_add_mask (int cond) |
e07e6e58 NC |
21969 | { |
21970 | #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit))) | |
21971 | #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \ | |
477330fc | 21972 | | ((bitvalue) << (nbit))) |
e07e6e58 | 21973 | const int resulting_bit = (cond & 1); |
c921be7d | 21974 | |
5ee91343 AV |
21975 | now_pred.mask &= 0xf; |
21976 | now_pred.mask = SET_BIT_VALUE (now_pred.mask, | |
477330fc | 21977 | resulting_bit, |
5ee91343 AV |
21978 | (5 - now_pred.block_length)); |
21979 | now_pred.mask = SET_BIT_VALUE (now_pred.mask, | |
477330fc | 21980 | 1, |
5ee91343 AV |
21981 | ((5 - now_pred.block_length) - 1)); |
21982 | output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn); | |
e07e6e58 NC |
21983 | |
21984 | #undef CLEAR_BIT | |
21985 | #undef SET_BIT_VALUE | |
e07e6e58 NC |
21986 | } |
21987 | ||
21988 | /* The IT blocks handling machinery is accessed through the these functions: | |
21989 | it_fsm_pre_encode () from md_assemble () | |
5ee91343 AV |
21990 | set_pred_insn_type () optional, from the tencode functions |
21991 | set_pred_insn_type_last () ditto | |
21992 | in_pred_block () ditto | |
e07e6e58 | 21993 | it_fsm_post_encode () from md_assemble () |
33eaf5de | 21994 | force_automatic_it_block_close () from label handling functions |
e07e6e58 NC |
21995 | |
21996 | Rationale: | |
21997 | 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (), | |
477330fc RM |
21998 | initializing the IT insn type with a generic initial value depending |
21999 | on the inst.condition. | |
e07e6e58 | 22000 | 2) During the tencode function, two things may happen: |
477330fc | 22001 | a) The tencode function overrides the IT insn type by |
5ee91343 AV |
22002 | calling either set_pred_insn_type (type) or |
22003 | set_pred_insn_type_last (). | |
477330fc | 22004 | b) The tencode function queries the IT block state by |
5ee91343 | 22005 | calling in_pred_block () (i.e. to determine narrow/not narrow mode). |
477330fc | 22006 | |
5ee91343 AV |
22007 | Both set_pred_insn_type and in_pred_block run the internal FSM state |
22008 | handling function (handle_pred_state), because: a) setting the IT insn | |
477330fc RM |
22009 | type may incur in an invalid state (exiting the function), |
22010 | and b) querying the state requires the FSM to be updated. | |
22011 | Specifically we want to avoid creating an IT block for conditional | |
22012 | branches, so it_fsm_pre_encode is actually a guess and we can't | |
22013 | determine whether an IT block is required until the tencode () routine | |
22014 | has decided what type of instruction this actually it. | |
5ee91343 AV |
22015 | Because of this, if set_pred_insn_type and in_pred_block have to be |
22016 | used, set_pred_insn_type has to be called first. | |
477330fc | 22017 | |
5ee91343 AV |
22018 | set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type), |
22019 | that determines the insn IT type depending on the inst.cond code. | |
477330fc RM |
22020 | When a tencode () routine encodes an instruction that can be |
22021 | either outside an IT block, or, in the case of being inside, has to be | |
5ee91343 | 22022 | the last one, set_pred_insn_type_last () will determine the proper |
477330fc | 22023 | IT instruction type based on the inst.cond code. Otherwise, |
5ee91343 | 22024 | set_pred_insn_type can be called for overriding that logic or |
477330fc RM |
22025 | for covering other cases. |
22026 | ||
5ee91343 AV |
22027 | Calling handle_pred_state () may not transition the IT block state to |
22028 | OUTSIDE_PRED_BLOCK immediately, since the (current) state could be | |
477330fc | 22029 | still queried. Instead, if the FSM determines that the state should |
5ee91343 | 22030 | be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed |
477330fc RM |
22031 | after the tencode () function: that's what it_fsm_post_encode () does. |
22032 | ||
5ee91343 | 22033 | Since in_pred_block () calls the state handling function to get an |
477330fc RM |
22034 | updated state, an error may occur (due to invalid insns combination). |
22035 | In that case, inst.error is set. | |
22036 | Therefore, inst.error has to be checked after the execution of | |
22037 | the tencode () routine. | |
e07e6e58 NC |
22038 | |
22039 | 3) Back in md_assemble(), it_fsm_post_encode () is called to commit | |
477330fc | 22040 | any pending state change (if any) that didn't take place in |
5ee91343 | 22041 | handle_pred_state () as explained above. */ |
e07e6e58 NC |
22042 | |
22043 | static void | |
22044 | it_fsm_pre_encode (void) | |
22045 | { | |
22046 | if (inst.cond != COND_ALWAYS) | |
5ee91343 | 22047 | inst.pred_insn_type = INSIDE_IT_INSN; |
e07e6e58 | 22048 | else |
5ee91343 | 22049 | inst.pred_insn_type = OUTSIDE_PRED_INSN; |
e07e6e58 | 22050 | |
5ee91343 | 22051 | now_pred.state_handled = 0; |
e07e6e58 NC |
22052 | } |
22053 | ||
22054 | /* IT state FSM handling function. */ | |
5ee91343 AV |
22055 | /* MVE instructions and non-MVE instructions are handled differently because of |
22056 | the introduction of VPT blocks. | |
22057 | Specifications say that any non-MVE instruction inside a VPT block is | |
22058 | UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE | |
22059 | instructions are deemed to be UNPREDICTABLE if inside an IT block. For the | |
35c228db | 22060 | few exceptions we have MVE_UNPREDICABLE_INSN. |
5ee91343 AV |
22061 | The error messages provided depending on the different combinations possible |
22062 | are described in the cases below: | |
22063 | For 'most' MVE instructions: | |
22064 | 1) In an IT block, with an IT code: syntax error | |
22065 | 2) In an IT block, with a VPT code: error: must be in a VPT block | |
22066 | 3) In an IT block, with no code: warning: UNPREDICTABLE | |
22067 | 4) In a VPT block, with an IT code: syntax error | |
22068 | 5) In a VPT block, with a VPT code: OK! | |
22069 | 6) In a VPT block, with no code: error: missing code | |
22070 | 7) Outside a pred block, with an IT code: error: syntax error | |
22071 | 8) Outside a pred block, with a VPT code: error: should be in a VPT block | |
22072 | 9) Outside a pred block, with no code: OK! | |
22073 | For non-MVE instructions: | |
22074 | 10) In an IT block, with an IT code: OK! | |
22075 | 11) In an IT block, with a VPT code: syntax error | |
22076 | 12) In an IT block, with no code: error: missing code | |
22077 | 13) In a VPT block, with an IT code: error: should be in an IT block | |
22078 | 14) In a VPT block, with a VPT code: syntax error | |
22079 | 15) In a VPT block, with no code: UNPREDICTABLE | |
22080 | 16) Outside a pred block, with an IT code: error: should be in an IT block | |
22081 | 17) Outside a pred block, with a VPT code: syntax error | |
22082 | 18) Outside a pred block, with no code: OK! | |
22083 | */ | |
22084 | ||
e07e6e58 NC |
22085 | |
22086 | static int | |
5ee91343 | 22087 | handle_pred_state (void) |
e07e6e58 | 22088 | { |
5ee91343 AV |
22089 | now_pred.state_handled = 1; |
22090 | now_pred.insn_cond = FALSE; | |
e07e6e58 | 22091 | |
5ee91343 | 22092 | switch (now_pred.state) |
e07e6e58 | 22093 | { |
5ee91343 AV |
22094 | case OUTSIDE_PRED_BLOCK: |
22095 | switch (inst.pred_insn_type) | |
e07e6e58 | 22096 | { |
35c228db | 22097 | case MVE_UNPREDICABLE_INSN: |
5ee91343 AV |
22098 | case MVE_OUTSIDE_PRED_INSN: |
22099 | if (inst.cond < COND_ALWAYS) | |
22100 | { | |
22101 | /* Case 7: Outside a pred block, with an IT code: error: syntax | |
22102 | error. */ | |
22103 | inst.error = BAD_SYNTAX; | |
22104 | return FAIL; | |
22105 | } | |
22106 | /* Case 9: Outside a pred block, with no code: OK! */ | |
22107 | break; | |
22108 | case OUTSIDE_PRED_INSN: | |
22109 | if (inst.cond > COND_ALWAYS) | |
22110 | { | |
22111 | /* Case 17: Outside a pred block, with a VPT code: syntax error. | |
22112 | */ | |
22113 | inst.error = BAD_SYNTAX; | |
22114 | return FAIL; | |
22115 | } | |
22116 | /* Case 18: Outside a pred block, with no code: OK! */ | |
e07e6e58 NC |
22117 | break; |
22118 | ||
5ee91343 AV |
22119 | case INSIDE_VPT_INSN: |
22120 | /* Case 8: Outside a pred block, with a VPT code: error: should be in | |
22121 | a VPT block. */ | |
22122 | inst.error = BAD_OUT_VPT; | |
22123 | return FAIL; | |
22124 | ||
e07e6e58 NC |
22125 | case INSIDE_IT_INSN: |
22126 | case INSIDE_IT_LAST_INSN: | |
5ee91343 | 22127 | if (inst.cond < COND_ALWAYS) |
e07e6e58 | 22128 | { |
5ee91343 AV |
22129 | /* Case 16: Outside a pred block, with an IT code: error: should |
22130 | be in an IT block. */ | |
22131 | if (thumb_mode == 0) | |
e07e6e58 | 22132 | { |
5ee91343 AV |
22133 | if (unified_syntax |
22134 | && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM)) | |
22135 | as_tsktsk (_("Warning: conditional outside an IT block"\ | |
22136 | " for Thumb.")); | |
e07e6e58 NC |
22137 | } |
22138 | else | |
22139 | { | |
5ee91343 AV |
22140 | if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB) |
22141 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) | |
22142 | { | |
22143 | /* Automatically generate the IT instruction. */ | |
22144 | new_automatic_it_block (inst.cond); | |
22145 | if (inst.pred_insn_type == INSIDE_IT_LAST_INSN) | |
22146 | close_automatic_it_block (); | |
22147 | } | |
22148 | else | |
22149 | { | |
22150 | inst.error = BAD_OUT_IT; | |
22151 | return FAIL; | |
22152 | } | |
e07e6e58 | 22153 | } |
5ee91343 | 22154 | break; |
e07e6e58 | 22155 | } |
5ee91343 AV |
22156 | else if (inst.cond > COND_ALWAYS) |
22157 | { | |
22158 | /* Case 17: Outside a pred block, with a VPT code: syntax error. | |
22159 | */ | |
22160 | inst.error = BAD_SYNTAX; | |
22161 | return FAIL; | |
22162 | } | |
22163 | else | |
22164 | gas_assert (0); | |
e07e6e58 NC |
22165 | case IF_INSIDE_IT_LAST_INSN: |
22166 | case NEUTRAL_IT_INSN: | |
22167 | break; | |
22168 | ||
5ee91343 AV |
22169 | case VPT_INSN: |
22170 | if (inst.cond != COND_ALWAYS) | |
22171 | first_error (BAD_SYNTAX); | |
22172 | now_pred.state = MANUAL_PRED_BLOCK; | |
22173 | now_pred.block_length = 0; | |
22174 | now_pred.type = VECTOR_PRED; | |
22175 | now_pred.cc = 0; | |
22176 | break; | |
e07e6e58 | 22177 | case IT_INSN: |
5ee91343 AV |
22178 | now_pred.state = MANUAL_PRED_BLOCK; |
22179 | now_pred.block_length = 0; | |
22180 | now_pred.type = SCALAR_PRED; | |
e07e6e58 NC |
22181 | break; |
22182 | } | |
22183 | break; | |
22184 | ||
5ee91343 | 22185 | case AUTOMATIC_PRED_BLOCK: |
e07e6e58 NC |
22186 | /* Three things may happen now: |
22187 | a) We should increment current it block size; | |
22188 | b) We should close current it block (closing insn or 4 insns); | |
22189 | c) We should close current it block and start a new one (due | |
22190 | to incompatible conditions or | |
22191 | 4 insns-length block reached). */ | |
22192 | ||
5ee91343 | 22193 | switch (inst.pred_insn_type) |
e07e6e58 | 22194 | { |
5ee91343 AV |
22195 | case INSIDE_VPT_INSN: |
22196 | case VPT_INSN: | |
35c228db | 22197 | case MVE_UNPREDICABLE_INSN: |
5ee91343 AV |
22198 | case MVE_OUTSIDE_PRED_INSN: |
22199 | gas_assert (0); | |
22200 | case OUTSIDE_PRED_INSN: | |
2b0f3761 | 22201 | /* The closure of the block shall happen immediately, |
5ee91343 | 22202 | so any in_pred_block () call reports the block as closed. */ |
e07e6e58 NC |
22203 | force_automatic_it_block_close (); |
22204 | break; | |
22205 | ||
22206 | case INSIDE_IT_INSN: | |
22207 | case INSIDE_IT_LAST_INSN: | |
22208 | case IF_INSIDE_IT_LAST_INSN: | |
5ee91343 | 22209 | now_pred.block_length++; |
e07e6e58 | 22210 | |
5ee91343 AV |
22211 | if (now_pred.block_length > 4 |
22212 | || !now_pred_compatible (inst.cond)) | |
e07e6e58 NC |
22213 | { |
22214 | force_automatic_it_block_close (); | |
5ee91343 | 22215 | if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN) |
e07e6e58 NC |
22216 | new_automatic_it_block (inst.cond); |
22217 | } | |
22218 | else | |
22219 | { | |
5ee91343 AV |
22220 | now_pred.insn_cond = TRUE; |
22221 | now_pred_add_mask (inst.cond); | |
e07e6e58 NC |
22222 | } |
22223 | ||
5ee91343 AV |
22224 | if (now_pred.state == AUTOMATIC_PRED_BLOCK |
22225 | && (inst.pred_insn_type == INSIDE_IT_LAST_INSN | |
22226 | || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN)) | |
e07e6e58 NC |
22227 | close_automatic_it_block (); |
22228 | break; | |
22229 | ||
22230 | case NEUTRAL_IT_INSN: | |
5ee91343 AV |
22231 | now_pred.block_length++; |
22232 | now_pred.insn_cond = TRUE; | |
e07e6e58 | 22233 | |
5ee91343 | 22234 | if (now_pred.block_length > 4) |
e07e6e58 NC |
22235 | force_automatic_it_block_close (); |
22236 | else | |
5ee91343 | 22237 | now_pred_add_mask (now_pred.cc & 1); |
e07e6e58 NC |
22238 | break; |
22239 | ||
22240 | case IT_INSN: | |
22241 | close_automatic_it_block (); | |
5ee91343 | 22242 | now_pred.state = MANUAL_PRED_BLOCK; |
e07e6e58 NC |
22243 | break; |
22244 | } | |
22245 | break; | |
22246 | ||
5ee91343 | 22247 | case MANUAL_PRED_BLOCK: |
e07e6e58 | 22248 | { |
5ee91343 AV |
22249 | int cond, is_last; |
22250 | if (now_pred.type == SCALAR_PRED) | |
e07e6e58 | 22251 | { |
5ee91343 AV |
22252 | /* Check conditional suffixes. */ |
22253 | cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1; | |
22254 | now_pred.mask <<= 1; | |
22255 | now_pred.mask &= 0x1f; | |
22256 | is_last = (now_pred.mask == 0x10); | |
22257 | } | |
22258 | else | |
22259 | { | |
22260 | now_pred.cc ^= (now_pred.mask >> 4); | |
22261 | cond = now_pred.cc + 0xf; | |
22262 | now_pred.mask <<= 1; | |
22263 | now_pred.mask &= 0x1f; | |
22264 | is_last = now_pred.mask == 0x10; | |
22265 | } | |
22266 | now_pred.insn_cond = TRUE; | |
e07e6e58 | 22267 | |
5ee91343 AV |
22268 | switch (inst.pred_insn_type) |
22269 | { | |
22270 | case OUTSIDE_PRED_INSN: | |
22271 | if (now_pred.type == SCALAR_PRED) | |
22272 | { | |
22273 | if (inst.cond == COND_ALWAYS) | |
22274 | { | |
22275 | /* Case 12: In an IT block, with no code: error: missing | |
22276 | code. */ | |
22277 | inst.error = BAD_NOT_IT; | |
22278 | return FAIL; | |
22279 | } | |
22280 | else if (inst.cond > COND_ALWAYS) | |
22281 | { | |
22282 | /* Case 11: In an IT block, with a VPT code: syntax error. | |
22283 | */ | |
22284 | inst.error = BAD_SYNTAX; | |
22285 | return FAIL; | |
22286 | } | |
22287 | else if (thumb_mode) | |
22288 | { | |
22289 | /* This is for some special cases where a non-MVE | |
22290 | instruction is not allowed in an IT block, such as cbz, | |
22291 | but are put into one with a condition code. | |
22292 | You could argue this should be a syntax error, but we | |
22293 | gave the 'not allowed in IT block' diagnostic in the | |
22294 | past so we will keep doing so. */ | |
22295 | inst.error = BAD_NOT_IT; | |
22296 | return FAIL; | |
22297 | } | |
22298 | break; | |
22299 | } | |
22300 | else | |
22301 | { | |
22302 | /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */ | |
22303 | as_tsktsk (MVE_NOT_VPT); | |
22304 | return SUCCESS; | |
22305 | } | |
22306 | case MVE_OUTSIDE_PRED_INSN: | |
22307 | if (now_pred.type == SCALAR_PRED) | |
22308 | { | |
22309 | if (inst.cond == COND_ALWAYS) | |
22310 | { | |
22311 | /* Case 3: In an IT block, with no code: warning: | |
22312 | UNPREDICTABLE. */ | |
22313 | as_tsktsk (MVE_NOT_IT); | |
22314 | return SUCCESS; | |
22315 | } | |
22316 | else if (inst.cond < COND_ALWAYS) | |
22317 | { | |
22318 | /* Case 1: In an IT block, with an IT code: syntax error. | |
22319 | */ | |
22320 | inst.error = BAD_SYNTAX; | |
22321 | return FAIL; | |
22322 | } | |
22323 | else | |
22324 | gas_assert (0); | |
22325 | } | |
22326 | else | |
22327 | { | |
22328 | if (inst.cond < COND_ALWAYS) | |
22329 | { | |
22330 | /* Case 4: In a VPT block, with an IT code: syntax error. | |
22331 | */ | |
22332 | inst.error = BAD_SYNTAX; | |
22333 | return FAIL; | |
22334 | } | |
22335 | else if (inst.cond == COND_ALWAYS) | |
22336 | { | |
22337 | /* Case 6: In a VPT block, with no code: error: missing | |
22338 | code. */ | |
22339 | inst.error = BAD_NOT_VPT; | |
22340 | return FAIL; | |
22341 | } | |
22342 | else | |
22343 | { | |
22344 | gas_assert (0); | |
22345 | } | |
22346 | } | |
35c228db AV |
22347 | case MVE_UNPREDICABLE_INSN: |
22348 | as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT); | |
22349 | return SUCCESS; | |
e07e6e58 | 22350 | case INSIDE_IT_INSN: |
5ee91343 | 22351 | if (inst.cond > COND_ALWAYS) |
e07e6e58 | 22352 | { |
5ee91343 AV |
22353 | /* Case 11: In an IT block, with a VPT code: syntax error. */ |
22354 | /* Case 14: In a VPT block, with a VPT code: syntax error. */ | |
22355 | inst.error = BAD_SYNTAX; | |
22356 | return FAIL; | |
22357 | } | |
22358 | else if (now_pred.type == SCALAR_PRED) | |
22359 | { | |
22360 | /* Case 10: In an IT block, with an IT code: OK! */ | |
22361 | if (cond != inst.cond) | |
22362 | { | |
22363 | inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND : | |
22364 | BAD_VPT_COND; | |
22365 | return FAIL; | |
22366 | } | |
22367 | } | |
22368 | else | |
22369 | { | |
22370 | /* Case 13: In a VPT block, with an IT code: error: should be | |
22371 | in an IT block. */ | |
22372 | inst.error = BAD_OUT_IT; | |
e07e6e58 NC |
22373 | return FAIL; |
22374 | } | |
22375 | break; | |
22376 | ||
5ee91343 AV |
22377 | case INSIDE_VPT_INSN: |
22378 | if (now_pred.type == SCALAR_PRED) | |
22379 | { | |
22380 | /* Case 2: In an IT block, with a VPT code: error: must be in a | |
22381 | VPT block. */ | |
22382 | inst.error = BAD_OUT_VPT; | |
22383 | return FAIL; | |
22384 | } | |
22385 | /* Case 5: In a VPT block, with a VPT code: OK! */ | |
22386 | else if (cond != inst.cond) | |
22387 | { | |
22388 | inst.error = BAD_VPT_COND; | |
22389 | return FAIL; | |
22390 | } | |
22391 | break; | |
e07e6e58 NC |
22392 | case INSIDE_IT_LAST_INSN: |
22393 | case IF_INSIDE_IT_LAST_INSN: | |
5ee91343 AV |
22394 | if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS) |
22395 | { | |
22396 | /* Case 4: In a VPT block, with an IT code: syntax error. */ | |
22397 | /* Case 11: In an IT block, with a VPT code: syntax error. */ | |
22398 | inst.error = BAD_SYNTAX; | |
22399 | return FAIL; | |
22400 | } | |
22401 | else if (cond != inst.cond) | |
e07e6e58 NC |
22402 | { |
22403 | inst.error = BAD_IT_COND; | |
22404 | return FAIL; | |
22405 | } | |
22406 | if (!is_last) | |
22407 | { | |
22408 | inst.error = BAD_BRANCH; | |
22409 | return FAIL; | |
22410 | } | |
22411 | break; | |
22412 | ||
22413 | case NEUTRAL_IT_INSN: | |
5ee91343 AV |
22414 | /* The BKPT instruction is unconditional even in a IT or VPT |
22415 | block. */ | |
e07e6e58 NC |
22416 | break; |
22417 | ||
22418 | case IT_INSN: | |
5ee91343 AV |
22419 | if (now_pred.type == SCALAR_PRED) |
22420 | { | |
22421 | inst.error = BAD_IT_IT; | |
22422 | return FAIL; | |
22423 | } | |
22424 | /* fall through. */ | |
22425 | case VPT_INSN: | |
22426 | if (inst.cond == COND_ALWAYS) | |
22427 | { | |
22428 | /* Executing a VPT/VPST instruction inside an IT block or a | |
22429 | VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE. | |
22430 | */ | |
22431 | if (now_pred.type == SCALAR_PRED) | |
22432 | as_tsktsk (MVE_NOT_IT); | |
22433 | else | |
22434 | as_tsktsk (MVE_NOT_VPT); | |
22435 | return SUCCESS; | |
22436 | } | |
22437 | else | |
22438 | { | |
22439 | /* VPT/VPST do not accept condition codes. */ | |
22440 | inst.error = BAD_SYNTAX; | |
22441 | return FAIL; | |
22442 | } | |
e07e6e58 | 22443 | } |
5ee91343 | 22444 | } |
e07e6e58 NC |
22445 | break; |
22446 | } | |
22447 | ||
22448 | return SUCCESS; | |
22449 | } | |
22450 | ||
5a01bb1d MGD |
22451 | struct depr_insn_mask |
22452 | { | |
22453 | unsigned long pattern; | |
22454 | unsigned long mask; | |
22455 | const char* description; | |
22456 | }; | |
22457 | ||
22458 | /* List of 16-bit instruction patterns deprecated in an IT block in | |
22459 | ARMv8. */ | |
22460 | static const struct depr_insn_mask depr_it_insns[] = { | |
22461 | { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") }, | |
22462 | { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") }, | |
22463 | { 0xa000, 0xb800, N_("ADR") }, | |
22464 | { 0x4800, 0xf800, N_("Literal loads") }, | |
22465 | { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") }, | |
22466 | { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") }, | |
c8de034b JW |
22467 | /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue' |
22468 | field in asm_opcode. 'tvalue' is used at the stage this check happen. */ | |
22469 | { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") }, | |
5a01bb1d MGD |
22470 | { 0, 0, NULL } |
22471 | }; | |
22472 | ||
e07e6e58 NC |
22473 | static void |
22474 | it_fsm_post_encode (void) | |
22475 | { | |
22476 | int is_last; | |
22477 | ||
5ee91343 AV |
22478 | if (!now_pred.state_handled) |
22479 | handle_pred_state (); | |
e07e6e58 | 22480 | |
5ee91343 AV |
22481 | if (now_pred.insn_cond |
22482 | && !now_pred.warn_deprecated | |
5a01bb1d | 22483 | && warn_on_deprecated |
df9909b8 TP |
22484 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8) |
22485 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m)) | |
5a01bb1d MGD |
22486 | { |
22487 | if (inst.instruction >= 0x10000) | |
22488 | { | |
5c3696f8 | 22489 | as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are " |
df9909b8 | 22490 | "performance deprecated in ARMv8-A and ARMv8-R")); |
5ee91343 | 22491 | now_pred.warn_deprecated = TRUE; |
5a01bb1d MGD |
22492 | } |
22493 | else | |
22494 | { | |
22495 | const struct depr_insn_mask *p = depr_it_insns; | |
22496 | ||
22497 | while (p->mask != 0) | |
22498 | { | |
22499 | if ((inst.instruction & p->mask) == p->pattern) | |
22500 | { | |
df9909b8 TP |
22501 | as_tsktsk (_("IT blocks containing 16-bit Thumb " |
22502 | "instructions of the following class are " | |
22503 | "performance deprecated in ARMv8-A and " | |
22504 | "ARMv8-R: %s"), p->description); | |
5ee91343 | 22505 | now_pred.warn_deprecated = TRUE; |
5a01bb1d MGD |
22506 | break; |
22507 | } | |
22508 | ||
22509 | ++p; | |
22510 | } | |
22511 | } | |
22512 | ||
5ee91343 | 22513 | if (now_pred.block_length > 1) |
5a01bb1d | 22514 | { |
5c3696f8 | 22515 | as_tsktsk (_("IT blocks containing more than one conditional " |
df9909b8 TP |
22516 | "instruction are performance deprecated in ARMv8-A and " |
22517 | "ARMv8-R")); | |
5ee91343 | 22518 | now_pred.warn_deprecated = TRUE; |
5a01bb1d MGD |
22519 | } |
22520 | } | |
22521 | ||
5ee91343 AV |
22522 | is_last = (now_pred.mask == 0x10); |
22523 | if (is_last) | |
22524 | { | |
22525 | now_pred.state = OUTSIDE_PRED_BLOCK; | |
22526 | now_pred.mask = 0; | |
22527 | } | |
e07e6e58 NC |
22528 | } |
22529 | ||
22530 | static void | |
22531 | force_automatic_it_block_close (void) | |
22532 | { | |
5ee91343 | 22533 | if (now_pred.state == AUTOMATIC_PRED_BLOCK) |
e07e6e58 NC |
22534 | { |
22535 | close_automatic_it_block (); | |
5ee91343 AV |
22536 | now_pred.state = OUTSIDE_PRED_BLOCK; |
22537 | now_pred.mask = 0; | |
e07e6e58 NC |
22538 | } |
22539 | } | |
22540 | ||
22541 | static int | |
5ee91343 | 22542 | in_pred_block (void) |
e07e6e58 | 22543 | { |
5ee91343 AV |
22544 | if (!now_pred.state_handled) |
22545 | handle_pred_state (); | |
e07e6e58 | 22546 | |
5ee91343 | 22547 | return now_pred.state != OUTSIDE_PRED_BLOCK; |
e07e6e58 NC |
22548 | } |
22549 | ||
ff8646ee TP |
22550 | /* Whether OPCODE only has T32 encoding. Since this function is only used by |
22551 | t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed | |
22552 | here, hence the "known" in the function name. */ | |
fc289b0a TP |
22553 | |
22554 | static bfd_boolean | |
ff8646ee | 22555 | known_t32_only_insn (const struct asm_opcode *opcode) |
fc289b0a TP |
22556 | { |
22557 | /* Original Thumb-1 wide instruction. */ | |
22558 | if (opcode->tencode == do_t_blx | |
22559 | || opcode->tencode == do_t_branch23 | |
22560 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr) | |
22561 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)) | |
22562 | return TRUE; | |
22563 | ||
16a1fa25 TP |
22564 | /* Wide-only instruction added to ARMv8-M Baseline. */ |
22565 | if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only) | |
ff8646ee TP |
22566 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics) |
22567 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m) | |
22568 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div)) | |
22569 | return TRUE; | |
22570 | ||
22571 | return FALSE; | |
22572 | } | |
22573 | ||
22574 | /* Whether wide instruction variant can be used if available for a valid OPCODE | |
22575 | in ARCH. */ | |
22576 | ||
22577 | static bfd_boolean | |
22578 | t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode) | |
22579 | { | |
22580 | if (known_t32_only_insn (opcode)) | |
22581 | return TRUE; | |
22582 | ||
22583 | /* Instruction with narrow and wide encoding added to ARMv8-M. Availability | |
22584 | of variant T3 of B.W is checked in do_t_branch. */ | |
22585 | if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m) | |
22586 | && opcode->tencode == do_t_branch) | |
22587 | return TRUE; | |
22588 | ||
bada4342 JW |
22589 | /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */ |
22590 | if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m) | |
22591 | && opcode->tencode == do_t_mov_cmp | |
22592 | /* Make sure CMP instruction is not affected. */ | |
22593 | && opcode->aencode == do_mov) | |
22594 | return TRUE; | |
22595 | ||
ff8646ee TP |
22596 | /* Wide instruction variants of all instructions with narrow *and* wide |
22597 | variants become available with ARMv6t2. Other opcodes are either | |
22598 | narrow-only or wide-only and are thus available if OPCODE is valid. */ | |
22599 | if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2)) | |
22600 | return TRUE; | |
22601 | ||
22602 | /* OPCODE with narrow only instruction variant or wide variant not | |
22603 | available. */ | |
fc289b0a TP |
22604 | return FALSE; |
22605 | } | |
22606 | ||
c19d1205 ZW |
22607 | void |
22608 | md_assemble (char *str) | |
b99bd4ef | 22609 | { |
c19d1205 ZW |
22610 | char *p = str; |
22611 | const struct asm_opcode * opcode; | |
b99bd4ef | 22612 | |
c19d1205 ZW |
22613 | /* Align the previous label if needed. */ |
22614 | if (last_label_seen != NULL) | |
b99bd4ef | 22615 | { |
c19d1205 ZW |
22616 | symbol_set_frag (last_label_seen, frag_now); |
22617 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
22618 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
22619 | } |
22620 | ||
c19d1205 | 22621 | memset (&inst, '\0', sizeof (inst)); |
e2b0ab59 AV |
22622 | int r; |
22623 | for (r = 0; r < ARM_IT_MAX_RELOCS; r++) | |
22624 | inst.relocs[r].type = BFD_RELOC_UNUSED; | |
b99bd4ef | 22625 | |
c19d1205 ZW |
22626 | opcode = opcode_lookup (&p); |
22627 | if (!opcode) | |
b99bd4ef | 22628 | { |
c19d1205 | 22629 | /* It wasn't an instruction, but it might be a register alias of |
dcbf9037 | 22630 | the form alias .req reg, or a Neon .dn/.qn directive. */ |
c921be7d | 22631 | if (! create_register_alias (str, p) |
477330fc | 22632 | && ! create_neon_reg_alias (str, p)) |
c19d1205 | 22633 | as_bad (_("bad instruction `%s'"), str); |
b99bd4ef | 22634 | |
b99bd4ef NC |
22635 | return; |
22636 | } | |
22637 | ||
278df34e | 22638 | if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated) |
5c3696f8 | 22639 | as_tsktsk (_("s suffix on comparison instruction is deprecated")); |
088fa78e | 22640 | |
037e8744 JB |
22641 | /* The value which unconditional instructions should have in place of the |
22642 | condition field. */ | |
22643 | inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1; | |
22644 | ||
c19d1205 | 22645 | if (thumb_mode) |
b99bd4ef | 22646 | { |
e74cfd16 | 22647 | arm_feature_set variant; |
8f06b2d8 PB |
22648 | |
22649 | variant = cpu_variant; | |
22650 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
22651 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
22652 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 22653 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
22654 | if (!opcode->tvariant |
22655 | || (thumb_mode == 1 | |
22656 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 22657 | { |
173205ca TP |
22658 | if (opcode->tencode == do_t_swi) |
22659 | as_bad (_("SVC is not permitted on this architecture")); | |
22660 | else | |
22661 | as_bad (_("selected processor does not support `%s' in Thumb mode"), str); | |
b99bd4ef NC |
22662 | return; |
22663 | } | |
c19d1205 ZW |
22664 | if (inst.cond != COND_ALWAYS && !unified_syntax |
22665 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 22666 | { |
c19d1205 | 22667 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
22668 | return; |
22669 | } | |
22670 | ||
fc289b0a TP |
22671 | /* Two things are addressed here: |
22672 | 1) Implicit require narrow instructions on Thumb-1. | |
22673 | This avoids relaxation accidentally introducing Thumb-2 | |
22674 | instructions. | |
22675 | 2) Reject wide instructions in non Thumb-2 cores. | |
22676 | ||
22677 | Only instructions with narrow and wide variants need to be handled | |
22678 | but selecting all non wide-only instructions is easier. */ | |
22679 | if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) | |
ff8646ee | 22680 | && !t32_insn_ok (variant, opcode)) |
076d447c | 22681 | { |
fc289b0a TP |
22682 | if (inst.size_req == 0) |
22683 | inst.size_req = 2; | |
22684 | else if (inst.size_req == 4) | |
752d5da4 | 22685 | { |
ff8646ee TP |
22686 | if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m)) |
22687 | as_bad (_("selected processor does not support 32bit wide " | |
22688 | "variant of instruction `%s'"), str); | |
22689 | else | |
22690 | as_bad (_("selected processor does not support `%s' in " | |
22691 | "Thumb-2 mode"), str); | |
fc289b0a | 22692 | return; |
752d5da4 | 22693 | } |
076d447c PB |
22694 | } |
22695 | ||
c19d1205 ZW |
22696 | inst.instruction = opcode->tvalue; |
22697 | ||
5be8be5d | 22698 | if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE)) |
477330fc | 22699 | { |
5ee91343 | 22700 | /* Prepare the pred_insn_type for those encodings that don't set |
477330fc RM |
22701 | it. */ |
22702 | it_fsm_pre_encode (); | |
c19d1205 | 22703 | |
477330fc | 22704 | opcode->tencode (); |
e07e6e58 | 22705 | |
477330fc RM |
22706 | it_fsm_post_encode (); |
22707 | } | |
e27ec89e | 22708 | |
0110f2b8 | 22709 | if (!(inst.error || inst.relax)) |
b99bd4ef | 22710 | { |
9c2799c2 | 22711 | gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
c19d1205 ZW |
22712 | inst.size = (inst.instruction > 0xffff ? 4 : 2); |
22713 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 22714 | { |
c19d1205 | 22715 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
22716 | return; |
22717 | } | |
22718 | } | |
076d447c PB |
22719 | |
22720 | /* Something has gone badly wrong if we try to relax a fixed size | |
477330fc | 22721 | instruction. */ |
9c2799c2 | 22722 | gas_assert (inst.size_req == 0 || !inst.relax); |
076d447c | 22723 | |
e74cfd16 PB |
22724 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
22725 | *opcode->tvariant); | |
ee065d83 | 22726 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
fc289b0a TP |
22727 | set those bits when Thumb-2 32-bit instructions are seen. The impact |
22728 | of relaxable instructions will be considered later after we finish all | |
22729 | relaxation. */ | |
ff8646ee TP |
22730 | if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any)) |
22731 | variant = arm_arch_none; | |
22732 | else | |
22733 | variant = cpu_variant; | |
22734 | if (inst.size == 4 && !t32_insn_ok (variant, opcode)) | |
e74cfd16 PB |
22735 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
22736 | arm_ext_v6t2); | |
cd000bff | 22737 | |
88714cb8 DG |
22738 | check_neon_suffixes; |
22739 | ||
cd000bff | 22740 | if (!inst.error) |
c877a2f2 NC |
22741 | { |
22742 | mapping_state (MAP_THUMB); | |
22743 | } | |
c19d1205 | 22744 | } |
3e9e4fcf | 22745 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 | 22746 | { |
845b51d6 PB |
22747 | bfd_boolean is_bx; |
22748 | ||
22749 | /* bx is allowed on v5 cores, and sometimes on v4 cores. */ | |
22750 | is_bx = (opcode->aencode == do_bx); | |
22751 | ||
c19d1205 | 22752 | /* Check that this instruction is supported for this CPU. */ |
845b51d6 PB |
22753 | if (!(is_bx && fix_v4bx) |
22754 | && !(opcode->avariant && | |
22755 | ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))) | |
b99bd4ef | 22756 | { |
84b52b66 | 22757 | as_bad (_("selected processor does not support `%s' in ARM mode"), str); |
c19d1205 | 22758 | return; |
b99bd4ef | 22759 | } |
c19d1205 | 22760 | if (inst.size_req) |
b99bd4ef | 22761 | { |
c19d1205 ZW |
22762 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
22763 | return; | |
b99bd4ef NC |
22764 | } |
22765 | ||
c19d1205 ZW |
22766 | inst.instruction = opcode->avalue; |
22767 | if (opcode->tag == OT_unconditionalF) | |
eff0bc54 | 22768 | inst.instruction |= 0xFU << 28; |
c19d1205 ZW |
22769 | else |
22770 | inst.instruction |= inst.cond << 28; | |
22771 | inst.size = INSN_SIZE; | |
5be8be5d | 22772 | if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE)) |
477330fc RM |
22773 | { |
22774 | it_fsm_pre_encode (); | |
22775 | opcode->aencode (); | |
22776 | it_fsm_post_encode (); | |
22777 | } | |
ee065d83 | 22778 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
477330fc | 22779 | on a hypothetical non-thumb v5 core. */ |
845b51d6 | 22780 | if (is_bx) |
e74cfd16 | 22781 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); |
ee065d83 | 22782 | else |
e74cfd16 PB |
22783 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
22784 | *opcode->avariant); | |
88714cb8 DG |
22785 | |
22786 | check_neon_suffixes; | |
22787 | ||
cd000bff | 22788 | if (!inst.error) |
c877a2f2 NC |
22789 | { |
22790 | mapping_state (MAP_ARM); | |
22791 | } | |
b99bd4ef | 22792 | } |
3e9e4fcf JB |
22793 | else |
22794 | { | |
22795 | as_bad (_("attempt to use an ARM instruction on a Thumb-only processor " | |
22796 | "-- `%s'"), str); | |
22797 | return; | |
22798 | } | |
c19d1205 ZW |
22799 | output_inst (str); |
22800 | } | |
b99bd4ef | 22801 | |
e07e6e58 | 22802 | static void |
5ee91343 | 22803 | check_pred_blocks_finished (void) |
e07e6e58 NC |
22804 | { |
22805 | #ifdef OBJ_ELF | |
22806 | asection *sect; | |
22807 | ||
22808 | for (sect = stdoutput->sections; sect != NULL; sect = sect->next) | |
5ee91343 AV |
22809 | if (seg_info (sect)->tc_segment_info_data.current_pred.state |
22810 | == MANUAL_PRED_BLOCK) | |
e07e6e58 | 22811 | { |
5ee91343 AV |
22812 | if (now_pred.type == SCALAR_PRED) |
22813 | as_warn (_("section '%s' finished with an open IT block."), | |
22814 | sect->name); | |
22815 | else | |
22816 | as_warn (_("section '%s' finished with an open VPT/VPST block."), | |
22817 | sect->name); | |
e07e6e58 NC |
22818 | } |
22819 | #else | |
5ee91343 AV |
22820 | if (now_pred.state == MANUAL_PRED_BLOCK) |
22821 | { | |
22822 | if (now_pred.type == SCALAR_PRED) | |
22823 | as_warn (_("file finished with an open IT block.")); | |
22824 | else | |
22825 | as_warn (_("file finished with an open VPT/VPST block.")); | |
22826 | } | |
e07e6e58 NC |
22827 | #endif |
22828 | } | |
22829 | ||
c19d1205 ZW |
22830 | /* Various frobbings of labels and their addresses. */ |
22831 | ||
22832 | void | |
22833 | arm_start_line_hook (void) | |
22834 | { | |
22835 | last_label_seen = NULL; | |
b99bd4ef NC |
22836 | } |
22837 | ||
c19d1205 ZW |
22838 | void |
22839 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 22840 | { |
c19d1205 | 22841 | last_label_seen = sym; |
b99bd4ef | 22842 | |
c19d1205 | 22843 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 22844 | |
c19d1205 ZW |
22845 | #if defined OBJ_COFF || defined OBJ_ELF |
22846 | ARM_SET_INTERWORK (sym, support_interwork); | |
22847 | #endif | |
b99bd4ef | 22848 | |
e07e6e58 NC |
22849 | force_automatic_it_block_close (); |
22850 | ||
5f4273c7 | 22851 | /* Note - do not allow local symbols (.Lxxx) to be labelled |
c19d1205 ZW |
22852 | as Thumb functions. This is because these labels, whilst |
22853 | they exist inside Thumb code, are not the entry points for | |
22854 | possible ARM->Thumb calls. Also, these labels can be used | |
22855 | as part of a computed goto or switch statement. eg gcc | |
22856 | can generate code that looks like this: | |
b99bd4ef | 22857 | |
c19d1205 ZW |
22858 | ldr r2, [pc, .Laaa] |
22859 | lsl r3, r3, #2 | |
22860 | ldr r2, [r3, r2] | |
22861 | mov pc, r2 | |
b99bd4ef | 22862 | |
c19d1205 ZW |
22863 | .Lbbb: .word .Lxxx |
22864 | .Lccc: .word .Lyyy | |
22865 | ..etc... | |
22866 | .Laaa: .word Lbbb | |
b99bd4ef | 22867 | |
c19d1205 ZW |
22868 | The first instruction loads the address of the jump table. |
22869 | The second instruction converts a table index into a byte offset. | |
22870 | The third instruction gets the jump address out of the table. | |
22871 | The fourth instruction performs the jump. | |
b99bd4ef | 22872 | |
c19d1205 ZW |
22873 | If the address stored at .Laaa is that of a symbol which has the |
22874 | Thumb_Func bit set, then the linker will arrange for this address | |
22875 | to have the bottom bit set, which in turn would mean that the | |
22876 | address computation performed by the third instruction would end | |
22877 | up with the bottom bit set. Since the ARM is capable of unaligned | |
22878 | word loads, the instruction would then load the incorrect address | |
22879 | out of the jump table, and chaos would ensue. */ | |
22880 | if (label_is_thumb_function_name | |
22881 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
fd361982 | 22882 | && (bfd_section_flags (now_seg) & SEC_CODE) != 0) |
b99bd4ef | 22883 | { |
c19d1205 ZW |
22884 | /* When the address of a Thumb function is taken the bottom |
22885 | bit of that address should be set. This will allow | |
22886 | interworking between Arm and Thumb functions to work | |
22887 | correctly. */ | |
b99bd4ef | 22888 | |
c19d1205 | 22889 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 22890 | |
c19d1205 | 22891 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 22892 | } |
07a53e5c | 22893 | |
07a53e5c | 22894 | dwarf2_emit_label (sym); |
b99bd4ef NC |
22895 | } |
22896 | ||
c921be7d | 22897 | bfd_boolean |
c19d1205 | 22898 | arm_data_in_code (void) |
b99bd4ef | 22899 | { |
c19d1205 | 22900 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 22901 | { |
c19d1205 ZW |
22902 | *input_line_pointer = '/'; |
22903 | input_line_pointer += 5; | |
22904 | *input_line_pointer = 0; | |
c921be7d | 22905 | return TRUE; |
b99bd4ef NC |
22906 | } |
22907 | ||
c921be7d | 22908 | return FALSE; |
b99bd4ef NC |
22909 | } |
22910 | ||
c19d1205 ZW |
22911 | char * |
22912 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 22913 | { |
c19d1205 | 22914 | int len; |
b99bd4ef | 22915 | |
c19d1205 ZW |
22916 | if (thumb_mode && (len = strlen (name)) > 5 |
22917 | && streq (name + len - 5, "/data")) | |
22918 | *(name + len - 5) = 0; | |
b99bd4ef | 22919 | |
c19d1205 | 22920 | return name; |
b99bd4ef | 22921 | } |
c19d1205 ZW |
22922 | \f |
22923 | /* Table of all register names defined by default. The user can | |
22924 | define additional names with .req. Note that all register names | |
22925 | should appear in both upper and lowercase variants. Some registers | |
22926 | also have mixed-case names. */ | |
b99bd4ef | 22927 | |
dcbf9037 | 22928 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 } |
c19d1205 | 22929 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 22930 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
22931 | #define REGSET(p,t) \ |
22932 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
22933 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
22934 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
22935 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
5287ad62 JB |
22936 | #define REGSETH(p,t) \ |
22937 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ | |
22938 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
22939 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
22940 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t) | |
22941 | #define REGSET2(p,t) \ | |
22942 | REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \ | |
22943 | REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \ | |
22944 | REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \ | |
22945 | REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t) | |
90ec0d68 MGD |
22946 | #define SPLRBANK(base,bank,t) \ |
22947 | REGDEF(lr_##bank, 768|((base+0)<<16), t), \ | |
22948 | REGDEF(sp_##bank, 768|((base+1)<<16), t), \ | |
22949 | REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \ | |
22950 | REGDEF(LR_##bank, 768|((base+0)<<16), t), \ | |
22951 | REGDEF(SP_##bank, 768|((base+1)<<16), t), \ | |
22952 | REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t) | |
7ed4c4c5 | 22953 | |
c19d1205 | 22954 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 22955 | { |
c19d1205 ZW |
22956 | /* ARM integer registers. */ |
22957 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 22958 | |
c19d1205 ZW |
22959 | /* ATPCS synonyms. */ |
22960 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
22961 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
22962 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 22963 | |
c19d1205 ZW |
22964 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
22965 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
22966 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 22967 | |
c19d1205 ZW |
22968 | /* Well-known aliases. */ |
22969 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
22970 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
22971 | ||
22972 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
22973 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
22974 | ||
1b883319 AV |
22975 | /* Defining the new Zero register from ARMv8.1-M. */ |
22976 | REGDEF(zr,15,ZR), | |
22977 | REGDEF(ZR,15,ZR), | |
22978 | ||
c19d1205 ZW |
22979 | /* Coprocessor numbers. */ |
22980 | REGSET(p, CP), REGSET(P, CP), | |
22981 | ||
22982 | /* Coprocessor register numbers. The "cr" variants are for backward | |
22983 | compatibility. */ | |
22984 | REGSET(c, CN), REGSET(C, CN), | |
22985 | REGSET(cr, CN), REGSET(CR, CN), | |
22986 | ||
90ec0d68 MGD |
22987 | /* ARM banked registers. */ |
22988 | REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB), | |
22989 | REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB), | |
22990 | REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB), | |
22991 | REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB), | |
22992 | REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB), | |
22993 | REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB), | |
22994 | REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB), | |
22995 | ||
22996 | REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB), | |
22997 | REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB), | |
22998 | REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB), | |
22999 | REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB), | |
23000 | REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB), | |
1472d06f | 23001 | REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB), |
90ec0d68 MGD |
23002 | REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB), |
23003 | REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB), | |
23004 | ||
23005 | SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB), | |
23006 | SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB), | |
23007 | SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB), | |
23008 | SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB), | |
23009 | SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB), | |
23010 | REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB), | |
23011 | REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB), | |
fa94de6b | 23012 | REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB), |
90ec0d68 MGD |
23013 | REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB), |
23014 | ||
c19d1205 ZW |
23015 | /* FPA registers. */ |
23016 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
23017 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
23018 | ||
23019 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
23020 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
23021 | ||
23022 | /* VFP SP registers. */ | |
5287ad62 JB |
23023 | REGSET(s,VFS), REGSET(S,VFS), |
23024 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
23025 | |
23026 | /* VFP DP Registers. */ | |
5287ad62 JB |
23027 | REGSET(d,VFD), REGSET(D,VFD), |
23028 | /* Extra Neon DP registers. */ | |
23029 | REGSETH(d,VFD), REGSETH(D,VFD), | |
23030 | ||
23031 | /* Neon QP registers. */ | |
23032 | REGSET2(q,NQ), REGSET2(Q,NQ), | |
c19d1205 ZW |
23033 | |
23034 | /* VFP control registers. */ | |
23035 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
23036 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
cd2cf30b PB |
23037 | REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC), |
23038 | REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC), | |
23039 | REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC), | |
23040 | REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC), | |
40c7d507 | 23041 | REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC), |
ba6cd17f SD |
23042 | REGDEF(fpscr_nzcvqc,2,VFC), REGDEF(FPSCR_nzcvqc,2,VFC), |
23043 | REGDEF(vpr,12,VFC), REGDEF(VPR,12,VFC), | |
23044 | REGDEF(fpcxt_ns,14,VFC), REGDEF(FPCXT_NS,14,VFC), | |
23045 | REGDEF(fpcxt_s,15,VFC), REGDEF(FPCXT_S,15,VFC), | |
c19d1205 ZW |
23046 | |
23047 | /* Maverick DSP coprocessor registers. */ | |
23048 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
23049 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
23050 | ||
23051 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
23052 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
23053 | REGDEF(dspsc,0,DSPSC), | |
23054 | ||
23055 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
23056 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
23057 | REGDEF(DSPSC,0,DSPSC), | |
23058 | ||
23059 | /* iWMMXt data registers - p0, c0-15. */ | |
23060 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
23061 | ||
23062 | /* iWMMXt control registers - p1, c0-3. */ | |
23063 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
23064 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
23065 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
23066 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
23067 | ||
23068 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
23069 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
23070 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
23071 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
23072 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
23073 | ||
23074 | /* XScale accumulator registers. */ | |
23075 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
23076 | }; | |
23077 | #undef REGDEF | |
23078 | #undef REGNUM | |
23079 | #undef REGSET | |
7ed4c4c5 | 23080 | |
c19d1205 ZW |
23081 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
23082 | within psr_required_here. */ | |
23083 | static const struct asm_psr psrs[] = | |
23084 | { | |
23085 | /* Backward compatibility notation. Note that "all" is no longer | |
23086 | truly all possible PSR bits. */ | |
23087 | {"all", PSR_c | PSR_f}, | |
23088 | {"flg", PSR_f}, | |
23089 | {"ctl", PSR_c}, | |
23090 | ||
23091 | /* Individual flags. */ | |
23092 | {"f", PSR_f}, | |
23093 | {"c", PSR_c}, | |
23094 | {"x", PSR_x}, | |
23095 | {"s", PSR_s}, | |
59b42a0d | 23096 | |
c19d1205 ZW |
23097 | /* Combinations of flags. */ |
23098 | {"fs", PSR_f | PSR_s}, | |
23099 | {"fx", PSR_f | PSR_x}, | |
23100 | {"fc", PSR_f | PSR_c}, | |
23101 | {"sf", PSR_s | PSR_f}, | |
23102 | {"sx", PSR_s | PSR_x}, | |
23103 | {"sc", PSR_s | PSR_c}, | |
23104 | {"xf", PSR_x | PSR_f}, | |
23105 | {"xs", PSR_x | PSR_s}, | |
23106 | {"xc", PSR_x | PSR_c}, | |
23107 | {"cf", PSR_c | PSR_f}, | |
23108 | {"cs", PSR_c | PSR_s}, | |
23109 | {"cx", PSR_c | PSR_x}, | |
23110 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
23111 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
23112 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
23113 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
23114 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
23115 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
23116 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
23117 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
23118 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
23119 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
23120 | {"scf", PSR_s | PSR_c | PSR_f}, | |
23121 | {"scx", PSR_s | PSR_c | PSR_x}, | |
23122 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
23123 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
23124 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
23125 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
23126 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
23127 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
23128 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
23129 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
23130 | {"csf", PSR_c | PSR_s | PSR_f}, | |
23131 | {"csx", PSR_c | PSR_s | PSR_x}, | |
23132 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
23133 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
23134 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
23135 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
23136 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
23137 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
23138 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
23139 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
23140 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
23141 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
23142 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
23143 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
23144 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
23145 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
23146 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
23147 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
23148 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
23149 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
23150 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
23151 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
23152 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
23153 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
23154 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
23155 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
23156 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
23157 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
23158 | }; | |
23159 | ||
62b3e311 PB |
23160 | /* Table of V7M psr names. */ |
23161 | static const struct asm_psr v7m_psrs[] = | |
23162 | { | |
1a336194 TP |
23163 | {"apsr", 0x0 }, {"APSR", 0x0 }, |
23164 | {"iapsr", 0x1 }, {"IAPSR", 0x1 }, | |
23165 | {"eapsr", 0x2 }, {"EAPSR", 0x2 }, | |
23166 | {"psr", 0x3 }, {"PSR", 0x3 }, | |
23167 | {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 }, | |
23168 | {"ipsr", 0x5 }, {"IPSR", 0x5 }, | |
23169 | {"epsr", 0x6 }, {"EPSR", 0x6 }, | |
23170 | {"iepsr", 0x7 }, {"IEPSR", 0x7 }, | |
23171 | {"msp", 0x8 }, {"MSP", 0x8 }, | |
23172 | {"psp", 0x9 }, {"PSP", 0x9 }, | |
23173 | {"msplim", 0xa }, {"MSPLIM", 0xa }, | |
23174 | {"psplim", 0xb }, {"PSPLIM", 0xb }, | |
23175 | {"primask", 0x10}, {"PRIMASK", 0x10}, | |
23176 | {"basepri", 0x11}, {"BASEPRI", 0x11}, | |
23177 | {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12}, | |
1a336194 TP |
23178 | {"faultmask", 0x13}, {"FAULTMASK", 0x13}, |
23179 | {"control", 0x14}, {"CONTROL", 0x14}, | |
23180 | {"msp_ns", 0x88}, {"MSP_NS", 0x88}, | |
23181 | {"psp_ns", 0x89}, {"PSP_NS", 0x89}, | |
23182 | {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a}, | |
23183 | {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b}, | |
23184 | {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90}, | |
23185 | {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91}, | |
23186 | {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93}, | |
23187 | {"control_ns", 0x94}, {"CONTROL_NS", 0x94}, | |
23188 | {"sp_ns", 0x98}, {"SP_NS", 0x98 } | |
62b3e311 PB |
23189 | }; |
23190 | ||
c19d1205 ZW |
23191 | /* Table of all shift-in-operand names. */ |
23192 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 23193 | { |
c19d1205 ZW |
23194 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
23195 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
23196 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
23197 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
23198 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
f5f10c66 AV |
23199 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }, |
23200 | { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW} | |
c19d1205 | 23201 | }; |
b99bd4ef | 23202 | |
c19d1205 ZW |
23203 | /* Table of all explicit relocation names. */ |
23204 | #ifdef OBJ_ELF | |
23205 | static struct reloc_entry reloc_names[] = | |
23206 | { | |
23207 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
23208 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
23209 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
23210 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
23211 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
23212 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
23213 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
23214 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
23215 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
23216 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
b43420e6 | 23217 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}, |
0855e32b NS |
23218 | { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}, |
23219 | { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC}, | |
477330fc | 23220 | { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC}, |
0855e32b | 23221 | { "tlscall", BFD_RELOC_ARM_TLS_CALL}, |
477330fc | 23222 | { "TLSCALL", BFD_RELOC_ARM_TLS_CALL}, |
0855e32b | 23223 | { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ}, |
188fd7ae CL |
23224 | { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}, |
23225 | { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC }, | |
23226 | { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC }, | |
23227 | { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC }, | |
23228 | { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC }, | |
23229 | { "funcdesc", BFD_RELOC_ARM_FUNCDESC }, | |
5c5a4843 CL |
23230 | { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC }, |
23231 | { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC }, | |
23232 | { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, | |
23233 | { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC }, | |
c19d1205 ZW |
23234 | }; |
23235 | #endif | |
b99bd4ef | 23236 | |
5ee91343 | 23237 | /* Table of all conditional affixes. */ |
c19d1205 ZW |
23238 | static const struct asm_cond conds[] = |
23239 | { | |
23240 | {"eq", 0x0}, | |
23241 | {"ne", 0x1}, | |
23242 | {"cs", 0x2}, {"hs", 0x2}, | |
23243 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
23244 | {"mi", 0x4}, | |
23245 | {"pl", 0x5}, | |
23246 | {"vs", 0x6}, | |
23247 | {"vc", 0x7}, | |
23248 | {"hi", 0x8}, | |
23249 | {"ls", 0x9}, | |
23250 | {"ge", 0xa}, | |
23251 | {"lt", 0xb}, | |
23252 | {"gt", 0xc}, | |
23253 | {"le", 0xd}, | |
23254 | {"al", 0xe} | |
23255 | }; | |
5ee91343 AV |
23256 | static const struct asm_cond vconds[] = |
23257 | { | |
23258 | {"t", 0xf}, | |
23259 | {"e", 0x10} | |
23260 | }; | |
bfae80f2 | 23261 | |
e797f7e0 | 23262 | #define UL_BARRIER(L,U,CODE,FEAT) \ |
823d2571 TG |
23263 | { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \ |
23264 | { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) } | |
e797f7e0 | 23265 | |
62b3e311 PB |
23266 | static struct asm_barrier_opt barrier_opt_names[] = |
23267 | { | |
e797f7e0 MGD |
23268 | UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER), |
23269 | UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER), | |
23270 | UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8), | |
23271 | UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER), | |
23272 | UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER), | |
23273 | UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER), | |
23274 | UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER), | |
23275 | UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8), | |
23276 | UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER), | |
23277 | UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER), | |
23278 | UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER), | |
23279 | UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER), | |
23280 | UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8), | |
23281 | UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER), | |
23282 | UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER), | |
23283 | UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8) | |
62b3e311 PB |
23284 | }; |
23285 | ||
e797f7e0 MGD |
23286 | #undef UL_BARRIER |
23287 | ||
c19d1205 ZW |
23288 | /* Table of ARM-format instructions. */ |
23289 | ||
23290 | /* Macros for gluing together operand strings. N.B. In all cases | |
23291 | other than OPS0, the trailing OP_stop comes from default | |
23292 | zero-initialization of the unspecified elements of the array. */ | |
23293 | #define OPS0() { OP_stop, } | |
23294 | #define OPS1(a) { OP_##a, } | |
23295 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
23296 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
23297 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
23298 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
23299 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
23300 | ||
5be8be5d DG |
23301 | /* These macros are similar to the OPSn, but do not prepend the OP_ prefix. |
23302 | This is useful when mixing operands for ARM and THUMB, i.e. using the | |
23303 | MIX_ARM_THUMB_OPERANDS macro. | |
23304 | In order to use these macros, prefix the number of operands with _ | |
23305 | e.g. _3. */ | |
23306 | #define OPS_1(a) { a, } | |
23307 | #define OPS_2(a,b) { a,b, } | |
23308 | #define OPS_3(a,b,c) { a,b,c, } | |
23309 | #define OPS_4(a,b,c,d) { a,b,c,d, } | |
23310 | #define OPS_5(a,b,c,d,e) { a,b,c,d,e, } | |
23311 | #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, } | |
23312 | ||
c19d1205 ZW |
23313 | /* These macros abstract out the exact format of the mnemonic table and |
23314 | save some repeated characters. */ | |
23315 | ||
23316 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
23317 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 23318 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ |
5ee91343 | 23319 | THUMB_VARIANT, do_##ae, do_##te, 0 } |
c19d1205 ZW |
23320 | |
23321 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
23322 | a T_MNEM_xyz enumerator. */ | |
23323 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
e07e6e58 | 23324 | TxCE (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 23325 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 23326 | TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 ZW |
23327 | |
23328 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
23329 | infix after the third character. */ | |
23330 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 23331 | { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ |
5ee91343 | 23332 | THUMB_VARIANT, do_##ae, do_##te, 0 } |
088fa78e | 23333 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 23334 | { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ |
5ee91343 | 23335 | THUMB_VARIANT, do_##ae, do_##te, 0 } |
c19d1205 | 23336 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 23337 | TxC3 (mnem, aop, 0x##top, nops, ops, ae, te) |
088fa78e | 23338 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 23339 | TxC3w (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 23340 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 23341 | TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
088fa78e | 23342 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 23343 | TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 | 23344 | |
c19d1205 | 23345 | /* Mnemonic that cannot be conditionalized. The ARM condition-code |
dfa9f0d5 PB |
23346 | field is still 0xE. Many of the Thumb variants can be executed |
23347 | conditionally, so this is checked separately. */ | |
c19d1205 | 23348 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 23349 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ |
5ee91343 | 23350 | THUMB_VARIANT, do_##ae, do_##te, 0 } |
c19d1205 | 23351 | |
dd5181d5 KT |
23352 | /* Same as TUE but the encoding function for ARM and Thumb modes is the same. |
23353 | Used by mnemonics that have very minimal differences in the encoding for | |
23354 | ARM and Thumb variants and can be handled in a common function. */ | |
23355 | #define TUEc(mnem, op, top, nops, ops, en) \ | |
23356 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ | |
5ee91343 | 23357 | THUMB_VARIANT, do_##en, do_##en, 0 } |
dd5181d5 | 23358 | |
c19d1205 ZW |
23359 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM |
23360 | condition code field. */ | |
23361 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 23362 | { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ |
5ee91343 | 23363 | THUMB_VARIANT, do_##ae, do_##te, 0 } |
c19d1205 ZW |
23364 | |
23365 | /* ARM-only variants of all the above. */ | |
6a86118a | 23366 | #define CE(mnem, op, nops, ops, ae) \ |
5ee91343 | 23367 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 } |
6a86118a NC |
23368 | |
23369 | #define C3(mnem, op, nops, ops, ae) \ | |
5ee91343 | 23370 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 } |
6a86118a | 23371 | |
cf3cf39d TP |
23372 | /* Thumb-only variants of TCE and TUE. */ |
23373 | #define ToC(mnem, top, nops, ops, te) \ | |
23374 | { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \ | |
5ee91343 | 23375 | do_##te, 0 } |
cf3cf39d TP |
23376 | |
23377 | #define ToU(mnem, top, nops, ops, te) \ | |
23378 | { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \ | |
5ee91343 | 23379 | NULL, do_##te, 0 } |
cf3cf39d | 23380 | |
4389b29a AV |
23381 | /* T_MNEM_xyz enumerator variants of ToC. */ |
23382 | #define toC(mnem, top, nops, ops, te) \ | |
23383 | { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \ | |
5ee91343 | 23384 | do_##te, 0 } |
4389b29a | 23385 | |
f6b2b12d AV |
23386 | /* T_MNEM_xyz enumerator variants of ToU. */ |
23387 | #define toU(mnem, top, nops, ops, te) \ | |
23388 | { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \ | |
5ee91343 | 23389 | NULL, do_##te, 0 } |
f6b2b12d | 23390 | |
e3cb604e PB |
23391 | /* Legacy mnemonics that always have conditional infix after the third |
23392 | character. */ | |
23393 | #define CL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 23394 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
5ee91343 | 23395 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 } |
e3cb604e | 23396 | |
8f06b2d8 PB |
23397 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
23398 | #define cCE(mnem, op, nops, ops, ae) \ | |
5ee91343 | 23399 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 } |
8f06b2d8 | 23400 | |
57785aa2 AV |
23401 | /* mov instructions that are shared between coprocessor and MVE. */ |
23402 | #define mcCE(mnem, op, nops, ops, ae) \ | |
23403 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##ae, 0 } | |
23404 | ||
e3cb604e PB |
23405 | /* Legacy coprocessor instructions where conditional infix and conditional |
23406 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
23407 | not just the potentially ambiguous ones. */ | |
23408 | #define cCL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 23409 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
5ee91343 | 23410 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 } |
e3cb604e PB |
23411 | |
23412 | /* Coprocessor, takes either a suffix or a position-3 infix | |
23413 | (for an FPA corner case). */ | |
23414 | #define C3E(mnem, op, nops, ops, ae) \ | |
21d799b5 | 23415 | { mnem, OPS##nops ops, OT_csuf_or_in3, \ |
5ee91343 | 23416 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 } |
8f06b2d8 | 23417 | |
6a86118a | 23418 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
21d799b5 NC |
23419 | { m1 #m2 m3, OPS##nops ops, \ |
23420 | sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \ | |
5ee91343 | 23421 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 } |
6a86118a NC |
23422 | |
23423 | #define CM(m1, m2, op, nops, ops, ae) \ | |
e07e6e58 NC |
23424 | xCM_ (m1, , m2, op, nops, ops, ae), \ |
23425 | xCM_ (m1, eq, m2, op, nops, ops, ae), \ | |
23426 | xCM_ (m1, ne, m2, op, nops, ops, ae), \ | |
23427 | xCM_ (m1, cs, m2, op, nops, ops, ae), \ | |
23428 | xCM_ (m1, hs, m2, op, nops, ops, ae), \ | |
23429 | xCM_ (m1, cc, m2, op, nops, ops, ae), \ | |
23430 | xCM_ (m1, ul, m2, op, nops, ops, ae), \ | |
23431 | xCM_ (m1, lo, m2, op, nops, ops, ae), \ | |
23432 | xCM_ (m1, mi, m2, op, nops, ops, ae), \ | |
23433 | xCM_ (m1, pl, m2, op, nops, ops, ae), \ | |
23434 | xCM_ (m1, vs, m2, op, nops, ops, ae), \ | |
23435 | xCM_ (m1, vc, m2, op, nops, ops, ae), \ | |
23436 | xCM_ (m1, hi, m2, op, nops, ops, ae), \ | |
23437 | xCM_ (m1, ls, m2, op, nops, ops, ae), \ | |
23438 | xCM_ (m1, ge, m2, op, nops, ops, ae), \ | |
23439 | xCM_ (m1, lt, m2, op, nops, ops, ae), \ | |
23440 | xCM_ (m1, gt, m2, op, nops, ops, ae), \ | |
23441 | xCM_ (m1, le, m2, op, nops, ops, ae), \ | |
23442 | xCM_ (m1, al, m2, op, nops, ops, ae) | |
6a86118a NC |
23443 | |
23444 | #define UE(mnem, op, nops, ops, ae) \ | |
5ee91343 | 23445 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 } |
6a86118a NC |
23446 | |
23447 | #define UF(mnem, op, nops, ops, ae) \ | |
5ee91343 | 23448 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 } |
6a86118a | 23449 | |
5287ad62 JB |
23450 | /* Neon data-processing. ARM versions are unconditional with cond=0xf. |
23451 | The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we | |
23452 | use the same encoding function for each. */ | |
23453 | #define NUF(mnem, op, nops, ops, enc) \ | |
23454 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
5ee91343 | 23455 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 } |
5287ad62 JB |
23456 | |
23457 | /* Neon data processing, version which indirects through neon_enc_tab for | |
23458 | the various overloaded versions of opcodes. */ | |
23459 | #define nUF(mnem, op, nops, ops, enc) \ | |
21d799b5 | 23460 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \ |
5ee91343 | 23461 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 } |
5287ad62 JB |
23462 | |
23463 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
23464 | version. */ | |
5ee91343 | 23465 | #define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \ |
037e8744 | 23466 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ |
5ee91343 | 23467 | THUMB_VARIANT, do_##enc, do_##enc, mve_p } |
5287ad62 | 23468 | |
037e8744 | 23469 | #define NCE(mnem, op, nops, ops, enc) \ |
5ee91343 | 23470 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0) |
037e8744 JB |
23471 | |
23472 | #define NCEF(mnem, op, nops, ops, enc) \ | |
5ee91343 | 23473 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0) |
037e8744 | 23474 | |
5287ad62 | 23475 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
5ee91343 | 23476 | #define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \ |
21d799b5 | 23477 | { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \ |
5ee91343 | 23478 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p } |
5287ad62 | 23479 | |
037e8744 | 23480 | #define nCE(mnem, op, nops, ops, enc) \ |
5ee91343 | 23481 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0) |
037e8744 JB |
23482 | |
23483 | #define nCEF(mnem, op, nops, ops, enc) \ | |
5ee91343 AV |
23484 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0) |
23485 | ||
23486 | /* */ | |
23487 | #define mCEF(mnem, op, nops, ops, enc) \ | |
a302e574 | 23488 | { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \ |
5ee91343 AV |
23489 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 } |
23490 | ||
23491 | ||
23492 | /* nCEF but for MVE predicated instructions. */ | |
23493 | #define mnCEF(mnem, op, nops, ops, enc) \ | |
23494 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1) | |
23495 | ||
23496 | /* nCE but for MVE predicated instructions. */ | |
23497 | #define mnCE(mnem, op, nops, ops, enc) \ | |
23498 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1) | |
037e8744 | 23499 | |
5ee91343 AV |
23500 | /* NUF but for potentially MVE predicated instructions. */ |
23501 | #define MNUF(mnem, op, nops, ops, enc) \ | |
23502 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
23503 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 } | |
23504 | ||
23505 | /* nUF but for potentially MVE predicated instructions. */ | |
23506 | #define mnUF(mnem, op, nops, ops, enc) \ | |
23507 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \ | |
23508 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 } | |
23509 | ||
23510 | /* ToC but for potentially MVE predicated instructions. */ | |
23511 | #define mToC(mnem, top, nops, ops, te) \ | |
23512 | { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \ | |
23513 | do_##te, 1 } | |
23514 | ||
23515 | /* NCE but for MVE predicated instructions. */ | |
23516 | #define MNCE(mnem, op, nops, ops, enc) \ | |
23517 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1) | |
23518 | ||
23519 | /* NCEF but for MVE predicated instructions. */ | |
23520 | #define MNCEF(mnem, op, nops, ops, enc) \ | |
23521 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1) | |
c19d1205 ZW |
23522 | #define do_0 0 |
23523 | ||
c19d1205 | 23524 | static const struct asm_opcode insns[] = |
bfae80f2 | 23525 | { |
74db7efb NC |
23526 | #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */ |
23527 | #define THUMB_VARIANT & arm_ext_v4t | |
21d799b5 NC |
23528 | tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c), |
23529 | tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
23530 | tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
23531 | tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
23532 | tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
23533 | tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
23534 | tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub), | |
23535 | tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub), | |
23536 | tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c), | |
23537 | tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
23538 | tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
23539 | tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
23540 | tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
23541 | tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
23542 | tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3), | |
23543 | tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3), | |
c19d1205 ZW |
23544 | |
23545 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
23546 | for setting PSR flag bits. They are obsolete in V6 and do not | |
23547 | have Thumb equivalents. */ | |
21d799b5 NC |
23548 | tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), |
23549 | tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), | |
23550 | CL("tstp", 110f000, 2, (RR, SH), cmp), | |
23551 | tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
23552 | tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
23553 | CL("cmpp", 150f000, 2, (RR, SH), cmp), | |
23554 | tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
23555 | tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
23556 | CL("cmnp", 170f000, 2, (RR, SH), cmp), | |
23557 | ||
23558 | tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp), | |
72d98d16 | 23559 | tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp), |
21d799b5 NC |
23560 | tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst), |
23561 | tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst), | |
23562 | ||
23563 | tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
5be8be5d DG |
23564 | tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), |
23565 | tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR, | |
23566 | OP_RRnpc), | |
23567 | OP_ADDRGLDR),ldst, t_ldst), | |
23568 | tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), | |
21d799b5 NC |
23569 | |
23570 | tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
23571 | tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
23572 | tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
23573 | tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
23574 | tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
23575 | tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
23576 | ||
21d799b5 NC |
23577 | tCE("b", a000000, _b, 1, (EXPr), branch, t_branch), |
23578 | TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23), | |
bfae80f2 | 23579 | |
c19d1205 | 23580 | /* Pseudo ops. */ |
21d799b5 | 23581 | tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac | 23582 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
21d799b5 | 23583 | tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop), |
74db7efb | 23584 | tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf), |
c19d1205 ZW |
23585 | |
23586 | /* Thumb-compatibility pseudo ops. */ | |
21d799b5 NC |
23587 | tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift), |
23588 | tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift), | |
23589 | tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift), | |
23590 | tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
23591 | tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift), | |
23592 | tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift), | |
23593 | tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift), | |
23594 | tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift), | |
23595 | tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg), | |
23596 | tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg), | |
23597 | tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop), | |
23598 | tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop), | |
c19d1205 | 23599 | |
16a4cf17 | 23600 | /* These may simplify to neg. */ |
21d799b5 NC |
23601 | TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), |
23602 | TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16a4cf17 | 23603 | |
173205ca TP |
23604 | #undef THUMB_VARIANT |
23605 | #define THUMB_VARIANT & arm_ext_os | |
23606 | ||
23607 | TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi), | |
23608 | TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi), | |
23609 | ||
c921be7d NC |
23610 | #undef THUMB_VARIANT |
23611 | #define THUMB_VARIANT & arm_ext_v6 | |
23612 | ||
21d799b5 | 23613 | TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
23614 | |
23615 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
c921be7d NC |
23616 | #undef THUMB_VARIANT |
23617 | #define THUMB_VARIANT & arm_ext_v6t2 | |
23618 | ||
21d799b5 NC |
23619 | TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
23620 | TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
23621 | CL("teqp", 130f000, 2, (RR, SH), cmp), | |
c19d1205 | 23622 | |
5be8be5d DG |
23623 | TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), |
23624 | TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
23625 | TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt), | |
23626 | TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
c19d1205 | 23627 | |
21d799b5 NC |
23628 | TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
23629 | TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 23630 | |
21d799b5 NC |
23631 | TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
23632 | TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
23633 | |
23634 | /* V1 instructions with no Thumb analogue at all. */ | |
21d799b5 | 23635 | CE("rsc", 0e00000, 3, (RR, oRR, SH), arit), |
c19d1205 ZW |
23636 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), |
23637 | ||
23638 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
23639 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
23640 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
23641 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
23642 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
23643 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
23644 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
23645 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
23646 | ||
c921be7d NC |
23647 | #undef ARM_VARIANT |
23648 | #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */ | |
23649 | #undef THUMB_VARIANT | |
23650 | #define THUMB_VARIANT & arm_ext_v4t | |
23651 | ||
21d799b5 NC |
23652 | tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
23653 | tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
c19d1205 | 23654 | |
c921be7d NC |
23655 | #undef THUMB_VARIANT |
23656 | #define THUMB_VARIANT & arm_ext_v6t2 | |
23657 | ||
21d799b5 | 23658 | TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
c19d1205 ZW |
23659 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), |
23660 | ||
23661 | /* Generic coprocessor instructions. */ | |
21d799b5 NC |
23662 | TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), |
23663 | TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
23664 | TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
23665 | TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
23666 | TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
23667 | TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
db472d6f | 23668 | TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg), |
c19d1205 | 23669 | |
c921be7d NC |
23670 | #undef ARM_VARIANT |
23671 | #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */ | |
23672 | ||
21d799b5 | 23673 | CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
c19d1205 ZW |
23674 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
23675 | ||
c921be7d NC |
23676 | #undef ARM_VARIANT |
23677 | #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */ | |
23678 | #undef THUMB_VARIANT | |
23679 | #define THUMB_VARIANT & arm_ext_msr | |
23680 | ||
d2cd1205 JB |
23681 | TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs), |
23682 | TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr), | |
c19d1205 | 23683 | |
c921be7d NC |
23684 | #undef ARM_VARIANT |
23685 | #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */ | |
23686 | #undef THUMB_VARIANT | |
23687 | #define THUMB_VARIANT & arm_ext_v6t2 | |
23688 | ||
21d799b5 NC |
23689 | TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
23690 | CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
23691 | TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
23692 | CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
23693 | TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
23694 | CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
23695 | TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
23696 | CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
c19d1205 | 23697 | |
c921be7d NC |
23698 | #undef ARM_VARIANT |
23699 | #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */ | |
23700 | #undef THUMB_VARIANT | |
23701 | #define THUMB_VARIANT & arm_ext_v4t | |
23702 | ||
5be8be5d DG |
23703 | tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
23704 | tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
23705 | tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
23706 | tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
56c0a61f RE |
23707 | tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
23708 | tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 | 23709 | |
c921be7d NC |
23710 | #undef ARM_VARIANT |
23711 | #define ARM_VARIANT & arm_ext_v4t_5 | |
23712 | ||
c19d1205 ZW |
23713 | /* ARM Architecture 4T. */ |
23714 | /* Note: bx (and blx) are required on V5, even if the processor does | |
23715 | not support Thumb. */ | |
21d799b5 | 23716 | TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx), |
c19d1205 | 23717 | |
c921be7d NC |
23718 | #undef ARM_VARIANT |
23719 | #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */ | |
23720 | #undef THUMB_VARIANT | |
23721 | #define THUMB_VARIANT & arm_ext_v5t | |
23722 | ||
c19d1205 ZW |
23723 | /* Note: blx has 2 variants; the .value coded here is for |
23724 | BLX(2). Only this variant has conditional execution. */ | |
21d799b5 NC |
23725 | TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx), |
23726 | TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
c19d1205 | 23727 | |
c921be7d NC |
23728 | #undef THUMB_VARIANT |
23729 | #define THUMB_VARIANT & arm_ext_v6t2 | |
23730 | ||
21d799b5 NC |
23731 | TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
23732 | TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
23733 | TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
23734 | TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
23735 | TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
23736 | TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
23737 | TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
23738 | TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
c19d1205 | 23739 | |
c921be7d | 23740 | #undef ARM_VARIANT |
74db7efb NC |
23741 | #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */ |
23742 | #undef THUMB_VARIANT | |
23743 | #define THUMB_VARIANT & arm_ext_v5exp | |
c921be7d | 23744 | |
21d799b5 NC |
23745 | TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
23746 | TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
23747 | TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
23748 | TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 23749 | |
21d799b5 NC |
23750 | TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
23751 | TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 23752 | |
21d799b5 NC |
23753 | TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), |
23754 | TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
23755 | TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
23756 | TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
c19d1205 | 23757 | |
21d799b5 NC |
23758 | TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
23759 | TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
23760 | TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
23761 | TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 23762 | |
21d799b5 NC |
23763 | TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
23764 | TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 23765 | |
03ee1b7f NC |
23766 | TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), |
23767 | TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
23768 | TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
23769 | TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
c19d1205 | 23770 | |
c921be7d | 23771 | #undef ARM_VARIANT |
74db7efb NC |
23772 | #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */ |
23773 | #undef THUMB_VARIANT | |
23774 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 23775 | |
21d799b5 | 23776 | TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld), |
5be8be5d DG |
23777 | TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS), |
23778 | ldrd, t_ldstd), | |
23779 | TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp, | |
23780 | ADDRGLDRS), ldrd, t_ldstd), | |
c19d1205 | 23781 | |
21d799b5 NC |
23782 | TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
23783 | TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
c19d1205 | 23784 | |
c921be7d NC |
23785 | #undef ARM_VARIANT |
23786 | #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */ | |
23787 | ||
21d799b5 | 23788 | TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
c19d1205 | 23789 | |
c921be7d NC |
23790 | #undef ARM_VARIANT |
23791 | #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */ | |
23792 | #undef THUMB_VARIANT | |
23793 | #define THUMB_VARIANT & arm_ext_v6 | |
23794 | ||
21d799b5 NC |
23795 | TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
23796 | TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
23797 | tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
23798 | tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
23799 | tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
23800 | tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
23801 | tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
23802 | tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
23803 | tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
23804 | TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend), | |
c19d1205 | 23805 | |
c921be7d | 23806 | #undef THUMB_VARIANT |
ff8646ee | 23807 | #define THUMB_VARIANT & arm_ext_v6t2_v8m |
c921be7d | 23808 | |
5be8be5d DG |
23809 | TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex), |
23810 | TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
23811 | strex, t_strex), | |
ff8646ee TP |
23812 | #undef THUMB_VARIANT |
23813 | #define THUMB_VARIANT & arm_ext_v6t2 | |
23814 | ||
21d799b5 NC |
23815 | TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
23816 | TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 | 23817 | |
21d799b5 NC |
23818 | TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), |
23819 | TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
62b3e311 | 23820 | |
9e3c6df6 | 23821 | /* ARM V6 not included in V7M. */ |
c921be7d NC |
23822 | #undef THUMB_VARIANT |
23823 | #define THUMB_VARIANT & arm_ext_v6_notm | |
9e3c6df6 | 23824 | TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
d709e4e6 | 23825 | TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
9e3c6df6 PB |
23826 | UF(rfeib, 9900a00, 1, (RRw), rfe), |
23827 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
23828 | TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
23829 | TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
d709e4e6 RE |
23830 | UF(rfefa, 8100a00, 1, (RRw), rfe), |
23831 | TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
23832 | UF(rfeed, 9900a00, 1, (RRw), rfe), | |
9e3c6df6 | 23833 | TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 RE |
23834 | TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
23835 | TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), | |
9e3c6df6 | 23836 | UF(srsib, 9c00500, 2, (oRRw, I31w), srs), |
d709e4e6 | 23837 | UF(srsfa, 9c00500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 23838 | UF(srsda, 8400500, 2, (oRRw, I31w), srs), |
d709e4e6 | 23839 | UF(srsed, 8400500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 23840 | TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 | 23841 | TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
941c9cad | 23842 | TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
c921be7d | 23843 | |
9e3c6df6 PB |
23844 | /* ARM V6 not included in V7M (eg. integer SIMD). */ |
23845 | #undef THUMB_VARIANT | |
23846 | #define THUMB_VARIANT & arm_ext_v6_dsp | |
21d799b5 NC |
23847 | TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), |
23848 | TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
23849 | TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23850 | TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23851 | TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 23852 | /* Old name for QASX. */ |
74db7efb | 23853 | TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 | 23854 | TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 23855 | /* Old name for QSAX. */ |
74db7efb | 23856 | TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
23857 | TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
23858 | TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23859 | TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23860 | TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23861 | TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 23862 | /* Old name for SASX. */ |
74db7efb | 23863 | TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
23864 | TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
23865 | TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 23866 | TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 23867 | /* Old name for SHASX. */ |
21d799b5 | 23868 | TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
74db7efb | 23869 | TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 23870 | /* Old name for SHSAX. */ |
21d799b5 NC |
23871 | TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
23872 | TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23873 | TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23874 | TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 23875 | /* Old name for SSAX. */ |
74db7efb | 23876 | TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
23877 | TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
23878 | TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23879 | TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23880 | TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23881 | TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 23882 | /* Old name for UASX. */ |
74db7efb | 23883 | TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
23884 | TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
23885 | TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 23886 | TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 23887 | /* Old name for UHASX. */ |
21d799b5 NC |
23888 | TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
23889 | TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 23890 | /* Old name for UHSAX. */ |
21d799b5 NC |
23891 | TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
23892 | TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23893 | TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23894 | TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23895 | TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 23896 | TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 23897 | /* Old name for UQASX. */ |
21d799b5 NC |
23898 | TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
23899 | TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 23900 | /* Old name for UQSAX. */ |
21d799b5 NC |
23901 | TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
23902 | TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23903 | TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23904 | TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23905 | TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 23906 | /* Old name for USAX. */ |
74db7efb | 23907 | TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 | 23908 | TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
23909 | TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), |
23910 | TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
23911 | TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
23912 | TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
23913 | TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
23914 | TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
23915 | TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
23916 | TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
23917 | TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
23918 | TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
23919 | TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
23920 | TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
23921 | TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
23922 | TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
23923 | TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
23924 | TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
23925 | TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
23926 | TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
23927 | TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
23928 | TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
23929 | TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
23930 | TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
23931 | TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
23932 | TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
23933 | TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
23934 | TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
23935 | TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
21d799b5 NC |
23936 | TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), |
23937 | TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), | |
23938 | TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
23939 | TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
23940 | TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), | |
c19d1205 | 23941 | |
c921be7d | 23942 | #undef ARM_VARIANT |
55e8aae7 | 23943 | #define ARM_VARIANT & arm_ext_v6k_v6t2 |
c921be7d | 23944 | #undef THUMB_VARIANT |
55e8aae7 | 23945 | #define THUMB_VARIANT & arm_ext_v6k_v6t2 |
c921be7d | 23946 | |
21d799b5 NC |
23947 | tCE("yield", 320f001, _yield, 0, (), noargs, t_hint), |
23948 | tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint), | |
23949 | tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint), | |
23950 | tCE("sev", 320f004, _sev, 0, (), noargs, t_hint), | |
c19d1205 | 23951 | |
c921be7d NC |
23952 | #undef THUMB_VARIANT |
23953 | #define THUMB_VARIANT & arm_ext_v6_notm | |
5be8be5d DG |
23954 | TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb), |
23955 | ldrexd, t_ldrexd), | |
23956 | TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp, | |
23957 | RRnpcb), strexd, t_strexd), | |
ebdca51a | 23958 | |
c921be7d | 23959 | #undef THUMB_VARIANT |
ff8646ee | 23960 | #define THUMB_VARIANT & arm_ext_v6t2_v8m |
5be8be5d DG |
23961 | TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb), |
23962 | rd_rn, rd_rn), | |
23963 | TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb), | |
23964 | rd_rn, rd_rn), | |
23965 | TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
877807f8 | 23966 | strex, t_strexbh), |
5be8be5d | 23967 | TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), |
877807f8 | 23968 | strex, t_strexbh), |
21d799b5 | 23969 | TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
c19d1205 | 23970 | |
c921be7d | 23971 | #undef ARM_VARIANT |
f4c65163 | 23972 | #define ARM_VARIANT & arm_ext_sec |
74db7efb | 23973 | #undef THUMB_VARIANT |
f4c65163 | 23974 | #define THUMB_VARIANT & arm_ext_sec |
c921be7d | 23975 | |
21d799b5 | 23976 | TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 | 23977 | |
90ec0d68 MGD |
23978 | #undef ARM_VARIANT |
23979 | #define ARM_VARIANT & arm_ext_virt | |
23980 | #undef THUMB_VARIANT | |
23981 | #define THUMB_VARIANT & arm_ext_virt | |
23982 | ||
23983 | TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc), | |
23984 | TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs), | |
23985 | ||
ddfded2f MW |
23986 | #undef ARM_VARIANT |
23987 | #define ARM_VARIANT & arm_ext_pan | |
23988 | #undef THUMB_VARIANT | |
23989 | #define THUMB_VARIANT & arm_ext_pan | |
23990 | ||
23991 | TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan), | |
23992 | ||
c921be7d | 23993 | #undef ARM_VARIANT |
74db7efb | 23994 | #define ARM_VARIANT & arm_ext_v6t2 |
f4c65163 MGD |
23995 | #undef THUMB_VARIANT |
23996 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 23997 | |
21d799b5 NC |
23998 | TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
23999 | TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
24000 | TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
24001 | TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
c19d1205 | 24002 | |
21d799b5 | 24003 | TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
21d799b5 | 24004 | TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), |
c19d1205 | 24005 | |
5be8be5d DG |
24006 | TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), |
24007 | TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
24008 | TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
24009 | TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
c19d1205 | 24010 | |
91d8b670 JG |
24011 | #undef ARM_VARIANT |
24012 | #define ARM_VARIANT & arm_ext_v3 | |
24013 | #undef THUMB_VARIANT | |
24014 | #define THUMB_VARIANT & arm_ext_v6t2 | |
24015 | ||
24016 | TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb), | |
c597cc3d SD |
24017 | TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb), |
24018 | TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb), | |
91d8b670 JG |
24019 | |
24020 | #undef ARM_VARIANT | |
24021 | #define ARM_VARIANT & arm_ext_v6t2 | |
ff8646ee TP |
24022 | #undef THUMB_VARIANT |
24023 | #define THUMB_VARIANT & arm_ext_v6t2_v8m | |
24024 | TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16), | |
24025 | TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16), | |
24026 | ||
bf3eeda7 | 24027 | /* Thumb-only instructions. */ |
74db7efb | 24028 | #undef ARM_VARIANT |
bf3eeda7 NS |
24029 | #define ARM_VARIANT NULL |
24030 | TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz), | |
24031 | TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz), | |
c921be7d NC |
24032 | |
24033 | /* ARM does not really have an IT instruction, so always allow it. | |
24034 | The opcode is copied from Thumb in order to allow warnings in | |
24035 | -mimplicit-it=[never | arm] modes. */ | |
24036 | #undef ARM_VARIANT | |
24037 | #define ARM_VARIANT & arm_ext_v1 | |
ff8646ee TP |
24038 | #undef THUMB_VARIANT |
24039 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 24040 | |
21d799b5 NC |
24041 | TUE("it", bf08, bf08, 1, (COND), it, t_it), |
24042 | TUE("itt", bf0c, bf0c, 1, (COND), it, t_it), | |
24043 | TUE("ite", bf04, bf04, 1, (COND), it, t_it), | |
24044 | TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it), | |
24045 | TUE("itet", bf06, bf06, 1, (COND), it, t_it), | |
24046 | TUE("itte", bf0a, bf0a, 1, (COND), it, t_it), | |
24047 | TUE("itee", bf02, bf02, 1, (COND), it, t_it), | |
24048 | TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it), | |
24049 | TUE("itett", bf07, bf07, 1, (COND), it, t_it), | |
24050 | TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it), | |
24051 | TUE("iteet", bf03, bf03, 1, (COND), it, t_it), | |
24052 | TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it), | |
24053 | TUE("itete", bf05, bf05, 1, (COND), it, t_it), | |
24054 | TUE("ittee", bf09, bf09, 1, (COND), it, t_it), | |
24055 | TUE("iteee", bf01, bf01, 1, (COND), it, t_it), | |
1c444d06 | 24056 | /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */ |
21d799b5 NC |
24057 | TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx), |
24058 | TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx), | |
c19d1205 | 24059 | |
92e90b6e | 24060 | /* Thumb2 only instructions. */ |
c921be7d NC |
24061 | #undef ARM_VARIANT |
24062 | #define ARM_VARIANT NULL | |
92e90b6e | 24063 | |
21d799b5 NC |
24064 | TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), |
24065 | TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
24066 | TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn), | |
24067 | TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn), | |
24068 | TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb), | |
24069 | TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb), | |
92e90b6e | 24070 | |
eea54501 MGD |
24071 | /* Hardware division instructions. */ |
24072 | #undef ARM_VARIANT | |
24073 | #define ARM_VARIANT & arm_ext_adiv | |
c921be7d NC |
24074 | #undef THUMB_VARIANT |
24075 | #define THUMB_VARIANT & arm_ext_div | |
24076 | ||
eea54501 MGD |
24077 | TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div), |
24078 | TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div), | |
62b3e311 | 24079 | |
7e806470 | 24080 | /* ARM V6M/V7 instructions. */ |
c921be7d NC |
24081 | #undef ARM_VARIANT |
24082 | #define ARM_VARIANT & arm_ext_barrier | |
24083 | #undef THUMB_VARIANT | |
24084 | #define THUMB_VARIANT & arm_ext_barrier | |
24085 | ||
ccb84d65 JB |
24086 | TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier), |
24087 | TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier), | |
24088 | TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier), | |
7e806470 | 24089 | |
62b3e311 | 24090 | /* ARM V7 instructions. */ |
c921be7d NC |
24091 | #undef ARM_VARIANT |
24092 | #define ARM_VARIANT & arm_ext_v7 | |
24093 | #undef THUMB_VARIANT | |
24094 | #define THUMB_VARIANT & arm_ext_v7 | |
24095 | ||
21d799b5 NC |
24096 | TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld), |
24097 | TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
62b3e311 | 24098 | |
74db7efb | 24099 | #undef ARM_VARIANT |
60e5ef9f | 24100 | #define ARM_VARIANT & arm_ext_mp |
74db7efb | 24101 | #undef THUMB_VARIANT |
60e5ef9f MGD |
24102 | #define THUMB_VARIANT & arm_ext_mp |
24103 | ||
24104 | TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld), | |
24105 | ||
53c4b28b MGD |
24106 | /* AArchv8 instructions. */ |
24107 | #undef ARM_VARIANT | |
24108 | #define ARM_VARIANT & arm_ext_v8 | |
4ed7ed8d TP |
24109 | |
24110 | /* Instructions shared between armv8-a and armv8-m. */ | |
53c4b28b | 24111 | #undef THUMB_VARIANT |
4ed7ed8d | 24112 | #define THUMB_VARIANT & arm_ext_atomics |
53c4b28b | 24113 | |
4ed7ed8d TP |
24114 | TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
24115 | TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
24116 | TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
24117 | TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
24118 | TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
24119 | TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
4b8c8c02 | 24120 | TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
4b8c8c02 RE |
24121 | TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn), |
24122 | TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
24123 | TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb), | |
24124 | stlex, t_stlex), | |
4b8c8c02 RE |
24125 | TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb), |
24126 | stlex, t_stlex), | |
24127 | TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb), | |
24128 | stlex, t_stlex), | |
4ed7ed8d TP |
24129 | #undef THUMB_VARIANT |
24130 | #define THUMB_VARIANT & arm_ext_v8 | |
53c4b28b | 24131 | |
4ed7ed8d | 24132 | tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint), |
4ed7ed8d TP |
24133 | TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb), |
24134 | ldrexd, t_ldrexd), | |
24135 | TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), | |
24136 | strexd, t_strexd), | |
f7dd2fb2 TC |
24137 | |
24138 | /* Defined in V8 but is in undefined encoding space for earlier | |
24139 | architectures. However earlier architectures are required to treat | |
24140 | this instuction as a semihosting trap as well. Hence while not explicitly | |
24141 | defined as such, it is in fact correct to define the instruction for all | |
24142 | architectures. */ | |
24143 | #undef THUMB_VARIANT | |
24144 | #define THUMB_VARIANT & arm_ext_v1 | |
24145 | #undef ARM_VARIANT | |
24146 | #define ARM_VARIANT & arm_ext_v1 | |
24147 | TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt), | |
24148 | ||
8884b720 | 24149 | /* ARMv8 T32 only. */ |
74db7efb | 24150 | #undef ARM_VARIANT |
b79f7053 MGD |
24151 | #define ARM_VARIANT NULL |
24152 | TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs), | |
24153 | TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs), | |
24154 | TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs), | |
24155 | ||
33399f07 MGD |
24156 | /* FP for ARMv8. */ |
24157 | #undef ARM_VARIANT | |
a715796b | 24158 | #define ARM_VARIANT & fpu_vfp_ext_armv8xd |
33399f07 | 24159 | #undef THUMB_VARIANT |
a715796b | 24160 | #define THUMB_VARIANT & fpu_vfp_ext_armv8xd |
33399f07 MGD |
24161 | |
24162 | nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel), | |
24163 | nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel), | |
24164 | nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel), | |
24165 | nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel), | |
30bdf752 | 24166 | nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr), |
a710b305 AV |
24167 | mnCE(vrintz, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintz), |
24168 | mnCE(vrintx, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintx), | |
24169 | mnUF(vrinta, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrinta), | |
24170 | mnUF(vrintn, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintn), | |
24171 | mnUF(vrintp, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintp), | |
24172 | mnUF(vrintm, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintm), | |
33399f07 | 24173 | |
91ff7894 MGD |
24174 | /* Crypto v1 extensions. */ |
24175 | #undef ARM_VARIANT | |
24176 | #define ARM_VARIANT & fpu_crypto_ext_armv8 | |
24177 | #undef THUMB_VARIANT | |
24178 | #define THUMB_VARIANT & fpu_crypto_ext_armv8 | |
24179 | ||
24180 | nUF(aese, _aes, 2, (RNQ, RNQ), aese), | |
24181 | nUF(aesd, _aes, 2, (RNQ, RNQ), aesd), | |
24182 | nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc), | |
24183 | nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc), | |
48adcd8e MGD |
24184 | nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c), |
24185 | nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p), | |
24186 | nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m), | |
24187 | nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0), | |
24188 | nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h), | |
24189 | nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2), | |
24190 | nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1), | |
3c9017d2 MGD |
24191 | nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h), |
24192 | nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1), | |
24193 | nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0), | |
91ff7894 | 24194 | |
dd5181d5 | 24195 | #undef ARM_VARIANT |
74db7efb | 24196 | #define ARM_VARIANT & crc_ext_armv8 |
dd5181d5 KT |
24197 | #undef THUMB_VARIANT |
24198 | #define THUMB_VARIANT & crc_ext_armv8 | |
24199 | TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b), | |
24200 | TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h), | |
24201 | TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w), | |
24202 | TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb), | |
24203 | TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch), | |
24204 | TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw), | |
24205 | ||
105bde57 MW |
24206 | /* ARMv8.2 RAS extension. */ |
24207 | #undef ARM_VARIANT | |
4d1464f2 | 24208 | #define ARM_VARIANT & arm_ext_ras |
105bde57 | 24209 | #undef THUMB_VARIANT |
4d1464f2 | 24210 | #define THUMB_VARIANT & arm_ext_ras |
105bde57 MW |
24211 | TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs), |
24212 | ||
49e8a725 SN |
24213 | #undef ARM_VARIANT |
24214 | #define ARM_VARIANT & arm_ext_v8_3 | |
24215 | #undef THUMB_VARIANT | |
24216 | #define THUMB_VARIANT & arm_ext_v8_3 | |
24217 | NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt), | |
24218 | ||
c604a79a JW |
24219 | #undef ARM_VARIANT |
24220 | #define ARM_VARIANT & fpu_neon_ext_dotprod | |
24221 | #undef THUMB_VARIANT | |
24222 | #define THUMB_VARIANT & fpu_neon_ext_dotprod | |
24223 | NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s), | |
24224 | NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u), | |
24225 | ||
c921be7d NC |
24226 | #undef ARM_VARIANT |
24227 | #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ | |
53c4b28b MGD |
24228 | #undef THUMB_VARIANT |
24229 | #define THUMB_VARIANT NULL | |
c921be7d | 24230 | |
21d799b5 NC |
24231 | cCE("wfs", e200110, 1, (RR), rd), |
24232 | cCE("rfs", e300110, 1, (RR), rd), | |
24233 | cCE("wfc", e400110, 1, (RR), rd), | |
24234 | cCE("rfc", e500110, 1, (RR), rd), | |
24235 | ||
24236 | cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
24237 | cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
24238 | cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
24239 | cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
24240 | ||
24241 | cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
24242 | cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
24243 | cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
24244 | cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
24245 | ||
24246 | cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm), | |
24247 | cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm), | |
24248 | cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm), | |
24249 | cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm), | |
24250 | cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm), | |
24251 | cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm), | |
24252 | cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm), | |
24253 | cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm), | |
24254 | cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm), | |
24255 | cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm), | |
24256 | cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm), | |
24257 | cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm), | |
24258 | ||
24259 | cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm), | |
24260 | cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm), | |
24261 | cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm), | |
24262 | cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm), | |
24263 | cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm), | |
24264 | cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm), | |
24265 | cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm), | |
24266 | cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm), | |
24267 | cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm), | |
24268 | cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm), | |
24269 | cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm), | |
24270 | cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm), | |
24271 | ||
24272 | cCL("abss", e208100, 2, (RF, RF_IF), rd_rm), | |
24273 | cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm), | |
24274 | cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm), | |
24275 | cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm), | |
24276 | cCL("absd", e208180, 2, (RF, RF_IF), rd_rm), | |
24277 | cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm), | |
24278 | cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm), | |
24279 | cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm), | |
24280 | cCL("abse", e288100, 2, (RF, RF_IF), rd_rm), | |
24281 | cCL("absep", e288120, 2, (RF, RF_IF), rd_rm), | |
24282 | cCL("absem", e288140, 2, (RF, RF_IF), rd_rm), | |
24283 | cCL("absez", e288160, 2, (RF, RF_IF), rd_rm), | |
24284 | ||
24285 | cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm), | |
24286 | cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm), | |
24287 | cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm), | |
24288 | cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm), | |
24289 | cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm), | |
24290 | cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm), | |
24291 | cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm), | |
24292 | cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm), | |
24293 | cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm), | |
24294 | cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm), | |
24295 | cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm), | |
24296 | cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm), | |
24297 | ||
24298 | cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm), | |
24299 | cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm), | |
24300 | cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm), | |
24301 | cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm), | |
24302 | cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm), | |
24303 | cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm), | |
24304 | cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm), | |
24305 | cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm), | |
24306 | cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm), | |
24307 | cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm), | |
24308 | cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm), | |
24309 | cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm), | |
24310 | ||
24311 | cCL("logs", e508100, 2, (RF, RF_IF), rd_rm), | |
24312 | cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm), | |
24313 | cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm), | |
24314 | cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm), | |
24315 | cCL("logd", e508180, 2, (RF, RF_IF), rd_rm), | |
24316 | cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm), | |
24317 | cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm), | |
24318 | cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm), | |
24319 | cCL("loge", e588100, 2, (RF, RF_IF), rd_rm), | |
24320 | cCL("logep", e588120, 2, (RF, RF_IF), rd_rm), | |
24321 | cCL("logem", e588140, 2, (RF, RF_IF), rd_rm), | |
24322 | cCL("logez", e588160, 2, (RF, RF_IF), rd_rm), | |
24323 | ||
24324 | cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm), | |
24325 | cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm), | |
24326 | cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm), | |
24327 | cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm), | |
24328 | cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm), | |
24329 | cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm), | |
24330 | cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm), | |
24331 | cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm), | |
24332 | cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm), | |
24333 | cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm), | |
24334 | cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm), | |
24335 | cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm), | |
24336 | ||
24337 | cCL("exps", e708100, 2, (RF, RF_IF), rd_rm), | |
24338 | cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm), | |
24339 | cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm), | |
24340 | cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm), | |
24341 | cCL("expd", e708180, 2, (RF, RF_IF), rd_rm), | |
24342 | cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm), | |
24343 | cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm), | |
24344 | cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm), | |
24345 | cCL("expe", e788100, 2, (RF, RF_IF), rd_rm), | |
24346 | cCL("expep", e788120, 2, (RF, RF_IF), rd_rm), | |
24347 | cCL("expem", e788140, 2, (RF, RF_IF), rd_rm), | |
24348 | cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm), | |
24349 | ||
24350 | cCL("sins", e808100, 2, (RF, RF_IF), rd_rm), | |
24351 | cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm), | |
24352 | cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm), | |
24353 | cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm), | |
24354 | cCL("sind", e808180, 2, (RF, RF_IF), rd_rm), | |
24355 | cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm), | |
24356 | cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm), | |
24357 | cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm), | |
24358 | cCL("sine", e888100, 2, (RF, RF_IF), rd_rm), | |
24359 | cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm), | |
24360 | cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm), | |
24361 | cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm), | |
24362 | ||
24363 | cCL("coss", e908100, 2, (RF, RF_IF), rd_rm), | |
24364 | cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm), | |
24365 | cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm), | |
24366 | cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm), | |
24367 | cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm), | |
24368 | cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm), | |
24369 | cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm), | |
24370 | cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm), | |
24371 | cCL("cose", e988100, 2, (RF, RF_IF), rd_rm), | |
24372 | cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm), | |
24373 | cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm), | |
24374 | cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm), | |
24375 | ||
24376 | cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm), | |
24377 | cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm), | |
24378 | cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm), | |
24379 | cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm), | |
24380 | cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm), | |
24381 | cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm), | |
24382 | cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm), | |
24383 | cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm), | |
24384 | cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm), | |
24385 | cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm), | |
24386 | cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm), | |
24387 | cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm), | |
24388 | ||
24389 | cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm), | |
24390 | cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm), | |
24391 | cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm), | |
24392 | cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm), | |
24393 | cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm), | |
24394 | cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm), | |
24395 | cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm), | |
24396 | cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm), | |
24397 | cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm), | |
24398 | cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm), | |
24399 | cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm), | |
24400 | cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm), | |
24401 | ||
24402 | cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm), | |
24403 | cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm), | |
24404 | cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm), | |
24405 | cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm), | |
24406 | cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm), | |
24407 | cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm), | |
24408 | cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm), | |
24409 | cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm), | |
24410 | cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm), | |
24411 | cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm), | |
24412 | cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm), | |
24413 | cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm), | |
24414 | ||
24415 | cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm), | |
24416 | cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm), | |
24417 | cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm), | |
24418 | cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm), | |
24419 | cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm), | |
24420 | cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm), | |
24421 | cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm), | |
24422 | cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm), | |
24423 | cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm), | |
24424 | cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm), | |
24425 | cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm), | |
24426 | cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm), | |
24427 | ||
24428 | cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm), | |
24429 | cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm), | |
24430 | cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm), | |
24431 | cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm), | |
24432 | cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm), | |
24433 | cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm), | |
24434 | cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm), | |
24435 | cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm), | |
24436 | cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm), | |
24437 | cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm), | |
24438 | cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm), | |
24439 | cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm), | |
24440 | ||
24441 | cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm), | |
24442 | cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm), | |
24443 | cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm), | |
24444 | cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm), | |
24445 | cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm), | |
24446 | cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm), | |
24447 | cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm), | |
24448 | cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm), | |
24449 | cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm), | |
24450 | cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm), | |
24451 | cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm), | |
24452 | cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm), | |
24453 | ||
24454 | cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24455 | cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24456 | cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24457 | cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24458 | cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24459 | cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24460 | cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24461 | cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24462 | cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24463 | cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24464 | cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24465 | cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24466 | ||
24467 | cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24468 | cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24469 | cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24470 | cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24471 | cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24472 | cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24473 | cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24474 | cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24475 | cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24476 | cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24477 | cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24478 | cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24479 | ||
24480 | cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24481 | cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24482 | cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24483 | cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24484 | cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24485 | cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24486 | cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24487 | cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24488 | cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24489 | cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24490 | cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24491 | cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24492 | ||
24493 | cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24494 | cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24495 | cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24496 | cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24497 | cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24498 | cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24499 | cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24500 | cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24501 | cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24502 | cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24503 | cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24504 | cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24505 | ||
24506 | cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24507 | cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24508 | cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24509 | cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24510 | cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24511 | cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24512 | cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24513 | cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24514 | cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24515 | cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24516 | cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24517 | cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24518 | ||
24519 | cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24520 | cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24521 | cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24522 | cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24523 | cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24524 | cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24525 | cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24526 | cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24527 | cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24528 | cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24529 | cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24530 | cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24531 | ||
24532 | cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24533 | cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24534 | cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24535 | cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24536 | cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24537 | cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24538 | cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24539 | cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24540 | cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24541 | cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24542 | cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24543 | cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24544 | ||
24545 | cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24546 | cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24547 | cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24548 | cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24549 | cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24550 | cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24551 | cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24552 | cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24553 | cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24554 | cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24555 | cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24556 | cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24557 | ||
24558 | cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24559 | cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24560 | cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24561 | cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24562 | cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24563 | cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24564 | cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24565 | cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24566 | cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24567 | cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24568 | cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24569 | cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24570 | ||
24571 | cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24572 | cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24573 | cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24574 | cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24575 | cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24576 | cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24577 | cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24578 | cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24579 | cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24580 | cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24581 | cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24582 | cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24583 | ||
24584 | cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24585 | cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24586 | cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24587 | cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24588 | cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24589 | cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24590 | cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24591 | cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24592 | cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24593 | cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24594 | cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24595 | cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24596 | ||
24597 | cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24598 | cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24599 | cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24600 | cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24601 | cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24602 | cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24603 | cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24604 | cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24605 | cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24606 | cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24607 | cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24608 | cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24609 | ||
24610 | cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24611 | cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24612 | cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24613 | cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24614 | cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24615 | cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24616 | cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24617 | cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24618 | cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24619 | cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24620 | cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24621 | cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
24622 | ||
24623 | cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp), | |
24624 | C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp), | |
24625 | cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp), | |
24626 | C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp), | |
24627 | ||
24628 | cCL("flts", e000110, 2, (RF, RR), rn_rd), | |
24629 | cCL("fltsp", e000130, 2, (RF, RR), rn_rd), | |
24630 | cCL("fltsm", e000150, 2, (RF, RR), rn_rd), | |
24631 | cCL("fltsz", e000170, 2, (RF, RR), rn_rd), | |
24632 | cCL("fltd", e000190, 2, (RF, RR), rn_rd), | |
24633 | cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd), | |
24634 | cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd), | |
24635 | cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd), | |
24636 | cCL("flte", e080110, 2, (RF, RR), rn_rd), | |
24637 | cCL("fltep", e080130, 2, (RF, RR), rn_rd), | |
24638 | cCL("fltem", e080150, 2, (RF, RR), rn_rd), | |
24639 | cCL("fltez", e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 24640 | |
c19d1205 ZW |
24641 | /* The implementation of the FIX instruction is broken on some |
24642 | assemblers, in that it accepts a precision specifier as well as a | |
24643 | rounding specifier, despite the fact that this is meaningless. | |
24644 | To be more compatible, we accept it as well, though of course it | |
24645 | does not set any bits. */ | |
21d799b5 NC |
24646 | cCE("fix", e100110, 2, (RR, RF), rd_rm), |
24647 | cCL("fixp", e100130, 2, (RR, RF), rd_rm), | |
24648 | cCL("fixm", e100150, 2, (RR, RF), rd_rm), | |
24649 | cCL("fixz", e100170, 2, (RR, RF), rd_rm), | |
24650 | cCL("fixsp", e100130, 2, (RR, RF), rd_rm), | |
24651 | cCL("fixsm", e100150, 2, (RR, RF), rd_rm), | |
24652 | cCL("fixsz", e100170, 2, (RR, RF), rd_rm), | |
24653 | cCL("fixdp", e100130, 2, (RR, RF), rd_rm), | |
24654 | cCL("fixdm", e100150, 2, (RR, RF), rd_rm), | |
24655 | cCL("fixdz", e100170, 2, (RR, RF), rd_rm), | |
24656 | cCL("fixep", e100130, 2, (RR, RF), rd_rm), | |
24657 | cCL("fixem", e100150, 2, (RR, RF), rd_rm), | |
24658 | cCL("fixez", e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 24659 | |
c19d1205 | 24660 | /* Instructions that were new with the real FPA, call them V2. */ |
c921be7d NC |
24661 | #undef ARM_VARIANT |
24662 | #define ARM_VARIANT & fpu_fpa_ext_v2 | |
24663 | ||
21d799b5 NC |
24664 | cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
24665 | cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
24666 | cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
24667 | cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
24668 | cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
24669 | cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 | 24670 | |
c921be7d NC |
24671 | #undef ARM_VARIANT |
24672 | #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ | |
ba6cd17f SD |
24673 | #undef THUMB_VARIANT |
24674 | #define THUMB_VARIANT & arm_ext_v6t2 | |
24675 | mcCE(vmrs, ef00a10, 2, (APSR_RR, RVC), vmrs), | |
24676 | mcCE(vmsr, ee00a10, 2, (RVC, RR), vmsr), | |
24677 | #undef THUMB_VARIANT | |
c921be7d | 24678 | |
c19d1205 | 24679 | /* Moves and type conversions. */ |
21d799b5 NC |
24680 | cCE("fmstat", ef1fa10, 0, (), noargs), |
24681 | cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
24682 | cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
24683 | cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
24684 | cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
24685 | cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
24686 | cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
24687 | cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn), | |
24688 | cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
24689 | |
24690 | /* Memory operations. */ | |
21d799b5 NC |
24691 | cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), |
24692 | cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), | |
55881a11 MGD |
24693 | cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), |
24694 | cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
24695 | cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
24696 | cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
24697 | cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
24698 | cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
24699 | cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
24700 | cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
24701 | cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
24702 | cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
24703 | cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
24704 | cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
24705 | cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
24706 | cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
24707 | cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
24708 | cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 24709 | |
c19d1205 | 24710 | /* Monadic operations. */ |
21d799b5 NC |
24711 | cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
24712 | cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
24713 | cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
24714 | |
24715 | /* Dyadic operations. */ | |
21d799b5 NC |
24716 | cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
24717 | cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
24718 | cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
24719 | cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
24720 | cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
24721 | cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
24722 | cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
24723 | cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
24724 | cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 24725 | |
c19d1205 | 24726 | /* Comparisons. */ |
21d799b5 NC |
24727 | cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
24728 | cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z), | |
24729 | cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
24730 | cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 24731 | |
62f3b8c8 PB |
24732 | /* Double precision load/store are still present on single precision |
24733 | implementations. */ | |
24734 | cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
24735 | cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
55881a11 MGD |
24736 | cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), |
24737 | cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
24738 | cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
24739 | cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
24740 | cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
24741 | cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
24742 | cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
24743 | cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
62f3b8c8 | 24744 | |
c921be7d NC |
24745 | #undef ARM_VARIANT |
24746 | #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ | |
24747 | ||
c19d1205 | 24748 | /* Moves and type conversions. */ |
21d799b5 NC |
24749 | cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), |
24750 | cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
24751 | cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
24752 | cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
24753 | cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
24754 | cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
24755 | cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
24756 | cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
24757 | cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
24758 | cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
24759 | cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
24760 | cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 | 24761 | |
c19d1205 | 24762 | /* Monadic operations. */ |
21d799b5 NC |
24763 | cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm), |
24764 | cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm), | |
24765 | cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
c19d1205 ZW |
24766 | |
24767 | /* Dyadic operations. */ | |
21d799b5 NC |
24768 | cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), |
24769 | cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
24770 | cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
24771 | cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
24772 | cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
24773 | cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
24774 | cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
24775 | cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
24776 | cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
b99bd4ef | 24777 | |
c19d1205 | 24778 | /* Comparisons. */ |
21d799b5 NC |
24779 | cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
24780 | cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd), | |
24781 | cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
24782 | cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd), | |
c19d1205 | 24783 | |
037e8744 JB |
24784 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
24785 | Individual encoder functions perform additional architecture checks. */ | |
c921be7d NC |
24786 | #undef ARM_VARIANT |
24787 | #define ARM_VARIANT & fpu_vfp_ext_v1xd | |
24788 | #undef THUMB_VARIANT | |
24789 | #define THUMB_VARIANT & fpu_vfp_ext_v1xd | |
24790 | ||
037e8744 JB |
24791 | /* These mnemonics are unique to VFP. */ |
24792 | NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt), | |
24793 | NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div), | |
21d799b5 NC |
24794 | nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), |
24795 | nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
24796 | nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
037e8744 JB |
24797 | NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push), |
24798 | NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop), | |
24799 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), | |
24800 | ||
24801 | /* Mnemonics shared by Neon and VFP. */ | |
21d799b5 | 24802 | nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), |
037e8744 | 24803 | |
55881a11 MGD |
24804 | NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), |
24805 | NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
24806 | NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
24807 | NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
24808 | NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
24809 | NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
037e8744 | 24810 | |
dd9634d9 | 24811 | mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt), |
e3e535bc | 24812 | nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr), |
dd9634d9 AV |
24813 | MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb), |
24814 | MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt), | |
f31fef98 | 24815 | |
037e8744 JB |
24816 | |
24817 | /* NOTE: All VMOV encoding is special-cased! */ | |
037e8744 JB |
24818 | NCE(vmovq, 0, 1, (VMOV), neon_mov), |
24819 | ||
32c36c3c AV |
24820 | #undef THUMB_VARIANT |
24821 | /* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded | |
24822 | by different feature bits. Since we are setting the Thumb guard, we can | |
24823 | require Thumb-1 which makes it a nop guard and set the right feature bit in | |
24824 | do_vldr_vstr (). */ | |
24825 | #define THUMB_VARIANT & arm_ext_v4t | |
24826 | NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr), | |
24827 | NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr), | |
24828 | ||
9db2f6b4 RL |
24829 | #undef ARM_VARIANT |
24830 | #define ARM_VARIANT & arm_ext_fp16 | |
24831 | #undef THUMB_VARIANT | |
24832 | #define THUMB_VARIANT & arm_ext_fp16 | |
24833 | /* New instructions added from v8.2, allowing the extraction and insertion of | |
24834 | the upper 16 bits of a 32-bit vector register. */ | |
24835 | NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf), | |
24836 | NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf), | |
24837 | ||
dec41383 JW |
24838 | /* New backported fma/fms instructions optional in v8.2. */ |
24839 | NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal), | |
24840 | NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl), | |
24841 | ||
c921be7d NC |
24842 | #undef THUMB_VARIANT |
24843 | #define THUMB_VARIANT & fpu_neon_ext_v1 | |
24844 | #undef ARM_VARIANT | |
24845 | #define ARM_VARIANT & fpu_neon_ext_v1 | |
24846 | ||
5287ad62 JB |
24847 | /* Data processing with three registers of the same length. */ |
24848 | /* integer ops, valid types S8 S16 S32 U8 U16 U32. */ | |
24849 | NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su), | |
24850 | NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su), | |
5287ad62 | 24851 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), |
5287ad62 | 24852 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), |
5287ad62 JB |
24853 | NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), |
24854 | /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */ | |
5287ad62 | 24855 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), |
5287ad62 | 24856 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), |
627907b7 | 24857 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl), |
627907b7 | 24858 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl), |
5287ad62 | 24859 | /* If not immediate, fall back to neon_dyadic_i64_su. |
5150f0d8 AV |
24860 | shl should accept I8 I16 I32 I64, |
24861 | qshl should accept S8 S16 S32 S64 U8 U16 U32 U64. */ | |
24862 | nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl), | |
24863 | nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl), | |
5287ad62 | 24864 | /* Logic ops, types optional & ignored. */ |
4316f0d2 | 24865 | nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), |
4316f0d2 | 24866 | nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), |
4316f0d2 | 24867 | nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), |
4316f0d2 | 24868 | nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), |
4316f0d2 | 24869 | nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic), |
5287ad62 JB |
24870 | /* Bitfield ops, untyped. */ |
24871 | NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
24872 | NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
24873 | NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
24874 | NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
24875 | NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
24876 | NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
cc933301 | 24877 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */ |
21d799b5 | 24878 | nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), |
21d799b5 | 24879 | nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), |
21d799b5 | 24880 | nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), |
5287ad62 JB |
24881 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall |
24882 | back to neon_dyadic_if_su. */ | |
21d799b5 NC |
24883 | nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), |
24884 | nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
24885 | nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
24886 | nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
24887 | nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
24888 | nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
24889 | nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
24890 | nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
428e3f1f | 24891 | /* Comparison. Type I8 I16 I32 F32. */ |
21d799b5 NC |
24892 | nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), |
24893 | nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
5287ad62 | 24894 | /* As above, D registers only. */ |
21d799b5 NC |
24895 | nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d), |
24896 | nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
5287ad62 | 24897 | /* Int and float variants, signedness unimportant. */ |
21d799b5 NC |
24898 | nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
24899 | nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), | |
24900 | nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d), | |
5287ad62 | 24901 | /* Add/sub take types I8 I16 I32 I64 F32. */ |
21d799b5 NC |
24902 | nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
24903 | nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), | |
5287ad62 JB |
24904 | /* vtst takes sizes 8, 16, 32. */ |
24905 | NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst), | |
24906 | NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst), | |
24907 | /* VMUL takes I8 I16 I32 F32 P8. */ | |
21d799b5 | 24908 | nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 | 24909 | /* VQD{R}MULH takes S16 S32. */ |
21d799b5 | 24910 | nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), |
21d799b5 | 24911 | nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), |
5287ad62 JB |
24912 | NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), |
24913 | NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
24914 | NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
24915 | NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
92559b5b PB |
24916 | NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), |
24917 | NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
24918 | NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
24919 | NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
5287ad62 JB |
24920 | NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), |
24921 | NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
24922 | NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
24923 | NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
d6b4b13e | 24924 | /* ARM v8.1 extension. */ |
643afb90 MW |
24925 | nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah), |
24926 | nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah), | |
24927 | nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah), | |
5287ad62 JB |
24928 | |
24929 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 24930 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
24931 | NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg), |
24932 | ||
24933 | /* Data processing with two registers and a shift amount. */ | |
24934 | /* Right shifts, and variants with rounding. | |
24935 | Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */ | |
5287ad62 | 24936 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), |
5287ad62 JB |
24937 | NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), |
24938 | NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
24939 | NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
24940 | NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
24941 | NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
24942 | /* Shift and insert. Sizes accepted 8 16 32 64. */ | |
5287ad62 | 24943 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), |
5287ad62 JB |
24944 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), |
24945 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
5287ad62 JB |
24946 | NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm), |
24947 | /* Right shift immediate, saturating & narrowing, with rounding variants. | |
24948 | Types accepted S16 S32 S64 U16 U32 U64. */ | |
24949 | NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
24950 | NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
24951 | /* As above, unsigned. Types accepted S16 S32 S64. */ | |
24952 | NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
24953 | NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
24954 | /* Right shift narrowing. Types accepted I16 I32 I64. */ | |
24955 | NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
24956 | NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
24957 | /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */ | |
21d799b5 | 24958 | nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll), |
5287ad62 | 24959 | /* CVT with optional immediate for fixed-point variant. */ |
21d799b5 | 24960 | nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 24961 | |
4316f0d2 | 24962 | nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn), |
5287ad62 JB |
24963 | |
24964 | /* Data processing, three registers of different lengths. */ | |
24965 | /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */ | |
24966 | NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal), | |
5287ad62 JB |
24967 | /* If not scalar, fall back to neon_dyadic_long. |
24968 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
21d799b5 NC |
24969 | nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), |
24970 | nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
5287ad62 JB |
24971 | /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */ |
24972 | NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
24973 | NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
24974 | /* Dyadic, narrowing insns. Types I16 I32 I64. */ | |
24975 | NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
24976 | NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
24977 | NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
24978 | NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
24979 | /* Saturating doubling multiplies. Types S16 S32. */ | |
21d799b5 NC |
24980 | nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), |
24981 | nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
24982 | nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
5287ad62 JB |
24983 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types |
24984 | S16 S32 U16 U32. */ | |
21d799b5 | 24985 | nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), |
5287ad62 JB |
24986 | |
24987 | /* Extract. Size 8. */ | |
3b8d421e PB |
24988 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext), |
24989 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext), | |
5287ad62 JB |
24990 | |
24991 | /* Two registers, miscellaneous. */ | |
24992 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
5287ad62 | 24993 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), |
5287ad62 | 24994 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), |
5287ad62 JB |
24995 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), |
24996 | /* Vector replicate. Sizes 8 16 32. */ | |
21d799b5 | 24997 | nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup), |
5287ad62 JB |
24998 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ |
24999 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
25000 | /* VMOVN. Types I16 I32 I64. */ | |
21d799b5 | 25001 | nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn), |
5287ad62 | 25002 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ |
21d799b5 | 25003 | nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn), |
5287ad62 | 25004 | /* VQMOVUN. Types S16 S32 S64. */ |
21d799b5 | 25005 | nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun), |
5287ad62 JB |
25006 | /* VZIP / VUZP. Sizes 8 16 32. */ |
25007 | NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
25008 | NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp), | |
25009 | NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
25010 | NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp), | |
25011 | /* VQABS / VQNEG. Types S8 S16 S32. */ | |
5287ad62 | 25012 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), |
5287ad62 JB |
25013 | NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg), |
25014 | /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */ | |
25015 | NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long), | |
25016 | NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long), | |
25017 | NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long), | |
25018 | NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long), | |
cc933301 | 25019 | /* Reciprocal estimates. Types U32 F16 F32. */ |
5287ad62 JB |
25020 | NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est), |
25021 | NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est), | |
25022 | NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est), | |
25023 | NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est), | |
25024 | /* VCLS. Types S8 S16 S32. */ | |
5287ad62 JB |
25025 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), |
25026 | /* VCLZ. Types I8 I16 I32. */ | |
5287ad62 JB |
25027 | NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz), |
25028 | /* VCNT. Size 8. */ | |
25029 | NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt), | |
25030 | NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt), | |
25031 | /* Two address, untyped. */ | |
25032 | NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp), | |
25033 | NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp), | |
25034 | /* VTRN. Sizes 8 16 32. */ | |
21d799b5 NC |
25035 | nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn), |
25036 | nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn), | |
5287ad62 JB |
25037 | |
25038 | /* Table lookup. Size 8. */ | |
25039 | NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
25040 | NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
25041 | ||
c921be7d NC |
25042 | #undef THUMB_VARIANT |
25043 | #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext | |
25044 | #undef ARM_VARIANT | |
25045 | #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext | |
25046 | ||
5287ad62 | 25047 | /* Neon element/structure load/store. */ |
21d799b5 NC |
25048 | nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx), |
25049 | nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
25050 | nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
25051 | nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
25052 | nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
25053 | nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
25054 | nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
25055 | nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
5287ad62 | 25056 | |
c921be7d | 25057 | #undef THUMB_VARIANT |
74db7efb NC |
25058 | #define THUMB_VARIANT & fpu_vfp_ext_v3xd |
25059 | #undef ARM_VARIANT | |
25060 | #define ARM_VARIANT & fpu_vfp_ext_v3xd | |
62f3b8c8 PB |
25061 | cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const), |
25062 | cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
25063 | cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
25064 | cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
25065 | cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
25066 | cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
25067 | cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
25068 | cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
25069 | cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
25070 | ||
74db7efb | 25071 | #undef THUMB_VARIANT |
c921be7d NC |
25072 | #define THUMB_VARIANT & fpu_vfp_ext_v3 |
25073 | #undef ARM_VARIANT | |
25074 | #define ARM_VARIANT & fpu_vfp_ext_v3 | |
25075 | ||
21d799b5 | 25076 | cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const), |
21d799b5 | 25077 | cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 25078 | cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 25079 | cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 25080 | cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 25081 | cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 25082 | cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 25083 | cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 25084 | cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
c19d1205 | 25085 | |
74db7efb NC |
25086 | #undef ARM_VARIANT |
25087 | #define ARM_VARIANT & fpu_vfp_ext_fma | |
25088 | #undef THUMB_VARIANT | |
25089 | #define THUMB_VARIANT & fpu_vfp_ext_fma | |
d58196e0 | 25090 | /* Mnemonics shared by Neon, VFP and MVE. These are included in the |
62f3b8c8 PB |
25091 | VFP FMA variant; NEON and VFP FMA always includes the NEON |
25092 | FMA instructions. */ | |
d58196e0 AV |
25093 | mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac), |
25094 | mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac), | |
25095 | ||
62f3b8c8 PB |
25096 | /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas; |
25097 | the v form should always be used. */ | |
25098 | cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
25099 | cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
25100 | cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
25101 | cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
25102 | nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
25103 | nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
25104 | ||
5287ad62 | 25105 | #undef THUMB_VARIANT |
c921be7d NC |
25106 | #undef ARM_VARIANT |
25107 | #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */ | |
25108 | ||
21d799b5 NC |
25109 | cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
25110 | cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
25111 | cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
25112 | cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
25113 | cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
25114 | cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
25115 | cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
25116 | cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 | 25117 | |
c921be7d NC |
25118 | #undef ARM_VARIANT |
25119 | #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */ | |
25120 | ||
21d799b5 NC |
25121 | cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc), |
25122 | cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc), | |
25123 | cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc), | |
25124 | cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd), | |
25125 | cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd), | |
25126 | cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd), | |
25127 | cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc), | |
25128 | cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc), | |
25129 | cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc), | |
74db7efb NC |
25130 | cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), |
25131 | cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
25132 | cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
25133 | cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
25134 | cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
25135 | cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
21d799b5 NC |
25136 | cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), |
25137 | cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
25138 | cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
25139 | cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd), | |
25140 | cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn), | |
25141 | cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
25142 | cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
25143 | cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
25144 | cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
25145 | cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
25146 | cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
74db7efb NC |
25147 | cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn), |
25148 | cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn), | |
25149 | cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn), | |
21d799b5 NC |
25150 | cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn), |
25151 | cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm), | |
25152 | cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc), | |
25153 | cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc), | |
25154 | cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc), | |
25155 | cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn), | |
25156 | cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn), | |
25157 | cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn), | |
25158 | cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25159 | cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25160 | cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25161 | cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25162 | cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25163 | cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25164 | cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25165 | cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25166 | cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25167 | cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
74db7efb NC |
25168 | cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
25169 | cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25170 | cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25171 | cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
25172 | cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
25173 | cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25174 | cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25175 | cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25176 | cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25177 | cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25178 | cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25179 | cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25180 | cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
74db7efb NC |
25181 | cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
25182 | cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25183 | cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25184 | cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25185 | cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25186 | cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
25187 | cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), |
25188 | cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
25189 | cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
25190 | cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
25191 | cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25192 | cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25193 | cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25194 | cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25195 | cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25196 | cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25197 | cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25198 | cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25199 | cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25200 | cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25201 | cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25202 | cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25203 | cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25204 | cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25205 | cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25206 | cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25207 | cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25208 | cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25209 | cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
25210 | cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25211 | cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25212 | cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25213 | cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25214 | cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
74db7efb NC |
25215 | cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
25216 | cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25217 | cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25218 | cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25219 | cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25220 | cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
25221 | cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
25222 | cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
25223 | cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
25224 | cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
25225 | cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
25226 | cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
25227 | cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25228 | cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25229 | cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25230 | cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25231 | cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
25232 | cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
25233 | cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
25234 | cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
25235 | cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
25236 | cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
25237 | cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
25238 | cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
25239 | cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
25240 | cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
25241 | cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
25242 | cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
25243 | cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
25244 | cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
25245 | cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
25246 | cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
25247 | cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
25248 | cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
25249 | cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
25250 | cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
25251 | cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
25252 | cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
25253 | cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
25254 | cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25255 | cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25256 | cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25257 | cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25258 | cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25259 | cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25260 | cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25261 | cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25262 | cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25263 | cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn), | |
25264 | cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn), | |
25265 | cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn), | |
25266 | cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn), | |
25267 | cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn), | |
25268 | cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn), | |
25269 | cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25270 | cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25271 | cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25272 | cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn), | |
25273 | cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn), | |
25274 | cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn), | |
25275 | cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn), | |
25276 | cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn), | |
25277 | cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn), | |
25278 | cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25279 | cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25280 | cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25281 | cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25282 | cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 | 25283 | |
c921be7d NC |
25284 | #undef ARM_VARIANT |
25285 | #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */ | |
25286 | ||
21d799b5 NC |
25287 | cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc), |
25288 | cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc), | |
25289 | cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc), | |
25290 | cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn), | |
25291 | cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn), | |
25292 | cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn), | |
25293 | cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25294 | cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25295 | cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25296 | cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25297 | cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25298 | cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25299 | cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25300 | cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25301 | cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25302 | cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25303 | cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25304 | cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25305 | cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25306 | cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25307 | cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge), | |
25308 | cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25309 | cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25310 | cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25311 | cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25312 | cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25313 | cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25314 | cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25315 | cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25316 | cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25317 | cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25318 | cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25319 | cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25320 | cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25321 | cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25322 | cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25323 | cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25324 | cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25325 | cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25326 | cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25327 | cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25328 | cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25329 | cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25330 | cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25331 | cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25332 | cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25333 | cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25334 | cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25335 | cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25336 | cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25337 | cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25338 | cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25339 | cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25340 | cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25341 | cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25342 | cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
25343 | cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
2d447fca | 25344 | |
c921be7d NC |
25345 | #undef ARM_VARIANT |
25346 | #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */ | |
25347 | ||
21d799b5 NC |
25348 | cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr), |
25349 | cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
25350 | cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
25351 | cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
25352 | cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr), | |
25353 | cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
25354 | cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
25355 | cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
25356 | cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd), | |
25357 | cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn), | |
25358 | cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd), | |
25359 | cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn), | |
25360 | cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd), | |
25361 | cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn), | |
74db7efb NC |
25362 | cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd), |
25363 | cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn), | |
25364 | cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd), | |
25365 | cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn), | |
25366 | cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn), | |
25367 | cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn), | |
25368 | cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn), | |
25369 | cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn), | |
25370 | cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn), | |
25371 | cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn), | |
21d799b5 NC |
25372 | cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn), |
25373 | cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn), | |
25374 | cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn), | |
25375 | cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn), | |
74db7efb NC |
25376 | cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc), |
25377 | cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd), | |
21d799b5 NC |
25378 | cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn), |
25379 | cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn), | |
25380 | cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn), | |
25381 | cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn), | |
74db7efb NC |
25382 | cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn), |
25383 | cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn), | |
25384 | cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn), | |
25385 | cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn), | |
25386 | cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn), | |
25387 | cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn), | |
21d799b5 NC |
25388 | cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn), |
25389 | cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn), | |
74db7efb NC |
25390 | cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple), |
25391 | cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
21d799b5 NC |
25392 | cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift), |
25393 | cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
25394 | cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
25395 | cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
25396 | cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
25397 | cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
25398 | cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn), | |
25399 | cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn), | |
25400 | cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn), | |
25401 | cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn), | |
25402 | cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
25403 | cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
25404 | cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
25405 | cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
25406 | cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
25407 | cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
25408 | cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn), | |
25409 | cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn), | |
25410 | cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn), | |
25411 | cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn), | |
25412 | cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
25413 | cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
25414 | cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
25415 | cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
25416 | cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
25417 | cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
25418 | cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
25419 | cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
74db7efb NC |
25420 | cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), |
25421 | cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
21d799b5 NC |
25422 | cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), |
25423 | cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
4ed7ed8d | 25424 | |
7fadb25d SD |
25425 | /* ARMv8.5-A instructions. */ |
25426 | #undef ARM_VARIANT | |
25427 | #define ARM_VARIANT & arm_ext_sb | |
25428 | #undef THUMB_VARIANT | |
25429 | #define THUMB_VARIANT & arm_ext_sb | |
25430 | TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs), | |
25431 | ||
dad0c3bf SD |
25432 | #undef ARM_VARIANT |
25433 | #define ARM_VARIANT & arm_ext_predres | |
25434 | #undef THUMB_VARIANT | |
25435 | #define THUMB_VARIANT & arm_ext_predres | |
25436 | CE("cfprctx", e070f93, 1, (RRnpc), rd), | |
25437 | CE("dvprctx", e070fb3, 1, (RRnpc), rd), | |
25438 | CE("cpprctx", e070ff3, 1, (RRnpc), rd), | |
25439 | ||
16a1fa25 | 25440 | /* ARMv8-M instructions. */ |
4ed7ed8d TP |
25441 | #undef ARM_VARIANT |
25442 | #define ARM_VARIANT NULL | |
25443 | #undef THUMB_VARIANT | |
25444 | #define THUMB_VARIANT & arm_ext_v8m | |
cf3cf39d TP |
25445 | ToU("sg", e97fe97f, 0, (), noargs), |
25446 | ToC("blxns", 4784, 1, (RRnpc), t_blx), | |
25447 | ToC("bxns", 4704, 1, (RRnpc), t_bx), | |
25448 | ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt), | |
25449 | ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt), | |
25450 | ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt), | |
25451 | ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt), | |
16a1fa25 TP |
25452 | |
25453 | /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the | |
25454 | instructions behave as nop if no VFP is present. */ | |
25455 | #undef THUMB_VARIANT | |
25456 | #define THUMB_VARIANT & arm_ext_v8m_main | |
cf3cf39d TP |
25457 | ToC("vlldm", ec300a00, 1, (RRnpc), rn), |
25458 | ToC("vlstm", ec200a00, 1, (RRnpc), rn), | |
4389b29a AV |
25459 | |
25460 | /* Armv8.1-M Mainline instructions. */ | |
25461 | #undef THUMB_VARIANT | |
25462 | #define THUMB_VARIANT & arm_ext_v8_1m_main | |
e39c1607 SD |
25463 | toU("cinc", _cinc, 3, (RRnpcsp, RR_ZR, COND), t_cond), |
25464 | toU("cinv", _cinv, 3, (RRnpcsp, RR_ZR, COND), t_cond), | |
25465 | toU("cneg", _cneg, 3, (RRnpcsp, RR_ZR, COND), t_cond), | |
25466 | toU("csel", _csel, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond), | |
25467 | toU("csetm", _csetm, 2, (RRnpcsp, COND), t_cond), | |
25468 | toU("cset", _cset, 2, (RRnpcsp, COND), t_cond), | |
25469 | toU("csinc", _csinc, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond), | |
25470 | toU("csinv", _csinv, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond), | |
25471 | toU("csneg", _csneg, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond), | |
25472 | ||
4389b29a | 25473 | toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future), |
f6b2b12d | 25474 | toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future), |
f1c7f421 | 25475 | toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future), |
65d1bc05 | 25476 | toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future), |
f1c7f421 | 25477 | toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future), |
60f993ce AV |
25478 | |
25479 | toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop), | |
25480 | toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop), | |
25481 | toU("le", _le, 2, (oLR, EXP), t_loloop), | |
4b5a202f | 25482 | |
efd6b359 | 25483 | ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm), |
5ee91343 AV |
25484 | ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm), |
25485 | ||
25486 | #undef THUMB_VARIANT | |
25487 | #define THUMB_VARIANT & mve_ext | |
23d00a41 SD |
25488 | ToC("lsll", ea50010d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift), |
25489 | ToC("lsrl", ea50011f, 3, (RRe, RRo, I32), mve_scalar_shift), | |
25490 | ToC("asrl", ea50012d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift), | |
08132bdd SP |
25491 | ToC("uqrshll", ea51010d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1), |
25492 | ToC("sqrshrl", ea51012d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1), | |
23d00a41 SD |
25493 | ToC("uqshll", ea51010f, 3, (RRe, RRo, I32), mve_scalar_shift), |
25494 | ToC("urshrl", ea51011f, 3, (RRe, RRo, I32), mve_scalar_shift), | |
25495 | ToC("srshrl", ea51012f, 3, (RRe, RRo, I32), mve_scalar_shift), | |
25496 | ToC("sqshll", ea51013f, 3, (RRe, RRo, I32), mve_scalar_shift), | |
25497 | ToC("uqrshl", ea500f0d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift), | |
25498 | ToC("sqrshr", ea500f2d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift), | |
25499 | ToC("uqshl", ea500f0f, 2, (RRnpcsp, I32), mve_scalar_shift), | |
25500 | ToC("urshr", ea500f1f, 2, (RRnpcsp, I32), mve_scalar_shift), | |
25501 | ToC("srshr", ea500f2f, 2, (RRnpcsp, I32), mve_scalar_shift), | |
25502 | ToC("sqshl", ea500f3f, 2, (RRnpcsp, I32), mve_scalar_shift), | |
1b883319 AV |
25503 | |
25504 | ToC("vpt", ee410f00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25505 | ToC("vptt", ee018f00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25506 | ToC("vpte", ee418f00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25507 | ToC("vpttt", ee014f00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25508 | ToC("vptte", ee01cf00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25509 | ToC("vptet", ee41cf00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25510 | ToC("vptee", ee414f00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25511 | ToC("vptttt", ee012f00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25512 | ToC("vpttte", ee016f00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25513 | ToC("vpttet", ee01ef00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25514 | ToC("vpttee", ee01af00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25515 | ToC("vptett", ee41af00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25516 | ToC("vptete", ee41ef00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25517 | ToC("vpteet", ee416f00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25518 | ToC("vpteee", ee412f00, 3, (COND, RMQ, RMQRZ), mve_vpt), | |
25519 | ||
5ee91343 AV |
25520 | ToC("vpst", fe710f4d, 0, (), mve_vpt), |
25521 | ToC("vpstt", fe318f4d, 0, (), mve_vpt), | |
25522 | ToC("vpste", fe718f4d, 0, (), mve_vpt), | |
25523 | ToC("vpsttt", fe314f4d, 0, (), mve_vpt), | |
25524 | ToC("vpstte", fe31cf4d, 0, (), mve_vpt), | |
25525 | ToC("vpstet", fe71cf4d, 0, (), mve_vpt), | |
25526 | ToC("vpstee", fe714f4d, 0, (), mve_vpt), | |
25527 | ToC("vpstttt", fe312f4d, 0, (), mve_vpt), | |
25528 | ToC("vpsttte", fe316f4d, 0, (), mve_vpt), | |
25529 | ToC("vpsttet", fe31ef4d, 0, (), mve_vpt), | |
25530 | ToC("vpsttee", fe31af4d, 0, (), mve_vpt), | |
25531 | ToC("vpstett", fe71af4d, 0, (), mve_vpt), | |
25532 | ToC("vpstete", fe71ef4d, 0, (), mve_vpt), | |
25533 | ToC("vpsteet", fe716f4d, 0, (), mve_vpt), | |
25534 | ToC("vpsteee", fe712f4d, 0, (), mve_vpt), | |
25535 | ||
a302e574 | 25536 | /* MVE and MVE FP only. */ |
7df54120 | 25537 | mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd), |
efd0b310 | 25538 | mCEF(vctp, _vctp, 1, (RRnpc), mve_vctp), |
c2dafc2a AV |
25539 | mCEF(vadc, _vadc, 3, (RMQ, RMQ, RMQ), mve_vadc), |
25540 | mCEF(vadci, _vadci, 3, (RMQ, RMQ, RMQ), mve_vadc), | |
25541 | mToC("vsbc", fe300f00, 3, (RMQ, RMQ, RMQ), mve_vsbc), | |
25542 | mToC("vsbci", fe301f00, 3, (RMQ, RMQ, RMQ), mve_vsbc), | |
886e1c73 | 25543 | mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull), |
a302e574 AV |
25544 | mCEF(vabav, _vabav, 3, (RRnpcsp, RMQ, RMQ), mve_vabav), |
25545 | mCEF(vmladav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav), | |
25546 | mCEF(vmladava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav), | |
25547 | mCEF(vmladavx, _vmladavx, 3, (RRe, RMQ, RMQ), mve_vmladav), | |
25548 | mCEF(vmladavax, _vmladavax, 3, (RRe, RMQ, RMQ), mve_vmladav), | |
25549 | mCEF(vmlav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav), | |
25550 | mCEF(vmlava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav), | |
25551 | mCEF(vmlsdav, _vmlsdav, 3, (RRe, RMQ, RMQ), mve_vmladav), | |
25552 | mCEF(vmlsdava, _vmlsdava, 3, (RRe, RMQ, RMQ), mve_vmladav), | |
25553 | mCEF(vmlsdavx, _vmlsdavx, 3, (RRe, RMQ, RMQ), mve_vmladav), | |
25554 | mCEF(vmlsdavax, _vmlsdavax, 3, (RRe, RMQ, RMQ), mve_vmladav), | |
25555 | ||
35c228db AV |
25556 | mCEF(vst20, _vst20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld), |
25557 | mCEF(vst21, _vst21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld), | |
25558 | mCEF(vst40, _vst40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld), | |
25559 | mCEF(vst41, _vst41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld), | |
25560 | mCEF(vst42, _vst42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld), | |
25561 | mCEF(vst43, _vst43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld), | |
25562 | mCEF(vld20, _vld20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld), | |
25563 | mCEF(vld21, _vld21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld), | |
25564 | mCEF(vld40, _vld40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld), | |
25565 | mCEF(vld41, _vld41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld), | |
25566 | mCEF(vld42, _vld42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld), | |
25567 | mCEF(vld43, _vld43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld), | |
f5f10c66 AV |
25568 | mCEF(vstrb, _vstrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr), |
25569 | mCEF(vstrh, _vstrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr), | |
25570 | mCEF(vstrw, _vstrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr), | |
25571 | mCEF(vstrd, _vstrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr), | |
25572 | mCEF(vldrb, _vldrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr), | |
25573 | mCEF(vldrh, _vldrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr), | |
25574 | mCEF(vldrw, _vldrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr), | |
25575 | mCEF(vldrd, _vldrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr), | |
35c228db | 25576 | |
57785aa2 AV |
25577 | mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn), |
25578 | mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn), | |
c2dafc2a | 25579 | mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr), |
26c1e780 AV |
25580 | mCEF(vaddlv, _vaddlv, 3, (RRe, RRo, RMQ), mve_vaddlv), |
25581 | mCEF(vaddlva, _vaddlva, 3, (RRe, RRo, RMQ), mve_vaddlv), | |
25582 | mCEF(vaddv, _vaddv, 2, (RRe, RMQ), mve_vaddv), | |
25583 | mCEF(vaddva, _vaddva, 2, (RRe, RMQ), mve_vaddv), | |
b409bdb6 AV |
25584 | mCEF(vddup, _vddup, 3, (RMQ, RRe, EXPi), mve_viddup), |
25585 | mCEF(vdwdup, _vdwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup), | |
25586 | mCEF(vidup, _vidup, 3, (RMQ, RRe, EXPi), mve_viddup), | |
25587 | mCEF(viwdup, _viwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup), | |
935295b5 AV |
25588 | mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina), |
25589 | mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina), | |
13ccd4c0 AV |
25590 | mCEF(vmaxv, _vmaxv, 2, (RR, RMQ), mve_vmaxv), |
25591 | mCEF(vmaxav, _vmaxav, 2, (RR, RMQ), mve_vmaxv), | |
25592 | mCEF(vminv, _vminv, 2, (RR, RMQ), mve_vmaxv), | |
25593 | mCEF(vminav, _vminav, 2, (RR, RMQ), mve_vmaxv), | |
57785aa2 | 25594 | |
93925576 AV |
25595 | mCEF(vmlaldav, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav), |
25596 | mCEF(vmlaldava, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav), | |
25597 | mCEF(vmlaldavx, _vmlaldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav), | |
25598 | mCEF(vmlaldavax, _vmlaldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav), | |
25599 | mCEF(vmlalv, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav), | |
25600 | mCEF(vmlalva, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav), | |
25601 | mCEF(vmlsldav, _vmlsldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav), | |
25602 | mCEF(vmlsldava, _vmlsldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav), | |
25603 | mCEF(vmlsldavx, _vmlsldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav), | |
25604 | mCEF(vmlsldavax, _vmlsldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav), | |
25605 | mToC("vrmlaldavh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh), | |
25606 | mToC("vrmlaldavha",ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh), | |
25607 | mCEF(vrmlaldavhx, _vrmlaldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh), | |
25608 | mCEF(vrmlaldavhax, _vrmlaldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh), | |
25609 | mToC("vrmlalvh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh), | |
25610 | mToC("vrmlalvha", ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh), | |
25611 | mCEF(vrmlsldavh, _vrmlsldavh, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh), | |
25612 | mCEF(vrmlsldavha, _vrmlsldavha, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh), | |
25613 | mCEF(vrmlsldavhx, _vrmlsldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh), | |
25614 | mCEF(vrmlsldavhax, _vrmlsldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh), | |
25615 | ||
2d78f95b AV |
25616 | mToC("vmlas", ee011e40, 3, (RMQ, RMQ, RR), mve_vmlas), |
25617 | mToC("vmulh", ee010e01, 3, (RMQ, RMQ, RMQ), mve_vmulh), | |
25618 | mToC("vrmulh", ee011e01, 3, (RMQ, RMQ, RMQ), mve_vmulh), | |
3063888e AV |
25619 | mToC("vpnot", fe310f4d, 0, (), mve_vpnot), |
25620 | mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel), | |
2d78f95b | 25621 | |
8b8b22a4 AV |
25622 | mToC("vqdmladh", ee000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh), |
25623 | mToC("vqdmladhx", ee001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh), | |
25624 | mToC("vqrdmladh", ee000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh), | |
25625 | mToC("vqrdmladhx",ee001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh), | |
25626 | mToC("vqdmlsdh", fe000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh), | |
25627 | mToC("vqdmlsdhx", fe001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh), | |
25628 | mToC("vqrdmlsdh", fe000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh), | |
25629 | mToC("vqrdmlsdhx",fe001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh), | |
42b16635 AV |
25630 | mToC("vqdmlah", ee000e60, 3, (RMQ, RMQ, RR), mve_vqdmlah), |
25631 | mToC("vqdmlash", ee001e60, 3, (RMQ, RMQ, RR), mve_vqdmlah), | |
25632 | mToC("vqrdmlash", ee001e40, 3, (RMQ, RMQ, RR), mve_vqdmlah), | |
35d1cfc2 AV |
25633 | mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull), |
25634 | mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull), | |
1be7aba3 AV |
25635 | mCEF(vqmovnt, _vqmovnt, 2, (RMQ, RMQ), mve_vqmovn), |
25636 | mCEF(vqmovnb, _vqmovnb, 2, (RMQ, RMQ), mve_vqmovn), | |
25637 | mCEF(vqmovunt, _vqmovunt, 2, (RMQ, RMQ), mve_vqmovn), | |
25638 | mCEF(vqmovunb, _vqmovunb, 2, (RMQ, RMQ), mve_vqmovn), | |
8b8b22a4 | 25639 | |
4aa88b50 AV |
25640 | mCEF(vshrnt, _vshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn), |
25641 | mCEF(vshrnb, _vshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn), | |
25642 | mCEF(vrshrnt, _vrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn), | |
25643 | mCEF(vrshrnb, _vrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn), | |
25644 | mCEF(vqshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn), | |
25645 | mCEF(vqshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn), | |
25646 | mCEF(vqshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn), | |
25647 | mCEF(vqshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn), | |
25648 | mCEF(vqrshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn), | |
25649 | mCEF(vqrshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn), | |
25650 | mCEF(vqrshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn), | |
25651 | mCEF(vqrshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn), | |
25652 | ||
acca5630 AV |
25653 | mToC("vshlc", eea00fc0, 3, (RMQ, RR, I32z), mve_vshlc), |
25654 | mToC("vshllt", ee201e00, 3, (RMQ, RMQ, I32), mve_vshll), | |
25655 | mToC("vshllb", ee200e00, 3, (RMQ, RMQ, I32), mve_vshll), | |
25656 | ||
1f6234a3 AV |
25657 | toU("dlstp", _dlstp, 2, (LR, RR), t_loloop), |
25658 | toU("wlstp", _wlstp, 3, (LR, RR, EXP), t_loloop), | |
25659 | toU("letp", _letp, 2, (LR, EXP), t_loloop), | |
25660 | toU("lctp", _lctp, 0, (), t_loloop), | |
25661 | ||
5d281bf0 AV |
25662 | #undef THUMB_VARIANT |
25663 | #define THUMB_VARIANT & mve_fp_ext | |
25664 | mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul), | |
f30ee27c | 25665 | mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas), |
935295b5 AV |
25666 | mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma), |
25667 | mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma), | |
8cd78170 AV |
25668 | mToC("vmaxnmv", eeee0f00, 2, (RR, RMQ), mve_vmaxnmv), |
25669 | mToC("vmaxnmav",eeec0f00, 2, (RR, RMQ), mve_vmaxnmv), | |
25670 | mToC("vminnmv", eeee0f80, 2, (RR, RMQ), mve_vmaxnmv), | |
25671 | mToC("vminnmav",eeec0f80, 2, (RR, RMQ), mve_vmaxnmv), | |
5d281bf0 | 25672 | |
5ee91343 | 25673 | #undef ARM_VARIANT |
57785aa2 | 25674 | #define ARM_VARIANT & fpu_vfp_ext_v1 |
5ee91343 AV |
25675 | #undef THUMB_VARIANT |
25676 | #define THUMB_VARIANT & arm_ext_v6t2 | |
a8465a06 AV |
25677 | mnCEF(vmla, _vmla, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mac_maybe_scalar), |
25678 | mnCEF(vmul, _vmul, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mul), | |
5ee91343 | 25679 | |
57785aa2 AV |
25680 | mcCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
25681 | ||
25682 | #undef ARM_VARIANT | |
25683 | #define ARM_VARIANT & fpu_vfp_ext_v1xd | |
25684 | ||
25685 | MNCE(vmov, 0, 1, (VMOV), neon_mov), | |
25686 | mcCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
25687 | mcCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
25688 | mcCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic), | |
25689 | ||
886e1c73 AV |
25690 | mCEF(vmullt, _vmullt, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ), mve_vmull), |
25691 | mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i), | |
25692 | mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i), | |
5ee91343 | 25693 | |
485dee97 AV |
25694 | MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg), |
25695 | MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg), | |
25696 | ||
57785aa2 AV |
25697 | mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl), |
25698 | mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl), | |
25699 | ||
1b883319 AV |
25700 | mnCE(vcmp, _vcmp, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp), |
25701 | mnCE(vcmpe, _vcmpe, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp), | |
25702 | ||
57785aa2 AV |
25703 | #undef ARM_VARIANT |
25704 | #define ARM_VARIANT & fpu_vfp_ext_v2 | |
25705 | ||
25706 | mcCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), | |
25707 | mcCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
25708 | mcCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn), | |
25709 | mcCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm), | |
25710 | ||
dd9634d9 AV |
25711 | #undef ARM_VARIANT |
25712 | #define ARM_VARIANT & fpu_vfp_ext_armv8xd | |
25713 | mnUF(vcvta, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvta), | |
25714 | mnUF(vcvtp, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtp), | |
25715 | mnUF(vcvtn, _vcvta, 3, (RNSDQMQ, oRNSDQMQ, oI32z), neon_cvtn), | |
25716 | mnUF(vcvtm, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtm), | |
935295b5 AV |
25717 | mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm), |
25718 | mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm), | |
dd9634d9 AV |
25719 | |
25720 | #undef ARM_VARIANT | |
5ee91343 | 25721 | #define ARM_VARIANT & fpu_neon_ext_v1 |
f601a00c | 25722 | mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su), |
5ee91343 AV |
25723 | mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long), |
25724 | mnUF(vaddl, _vaddl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long), | |
25725 | mnUF(vsubl, _vsubl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long), | |
f601a00c AV |
25726 | mnUF(vand, _vand, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic), |
25727 | mnUF(vbic, _vbic, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic), | |
25728 | mnUF(vorr, _vorr, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic), | |
25729 | mnUF(vorn, _vorn, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic), | |
25730 | mnUF(veor, _veor, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_logic), | |
f30ee27c AV |
25731 | MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls), |
25732 | MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz), | |
b409bdb6 | 25733 | mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup), |
7df54120 AV |
25734 | MNUF(vhadd, 00000000, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su), |
25735 | MNUF(vrhadd, 00000100, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_i_su), | |
25736 | MNUF(vhsub, 00000200, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su), | |
935295b5 AV |
25737 | mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su), |
25738 | mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su), | |
a8465a06 AV |
25739 | MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su), |
25740 | MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su), | |
1a186d29 AV |
25741 | mnUF(vmvn, _vmvn, 2, (RNDQMQ, RNDQMQ_Ibig), neon_mvn), |
25742 | MNUF(vqabs, 1b00700, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg), | |
25743 | MNUF(vqneg, 1b00780, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg), | |
42b16635 AV |
25744 | mnUF(vqrdmlah, _vqrdmlah,3, (RNDQMQ, oRNDQMQ, RNDQ_RNSC_RR), neon_qrdmlah), |
25745 | mnUF(vqdmulh, _vqdmulh, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh), | |
25746 | mnUF(vqrdmulh, _vqrdmulh,3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh), | |
1be7aba3 AV |
25747 | MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl), |
25748 | MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl), | |
4401c241 AV |
25749 | MNUF(vshr, 0800010, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm), |
25750 | MNUF(vrshr, 0800210, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm), | |
25751 | MNUF(vsli, 1800510, 3, (RNDQMQ, oRNDQMQ, I63), neon_sli), | |
25752 | MNUF(vsri, 1800410, 3, (RNDQMQ, oRNDQMQ, I64z), neon_sri), | |
25753 | MNUF(vrev64, 1b00000, 2, (RNDQMQ, RNDQMQ), neon_rev), | |
25754 | MNUF(vrev32, 1b00080, 2, (RNDQMQ, RNDQMQ), neon_rev), | |
25755 | MNUF(vrev16, 1b00100, 2, (RNDQMQ, RNDQMQ), neon_rev), | |
5150f0d8 AV |
25756 | mnUF(vshl, _vshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_shl), |
25757 | mnUF(vqshl, _vqshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_qshl), | |
25758 | MNUF(vqshlu, 1800610, 3, (RNDQMQ, oRNDQMQ, I63), neon_qshlu_imm), | |
5d281bf0 AV |
25759 | |
25760 | #undef ARM_VARIANT | |
25761 | #define ARM_VARIANT & arm_ext_v8_3 | |
25762 | #undef THUMB_VARIANT | |
25763 | #define THUMB_VARIANT & arm_ext_v6t2_v8m | |
25764 | MNUF (vcadd, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ, EXPi), vcadd), | |
25765 | MNUF (vcmla, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ_RNSC, EXPi), vcmla), | |
c19d1205 ZW |
25766 | }; |
25767 | #undef ARM_VARIANT | |
25768 | #undef THUMB_VARIANT | |
25769 | #undef TCE | |
c19d1205 ZW |
25770 | #undef TUE |
25771 | #undef TUF | |
25772 | #undef TCC | |
8f06b2d8 | 25773 | #undef cCE |
e3cb604e PB |
25774 | #undef cCL |
25775 | #undef C3E | |
4389b29a | 25776 | #undef C3 |
c19d1205 ZW |
25777 | #undef CE |
25778 | #undef CM | |
4389b29a | 25779 | #undef CL |
c19d1205 ZW |
25780 | #undef UE |
25781 | #undef UF | |
25782 | #undef UT | |
5287ad62 JB |
25783 | #undef NUF |
25784 | #undef nUF | |
25785 | #undef NCE | |
25786 | #undef nCE | |
c19d1205 ZW |
25787 | #undef OPS0 |
25788 | #undef OPS1 | |
25789 | #undef OPS2 | |
25790 | #undef OPS3 | |
25791 | #undef OPS4 | |
25792 | #undef OPS5 | |
25793 | #undef OPS6 | |
25794 | #undef do_0 | |
4389b29a AV |
25795 | #undef ToC |
25796 | #undef toC | |
25797 | #undef ToU | |
f6b2b12d | 25798 | #undef toU |
c19d1205 ZW |
25799 | \f |
25800 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 25801 | |
c19d1205 ZW |
25802 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
25803 | for use in the a.out file, and stores them in the array pointed to by buf. | |
25804 | This knows about the endian-ness of the target machine and does | |
25805 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
25806 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
25807 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 25808 | |
c19d1205 ZW |
25809 | void |
25810 | md_number_to_chars (char * buf, valueT val, int n) | |
25811 | { | |
25812 | if (target_big_endian) | |
25813 | number_to_chars_bigendian (buf, val, n); | |
25814 | else | |
25815 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
25816 | } |
25817 | ||
c19d1205 ZW |
25818 | static valueT |
25819 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 25820 | { |
c19d1205 ZW |
25821 | valueT result = 0; |
25822 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 25823 | |
c19d1205 | 25824 | if (target_big_endian) |
b99bd4ef | 25825 | { |
c19d1205 ZW |
25826 | while (n--) |
25827 | { | |
25828 | result <<= 8; | |
25829 | result |= (*where++ & 255); | |
25830 | } | |
b99bd4ef | 25831 | } |
c19d1205 | 25832 | else |
b99bd4ef | 25833 | { |
c19d1205 ZW |
25834 | while (n--) |
25835 | { | |
25836 | result <<= 8; | |
25837 | result |= (where[n] & 255); | |
25838 | } | |
bfae80f2 | 25839 | } |
b99bd4ef | 25840 | |
c19d1205 | 25841 | return result; |
bfae80f2 | 25842 | } |
b99bd4ef | 25843 | |
c19d1205 | 25844 | /* MD interface: Sections. */ |
b99bd4ef | 25845 | |
fa94de6b RM |
25846 | /* Calculate the maximum variable size (i.e., excluding fr_fix) |
25847 | that an rs_machine_dependent frag may reach. */ | |
25848 | ||
25849 | unsigned int | |
25850 | arm_frag_max_var (fragS *fragp) | |
25851 | { | |
25852 | /* We only use rs_machine_dependent for variable-size Thumb instructions, | |
25853 | which are either THUMB_SIZE (2) or INSN_SIZE (4). | |
25854 | ||
25855 | Note that we generate relaxable instructions even for cases that don't | |
25856 | really need it, like an immediate that's a trivial constant. So we're | |
25857 | overestimating the instruction size for some of those cases. Rather | |
25858 | than putting more intelligence here, it would probably be better to | |
25859 | avoid generating a relaxation frag in the first place when it can be | |
25860 | determined up front that a short instruction will suffice. */ | |
25861 | ||
25862 | gas_assert (fragp->fr_type == rs_machine_dependent); | |
25863 | return INSN_SIZE; | |
25864 | } | |
25865 | ||
0110f2b8 PB |
25866 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
25867 | 2 bytes. */ | |
25868 | ||
c19d1205 | 25869 | int |
0110f2b8 | 25870 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
25871 | segT segtype ATTRIBUTE_UNUSED) |
25872 | { | |
0110f2b8 PB |
25873 | fragp->fr_var = 2; |
25874 | return 2; | |
25875 | } | |
25876 | ||
25877 | /* Convert a machine dependent frag. */ | |
25878 | ||
25879 | void | |
25880 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
25881 | { | |
25882 | unsigned long insn; | |
25883 | unsigned long old_op; | |
25884 | char *buf; | |
25885 | expressionS exp; | |
25886 | fixS *fixp; | |
25887 | int reloc_type; | |
25888 | int pc_rel; | |
25889 | int opcode; | |
25890 | ||
25891 | buf = fragp->fr_literal + fragp->fr_fix; | |
25892 | ||
25893 | old_op = bfd_get_16(abfd, buf); | |
5f4273c7 NC |
25894 | if (fragp->fr_symbol) |
25895 | { | |
0110f2b8 PB |
25896 | exp.X_op = O_symbol; |
25897 | exp.X_add_symbol = fragp->fr_symbol; | |
5f4273c7 NC |
25898 | } |
25899 | else | |
25900 | { | |
0110f2b8 | 25901 | exp.X_op = O_constant; |
5f4273c7 | 25902 | } |
0110f2b8 PB |
25903 | exp.X_add_number = fragp->fr_offset; |
25904 | opcode = fragp->fr_subtype; | |
25905 | switch (opcode) | |
25906 | { | |
25907 | case T_MNEM_ldr_pc: | |
25908 | case T_MNEM_ldr_pc2: | |
25909 | case T_MNEM_ldr_sp: | |
25910 | case T_MNEM_str_sp: | |
25911 | case T_MNEM_ldr: | |
25912 | case T_MNEM_ldrb: | |
25913 | case T_MNEM_ldrh: | |
25914 | case T_MNEM_str: | |
25915 | case T_MNEM_strb: | |
25916 | case T_MNEM_strh: | |
25917 | if (fragp->fr_var == 4) | |
25918 | { | |
5f4273c7 | 25919 | insn = THUMB_OP32 (opcode); |
0110f2b8 PB |
25920 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) |
25921 | { | |
25922 | insn |= (old_op & 0x700) << 4; | |
25923 | } | |
25924 | else | |
25925 | { | |
25926 | insn |= (old_op & 7) << 12; | |
25927 | insn |= (old_op & 0x38) << 13; | |
25928 | } | |
25929 | insn |= 0x00000c00; | |
25930 | put_thumb32_insn (buf, insn); | |
25931 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
25932 | } | |
25933 | else | |
25934 | { | |
25935 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
25936 | } | |
25937 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
25938 | break; | |
25939 | case T_MNEM_adr: | |
25940 | if (fragp->fr_var == 4) | |
25941 | { | |
25942 | insn = THUMB_OP32 (opcode); | |
25943 | insn |= (old_op & 0xf0) << 4; | |
25944 | put_thumb32_insn (buf, insn); | |
25945 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
25946 | } | |
25947 | else | |
25948 | { | |
25949 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
25950 | exp.X_add_number -= 4; | |
25951 | } | |
25952 | pc_rel = 1; | |
25953 | break; | |
25954 | case T_MNEM_mov: | |
25955 | case T_MNEM_movs: | |
25956 | case T_MNEM_cmp: | |
25957 | case T_MNEM_cmn: | |
25958 | if (fragp->fr_var == 4) | |
25959 | { | |
25960 | int r0off = (opcode == T_MNEM_mov | |
25961 | || opcode == T_MNEM_movs) ? 0 : 8; | |
25962 | insn = THUMB_OP32 (opcode); | |
25963 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
25964 | insn |= (old_op & 0x700) << r0off; | |
25965 | put_thumb32_insn (buf, insn); | |
25966 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
25967 | } | |
25968 | else | |
25969 | { | |
25970 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
25971 | } | |
25972 | pc_rel = 0; | |
25973 | break; | |
25974 | case T_MNEM_b: | |
25975 | if (fragp->fr_var == 4) | |
25976 | { | |
25977 | insn = THUMB_OP32(opcode); | |
25978 | put_thumb32_insn (buf, insn); | |
25979 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
25980 | } | |
25981 | else | |
25982 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
25983 | pc_rel = 1; | |
25984 | break; | |
25985 | case T_MNEM_bcond: | |
25986 | if (fragp->fr_var == 4) | |
25987 | { | |
25988 | insn = THUMB_OP32(opcode); | |
25989 | insn |= (old_op & 0xf00) << 14; | |
25990 | put_thumb32_insn (buf, insn); | |
25991 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
25992 | } | |
25993 | else | |
25994 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
25995 | pc_rel = 1; | |
25996 | break; | |
25997 | case T_MNEM_add_sp: | |
25998 | case T_MNEM_add_pc: | |
25999 | case T_MNEM_inc_sp: | |
26000 | case T_MNEM_dec_sp: | |
26001 | if (fragp->fr_var == 4) | |
26002 | { | |
26003 | /* ??? Choose between add and addw. */ | |
26004 | insn = THUMB_OP32 (opcode); | |
26005 | insn |= (old_op & 0xf0) << 4; | |
26006 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
26007 | if (opcode == T_MNEM_add_pc) |
26008 | reloc_type = BFD_RELOC_ARM_T32_IMM12; | |
26009 | else | |
26010 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
0110f2b8 PB |
26011 | } |
26012 | else | |
26013 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
26014 | pc_rel = 0; | |
26015 | break; | |
26016 | ||
26017 | case T_MNEM_addi: | |
26018 | case T_MNEM_addis: | |
26019 | case T_MNEM_subi: | |
26020 | case T_MNEM_subis: | |
26021 | if (fragp->fr_var == 4) | |
26022 | { | |
26023 | insn = THUMB_OP32 (opcode); | |
26024 | insn |= (old_op & 0xf0) << 4; | |
26025 | insn |= (old_op & 0xf) << 16; | |
26026 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
26027 | if (insn & (1 << 20)) |
26028 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
26029 | else | |
26030 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
0110f2b8 PB |
26031 | } |
26032 | else | |
26033 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
26034 | pc_rel = 0; | |
26035 | break; | |
26036 | default: | |
5f4273c7 | 26037 | abort (); |
0110f2b8 PB |
26038 | } |
26039 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
21d799b5 | 26040 | (enum bfd_reloc_code_real) reloc_type); |
0110f2b8 PB |
26041 | fixp->fx_file = fragp->fr_file; |
26042 | fixp->fx_line = fragp->fr_line; | |
26043 | fragp->fr_fix += fragp->fr_var; | |
3cfdb781 TG |
26044 | |
26045 | /* Set whether we use thumb-2 ISA based on final relaxation results. */ | |
26046 | if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected () | |
26047 | && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2)) | |
26048 | ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2); | |
0110f2b8 PB |
26049 | } |
26050 | ||
26051 | /* Return the size of a relaxable immediate operand instruction. | |
26052 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
26053 | static int | |
26054 | relax_immediate (fragS *fragp, int size, int shift) | |
26055 | { | |
26056 | offsetT offset; | |
26057 | offsetT mask; | |
26058 | offsetT low; | |
26059 | ||
26060 | /* ??? Should be able to do better than this. */ | |
26061 | if (fragp->fr_symbol) | |
26062 | return 4; | |
26063 | ||
26064 | low = (1 << shift) - 1; | |
26065 | mask = (1 << (shift + size)) - (1 << shift); | |
26066 | offset = fragp->fr_offset; | |
26067 | /* Force misaligned offsets to 32-bit variant. */ | |
26068 | if (offset & low) | |
5e77afaa | 26069 | return 4; |
0110f2b8 PB |
26070 | if (offset & ~mask) |
26071 | return 4; | |
26072 | return 2; | |
26073 | } | |
26074 | ||
5e77afaa PB |
26075 | /* Get the address of a symbol during relaxation. */ |
26076 | static addressT | |
5f4273c7 | 26077 | relaxed_symbol_addr (fragS *fragp, long stretch) |
5e77afaa PB |
26078 | { |
26079 | fragS *sym_frag; | |
26080 | addressT addr; | |
26081 | symbolS *sym; | |
26082 | ||
26083 | sym = fragp->fr_symbol; | |
26084 | sym_frag = symbol_get_frag (sym); | |
26085 | know (S_GET_SEGMENT (sym) != absolute_section | |
26086 | || sym_frag == &zero_address_frag); | |
26087 | addr = S_GET_VALUE (sym) + fragp->fr_offset; | |
26088 | ||
26089 | /* If frag has yet to be reached on this pass, assume it will | |
26090 | move by STRETCH just as we did. If this is not so, it will | |
26091 | be because some frag between grows, and that will force | |
26092 | another pass. */ | |
26093 | ||
26094 | if (stretch != 0 | |
26095 | && sym_frag->relax_marker != fragp->relax_marker) | |
4396b686 PB |
26096 | { |
26097 | fragS *f; | |
26098 | ||
26099 | /* Adjust stretch for any alignment frag. Note that if have | |
26100 | been expanding the earlier code, the symbol may be | |
26101 | defined in what appears to be an earlier frag. FIXME: | |
26102 | This doesn't handle the fr_subtype field, which specifies | |
26103 | a maximum number of bytes to skip when doing an | |
26104 | alignment. */ | |
26105 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) | |
26106 | { | |
26107 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
26108 | { | |
26109 | if (stretch < 0) | |
26110 | stretch = - ((- stretch) | |
26111 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
26112 | else | |
26113 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
26114 | if (stretch == 0) | |
26115 | break; | |
26116 | } | |
26117 | } | |
26118 | if (f != NULL) | |
26119 | addr += stretch; | |
26120 | } | |
5e77afaa PB |
26121 | |
26122 | return addr; | |
26123 | } | |
26124 | ||
0110f2b8 PB |
26125 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative |
26126 | load. */ | |
26127 | static int | |
5e77afaa | 26128 | relax_adr (fragS *fragp, asection *sec, long stretch) |
0110f2b8 PB |
26129 | { |
26130 | addressT addr; | |
26131 | offsetT val; | |
26132 | ||
26133 | /* Assume worst case for symbols not known to be in the same section. */ | |
974da60d NC |
26134 | if (fragp->fr_symbol == NULL |
26135 | || !S_IS_DEFINED (fragp->fr_symbol) | |
77db8e2e NC |
26136 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
26137 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
26138 | return 4; |
26139 | ||
5f4273c7 | 26140 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
26141 | addr = fragp->fr_address + fragp->fr_fix; |
26142 | addr = (addr + 4) & ~3; | |
5e77afaa | 26143 | /* Force misaligned targets to 32-bit variant. */ |
0110f2b8 | 26144 | if (val & 3) |
5e77afaa | 26145 | return 4; |
0110f2b8 PB |
26146 | val -= addr; |
26147 | if (val < 0 || val > 1020) | |
26148 | return 4; | |
26149 | return 2; | |
26150 | } | |
26151 | ||
26152 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
26153 | static int | |
26154 | relax_addsub (fragS *fragp, asection *sec) | |
26155 | { | |
26156 | char *buf; | |
26157 | int op; | |
26158 | ||
26159 | buf = fragp->fr_literal + fragp->fr_fix; | |
26160 | op = bfd_get_16(sec->owner, buf); | |
26161 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
26162 | return relax_immediate (fragp, 8, 0); | |
26163 | else | |
26164 | return relax_immediate (fragp, 3, 0); | |
26165 | } | |
26166 | ||
e83a675f RE |
26167 | /* Return TRUE iff the definition of symbol S could be pre-empted |
26168 | (overridden) at link or load time. */ | |
26169 | static bfd_boolean | |
26170 | symbol_preemptible (symbolS *s) | |
26171 | { | |
26172 | /* Weak symbols can always be pre-empted. */ | |
26173 | if (S_IS_WEAK (s)) | |
26174 | return TRUE; | |
26175 | ||
26176 | /* Non-global symbols cannot be pre-empted. */ | |
26177 | if (! S_IS_EXTERNAL (s)) | |
26178 | return FALSE; | |
26179 | ||
26180 | #ifdef OBJ_ELF | |
26181 | /* In ELF, a global symbol can be marked protected, or private. In that | |
26182 | case it can't be pre-empted (other definitions in the same link unit | |
26183 | would violate the ODR). */ | |
26184 | if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT) | |
26185 | return FALSE; | |
26186 | #endif | |
26187 | ||
26188 | /* Other global symbols might be pre-empted. */ | |
26189 | return TRUE; | |
26190 | } | |
0110f2b8 PB |
26191 | |
26192 | /* Return the size of a relaxable branch instruction. BITS is the | |
26193 | size of the offset field in the narrow instruction. */ | |
26194 | ||
26195 | static int | |
5e77afaa | 26196 | relax_branch (fragS *fragp, asection *sec, int bits, long stretch) |
0110f2b8 PB |
26197 | { |
26198 | addressT addr; | |
26199 | offsetT val; | |
26200 | offsetT limit; | |
26201 | ||
26202 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 26203 | if (!S_IS_DEFINED (fragp->fr_symbol) |
77db8e2e NC |
26204 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
26205 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
26206 | return 4; |
26207 | ||
267bf995 | 26208 | #ifdef OBJ_ELF |
e83a675f | 26209 | /* A branch to a function in ARM state will require interworking. */ |
267bf995 RR |
26210 | if (S_IS_DEFINED (fragp->fr_symbol) |
26211 | && ARM_IS_FUNC (fragp->fr_symbol)) | |
26212 | return 4; | |
e83a675f | 26213 | #endif |
0d9b4b55 | 26214 | |
e83a675f | 26215 | if (symbol_preemptible (fragp->fr_symbol)) |
0d9b4b55 | 26216 | return 4; |
267bf995 | 26217 | |
5f4273c7 | 26218 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
26219 | addr = fragp->fr_address + fragp->fr_fix + 4; |
26220 | val -= addr; | |
26221 | ||
26222 | /* Offset is a signed value *2 */ | |
26223 | limit = 1 << bits; | |
26224 | if (val >= limit || val < -limit) | |
26225 | return 4; | |
26226 | return 2; | |
26227 | } | |
26228 | ||
26229 | ||
26230 | /* Relax a machine dependent frag. This returns the amount by which | |
26231 | the current size of the frag should change. */ | |
26232 | ||
26233 | int | |
5e77afaa | 26234 | arm_relax_frag (asection *sec, fragS *fragp, long stretch) |
0110f2b8 PB |
26235 | { |
26236 | int oldsize; | |
26237 | int newsize; | |
26238 | ||
26239 | oldsize = fragp->fr_var; | |
26240 | switch (fragp->fr_subtype) | |
26241 | { | |
26242 | case T_MNEM_ldr_pc2: | |
5f4273c7 | 26243 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
26244 | break; |
26245 | case T_MNEM_ldr_pc: | |
26246 | case T_MNEM_ldr_sp: | |
26247 | case T_MNEM_str_sp: | |
5f4273c7 | 26248 | newsize = relax_immediate (fragp, 8, 2); |
0110f2b8 PB |
26249 | break; |
26250 | case T_MNEM_ldr: | |
26251 | case T_MNEM_str: | |
5f4273c7 | 26252 | newsize = relax_immediate (fragp, 5, 2); |
0110f2b8 PB |
26253 | break; |
26254 | case T_MNEM_ldrh: | |
26255 | case T_MNEM_strh: | |
5f4273c7 | 26256 | newsize = relax_immediate (fragp, 5, 1); |
0110f2b8 PB |
26257 | break; |
26258 | case T_MNEM_ldrb: | |
26259 | case T_MNEM_strb: | |
5f4273c7 | 26260 | newsize = relax_immediate (fragp, 5, 0); |
0110f2b8 PB |
26261 | break; |
26262 | case T_MNEM_adr: | |
5f4273c7 | 26263 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
26264 | break; |
26265 | case T_MNEM_mov: | |
26266 | case T_MNEM_movs: | |
26267 | case T_MNEM_cmp: | |
26268 | case T_MNEM_cmn: | |
5f4273c7 | 26269 | newsize = relax_immediate (fragp, 8, 0); |
0110f2b8 PB |
26270 | break; |
26271 | case T_MNEM_b: | |
5f4273c7 | 26272 | newsize = relax_branch (fragp, sec, 11, stretch); |
0110f2b8 PB |
26273 | break; |
26274 | case T_MNEM_bcond: | |
5f4273c7 | 26275 | newsize = relax_branch (fragp, sec, 8, stretch); |
0110f2b8 PB |
26276 | break; |
26277 | case T_MNEM_add_sp: | |
26278 | case T_MNEM_add_pc: | |
26279 | newsize = relax_immediate (fragp, 8, 2); | |
26280 | break; | |
26281 | case T_MNEM_inc_sp: | |
26282 | case T_MNEM_dec_sp: | |
26283 | newsize = relax_immediate (fragp, 7, 2); | |
26284 | break; | |
26285 | case T_MNEM_addi: | |
26286 | case T_MNEM_addis: | |
26287 | case T_MNEM_subi: | |
26288 | case T_MNEM_subis: | |
26289 | newsize = relax_addsub (fragp, sec); | |
26290 | break; | |
26291 | default: | |
5f4273c7 | 26292 | abort (); |
0110f2b8 | 26293 | } |
5e77afaa PB |
26294 | |
26295 | fragp->fr_var = newsize; | |
26296 | /* Freeze wide instructions that are at or before the same location as | |
26297 | in the previous pass. This avoids infinite loops. | |
5f4273c7 NC |
26298 | Don't freeze them unconditionally because targets may be artificially |
26299 | misaligned by the expansion of preceding frags. */ | |
5e77afaa | 26300 | if (stretch <= 0 && newsize > 2) |
0110f2b8 | 26301 | { |
0110f2b8 | 26302 | md_convert_frag (sec->owner, sec, fragp); |
5f4273c7 | 26303 | frag_wane (fragp); |
0110f2b8 | 26304 | } |
5e77afaa | 26305 | |
0110f2b8 | 26306 | return newsize - oldsize; |
c19d1205 | 26307 | } |
b99bd4ef | 26308 | |
c19d1205 | 26309 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 26310 | |
c19d1205 ZW |
26311 | valueT |
26312 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
26313 | valueT size) | |
26314 | { | |
6844c0cc | 26315 | return size; |
bfae80f2 | 26316 | } |
b99bd4ef | 26317 | |
c19d1205 ZW |
26318 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
26319 | of an rs_align_code fragment. */ | |
26320 | ||
26321 | void | |
26322 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 26323 | { |
d9235011 | 26324 | static unsigned char const arm_noop[2][2][4] = |
e7495e45 NS |
26325 | { |
26326 | { /* ARMv1 */ | |
26327 | {0x00, 0x00, 0xa0, 0xe1}, /* LE */ | |
26328 | {0xe1, 0xa0, 0x00, 0x00}, /* BE */ | |
26329 | }, | |
26330 | { /* ARMv6k */ | |
26331 | {0x00, 0xf0, 0x20, 0xe3}, /* LE */ | |
26332 | {0xe3, 0x20, 0xf0, 0x00}, /* BE */ | |
26333 | }, | |
26334 | }; | |
d9235011 | 26335 | static unsigned char const thumb_noop[2][2][2] = |
e7495e45 NS |
26336 | { |
26337 | { /* Thumb-1 */ | |
26338 | {0xc0, 0x46}, /* LE */ | |
26339 | {0x46, 0xc0}, /* BE */ | |
26340 | }, | |
26341 | { /* Thumb-2 */ | |
26342 | {0x00, 0xbf}, /* LE */ | |
26343 | {0xbf, 0x00} /* BE */ | |
26344 | } | |
26345 | }; | |
d9235011 | 26346 | static unsigned char const wide_thumb_noop[2][4] = |
e7495e45 NS |
26347 | { /* Wide Thumb-2 */ |
26348 | {0xaf, 0xf3, 0x00, 0x80}, /* LE */ | |
26349 | {0xf3, 0xaf, 0x80, 0x00}, /* BE */ | |
26350 | }; | |
c921be7d | 26351 | |
e7495e45 | 26352 | unsigned bytes, fix, noop_size; |
c19d1205 | 26353 | char * p; |
d9235011 TS |
26354 | const unsigned char * noop; |
26355 | const unsigned char *narrow_noop = NULL; | |
cd000bff DJ |
26356 | #ifdef OBJ_ELF |
26357 | enum mstate state; | |
26358 | #endif | |
bfae80f2 | 26359 | |
c19d1205 | 26360 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
26361 | return; |
26362 | ||
c19d1205 ZW |
26363 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
26364 | p = fragP->fr_literal + fragP->fr_fix; | |
26365 | fix = 0; | |
bfae80f2 | 26366 | |
c19d1205 ZW |
26367 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
26368 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 26369 | |
cd000bff | 26370 | gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0); |
8dc2430f | 26371 | |
cd000bff | 26372 | if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED)) |
a737bd4d | 26373 | { |
7f78eb34 JW |
26374 | if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0] |
26375 | ? selected_cpu : arm_arch_none, arm_ext_v6t2)) | |
e7495e45 NS |
26376 | { |
26377 | narrow_noop = thumb_noop[1][target_big_endian]; | |
26378 | noop = wide_thumb_noop[target_big_endian]; | |
26379 | } | |
c19d1205 | 26380 | else |
e7495e45 NS |
26381 | noop = thumb_noop[0][target_big_endian]; |
26382 | noop_size = 2; | |
cd000bff DJ |
26383 | #ifdef OBJ_ELF |
26384 | state = MAP_THUMB; | |
26385 | #endif | |
7ed4c4c5 NC |
26386 | } |
26387 | else | |
26388 | { | |
7f78eb34 JW |
26389 | noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0] |
26390 | ? selected_cpu : arm_arch_none, | |
26391 | arm_ext_v6k) != 0] | |
e7495e45 NS |
26392 | [target_big_endian]; |
26393 | noop_size = 4; | |
cd000bff DJ |
26394 | #ifdef OBJ_ELF |
26395 | state = MAP_ARM; | |
26396 | #endif | |
7ed4c4c5 | 26397 | } |
c921be7d | 26398 | |
e7495e45 | 26399 | fragP->fr_var = noop_size; |
c921be7d | 26400 | |
c19d1205 | 26401 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 26402 | { |
c19d1205 | 26403 | fix = bytes & (noop_size - 1); |
cd000bff DJ |
26404 | #ifdef OBJ_ELF |
26405 | insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix); | |
26406 | #endif | |
c19d1205 ZW |
26407 | memset (p, 0, fix); |
26408 | p += fix; | |
26409 | bytes -= fix; | |
a737bd4d | 26410 | } |
a737bd4d | 26411 | |
e7495e45 NS |
26412 | if (narrow_noop) |
26413 | { | |
26414 | if (bytes & noop_size) | |
26415 | { | |
26416 | /* Insert a narrow noop. */ | |
26417 | memcpy (p, narrow_noop, noop_size); | |
26418 | p += noop_size; | |
26419 | bytes -= noop_size; | |
26420 | fix += noop_size; | |
26421 | } | |
26422 | ||
26423 | /* Use wide noops for the remainder */ | |
26424 | noop_size = 4; | |
26425 | } | |
26426 | ||
c19d1205 | 26427 | while (bytes >= noop_size) |
a737bd4d | 26428 | { |
c19d1205 ZW |
26429 | memcpy (p, noop, noop_size); |
26430 | p += noop_size; | |
26431 | bytes -= noop_size; | |
26432 | fix += noop_size; | |
a737bd4d NC |
26433 | } |
26434 | ||
c19d1205 | 26435 | fragP->fr_fix += fix; |
a737bd4d NC |
26436 | } |
26437 | ||
c19d1205 ZW |
26438 | /* Called from md_do_align. Used to create an alignment |
26439 | frag in a code section. */ | |
26440 | ||
26441 | void | |
26442 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 26443 | { |
c19d1205 | 26444 | char * p; |
7ed4c4c5 | 26445 | |
c19d1205 | 26446 | /* We assume that there will never be a requirement |
6ec8e702 | 26447 | to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */ |
c19d1205 | 26448 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) |
6ec8e702 NC |
26449 | { |
26450 | char err_msg[128]; | |
26451 | ||
fa94de6b | 26452 | sprintf (err_msg, |
477330fc RM |
26453 | _("alignments greater than %d bytes not supported in .text sections."), |
26454 | MAX_MEM_FOR_RS_ALIGN_CODE + 1); | |
20203fb9 | 26455 | as_fatal ("%s", err_msg); |
6ec8e702 | 26456 | } |
bfae80f2 | 26457 | |
c19d1205 ZW |
26458 | p = frag_var (rs_align_code, |
26459 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
26460 | 1, | |
26461 | (relax_substateT) max, | |
26462 | (symbolS *) NULL, | |
26463 | (offsetT) n, | |
26464 | (char *) NULL); | |
26465 | *p = 0; | |
26466 | } | |
bfae80f2 | 26467 | |
8dc2430f NC |
26468 | /* Perform target specific initialisation of a frag. |
26469 | Note - despite the name this initialisation is not done when the frag | |
26470 | is created, but only when its type is assigned. A frag can be created | |
26471 | and used a long time before its type is set, so beware of assuming that | |
33eaf5de | 26472 | this initialisation is performed first. */ |
bfae80f2 | 26473 | |
cd000bff DJ |
26474 | #ifndef OBJ_ELF |
26475 | void | |
26476 | arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED) | |
26477 | { | |
26478 | /* Record whether this frag is in an ARM or a THUMB area. */ | |
2e98972e | 26479 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
cd000bff DJ |
26480 | } |
26481 | ||
26482 | #else /* OBJ_ELF is defined. */ | |
c19d1205 | 26483 | void |
cd000bff | 26484 | arm_init_frag (fragS * fragP, int max_chars) |
c19d1205 | 26485 | { |
e8d84ca1 | 26486 | bfd_boolean frag_thumb_mode; |
b968d18a | 26487 | |
8dc2430f NC |
26488 | /* If the current ARM vs THUMB mode has not already |
26489 | been recorded into this frag then do so now. */ | |
cd000bff | 26490 | if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0) |
b968d18a JW |
26491 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
26492 | ||
e8d84ca1 NC |
26493 | /* PR 21809: Do not set a mapping state for debug sections |
26494 | - it just confuses other tools. */ | |
fd361982 | 26495 | if (bfd_section_flags (now_seg) & SEC_DEBUGGING) |
e8d84ca1 NC |
26496 | return; |
26497 | ||
b968d18a | 26498 | frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED; |
cd000bff | 26499 | |
f9c1b181 RL |
26500 | /* Record a mapping symbol for alignment frags. We will delete this |
26501 | later if the alignment ends up empty. */ | |
26502 | switch (fragP->fr_type) | |
26503 | { | |
26504 | case rs_align: | |
26505 | case rs_align_test: | |
26506 | case rs_fill: | |
26507 | mapping_state_2 (MAP_DATA, max_chars); | |
26508 | break; | |
26509 | case rs_align_code: | |
b968d18a | 26510 | mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars); |
f9c1b181 RL |
26511 | break; |
26512 | default: | |
26513 | break; | |
cd000bff | 26514 | } |
bfae80f2 RE |
26515 | } |
26516 | ||
c19d1205 ZW |
26517 | /* When we change sections we need to issue a new mapping symbol. */ |
26518 | ||
26519 | void | |
26520 | arm_elf_change_section (void) | |
bfae80f2 | 26521 | { |
c19d1205 ZW |
26522 | /* Link an unlinked unwind index table section to the .text section. */ |
26523 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
26524 | && elf_linked_to_section (now_seg) == NULL) | |
26525 | elf_linked_to_section (now_seg) = text_section; | |
bfae80f2 RE |
26526 | } |
26527 | ||
c19d1205 ZW |
26528 | int |
26529 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 26530 | { |
c19d1205 ZW |
26531 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
26532 | return SHT_ARM_EXIDX; | |
e45d0630 | 26533 | |
c19d1205 ZW |
26534 | return -1; |
26535 | } | |
26536 | \f | |
26537 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 26538 | |
c19d1205 | 26539 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 26540 | |
5f4273c7 | 26541 | /* Generate any deferred unwind frame offset. */ |
e45d0630 | 26542 | |
bfae80f2 | 26543 | static void |
c19d1205 | 26544 | flush_pending_unwind (void) |
bfae80f2 | 26545 | { |
c19d1205 | 26546 | offsetT offset; |
bfae80f2 | 26547 | |
c19d1205 ZW |
26548 | offset = unwind.pending_offset; |
26549 | unwind.pending_offset = 0; | |
26550 | if (offset != 0) | |
26551 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
26552 | } |
26553 | ||
c19d1205 ZW |
26554 | /* Add an opcode to this list for this function. Two-byte opcodes should |
26555 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
26556 | order. */ | |
26557 | ||
bfae80f2 | 26558 | static void |
c19d1205 | 26559 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 26560 | { |
c19d1205 ZW |
26561 | /* Add any deferred stack adjustment. */ |
26562 | if (unwind.pending_offset) | |
26563 | flush_pending_unwind (); | |
bfae80f2 | 26564 | |
c19d1205 | 26565 | unwind.sp_restored = 0; |
bfae80f2 | 26566 | |
c19d1205 | 26567 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 26568 | { |
c19d1205 ZW |
26569 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
26570 | if (unwind.opcodes) | |
325801bd TS |
26571 | unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes, |
26572 | unwind.opcode_alloc); | |
c19d1205 | 26573 | else |
325801bd | 26574 | unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc); |
bfae80f2 | 26575 | } |
c19d1205 | 26576 | while (length > 0) |
bfae80f2 | 26577 | { |
c19d1205 ZW |
26578 | length--; |
26579 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
26580 | op >>= 8; | |
26581 | unwind.opcode_count++; | |
bfae80f2 | 26582 | } |
bfae80f2 RE |
26583 | } |
26584 | ||
c19d1205 ZW |
26585 | /* Add unwind opcodes to adjust the stack pointer. */ |
26586 | ||
bfae80f2 | 26587 | static void |
c19d1205 | 26588 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 26589 | { |
c19d1205 | 26590 | valueT op; |
bfae80f2 | 26591 | |
c19d1205 | 26592 | if (offset > 0x200) |
bfae80f2 | 26593 | { |
c19d1205 ZW |
26594 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
26595 | char bytes[5]; | |
26596 | int n; | |
26597 | valueT o; | |
bfae80f2 | 26598 | |
c19d1205 ZW |
26599 | /* Long form: 0xb2, uleb128. */ |
26600 | /* This might not fit in a word so add the individual bytes, | |
26601 | remembering the list is built in reverse order. */ | |
26602 | o = (valueT) ((offset - 0x204) >> 2); | |
26603 | if (o == 0) | |
26604 | add_unwind_opcode (0, 1); | |
bfae80f2 | 26605 | |
c19d1205 ZW |
26606 | /* Calculate the uleb128 encoding of the offset. */ |
26607 | n = 0; | |
26608 | while (o) | |
26609 | { | |
26610 | bytes[n] = o & 0x7f; | |
26611 | o >>= 7; | |
26612 | if (o) | |
26613 | bytes[n] |= 0x80; | |
26614 | n++; | |
26615 | } | |
26616 | /* Add the insn. */ | |
26617 | for (; n; n--) | |
26618 | add_unwind_opcode (bytes[n - 1], 1); | |
26619 | add_unwind_opcode (0xb2, 1); | |
26620 | } | |
26621 | else if (offset > 0x100) | |
bfae80f2 | 26622 | { |
c19d1205 ZW |
26623 | /* Two short opcodes. */ |
26624 | add_unwind_opcode (0x3f, 1); | |
26625 | op = (offset - 0x104) >> 2; | |
26626 | add_unwind_opcode (op, 1); | |
bfae80f2 | 26627 | } |
c19d1205 ZW |
26628 | else if (offset > 0) |
26629 | { | |
26630 | /* Short opcode. */ | |
26631 | op = (offset - 4) >> 2; | |
26632 | add_unwind_opcode (op, 1); | |
26633 | } | |
26634 | else if (offset < 0) | |
bfae80f2 | 26635 | { |
c19d1205 ZW |
26636 | offset = -offset; |
26637 | while (offset > 0x100) | |
bfae80f2 | 26638 | { |
c19d1205 ZW |
26639 | add_unwind_opcode (0x7f, 1); |
26640 | offset -= 0x100; | |
bfae80f2 | 26641 | } |
c19d1205 ZW |
26642 | op = ((offset - 4) >> 2) | 0x40; |
26643 | add_unwind_opcode (op, 1); | |
bfae80f2 | 26644 | } |
bfae80f2 RE |
26645 | } |
26646 | ||
c19d1205 | 26647 | /* Finish the list of unwind opcodes for this function. */ |
0198d5e6 | 26648 | |
c19d1205 ZW |
26649 | static void |
26650 | finish_unwind_opcodes (void) | |
bfae80f2 | 26651 | { |
c19d1205 | 26652 | valueT op; |
bfae80f2 | 26653 | |
c19d1205 | 26654 | if (unwind.fp_used) |
bfae80f2 | 26655 | { |
708587a4 | 26656 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
26657 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
26658 | flush_pending_unwind (); | |
bfae80f2 | 26659 | |
c19d1205 ZW |
26660 | /* After restoring sp from the frame pointer. */ |
26661 | op = 0x90 | unwind.fp_reg; | |
26662 | add_unwind_opcode (op, 1); | |
26663 | } | |
26664 | else | |
26665 | flush_pending_unwind (); | |
bfae80f2 RE |
26666 | } |
26667 | ||
bfae80f2 | 26668 | |
c19d1205 ZW |
26669 | /* Start an exception table entry. If idx is nonzero this is an index table |
26670 | entry. */ | |
bfae80f2 RE |
26671 | |
26672 | static void | |
c19d1205 | 26673 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 26674 | { |
c19d1205 ZW |
26675 | const char * text_name; |
26676 | const char * prefix; | |
26677 | const char * prefix_once; | |
26678 | const char * group_name; | |
c19d1205 | 26679 | char * sec_name; |
c19d1205 ZW |
26680 | int type; |
26681 | int flags; | |
26682 | int linkonce; | |
bfae80f2 | 26683 | |
c19d1205 | 26684 | if (idx) |
bfae80f2 | 26685 | { |
c19d1205 ZW |
26686 | prefix = ELF_STRING_ARM_unwind; |
26687 | prefix_once = ELF_STRING_ARM_unwind_once; | |
26688 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 26689 | } |
c19d1205 | 26690 | else |
bfae80f2 | 26691 | { |
c19d1205 ZW |
26692 | prefix = ELF_STRING_ARM_unwind_info; |
26693 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
26694 | type = SHT_PROGBITS; | |
bfae80f2 RE |
26695 | } |
26696 | ||
c19d1205 ZW |
26697 | text_name = segment_name (text_seg); |
26698 | if (streq (text_name, ".text")) | |
26699 | text_name = ""; | |
26700 | ||
26701 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
26702 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 26703 | { |
c19d1205 ZW |
26704 | prefix = prefix_once; |
26705 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
26706 | } |
26707 | ||
29a2809e | 26708 | sec_name = concat (prefix, text_name, (char *) NULL); |
bfae80f2 | 26709 | |
c19d1205 ZW |
26710 | flags = SHF_ALLOC; |
26711 | linkonce = 0; | |
26712 | group_name = 0; | |
bfae80f2 | 26713 | |
c19d1205 ZW |
26714 | /* Handle COMDAT group. */ |
26715 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 26716 | { |
c19d1205 ZW |
26717 | group_name = elf_group_name (text_seg); |
26718 | if (group_name == NULL) | |
26719 | { | |
bd3ba5d1 | 26720 | as_bad (_("Group section `%s' has no group signature"), |
c19d1205 ZW |
26721 | segment_name (text_seg)); |
26722 | ignore_rest_of_line (); | |
26723 | return; | |
26724 | } | |
26725 | flags |= SHF_GROUP; | |
26726 | linkonce = 1; | |
bfae80f2 RE |
26727 | } |
26728 | ||
a91e1603 L |
26729 | obj_elf_change_section (sec_name, type, 0, flags, 0, group_name, |
26730 | linkonce, 0); | |
bfae80f2 | 26731 | |
5f4273c7 | 26732 | /* Set the section link for index tables. */ |
c19d1205 ZW |
26733 | if (idx) |
26734 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
26735 | } |
26736 | ||
bfae80f2 | 26737 | |
c19d1205 ZW |
26738 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
26739 | personality routine data. Returns zero, or the index table value for | |
cad0da33 | 26740 | an inline entry. */ |
c19d1205 ZW |
26741 | |
26742 | static valueT | |
26743 | create_unwind_entry (int have_data) | |
bfae80f2 | 26744 | { |
c19d1205 ZW |
26745 | int size; |
26746 | addressT where; | |
26747 | char *ptr; | |
26748 | /* The current word of data. */ | |
26749 | valueT data; | |
26750 | /* The number of bytes left in this word. */ | |
26751 | int n; | |
bfae80f2 | 26752 | |
c19d1205 | 26753 | finish_unwind_opcodes (); |
bfae80f2 | 26754 | |
c19d1205 ZW |
26755 | /* Remember the current text section. */ |
26756 | unwind.saved_seg = now_seg; | |
26757 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 26758 | |
c19d1205 | 26759 | start_unwind_section (now_seg, 0); |
bfae80f2 | 26760 | |
c19d1205 | 26761 | if (unwind.personality_routine == NULL) |
bfae80f2 | 26762 | { |
c19d1205 ZW |
26763 | if (unwind.personality_index == -2) |
26764 | { | |
26765 | if (have_data) | |
5f4273c7 | 26766 | as_bad (_("handlerdata in cantunwind frame")); |
c19d1205 ZW |
26767 | return 1; /* EXIDX_CANTUNWIND. */ |
26768 | } | |
bfae80f2 | 26769 | |
c19d1205 ZW |
26770 | /* Use a default personality routine if none is specified. */ |
26771 | if (unwind.personality_index == -1) | |
26772 | { | |
26773 | if (unwind.opcode_count > 3) | |
26774 | unwind.personality_index = 1; | |
26775 | else | |
26776 | unwind.personality_index = 0; | |
26777 | } | |
bfae80f2 | 26778 | |
c19d1205 ZW |
26779 | /* Space for the personality routine entry. */ |
26780 | if (unwind.personality_index == 0) | |
26781 | { | |
26782 | if (unwind.opcode_count > 3) | |
26783 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 26784 | |
c19d1205 ZW |
26785 | if (!have_data) |
26786 | { | |
26787 | /* All the data is inline in the index table. */ | |
26788 | data = 0x80; | |
26789 | n = 3; | |
26790 | while (unwind.opcode_count > 0) | |
26791 | { | |
26792 | unwind.opcode_count--; | |
26793 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
26794 | n--; | |
26795 | } | |
bfae80f2 | 26796 | |
c19d1205 ZW |
26797 | /* Pad with "finish" opcodes. */ |
26798 | while (n--) | |
26799 | data = (data << 8) | 0xb0; | |
bfae80f2 | 26800 | |
c19d1205 ZW |
26801 | return data; |
26802 | } | |
26803 | size = 0; | |
26804 | } | |
26805 | else | |
26806 | /* We get two opcodes "free" in the first word. */ | |
26807 | size = unwind.opcode_count - 2; | |
26808 | } | |
26809 | else | |
5011093d | 26810 | { |
cad0da33 NC |
26811 | /* PR 16765: Missing or misplaced unwind directives can trigger this. */ |
26812 | if (unwind.personality_index != -1) | |
26813 | { | |
26814 | as_bad (_("attempt to recreate an unwind entry")); | |
26815 | return 1; | |
26816 | } | |
5011093d NC |
26817 | |
26818 | /* An extra byte is required for the opcode count. */ | |
26819 | size = unwind.opcode_count + 1; | |
26820 | } | |
bfae80f2 | 26821 | |
c19d1205 ZW |
26822 | size = (size + 3) >> 2; |
26823 | if (size > 0xff) | |
26824 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 26825 | |
c19d1205 ZW |
26826 | frag_align (2, 0, 0); |
26827 | record_alignment (now_seg, 2); | |
26828 | unwind.table_entry = expr_build_dot (); | |
26829 | ||
26830 | /* Allocate the table entry. */ | |
26831 | ptr = frag_more ((size << 2) + 4); | |
74929e7b NC |
26832 | /* PR 13449: Zero the table entries in case some of them are not used. */ |
26833 | memset (ptr, 0, (size << 2) + 4); | |
c19d1205 | 26834 | where = frag_now_fix () - ((size << 2) + 4); |
bfae80f2 | 26835 | |
c19d1205 | 26836 | switch (unwind.personality_index) |
bfae80f2 | 26837 | { |
c19d1205 ZW |
26838 | case -1: |
26839 | /* ??? Should this be a PLT generating relocation? */ | |
26840 | /* Custom personality routine. */ | |
26841 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
26842 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 26843 | |
c19d1205 ZW |
26844 | where += 4; |
26845 | ptr += 4; | |
bfae80f2 | 26846 | |
c19d1205 | 26847 | /* Set the first byte to the number of additional words. */ |
5011093d | 26848 | data = size > 0 ? size - 1 : 0; |
c19d1205 ZW |
26849 | n = 3; |
26850 | break; | |
bfae80f2 | 26851 | |
c19d1205 ZW |
26852 | /* ABI defined personality routines. */ |
26853 | case 0: | |
26854 | /* Three opcodes bytes are packed into the first word. */ | |
26855 | data = 0x80; | |
26856 | n = 3; | |
26857 | break; | |
bfae80f2 | 26858 | |
c19d1205 ZW |
26859 | case 1: |
26860 | case 2: | |
26861 | /* The size and first two opcode bytes go in the first word. */ | |
26862 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
26863 | n = 2; | |
26864 | break; | |
bfae80f2 | 26865 | |
c19d1205 ZW |
26866 | default: |
26867 | /* Should never happen. */ | |
26868 | abort (); | |
26869 | } | |
bfae80f2 | 26870 | |
c19d1205 ZW |
26871 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
26872 | time. */ | |
26873 | while (unwind.opcode_count > 0) | |
26874 | { | |
26875 | if (n == 0) | |
26876 | { | |
26877 | md_number_to_chars (ptr, data, 4); | |
26878 | ptr += 4; | |
26879 | n = 4; | |
26880 | data = 0; | |
26881 | } | |
26882 | unwind.opcode_count--; | |
26883 | n--; | |
26884 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
26885 | } | |
26886 | ||
26887 | /* Finish off the last word. */ | |
26888 | if (n < 4) | |
26889 | { | |
26890 | /* Pad with "finish" opcodes. */ | |
26891 | while (n--) | |
26892 | data = (data << 8) | 0xb0; | |
26893 | ||
26894 | md_number_to_chars (ptr, data, 4); | |
26895 | } | |
26896 | ||
26897 | if (!have_data) | |
26898 | { | |
26899 | /* Add an empty descriptor if there is no user-specified data. */ | |
26900 | ptr = frag_more (4); | |
26901 | md_number_to_chars (ptr, 0, 4); | |
26902 | } | |
26903 | ||
26904 | return 0; | |
bfae80f2 RE |
26905 | } |
26906 | ||
f0927246 NC |
26907 | |
26908 | /* Initialize the DWARF-2 unwind information for this procedure. */ | |
26909 | ||
26910 | void | |
26911 | tc_arm_frame_initial_instructions (void) | |
26912 | { | |
26913 | cfi_add_CFA_def_cfa (REG_SP, 0); | |
26914 | } | |
26915 | #endif /* OBJ_ELF */ | |
26916 | ||
c19d1205 ZW |
26917 | /* Convert REGNAME to a DWARF-2 register number. */ |
26918 | ||
26919 | int | |
1df69f4f | 26920 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 26921 | { |
1df69f4f | 26922 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
1f5afe1c NC |
26923 | if (reg != FAIL) |
26924 | return reg; | |
c19d1205 | 26925 | |
1f5afe1c NC |
26926 | /* PR 16694: Allow VFP registers as well. */ |
26927 | reg = arm_reg_parse (®name, REG_TYPE_VFS); | |
26928 | if (reg != FAIL) | |
26929 | return 64 + reg; | |
c19d1205 | 26930 | |
1f5afe1c NC |
26931 | reg = arm_reg_parse (®name, REG_TYPE_VFD); |
26932 | if (reg != FAIL) | |
26933 | return reg + 256; | |
26934 | ||
0198d5e6 | 26935 | return FAIL; |
bfae80f2 RE |
26936 | } |
26937 | ||
f0927246 | 26938 | #ifdef TE_PE |
c19d1205 | 26939 | void |
f0927246 | 26940 | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
bfae80f2 | 26941 | { |
91d6fa6a | 26942 | expressionS exp; |
bfae80f2 | 26943 | |
91d6fa6a NC |
26944 | exp.X_op = O_secrel; |
26945 | exp.X_add_symbol = symbol; | |
26946 | exp.X_add_number = 0; | |
26947 | emit_expr (&exp, size); | |
f0927246 NC |
26948 | } |
26949 | #endif | |
bfae80f2 | 26950 | |
c19d1205 | 26951 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 26952 | |
2fc8bdac ZW |
26953 | /* Return the address within the segment that a PC-relative fixup is |
26954 | relative to. For ARM, PC-relative fixups applied to instructions | |
26955 | are generally relative to the location of the fixup plus 8 bytes. | |
26956 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
26957 | require special handling. */ | |
bfae80f2 | 26958 | |
c19d1205 | 26959 | long |
2fc8bdac | 26960 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 26961 | { |
2fc8bdac ZW |
26962 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
26963 | ||
26964 | /* If this is pc-relative and we are going to emit a relocation | |
26965 | then we just want to put out any pipeline compensation that the linker | |
53baae48 NC |
26966 | will need. Otherwise we want to use the calculated base. |
26967 | For WinCE we skip the bias for externals as well, since this | |
26968 | is how the MS ARM-CE assembler behaves and we want to be compatible. */ | |
5f4273c7 | 26969 | if (fixP->fx_pcrel |
2fc8bdac | 26970 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) |
53baae48 NC |
26971 | || (arm_force_relocation (fixP) |
26972 | #ifdef TE_WINCE | |
26973 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
26974 | #endif | |
26975 | ))) | |
2fc8bdac | 26976 | base = 0; |
bfae80f2 | 26977 | |
267bf995 | 26978 | |
c19d1205 | 26979 | switch (fixP->fx_r_type) |
bfae80f2 | 26980 | { |
2fc8bdac ZW |
26981 | /* PC relative addressing on the Thumb is slightly odd as the |
26982 | bottom two bits of the PC are forced to zero for the | |
26983 | calculation. This happens *after* application of the | |
26984 | pipeline offset. However, Thumb adrl already adjusts for | |
26985 | this, so we need not do it again. */ | |
c19d1205 | 26986 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 26987 | return base & ~3; |
c19d1205 ZW |
26988 | |
26989 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
26990 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 26991 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 26992 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 26993 | return (base + 4) & ~3; |
c19d1205 | 26994 | |
2fc8bdac | 26995 | /* Thumb branches are simply offset by +4. */ |
e12437dc | 26996 | case BFD_RELOC_THUMB_PCREL_BRANCH5: |
2fc8bdac ZW |
26997 | case BFD_RELOC_THUMB_PCREL_BRANCH7: |
26998 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
26999 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
27000 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
2fc8bdac | 27001 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
f6b2b12d | 27002 | case BFD_RELOC_THUMB_PCREL_BFCSEL: |
e5d6e09e | 27003 | case BFD_RELOC_ARM_THUMB_BF17: |
1caf72a5 | 27004 | case BFD_RELOC_ARM_THUMB_BF19: |
1889da70 | 27005 | case BFD_RELOC_ARM_THUMB_BF13: |
60f993ce | 27006 | case BFD_RELOC_ARM_THUMB_LOOP12: |
2fc8bdac | 27007 | return base + 4; |
bfae80f2 | 27008 | |
267bf995 | 27009 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
486499d0 CL |
27010 | if (fixP->fx_addsy |
27011 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 27012 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 | 27013 | && ARM_IS_FUNC (fixP->fx_addsy) |
477330fc RM |
27014 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) |
27015 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
267bf995 RR |
27016 | return base + 4; |
27017 | ||
00adf2d4 JB |
27018 | /* BLX is like branches above, but forces the low two bits of PC to |
27019 | zero. */ | |
486499d0 CL |
27020 | case BFD_RELOC_THUMB_PCREL_BLX: |
27021 | if (fixP->fx_addsy | |
27022 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 27023 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
27024 | && THUMB_IS_FUNC (fixP->fx_addsy) |
27025 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
27026 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
00adf2d4 JB |
27027 | return (base + 4) & ~3; |
27028 | ||
2fc8bdac ZW |
27029 | /* ARM mode branches are offset by +8. However, the Windows CE |
27030 | loader expects the relocation not to take this into account. */ | |
267bf995 | 27031 | case BFD_RELOC_ARM_PCREL_BLX: |
486499d0 CL |
27032 | if (fixP->fx_addsy |
27033 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 27034 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
27035 | && ARM_IS_FUNC (fixP->fx_addsy) |
27036 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
27037 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 27038 | return base + 8; |
267bf995 | 27039 | |
486499d0 CL |
27040 | case BFD_RELOC_ARM_PCREL_CALL: |
27041 | if (fixP->fx_addsy | |
27042 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 27043 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
27044 | && THUMB_IS_FUNC (fixP->fx_addsy) |
27045 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
27046 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 27047 | return base + 8; |
267bf995 | 27048 | |
2fc8bdac | 27049 | case BFD_RELOC_ARM_PCREL_BRANCH: |
39b41c9c | 27050 | case BFD_RELOC_ARM_PCREL_JUMP: |
2fc8bdac | 27051 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 27052 | #ifdef TE_WINCE |
5f4273c7 | 27053 | /* When handling fixups immediately, because we have already |
477330fc | 27054 | discovered the value of a symbol, or the address of the frag involved |
53baae48 | 27055 | we must account for the offset by +8, as the OS loader will never see the reloc. |
477330fc RM |
27056 | see fixup_segment() in write.c |
27057 | The S_IS_EXTERNAL test handles the case of global symbols. | |
27058 | Those need the calculated base, not just the pipe compensation the linker will need. */ | |
53baae48 NC |
27059 | if (fixP->fx_pcrel |
27060 | && fixP->fx_addsy != NULL | |
27061 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
27062 | && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP))) | |
27063 | return base + 8; | |
2fc8bdac | 27064 | return base; |
c19d1205 | 27065 | #else |
2fc8bdac | 27066 | return base + 8; |
c19d1205 | 27067 | #endif |
2fc8bdac | 27068 | |
267bf995 | 27069 | |
2fc8bdac ZW |
27070 | /* ARM mode loads relative to PC are also offset by +8. Unlike |
27071 | branches, the Windows CE loader *does* expect the relocation | |
27072 | to take this into account. */ | |
27073 | case BFD_RELOC_ARM_OFFSET_IMM: | |
27074 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
27075 | case BFD_RELOC_ARM_HWLITERAL: | |
27076 | case BFD_RELOC_ARM_LITERAL: | |
27077 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
27078 | return base + 8; | |
27079 | ||
27080 | ||
27081 | /* Other PC-relative relocations are un-offset. */ | |
27082 | default: | |
27083 | return base; | |
27084 | } | |
bfae80f2 RE |
27085 | } |
27086 | ||
8b2d793c NC |
27087 | static bfd_boolean flag_warn_syms = TRUE; |
27088 | ||
ae8714c2 NC |
27089 | bfd_boolean |
27090 | arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name) | |
bfae80f2 | 27091 | { |
8b2d793c NC |
27092 | /* PR 18347 - Warn if the user attempts to create a symbol with the same |
27093 | name as an ARM instruction. Whilst strictly speaking it is allowed, it | |
27094 | does mean that the resulting code might be very confusing to the reader. | |
27095 | Also this warning can be triggered if the user omits an operand before | |
27096 | an immediate address, eg: | |
27097 | ||
27098 | LDR =foo | |
27099 | ||
27100 | GAS treats this as an assignment of the value of the symbol foo to a | |
27101 | symbol LDR, and so (without this code) it will not issue any kind of | |
27102 | warning or error message. | |
27103 | ||
27104 | Note - ARM instructions are case-insensitive but the strings in the hash | |
27105 | table are all stored in lower case, so we must first ensure that name is | |
ae8714c2 NC |
27106 | lower case too. */ |
27107 | if (flag_warn_syms && arm_ops_hsh) | |
8b2d793c NC |
27108 | { |
27109 | char * nbuf = strdup (name); | |
27110 | char * p; | |
27111 | ||
27112 | for (p = nbuf; *p; p++) | |
27113 | *p = TOLOWER (*p); | |
27114 | if (hash_find (arm_ops_hsh, nbuf) != NULL) | |
27115 | { | |
27116 | static struct hash_control * already_warned = NULL; | |
27117 | ||
27118 | if (already_warned == NULL) | |
27119 | already_warned = hash_new (); | |
27120 | /* Only warn about the symbol once. To keep the code | |
27121 | simple we let hash_insert do the lookup for us. */ | |
3076e594 | 27122 | if (hash_insert (already_warned, nbuf, NULL) == NULL) |
ae8714c2 | 27123 | as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name); |
8b2d793c NC |
27124 | } |
27125 | else | |
27126 | free (nbuf); | |
27127 | } | |
3739860c | 27128 | |
ae8714c2 NC |
27129 | return FALSE; |
27130 | } | |
27131 | ||
27132 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. | |
27133 | Otherwise we have no need to default values of symbols. */ | |
27134 | ||
27135 | symbolS * | |
27136 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
27137 | { | |
27138 | #ifdef OBJ_ELF | |
27139 | if (name[0] == '_' && name[1] == 'G' | |
27140 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
27141 | { | |
27142 | if (!GOT_symbol) | |
27143 | { | |
27144 | if (symbol_find (name)) | |
27145 | as_bad (_("GOT already in the symbol table")); | |
27146 | ||
27147 | GOT_symbol = symbol_new (name, undefined_section, | |
27148 | (valueT) 0, & zero_address_frag); | |
27149 | } | |
27150 | ||
27151 | return GOT_symbol; | |
27152 | } | |
27153 | #endif | |
27154 | ||
c921be7d | 27155 | return NULL; |
bfae80f2 RE |
27156 | } |
27157 | ||
55cf6793 | 27158 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
27159 | computed as two separate immediate values, added together. We |
27160 | already know that this value cannot be computed by just one ARM | |
27161 | instruction. */ | |
27162 | ||
27163 | static unsigned int | |
27164 | validate_immediate_twopart (unsigned int val, | |
27165 | unsigned int * highpart) | |
bfae80f2 | 27166 | { |
c19d1205 ZW |
27167 | unsigned int a; |
27168 | unsigned int i; | |
bfae80f2 | 27169 | |
c19d1205 ZW |
27170 | for (i = 0; i < 32; i += 2) |
27171 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
27172 | { | |
27173 | if (a & 0xff00) | |
27174 | { | |
27175 | if (a & ~ 0xffff) | |
27176 | continue; | |
27177 | * highpart = (a >> 8) | ((i + 24) << 7); | |
27178 | } | |
27179 | else if (a & 0xff0000) | |
27180 | { | |
27181 | if (a & 0xff000000) | |
27182 | continue; | |
27183 | * highpart = (a >> 16) | ((i + 16) << 7); | |
27184 | } | |
27185 | else | |
27186 | { | |
9c2799c2 | 27187 | gas_assert (a & 0xff000000); |
c19d1205 ZW |
27188 | * highpart = (a >> 24) | ((i + 8) << 7); |
27189 | } | |
bfae80f2 | 27190 | |
c19d1205 ZW |
27191 | return (a & 0xff) | (i << 7); |
27192 | } | |
bfae80f2 | 27193 | |
c19d1205 | 27194 | return FAIL; |
bfae80f2 RE |
27195 | } |
27196 | ||
c19d1205 ZW |
27197 | static int |
27198 | validate_offset_imm (unsigned int val, int hwse) | |
27199 | { | |
27200 | if ((hwse && val > 255) || val > 4095) | |
27201 | return FAIL; | |
27202 | return val; | |
27203 | } | |
bfae80f2 | 27204 | |
55cf6793 | 27205 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
27206 | negative immediate constant by altering the instruction. A bit of |
27207 | a hack really. | |
27208 | MOV <-> MVN | |
27209 | AND <-> BIC | |
27210 | ADC <-> SBC | |
27211 | by inverting the second operand, and | |
27212 | ADD <-> SUB | |
27213 | CMP <-> CMN | |
27214 | by negating the second operand. */ | |
bfae80f2 | 27215 | |
c19d1205 ZW |
27216 | static int |
27217 | negate_data_op (unsigned long * instruction, | |
27218 | unsigned long value) | |
bfae80f2 | 27219 | { |
c19d1205 ZW |
27220 | int op, new_inst; |
27221 | unsigned long negated, inverted; | |
bfae80f2 | 27222 | |
c19d1205 ZW |
27223 | negated = encode_arm_immediate (-value); |
27224 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 27225 | |
c19d1205 ZW |
27226 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
27227 | switch (op) | |
bfae80f2 | 27228 | { |
c19d1205 ZW |
27229 | /* First negates. */ |
27230 | case OPCODE_SUB: /* ADD <-> SUB */ | |
27231 | new_inst = OPCODE_ADD; | |
27232 | value = negated; | |
27233 | break; | |
bfae80f2 | 27234 | |
c19d1205 ZW |
27235 | case OPCODE_ADD: |
27236 | new_inst = OPCODE_SUB; | |
27237 | value = negated; | |
27238 | break; | |
bfae80f2 | 27239 | |
c19d1205 ZW |
27240 | case OPCODE_CMP: /* CMP <-> CMN */ |
27241 | new_inst = OPCODE_CMN; | |
27242 | value = negated; | |
27243 | break; | |
bfae80f2 | 27244 | |
c19d1205 ZW |
27245 | case OPCODE_CMN: |
27246 | new_inst = OPCODE_CMP; | |
27247 | value = negated; | |
27248 | break; | |
bfae80f2 | 27249 | |
c19d1205 ZW |
27250 | /* Now Inverted ops. */ |
27251 | case OPCODE_MOV: /* MOV <-> MVN */ | |
27252 | new_inst = OPCODE_MVN; | |
27253 | value = inverted; | |
27254 | break; | |
bfae80f2 | 27255 | |
c19d1205 ZW |
27256 | case OPCODE_MVN: |
27257 | new_inst = OPCODE_MOV; | |
27258 | value = inverted; | |
27259 | break; | |
bfae80f2 | 27260 | |
c19d1205 ZW |
27261 | case OPCODE_AND: /* AND <-> BIC */ |
27262 | new_inst = OPCODE_BIC; | |
27263 | value = inverted; | |
27264 | break; | |
bfae80f2 | 27265 | |
c19d1205 ZW |
27266 | case OPCODE_BIC: |
27267 | new_inst = OPCODE_AND; | |
27268 | value = inverted; | |
27269 | break; | |
bfae80f2 | 27270 | |
c19d1205 ZW |
27271 | case OPCODE_ADC: /* ADC <-> SBC */ |
27272 | new_inst = OPCODE_SBC; | |
27273 | value = inverted; | |
27274 | break; | |
bfae80f2 | 27275 | |
c19d1205 ZW |
27276 | case OPCODE_SBC: |
27277 | new_inst = OPCODE_ADC; | |
27278 | value = inverted; | |
27279 | break; | |
bfae80f2 | 27280 | |
c19d1205 ZW |
27281 | /* We cannot do anything. */ |
27282 | default: | |
27283 | return FAIL; | |
b99bd4ef NC |
27284 | } |
27285 | ||
c19d1205 ZW |
27286 | if (value == (unsigned) FAIL) |
27287 | return FAIL; | |
27288 | ||
27289 | *instruction &= OPCODE_MASK; | |
27290 | *instruction |= new_inst << DATA_OP_SHIFT; | |
27291 | return value; | |
b99bd4ef NC |
27292 | } |
27293 | ||
ef8d22e6 PB |
27294 | /* Like negate_data_op, but for Thumb-2. */ |
27295 | ||
27296 | static unsigned int | |
16dd5e42 | 27297 | thumb32_negate_data_op (offsetT *instruction, unsigned int value) |
ef8d22e6 PB |
27298 | { |
27299 | int op, new_inst; | |
27300 | int rd; | |
16dd5e42 | 27301 | unsigned int negated, inverted; |
ef8d22e6 PB |
27302 | |
27303 | negated = encode_thumb32_immediate (-value); | |
27304 | inverted = encode_thumb32_immediate (~value); | |
27305 | ||
27306 | rd = (*instruction >> 8) & 0xf; | |
27307 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
27308 | switch (op) | |
27309 | { | |
27310 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
27311 | case T2_OPCODE_SUB: | |
27312 | new_inst = T2_OPCODE_ADD; | |
27313 | value = negated; | |
27314 | break; | |
27315 | ||
27316 | case T2_OPCODE_ADD: | |
27317 | new_inst = T2_OPCODE_SUB; | |
27318 | value = negated; | |
27319 | break; | |
27320 | ||
27321 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
27322 | case T2_OPCODE_ORR: | |
27323 | new_inst = T2_OPCODE_ORN; | |
27324 | value = inverted; | |
27325 | break; | |
27326 | ||
27327 | case T2_OPCODE_ORN: | |
27328 | new_inst = T2_OPCODE_ORR; | |
27329 | value = inverted; | |
27330 | break; | |
27331 | ||
27332 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
27333 | case T2_OPCODE_AND: | |
27334 | new_inst = T2_OPCODE_BIC; | |
27335 | if (rd == 15) | |
27336 | value = FAIL; | |
27337 | else | |
27338 | value = inverted; | |
27339 | break; | |
27340 | ||
27341 | case T2_OPCODE_BIC: | |
27342 | new_inst = T2_OPCODE_AND; | |
27343 | value = inverted; | |
27344 | break; | |
27345 | ||
27346 | /* ADC <-> SBC */ | |
27347 | case T2_OPCODE_ADC: | |
27348 | new_inst = T2_OPCODE_SBC; | |
27349 | value = inverted; | |
27350 | break; | |
27351 | ||
27352 | case T2_OPCODE_SBC: | |
27353 | new_inst = T2_OPCODE_ADC; | |
27354 | value = inverted; | |
27355 | break; | |
27356 | ||
27357 | /* We cannot do anything. */ | |
27358 | default: | |
27359 | return FAIL; | |
27360 | } | |
27361 | ||
16dd5e42 | 27362 | if (value == (unsigned int)FAIL) |
ef8d22e6 PB |
27363 | return FAIL; |
27364 | ||
27365 | *instruction &= T2_OPCODE_MASK; | |
27366 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
27367 | return value; | |
27368 | } | |
27369 | ||
8f06b2d8 | 27370 | /* Read a 32-bit thumb instruction from buf. */ |
0198d5e6 | 27371 | |
8f06b2d8 PB |
27372 | static unsigned long |
27373 | get_thumb32_insn (char * buf) | |
27374 | { | |
27375 | unsigned long insn; | |
27376 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
27377 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
27378 | ||
27379 | return insn; | |
27380 | } | |
27381 | ||
a8bc6c78 PB |
27382 | /* We usually want to set the low bit on the address of thumb function |
27383 | symbols. In particular .word foo - . should have the low bit set. | |
27384 | Generic code tries to fold the difference of two symbols to | |
27385 | a constant. Prevent this and force a relocation when the first symbols | |
27386 | is a thumb function. */ | |
c921be7d NC |
27387 | |
27388 | bfd_boolean | |
a8bc6c78 PB |
27389 | arm_optimize_expr (expressionS *l, operatorT op, expressionS *r) |
27390 | { | |
27391 | if (op == O_subtract | |
27392 | && l->X_op == O_symbol | |
27393 | && r->X_op == O_symbol | |
27394 | && THUMB_IS_FUNC (l->X_add_symbol)) | |
27395 | { | |
27396 | l->X_op = O_subtract; | |
27397 | l->X_op_symbol = r->X_add_symbol; | |
27398 | l->X_add_number -= r->X_add_number; | |
c921be7d | 27399 | return TRUE; |
a8bc6c78 | 27400 | } |
c921be7d | 27401 | |
a8bc6c78 | 27402 | /* Process as normal. */ |
c921be7d | 27403 | return FALSE; |
a8bc6c78 PB |
27404 | } |
27405 | ||
4a42ebbc RR |
27406 | /* Encode Thumb2 unconditional branches and calls. The encoding |
27407 | for the 2 are identical for the immediate values. */ | |
27408 | ||
27409 | static void | |
27410 | encode_thumb2_b_bl_offset (char * buf, offsetT value) | |
27411 | { | |
27412 | #define T2I1I2MASK ((1 << 13) | (1 << 11)) | |
27413 | offsetT newval; | |
27414 | offsetT newval2; | |
27415 | addressT S, I1, I2, lo, hi; | |
27416 | ||
27417 | S = (value >> 24) & 0x01; | |
27418 | I1 = (value >> 23) & 0x01; | |
27419 | I2 = (value >> 22) & 0x01; | |
27420 | hi = (value >> 12) & 0x3ff; | |
fa94de6b | 27421 | lo = (value >> 1) & 0x7ff; |
4a42ebbc RR |
27422 | newval = md_chars_to_number (buf, THUMB_SIZE); |
27423 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
27424 | newval |= (S << 10) | hi; | |
27425 | newval2 &= ~T2I1I2MASK; | |
27426 | newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK; | |
27427 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
27428 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
27429 | } | |
27430 | ||
c19d1205 | 27431 | void |
55cf6793 | 27432 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
27433 | valueT * valP, |
27434 | segT seg) | |
27435 | { | |
27436 | offsetT value = * valP; | |
27437 | offsetT newval; | |
27438 | unsigned int newimm; | |
27439 | unsigned long temp; | |
27440 | int sign; | |
27441 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 27442 | |
9c2799c2 | 27443 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 27444 | |
c19d1205 | 27445 | /* Note whether this will delete the relocation. */ |
4962c51a | 27446 | |
c19d1205 ZW |
27447 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
27448 | fixP->fx_done = 1; | |
b99bd4ef | 27449 | |
adbaf948 | 27450 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
5f4273c7 | 27451 | consistency with the behaviour on 32-bit hosts. Remember value |
adbaf948 ZW |
27452 | for emit_reloc. */ |
27453 | value &= 0xffffffff; | |
27454 | value ^= 0x80000000; | |
5f4273c7 | 27455 | value -= 0x80000000; |
adbaf948 ZW |
27456 | |
27457 | *valP = value; | |
c19d1205 | 27458 | fixP->fx_addnumber = value; |
b99bd4ef | 27459 | |
adbaf948 ZW |
27460 | /* Same treatment for fixP->fx_offset. */ |
27461 | fixP->fx_offset &= 0xffffffff; | |
27462 | fixP->fx_offset ^= 0x80000000; | |
27463 | fixP->fx_offset -= 0x80000000; | |
27464 | ||
c19d1205 | 27465 | switch (fixP->fx_r_type) |
b99bd4ef | 27466 | { |
c19d1205 ZW |
27467 | case BFD_RELOC_NONE: |
27468 | /* This will need to go in the object file. */ | |
27469 | fixP->fx_done = 0; | |
27470 | break; | |
b99bd4ef | 27471 | |
c19d1205 ZW |
27472 | case BFD_RELOC_ARM_IMMEDIATE: |
27473 | /* We claim that this fixup has been processed here, | |
27474 | even if in fact we generate an error because we do | |
27475 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
27476 | fixP->fx_done = 1; | |
b99bd4ef | 27477 | |
77db8e2e | 27478 | if (fixP->fx_addsy) |
b99bd4ef | 27479 | { |
77db8e2e | 27480 | const char *msg = 0; |
b99bd4ef | 27481 | |
77db8e2e NC |
27482 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
27483 | msg = _("undefined symbol %s used as an immediate value"); | |
27484 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
27485 | msg = _("symbol %s is in a different section"); | |
27486 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
27487 | msg = _("symbol %s is weak and may be overridden later"); | |
27488 | ||
27489 | if (msg) | |
27490 | { | |
27491 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27492 | msg, S_GET_NAME (fixP->fx_addsy)); | |
27493 | break; | |
27494 | } | |
42e5fcbf AS |
27495 | } |
27496 | ||
c19d1205 ZW |
27497 | temp = md_chars_to_number (buf, INSN_SIZE); |
27498 | ||
5e73442d SL |
27499 | /* If the offset is negative, we should use encoding A2 for ADR. */ |
27500 | if ((temp & 0xfff0000) == 0x28f0000 && value < 0) | |
27501 | newimm = negate_data_op (&temp, value); | |
27502 | else | |
27503 | { | |
27504 | newimm = encode_arm_immediate (value); | |
27505 | ||
27506 | /* If the instruction will fail, see if we can fix things up by | |
27507 | changing the opcode. */ | |
27508 | if (newimm == (unsigned int) FAIL) | |
27509 | newimm = negate_data_op (&temp, value); | |
bada4342 JW |
27510 | /* MOV accepts both ARM modified immediate (A1 encoding) and |
27511 | UINT16 (A2 encoding) when possible, MOVW only accepts UINT16. | |
27512 | When disassembling, MOV is preferred when there is no encoding | |
27513 | overlap. */ | |
27514 | if (newimm == (unsigned int) FAIL | |
27515 | && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV | |
27516 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2) | |
27517 | && !((temp >> SBIT_SHIFT) & 0x1) | |
27518 | && value >= 0 && value <= 0xffff) | |
27519 | { | |
27520 | /* Clear bits[23:20] to change encoding from A1 to A2. */ | |
27521 | temp &= 0xff0fffff; | |
27522 | /* Encoding high 4bits imm. Code below will encode the remaining | |
27523 | low 12bits. */ | |
27524 | temp |= (value & 0x0000f000) << 4; | |
27525 | newimm = value & 0x00000fff; | |
27526 | } | |
5e73442d SL |
27527 | } |
27528 | ||
27529 | if (newimm == (unsigned int) FAIL) | |
b99bd4ef | 27530 | { |
c19d1205 ZW |
27531 | as_bad_where (fixP->fx_file, fixP->fx_line, |
27532 | _("invalid constant (%lx) after fixup"), | |
27533 | (unsigned long) value); | |
27534 | break; | |
b99bd4ef | 27535 | } |
b99bd4ef | 27536 | |
c19d1205 ZW |
27537 | newimm |= (temp & 0xfffff000); |
27538 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
27539 | break; | |
b99bd4ef | 27540 | |
c19d1205 ZW |
27541 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
27542 | { | |
27543 | unsigned int highpart = 0; | |
27544 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 27545 | |
77db8e2e | 27546 | if (fixP->fx_addsy) |
42e5fcbf | 27547 | { |
77db8e2e | 27548 | const char *msg = 0; |
42e5fcbf | 27549 | |
77db8e2e NC |
27550 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
27551 | msg = _("undefined symbol %s used as an immediate value"); | |
27552 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
27553 | msg = _("symbol %s is in a different section"); | |
27554 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
27555 | msg = _("symbol %s is weak and may be overridden later"); | |
42e5fcbf | 27556 | |
77db8e2e NC |
27557 | if (msg) |
27558 | { | |
27559 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27560 | msg, S_GET_NAME (fixP->fx_addsy)); | |
27561 | break; | |
27562 | } | |
27563 | } | |
fa94de6b | 27564 | |
c19d1205 ZW |
27565 | newimm = encode_arm_immediate (value); |
27566 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 27567 | |
c19d1205 ZW |
27568 | /* If the instruction will fail, see if we can fix things up by |
27569 | changing the opcode. */ | |
27570 | if (newimm == (unsigned int) FAIL | |
27571 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
27572 | { | |
27573 | /* No ? OK - try using two ADD instructions to generate | |
27574 | the value. */ | |
27575 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 27576 | |
c19d1205 ZW |
27577 | /* Yes - then make sure that the second instruction is |
27578 | also an add. */ | |
27579 | if (newimm != (unsigned int) FAIL) | |
27580 | newinsn = temp; | |
27581 | /* Still No ? Try using a negated value. */ | |
27582 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
27583 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
27584 | /* Otherwise - give up. */ | |
27585 | else | |
27586 | { | |
27587 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27588 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
27589 | (long) value); | |
27590 | break; | |
27591 | } | |
b99bd4ef | 27592 | |
c19d1205 ZW |
27593 | /* Replace the first operand in the 2nd instruction (which |
27594 | is the PC) with the destination register. We have | |
27595 | already added in the PC in the first instruction and we | |
27596 | do not want to do it again. */ | |
27597 | newinsn &= ~ 0xf0000; | |
27598 | newinsn |= ((newinsn & 0x0f000) << 4); | |
27599 | } | |
b99bd4ef | 27600 | |
c19d1205 ZW |
27601 | newimm |= (temp & 0xfffff000); |
27602 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 27603 | |
c19d1205 ZW |
27604 | highpart |= (newinsn & 0xfffff000); |
27605 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
27606 | } | |
27607 | break; | |
b99bd4ef | 27608 | |
c19d1205 | 27609 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
27610 | if (!fixP->fx_done && seg->use_rela_p) |
27611 | value = 0; | |
1a0670f3 | 27612 | /* Fall through. */ |
00a97672 | 27613 | |
c19d1205 | 27614 | case BFD_RELOC_ARM_LITERAL: |
26d97720 | 27615 | sign = value > 0; |
b99bd4ef | 27616 | |
c19d1205 ZW |
27617 | if (value < 0) |
27618 | value = - value; | |
b99bd4ef | 27619 | |
c19d1205 | 27620 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 27621 | { |
c19d1205 ZW |
27622 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
27623 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27624 | _("invalid literal constant: pool needs to be closer")); | |
27625 | else | |
27626 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27627 | _("bad immediate value for offset (%ld)"), | |
27628 | (long) value); | |
27629 | break; | |
f03698e6 RE |
27630 | } |
27631 | ||
c19d1205 | 27632 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
27633 | if (value == 0) |
27634 | newval &= 0xfffff000; | |
27635 | else | |
27636 | { | |
27637 | newval &= 0xff7ff000; | |
27638 | newval |= value | (sign ? INDEX_UP : 0); | |
27639 | } | |
c19d1205 ZW |
27640 | md_number_to_chars (buf, newval, INSN_SIZE); |
27641 | break; | |
b99bd4ef | 27642 | |
c19d1205 ZW |
27643 | case BFD_RELOC_ARM_OFFSET_IMM8: |
27644 | case BFD_RELOC_ARM_HWLITERAL: | |
26d97720 | 27645 | sign = value > 0; |
b99bd4ef | 27646 | |
c19d1205 ZW |
27647 | if (value < 0) |
27648 | value = - value; | |
b99bd4ef | 27649 | |
c19d1205 | 27650 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 27651 | { |
c19d1205 ZW |
27652 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
27653 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27654 | _("invalid literal constant: pool needs to be closer")); | |
27655 | else | |
427d0db6 RM |
27656 | as_bad_where (fixP->fx_file, fixP->fx_line, |
27657 | _("bad immediate value for 8-bit offset (%ld)"), | |
27658 | (long) value); | |
c19d1205 | 27659 | break; |
b99bd4ef NC |
27660 | } |
27661 | ||
c19d1205 | 27662 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
27663 | if (value == 0) |
27664 | newval &= 0xfffff0f0; | |
27665 | else | |
27666 | { | |
27667 | newval &= 0xff7ff0f0; | |
27668 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
27669 | } | |
c19d1205 ZW |
27670 | md_number_to_chars (buf, newval, INSN_SIZE); |
27671 | break; | |
b99bd4ef | 27672 | |
c19d1205 ZW |
27673 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
27674 | if (value < 0 || value > 1020 || value % 4 != 0) | |
27675 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27676 | _("bad immediate value for offset (%ld)"), (long) value); | |
27677 | value /= 4; | |
b99bd4ef | 27678 | |
c19d1205 | 27679 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
27680 | newval |= value; |
27681 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
27682 | break; | |
b99bd4ef | 27683 | |
c19d1205 ZW |
27684 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
27685 | /* This is a complicated relocation used for all varieties of Thumb32 | |
27686 | load/store instruction with immediate offset: | |
27687 | ||
27688 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
477330fc | 27689 | *4, optional writeback(W) |
c19d1205 ZW |
27690 | (doubleword load/store) |
27691 | ||
27692 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
27693 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
27694 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
27695 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
27696 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
27697 | ||
27698 | Uppercase letters indicate bits that are already encoded at | |
27699 | this point. Lowercase letters are our problem. For the | |
27700 | second block of instructions, the secondary opcode nybble | |
27701 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
27702 | a PC-relative operation. */ | |
27703 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
27704 | newval <<= 16; | |
27705 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 27706 | |
c19d1205 | 27707 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 27708 | { |
c19d1205 ZW |
27709 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
27710 | if (value >= 0) | |
27711 | newval |= (1 << 23); | |
27712 | else | |
27713 | value = -value; | |
27714 | if (value % 4 != 0) | |
27715 | { | |
27716 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27717 | _("offset not a multiple of 4")); | |
27718 | break; | |
27719 | } | |
27720 | value /= 4; | |
216d22bc | 27721 | if (value > 0xff) |
c19d1205 ZW |
27722 | { |
27723 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27724 | _("offset out of range")); | |
27725 | break; | |
27726 | } | |
27727 | newval &= ~0xff; | |
b99bd4ef | 27728 | } |
c19d1205 | 27729 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 27730 | { |
c19d1205 ZW |
27731 | /* PC-relative, 12-bit offset. */ |
27732 | if (value >= 0) | |
27733 | newval |= (1 << 23); | |
27734 | else | |
27735 | value = -value; | |
216d22bc | 27736 | if (value > 0xfff) |
c19d1205 ZW |
27737 | { |
27738 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27739 | _("offset out of range")); | |
27740 | break; | |
27741 | } | |
27742 | newval &= ~0xfff; | |
b99bd4ef | 27743 | } |
c19d1205 | 27744 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 27745 | { |
c19d1205 ZW |
27746 | /* Writeback: 8-bit, +/- offset. */ |
27747 | if (value >= 0) | |
27748 | newval |= (1 << 9); | |
27749 | else | |
27750 | value = -value; | |
216d22bc | 27751 | if (value > 0xff) |
c19d1205 ZW |
27752 | { |
27753 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27754 | _("offset out of range")); | |
27755 | break; | |
27756 | } | |
27757 | newval &= ~0xff; | |
b99bd4ef | 27758 | } |
c19d1205 | 27759 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 27760 | { |
c19d1205 | 27761 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 27762 | if (value < 0 || value > 0xff) |
b99bd4ef | 27763 | { |
c19d1205 ZW |
27764 | as_bad_where (fixP->fx_file, fixP->fx_line, |
27765 | _("offset out of range")); | |
27766 | break; | |
b99bd4ef | 27767 | } |
c19d1205 ZW |
27768 | newval &= ~0xff; |
27769 | newval |= value; | |
b99bd4ef NC |
27770 | } |
27771 | else | |
b99bd4ef | 27772 | { |
c19d1205 ZW |
27773 | /* Positive 12-bit or negative 8-bit offset. */ |
27774 | int limit; | |
27775 | if (value >= 0) | |
b99bd4ef | 27776 | { |
c19d1205 ZW |
27777 | newval |= (1 << 23); |
27778 | limit = 0xfff; | |
27779 | } | |
27780 | else | |
27781 | { | |
27782 | value = -value; | |
27783 | limit = 0xff; | |
27784 | } | |
27785 | if (value > limit) | |
27786 | { | |
27787 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27788 | _("offset out of range")); | |
27789 | break; | |
b99bd4ef | 27790 | } |
c19d1205 | 27791 | newval &= ~limit; |
b99bd4ef | 27792 | } |
b99bd4ef | 27793 | |
c19d1205 ZW |
27794 | newval |= value; |
27795 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
27796 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
27797 | break; | |
404ff6b5 | 27798 | |
c19d1205 ZW |
27799 | case BFD_RELOC_ARM_SHIFT_IMM: |
27800 | newval = md_chars_to_number (buf, INSN_SIZE); | |
27801 | if (((unsigned long) value) > 32 | |
27802 | || (value == 32 | |
27803 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
27804 | { | |
27805 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27806 | _("shift expression is too large")); | |
27807 | break; | |
27808 | } | |
404ff6b5 | 27809 | |
c19d1205 ZW |
27810 | if (value == 0) |
27811 | /* Shifts of zero must be done as lsl. */ | |
27812 | newval &= ~0x60; | |
27813 | else if (value == 32) | |
27814 | value = 0; | |
27815 | newval &= 0xfffff07f; | |
27816 | newval |= (value & 0x1f) << 7; | |
27817 | md_number_to_chars (buf, newval, INSN_SIZE); | |
27818 | break; | |
404ff6b5 | 27819 | |
c19d1205 | 27820 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
16805f35 | 27821 | case BFD_RELOC_ARM_T32_ADD_IMM: |
92e90b6e | 27822 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 27823 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
27824 | /* We claim that this fixup has been processed here, |
27825 | even if in fact we generate an error because we do | |
27826 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
27827 | fixP->fx_done = 1; | |
404ff6b5 | 27828 | |
c19d1205 ZW |
27829 | if (fixP->fx_addsy |
27830 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
27831 | { | |
27832 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27833 | _("undefined symbol %s used as an immediate value"), | |
27834 | S_GET_NAME (fixP->fx_addsy)); | |
27835 | break; | |
27836 | } | |
404ff6b5 | 27837 | |
c19d1205 ZW |
27838 | newval = md_chars_to_number (buf, THUMB_SIZE); |
27839 | newval <<= 16; | |
27840 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 27841 | |
16805f35 | 27842 | newimm = FAIL; |
bada4342 JW |
27843 | if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
27844 | /* ARMv8-M Baseline MOV will reach here, but it doesn't support | |
27845 | Thumb2 modified immediate encoding (T2). */ | |
27846 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) | |
16805f35 | 27847 | || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) |
ef8d22e6 PB |
27848 | { |
27849 | newimm = encode_thumb32_immediate (value); | |
27850 | if (newimm == (unsigned int) FAIL) | |
27851 | newimm = thumb32_negate_data_op (&newval, value); | |
27852 | } | |
bada4342 | 27853 | if (newimm == (unsigned int) FAIL) |
92e90b6e | 27854 | { |
bada4342 | 27855 | if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE) |
e9f89963 | 27856 | { |
bada4342 JW |
27857 | /* Turn add/sum into addw/subw. */ |
27858 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
27859 | newval = (newval & 0xfeffffff) | 0x02000000; | |
27860 | /* No flat 12-bit imm encoding for addsw/subsw. */ | |
27861 | if ((newval & 0x00100000) == 0) | |
40f246e3 | 27862 | { |
bada4342 JW |
27863 | /* 12 bit immediate for addw/subw. */ |
27864 | if (value < 0) | |
27865 | { | |
27866 | value = -value; | |
27867 | newval ^= 0x00a00000; | |
27868 | } | |
27869 | if (value > 0xfff) | |
27870 | newimm = (unsigned int) FAIL; | |
27871 | else | |
27872 | newimm = value; | |
27873 | } | |
27874 | } | |
27875 | else | |
27876 | { | |
27877 | /* MOV accepts both Thumb2 modified immediate (T2 encoding) and | |
27878 | UINT16 (T3 encoding), MOVW only accepts UINT16. When | |
27879 | disassembling, MOV is preferred when there is no encoding | |
db7bf105 | 27880 | overlap. */ |
bada4342 | 27881 | if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR |
db7bf105 NC |
27882 | /* NOTE: MOV uses the ORR opcode in Thumb 2 mode |
27883 | but with the Rn field [19:16] set to 1111. */ | |
27884 | && (((newval >> 16) & 0xf) == 0xf) | |
bada4342 JW |
27885 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m) |
27886 | && !((newval >> T2_SBIT_SHIFT) & 0x1) | |
db7bf105 | 27887 | && value >= 0 && value <= 0xffff) |
bada4342 JW |
27888 | { |
27889 | /* Toggle bit[25] to change encoding from T2 to T3. */ | |
27890 | newval ^= 1 << 25; | |
27891 | /* Clear bits[19:16]. */ | |
27892 | newval &= 0xfff0ffff; | |
27893 | /* Encoding high 4bits imm. Code below will encode the | |
27894 | remaining low 12bits. */ | |
27895 | newval |= (value & 0x0000f000) << 4; | |
27896 | newimm = value & 0x00000fff; | |
40f246e3 | 27897 | } |
e9f89963 | 27898 | } |
92e90b6e | 27899 | } |
cc8a6dd0 | 27900 | |
c19d1205 | 27901 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 27902 | { |
c19d1205 ZW |
27903 | as_bad_where (fixP->fx_file, fixP->fx_line, |
27904 | _("invalid constant (%lx) after fixup"), | |
27905 | (unsigned long) value); | |
27906 | break; | |
3631a3c8 NC |
27907 | } |
27908 | ||
c19d1205 ZW |
27909 | newval |= (newimm & 0x800) << 15; |
27910 | newval |= (newimm & 0x700) << 4; | |
27911 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 27912 | |
c19d1205 ZW |
27913 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
27914 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
27915 | break; | |
a737bd4d | 27916 | |
3eb17e6b | 27917 | case BFD_RELOC_ARM_SMC: |
ba85f98c | 27918 | if (((unsigned long) value) > 0xf) |
c19d1205 | 27919 | as_bad_where (fixP->fx_file, fixP->fx_line, |
3eb17e6b | 27920 | _("invalid smc expression")); |
ba85f98c | 27921 | |
2fc8bdac | 27922 | newval = md_chars_to_number (buf, INSN_SIZE); |
ba85f98c | 27923 | newval |= (value & 0xf); |
c19d1205 ZW |
27924 | md_number_to_chars (buf, newval, INSN_SIZE); |
27925 | break; | |
a737bd4d | 27926 | |
90ec0d68 MGD |
27927 | case BFD_RELOC_ARM_HVC: |
27928 | if (((unsigned long) value) > 0xffff) | |
27929 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27930 | _("invalid hvc expression")); | |
27931 | newval = md_chars_to_number (buf, INSN_SIZE); | |
27932 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); | |
27933 | md_number_to_chars (buf, newval, INSN_SIZE); | |
27934 | break; | |
27935 | ||
c19d1205 | 27936 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 27937 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
27938 | { |
27939 | if (((unsigned long) value) > 0xff) | |
27940 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27941 | _("invalid swi expression")); | |
2fc8bdac | 27942 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
27943 | newval |= value; |
27944 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
27945 | } | |
27946 | else | |
27947 | { | |
27948 | if (((unsigned long) value) > 0x00ffffff) | |
27949 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27950 | _("invalid swi expression")); | |
2fc8bdac | 27951 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
27952 | newval |= value; |
27953 | md_number_to_chars (buf, newval, INSN_SIZE); | |
27954 | } | |
27955 | break; | |
a737bd4d | 27956 | |
c19d1205 ZW |
27957 | case BFD_RELOC_ARM_MULTI: |
27958 | if (((unsigned long) value) > 0xffff) | |
27959 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
27960 | _("invalid expression in load/store multiple")); | |
27961 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
27962 | md_number_to_chars (buf, newval, INSN_SIZE); | |
27963 | break; | |
a737bd4d | 27964 | |
c19d1205 | 27965 | #ifdef OBJ_ELF |
39b41c9c | 27966 | case BFD_RELOC_ARM_PCREL_CALL: |
267bf995 RR |
27967 | |
27968 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
27969 | && fixP->fx_addsy | |
34e77a92 | 27970 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
27971 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
27972 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
27973 | /* Flip the bl to blx. This is a simple flip | |
27974 | bit here because we generate PCREL_CALL for | |
27975 | unconditional bls. */ | |
27976 | { | |
27977 | newval = md_chars_to_number (buf, INSN_SIZE); | |
27978 | newval = newval | 0x10000000; | |
27979 | md_number_to_chars (buf, newval, INSN_SIZE); | |
27980 | temp = 1; | |
27981 | fixP->fx_done = 1; | |
27982 | } | |
39b41c9c PB |
27983 | else |
27984 | temp = 3; | |
27985 | goto arm_branch_common; | |
27986 | ||
27987 | case BFD_RELOC_ARM_PCREL_JUMP: | |
267bf995 RR |
27988 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
27989 | && fixP->fx_addsy | |
34e77a92 | 27990 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
27991 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
27992 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
27993 | { | |
27994 | /* This would map to a bl<cond>, b<cond>, | |
27995 | b<always> to a Thumb function. We | |
27996 | need to force a relocation for this particular | |
27997 | case. */ | |
27998 | newval = md_chars_to_number (buf, INSN_SIZE); | |
27999 | fixP->fx_done = 0; | |
28000 | } | |
1a0670f3 | 28001 | /* Fall through. */ |
267bf995 | 28002 | |
2fc8bdac | 28003 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 28004 | #endif |
39b41c9c PB |
28005 | case BFD_RELOC_ARM_PCREL_BRANCH: |
28006 | temp = 3; | |
28007 | goto arm_branch_common; | |
a737bd4d | 28008 | |
39b41c9c | 28009 | case BFD_RELOC_ARM_PCREL_BLX: |
267bf995 | 28010 | |
39b41c9c | 28011 | temp = 1; |
267bf995 RR |
28012 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
28013 | && fixP->fx_addsy | |
34e77a92 | 28014 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
28015 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
28016 | && ARM_IS_FUNC (fixP->fx_addsy)) | |
28017 | { | |
28018 | /* Flip the blx to a bl and warn. */ | |
28019 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
28020 | newval = 0xeb000000; | |
28021 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
28022 | _("blx to '%s' an ARM ISA state function changed to bl"), | |
28023 | name); | |
28024 | md_number_to_chars (buf, newval, INSN_SIZE); | |
28025 | temp = 3; | |
28026 | fixP->fx_done = 1; | |
28027 | } | |
28028 | ||
28029 | #ifdef OBJ_ELF | |
28030 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
477330fc | 28031 | fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL; |
267bf995 RR |
28032 | #endif |
28033 | ||
39b41c9c | 28034 | arm_branch_common: |
c19d1205 | 28035 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
28036 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
28037 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
de194d85 | 28038 | also be clear. */ |
39b41c9c | 28039 | if (value & temp) |
c19d1205 | 28040 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
28041 | _("misaligned branch destination")); |
28042 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
28043 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
08f10d51 | 28044 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 28045 | |
2fc8bdac | 28046 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 28047 | { |
2fc8bdac ZW |
28048 | newval = md_chars_to_number (buf, INSN_SIZE); |
28049 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
28050 | /* Set the H bit on BLX instructions. */ |
28051 | if (temp == 1) | |
28052 | { | |
28053 | if (value & 2) | |
28054 | newval |= 0x01000000; | |
28055 | else | |
28056 | newval &= ~0x01000000; | |
28057 | } | |
2fc8bdac | 28058 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 28059 | } |
c19d1205 | 28060 | break; |
a737bd4d | 28061 | |
25fe350b MS |
28062 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */ |
28063 | /* CBZ can only branch forward. */ | |
a737bd4d | 28064 | |
738755b0 | 28065 | /* Attempts to use CBZ to branch to the next instruction |
477330fc RM |
28066 | (which, strictly speaking, are prohibited) will be turned into |
28067 | no-ops. | |
738755b0 MS |
28068 | |
28069 | FIXME: It may be better to remove the instruction completely and | |
28070 | perform relaxation. */ | |
28071 | if (value == -2) | |
2fc8bdac ZW |
28072 | { |
28073 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
738755b0 | 28074 | newval = 0xbf00; /* NOP encoding T1 */ |
2fc8bdac ZW |
28075 | md_number_to_chars (buf, newval, THUMB_SIZE); |
28076 | } | |
738755b0 MS |
28077 | else |
28078 | { | |
28079 | if (value & ~0x7e) | |
08f10d51 | 28080 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
738755b0 | 28081 | |
477330fc | 28082 | if (fixP->fx_done || !seg->use_rela_p) |
738755b0 MS |
28083 | { |
28084 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
28085 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); | |
28086 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
28087 | } | |
28088 | } | |
c19d1205 | 28089 | break; |
a737bd4d | 28090 | |
c19d1205 | 28091 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac | 28092 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
08f10d51 | 28093 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 28094 | |
2fc8bdac ZW |
28095 | if (fixP->fx_done || !seg->use_rela_p) |
28096 | { | |
28097 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
28098 | newval |= (value & 0x1ff) >> 1; | |
28099 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
28100 | } | |
c19d1205 | 28101 | break; |
a737bd4d | 28102 | |
c19d1205 | 28103 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac | 28104 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
08f10d51 | 28105 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 28106 | |
2fc8bdac ZW |
28107 | if (fixP->fx_done || !seg->use_rela_p) |
28108 | { | |
28109 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
28110 | newval |= (value & 0xfff) >> 1; | |
28111 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
28112 | } | |
c19d1205 | 28113 | break; |
a737bd4d | 28114 | |
c19d1205 | 28115 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
267bf995 RR |
28116 | if (fixP->fx_addsy |
28117 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 28118 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
28119 | && ARM_IS_FUNC (fixP->fx_addsy) |
28120 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
28121 | { | |
28122 | /* Force a relocation for a branch 20 bits wide. */ | |
28123 | fixP->fx_done = 0; | |
28124 | } | |
08f10d51 | 28125 | if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff)) |
2fc8bdac ZW |
28126 | as_bad_where (fixP->fx_file, fixP->fx_line, |
28127 | _("conditional branch out of range")); | |
404ff6b5 | 28128 | |
2fc8bdac ZW |
28129 | if (fixP->fx_done || !seg->use_rela_p) |
28130 | { | |
28131 | offsetT newval2; | |
28132 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 28133 | |
2fc8bdac ZW |
28134 | S = (value & 0x00100000) >> 20; |
28135 | J2 = (value & 0x00080000) >> 19; | |
28136 | J1 = (value & 0x00040000) >> 18; | |
28137 | hi = (value & 0x0003f000) >> 12; | |
28138 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 28139 | |
2fc8bdac ZW |
28140 | newval = md_chars_to_number (buf, THUMB_SIZE); |
28141 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
28142 | newval |= (S << 10) | hi; | |
28143 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
28144 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
28145 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
28146 | } | |
c19d1205 | 28147 | break; |
6c43fab6 | 28148 | |
c19d1205 | 28149 | case BFD_RELOC_THUMB_PCREL_BLX: |
267bf995 RR |
28150 | /* If there is a blx from a thumb state function to |
28151 | another thumb function flip this to a bl and warn | |
28152 | about it. */ | |
28153 | ||
28154 | if (fixP->fx_addsy | |
34e77a92 | 28155 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
28156 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
28157 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
28158 | { | |
28159 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
28160 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
28161 | _("blx to Thumb func '%s' from Thumb ISA state changed to bl"), | |
28162 | name); | |
28163 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
28164 | newval = newval | 0x1000; | |
28165 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
28166 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
28167 | fixP->fx_done = 1; | |
28168 | } | |
28169 | ||
28170 | ||
28171 | goto thumb_bl_common; | |
28172 | ||
c19d1205 | 28173 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
267bf995 RR |
28174 | /* A bl from Thumb state ISA to an internal ARM state function |
28175 | is converted to a blx. */ | |
28176 | if (fixP->fx_addsy | |
28177 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 28178 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
28179 | && ARM_IS_FUNC (fixP->fx_addsy) |
28180 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
28181 | { | |
28182 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
28183 | newval = newval & ~0x1000; | |
28184 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
28185 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX; | |
28186 | fixP->fx_done = 1; | |
28187 | } | |
28188 | ||
28189 | thumb_bl_common: | |
28190 | ||
2fc8bdac ZW |
28191 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
28192 | /* For a BLX instruction, make sure that the relocation is rounded up | |
28193 | to a word boundary. This follows the semantics of the instruction | |
28194 | which specifies that bit 1 of the target address will come from bit | |
28195 | 1 of the base address. */ | |
d406f3e4 JB |
28196 | value = (value + 3) & ~ 3; |
28197 | ||
28198 | #ifdef OBJ_ELF | |
28199 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 | |
28200 | && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) | |
28201 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
28202 | #endif | |
404ff6b5 | 28203 | |
2b2f5df9 NC |
28204 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
28205 | { | |
fc289b0a | 28206 | if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))) |
2b2f5df9 NC |
28207 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
28208 | else if ((value & ~0x1ffffff) | |
28209 | && ((value & ~0x1ffffff) != ~0x1ffffff)) | |
28210 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28211 | _("Thumb2 branch out of range")); | |
28212 | } | |
4a42ebbc RR |
28213 | |
28214 | if (fixP->fx_done || !seg->use_rela_p) | |
28215 | encode_thumb2_b_bl_offset (buf, value); | |
28216 | ||
c19d1205 | 28217 | break; |
404ff6b5 | 28218 | |
c19d1205 | 28219 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
08f10d51 NC |
28220 | if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff)) |
28221 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); | |
6c43fab6 | 28222 | |
2fc8bdac | 28223 | if (fixP->fx_done || !seg->use_rela_p) |
4a42ebbc | 28224 | encode_thumb2_b_bl_offset (buf, value); |
6c43fab6 | 28225 | |
2fc8bdac | 28226 | break; |
a737bd4d | 28227 | |
2fc8bdac ZW |
28228 | case BFD_RELOC_8: |
28229 | if (fixP->fx_done || !seg->use_rela_p) | |
4b1a927e | 28230 | *buf = value; |
c19d1205 | 28231 | break; |
a737bd4d | 28232 | |
c19d1205 | 28233 | case BFD_RELOC_16: |
2fc8bdac | 28234 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 28235 | md_number_to_chars (buf, value, 2); |
c19d1205 | 28236 | break; |
a737bd4d | 28237 | |
c19d1205 | 28238 | #ifdef OBJ_ELF |
0855e32b NS |
28239 | case BFD_RELOC_ARM_TLS_CALL: |
28240 | case BFD_RELOC_ARM_THM_TLS_CALL: | |
28241 | case BFD_RELOC_ARM_TLS_DESCSEQ: | |
28242 | case BFD_RELOC_ARM_THM_TLS_DESCSEQ: | |
0855e32b | 28243 | case BFD_RELOC_ARM_TLS_GOTDESC: |
c19d1205 ZW |
28244 | case BFD_RELOC_ARM_TLS_GD32: |
28245 | case BFD_RELOC_ARM_TLS_LE32: | |
28246 | case BFD_RELOC_ARM_TLS_IE32: | |
28247 | case BFD_RELOC_ARM_TLS_LDM32: | |
28248 | case BFD_RELOC_ARM_TLS_LDO32: | |
28249 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
4b1a927e | 28250 | break; |
6c43fab6 | 28251 | |
5c5a4843 CL |
28252 | /* Same handling as above, but with the arm_fdpic guard. */ |
28253 | case BFD_RELOC_ARM_TLS_GD32_FDPIC: | |
28254 | case BFD_RELOC_ARM_TLS_IE32_FDPIC: | |
28255 | case BFD_RELOC_ARM_TLS_LDM32_FDPIC: | |
28256 | if (arm_fdpic) | |
28257 | { | |
28258 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
28259 | } | |
28260 | else | |
28261 | { | |
28262 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28263 | _("Relocation supported only in FDPIC mode")); | |
28264 | } | |
28265 | break; | |
28266 | ||
c19d1205 ZW |
28267 | case BFD_RELOC_ARM_GOT32: |
28268 | case BFD_RELOC_ARM_GOTOFF: | |
c19d1205 | 28269 | break; |
b43420e6 NC |
28270 | |
28271 | case BFD_RELOC_ARM_GOT_PREL: | |
28272 | if (fixP->fx_done || !seg->use_rela_p) | |
477330fc | 28273 | md_number_to_chars (buf, value, 4); |
b43420e6 NC |
28274 | break; |
28275 | ||
9a6f4e97 NS |
28276 | case BFD_RELOC_ARM_TARGET2: |
28277 | /* TARGET2 is not partial-inplace, so we need to write the | |
477330fc RM |
28278 | addend here for REL targets, because it won't be written out |
28279 | during reloc processing later. */ | |
9a6f4e97 NS |
28280 | if (fixP->fx_done || !seg->use_rela_p) |
28281 | md_number_to_chars (buf, fixP->fx_offset, 4); | |
28282 | break; | |
188fd7ae CL |
28283 | |
28284 | /* Relocations for FDPIC. */ | |
28285 | case BFD_RELOC_ARM_GOTFUNCDESC: | |
28286 | case BFD_RELOC_ARM_GOTOFFFUNCDESC: | |
28287 | case BFD_RELOC_ARM_FUNCDESC: | |
28288 | if (arm_fdpic) | |
28289 | { | |
28290 | if (fixP->fx_done || !seg->use_rela_p) | |
28291 | md_number_to_chars (buf, 0, 4); | |
28292 | } | |
28293 | else | |
28294 | { | |
28295 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28296 | _("Relocation supported only in FDPIC mode")); | |
28297 | } | |
28298 | break; | |
c19d1205 | 28299 | #endif |
6c43fab6 | 28300 | |
c19d1205 ZW |
28301 | case BFD_RELOC_RVA: |
28302 | case BFD_RELOC_32: | |
28303 | case BFD_RELOC_ARM_TARGET1: | |
28304 | case BFD_RELOC_ARM_ROSEGREL32: | |
28305 | case BFD_RELOC_ARM_SBREL32: | |
28306 | case BFD_RELOC_32_PCREL: | |
f0927246 NC |
28307 | #ifdef TE_PE |
28308 | case BFD_RELOC_32_SECREL: | |
28309 | #endif | |
2fc8bdac | 28310 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
28311 | #ifdef TE_WINCE |
28312 | /* For WinCE we only do this for pcrel fixups. */ | |
28313 | if (fixP->fx_done || fixP->fx_pcrel) | |
28314 | #endif | |
28315 | md_number_to_chars (buf, value, 4); | |
c19d1205 | 28316 | break; |
6c43fab6 | 28317 | |
c19d1205 ZW |
28318 | #ifdef OBJ_ELF |
28319 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 28320 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
28321 | { |
28322 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
28323 | if ((value ^ (value >> 1)) & 0x40000000) | |
28324 | { | |
28325 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28326 | _("rel31 relocation overflow")); | |
28327 | } | |
28328 | newval |= value & 0x7fffffff; | |
28329 | md_number_to_chars (buf, newval, 4); | |
28330 | } | |
28331 | break; | |
c19d1205 | 28332 | #endif |
a737bd4d | 28333 | |
c19d1205 | 28334 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 28335 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
32c36c3c | 28336 | case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM: |
9db2f6b4 RL |
28337 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM) |
28338 | newval = md_chars_to_number (buf, INSN_SIZE); | |
28339 | else | |
28340 | newval = get_thumb32_insn (buf); | |
28341 | if ((newval & 0x0f200f00) == 0x0d000900) | |
28342 | { | |
28343 | /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic | |
28344 | has permitted values that are multiples of 2, in the range 0 | |
28345 | to 510. */ | |
28346 | if (value < -510 || value > 510 || (value & 1)) | |
28347 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28348 | _("co-processor offset out of range")); | |
28349 | } | |
32c36c3c AV |
28350 | else if ((newval & 0xfe001f80) == 0xec000f80) |
28351 | { | |
28352 | if (value < -511 || value > 512 || (value & 3)) | |
28353 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28354 | _("co-processor offset out of range")); | |
28355 | } | |
9db2f6b4 | 28356 | else if (value < -1023 || value > 1023 || (value & 3)) |
c19d1205 ZW |
28357 | as_bad_where (fixP->fx_file, fixP->fx_line, |
28358 | _("co-processor offset out of range")); | |
28359 | cp_off_common: | |
26d97720 | 28360 | sign = value > 0; |
c19d1205 ZW |
28361 | if (value < 0) |
28362 | value = -value; | |
8f06b2d8 PB |
28363 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
28364 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
28365 | newval = md_chars_to_number (buf, INSN_SIZE); | |
28366 | else | |
28367 | newval = get_thumb32_insn (buf); | |
26d97720 | 28368 | if (value == 0) |
32c36c3c AV |
28369 | { |
28370 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM) | |
28371 | newval &= 0xffffff80; | |
28372 | else | |
28373 | newval &= 0xffffff00; | |
28374 | } | |
26d97720 NS |
28375 | else |
28376 | { | |
32c36c3c AV |
28377 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM) |
28378 | newval &= 0xff7fff80; | |
28379 | else | |
28380 | newval &= 0xff7fff00; | |
9db2f6b4 RL |
28381 | if ((newval & 0x0f200f00) == 0x0d000900) |
28382 | { | |
28383 | /* This is a fp16 vstr/vldr. | |
28384 | ||
28385 | It requires the immediate offset in the instruction is shifted | |
28386 | left by 1 to be a half-word offset. | |
28387 | ||
28388 | Here, left shift by 1 first, and later right shift by 2 | |
28389 | should get the right offset. */ | |
28390 | value <<= 1; | |
28391 | } | |
26d97720 NS |
28392 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
28393 | } | |
8f06b2d8 PB |
28394 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
28395 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
28396 | md_number_to_chars (buf, newval, INSN_SIZE); | |
28397 | else | |
28398 | put_thumb32_insn (buf, newval); | |
c19d1205 | 28399 | break; |
a737bd4d | 28400 | |
c19d1205 | 28401 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 28402 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
28403 | if (value < -255 || value > 255) |
28404 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28405 | _("co-processor offset out of range")); | |
df7849c5 | 28406 | value *= 4; |
c19d1205 | 28407 | goto cp_off_common; |
6c43fab6 | 28408 | |
c19d1205 ZW |
28409 | case BFD_RELOC_ARM_THUMB_OFFSET: |
28410 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
28411 | /* Exactly what ranges, and where the offset is inserted depends | |
28412 | on the type of instruction, we can establish this from the | |
28413 | top 4 bits. */ | |
28414 | switch (newval >> 12) | |
28415 | { | |
28416 | case 4: /* PC load. */ | |
28417 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
28418 | forced to zero for these loads; md_pcrel_from has already | |
28419 | compensated for this. */ | |
28420 | if (value & 3) | |
28421 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28422 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
28423 | (((unsigned long) fixP->fx_frag->fr_address |
28424 | + (unsigned long) fixP->fx_where) & ~3) | |
28425 | + (unsigned long) value); | |
a737bd4d | 28426 | |
c19d1205 ZW |
28427 | if (value & ~0x3fc) |
28428 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28429 | _("invalid offset, value too big (0x%08lX)"), | |
28430 | (long) value); | |
a737bd4d | 28431 | |
c19d1205 ZW |
28432 | newval |= value >> 2; |
28433 | break; | |
a737bd4d | 28434 | |
c19d1205 ZW |
28435 | case 9: /* SP load/store. */ |
28436 | if (value & ~0x3fc) | |
28437 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28438 | _("invalid offset, value too big (0x%08lX)"), | |
28439 | (long) value); | |
28440 | newval |= value >> 2; | |
28441 | break; | |
6c43fab6 | 28442 | |
c19d1205 ZW |
28443 | case 6: /* Word load/store. */ |
28444 | if (value & ~0x7c) | |
28445 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28446 | _("invalid offset, value too big (0x%08lX)"), | |
28447 | (long) value); | |
28448 | newval |= value << 4; /* 6 - 2. */ | |
28449 | break; | |
a737bd4d | 28450 | |
c19d1205 ZW |
28451 | case 7: /* Byte load/store. */ |
28452 | if (value & ~0x1f) | |
28453 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28454 | _("invalid offset, value too big (0x%08lX)"), | |
28455 | (long) value); | |
28456 | newval |= value << 6; | |
28457 | break; | |
a737bd4d | 28458 | |
c19d1205 ZW |
28459 | case 8: /* Halfword load/store. */ |
28460 | if (value & ~0x3e) | |
28461 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28462 | _("invalid offset, value too big (0x%08lX)"), | |
28463 | (long) value); | |
28464 | newval |= value << 5; /* 6 - 1. */ | |
28465 | break; | |
a737bd4d | 28466 | |
c19d1205 ZW |
28467 | default: |
28468 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28469 | "Unable to process relocation for thumb opcode: %lx", | |
28470 | (unsigned long) newval); | |
28471 | break; | |
28472 | } | |
28473 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
28474 | break; | |
a737bd4d | 28475 | |
c19d1205 ZW |
28476 | case BFD_RELOC_ARM_THUMB_ADD: |
28477 | /* This is a complicated relocation, since we use it for all of | |
28478 | the following immediate relocations: | |
a737bd4d | 28479 | |
c19d1205 ZW |
28480 | 3bit ADD/SUB |
28481 | 8bit ADD/SUB | |
28482 | 9bit ADD/SUB SP word-aligned | |
28483 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 28484 | |
c19d1205 ZW |
28485 | The type of instruction being processed is encoded in the |
28486 | instruction field: | |
a737bd4d | 28487 | |
c19d1205 ZW |
28488 | 0x8000 SUB |
28489 | 0x00F0 Rd | |
28490 | 0x000F Rs | |
28491 | */ | |
28492 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
28493 | { | |
28494 | int rd = (newval >> 4) & 0xf; | |
28495 | int rs = newval & 0xf; | |
28496 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 28497 | |
c19d1205 ZW |
28498 | /* Check for HI regs, only very restricted cases allowed: |
28499 | Adjusting SP, and using PC or SP to get an address. */ | |
28500 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
28501 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
28502 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28503 | _("invalid Hi register with immediate")); | |
a737bd4d | 28504 | |
c19d1205 ZW |
28505 | /* If value is negative, choose the opposite instruction. */ |
28506 | if (value < 0) | |
28507 | { | |
28508 | value = -value; | |
28509 | subtract = !subtract; | |
28510 | if (value < 0) | |
28511 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28512 | _("immediate value out of range")); | |
28513 | } | |
a737bd4d | 28514 | |
c19d1205 ZW |
28515 | if (rd == REG_SP) |
28516 | { | |
75c11999 | 28517 | if (value & ~0x1fc) |
c19d1205 ZW |
28518 | as_bad_where (fixP->fx_file, fixP->fx_line, |
28519 | _("invalid immediate for stack address calculation")); | |
28520 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
28521 | newval |= value >> 2; | |
28522 | } | |
28523 | else if (rs == REG_PC || rs == REG_SP) | |
28524 | { | |
c12d2c9d NC |
28525 | /* PR gas/18541. If the addition is for a defined symbol |
28526 | within range of an ADR instruction then accept it. */ | |
28527 | if (subtract | |
28528 | && value == 4 | |
28529 | && fixP->fx_addsy != NULL) | |
28530 | { | |
28531 | subtract = 0; | |
28532 | ||
28533 | if (! S_IS_DEFINED (fixP->fx_addsy) | |
28534 | || S_GET_SEGMENT (fixP->fx_addsy) != seg | |
28535 | || S_IS_WEAK (fixP->fx_addsy)) | |
28536 | { | |
28537 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28538 | _("address calculation needs a strongly defined nearby symbol")); | |
28539 | } | |
28540 | else | |
28541 | { | |
28542 | offsetT v = fixP->fx_where + fixP->fx_frag->fr_address; | |
28543 | ||
28544 | /* Round up to the next 4-byte boundary. */ | |
28545 | if (v & 3) | |
28546 | v = (v + 3) & ~ 3; | |
28547 | else | |
28548 | v += 4; | |
28549 | v = S_GET_VALUE (fixP->fx_addsy) - v; | |
28550 | ||
28551 | if (v & ~0x3fc) | |
28552 | { | |
28553 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28554 | _("symbol too far away")); | |
28555 | } | |
28556 | else | |
28557 | { | |
28558 | fixP->fx_done = 1; | |
28559 | value = v; | |
28560 | } | |
28561 | } | |
28562 | } | |
28563 | ||
c19d1205 ZW |
28564 | if (subtract || value & ~0x3fc) |
28565 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28566 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
5fc177c8 | 28567 | (unsigned long) (subtract ? - value : value)); |
c19d1205 ZW |
28568 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); |
28569 | newval |= rd << 8; | |
28570 | newval |= value >> 2; | |
28571 | } | |
28572 | else if (rs == rd) | |
28573 | { | |
28574 | if (value & ~0xff) | |
28575 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28576 | _("immediate value out of range")); | |
28577 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
28578 | newval |= (rd << 8) | value; | |
28579 | } | |
28580 | else | |
28581 | { | |
28582 | if (value & ~0x7) | |
28583 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28584 | _("immediate value out of range")); | |
28585 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
28586 | newval |= rd | (rs << 3) | (value << 6); | |
28587 | } | |
28588 | } | |
28589 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
28590 | break; | |
a737bd4d | 28591 | |
c19d1205 ZW |
28592 | case BFD_RELOC_ARM_THUMB_IMM: |
28593 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
28594 | if (value < 0 || value > 255) | |
28595 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4e6e072b | 28596 | _("invalid immediate: %ld is out of range"), |
c19d1205 ZW |
28597 | (long) value); |
28598 | newval |= value; | |
28599 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
28600 | break; | |
a737bd4d | 28601 | |
c19d1205 ZW |
28602 | case BFD_RELOC_ARM_THUMB_SHIFT: |
28603 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
28604 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
28605 | temp = newval & 0xf800; | |
28606 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
28607 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28608 | _("invalid shift value: %ld"), (long) value); | |
28609 | /* Shifts of zero must be encoded as LSL. */ | |
28610 | if (value == 0) | |
28611 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
28612 | /* Shifts of 32 are encoded as zero. */ | |
28613 | else if (value == 32) | |
28614 | value = 0; | |
28615 | newval |= value << 6; | |
28616 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
28617 | break; | |
a737bd4d | 28618 | |
c19d1205 ZW |
28619 | case BFD_RELOC_VTABLE_INHERIT: |
28620 | case BFD_RELOC_VTABLE_ENTRY: | |
28621 | fixP->fx_done = 0; | |
28622 | return; | |
6c43fab6 | 28623 | |
b6895b4f PB |
28624 | case BFD_RELOC_ARM_MOVW: |
28625 | case BFD_RELOC_ARM_MOVT: | |
28626 | case BFD_RELOC_ARM_THUMB_MOVW: | |
28627 | case BFD_RELOC_ARM_THUMB_MOVT: | |
28628 | if (fixP->fx_done || !seg->use_rela_p) | |
28629 | { | |
28630 | /* REL format relocations are limited to a 16-bit addend. */ | |
28631 | if (!fixP->fx_done) | |
28632 | { | |
39623e12 | 28633 | if (value < -0x8000 || value > 0x7fff) |
b6895b4f | 28634 | as_bad_where (fixP->fx_file, fixP->fx_line, |
ff5075ca | 28635 | _("offset out of range")); |
b6895b4f PB |
28636 | } |
28637 | else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
28638 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
28639 | { | |
28640 | value >>= 16; | |
28641 | } | |
28642 | ||
28643 | if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
28644 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
28645 | { | |
28646 | newval = get_thumb32_insn (buf); | |
28647 | newval &= 0xfbf08f00; | |
28648 | newval |= (value & 0xf000) << 4; | |
28649 | newval |= (value & 0x0800) << 15; | |
28650 | newval |= (value & 0x0700) << 4; | |
28651 | newval |= (value & 0x00ff); | |
28652 | put_thumb32_insn (buf, newval); | |
28653 | } | |
28654 | else | |
28655 | { | |
28656 | newval = md_chars_to_number (buf, 4); | |
28657 | newval &= 0xfff0f000; | |
28658 | newval |= value & 0x0fff; | |
28659 | newval |= (value & 0xf000) << 4; | |
28660 | md_number_to_chars (buf, newval, 4); | |
28661 | } | |
28662 | } | |
28663 | return; | |
28664 | ||
72d98d16 MG |
28665 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC: |
28666 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC: | |
28667 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC: | |
28668 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC: | |
28669 | gas_assert (!fixP->fx_done); | |
28670 | { | |
28671 | bfd_vma insn; | |
28672 | bfd_boolean is_mov; | |
28673 | bfd_vma encoded_addend = value; | |
28674 | ||
28675 | /* Check that addend can be encoded in instruction. */ | |
28676 | if (!seg->use_rela_p && (value < 0 || value > 255)) | |
28677 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28678 | _("the offset 0x%08lX is not representable"), | |
28679 | (unsigned long) encoded_addend); | |
28680 | ||
28681 | /* Extract the instruction. */ | |
28682 | insn = md_chars_to_number (buf, THUMB_SIZE); | |
28683 | is_mov = (insn & 0xf800) == 0x2000; | |
28684 | ||
28685 | /* Encode insn. */ | |
28686 | if (is_mov) | |
28687 | { | |
28688 | if (!seg->use_rela_p) | |
28689 | insn |= encoded_addend; | |
28690 | } | |
28691 | else | |
28692 | { | |
28693 | int rd, rs; | |
28694 | ||
28695 | /* Extract the instruction. */ | |
28696 | /* Encoding is the following | |
28697 | 0x8000 SUB | |
28698 | 0x00F0 Rd | |
28699 | 0x000F Rs | |
28700 | */ | |
28701 | /* The following conditions must be true : | |
28702 | - ADD | |
28703 | - Rd == Rs | |
28704 | - Rd <= 7 | |
28705 | */ | |
28706 | rd = (insn >> 4) & 0xf; | |
28707 | rs = insn & 0xf; | |
28708 | if ((insn & 0x8000) || (rd != rs) || rd > 7) | |
28709 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28710 | _("Unable to process relocation for thumb opcode: %lx"), | |
28711 | (unsigned long) insn); | |
28712 | ||
28713 | /* Encode as ADD immediate8 thumb 1 code. */ | |
28714 | insn = 0x3000 | (rd << 8); | |
28715 | ||
28716 | /* Place the encoded addend into the first 8 bits of the | |
28717 | instruction. */ | |
28718 | if (!seg->use_rela_p) | |
28719 | insn |= encoded_addend; | |
28720 | } | |
28721 | ||
28722 | /* Update the instruction. */ | |
28723 | md_number_to_chars (buf, insn, THUMB_SIZE); | |
28724 | } | |
28725 | break; | |
28726 | ||
4962c51a MS |
28727 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
28728 | case BFD_RELOC_ARM_ALU_PC_G0: | |
28729 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
28730 | case BFD_RELOC_ARM_ALU_PC_G1: | |
28731 | case BFD_RELOC_ARM_ALU_PC_G2: | |
28732 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
28733 | case BFD_RELOC_ARM_ALU_SB_G0: | |
28734 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
28735 | case BFD_RELOC_ARM_ALU_SB_G1: | |
28736 | case BFD_RELOC_ARM_ALU_SB_G2: | |
9c2799c2 | 28737 | gas_assert (!fixP->fx_done); |
4962c51a MS |
28738 | if (!seg->use_rela_p) |
28739 | { | |
477330fc RM |
28740 | bfd_vma insn; |
28741 | bfd_vma encoded_addend; | |
3ca4a8ec | 28742 | bfd_vma addend_abs = llabs (value); |
477330fc RM |
28743 | |
28744 | /* Check that the absolute value of the addend can be | |
28745 | expressed as an 8-bit constant plus a rotation. */ | |
28746 | encoded_addend = encode_arm_immediate (addend_abs); | |
28747 | if (encoded_addend == (unsigned int) FAIL) | |
4962c51a | 28748 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
28749 | _("the offset 0x%08lX is not representable"), |
28750 | (unsigned long) addend_abs); | |
28751 | ||
28752 | /* Extract the instruction. */ | |
28753 | insn = md_chars_to_number (buf, INSN_SIZE); | |
28754 | ||
28755 | /* If the addend is positive, use an ADD instruction. | |
28756 | Otherwise use a SUB. Take care not to destroy the S bit. */ | |
28757 | insn &= 0xff1fffff; | |
28758 | if (value < 0) | |
28759 | insn |= 1 << 22; | |
28760 | else | |
28761 | insn |= 1 << 23; | |
28762 | ||
28763 | /* Place the encoded addend into the first 12 bits of the | |
28764 | instruction. */ | |
28765 | insn &= 0xfffff000; | |
28766 | insn |= encoded_addend; | |
28767 | ||
28768 | /* Update the instruction. */ | |
28769 | md_number_to_chars (buf, insn, INSN_SIZE); | |
4962c51a MS |
28770 | } |
28771 | break; | |
28772 | ||
28773 | case BFD_RELOC_ARM_LDR_PC_G0: | |
28774 | case BFD_RELOC_ARM_LDR_PC_G1: | |
28775 | case BFD_RELOC_ARM_LDR_PC_G2: | |
28776 | case BFD_RELOC_ARM_LDR_SB_G0: | |
28777 | case BFD_RELOC_ARM_LDR_SB_G1: | |
28778 | case BFD_RELOC_ARM_LDR_SB_G2: | |
9c2799c2 | 28779 | gas_assert (!fixP->fx_done); |
4962c51a | 28780 | if (!seg->use_rela_p) |
477330fc RM |
28781 | { |
28782 | bfd_vma insn; | |
3ca4a8ec | 28783 | bfd_vma addend_abs = llabs (value); |
4962c51a | 28784 | |
477330fc RM |
28785 | /* Check that the absolute value of the addend can be |
28786 | encoded in 12 bits. */ | |
28787 | if (addend_abs >= 0x1000) | |
4962c51a | 28788 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
28789 | _("bad offset 0x%08lX (only 12 bits available for the magnitude)"), |
28790 | (unsigned long) addend_abs); | |
28791 | ||
28792 | /* Extract the instruction. */ | |
28793 | insn = md_chars_to_number (buf, INSN_SIZE); | |
28794 | ||
28795 | /* If the addend is negative, clear bit 23 of the instruction. | |
28796 | Otherwise set it. */ | |
28797 | if (value < 0) | |
28798 | insn &= ~(1 << 23); | |
28799 | else | |
28800 | insn |= 1 << 23; | |
28801 | ||
28802 | /* Place the absolute value of the addend into the first 12 bits | |
28803 | of the instruction. */ | |
28804 | insn &= 0xfffff000; | |
28805 | insn |= addend_abs; | |
28806 | ||
28807 | /* Update the instruction. */ | |
28808 | md_number_to_chars (buf, insn, INSN_SIZE); | |
28809 | } | |
4962c51a MS |
28810 | break; |
28811 | ||
28812 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
28813 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
28814 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
28815 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
28816 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
28817 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
9c2799c2 | 28818 | gas_assert (!fixP->fx_done); |
4962c51a | 28819 | if (!seg->use_rela_p) |
477330fc RM |
28820 | { |
28821 | bfd_vma insn; | |
3ca4a8ec | 28822 | bfd_vma addend_abs = llabs (value); |
4962c51a | 28823 | |
477330fc RM |
28824 | /* Check that the absolute value of the addend can be |
28825 | encoded in 8 bits. */ | |
28826 | if (addend_abs >= 0x100) | |
4962c51a | 28827 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
28828 | _("bad offset 0x%08lX (only 8 bits available for the magnitude)"), |
28829 | (unsigned long) addend_abs); | |
28830 | ||
28831 | /* Extract the instruction. */ | |
28832 | insn = md_chars_to_number (buf, INSN_SIZE); | |
28833 | ||
28834 | /* If the addend is negative, clear bit 23 of the instruction. | |
28835 | Otherwise set it. */ | |
28836 | if (value < 0) | |
28837 | insn &= ~(1 << 23); | |
28838 | else | |
28839 | insn |= 1 << 23; | |
28840 | ||
28841 | /* Place the first four bits of the absolute value of the addend | |
28842 | into the first 4 bits of the instruction, and the remaining | |
28843 | four into bits 8 .. 11. */ | |
28844 | insn &= 0xfffff0f0; | |
28845 | insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4); | |
28846 | ||
28847 | /* Update the instruction. */ | |
28848 | md_number_to_chars (buf, insn, INSN_SIZE); | |
28849 | } | |
4962c51a MS |
28850 | break; |
28851 | ||
28852 | case BFD_RELOC_ARM_LDC_PC_G0: | |
28853 | case BFD_RELOC_ARM_LDC_PC_G1: | |
28854 | case BFD_RELOC_ARM_LDC_PC_G2: | |
28855 | case BFD_RELOC_ARM_LDC_SB_G0: | |
28856 | case BFD_RELOC_ARM_LDC_SB_G1: | |
28857 | case BFD_RELOC_ARM_LDC_SB_G2: | |
9c2799c2 | 28858 | gas_assert (!fixP->fx_done); |
4962c51a | 28859 | if (!seg->use_rela_p) |
477330fc RM |
28860 | { |
28861 | bfd_vma insn; | |
3ca4a8ec | 28862 | bfd_vma addend_abs = llabs (value); |
4962c51a | 28863 | |
477330fc RM |
28864 | /* Check that the absolute value of the addend is a multiple of |
28865 | four and, when divided by four, fits in 8 bits. */ | |
28866 | if (addend_abs & 0x3) | |
4962c51a | 28867 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
28868 | _("bad offset 0x%08lX (must be word-aligned)"), |
28869 | (unsigned long) addend_abs); | |
4962c51a | 28870 | |
477330fc | 28871 | if ((addend_abs >> 2) > 0xff) |
4962c51a | 28872 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
28873 | _("bad offset 0x%08lX (must be an 8-bit number of words)"), |
28874 | (unsigned long) addend_abs); | |
28875 | ||
28876 | /* Extract the instruction. */ | |
28877 | insn = md_chars_to_number (buf, INSN_SIZE); | |
28878 | ||
28879 | /* If the addend is negative, clear bit 23 of the instruction. | |
28880 | Otherwise set it. */ | |
28881 | if (value < 0) | |
28882 | insn &= ~(1 << 23); | |
28883 | else | |
28884 | insn |= 1 << 23; | |
28885 | ||
28886 | /* Place the addend (divided by four) into the first eight | |
28887 | bits of the instruction. */ | |
28888 | insn &= 0xfffffff0; | |
28889 | insn |= addend_abs >> 2; | |
28890 | ||
28891 | /* Update the instruction. */ | |
28892 | md_number_to_chars (buf, insn, INSN_SIZE); | |
28893 | } | |
4962c51a MS |
28894 | break; |
28895 | ||
e12437dc AV |
28896 | case BFD_RELOC_THUMB_PCREL_BRANCH5: |
28897 | if (fixP->fx_addsy | |
28898 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
28899 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
28900 | && ARM_IS_FUNC (fixP->fx_addsy) | |
28901 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
28902 | { | |
28903 | /* Force a relocation for a branch 5 bits wide. */ | |
28904 | fixP->fx_done = 0; | |
28905 | } | |
28906 | if (v8_1_branch_value_check (value, 5, FALSE) == FAIL) | |
28907 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28908 | BAD_BRANCH_OFF); | |
28909 | ||
28910 | if (fixP->fx_done || !seg->use_rela_p) | |
28911 | { | |
28912 | addressT boff = value >> 1; | |
28913 | ||
28914 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
28915 | newval |= (boff << 7); | |
28916 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
28917 | } | |
28918 | break; | |
28919 | ||
f6b2b12d AV |
28920 | case BFD_RELOC_THUMB_PCREL_BFCSEL: |
28921 | if (fixP->fx_addsy | |
28922 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
28923 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
28924 | && ARM_IS_FUNC (fixP->fx_addsy) | |
28925 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
28926 | { | |
28927 | fixP->fx_done = 0; | |
28928 | } | |
28929 | if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f)) | |
28930 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28931 | _("branch out of range")); | |
28932 | ||
28933 | if (fixP->fx_done || !seg->use_rela_p) | |
28934 | { | |
28935 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
28936 | ||
28937 | addressT boff = ((newval & 0x0780) >> 7) << 1; | |
28938 | addressT diff = value - boff; | |
28939 | ||
28940 | if (diff == 4) | |
28941 | { | |
28942 | newval |= 1 << 1; /* T bit. */ | |
28943 | } | |
28944 | else if (diff != 2) | |
28945 | { | |
28946 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28947 | _("out of range label-relative fixup value")); | |
28948 | } | |
28949 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
28950 | } | |
28951 | break; | |
28952 | ||
e5d6e09e AV |
28953 | case BFD_RELOC_ARM_THUMB_BF17: |
28954 | if (fixP->fx_addsy | |
28955 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
28956 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
28957 | && ARM_IS_FUNC (fixP->fx_addsy) | |
28958 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
28959 | { | |
28960 | /* Force a relocation for a branch 17 bits wide. */ | |
28961 | fixP->fx_done = 0; | |
28962 | } | |
28963 | ||
28964 | if (v8_1_branch_value_check (value, 17, TRUE) == FAIL) | |
28965 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28966 | BAD_BRANCH_OFF); | |
28967 | ||
28968 | if (fixP->fx_done || !seg->use_rela_p) | |
28969 | { | |
28970 | offsetT newval2; | |
28971 | addressT immA, immB, immC; | |
28972 | ||
28973 | immA = (value & 0x0001f000) >> 12; | |
28974 | immB = (value & 0x00000ffc) >> 2; | |
28975 | immC = (value & 0x00000002) >> 1; | |
28976 | ||
28977 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
28978 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
28979 | newval |= immA; | |
28980 | newval2 |= (immC << 11) | (immB << 1); | |
28981 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
28982 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
28983 | } | |
28984 | break; | |
28985 | ||
1caf72a5 AV |
28986 | case BFD_RELOC_ARM_THUMB_BF19: |
28987 | if (fixP->fx_addsy | |
28988 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
28989 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
28990 | && ARM_IS_FUNC (fixP->fx_addsy) | |
28991 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
28992 | { | |
28993 | /* Force a relocation for a branch 19 bits wide. */ | |
28994 | fixP->fx_done = 0; | |
28995 | } | |
28996 | ||
28997 | if (v8_1_branch_value_check (value, 19, TRUE) == FAIL) | |
28998 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28999 | BAD_BRANCH_OFF); | |
29000 | ||
29001 | if (fixP->fx_done || !seg->use_rela_p) | |
29002 | { | |
29003 | offsetT newval2; | |
29004 | addressT immA, immB, immC; | |
29005 | ||
29006 | immA = (value & 0x0007f000) >> 12; | |
29007 | immB = (value & 0x00000ffc) >> 2; | |
29008 | immC = (value & 0x00000002) >> 1; | |
29009 | ||
29010 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
29011 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
29012 | newval |= immA; | |
29013 | newval2 |= (immC << 11) | (immB << 1); | |
29014 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
29015 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
29016 | } | |
29017 | break; | |
29018 | ||
1889da70 AV |
29019 | case BFD_RELOC_ARM_THUMB_BF13: |
29020 | if (fixP->fx_addsy | |
29021 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
29022 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
29023 | && ARM_IS_FUNC (fixP->fx_addsy) | |
29024 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
29025 | { | |
29026 | /* Force a relocation for a branch 13 bits wide. */ | |
29027 | fixP->fx_done = 0; | |
29028 | } | |
29029 | ||
29030 | if (v8_1_branch_value_check (value, 13, TRUE) == FAIL) | |
29031 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
29032 | BAD_BRANCH_OFF); | |
29033 | ||
29034 | if (fixP->fx_done || !seg->use_rela_p) | |
29035 | { | |
29036 | offsetT newval2; | |
29037 | addressT immA, immB, immC; | |
29038 | ||
29039 | immA = (value & 0x00001000) >> 12; | |
29040 | immB = (value & 0x00000ffc) >> 2; | |
29041 | immC = (value & 0x00000002) >> 1; | |
29042 | ||
29043 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
29044 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
29045 | newval |= immA; | |
29046 | newval2 |= (immC << 11) | (immB << 1); | |
29047 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
29048 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
29049 | } | |
29050 | break; | |
29051 | ||
60f993ce AV |
29052 | case BFD_RELOC_ARM_THUMB_LOOP12: |
29053 | if (fixP->fx_addsy | |
29054 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
29055 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
29056 | && ARM_IS_FUNC (fixP->fx_addsy) | |
29057 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
29058 | { | |
29059 | /* Force a relocation for a branch 12 bits wide. */ | |
29060 | fixP->fx_done = 0; | |
29061 | } | |
29062 | ||
29063 | bfd_vma insn = get_thumb32_insn (buf); | |
1f6234a3 | 29064 | /* le lr, <label>, le <label> or letp lr, <label> */ |
60f993ce | 29065 | if (((insn & 0xffffffff) == 0xf00fc001) |
1f6234a3 AV |
29066 | || ((insn & 0xffffffff) == 0xf02fc001) |
29067 | || ((insn & 0xffffffff) == 0xf01fc001)) | |
60f993ce AV |
29068 | value = -value; |
29069 | ||
29070 | if (v8_1_branch_value_check (value, 12, FALSE) == FAIL) | |
29071 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
29072 | BAD_BRANCH_OFF); | |
29073 | if (fixP->fx_done || !seg->use_rela_p) | |
29074 | { | |
29075 | addressT imml, immh; | |
29076 | ||
29077 | immh = (value & 0x00000ffc) >> 2; | |
29078 | imml = (value & 0x00000002) >> 1; | |
29079 | ||
29080 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
29081 | newval |= (imml << 11) | (immh << 1); | |
29082 | md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE); | |
29083 | } | |
29084 | break; | |
29085 | ||
845b51d6 PB |
29086 | case BFD_RELOC_ARM_V4BX: |
29087 | /* This will need to go in the object file. */ | |
29088 | fixP->fx_done = 0; | |
29089 | break; | |
29090 | ||
c19d1205 ZW |
29091 | case BFD_RELOC_UNUSED: |
29092 | default: | |
29093 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
29094 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
29095 | } | |
6c43fab6 RE |
29096 | } |
29097 | ||
c19d1205 ZW |
29098 | /* Translate internal representation of relocation info to BFD target |
29099 | format. */ | |
a737bd4d | 29100 | |
c19d1205 | 29101 | arelent * |
00a97672 | 29102 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 29103 | { |
c19d1205 ZW |
29104 | arelent * reloc; |
29105 | bfd_reloc_code_real_type code; | |
a737bd4d | 29106 | |
325801bd | 29107 | reloc = XNEW (arelent); |
a737bd4d | 29108 | |
325801bd | 29109 | reloc->sym_ptr_ptr = XNEW (asymbol *); |
c19d1205 ZW |
29110 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
29111 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 29112 | |
2fc8bdac | 29113 | if (fixp->fx_pcrel) |
00a97672 RS |
29114 | { |
29115 | if (section->use_rela_p) | |
29116 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
29117 | else | |
29118 | fixp->fx_offset = reloc->address; | |
29119 | } | |
c19d1205 | 29120 | reloc->addend = fixp->fx_offset; |
a737bd4d | 29121 | |
c19d1205 | 29122 | switch (fixp->fx_r_type) |
a737bd4d | 29123 | { |
c19d1205 ZW |
29124 | case BFD_RELOC_8: |
29125 | if (fixp->fx_pcrel) | |
29126 | { | |
29127 | code = BFD_RELOC_8_PCREL; | |
29128 | break; | |
29129 | } | |
1a0670f3 | 29130 | /* Fall through. */ |
a737bd4d | 29131 | |
c19d1205 ZW |
29132 | case BFD_RELOC_16: |
29133 | if (fixp->fx_pcrel) | |
29134 | { | |
29135 | code = BFD_RELOC_16_PCREL; | |
29136 | break; | |
29137 | } | |
1a0670f3 | 29138 | /* Fall through. */ |
6c43fab6 | 29139 | |
c19d1205 ZW |
29140 | case BFD_RELOC_32: |
29141 | if (fixp->fx_pcrel) | |
29142 | { | |
29143 | code = BFD_RELOC_32_PCREL; | |
29144 | break; | |
29145 | } | |
1a0670f3 | 29146 | /* Fall through. */ |
a737bd4d | 29147 | |
b6895b4f PB |
29148 | case BFD_RELOC_ARM_MOVW: |
29149 | if (fixp->fx_pcrel) | |
29150 | { | |
29151 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
29152 | break; | |
29153 | } | |
1a0670f3 | 29154 | /* Fall through. */ |
b6895b4f PB |
29155 | |
29156 | case BFD_RELOC_ARM_MOVT: | |
29157 | if (fixp->fx_pcrel) | |
29158 | { | |
29159 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
29160 | break; | |
29161 | } | |
1a0670f3 | 29162 | /* Fall through. */ |
b6895b4f PB |
29163 | |
29164 | case BFD_RELOC_ARM_THUMB_MOVW: | |
29165 | if (fixp->fx_pcrel) | |
29166 | { | |
29167 | code = BFD_RELOC_ARM_THUMB_MOVW_PCREL; | |
29168 | break; | |
29169 | } | |
1a0670f3 | 29170 | /* Fall through. */ |
b6895b4f PB |
29171 | |
29172 | case BFD_RELOC_ARM_THUMB_MOVT: | |
29173 | if (fixp->fx_pcrel) | |
29174 | { | |
29175 | code = BFD_RELOC_ARM_THUMB_MOVT_PCREL; | |
29176 | break; | |
29177 | } | |
1a0670f3 | 29178 | /* Fall through. */ |
b6895b4f | 29179 | |
c19d1205 ZW |
29180 | case BFD_RELOC_NONE: |
29181 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
29182 | case BFD_RELOC_ARM_PCREL_BLX: | |
29183 | case BFD_RELOC_RVA: | |
29184 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
29185 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
29186 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
29187 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
29188 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
29189 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
c19d1205 ZW |
29190 | case BFD_RELOC_VTABLE_ENTRY: |
29191 | case BFD_RELOC_VTABLE_INHERIT: | |
f0927246 NC |
29192 | #ifdef TE_PE |
29193 | case BFD_RELOC_32_SECREL: | |
29194 | #endif | |
c19d1205 ZW |
29195 | code = fixp->fx_r_type; |
29196 | break; | |
a737bd4d | 29197 | |
00adf2d4 JB |
29198 | case BFD_RELOC_THUMB_PCREL_BLX: |
29199 | #ifdef OBJ_ELF | |
29200 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
29201 | code = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
29202 | else | |
29203 | #endif | |
29204 | code = BFD_RELOC_THUMB_PCREL_BLX; | |
29205 | break; | |
29206 | ||
c19d1205 ZW |
29207 | case BFD_RELOC_ARM_LITERAL: |
29208 | case BFD_RELOC_ARM_HWLITERAL: | |
29209 | /* If this is called then the a literal has | |
29210 | been referenced across a section boundary. */ | |
29211 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
29212 | _("literal referenced across section boundary")); | |
29213 | return NULL; | |
a737bd4d | 29214 | |
c19d1205 | 29215 | #ifdef OBJ_ELF |
0855e32b NS |
29216 | case BFD_RELOC_ARM_TLS_CALL: |
29217 | case BFD_RELOC_ARM_THM_TLS_CALL: | |
29218 | case BFD_RELOC_ARM_TLS_DESCSEQ: | |
29219 | case BFD_RELOC_ARM_THM_TLS_DESCSEQ: | |
c19d1205 ZW |
29220 | case BFD_RELOC_ARM_GOT32: |
29221 | case BFD_RELOC_ARM_GOTOFF: | |
b43420e6 | 29222 | case BFD_RELOC_ARM_GOT_PREL: |
c19d1205 ZW |
29223 | case BFD_RELOC_ARM_PLT32: |
29224 | case BFD_RELOC_ARM_TARGET1: | |
29225 | case BFD_RELOC_ARM_ROSEGREL32: | |
29226 | case BFD_RELOC_ARM_SBREL32: | |
29227 | case BFD_RELOC_ARM_PREL31: | |
29228 | case BFD_RELOC_ARM_TARGET2: | |
c19d1205 | 29229 | case BFD_RELOC_ARM_TLS_LDO32: |
39b41c9c PB |
29230 | case BFD_RELOC_ARM_PCREL_CALL: |
29231 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
29232 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
29233 | case BFD_RELOC_ARM_ALU_PC_G0: | |
29234 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
29235 | case BFD_RELOC_ARM_ALU_PC_G1: | |
29236 | case BFD_RELOC_ARM_ALU_PC_G2: | |
29237 | case BFD_RELOC_ARM_LDR_PC_G0: | |
29238 | case BFD_RELOC_ARM_LDR_PC_G1: | |
29239 | case BFD_RELOC_ARM_LDR_PC_G2: | |
29240 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
29241 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
29242 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
29243 | case BFD_RELOC_ARM_LDC_PC_G0: | |
29244 | case BFD_RELOC_ARM_LDC_PC_G1: | |
29245 | case BFD_RELOC_ARM_LDC_PC_G2: | |
29246 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
29247 | case BFD_RELOC_ARM_ALU_SB_G0: | |
29248 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
29249 | case BFD_RELOC_ARM_ALU_SB_G1: | |
29250 | case BFD_RELOC_ARM_ALU_SB_G2: | |
29251 | case BFD_RELOC_ARM_LDR_SB_G0: | |
29252 | case BFD_RELOC_ARM_LDR_SB_G1: | |
29253 | case BFD_RELOC_ARM_LDR_SB_G2: | |
29254 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
29255 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
29256 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
29257 | case BFD_RELOC_ARM_LDC_SB_G0: | |
29258 | case BFD_RELOC_ARM_LDC_SB_G1: | |
29259 | case BFD_RELOC_ARM_LDC_SB_G2: | |
845b51d6 | 29260 | case BFD_RELOC_ARM_V4BX: |
72d98d16 MG |
29261 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC: |
29262 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC: | |
29263 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC: | |
29264 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC: | |
188fd7ae CL |
29265 | case BFD_RELOC_ARM_GOTFUNCDESC: |
29266 | case BFD_RELOC_ARM_GOTOFFFUNCDESC: | |
29267 | case BFD_RELOC_ARM_FUNCDESC: | |
e5d6e09e | 29268 | case BFD_RELOC_ARM_THUMB_BF17: |
1caf72a5 | 29269 | case BFD_RELOC_ARM_THUMB_BF19: |
1889da70 | 29270 | case BFD_RELOC_ARM_THUMB_BF13: |
c19d1205 ZW |
29271 | code = fixp->fx_r_type; |
29272 | break; | |
a737bd4d | 29273 | |
0855e32b | 29274 | case BFD_RELOC_ARM_TLS_GOTDESC: |
c19d1205 | 29275 | case BFD_RELOC_ARM_TLS_GD32: |
5c5a4843 | 29276 | case BFD_RELOC_ARM_TLS_GD32_FDPIC: |
75c11999 | 29277 | case BFD_RELOC_ARM_TLS_LE32: |
c19d1205 | 29278 | case BFD_RELOC_ARM_TLS_IE32: |
5c5a4843 | 29279 | case BFD_RELOC_ARM_TLS_IE32_FDPIC: |
c19d1205 | 29280 | case BFD_RELOC_ARM_TLS_LDM32: |
5c5a4843 | 29281 | case BFD_RELOC_ARM_TLS_LDM32_FDPIC: |
c19d1205 ZW |
29282 | /* BFD will include the symbol's address in the addend. |
29283 | But we don't want that, so subtract it out again here. */ | |
29284 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
29285 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
29286 | code = fixp->fx_r_type; | |
29287 | break; | |
29288 | #endif | |
a737bd4d | 29289 | |
c19d1205 ZW |
29290 | case BFD_RELOC_ARM_IMMEDIATE: |
29291 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
29292 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
29293 | return NULL; | |
a737bd4d | 29294 | |
c19d1205 ZW |
29295 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
29296 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
29297 | _("ADRL used for a symbol not defined in the same file")); | |
29298 | return NULL; | |
a737bd4d | 29299 | |
e12437dc | 29300 | case BFD_RELOC_THUMB_PCREL_BRANCH5: |
f6b2b12d | 29301 | case BFD_RELOC_THUMB_PCREL_BFCSEL: |
60f993ce | 29302 | case BFD_RELOC_ARM_THUMB_LOOP12: |
e12437dc AV |
29303 | as_bad_where (fixp->fx_file, fixp->fx_line, |
29304 | _("%s used for a symbol not defined in the same file"), | |
29305 | bfd_get_reloc_code_name (fixp->fx_r_type)); | |
29306 | return NULL; | |
29307 | ||
c19d1205 | 29308 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
29309 | if (section->use_rela_p) |
29310 | { | |
29311 | code = fixp->fx_r_type; | |
29312 | break; | |
29313 | } | |
29314 | ||
c19d1205 ZW |
29315 | if (fixp->fx_addsy != NULL |
29316 | && !S_IS_DEFINED (fixp->fx_addsy) | |
29317 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 29318 | { |
c19d1205 ZW |
29319 | as_bad_where (fixp->fx_file, fixp->fx_line, |
29320 | _("undefined local label `%s'"), | |
29321 | S_GET_NAME (fixp->fx_addsy)); | |
29322 | return NULL; | |
a737bd4d NC |
29323 | } |
29324 | ||
c19d1205 ZW |
29325 | as_bad_where (fixp->fx_file, fixp->fx_line, |
29326 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
29327 | return NULL; | |
a737bd4d | 29328 | |
c19d1205 ZW |
29329 | default: |
29330 | { | |
e0471c16 | 29331 | const char * type; |
6c43fab6 | 29332 | |
c19d1205 ZW |
29333 | switch (fixp->fx_r_type) |
29334 | { | |
29335 | case BFD_RELOC_NONE: type = "NONE"; break; | |
29336 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
29337 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 29338 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
29339 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
29340 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
29341 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
db187cb9 | 29342 | case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break; |
8f06b2d8 | 29343 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
29344 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
29345 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
29346 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
29347 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
29348 | default: type = _("<unknown>"); break; | |
29349 | } | |
29350 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
29351 | _("cannot represent %s relocation in this object file format"), | |
29352 | type); | |
29353 | return NULL; | |
29354 | } | |
a737bd4d | 29355 | } |
6c43fab6 | 29356 | |
c19d1205 ZW |
29357 | #ifdef OBJ_ELF |
29358 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
29359 | && GOT_symbol | |
29360 | && fixp->fx_addsy == GOT_symbol) | |
29361 | { | |
29362 | code = BFD_RELOC_ARM_GOTPC; | |
29363 | reloc->addend = fixp->fx_offset = reloc->address; | |
29364 | } | |
29365 | #endif | |
6c43fab6 | 29366 | |
c19d1205 | 29367 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 29368 | |
c19d1205 ZW |
29369 | if (reloc->howto == NULL) |
29370 | { | |
29371 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
29372 | _("cannot represent %s relocation in this object file format"), | |
29373 | bfd_get_reloc_code_name (code)); | |
29374 | return NULL; | |
29375 | } | |
6c43fab6 | 29376 | |
c19d1205 ZW |
29377 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
29378 | vtable entry to be used in the relocation's section offset. */ | |
29379 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
29380 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 29381 | |
c19d1205 | 29382 | return reloc; |
6c43fab6 RE |
29383 | } |
29384 | ||
c19d1205 | 29385 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 29386 | |
c19d1205 ZW |
29387 | void |
29388 | cons_fix_new_arm (fragS * frag, | |
29389 | int where, | |
29390 | int size, | |
62ebcb5c AM |
29391 | expressionS * exp, |
29392 | bfd_reloc_code_real_type reloc) | |
6c43fab6 | 29393 | { |
c19d1205 | 29394 | int pcrel = 0; |
6c43fab6 | 29395 | |
c19d1205 ZW |
29396 | /* Pick a reloc. |
29397 | FIXME: @@ Should look at CPU word size. */ | |
29398 | switch (size) | |
29399 | { | |
29400 | case 1: | |
62ebcb5c | 29401 | reloc = BFD_RELOC_8; |
c19d1205 ZW |
29402 | break; |
29403 | case 2: | |
62ebcb5c | 29404 | reloc = BFD_RELOC_16; |
c19d1205 ZW |
29405 | break; |
29406 | case 4: | |
29407 | default: | |
62ebcb5c | 29408 | reloc = BFD_RELOC_32; |
c19d1205 ZW |
29409 | break; |
29410 | case 8: | |
62ebcb5c | 29411 | reloc = BFD_RELOC_64; |
c19d1205 ZW |
29412 | break; |
29413 | } | |
6c43fab6 | 29414 | |
f0927246 NC |
29415 | #ifdef TE_PE |
29416 | if (exp->X_op == O_secrel) | |
29417 | { | |
29418 | exp->X_op = O_symbol; | |
62ebcb5c | 29419 | reloc = BFD_RELOC_32_SECREL; |
f0927246 NC |
29420 | } |
29421 | #endif | |
29422 | ||
62ebcb5c | 29423 | fix_new_exp (frag, where, size, exp, pcrel, reloc); |
c19d1205 | 29424 | } |
6c43fab6 | 29425 | |
4343666d | 29426 | #if defined (OBJ_COFF) |
c19d1205 ZW |
29427 | void |
29428 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 29429 | { |
c19d1205 ZW |
29430 | /* If the destination of the branch is a defined symbol which does not have |
29431 | the THUMB_FUNC attribute, then we must be calling a function which has | |
29432 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
29433 | function and change the branch to refer to that function instead. */ | |
29434 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
29435 | && fixP->fx_addsy != NULL | |
29436 | && S_IS_DEFINED (fixP->fx_addsy) | |
29437 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 29438 | { |
c19d1205 | 29439 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 29440 | } |
c19d1205 ZW |
29441 | } |
29442 | #endif | |
6c43fab6 | 29443 | |
267bf995 | 29444 | |
c19d1205 ZW |
29445 | int |
29446 | arm_force_relocation (struct fix * fixp) | |
29447 | { | |
29448 | #if defined (OBJ_COFF) && defined (TE_PE) | |
29449 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
29450 | return 1; | |
29451 | #endif | |
6c43fab6 | 29452 | |
267bf995 RR |
29453 | /* In case we have a call or a branch to a function in ARM ISA mode from |
29454 | a thumb function or vice-versa force the relocation. These relocations | |
29455 | are cleared off for some cores that might have blx and simple transformations | |
29456 | are possible. */ | |
29457 | ||
29458 | #ifdef OBJ_ELF | |
29459 | switch (fixp->fx_r_type) | |
29460 | { | |
29461 | case BFD_RELOC_ARM_PCREL_JUMP: | |
29462 | case BFD_RELOC_ARM_PCREL_CALL: | |
29463 | case BFD_RELOC_THUMB_PCREL_BLX: | |
29464 | if (THUMB_IS_FUNC (fixp->fx_addsy)) | |
29465 | return 1; | |
29466 | break; | |
29467 | ||
29468 | case BFD_RELOC_ARM_PCREL_BLX: | |
29469 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
29470 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
29471 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
29472 | if (ARM_IS_FUNC (fixp->fx_addsy)) | |
29473 | return 1; | |
29474 | break; | |
29475 | ||
29476 | default: | |
29477 | break; | |
29478 | } | |
29479 | #endif | |
29480 | ||
b5884301 PB |
29481 | /* Resolve these relocations even if the symbol is extern or weak. |
29482 | Technically this is probably wrong due to symbol preemption. | |
29483 | In practice these relocations do not have enough range to be useful | |
29484 | at dynamic link time, and some code (e.g. in the Linux kernel) | |
29485 | expects these references to be resolved. */ | |
c19d1205 ZW |
29486 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE |
29487 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
b5884301 | 29488 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8 |
0110f2b8 | 29489 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
b5884301 PB |
29490 | || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
29491 | || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2 | |
29492 | || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET | |
16805f35 | 29493 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM |
0110f2b8 PB |
29494 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
29495 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
b5884301 PB |
29496 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM |
29497 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12 | |
29498 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM | |
29499 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2) | |
c19d1205 | 29500 | return 0; |
a737bd4d | 29501 | |
4962c51a MS |
29502 | /* Always leave these relocations for the linker. */ |
29503 | if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
29504 | && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
29505 | || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
29506 | return 1; | |
29507 | ||
f0291e4c PB |
29508 | /* Always generate relocations against function symbols. */ |
29509 | if (fixp->fx_r_type == BFD_RELOC_32 | |
29510 | && fixp->fx_addsy | |
29511 | && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION)) | |
29512 | return 1; | |
29513 | ||
c19d1205 | 29514 | return generic_force_reloc (fixp); |
404ff6b5 AH |
29515 | } |
29516 | ||
0ffdc86c | 29517 | #if defined (OBJ_ELF) || defined (OBJ_COFF) |
e28387c3 PB |
29518 | /* Relocations against function names must be left unadjusted, |
29519 | so that the linker can use this information to generate interworking | |
29520 | stubs. The MIPS version of this function | |
c19d1205 ZW |
29521 | also prevents relocations that are mips-16 specific, but I do not |
29522 | know why it does this. | |
404ff6b5 | 29523 | |
c19d1205 ZW |
29524 | FIXME: |
29525 | There is one other problem that ought to be addressed here, but | |
29526 | which currently is not: Taking the address of a label (rather | |
29527 | than a function) and then later jumping to that address. Such | |
29528 | addresses also ought to have their bottom bit set (assuming that | |
29529 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 29530 | |
c19d1205 ZW |
29531 | bfd_boolean |
29532 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 29533 | { |
c19d1205 ZW |
29534 | if (fixP->fx_addsy == NULL) |
29535 | return 1; | |
404ff6b5 | 29536 | |
e28387c3 PB |
29537 | /* Preserve relocations against symbols with function type. */ |
29538 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
c921be7d | 29539 | return FALSE; |
e28387c3 | 29540 | |
c19d1205 ZW |
29541 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
29542 | && fixP->fx_subsy == NULL) | |
c921be7d | 29543 | return FALSE; |
a737bd4d | 29544 | |
c19d1205 ZW |
29545 | /* We need the symbol name for the VTABLE entries. */ |
29546 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
29547 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
c921be7d | 29548 | return FALSE; |
404ff6b5 | 29549 | |
c19d1205 ZW |
29550 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
29551 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
29552 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
29553 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
29554 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
5c5a4843 | 29555 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC |
c19d1205 ZW |
29556 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 |
29557 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
5c5a4843 | 29558 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC |
c19d1205 | 29559 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 |
5c5a4843 | 29560 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC |
c19d1205 | 29561 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 |
0855e32b NS |
29562 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC |
29563 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL | |
29564 | || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL | |
29565 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ | |
29566 | || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ | |
c19d1205 | 29567 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) |
c921be7d | 29568 | return FALSE; |
a737bd4d | 29569 | |
4962c51a MS |
29570 | /* Similarly for group relocations. */ |
29571 | if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
29572 | && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
29573 | || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
c921be7d | 29574 | return FALSE; |
4962c51a | 29575 | |
79947c54 CD |
29576 | /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */ |
29577 | if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW | |
29578 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
29579 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL | |
29580 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL | |
29581 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
29582 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT | |
29583 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL | |
29584 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL) | |
c921be7d | 29585 | return FALSE; |
79947c54 | 29586 | |
72d98d16 MG |
29587 | /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited |
29588 | offsets, so keep these symbols. */ | |
29589 | if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC | |
29590 | && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) | |
29591 | return FALSE; | |
29592 | ||
c921be7d | 29593 | return TRUE; |
a737bd4d | 29594 | } |
0ffdc86c NC |
29595 | #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */ |
29596 | ||
29597 | #ifdef OBJ_ELF | |
c19d1205 ZW |
29598 | const char * |
29599 | elf32_arm_target_format (void) | |
404ff6b5 | 29600 | { |
c19d1205 ZW |
29601 | #ifdef TE_SYMBIAN |
29602 | return (target_big_endian | |
29603 | ? "elf32-bigarm-symbian" | |
29604 | : "elf32-littlearm-symbian"); | |
29605 | #elif defined (TE_VXWORKS) | |
29606 | return (target_big_endian | |
29607 | ? "elf32-bigarm-vxworks" | |
29608 | : "elf32-littlearm-vxworks"); | |
b38cadfb NC |
29609 | #elif defined (TE_NACL) |
29610 | return (target_big_endian | |
29611 | ? "elf32-bigarm-nacl" | |
29612 | : "elf32-littlearm-nacl"); | |
c19d1205 | 29613 | #else |
18a20338 CL |
29614 | if (arm_fdpic) |
29615 | { | |
29616 | if (target_big_endian) | |
29617 | return "elf32-bigarm-fdpic"; | |
29618 | else | |
29619 | return "elf32-littlearm-fdpic"; | |
29620 | } | |
c19d1205 | 29621 | else |
18a20338 CL |
29622 | { |
29623 | if (target_big_endian) | |
29624 | return "elf32-bigarm"; | |
29625 | else | |
29626 | return "elf32-littlearm"; | |
29627 | } | |
c19d1205 | 29628 | #endif |
404ff6b5 AH |
29629 | } |
29630 | ||
c19d1205 ZW |
29631 | void |
29632 | armelf_frob_symbol (symbolS * symp, | |
29633 | int * puntp) | |
404ff6b5 | 29634 | { |
c19d1205 ZW |
29635 | elf_frob_symbol (symp, puntp); |
29636 | } | |
29637 | #endif | |
404ff6b5 | 29638 | |
c19d1205 | 29639 | /* MD interface: Finalization. */ |
a737bd4d | 29640 | |
c19d1205 ZW |
29641 | void |
29642 | arm_cleanup (void) | |
29643 | { | |
29644 | literal_pool * pool; | |
a737bd4d | 29645 | |
5ee91343 AV |
29646 | /* Ensure that all the predication blocks are properly closed. */ |
29647 | check_pred_blocks_finished (); | |
e07e6e58 | 29648 | |
c19d1205 ZW |
29649 | for (pool = list_of_pools; pool; pool = pool->next) |
29650 | { | |
5f4273c7 | 29651 | /* Put it at the end of the relevant section. */ |
c19d1205 ZW |
29652 | subseg_set (pool->section, pool->sub_section); |
29653 | #ifdef OBJ_ELF | |
29654 | arm_elf_change_section (); | |
29655 | #endif | |
29656 | s_ltorg (0); | |
29657 | } | |
404ff6b5 AH |
29658 | } |
29659 | ||
cd000bff DJ |
29660 | #ifdef OBJ_ELF |
29661 | /* Remove any excess mapping symbols generated for alignment frags in | |
29662 | SEC. We may have created a mapping symbol before a zero byte | |
29663 | alignment; remove it if there's a mapping symbol after the | |
29664 | alignment. */ | |
29665 | static void | |
29666 | check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, | |
29667 | void *dummy ATTRIBUTE_UNUSED) | |
29668 | { | |
29669 | segment_info_type *seginfo = seg_info (sec); | |
29670 | fragS *fragp; | |
29671 | ||
29672 | if (seginfo == NULL || seginfo->frchainP == NULL) | |
29673 | return; | |
29674 | ||
29675 | for (fragp = seginfo->frchainP->frch_root; | |
29676 | fragp != NULL; | |
29677 | fragp = fragp->fr_next) | |
29678 | { | |
29679 | symbolS *sym = fragp->tc_frag_data.last_map; | |
29680 | fragS *next = fragp->fr_next; | |
29681 | ||
29682 | /* Variable-sized frags have been converted to fixed size by | |
29683 | this point. But if this was variable-sized to start with, | |
29684 | there will be a fixed-size frag after it. So don't handle | |
29685 | next == NULL. */ | |
29686 | if (sym == NULL || next == NULL) | |
29687 | continue; | |
29688 | ||
29689 | if (S_GET_VALUE (sym) < next->fr_address) | |
29690 | /* Not at the end of this frag. */ | |
29691 | continue; | |
29692 | know (S_GET_VALUE (sym) == next->fr_address); | |
29693 | ||
29694 | do | |
29695 | { | |
29696 | if (next->tc_frag_data.first_map != NULL) | |
29697 | { | |
29698 | /* Next frag starts with a mapping symbol. Discard this | |
29699 | one. */ | |
29700 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
29701 | break; | |
29702 | } | |
29703 | ||
29704 | if (next->fr_next == NULL) | |
29705 | { | |
29706 | /* This mapping symbol is at the end of the section. Discard | |
29707 | it. */ | |
29708 | know (next->fr_fix == 0 && next->fr_var == 0); | |
29709 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
29710 | break; | |
29711 | } | |
29712 | ||
29713 | /* As long as we have empty frags without any mapping symbols, | |
29714 | keep looking. */ | |
29715 | /* If the next frag is non-empty and does not start with a | |
29716 | mapping symbol, then this mapping symbol is required. */ | |
29717 | if (next->fr_address != next->fr_next->fr_address) | |
29718 | break; | |
29719 | ||
29720 | next = next->fr_next; | |
29721 | } | |
29722 | while (next != NULL); | |
29723 | } | |
29724 | } | |
29725 | #endif | |
29726 | ||
c19d1205 ZW |
29727 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
29728 | ARM ones. */ | |
404ff6b5 | 29729 | |
c19d1205 ZW |
29730 | void |
29731 | arm_adjust_symtab (void) | |
404ff6b5 | 29732 | { |
c19d1205 ZW |
29733 | #ifdef OBJ_COFF |
29734 | symbolS * sym; | |
404ff6b5 | 29735 | |
c19d1205 ZW |
29736 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
29737 | { | |
29738 | if (ARM_IS_THUMB (sym)) | |
29739 | { | |
29740 | if (THUMB_IS_FUNC (sym)) | |
29741 | { | |
29742 | /* Mark the symbol as a Thumb function. */ | |
29743 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
29744 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
29745 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 29746 | |
c19d1205 ZW |
29747 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
29748 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
29749 | else | |
29750 | as_bad (_("%s: unexpected function type: %d"), | |
29751 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
29752 | } | |
29753 | else switch (S_GET_STORAGE_CLASS (sym)) | |
29754 | { | |
29755 | case C_EXT: | |
29756 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
29757 | break; | |
29758 | case C_STAT: | |
29759 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
29760 | break; | |
29761 | case C_LABEL: | |
29762 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
29763 | break; | |
29764 | default: | |
29765 | /* Do nothing. */ | |
29766 | break; | |
29767 | } | |
29768 | } | |
a737bd4d | 29769 | |
c19d1205 ZW |
29770 | if (ARM_IS_INTERWORK (sym)) |
29771 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 29772 | } |
c19d1205 ZW |
29773 | #endif |
29774 | #ifdef OBJ_ELF | |
29775 | symbolS * sym; | |
29776 | char bind; | |
404ff6b5 | 29777 | |
c19d1205 | 29778 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 29779 | { |
c19d1205 ZW |
29780 | if (ARM_IS_THUMB (sym)) |
29781 | { | |
29782 | elf_symbol_type * elf_sym; | |
404ff6b5 | 29783 | |
c19d1205 ZW |
29784 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
29785 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 29786 | |
b0796911 PB |
29787 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
29788 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
29789 | { |
29790 | /* If it's a .thumb_func, declare it as so, | |
29791 | otherwise tag label as .code 16. */ | |
29792 | if (THUMB_IS_FUNC (sym)) | |
39d911fc TP |
29793 | ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal, |
29794 | ST_BRANCH_TO_THUMB); | |
3ba67470 | 29795 | else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
c19d1205 ZW |
29796 | elf_sym->internal_elf_sym.st_info = |
29797 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
29798 | } | |
29799 | } | |
29800 | } | |
cd000bff DJ |
29801 | |
29802 | /* Remove any overlapping mapping symbols generated by alignment frags. */ | |
29803 | bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0); | |
709001e9 MM |
29804 | /* Now do generic ELF adjustments. */ |
29805 | elf_adjust_symtab (); | |
c19d1205 | 29806 | #endif |
404ff6b5 AH |
29807 | } |
29808 | ||
c19d1205 | 29809 | /* MD interface: Initialization. */ |
404ff6b5 | 29810 | |
a737bd4d | 29811 | static void |
c19d1205 | 29812 | set_constant_flonums (void) |
a737bd4d | 29813 | { |
c19d1205 | 29814 | int i; |
404ff6b5 | 29815 | |
c19d1205 ZW |
29816 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
29817 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
29818 | abort (); | |
a737bd4d | 29819 | } |
404ff6b5 | 29820 | |
3e9e4fcf JB |
29821 | /* Auto-select Thumb mode if it's the only available instruction set for the |
29822 | given architecture. */ | |
29823 | ||
29824 | static void | |
29825 | autoselect_thumb_from_cpu_variant (void) | |
29826 | { | |
29827 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) | |
29828 | opcode_select (16); | |
29829 | } | |
29830 | ||
c19d1205 ZW |
29831 | void |
29832 | md_begin (void) | |
a737bd4d | 29833 | { |
c19d1205 ZW |
29834 | unsigned mach; |
29835 | unsigned int i; | |
404ff6b5 | 29836 | |
c19d1205 ZW |
29837 | if ( (arm_ops_hsh = hash_new ()) == NULL |
29838 | || (arm_cond_hsh = hash_new ()) == NULL | |
5ee91343 | 29839 | || (arm_vcond_hsh = hash_new ()) == NULL |
c19d1205 ZW |
29840 | || (arm_shift_hsh = hash_new ()) == NULL |
29841 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 29842 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 29843 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
29844 | || (arm_reloc_hsh = hash_new ()) == NULL |
29845 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
29846 | as_fatal (_("virtual memory exhausted")); |
29847 | ||
29848 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
d3ce72d0 | 29849 | hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i)); |
c19d1205 | 29850 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) |
d3ce72d0 | 29851 | hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i)); |
5ee91343 AV |
29852 | for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++) |
29853 | hash_insert (arm_vcond_hsh, vconds[i].template_name, (void *) (vconds + i)); | |
c19d1205 | 29854 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) |
5a49b8ac | 29855 | hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i)); |
c19d1205 | 29856 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 | 29857 | hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i)); |
62b3e311 | 29858 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 | 29859 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name, |
477330fc | 29860 | (void *) (v7m_psrs + i)); |
c19d1205 | 29861 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
5a49b8ac | 29862 | hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i)); |
62b3e311 PB |
29863 | for (i = 0; |
29864 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
29865 | i++) | |
d3ce72d0 | 29866 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name, |
5a49b8ac | 29867 | (void *) (barrier_opt_names + i)); |
c19d1205 | 29868 | #ifdef OBJ_ELF |
3da1d841 NC |
29869 | for (i = 0; i < ARRAY_SIZE (reloc_names); i++) |
29870 | { | |
29871 | struct reloc_entry * entry = reloc_names + i; | |
29872 | ||
29873 | if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32) | |
29874 | /* This makes encode_branch() use the EABI versions of this relocation. */ | |
29875 | entry->reloc = BFD_RELOC_UNUSED; | |
29876 | ||
29877 | hash_insert (arm_reloc_hsh, entry->name, (void *) entry); | |
29878 | } | |
c19d1205 ZW |
29879 | #endif |
29880 | ||
29881 | set_constant_flonums (); | |
404ff6b5 | 29882 | |
c19d1205 ZW |
29883 | /* Set the cpu variant based on the command-line options. We prefer |
29884 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
29885 | -mfpu= over any other way of setting the floating point unit. | |
29886 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 29887 | if (legacy_cpu) |
404ff6b5 | 29888 | { |
e74cfd16 | 29889 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
29890 | as_bad (_("use of old and new-style options to set CPU type")); |
29891 | ||
4d354d8b | 29892 | selected_arch = *legacy_cpu; |
404ff6b5 | 29893 | } |
4d354d8b TP |
29894 | else if (mcpu_cpu_opt) |
29895 | { | |
29896 | selected_arch = *mcpu_cpu_opt; | |
29897 | selected_ext = *mcpu_ext_opt; | |
29898 | } | |
29899 | else if (march_cpu_opt) | |
c168ce07 | 29900 | { |
4d354d8b TP |
29901 | selected_arch = *march_cpu_opt; |
29902 | selected_ext = *march_ext_opt; | |
c168ce07 | 29903 | } |
4d354d8b | 29904 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext); |
404ff6b5 | 29905 | |
e74cfd16 | 29906 | if (legacy_fpu) |
c19d1205 | 29907 | { |
e74cfd16 | 29908 | if (mfpu_opt) |
c19d1205 | 29909 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f | 29910 | |
4d354d8b | 29911 | selected_fpu = *legacy_fpu; |
03b1477f | 29912 | } |
4d354d8b TP |
29913 | else if (mfpu_opt) |
29914 | selected_fpu = *mfpu_opt; | |
29915 | else | |
03b1477f | 29916 | { |
45eb4c1b NS |
29917 | #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \ |
29918 | || defined (TE_NetBSD) || defined (TE_VXWORKS)) | |
39c2da32 RE |
29919 | /* Some environments specify a default FPU. If they don't, infer it |
29920 | from the processor. */ | |
e74cfd16 | 29921 | if (mcpu_fpu_opt) |
4d354d8b | 29922 | selected_fpu = *mcpu_fpu_opt; |
e7da50fa | 29923 | else if (march_fpu_opt) |
4d354d8b | 29924 | selected_fpu = *march_fpu_opt; |
39c2da32 | 29925 | #else |
4d354d8b | 29926 | selected_fpu = fpu_default; |
39c2da32 | 29927 | #endif |
03b1477f RE |
29928 | } |
29929 | ||
4d354d8b | 29930 | if (ARM_FEATURE_ZERO (selected_fpu)) |
03b1477f | 29931 | { |
4d354d8b TP |
29932 | if (!no_cpu_selected ()) |
29933 | selected_fpu = fpu_default; | |
03b1477f | 29934 | else |
4d354d8b | 29935 | selected_fpu = fpu_arch_fpa; |
03b1477f RE |
29936 | } |
29937 | ||
ee065d83 | 29938 | #ifdef CPU_DEFAULT |
4d354d8b | 29939 | if (ARM_FEATURE_ZERO (selected_arch)) |
ee065d83 | 29940 | { |
4d354d8b TP |
29941 | selected_arch = cpu_default; |
29942 | selected_cpu = selected_arch; | |
ee065d83 | 29943 | } |
4d354d8b | 29944 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
e74cfd16 | 29945 | #else |
4d354d8b TP |
29946 | /* Autodection of feature mode: allow all features in cpu_variant but leave |
29947 | selected_cpu unset. It will be set in aeabi_set_public_attributes () | |
29948 | after all instruction have been processed and we can decide what CPU | |
29949 | should be selected. */ | |
29950 | if (ARM_FEATURE_ZERO (selected_arch)) | |
29951 | ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu); | |
ee065d83 | 29952 | else |
4d354d8b | 29953 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
ee065d83 | 29954 | #endif |
03b1477f | 29955 | |
3e9e4fcf JB |
29956 | autoselect_thumb_from_cpu_variant (); |
29957 | ||
e74cfd16 | 29958 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 29959 | |
f17c130b | 29960 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 29961 | { |
7cc69913 NC |
29962 | unsigned int flags = 0; |
29963 | ||
29964 | #if defined OBJ_ELF | |
29965 | flags = meabi_flags; | |
d507cf36 PB |
29966 | |
29967 | switch (meabi_flags) | |
33a392fb | 29968 | { |
d507cf36 | 29969 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 29970 | #endif |
d507cf36 PB |
29971 | /* Set the flags in the private structure. */ |
29972 | if (uses_apcs_26) flags |= F_APCS26; | |
29973 | if (support_interwork) flags |= F_INTERWORK; | |
29974 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 29975 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 29976 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
29977 | flags |= F_SOFT_FLOAT; |
29978 | ||
d507cf36 PB |
29979 | switch (mfloat_abi_opt) |
29980 | { | |
29981 | case ARM_FLOAT_ABI_SOFT: | |
29982 | case ARM_FLOAT_ABI_SOFTFP: | |
29983 | flags |= F_SOFT_FLOAT; | |
29984 | break; | |
33a392fb | 29985 | |
d507cf36 PB |
29986 | case ARM_FLOAT_ABI_HARD: |
29987 | if (flags & F_SOFT_FLOAT) | |
29988 | as_bad (_("hard-float conflicts with specified fpu")); | |
29989 | break; | |
29990 | } | |
03b1477f | 29991 | |
e74cfd16 PB |
29992 | /* Using pure-endian doubles (even if soft-float). */ |
29993 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 29994 | flags |= F_VFP_FLOAT; |
f17c130b | 29995 | |
fde78edd | 29996 | #if defined OBJ_ELF |
e74cfd16 | 29997 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 29998 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
29999 | break; |
30000 | ||
8cb51566 | 30001 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 30002 | case EF_ARM_EABI_VER5: |
c19d1205 | 30003 | /* No additional flags to set. */ |
d507cf36 PB |
30004 | break; |
30005 | ||
30006 | default: | |
30007 | abort (); | |
30008 | } | |
7cc69913 | 30009 | #endif |
b99bd4ef NC |
30010 | bfd_set_private_flags (stdoutput, flags); |
30011 | ||
30012 | /* We have run out flags in the COFF header to encode the | |
30013 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 30014 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
30015 | if (atpcs) |
30016 | { | |
30017 | asection * sec; | |
30018 | ||
30019 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
30020 | ||
30021 | if (sec != NULL) | |
30022 | { | |
fd361982 AM |
30023 | bfd_set_section_flags (sec, SEC_READONLY | SEC_DEBUGGING); |
30024 | bfd_set_section_size (sec, 0); | |
b99bd4ef NC |
30025 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); |
30026 | } | |
30027 | } | |
7cc69913 | 30028 | } |
f17c130b | 30029 | #endif |
b99bd4ef NC |
30030 | |
30031 | /* Record the CPU type as well. */ | |
2d447fca JM |
30032 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)) |
30033 | mach = bfd_mach_arm_iWMMXt2; | |
30034 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) | |
e16bb312 | 30035 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 30036 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 30037 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 30038 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 30039 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 30040 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 30041 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 30042 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 30043 | { |
e74cfd16 | 30044 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
30045 | mach = bfd_mach_arm_5T; |
30046 | else | |
30047 | mach = bfd_mach_arm_5; | |
30048 | } | |
e74cfd16 | 30049 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 30050 | { |
e74cfd16 | 30051 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
30052 | mach = bfd_mach_arm_4T; |
30053 | else | |
30054 | mach = bfd_mach_arm_4; | |
30055 | } | |
e74cfd16 | 30056 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 30057 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
30058 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
30059 | mach = bfd_mach_arm_3; | |
30060 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
30061 | mach = bfd_mach_arm_2a; | |
30062 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
30063 | mach = bfd_mach_arm_2; | |
30064 | else | |
30065 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
30066 | |
30067 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
30068 | } | |
30069 | ||
c19d1205 | 30070 | /* Command line processing. */ |
b99bd4ef | 30071 | |
c19d1205 ZW |
30072 | /* md_parse_option |
30073 | Invocation line includes a switch not recognized by the base assembler. | |
30074 | See if it's a processor-specific option. | |
b99bd4ef | 30075 | |
c19d1205 ZW |
30076 | This routine is somewhat complicated by the need for backwards |
30077 | compatibility (since older releases of gcc can't be changed). | |
30078 | The new options try to make the interface as compatible as | |
30079 | possible with GCC. | |
b99bd4ef | 30080 | |
c19d1205 | 30081 | New options (supported) are: |
b99bd4ef | 30082 | |
c19d1205 ZW |
30083 | -mcpu=<cpu name> Assemble for selected processor |
30084 | -march=<architecture name> Assemble for selected architecture | |
30085 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
30086 | -EB/-mbig-endian Big-endian | |
30087 | -EL/-mlittle-endian Little-endian | |
30088 | -k Generate PIC code | |
30089 | -mthumb Start in Thumb mode | |
30090 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 30091 | |
278df34e | 30092 | -m[no-]warn-deprecated Warn about deprecated features |
8b2d793c | 30093 | -m[no-]warn-syms Warn when symbols match instructions |
267bf995 | 30094 | |
c19d1205 | 30095 | For now we will also provide support for: |
b99bd4ef | 30096 | |
c19d1205 ZW |
30097 | -mapcs-32 32-bit Program counter |
30098 | -mapcs-26 26-bit Program counter | |
30099 | -macps-float Floats passed in FP registers | |
30100 | -mapcs-reentrant Reentrant code | |
30101 | -matpcs | |
30102 | (sometime these will probably be replaced with -mapcs=<list of options> | |
30103 | and -matpcs=<list of options>) | |
b99bd4ef | 30104 | |
c19d1205 ZW |
30105 | The remaining options are only supported for back-wards compatibility. |
30106 | Cpu variants, the arm part is optional: | |
30107 | -m[arm]1 Currently not supported. | |
30108 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
30109 | -m[arm]3 Arm 3 processor | |
30110 | -m[arm]6[xx], Arm 6 processors | |
30111 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
30112 | -m[arm]8[10] Arm 8 processors | |
30113 | -m[arm]9[20][tdmi] Arm 9 processors | |
30114 | -mstrongarm[110[0]] StrongARM processors | |
30115 | -mxscale XScale processors | |
30116 | -m[arm]v[2345[t[e]]] Arm architectures | |
30117 | -mall All (except the ARM1) | |
30118 | FP variants: | |
30119 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
30120 | -mfpe-old (No float load/store multiples) | |
30121 | -mvfpxd VFP Single precision | |
30122 | -mvfp All VFP | |
30123 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 30124 | |
c19d1205 ZW |
30125 | The following CPU names are recognized: |
30126 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
30127 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
30128 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
30129 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
30130 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
30131 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
30132 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 30133 | |
c19d1205 | 30134 | */ |
b99bd4ef | 30135 | |
c19d1205 | 30136 | const char * md_shortopts = "m:k"; |
b99bd4ef | 30137 | |
c19d1205 ZW |
30138 | #ifdef ARM_BI_ENDIAN |
30139 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
30140 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 30141 | #else |
c19d1205 ZW |
30142 | #if TARGET_BYTES_BIG_ENDIAN |
30143 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 30144 | #else |
c19d1205 ZW |
30145 | #define OPTION_EL (OPTION_MD_BASE + 1) |
30146 | #endif | |
b99bd4ef | 30147 | #endif |
845b51d6 | 30148 | #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2) |
18a20338 | 30149 | #define OPTION_FDPIC (OPTION_MD_BASE + 3) |
b99bd4ef | 30150 | |
c19d1205 | 30151 | struct option md_longopts[] = |
b99bd4ef | 30152 | { |
c19d1205 ZW |
30153 | #ifdef OPTION_EB |
30154 | {"EB", no_argument, NULL, OPTION_EB}, | |
30155 | #endif | |
30156 | #ifdef OPTION_EL | |
30157 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 30158 | #endif |
845b51d6 | 30159 | {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX}, |
18a20338 CL |
30160 | #ifdef OBJ_ELF |
30161 | {"fdpic", no_argument, NULL, OPTION_FDPIC}, | |
30162 | #endif | |
c19d1205 ZW |
30163 | {NULL, no_argument, NULL, 0} |
30164 | }; | |
b99bd4ef | 30165 | |
c19d1205 | 30166 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 30167 | |
c19d1205 | 30168 | struct arm_option_table |
b99bd4ef | 30169 | { |
0198d5e6 TC |
30170 | const char * option; /* Option name to match. */ |
30171 | const char * help; /* Help information. */ | |
30172 | int * var; /* Variable to change. */ | |
30173 | int value; /* What to change it to. */ | |
30174 | const char * deprecated; /* If non-null, print this message. */ | |
c19d1205 | 30175 | }; |
b99bd4ef | 30176 | |
c19d1205 ZW |
30177 | struct arm_option_table arm_opts[] = |
30178 | { | |
30179 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
30180 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
30181 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
30182 | &support_interwork, 1, NULL}, | |
30183 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
30184 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
30185 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
30186 | 1, NULL}, | |
30187 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
30188 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
30189 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
30190 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
30191 | NULL}, | |
b99bd4ef | 30192 | |
c19d1205 ZW |
30193 | /* These are recognized by the assembler, but have no affect on code. */ |
30194 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
30195 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
278df34e NS |
30196 | |
30197 | {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL}, | |
30198 | {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"), | |
30199 | &warn_on_deprecated, 0, NULL}, | |
8b2d793c NC |
30200 | {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL}, |
30201 | {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL}, | |
e74cfd16 PB |
30202 | {NULL, NULL, NULL, 0, NULL} |
30203 | }; | |
30204 | ||
30205 | struct arm_legacy_option_table | |
30206 | { | |
0198d5e6 TC |
30207 | const char * option; /* Option name to match. */ |
30208 | const arm_feature_set ** var; /* Variable to change. */ | |
30209 | const arm_feature_set value; /* What to change it to. */ | |
30210 | const char * deprecated; /* If non-null, print this message. */ | |
e74cfd16 | 30211 | }; |
b99bd4ef | 30212 | |
e74cfd16 PB |
30213 | const struct arm_legacy_option_table arm_legacy_opts[] = |
30214 | { | |
c19d1205 ZW |
30215 | /* DON'T add any new processors to this list -- we want the whole list |
30216 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
30217 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
30218 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
30219 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
30220 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
30221 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
30222 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
30223 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
30224 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
30225 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
30226 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
30227 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
30228 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
30229 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
30230 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
30231 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
30232 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
30233 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
30234 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
30235 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
30236 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
30237 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
30238 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
30239 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
30240 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
30241 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
30242 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
30243 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
30244 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
30245 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
30246 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
30247 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
30248 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
30249 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
30250 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
30251 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
30252 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
30253 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
30254 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
30255 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
30256 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
30257 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
30258 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
30259 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
30260 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
30261 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
30262 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
30263 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
30264 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
30265 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
30266 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
30267 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
30268 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
30269 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
30270 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
30271 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
30272 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
30273 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
30274 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
30275 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
30276 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
30277 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
30278 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
30279 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
30280 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
30281 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
30282 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
30283 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
30284 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
30285 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
30286 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 30287 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 30288 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 30289 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 30290 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 30291 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
30292 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
30293 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
30294 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 30295 | |
c19d1205 | 30296 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
30297 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
30298 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
30299 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
30300 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
30301 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
30302 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
30303 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
30304 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
30305 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
30306 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
30307 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
30308 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
30309 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
30310 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
30311 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
30312 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
30313 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
30314 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 30315 | |
c19d1205 | 30316 | /* Floating point variants -- don't add any more to this list either. */ |
0198d5e6 TC |
30317 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
30318 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
30319 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
30320 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 30321 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 30322 | |
e74cfd16 | 30323 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 30324 | }; |
7ed4c4c5 | 30325 | |
c19d1205 | 30326 | struct arm_cpu_option_table |
7ed4c4c5 | 30327 | { |
0198d5e6 TC |
30328 | const char * name; |
30329 | size_t name_len; | |
30330 | const arm_feature_set value; | |
30331 | const arm_feature_set ext; | |
c19d1205 ZW |
30332 | /* For some CPUs we assume an FPU unless the user explicitly sets |
30333 | -mfpu=... */ | |
0198d5e6 | 30334 | const arm_feature_set default_fpu; |
ee065d83 PB |
30335 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
30336 | case. */ | |
0198d5e6 | 30337 | const char * canonical_name; |
c19d1205 | 30338 | }; |
7ed4c4c5 | 30339 | |
c19d1205 ZW |
30340 | /* This list should, at a minimum, contain all the cpu names |
30341 | recognized by GCC. */ | |
996b5569 | 30342 | #define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN } |
0198d5e6 | 30343 | |
e74cfd16 | 30344 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 30345 | { |
996b5569 TP |
30346 | ARM_CPU_OPT ("all", NULL, ARM_ANY, |
30347 | ARM_ARCH_NONE, | |
30348 | FPU_ARCH_FPA), | |
30349 | ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1, | |
30350 | ARM_ARCH_NONE, | |
30351 | FPU_ARCH_FPA), | |
30352 | ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2, | |
30353 | ARM_ARCH_NONE, | |
30354 | FPU_ARCH_FPA), | |
30355 | ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S, | |
30356 | ARM_ARCH_NONE, | |
30357 | FPU_ARCH_FPA), | |
30358 | ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S, | |
30359 | ARM_ARCH_NONE, | |
30360 | FPU_ARCH_FPA), | |
30361 | ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3, | |
30362 | ARM_ARCH_NONE, | |
30363 | FPU_ARCH_FPA), | |
30364 | ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3, | |
30365 | ARM_ARCH_NONE, | |
30366 | FPU_ARCH_FPA), | |
30367 | ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3, | |
30368 | ARM_ARCH_NONE, | |
30369 | FPU_ARCH_FPA), | |
30370 | ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3, | |
30371 | ARM_ARCH_NONE, | |
30372 | FPU_ARCH_FPA), | |
30373 | ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3, | |
30374 | ARM_ARCH_NONE, | |
30375 | FPU_ARCH_FPA), | |
30376 | ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3, | |
30377 | ARM_ARCH_NONE, | |
30378 | FPU_ARCH_FPA), | |
30379 | ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M, | |
30380 | ARM_ARCH_NONE, | |
30381 | FPU_ARCH_FPA), | |
30382 | ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3, | |
30383 | ARM_ARCH_NONE, | |
30384 | FPU_ARCH_FPA), | |
30385 | ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M, | |
30386 | ARM_ARCH_NONE, | |
30387 | FPU_ARCH_FPA), | |
30388 | ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3, | |
30389 | ARM_ARCH_NONE, | |
30390 | FPU_ARCH_FPA), | |
30391 | ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M, | |
30392 | ARM_ARCH_NONE, | |
30393 | FPU_ARCH_FPA), | |
30394 | ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3, | |
30395 | ARM_ARCH_NONE, | |
30396 | FPU_ARCH_FPA), | |
30397 | ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3, | |
30398 | ARM_ARCH_NONE, | |
30399 | FPU_ARCH_FPA), | |
30400 | ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3, | |
30401 | ARM_ARCH_NONE, | |
30402 | FPU_ARCH_FPA), | |
30403 | ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3, | |
30404 | ARM_ARCH_NONE, | |
30405 | FPU_ARCH_FPA), | |
30406 | ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T, | |
30407 | ARM_ARCH_NONE, | |
30408 | FPU_ARCH_FPA), | |
30409 | ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3, | |
30410 | ARM_ARCH_NONE, | |
30411 | FPU_ARCH_FPA), | |
30412 | ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T, | |
30413 | ARM_ARCH_NONE, | |
30414 | FPU_ARCH_FPA), | |
30415 | ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T, | |
30416 | ARM_ARCH_NONE, | |
30417 | FPU_ARCH_FPA), | |
30418 | ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3, | |
30419 | ARM_ARCH_NONE, | |
30420 | FPU_ARCH_FPA), | |
30421 | ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3, | |
30422 | ARM_ARCH_NONE, | |
30423 | FPU_ARCH_FPA), | |
30424 | ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3, | |
30425 | ARM_ARCH_NONE, | |
30426 | FPU_ARCH_FPA), | |
30427 | ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3, | |
30428 | ARM_ARCH_NONE, | |
30429 | FPU_ARCH_FPA), | |
30430 | ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T, | |
30431 | ARM_ARCH_NONE, | |
30432 | FPU_ARCH_FPA), | |
30433 | ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T, | |
30434 | ARM_ARCH_NONE, | |
30435 | FPU_ARCH_FPA), | |
30436 | ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T, | |
30437 | ARM_ARCH_NONE, | |
30438 | FPU_ARCH_FPA), | |
30439 | ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4, | |
30440 | ARM_ARCH_NONE, | |
30441 | FPU_ARCH_FPA), | |
30442 | ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4, | |
30443 | ARM_ARCH_NONE, | |
30444 | FPU_ARCH_FPA), | |
30445 | ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4, | |
30446 | ARM_ARCH_NONE, | |
30447 | FPU_ARCH_FPA), | |
30448 | ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4, | |
30449 | ARM_ARCH_NONE, | |
30450 | FPU_ARCH_FPA), | |
30451 | ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4, | |
30452 | ARM_ARCH_NONE, | |
30453 | FPU_ARCH_FPA), | |
30454 | ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4, | |
30455 | ARM_ARCH_NONE, | |
30456 | FPU_ARCH_FPA), | |
30457 | ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4, | |
30458 | ARM_ARCH_NONE, | |
30459 | FPU_ARCH_FPA), | |
30460 | ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T, | |
30461 | ARM_ARCH_NONE, | |
30462 | FPU_ARCH_FPA), | |
30463 | ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T, | |
30464 | ARM_ARCH_NONE, | |
30465 | FPU_ARCH_FPA), | |
30466 | ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T, | |
30467 | ARM_ARCH_NONE, | |
30468 | FPU_ARCH_FPA), | |
30469 | ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T, | |
30470 | ARM_ARCH_NONE, | |
30471 | FPU_ARCH_FPA), | |
30472 | ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T, | |
30473 | ARM_ARCH_NONE, | |
30474 | FPU_ARCH_FPA), | |
30475 | ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T, | |
30476 | ARM_ARCH_NONE, | |
30477 | FPU_ARCH_FPA), | |
30478 | ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4, | |
30479 | ARM_ARCH_NONE, | |
30480 | FPU_ARCH_FPA), | |
30481 | ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4, | |
30482 | ARM_ARCH_NONE, | |
30483 | FPU_ARCH_FPA), | |
30484 | ||
c19d1205 ZW |
30485 | /* For V5 or later processors we default to using VFP; but the user |
30486 | should really set the FPU type explicitly. */ | |
996b5569 TP |
30487 | ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP, |
30488 | ARM_ARCH_NONE, | |
30489 | FPU_ARCH_VFP_V2), | |
30490 | ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE, | |
30491 | ARM_ARCH_NONE, | |
30492 | FPU_ARCH_VFP_V2), | |
30493 | ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ, | |
30494 | ARM_ARCH_NONE, | |
30495 | FPU_ARCH_VFP_V2), | |
30496 | ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ, | |
30497 | ARM_ARCH_NONE, | |
30498 | FPU_ARCH_VFP_V2), | |
30499 | ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ, | |
30500 | ARM_ARCH_NONE, | |
30501 | FPU_ARCH_VFP_V2), | |
30502 | ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP, | |
30503 | ARM_ARCH_NONE, | |
30504 | FPU_ARCH_VFP_V2), | |
30505 | ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE, | |
30506 | ARM_ARCH_NONE, | |
30507 | FPU_ARCH_VFP_V2), | |
30508 | ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE, | |
30509 | ARM_ARCH_NONE, | |
30510 | FPU_ARCH_VFP_V2), | |
30511 | ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP, | |
30512 | ARM_ARCH_NONE, | |
30513 | FPU_ARCH_VFP_V2), | |
30514 | ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE, | |
30515 | ARM_ARCH_NONE, | |
30516 | FPU_ARCH_VFP_V2), | |
30517 | ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE, | |
30518 | ARM_ARCH_NONE, | |
30519 | FPU_ARCH_VFP_V2), | |
30520 | ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE, | |
30521 | ARM_ARCH_NONE, | |
30522 | FPU_ARCH_VFP_V2), | |
30523 | ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T, | |
30524 | ARM_ARCH_NONE, | |
30525 | FPU_ARCH_VFP_V1), | |
30526 | ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T, | |
30527 | ARM_ARCH_NONE, | |
30528 | FPU_ARCH_VFP_V1), | |
30529 | ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE, | |
30530 | ARM_ARCH_NONE, | |
30531 | FPU_ARCH_VFP_V2), | |
30532 | ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE, | |
30533 | ARM_ARCH_NONE, | |
30534 | FPU_ARCH_VFP_V2), | |
30535 | ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T, | |
30536 | ARM_ARCH_NONE, | |
30537 | FPU_ARCH_VFP_V1), | |
30538 | ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE, | |
30539 | ARM_ARCH_NONE, | |
30540 | FPU_ARCH_VFP_V2), | |
30541 | ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE, | |
30542 | ARM_ARCH_NONE, | |
30543 | FPU_ARCH_VFP_V2), | |
30544 | ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ, | |
30545 | ARM_ARCH_NONE, | |
30546 | FPU_ARCH_VFP_V2), | |
30547 | ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ, | |
30548 | ARM_ARCH_NONE, | |
30549 | FPU_ARCH_VFP_V2), | |
30550 | ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE, | |
30551 | ARM_ARCH_NONE, | |
30552 | FPU_ARCH_VFP_V2), | |
30553 | ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE, | |
30554 | ARM_ARCH_NONE, | |
30555 | FPU_ARCH_VFP_V2), | |
30556 | ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE, | |
30557 | ARM_ARCH_NONE, | |
30558 | FPU_ARCH_VFP_V2), | |
30559 | ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE, | |
30560 | ARM_ARCH_NONE, | |
30561 | FPU_ARCH_VFP_V2), | |
30562 | ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE, | |
30563 | ARM_ARCH_NONE, | |
30564 | FPU_ARCH_VFP_V2), | |
30565 | ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6, | |
30566 | ARM_ARCH_NONE, | |
30567 | FPU_NONE), | |
30568 | ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6, | |
30569 | ARM_ARCH_NONE, | |
30570 | FPU_NONE), | |
30571 | ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6, | |
30572 | ARM_ARCH_NONE, | |
30573 | FPU_ARCH_VFP_V2), | |
30574 | ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6, | |
30575 | ARM_ARCH_NONE, | |
30576 | FPU_ARCH_VFP_V2), | |
30577 | ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K, | |
30578 | ARM_ARCH_NONE, | |
30579 | FPU_ARCH_VFP_V2), | |
30580 | ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K, | |
30581 | ARM_ARCH_NONE, | |
30582 | FPU_NONE), | |
30583 | ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2, | |
30584 | ARM_ARCH_NONE, | |
30585 | FPU_NONE), | |
30586 | ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2, | |
30587 | ARM_ARCH_NONE, | |
30588 | FPU_ARCH_VFP_V2), | |
30589 | ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ, | |
30590 | ARM_ARCH_NONE, | |
30591 | FPU_NONE), | |
30592 | ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ, | |
30593 | ARM_ARCH_NONE, | |
30594 | FPU_ARCH_VFP_V2), | |
30595 | ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A, | |
30596 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC), | |
30597 | FPU_NONE), | |
30598 | ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE, | |
30599 | ARM_ARCH_NONE, | |
30600 | FPU_ARCH_NEON_VFP_V4), | |
30601 | ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A, | |
30602 | ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), | |
30603 | ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)), | |
30604 | ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A, | |
30605 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC), | |
30606 | ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)), | |
30607 | ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE, | |
30608 | ARM_ARCH_NONE, | |
30609 | FPU_ARCH_NEON_VFP_V4), | |
30610 | ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE, | |
30611 | ARM_ARCH_NONE, | |
30612 | FPU_ARCH_NEON_VFP_V4), | |
30613 | ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE, | |
30614 | ARM_ARCH_NONE, | |
30615 | FPU_ARCH_NEON_VFP_V4), | |
30616 | ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A, | |
30617 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
30618 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
30619 | ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A, | |
30620 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
30621 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
30622 | ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A, | |
30623 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
30624 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
15a7695f JG |
30625 | ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A, |
30626 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
0198d5e6 | 30627 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), |
996b5569 TP |
30628 | ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A, |
30629 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
30630 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
30631 | ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A, | |
30632 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
30633 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
30634 | ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A, | |
30635 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
30636 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
15a7695f JG |
30637 | ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A, |
30638 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
0198d5e6 | 30639 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), |
7ebd1359 | 30640 | ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A, |
30641 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
30642 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), | |
0535e5d7 DZ |
30643 | ARM_CPU_OPT ("cortex-a76ae", "Cortex-A76AE", ARM_ARCH_V8_2A, |
30644 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
30645 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), | |
30646 | ARM_CPU_OPT ("cortex-a77", "Cortex-A77", ARM_ARCH_V8_2A, | |
30647 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
30648 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), | |
ef8df4ca KT |
30649 | ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A, |
30650 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
30651 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), | |
996b5569 TP |
30652 | ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R, |
30653 | ARM_ARCH_NONE, | |
30654 | FPU_NONE), | |
30655 | ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R, | |
30656 | ARM_ARCH_NONE, | |
30657 | FPU_ARCH_VFP_V3D16), | |
30658 | ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R, | |
30659 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV), | |
30660 | FPU_NONE), | |
30661 | ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R, | |
30662 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV), | |
30663 | FPU_ARCH_VFP_V3D16), | |
30664 | ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R, | |
30665 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV), | |
30666 | FPU_ARCH_VFP_V3D16), | |
0cda1e19 TP |
30667 | ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R, |
30668 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
30669 | FPU_ARCH_NEON_VFP_ARMV8), | |
0535e5d7 DZ |
30670 | ARM_CPU_OPT ("cortex-m35p", "Cortex-M35P", ARM_ARCH_V8M_MAIN, |
30671 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), | |
30672 | FPU_NONE), | |
996b5569 TP |
30673 | ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN, |
30674 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), | |
30675 | FPU_NONE), | |
30676 | ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE, | |
30677 | ARM_ARCH_NONE, | |
30678 | FPU_NONE), | |
30679 | ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM, | |
30680 | ARM_ARCH_NONE, | |
30681 | FPU_NONE), | |
30682 | ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM, | |
30683 | ARM_ARCH_NONE, | |
30684 | FPU_NONE), | |
30685 | ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M, | |
30686 | ARM_ARCH_NONE, | |
30687 | FPU_NONE), | |
30688 | ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM, | |
30689 | ARM_ARCH_NONE, | |
30690 | FPU_NONE), | |
30691 | ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM, | |
30692 | ARM_ARCH_NONE, | |
30693 | FPU_NONE), | |
30694 | ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM, | |
30695 | ARM_ARCH_NONE, | |
30696 | FPU_NONE), | |
30697 | ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A, | |
30698 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
30699 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
83f43c83 KT |
30700 | ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A, |
30701 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
30702 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), | |
c19d1205 | 30703 | /* ??? XSCALE is really an architecture. */ |
996b5569 TP |
30704 | ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE, |
30705 | ARM_ARCH_NONE, | |
30706 | FPU_ARCH_VFP_V2), | |
30707 | ||
c19d1205 | 30708 | /* ??? iwmmxt is not a processor. */ |
996b5569 TP |
30709 | ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT, |
30710 | ARM_ARCH_NONE, | |
30711 | FPU_ARCH_VFP_V2), | |
30712 | ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2, | |
30713 | ARM_ARCH_NONE, | |
30714 | FPU_ARCH_VFP_V2), | |
30715 | ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE, | |
30716 | ARM_ARCH_NONE, | |
30717 | FPU_ARCH_VFP_V2), | |
30718 | ||
0198d5e6 | 30719 | /* Maverick. */ |
996b5569 TP |
30720 | ARM_CPU_OPT ("ep9312", "ARM920T", |
30721 | ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), | |
30722 | ARM_ARCH_NONE, FPU_ARCH_MAVERICK), | |
30723 | ||
da4339ed | 30724 | /* Marvell processors. */ |
996b5569 TP |
30725 | ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A, |
30726 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC), | |
30727 | FPU_ARCH_VFP_V3D16), | |
30728 | ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A, | |
30729 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC), | |
30730 | FPU_ARCH_NEON_VFP_V4), | |
da4339ed | 30731 | |
996b5569 TP |
30732 | /* APM X-Gene family. */ |
30733 | ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A, | |
30734 | ARM_ARCH_NONE, | |
30735 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
30736 | ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A, | |
30737 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
30738 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
30739 | ||
30740 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL } | |
c19d1205 | 30741 | }; |
f3bad469 | 30742 | #undef ARM_CPU_OPT |
7ed4c4c5 | 30743 | |
34ef62f4 AV |
30744 | struct arm_ext_table |
30745 | { | |
30746 | const char * name; | |
30747 | size_t name_len; | |
30748 | const arm_feature_set merge; | |
30749 | const arm_feature_set clear; | |
30750 | }; | |
30751 | ||
c19d1205 | 30752 | struct arm_arch_option_table |
7ed4c4c5 | 30753 | { |
34ef62f4 AV |
30754 | const char * name; |
30755 | size_t name_len; | |
30756 | const arm_feature_set value; | |
30757 | const arm_feature_set default_fpu; | |
30758 | const struct arm_ext_table * ext_table; | |
30759 | }; | |
30760 | ||
30761 | /* Used to add support for +E and +noE extension. */ | |
30762 | #define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C } | |
30763 | /* Used to add support for a +E extension. */ | |
30764 | #define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE } | |
30765 | /* Used to add support for a +noE extension. */ | |
30766 | #define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C } | |
30767 | ||
30768 | #define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \ | |
30769 | ~0 & ~FPU_ENDIAN_PURE) | |
30770 | ||
30771 | static const struct arm_ext_table armv5te_ext_table[] = | |
30772 | { | |
30773 | ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP), | |
30774 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
30775 | }; | |
30776 | ||
30777 | static const struct arm_ext_table armv7_ext_table[] = | |
30778 | { | |
30779 | ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP), | |
30780 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
30781 | }; | |
30782 | ||
30783 | static const struct arm_ext_table armv7ve_ext_table[] = | |
30784 | { | |
30785 | ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP), | |
30786 | ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), | |
30787 | ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3), | |
30788 | ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16), | |
30789 | ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16), | |
30790 | ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */ | |
30791 | ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4), | |
30792 | ||
30793 | ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4, | |
30794 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)), | |
30795 | ||
30796 | /* Aliases for +simd. */ | |
30797 | ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4), | |
30798 | ||
30799 | ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1), | |
30800 | ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1), | |
30801 | ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16), | |
30802 | ||
30803 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
30804 | }; | |
30805 | ||
30806 | static const struct arm_ext_table armv7a_ext_table[] = | |
30807 | { | |
30808 | ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP), | |
30809 | ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */ | |
30810 | ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3), | |
30811 | ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16), | |
30812 | ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16), | |
30813 | ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), | |
30814 | ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4), | |
30815 | ||
30816 | ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1, | |
30817 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)), | |
30818 | ||
30819 | /* Aliases for +simd. */ | |
30820 | ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1), | |
30821 | ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1), | |
30822 | ||
30823 | ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16), | |
30824 | ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4), | |
30825 | ||
30826 | ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)), | |
30827 | ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)), | |
30828 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
30829 | }; | |
30830 | ||
30831 | static const struct arm_ext_table armv7r_ext_table[] = | |
30832 | { | |
30833 | ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD), | |
30834 | ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */ | |
30835 | ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP), | |
30836 | ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */ | |
30837 | ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16), | |
30838 | ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16), | |
30839 | ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), | |
30840 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)), | |
30841 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
30842 | }; | |
30843 | ||
30844 | static const struct arm_ext_table armv7em_ext_table[] = | |
30845 | { | |
30846 | ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP), | |
30847 | /* Alias for +fp, used to be known as fpv4-sp-d16. */ | |
30848 | ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16), | |
30849 | ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16), | |
30850 | ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16), | |
30851 | ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16), | |
30852 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
30853 | }; | |
30854 | ||
30855 | static const struct arm_ext_table armv8a_ext_table[] = | |
30856 | { | |
30857 | ARM_ADD ("crc", ARCH_CRC_ARMV8), | |
30858 | ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8), | |
30859 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, | |
30860 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
30861 | ||
30862 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
30863 | should use the +simd option to turn on FP. */ | |
30864 | ARM_REMOVE ("fp", ALL_FP), | |
30865 | ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)), | |
30866 | ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)), | |
30867 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
30868 | }; | |
30869 | ||
30870 | ||
30871 | static const struct arm_ext_table armv81a_ext_table[] = | |
30872 | { | |
30873 | ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1), | |
30874 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1, | |
30875 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
30876 | ||
30877 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
30878 | should use the +simd option to turn on FP. */ | |
30879 | ARM_REMOVE ("fp", ALL_FP), | |
30880 | ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)), | |
30881 | ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)), | |
30882 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
30883 | }; | |
30884 | ||
30885 | static const struct arm_ext_table armv82a_ext_table[] = | |
30886 | { | |
30887 | ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1), | |
30888 | ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16), | |
30889 | ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML), | |
30890 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1, | |
30891 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
30892 | ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8), | |
30893 | ||
30894 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
30895 | should use the +simd option to turn on FP. */ | |
30896 | ARM_REMOVE ("fp", ALL_FP), | |
30897 | ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)), | |
30898 | ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)), | |
30899 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
30900 | }; | |
30901 | ||
30902 | static const struct arm_ext_table armv84a_ext_table[] = | |
30903 | { | |
30904 | ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8), | |
30905 | ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML), | |
30906 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4, | |
30907 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
30908 | ||
30909 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
30910 | should use the +simd option to turn on FP. */ | |
30911 | ARM_REMOVE ("fp", ALL_FP), | |
30912 | ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)), | |
30913 | ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)), | |
30914 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
30915 | }; | |
30916 | ||
30917 | static const struct arm_ext_table armv85a_ext_table[] = | |
30918 | { | |
30919 | ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8), | |
30920 | ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML), | |
30921 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4, | |
30922 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
30923 | ||
30924 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
30925 | should use the +simd option to turn on FP. */ | |
30926 | ARM_REMOVE ("fp", ALL_FP), | |
30927 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
30928 | }; | |
30929 | ||
30930 | static const struct arm_ext_table armv8m_main_ext_table[] = | |
30931 | { | |
30932 | ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), | |
30933 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)), | |
30934 | ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP), | |
30935 | ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16), | |
30936 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
30937 | }; | |
30938 | ||
e0991585 AV |
30939 | static const struct arm_ext_table armv8_1m_main_ext_table[] = |
30940 | { | |
30941 | ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), | |
30942 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)), | |
30943 | ARM_EXT ("fp", | |
30944 | ARM_FEATURE (0, ARM_EXT2_FP16_INST, | |
30945 | FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA), | |
30946 | ALL_FP), | |
30947 | ARM_ADD ("fp.dp", | |
30948 | ARM_FEATURE (0, ARM_EXT2_FP16_INST, | |
30949 | FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)), | |
a7ad558c AV |
30950 | ARM_EXT ("mve", ARM_FEATURE_COPROC (FPU_MVE), |
30951 | ARM_FEATURE_COPROC (FPU_MVE | FPU_MVE_FP)), | |
30952 | ARM_ADD ("mve.fp", | |
30953 | ARM_FEATURE (0, ARM_EXT2_FP16_INST, | |
30954 | FPU_MVE | FPU_MVE_FP | FPU_VFP_V5_SP_D16 | | |
30955 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)), | |
e0991585 AV |
30956 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } |
30957 | }; | |
30958 | ||
34ef62f4 AV |
30959 | static const struct arm_ext_table armv8r_ext_table[] = |
30960 | { | |
30961 | ARM_ADD ("crc", ARCH_CRC_ARMV8), | |
30962 | ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8), | |
30963 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, | |
30964 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
30965 | ARM_REMOVE ("fp", ALL_FP), | |
30966 | ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16), | |
30967 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
c19d1205 | 30968 | }; |
7ed4c4c5 | 30969 | |
c19d1205 ZW |
30970 | /* This list should, at a minimum, contain all the architecture names |
30971 | recognized by GCC. */ | |
34ef62f4 AV |
30972 | #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL } |
30973 | #define ARM_ARCH_OPT2(N, V, DF, ext) \ | |
30974 | { N, sizeof (N) - 1, V, DF, ext##_ext_table } | |
0198d5e6 | 30975 | |
e74cfd16 | 30976 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 | 30977 | { |
497d849d TP |
30978 | ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA), |
30979 | ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA), | |
30980 | ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA), | |
30981 | ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA), | |
30982 | ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA), | |
30983 | ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA), | |
30984 | ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA), | |
30985 | ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA), | |
30986 | ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA), | |
30987 | ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA), | |
30988 | ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA), | |
30989 | ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP), | |
30990 | ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP), | |
30991 | ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP), | |
34ef62f4 AV |
30992 | ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te), |
30993 | ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te), | |
30994 | ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te), | |
30995 | ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te), | |
30996 | ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te), | |
30997 | ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te), | |
30998 | ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te), | |
f33026a9 MW |
30999 | /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is |
31000 | kept to preserve existing behaviour. */ | |
34ef62f4 AV |
31001 | ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te), |
31002 | ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te), | |
31003 | ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te), | |
31004 | ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te), | |
31005 | ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te), | |
f33026a9 MW |
31006 | /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is |
31007 | kept to preserve existing behaviour. */ | |
34ef62f4 AV |
31008 | ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te), |
31009 | ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te), | |
497d849d TP |
31010 | ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP), |
31011 | ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP), | |
34ef62f4 | 31012 | ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7), |
c450d570 PB |
31013 | /* The official spelling of the ARMv7 profile variants is the dashed form. |
31014 | Accept the non-dashed form for compatibility with old toolchains. */ | |
34ef62f4 AV |
31015 | ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a), |
31016 | ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve), | |
31017 | ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r), | |
497d849d | 31018 | ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP), |
34ef62f4 AV |
31019 | ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a), |
31020 | ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r), | |
497d849d | 31021 | ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP), |
34ef62f4 | 31022 | ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em), |
497d849d | 31023 | ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP), |
34ef62f4 AV |
31024 | ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP, |
31025 | armv8m_main), | |
e0991585 AV |
31026 | ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP, |
31027 | armv8_1m_main), | |
34ef62f4 AV |
31028 | ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a), |
31029 | ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a), | |
31030 | ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a), | |
31031 | ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a), | |
31032 | ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r), | |
31033 | ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a), | |
31034 | ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a), | |
497d849d TP |
31035 | ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP), |
31036 | ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP), | |
31037 | ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP), | |
34ef62f4 | 31038 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL } |
c19d1205 | 31039 | }; |
f3bad469 | 31040 | #undef ARM_ARCH_OPT |
7ed4c4c5 | 31041 | |
69133863 | 31042 | /* ISA extensions in the co-processor and main instruction set space. */ |
0198d5e6 | 31043 | |
69133863 | 31044 | struct arm_option_extension_value_table |
c19d1205 | 31045 | { |
0198d5e6 TC |
31046 | const char * name; |
31047 | size_t name_len; | |
31048 | const arm_feature_set merge_value; | |
31049 | const arm_feature_set clear_value; | |
d942732e TP |
31050 | /* List of architectures for which an extension is available. ARM_ARCH_NONE |
31051 | indicates that an extension is available for all architectures while | |
31052 | ARM_ANY marks an empty entry. */ | |
0198d5e6 | 31053 | const arm_feature_set allowed_archs[2]; |
c19d1205 | 31054 | }; |
7ed4c4c5 | 31055 | |
0198d5e6 TC |
31056 | /* The following table must be in alphabetical order with a NULL last entry. */ |
31057 | ||
d942732e TP |
31058 | #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } } |
31059 | #define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} } | |
0198d5e6 | 31060 | |
34ef62f4 AV |
31061 | /* DEPRECATED: Refrain from using this table to add any new extensions, instead |
31062 | use the context sensitive approach using arm_ext_table's. */ | |
69133863 | 31063 | static const struct arm_option_extension_value_table arm_extensions[] = |
c19d1205 | 31064 | { |
823d2571 TG |
31065 | ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8), |
31066 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
bca38921 | 31067 | ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
823d2571 TG |
31068 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8), |
31069 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
c604a79a JW |
31070 | ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8, |
31071 | ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD), | |
31072 | ARM_ARCH_V8_2A), | |
15afaa63 TP |
31073 | ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), |
31074 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), | |
31075 | ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)), | |
823d2571 TG |
31076 | ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8), |
31077 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
b8ec4e87 JW |
31078 | ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), |
31079 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
31080 | ARM_ARCH_V8_2A), | |
01f48020 TC |
31081 | ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST |
31082 | | ARM_EXT2_FP16_FML), | |
31083 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | |
31084 | | ARM_EXT2_FP16_FML), | |
31085 | ARM_ARCH_V8_2A), | |
d942732e | 31086 | ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), |
823d2571 | 31087 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), |
d942732e TP |
31088 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A), |
31089 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)), | |
3d030cdb TP |
31090 | /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of |
31091 | Thumb divide instruction. Due to this having the same name as the | |
31092 | previous entry, this will be ignored when doing command-line parsing and | |
31093 | only considered by build attribute selection code. */ | |
31094 | ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV), | |
31095 | ARM_FEATURE_CORE_LOW (ARM_EXT_DIV), | |
31096 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7)), | |
823d2571 | 31097 | ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), |
d942732e | 31098 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE), |
823d2571 | 31099 | ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), |
d942732e | 31100 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE), |
823d2571 | 31101 | ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), |
d942732e TP |
31102 | ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE), |
31103 | ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP), | |
823d2571 | 31104 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP), |
d942732e TP |
31105 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A), |
31106 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)), | |
823d2571 TG |
31107 | ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS), |
31108 | ARM_FEATURE_CORE_LOW (ARM_EXT_OS), | |
31109 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)), | |
ddfded2f MW |
31110 | ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN), |
31111 | ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0), | |
ced40572 | 31112 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)), |
dad0c3bf SD |
31113 | ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES), |
31114 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES), | |
31115 | ARM_ARCH_V8A), | |
4d1464f2 MW |
31116 | ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS), |
31117 | ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0), | |
ced40572 | 31118 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)), |
643afb90 MW |
31119 | ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1, |
31120 | ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA), | |
ced40572 | 31121 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)), |
7fadb25d SD |
31122 | ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB), |
31123 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB), | |
31124 | ARM_ARCH_V8A), | |
d942732e | 31125 | ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), |
823d2571 | 31126 | ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), |
d942732e TP |
31127 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6K), |
31128 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)), | |
643afb90 MW |
31129 | ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8, |
31130 | ARM_FEATURE_COPROC (FPU_NEON_ARMV8), | |
31131 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
823d2571 TG |
31132 | ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV |
31133 | | ARM_EXT_DIV), | |
31134 | ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT), | |
31135 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)), | |
31136 | ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), | |
d942732e TP |
31137 | ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE), |
31138 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } } | |
69133863 | 31139 | }; |
f3bad469 | 31140 | #undef ARM_EXT_OPT |
69133863 MGD |
31141 | |
31142 | /* ISA floating-point and Advanced SIMD extensions. */ | |
31143 | struct arm_option_fpu_value_table | |
31144 | { | |
0198d5e6 TC |
31145 | const char * name; |
31146 | const arm_feature_set value; | |
c19d1205 | 31147 | }; |
7ed4c4c5 | 31148 | |
c19d1205 ZW |
31149 | /* This list should, at a minimum, contain all the fpu names |
31150 | recognized by GCC. */ | |
69133863 | 31151 | static const struct arm_option_fpu_value_table arm_fpus[] = |
c19d1205 ZW |
31152 | { |
31153 | {"softfpa", FPU_NONE}, | |
31154 | {"fpe", FPU_ARCH_FPE}, | |
31155 | {"fpe2", FPU_ARCH_FPE}, | |
31156 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
31157 | {"fpa", FPU_ARCH_FPA}, | |
31158 | {"fpa10", FPU_ARCH_FPA}, | |
31159 | {"fpa11", FPU_ARCH_FPA}, | |
31160 | {"arm7500fe", FPU_ARCH_FPA}, | |
31161 | {"softvfp", FPU_ARCH_VFP}, | |
31162 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
31163 | {"vfp", FPU_ARCH_VFP_V2}, | |
31164 | {"vfp9", FPU_ARCH_VFP_V2}, | |
d5e0ba9c | 31165 | {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */ |
c19d1205 ZW |
31166 | {"vfp10", FPU_ARCH_VFP_V2}, |
31167 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
31168 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
b1cc4aeb PB |
31169 | {"vfpv2", FPU_ARCH_VFP_V2}, |
31170 | {"vfpv3", FPU_ARCH_VFP_V3}, | |
62f3b8c8 | 31171 | {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16}, |
b1cc4aeb | 31172 | {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, |
62f3b8c8 PB |
31173 | {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16}, |
31174 | {"vfpv3xd", FPU_ARCH_VFP_V3xD}, | |
31175 | {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16}, | |
c19d1205 ZW |
31176 | {"arm1020t", FPU_ARCH_VFP_V1}, |
31177 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
d5e0ba9c | 31178 | {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */ |
c19d1205 ZW |
31179 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, |
31180 | {"maverick", FPU_ARCH_MAVERICK}, | |
d5e0ba9c | 31181 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
d3375ddd | 31182 | {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
8e79c3df | 31183 | {"neon-fp16", FPU_ARCH_NEON_FP16}, |
62f3b8c8 PB |
31184 | {"vfpv4", FPU_ARCH_VFP_V4}, |
31185 | {"vfpv4-d16", FPU_ARCH_VFP_V4D16}, | |
ada65aa3 | 31186 | {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16}, |
a715796b TG |
31187 | {"fpv5-d16", FPU_ARCH_VFP_V5D16}, |
31188 | {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16}, | |
62f3b8c8 | 31189 | {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4}, |
bca38921 MGD |
31190 | {"fp-armv8", FPU_ARCH_VFP_ARMV8}, |
31191 | {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8}, | |
31192 | {"crypto-neon-fp-armv8", | |
31193 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8}, | |
d6b4b13e | 31194 | {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1}, |
081e4c7d MW |
31195 | {"crypto-neon-fp-armv8.1", |
31196 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1}, | |
e74cfd16 PB |
31197 | {NULL, ARM_ARCH_NONE} |
31198 | }; | |
31199 | ||
31200 | struct arm_option_value_table | |
31201 | { | |
e0471c16 | 31202 | const char *name; |
e74cfd16 | 31203 | long value; |
c19d1205 | 31204 | }; |
7ed4c4c5 | 31205 | |
e74cfd16 | 31206 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
31207 | { |
31208 | {"hard", ARM_FLOAT_ABI_HARD}, | |
31209 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
31210 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 31211 | {NULL, 0} |
c19d1205 | 31212 | }; |
7ed4c4c5 | 31213 | |
c19d1205 | 31214 | #ifdef OBJ_ELF |
3a4a14e9 | 31215 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 31216 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
31217 | { |
31218 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
31219 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 31220 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 31221 | {NULL, 0} |
c19d1205 ZW |
31222 | }; |
31223 | #endif | |
7ed4c4c5 | 31224 | |
c19d1205 ZW |
31225 | struct arm_long_option_table |
31226 | { | |
0198d5e6 | 31227 | const char * option; /* Substring to match. */ |
e0471c16 | 31228 | const char * help; /* Help information. */ |
17b9d67d | 31229 | int (* func) (const char * subopt); /* Function to decode sub-option. */ |
e0471c16 | 31230 | const char * deprecated; /* If non-null, print this message. */ |
c19d1205 | 31231 | }; |
7ed4c4c5 | 31232 | |
c921be7d | 31233 | static bfd_boolean |
c168ce07 | 31234 | arm_parse_extension (const char *str, const arm_feature_set *opt_set, |
34ef62f4 AV |
31235 | arm_feature_set *ext_set, |
31236 | const struct arm_ext_table *ext_table) | |
7ed4c4c5 | 31237 | { |
69133863 | 31238 | /* We insist on extensions being specified in alphabetical order, and with |
fa94de6b RM |
31239 | extensions being added before being removed. We achieve this by having |
31240 | the global ARM_EXTENSIONS table in alphabetical order, and using the | |
69133863 | 31241 | ADDING_VALUE variable to indicate whether we are adding an extension (1) |
fa94de6b | 31242 | or removing it (0) and only allowing it to change in the order |
69133863 MGD |
31243 | -1 -> 1 -> 0. */ |
31244 | const struct arm_option_extension_value_table * opt = NULL; | |
d942732e | 31245 | const arm_feature_set arm_any = ARM_ANY; |
69133863 MGD |
31246 | int adding_value = -1; |
31247 | ||
c19d1205 | 31248 | while (str != NULL && *str != 0) |
7ed4c4c5 | 31249 | { |
82b8a785 | 31250 | const char *ext; |
f3bad469 | 31251 | size_t len; |
7ed4c4c5 | 31252 | |
c19d1205 ZW |
31253 | if (*str != '+') |
31254 | { | |
31255 | as_bad (_("invalid architectural extension")); | |
c921be7d | 31256 | return FALSE; |
c19d1205 | 31257 | } |
7ed4c4c5 | 31258 | |
c19d1205 ZW |
31259 | str++; |
31260 | ext = strchr (str, '+'); | |
7ed4c4c5 | 31261 | |
c19d1205 | 31262 | if (ext != NULL) |
f3bad469 | 31263 | len = ext - str; |
c19d1205 | 31264 | else |
f3bad469 | 31265 | len = strlen (str); |
7ed4c4c5 | 31266 | |
f3bad469 | 31267 | if (len >= 2 && strncmp (str, "no", 2) == 0) |
69133863 MGD |
31268 | { |
31269 | if (adding_value != 0) | |
31270 | { | |
31271 | adding_value = 0; | |
31272 | opt = arm_extensions; | |
31273 | } | |
31274 | ||
f3bad469 | 31275 | len -= 2; |
69133863 MGD |
31276 | str += 2; |
31277 | } | |
f3bad469 | 31278 | else if (len > 0) |
69133863 MGD |
31279 | { |
31280 | if (adding_value == -1) | |
31281 | { | |
31282 | adding_value = 1; | |
31283 | opt = arm_extensions; | |
31284 | } | |
31285 | else if (adding_value != 1) | |
31286 | { | |
31287 | as_bad (_("must specify extensions to add before specifying " | |
31288 | "those to remove")); | |
31289 | return FALSE; | |
31290 | } | |
31291 | } | |
31292 | ||
f3bad469 | 31293 | if (len == 0) |
c19d1205 ZW |
31294 | { |
31295 | as_bad (_("missing architectural extension")); | |
c921be7d | 31296 | return FALSE; |
c19d1205 | 31297 | } |
7ed4c4c5 | 31298 | |
69133863 MGD |
31299 | gas_assert (adding_value != -1); |
31300 | gas_assert (opt != NULL); | |
31301 | ||
34ef62f4 AV |
31302 | if (ext_table != NULL) |
31303 | { | |
31304 | const struct arm_ext_table * ext_opt = ext_table; | |
31305 | bfd_boolean found = FALSE; | |
31306 | for (; ext_opt->name != NULL; ext_opt++) | |
31307 | if (ext_opt->name_len == len | |
31308 | && strncmp (ext_opt->name, str, len) == 0) | |
31309 | { | |
31310 | if (adding_value) | |
31311 | { | |
31312 | if (ARM_FEATURE_ZERO (ext_opt->merge)) | |
31313 | /* TODO: Option not supported. When we remove the | |
31314 | legacy table this case should error out. */ | |
31315 | continue; | |
31316 | ||
31317 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge); | |
31318 | } | |
31319 | else | |
31320 | { | |
31321 | if (ARM_FEATURE_ZERO (ext_opt->clear)) | |
31322 | /* TODO: Option not supported. When we remove the | |
31323 | legacy table this case should error out. */ | |
31324 | continue; | |
31325 | ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear); | |
31326 | } | |
31327 | found = TRUE; | |
31328 | break; | |
31329 | } | |
31330 | if (found) | |
31331 | { | |
31332 | str = ext; | |
31333 | continue; | |
31334 | } | |
31335 | } | |
31336 | ||
69133863 MGD |
31337 | /* Scan over the options table trying to find an exact match. */ |
31338 | for (; opt->name != NULL; opt++) | |
f3bad469 | 31339 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 31340 | { |
d942732e TP |
31341 | int i, nb_allowed_archs = |
31342 | sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]); | |
69133863 | 31343 | /* Check we can apply the extension to this architecture. */ |
d942732e TP |
31344 | for (i = 0; i < nb_allowed_archs; i++) |
31345 | { | |
31346 | /* Empty entry. */ | |
31347 | if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any)) | |
31348 | continue; | |
c168ce07 | 31349 | if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set)) |
d942732e TP |
31350 | break; |
31351 | } | |
31352 | if (i == nb_allowed_archs) | |
69133863 MGD |
31353 | { |
31354 | as_bad (_("extension does not apply to the base architecture")); | |
31355 | return FALSE; | |
31356 | } | |
31357 | ||
31358 | /* Add or remove the extension. */ | |
31359 | if (adding_value) | |
4d354d8b | 31360 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value); |
69133863 | 31361 | else |
4d354d8b | 31362 | ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value); |
69133863 | 31363 | |
3d030cdb TP |
31364 | /* Allowing Thumb division instructions for ARMv7 in autodetection |
31365 | rely on this break so that duplicate extensions (extensions | |
31366 | with the same name as a previous extension in the list) are not | |
31367 | considered for command-line parsing. */ | |
c19d1205 ZW |
31368 | break; |
31369 | } | |
7ed4c4c5 | 31370 | |
c19d1205 ZW |
31371 | if (opt->name == NULL) |
31372 | { | |
69133863 MGD |
31373 | /* Did we fail to find an extension because it wasn't specified in |
31374 | alphabetical order, or because it does not exist? */ | |
31375 | ||
31376 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
f3bad469 | 31377 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
69133863 MGD |
31378 | break; |
31379 | ||
31380 | if (opt->name == NULL) | |
31381 | as_bad (_("unknown architectural extension `%s'"), str); | |
31382 | else | |
31383 | as_bad (_("architectural extensions must be specified in " | |
31384 | "alphabetical order")); | |
31385 | ||
c921be7d | 31386 | return FALSE; |
c19d1205 | 31387 | } |
69133863 MGD |
31388 | else |
31389 | { | |
31390 | /* We should skip the extension we've just matched the next time | |
31391 | round. */ | |
31392 | opt++; | |
31393 | } | |
7ed4c4c5 | 31394 | |
c19d1205 ZW |
31395 | str = ext; |
31396 | }; | |
7ed4c4c5 | 31397 | |
c921be7d | 31398 | return TRUE; |
c19d1205 | 31399 | } |
7ed4c4c5 | 31400 | |
5312fe52 BW |
31401 | static bfd_boolean |
31402 | arm_parse_fp16_opt (const char *str) | |
31403 | { | |
31404 | if (strcasecmp (str, "ieee") == 0) | |
31405 | fp16_format = ARM_FP16_FORMAT_IEEE; | |
31406 | else if (strcasecmp (str, "alternative") == 0) | |
31407 | fp16_format = ARM_FP16_FORMAT_ALTERNATIVE; | |
31408 | else | |
31409 | { | |
31410 | as_bad (_("unrecognised float16 format \"%s\""), str); | |
31411 | return FALSE; | |
31412 | } | |
31413 | ||
31414 | return TRUE; | |
31415 | } | |
31416 | ||
c921be7d | 31417 | static bfd_boolean |
17b9d67d | 31418 | arm_parse_cpu (const char *str) |
7ed4c4c5 | 31419 | { |
f3bad469 | 31420 | const struct arm_cpu_option_table *opt; |
82b8a785 | 31421 | const char *ext = strchr (str, '+'); |
f3bad469 | 31422 | size_t len; |
7ed4c4c5 | 31423 | |
c19d1205 | 31424 | if (ext != NULL) |
f3bad469 | 31425 | len = ext - str; |
7ed4c4c5 | 31426 | else |
f3bad469 | 31427 | len = strlen (str); |
7ed4c4c5 | 31428 | |
f3bad469 | 31429 | if (len == 0) |
7ed4c4c5 | 31430 | { |
c19d1205 | 31431 | as_bad (_("missing cpu name `%s'"), str); |
c921be7d | 31432 | return FALSE; |
7ed4c4c5 NC |
31433 | } |
31434 | ||
c19d1205 | 31435 | for (opt = arm_cpus; opt->name != NULL; opt++) |
f3bad469 | 31436 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 31437 | { |
c168ce07 | 31438 | mcpu_cpu_opt = &opt->value; |
4d354d8b TP |
31439 | if (mcpu_ext_opt == NULL) |
31440 | mcpu_ext_opt = XNEW (arm_feature_set); | |
31441 | *mcpu_ext_opt = opt->ext; | |
e74cfd16 | 31442 | mcpu_fpu_opt = &opt->default_fpu; |
ee065d83 | 31443 | if (opt->canonical_name) |
ef8e6722 JW |
31444 | { |
31445 | gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name)); | |
31446 | strcpy (selected_cpu_name, opt->canonical_name); | |
31447 | } | |
ee065d83 PB |
31448 | else |
31449 | { | |
f3bad469 | 31450 | size_t i; |
c921be7d | 31451 | |
ef8e6722 JW |
31452 | if (len >= sizeof selected_cpu_name) |
31453 | len = (sizeof selected_cpu_name) - 1; | |
31454 | ||
f3bad469 | 31455 | for (i = 0; i < len; i++) |
ee065d83 PB |
31456 | selected_cpu_name[i] = TOUPPER (opt->name[i]); |
31457 | selected_cpu_name[i] = 0; | |
31458 | } | |
7ed4c4c5 | 31459 | |
c19d1205 | 31460 | if (ext != NULL) |
34ef62f4 | 31461 | return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL); |
7ed4c4c5 | 31462 | |
c921be7d | 31463 | return TRUE; |
c19d1205 | 31464 | } |
7ed4c4c5 | 31465 | |
c19d1205 | 31466 | as_bad (_("unknown cpu `%s'"), str); |
c921be7d | 31467 | return FALSE; |
7ed4c4c5 NC |
31468 | } |
31469 | ||
c921be7d | 31470 | static bfd_boolean |
17b9d67d | 31471 | arm_parse_arch (const char *str) |
7ed4c4c5 | 31472 | { |
e74cfd16 | 31473 | const struct arm_arch_option_table *opt; |
82b8a785 | 31474 | const char *ext = strchr (str, '+'); |
f3bad469 | 31475 | size_t len; |
7ed4c4c5 | 31476 | |
c19d1205 | 31477 | if (ext != NULL) |
f3bad469 | 31478 | len = ext - str; |
7ed4c4c5 | 31479 | else |
f3bad469 | 31480 | len = strlen (str); |
7ed4c4c5 | 31481 | |
f3bad469 | 31482 | if (len == 0) |
7ed4c4c5 | 31483 | { |
c19d1205 | 31484 | as_bad (_("missing architecture name `%s'"), str); |
c921be7d | 31485 | return FALSE; |
7ed4c4c5 NC |
31486 | } |
31487 | ||
c19d1205 | 31488 | for (opt = arm_archs; opt->name != NULL; opt++) |
f3bad469 | 31489 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 31490 | { |
e74cfd16 | 31491 | march_cpu_opt = &opt->value; |
4d354d8b TP |
31492 | if (march_ext_opt == NULL) |
31493 | march_ext_opt = XNEW (arm_feature_set); | |
31494 | *march_ext_opt = arm_arch_none; | |
e74cfd16 | 31495 | march_fpu_opt = &opt->default_fpu; |
5f4273c7 | 31496 | strcpy (selected_cpu_name, opt->name); |
7ed4c4c5 | 31497 | |
c19d1205 | 31498 | if (ext != NULL) |
34ef62f4 AV |
31499 | return arm_parse_extension (ext, march_cpu_opt, march_ext_opt, |
31500 | opt->ext_table); | |
7ed4c4c5 | 31501 | |
c921be7d | 31502 | return TRUE; |
c19d1205 ZW |
31503 | } |
31504 | ||
31505 | as_bad (_("unknown architecture `%s'\n"), str); | |
c921be7d | 31506 | return FALSE; |
7ed4c4c5 | 31507 | } |
eb043451 | 31508 | |
c921be7d | 31509 | static bfd_boolean |
17b9d67d | 31510 | arm_parse_fpu (const char * str) |
c19d1205 | 31511 | { |
69133863 | 31512 | const struct arm_option_fpu_value_table * opt; |
b99bd4ef | 31513 | |
c19d1205 ZW |
31514 | for (opt = arm_fpus; opt->name != NULL; opt++) |
31515 | if (streq (opt->name, str)) | |
31516 | { | |
e74cfd16 | 31517 | mfpu_opt = &opt->value; |
c921be7d | 31518 | return TRUE; |
c19d1205 | 31519 | } |
b99bd4ef | 31520 | |
c19d1205 | 31521 | as_bad (_("unknown floating point format `%s'\n"), str); |
c921be7d | 31522 | return FALSE; |
c19d1205 ZW |
31523 | } |
31524 | ||
c921be7d | 31525 | static bfd_boolean |
17b9d67d | 31526 | arm_parse_float_abi (const char * str) |
b99bd4ef | 31527 | { |
e74cfd16 | 31528 | const struct arm_option_value_table * opt; |
b99bd4ef | 31529 | |
c19d1205 ZW |
31530 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
31531 | if (streq (opt->name, str)) | |
31532 | { | |
31533 | mfloat_abi_opt = opt->value; | |
c921be7d | 31534 | return TRUE; |
c19d1205 | 31535 | } |
cc8a6dd0 | 31536 | |
c19d1205 | 31537 | as_bad (_("unknown floating point abi `%s'\n"), str); |
c921be7d | 31538 | return FALSE; |
c19d1205 | 31539 | } |
b99bd4ef | 31540 | |
c19d1205 | 31541 | #ifdef OBJ_ELF |
c921be7d | 31542 | static bfd_boolean |
17b9d67d | 31543 | arm_parse_eabi (const char * str) |
c19d1205 | 31544 | { |
e74cfd16 | 31545 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 31546 | |
c19d1205 ZW |
31547 | for (opt = arm_eabis; opt->name != NULL; opt++) |
31548 | if (streq (opt->name, str)) | |
31549 | { | |
31550 | meabi_flags = opt->value; | |
c921be7d | 31551 | return TRUE; |
c19d1205 ZW |
31552 | } |
31553 | as_bad (_("unknown EABI `%s'\n"), str); | |
c921be7d | 31554 | return FALSE; |
c19d1205 ZW |
31555 | } |
31556 | #endif | |
cc8a6dd0 | 31557 | |
c921be7d | 31558 | static bfd_boolean |
17b9d67d | 31559 | arm_parse_it_mode (const char * str) |
e07e6e58 | 31560 | { |
c921be7d | 31561 | bfd_boolean ret = TRUE; |
e07e6e58 NC |
31562 | |
31563 | if (streq ("arm", str)) | |
31564 | implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
31565 | else if (streq ("thumb", str)) | |
31566 | implicit_it_mode = IMPLICIT_IT_MODE_THUMB; | |
31567 | else if (streq ("always", str)) | |
31568 | implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS; | |
31569 | else if (streq ("never", str)) | |
31570 | implicit_it_mode = IMPLICIT_IT_MODE_NEVER; | |
31571 | else | |
31572 | { | |
31573 | as_bad (_("unknown implicit IT mode `%s', should be "\ | |
477330fc | 31574 | "arm, thumb, always, or never."), str); |
c921be7d | 31575 | ret = FALSE; |
e07e6e58 NC |
31576 | } |
31577 | ||
31578 | return ret; | |
31579 | } | |
31580 | ||
2e6976a8 | 31581 | static bfd_boolean |
17b9d67d | 31582 | arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED) |
2e6976a8 DG |
31583 | { |
31584 | codecomposer_syntax = TRUE; | |
31585 | arm_comment_chars[0] = ';'; | |
31586 | arm_line_separator_chars[0] = 0; | |
31587 | return TRUE; | |
31588 | } | |
31589 | ||
c19d1205 ZW |
31590 | struct arm_long_option_table arm_long_opts[] = |
31591 | { | |
31592 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
31593 | arm_parse_cpu, NULL}, | |
31594 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
31595 | arm_parse_arch, NULL}, | |
31596 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
31597 | arm_parse_fpu, NULL}, | |
31598 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
31599 | arm_parse_float_abi, NULL}, | |
31600 | #ifdef OBJ_ELF | |
7fac0536 | 31601 | {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"), |
c19d1205 ZW |
31602 | arm_parse_eabi, NULL}, |
31603 | #endif | |
e07e6e58 NC |
31604 | {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"), |
31605 | arm_parse_it_mode, NULL}, | |
2e6976a8 DG |
31606 | {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"), |
31607 | arm_ccs_mode, NULL}, | |
5312fe52 BW |
31608 | {"mfp16-format=", |
31609 | N_("[ieee|alternative]\n\ | |
31610 | set the encoding for half precision floating point " | |
31611 | "numbers to IEEE\n\ | |
31612 | or Arm alternative format."), | |
31613 | arm_parse_fp16_opt, NULL }, | |
c19d1205 ZW |
31614 | {NULL, NULL, 0, NULL} |
31615 | }; | |
cc8a6dd0 | 31616 | |
c19d1205 | 31617 | int |
17b9d67d | 31618 | md_parse_option (int c, const char * arg) |
c19d1205 ZW |
31619 | { |
31620 | struct arm_option_table *opt; | |
e74cfd16 | 31621 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 31622 | struct arm_long_option_table *lopt; |
b99bd4ef | 31623 | |
c19d1205 | 31624 | switch (c) |
b99bd4ef | 31625 | { |
c19d1205 ZW |
31626 | #ifdef OPTION_EB |
31627 | case OPTION_EB: | |
31628 | target_big_endian = 1; | |
31629 | break; | |
31630 | #endif | |
cc8a6dd0 | 31631 | |
c19d1205 ZW |
31632 | #ifdef OPTION_EL |
31633 | case OPTION_EL: | |
31634 | target_big_endian = 0; | |
31635 | break; | |
31636 | #endif | |
b99bd4ef | 31637 | |
845b51d6 PB |
31638 | case OPTION_FIX_V4BX: |
31639 | fix_v4bx = TRUE; | |
31640 | break; | |
31641 | ||
18a20338 CL |
31642 | #ifdef OBJ_ELF |
31643 | case OPTION_FDPIC: | |
31644 | arm_fdpic = TRUE; | |
31645 | break; | |
31646 | #endif /* OBJ_ELF */ | |
31647 | ||
c19d1205 ZW |
31648 | case 'a': |
31649 | /* Listing option. Just ignore these, we don't support additional | |
31650 | ones. */ | |
31651 | return 0; | |
b99bd4ef | 31652 | |
c19d1205 ZW |
31653 | default: |
31654 | for (opt = arm_opts; opt->option != NULL; opt++) | |
31655 | { | |
31656 | if (c == opt->option[0] | |
31657 | && ((arg == NULL && opt->option[1] == 0) | |
31658 | || streq (arg, opt->option + 1))) | |
31659 | { | |
c19d1205 | 31660 | /* If the option is deprecated, tell the user. */ |
278df34e | 31661 | if (warn_on_deprecated && opt->deprecated != NULL) |
c19d1205 ZW |
31662 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
31663 | arg ? arg : "", _(opt->deprecated)); | |
b99bd4ef | 31664 | |
c19d1205 ZW |
31665 | if (opt->var != NULL) |
31666 | *opt->var = opt->value; | |
cc8a6dd0 | 31667 | |
c19d1205 ZW |
31668 | return 1; |
31669 | } | |
31670 | } | |
b99bd4ef | 31671 | |
e74cfd16 PB |
31672 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
31673 | { | |
31674 | if (c == fopt->option[0] | |
31675 | && ((arg == NULL && fopt->option[1] == 0) | |
31676 | || streq (arg, fopt->option + 1))) | |
31677 | { | |
e74cfd16 | 31678 | /* If the option is deprecated, tell the user. */ |
278df34e | 31679 | if (warn_on_deprecated && fopt->deprecated != NULL) |
e74cfd16 PB |
31680 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
31681 | arg ? arg : "", _(fopt->deprecated)); | |
e74cfd16 PB |
31682 | |
31683 | if (fopt->var != NULL) | |
31684 | *fopt->var = &fopt->value; | |
31685 | ||
31686 | return 1; | |
31687 | } | |
31688 | } | |
31689 | ||
c19d1205 ZW |
31690 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
31691 | { | |
31692 | /* These options are expected to have an argument. */ | |
31693 | if (c == lopt->option[0] | |
31694 | && arg != NULL | |
31695 | && strncmp (arg, lopt->option + 1, | |
31696 | strlen (lopt->option + 1)) == 0) | |
31697 | { | |
c19d1205 | 31698 | /* If the option is deprecated, tell the user. */ |
278df34e | 31699 | if (warn_on_deprecated && lopt->deprecated != NULL) |
c19d1205 ZW |
31700 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, |
31701 | _(lopt->deprecated)); | |
b99bd4ef | 31702 | |
c19d1205 ZW |
31703 | /* Call the sup-option parser. */ |
31704 | return lopt->func (arg + strlen (lopt->option) - 1); | |
31705 | } | |
31706 | } | |
a737bd4d | 31707 | |
c19d1205 ZW |
31708 | return 0; |
31709 | } | |
a394c00f | 31710 | |
c19d1205 ZW |
31711 | return 1; |
31712 | } | |
a394c00f | 31713 | |
c19d1205 ZW |
31714 | void |
31715 | md_show_usage (FILE * fp) | |
a394c00f | 31716 | { |
c19d1205 ZW |
31717 | struct arm_option_table *opt; |
31718 | struct arm_long_option_table *lopt; | |
a394c00f | 31719 | |
c19d1205 | 31720 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 31721 | |
c19d1205 ZW |
31722 | for (opt = arm_opts; opt->option != NULL; opt++) |
31723 | if (opt->help != NULL) | |
31724 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 31725 | |
c19d1205 ZW |
31726 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
31727 | if (lopt->help != NULL) | |
31728 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 31729 | |
c19d1205 ZW |
31730 | #ifdef OPTION_EB |
31731 | fprintf (fp, _("\ | |
31732 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
31733 | #endif |
31734 | ||
c19d1205 ZW |
31735 | #ifdef OPTION_EL |
31736 | fprintf (fp, _("\ | |
31737 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 31738 | #endif |
845b51d6 PB |
31739 | |
31740 | fprintf (fp, _("\ | |
31741 | --fix-v4bx Allow BX in ARMv4 code\n")); | |
18a20338 CL |
31742 | |
31743 | #ifdef OBJ_ELF | |
31744 | fprintf (fp, _("\ | |
31745 | --fdpic generate an FDPIC object file\n")); | |
31746 | #endif /* OBJ_ELF */ | |
c19d1205 | 31747 | } |
ee065d83 | 31748 | |
ee065d83 | 31749 | #ifdef OBJ_ELF |
0198d5e6 | 31750 | |
62b3e311 PB |
31751 | typedef struct |
31752 | { | |
31753 | int val; | |
31754 | arm_feature_set flags; | |
31755 | } cpu_arch_ver_table; | |
31756 | ||
2c6b98ea TP |
31757 | /* Mapping from CPU features to EABI CPU arch values. Table must be sorted |
31758 | chronologically for architectures, with an exception for ARMv6-M and | |
31759 | ARMv6S-M due to legacy reasons. No new architecture should have a | |
31760 | special case. This allows for build attribute selection results to be | |
31761 | stable when new architectures are added. */ | |
62b3e311 PB |
31762 | static const cpu_arch_ver_table cpu_arch_ver[] = |
31763 | { | |
031254f2 AV |
31764 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1}, |
31765 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2}, | |
31766 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S}, | |
31767 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3}, | |
31768 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M}, | |
31769 | {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM}, | |
31770 | {TAG_CPU_ARCH_V4, ARM_ARCH_V4}, | |
31771 | {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM}, | |
31772 | {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T}, | |
31773 | {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM}, | |
31774 | {TAG_CPU_ARCH_V5T, ARM_ARCH_V5}, | |
31775 | {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM}, | |
31776 | {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T}, | |
31777 | {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP}, | |
31778 | {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE}, | |
31779 | {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ}, | |
31780 | {TAG_CPU_ARCH_V6, ARM_ARCH_V6}, | |
31781 | {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z}, | |
31782 | {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ}, | |
31783 | {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K}, | |
31784 | {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2}, | |
31785 | {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2}, | |
31786 | {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2}, | |
31787 | {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2}, | |
2c6b98ea TP |
31788 | |
31789 | /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as | |
31790 | always selected build attributes to match those of ARMv6-M | |
31791 | (resp. ARMv6S-M). However, due to these architectures being a strict | |
31792 | subset of ARMv7-M in terms of instructions available, ARMv7-M attributes | |
31793 | would be selected when fully respecting chronology of architectures. | |
31794 | It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and | |
31795 | move them before ARMv7 architectures. */ | |
031254f2 AV |
31796 | {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M}, |
31797 | {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM}, | |
31798 | ||
31799 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7}, | |
31800 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7A}, | |
31801 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7R}, | |
31802 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7M}, | |
31803 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE}, | |
31804 | {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM}, | |
31805 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8A}, | |
31806 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A}, | |
31807 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A}, | |
31808 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A}, | |
31809 | {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE}, | |
31810 | {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN}, | |
31811 | {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R}, | |
31812 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A}, | |
31813 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A}, | |
31814 | {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN}, | |
31815 | {-1, ARM_ARCH_NONE} | |
62b3e311 PB |
31816 | }; |
31817 | ||
ee3c0378 | 31818 | /* Set an attribute if it has not already been set by the user. */ |
0198d5e6 | 31819 | |
ee3c0378 AS |
31820 | static void |
31821 | aeabi_set_attribute_int (int tag, int value) | |
31822 | { | |
31823 | if (tag < 1 | |
31824 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
31825 | || !attributes_set_explicitly[tag]) | |
31826 | bfd_elf_add_proc_attr_int (stdoutput, tag, value); | |
31827 | } | |
31828 | ||
31829 | static void | |
31830 | aeabi_set_attribute_string (int tag, const char *value) | |
31831 | { | |
31832 | if (tag < 1 | |
31833 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
31834 | || !attributes_set_explicitly[tag]) | |
31835 | bfd_elf_add_proc_attr_string (stdoutput, tag, value); | |
31836 | } | |
31837 | ||
2c6b98ea TP |
31838 | /* Return whether features in the *NEEDED feature set are available via |
31839 | extensions for the architecture whose feature set is *ARCH_FSET. */ | |
0198d5e6 | 31840 | |
2c6b98ea TP |
31841 | static bfd_boolean |
31842 | have_ext_for_needed_feat_p (const arm_feature_set *arch_fset, | |
31843 | const arm_feature_set *needed) | |
31844 | { | |
31845 | int i, nb_allowed_archs; | |
31846 | arm_feature_set ext_fset; | |
31847 | const struct arm_option_extension_value_table *opt; | |
31848 | ||
31849 | ext_fset = arm_arch_none; | |
31850 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
31851 | { | |
31852 | /* Extension does not provide any feature we need. */ | |
31853 | if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value)) | |
31854 | continue; | |
31855 | ||
31856 | nb_allowed_archs = | |
31857 | sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]); | |
31858 | for (i = 0; i < nb_allowed_archs; i++) | |
31859 | { | |
31860 | /* Empty entry. */ | |
31861 | if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any)) | |
31862 | break; | |
31863 | ||
31864 | /* Extension is available, add it. */ | |
31865 | if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset)) | |
31866 | ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value); | |
31867 | } | |
31868 | } | |
31869 | ||
31870 | /* Can we enable all features in *needed? */ | |
31871 | return ARM_FSET_CPU_SUBSET (*needed, ext_fset); | |
31872 | } | |
31873 | ||
31874 | /* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for | |
31875 | a given architecture feature set *ARCH_EXT_FSET including extension feature | |
31876 | set *EXT_FSET. Selection logic used depend on EXACT_MATCH: | |
31877 | - if true, check for an exact match of the architecture modulo extensions; | |
31878 | - otherwise, select build attribute value of the first superset | |
31879 | architecture released so that results remains stable when new architectures | |
31880 | are added. | |
31881 | For -march/-mcpu=all the build attribute value of the most featureful | |
31882 | architecture is returned. Tag_CPU_arch_profile result is returned in | |
31883 | PROFILE. */ | |
0198d5e6 | 31884 | |
2c6b98ea TP |
31885 | static int |
31886 | get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset, | |
31887 | const arm_feature_set *ext_fset, | |
31888 | char *profile, int exact_match) | |
31889 | { | |
31890 | arm_feature_set arch_fset; | |
31891 | const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL; | |
31892 | ||
31893 | /* Select most featureful architecture with all its extensions if building | |
31894 | for -march=all as the feature sets used to set build attributes. */ | |
31895 | if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any)) | |
31896 | { | |
31897 | /* Force revisiting of decision for each new architecture. */ | |
031254f2 | 31898 | gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN); |
2c6b98ea TP |
31899 | *profile = 'A'; |
31900 | return TAG_CPU_ARCH_V8; | |
31901 | } | |
31902 | ||
31903 | ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset); | |
31904 | ||
31905 | for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++) | |
31906 | { | |
31907 | arm_feature_set known_arch_fset; | |
31908 | ||
31909 | ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any); | |
31910 | if (exact_match) | |
31911 | { | |
31912 | /* Base architecture match user-specified architecture and | |
31913 | extensions, eg. ARMv6S-M matching -march=armv6-m+os. */ | |
31914 | if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset)) | |
31915 | { | |
31916 | p_ver_ret = p_ver; | |
31917 | goto found; | |
31918 | } | |
31919 | /* Base architecture match user-specified architecture only | |
31920 | (eg. ARMv6-M in the same case as above). Record it in case we | |
31921 | find a match with above condition. */ | |
31922 | else if (p_ver_ret == NULL | |
31923 | && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset)) | |
31924 | p_ver_ret = p_ver; | |
31925 | } | |
31926 | else | |
31927 | { | |
31928 | ||
31929 | /* Architecture has all features wanted. */ | |
31930 | if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset)) | |
31931 | { | |
31932 | arm_feature_set added_fset; | |
31933 | ||
31934 | /* Compute features added by this architecture over the one | |
31935 | recorded in p_ver_ret. */ | |
31936 | if (p_ver_ret != NULL) | |
31937 | ARM_CLEAR_FEATURE (added_fset, known_arch_fset, | |
31938 | p_ver_ret->flags); | |
31939 | /* First architecture that match incl. with extensions, or the | |
31940 | only difference in features over the recorded match is | |
31941 | features that were optional and are now mandatory. */ | |
31942 | if (p_ver_ret == NULL | |
31943 | || ARM_FSET_CPU_SUBSET (added_fset, arch_fset)) | |
31944 | { | |
31945 | p_ver_ret = p_ver; | |
31946 | goto found; | |
31947 | } | |
31948 | } | |
31949 | else if (p_ver_ret == NULL) | |
31950 | { | |
31951 | arm_feature_set needed_ext_fset; | |
31952 | ||
31953 | ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset); | |
31954 | ||
31955 | /* Architecture has all features needed when using some | |
31956 | extensions. Record it and continue searching in case there | |
31957 | exist an architecture providing all needed features without | |
31958 | the need for extensions (eg. ARMv6S-M Vs ARMv6-M with | |
31959 | OS extension). */ | |
31960 | if (have_ext_for_needed_feat_p (&known_arch_fset, | |
31961 | &needed_ext_fset)) | |
31962 | p_ver_ret = p_ver; | |
31963 | } | |
31964 | } | |
31965 | } | |
31966 | ||
31967 | if (p_ver_ret == NULL) | |
31968 | return -1; | |
31969 | ||
31970 | found: | |
31971 | /* Tag_CPU_arch_profile. */ | |
31972 | if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a) | |
31973 | || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8) | |
31974 | || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics) | |
31975 | && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only))) | |
31976 | *profile = 'A'; | |
31977 | else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r)) | |
31978 | *profile = 'R'; | |
31979 | else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m)) | |
31980 | *profile = 'M'; | |
31981 | else | |
31982 | *profile = '\0'; | |
31983 | return p_ver_ret->val; | |
31984 | } | |
31985 | ||
ee065d83 | 31986 | /* Set the public EABI object attributes. */ |
0198d5e6 | 31987 | |
c168ce07 | 31988 | static void |
ee065d83 PB |
31989 | aeabi_set_public_attributes (void) |
31990 | { | |
b90d5ba0 | 31991 | char profile = '\0'; |
2c6b98ea | 31992 | int arch = -1; |
90ec0d68 | 31993 | int virt_sec = 0; |
bca38921 | 31994 | int fp16_optional = 0; |
2c6b98ea TP |
31995 | int skip_exact_match = 0; |
31996 | arm_feature_set flags, flags_arch, flags_ext; | |
ee065d83 | 31997 | |
54bab281 TP |
31998 | /* Autodetection mode, choose the architecture based the instructions |
31999 | actually used. */ | |
32000 | if (no_cpu_selected ()) | |
32001 | { | |
32002 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); | |
ddd7f988 | 32003 | |
54bab281 TP |
32004 | if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)) |
32005 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1); | |
ddd7f988 | 32006 | |
54bab281 TP |
32007 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any)) |
32008 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t); | |
ddd7f988 | 32009 | |
54bab281 | 32010 | /* Code run during relaxation relies on selected_cpu being set. */ |
4d354d8b TP |
32011 | ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any); |
32012 | flags_ext = arm_arch_none; | |
32013 | ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext); | |
32014 | selected_ext = flags_ext; | |
54bab281 TP |
32015 | selected_cpu = flags; |
32016 | } | |
32017 | /* Otherwise, choose the architecture based on the capabilities of the | |
32018 | requested cpu. */ | |
32019 | else | |
4d354d8b TP |
32020 | { |
32021 | ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext); | |
32022 | ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any); | |
32023 | flags_ext = selected_ext; | |
32024 | flags = selected_cpu; | |
32025 | } | |
32026 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu); | |
7f78eb34 | 32027 | |
ddd7f988 | 32028 | /* Allow the user to override the reported architecture. */ |
4d354d8b | 32029 | if (!ARM_FEATURE_ZERO (selected_object_arch)) |
7a1d4c38 | 32030 | { |
4d354d8b | 32031 | ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any); |
2c6b98ea | 32032 | flags_ext = arm_arch_none; |
7a1d4c38 | 32033 | } |
2c6b98ea | 32034 | else |
4d354d8b | 32035 | skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any); |
2c6b98ea TP |
32036 | |
32037 | /* When this function is run again after relaxation has happened there is no | |
32038 | way to determine whether an architecture or CPU was specified by the user: | |
32039 | - selected_cpu is set above for relaxation to work; | |
32040 | - march_cpu_opt is not set if only -mcpu or .cpu is used; | |
32041 | - mcpu_cpu_opt is set to arm_arch_any for autodetection. | |
32042 | Therefore, if not in -march=all case we first try an exact match and fall | |
32043 | back to autodetection. */ | |
32044 | if (!skip_exact_match) | |
32045 | arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1); | |
32046 | if (arch == -1) | |
32047 | arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0); | |
32048 | if (arch == -1) | |
32049 | as_bad (_("no architecture contains all the instructions used\n")); | |
9e3c6df6 | 32050 | |
ee065d83 PB |
32051 | /* Tag_CPU_name. */ |
32052 | if (selected_cpu_name[0]) | |
32053 | { | |
91d6fa6a | 32054 | char *q; |
ee065d83 | 32055 | |
91d6fa6a NC |
32056 | q = selected_cpu_name; |
32057 | if (strncmp (q, "armv", 4) == 0) | |
ee065d83 PB |
32058 | { |
32059 | int i; | |
5f4273c7 | 32060 | |
91d6fa6a NC |
32061 | q += 4; |
32062 | for (i = 0; q[i]; i++) | |
32063 | q[i] = TOUPPER (q[i]); | |
ee065d83 | 32064 | } |
91d6fa6a | 32065 | aeabi_set_attribute_string (Tag_CPU_name, q); |
ee065d83 | 32066 | } |
62f3b8c8 | 32067 | |
ee065d83 | 32068 | /* Tag_CPU_arch. */ |
ee3c0378 | 32069 | aeabi_set_attribute_int (Tag_CPU_arch, arch); |
62f3b8c8 | 32070 | |
62b3e311 | 32071 | /* Tag_CPU_arch_profile. */ |
69239280 MGD |
32072 | if (profile != '\0') |
32073 | aeabi_set_attribute_int (Tag_CPU_arch_profile, profile); | |
62f3b8c8 | 32074 | |
15afaa63 | 32075 | /* Tag_DSP_extension. */ |
4d354d8b | 32076 | if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp)) |
6c290d53 | 32077 | aeabi_set_attribute_int (Tag_DSP_extension, 1); |
15afaa63 | 32078 | |
2c6b98ea | 32079 | ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any); |
ee065d83 | 32080 | /* Tag_ARM_ISA_use. */ |
ee3c0378 | 32081 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1) |
2c6b98ea | 32082 | || ARM_FEATURE_ZERO (flags_arch)) |
ee3c0378 | 32083 | aeabi_set_attribute_int (Tag_ARM_ISA_use, 1); |
62f3b8c8 | 32084 | |
ee065d83 | 32085 | /* Tag_THUMB_ISA_use. */ |
ee3c0378 | 32086 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t) |
2c6b98ea | 32087 | || ARM_FEATURE_ZERO (flags_arch)) |
4ed7ed8d TP |
32088 | { |
32089 | int thumb_isa_use; | |
32090 | ||
32091 | if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) | |
16a1fa25 | 32092 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only)) |
4ed7ed8d TP |
32093 | thumb_isa_use = 3; |
32094 | else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2)) | |
32095 | thumb_isa_use = 2; | |
32096 | else | |
32097 | thumb_isa_use = 1; | |
32098 | aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use); | |
32099 | } | |
62f3b8c8 | 32100 | |
ee065d83 | 32101 | /* Tag_VFP_arch. */ |
a715796b TG |
32102 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd)) |
32103 | aeabi_set_attribute_int (Tag_VFP_arch, | |
32104 | ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32) | |
32105 | ? 7 : 8); | |
bca38921 | 32106 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma)) |
62f3b8c8 PB |
32107 | aeabi_set_attribute_int (Tag_VFP_arch, |
32108 | ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32) | |
32109 | ? 5 : 6); | |
32110 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)) | |
bca38921 MGD |
32111 | { |
32112 | fp16_optional = 1; | |
32113 | aeabi_set_attribute_int (Tag_VFP_arch, 3); | |
32114 | } | |
ada65aa3 | 32115 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd)) |
bca38921 MGD |
32116 | { |
32117 | aeabi_set_attribute_int (Tag_VFP_arch, 4); | |
32118 | fp16_optional = 1; | |
32119 | } | |
ee3c0378 AS |
32120 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2)) |
32121 | aeabi_set_attribute_int (Tag_VFP_arch, 2); | |
32122 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1) | |
477330fc | 32123 | || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)) |
ee3c0378 | 32124 | aeabi_set_attribute_int (Tag_VFP_arch, 1); |
62f3b8c8 | 32125 | |
4547cb56 NC |
32126 | /* Tag_ABI_HardFP_use. */ |
32127 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd) | |
32128 | && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)) | |
32129 | aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1); | |
32130 | ||
ee065d83 | 32131 | /* Tag_WMMX_arch. */ |
ee3c0378 AS |
32132 | if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2)) |
32133 | aeabi_set_attribute_int (Tag_WMMX_arch, 2); | |
32134 | else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt)) | |
32135 | aeabi_set_attribute_int (Tag_WMMX_arch, 1); | |
62f3b8c8 | 32136 | |
ee3c0378 | 32137 | /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */ |
9411fd44 MW |
32138 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1)) |
32139 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4); | |
32140 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8)) | |
bca38921 MGD |
32141 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3); |
32142 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1)) | |
32143 | { | |
32144 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)) | |
32145 | { | |
32146 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2); | |
32147 | } | |
32148 | else | |
32149 | { | |
32150 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1); | |
32151 | fp16_optional = 1; | |
32152 | } | |
32153 | } | |
fa94de6b | 32154 | |
a7ad558c AV |
32155 | if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext)) |
32156 | aeabi_set_attribute_int (Tag_MVE_arch, 2); | |
32157 | else if (ARM_CPU_HAS_FEATURE (flags, mve_ext)) | |
32158 | aeabi_set_attribute_int (Tag_MVE_arch, 1); | |
32159 | ||
ee3c0378 | 32160 | /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */ |
bca38921 | 32161 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional) |
ee3c0378 | 32162 | aeabi_set_attribute_int (Tag_VFP_HP_extension, 1); |
4547cb56 | 32163 | |
69239280 MGD |
32164 | /* Tag_DIV_use. |
32165 | ||
32166 | We set Tag_DIV_use to two when integer divide instructions have been used | |
32167 | in ARM state, or when Thumb integer divide instructions have been used, | |
32168 | but we have no architecture profile set, nor have we any ARM instructions. | |
32169 | ||
4ed7ed8d TP |
32170 | For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied |
32171 | by the base architecture. | |
bca38921 | 32172 | |
69239280 | 32173 | For new architectures we will have to check these tests. */ |
031254f2 | 32174 | gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN); |
4ed7ed8d TP |
32175 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) |
32176 | || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m)) | |
bca38921 MGD |
32177 | aeabi_set_attribute_int (Tag_DIV_use, 0); |
32178 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv) | |
32179 | || (profile == '\0' | |
32180 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_div) | |
32181 | && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))) | |
eea54501 | 32182 | aeabi_set_attribute_int (Tag_DIV_use, 2); |
60e5ef9f MGD |
32183 | |
32184 | /* Tag_MP_extension_use. */ | |
32185 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp)) | |
32186 | aeabi_set_attribute_int (Tag_MPextension_use, 1); | |
f4c65163 MGD |
32187 | |
32188 | /* Tag Virtualization_use. */ | |
32189 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec)) | |
90ec0d68 MGD |
32190 | virt_sec |= 1; |
32191 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt)) | |
32192 | virt_sec |= 2; | |
32193 | if (virt_sec != 0) | |
32194 | aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec); | |
5312fe52 BW |
32195 | |
32196 | if (fp16_format != ARM_FP16_FORMAT_DEFAULT) | |
32197 | aeabi_set_attribute_int (Tag_ABI_FP_16bit_format, fp16_format); | |
ee065d83 PB |
32198 | } |
32199 | ||
c168ce07 TP |
32200 | /* Post relaxation hook. Recompute ARM attributes now that relaxation is |
32201 | finished and free extension feature bits which will not be used anymore. */ | |
0198d5e6 | 32202 | |
c168ce07 TP |
32203 | void |
32204 | arm_md_post_relax (void) | |
32205 | { | |
32206 | aeabi_set_public_attributes (); | |
4d354d8b TP |
32207 | XDELETE (mcpu_ext_opt); |
32208 | mcpu_ext_opt = NULL; | |
32209 | XDELETE (march_ext_opt); | |
32210 | march_ext_opt = NULL; | |
c168ce07 TP |
32211 | } |
32212 | ||
104d59d1 | 32213 | /* Add the default contents for the .ARM.attributes section. */ |
0198d5e6 | 32214 | |
ee065d83 PB |
32215 | void |
32216 | arm_md_end (void) | |
32217 | { | |
ee065d83 PB |
32218 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
32219 | return; | |
32220 | ||
32221 | aeabi_set_public_attributes (); | |
ee065d83 | 32222 | } |
8463be01 | 32223 | #endif /* OBJ_ELF */ |
ee065d83 | 32224 | |
ee065d83 PB |
32225 | /* Parse a .cpu directive. */ |
32226 | ||
32227 | static void | |
32228 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
32229 | { | |
e74cfd16 | 32230 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
32231 | char *name; |
32232 | char saved_char; | |
32233 | ||
32234 | name = input_line_pointer; | |
5f4273c7 | 32235 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
32236 | input_line_pointer++; |
32237 | saved_char = *input_line_pointer; | |
32238 | *input_line_pointer = 0; | |
32239 | ||
32240 | /* Skip the first "all" entry. */ | |
32241 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
32242 | if (streq (opt->name, name)) | |
32243 | { | |
4d354d8b TP |
32244 | selected_arch = opt->value; |
32245 | selected_ext = opt->ext; | |
32246 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext); | |
ee065d83 | 32247 | if (opt->canonical_name) |
5f4273c7 | 32248 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
32249 | else |
32250 | { | |
32251 | int i; | |
32252 | for (i = 0; opt->name[i]; i++) | |
32253 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
f3bad469 | 32254 | |
ee065d83 PB |
32255 | selected_cpu_name[i] = 0; |
32256 | } | |
4d354d8b TP |
32257 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
32258 | ||
ee065d83 PB |
32259 | *input_line_pointer = saved_char; |
32260 | demand_empty_rest_of_line (); | |
32261 | return; | |
32262 | } | |
32263 | as_bad (_("unknown cpu `%s'"), name); | |
32264 | *input_line_pointer = saved_char; | |
32265 | ignore_rest_of_line (); | |
32266 | } | |
32267 | ||
ee065d83 PB |
32268 | /* Parse a .arch directive. */ |
32269 | ||
32270 | static void | |
32271 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
32272 | { | |
e74cfd16 | 32273 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
32274 | char saved_char; |
32275 | char *name; | |
32276 | ||
32277 | name = input_line_pointer; | |
5f4273c7 | 32278 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
32279 | input_line_pointer++; |
32280 | saved_char = *input_line_pointer; | |
32281 | *input_line_pointer = 0; | |
32282 | ||
32283 | /* Skip the first "all" entry. */ | |
32284 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
32285 | if (streq (opt->name, name)) | |
32286 | { | |
4d354d8b TP |
32287 | selected_arch = opt->value; |
32288 | selected_ext = arm_arch_none; | |
32289 | selected_cpu = selected_arch; | |
5f4273c7 | 32290 | strcpy (selected_cpu_name, opt->name); |
4d354d8b | 32291 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
ee065d83 PB |
32292 | *input_line_pointer = saved_char; |
32293 | demand_empty_rest_of_line (); | |
32294 | return; | |
32295 | } | |
32296 | ||
32297 | as_bad (_("unknown architecture `%s'\n"), name); | |
32298 | *input_line_pointer = saved_char; | |
32299 | ignore_rest_of_line (); | |
32300 | } | |
32301 | ||
7a1d4c38 PB |
32302 | /* Parse a .object_arch directive. */ |
32303 | ||
32304 | static void | |
32305 | s_arm_object_arch (int ignored ATTRIBUTE_UNUSED) | |
32306 | { | |
32307 | const struct arm_arch_option_table *opt; | |
32308 | char saved_char; | |
32309 | char *name; | |
32310 | ||
32311 | name = input_line_pointer; | |
5f4273c7 | 32312 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
7a1d4c38 PB |
32313 | input_line_pointer++; |
32314 | saved_char = *input_line_pointer; | |
32315 | *input_line_pointer = 0; | |
32316 | ||
32317 | /* Skip the first "all" entry. */ | |
32318 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
32319 | if (streq (opt->name, name)) | |
32320 | { | |
4d354d8b | 32321 | selected_object_arch = opt->value; |
7a1d4c38 PB |
32322 | *input_line_pointer = saved_char; |
32323 | demand_empty_rest_of_line (); | |
32324 | return; | |
32325 | } | |
32326 | ||
32327 | as_bad (_("unknown architecture `%s'\n"), name); | |
32328 | *input_line_pointer = saved_char; | |
32329 | ignore_rest_of_line (); | |
32330 | } | |
32331 | ||
69133863 MGD |
32332 | /* Parse a .arch_extension directive. */ |
32333 | ||
32334 | static void | |
32335 | s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED) | |
32336 | { | |
32337 | const struct arm_option_extension_value_table *opt; | |
32338 | char saved_char; | |
32339 | char *name; | |
32340 | int adding_value = 1; | |
32341 | ||
32342 | name = input_line_pointer; | |
32343 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) | |
32344 | input_line_pointer++; | |
32345 | saved_char = *input_line_pointer; | |
32346 | *input_line_pointer = 0; | |
32347 | ||
32348 | if (strlen (name) >= 2 | |
32349 | && strncmp (name, "no", 2) == 0) | |
32350 | { | |
32351 | adding_value = 0; | |
32352 | name += 2; | |
32353 | } | |
32354 | ||
32355 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
32356 | if (streq (opt->name, name)) | |
32357 | { | |
d942732e TP |
32358 | int i, nb_allowed_archs = |
32359 | sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]); | |
32360 | for (i = 0; i < nb_allowed_archs; i++) | |
32361 | { | |
32362 | /* Empty entry. */ | |
4d354d8b | 32363 | if (ARM_CPU_IS_ANY (opt->allowed_archs[i])) |
d942732e | 32364 | continue; |
4d354d8b | 32365 | if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch)) |
d942732e TP |
32366 | break; |
32367 | } | |
32368 | ||
32369 | if (i == nb_allowed_archs) | |
69133863 MGD |
32370 | { |
32371 | as_bad (_("architectural extension `%s' is not allowed for the " | |
32372 | "current base architecture"), name); | |
32373 | break; | |
32374 | } | |
32375 | ||
32376 | if (adding_value) | |
4d354d8b | 32377 | ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext, |
5a70a223 | 32378 | opt->merge_value); |
69133863 | 32379 | else |
4d354d8b | 32380 | ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value); |
69133863 | 32381 | |
4d354d8b TP |
32382 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext); |
32383 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); | |
69133863 MGD |
32384 | *input_line_pointer = saved_char; |
32385 | demand_empty_rest_of_line (); | |
3d030cdb TP |
32386 | /* Allowing Thumb division instructions for ARMv7 in autodetection rely |
32387 | on this return so that duplicate extensions (extensions with the | |
32388 | same name as a previous extension in the list) are not considered | |
32389 | for command-line parsing. */ | |
69133863 MGD |
32390 | return; |
32391 | } | |
32392 | ||
32393 | if (opt->name == NULL) | |
e673710a | 32394 | as_bad (_("unknown architecture extension `%s'\n"), name); |
69133863 MGD |
32395 | |
32396 | *input_line_pointer = saved_char; | |
32397 | ignore_rest_of_line (); | |
32398 | } | |
32399 | ||
ee065d83 PB |
32400 | /* Parse a .fpu directive. */ |
32401 | ||
32402 | static void | |
32403 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
32404 | { | |
69133863 | 32405 | const struct arm_option_fpu_value_table *opt; |
ee065d83 PB |
32406 | char saved_char; |
32407 | char *name; | |
32408 | ||
32409 | name = input_line_pointer; | |
5f4273c7 | 32410 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
32411 | input_line_pointer++; |
32412 | saved_char = *input_line_pointer; | |
32413 | *input_line_pointer = 0; | |
5f4273c7 | 32414 | |
ee065d83 PB |
32415 | for (opt = arm_fpus; opt->name != NULL; opt++) |
32416 | if (streq (opt->name, name)) | |
32417 | { | |
4d354d8b TP |
32418 | selected_fpu = opt->value; |
32419 | #ifndef CPU_DEFAULT | |
32420 | if (no_cpu_selected ()) | |
32421 | ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu); | |
32422 | else | |
32423 | #endif | |
32424 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); | |
ee065d83 PB |
32425 | *input_line_pointer = saved_char; |
32426 | demand_empty_rest_of_line (); | |
32427 | return; | |
32428 | } | |
32429 | ||
32430 | as_bad (_("unknown floating point format `%s'\n"), name); | |
32431 | *input_line_pointer = saved_char; | |
32432 | ignore_rest_of_line (); | |
32433 | } | |
ee065d83 | 32434 | |
794ba86a | 32435 | /* Copy symbol information. */ |
f31fef98 | 32436 | |
794ba86a DJ |
32437 | void |
32438 | arm_copy_symbol_attributes (symbolS *dest, symbolS *src) | |
32439 | { | |
32440 | ARM_GET_FLAG (dest) = ARM_GET_FLAG (src); | |
32441 | } | |
e04befd0 | 32442 | |
f31fef98 | 32443 | #ifdef OBJ_ELF |
e04befd0 AS |
32444 | /* Given a symbolic attribute NAME, return the proper integer value. |
32445 | Returns -1 if the attribute is not known. */ | |
f31fef98 | 32446 | |
e04befd0 AS |
32447 | int |
32448 | arm_convert_symbolic_attribute (const char *name) | |
32449 | { | |
f31fef98 NC |
32450 | static const struct |
32451 | { | |
32452 | const char * name; | |
32453 | const int tag; | |
32454 | } | |
32455 | attribute_table[] = | |
32456 | { | |
32457 | /* When you modify this table you should | |
32458 | also modify the list in doc/c-arm.texi. */ | |
e04befd0 | 32459 | #define T(tag) {#tag, tag} |
f31fef98 NC |
32460 | T (Tag_CPU_raw_name), |
32461 | T (Tag_CPU_name), | |
32462 | T (Tag_CPU_arch), | |
32463 | T (Tag_CPU_arch_profile), | |
32464 | T (Tag_ARM_ISA_use), | |
32465 | T (Tag_THUMB_ISA_use), | |
75375b3e | 32466 | T (Tag_FP_arch), |
f31fef98 NC |
32467 | T (Tag_VFP_arch), |
32468 | T (Tag_WMMX_arch), | |
32469 | T (Tag_Advanced_SIMD_arch), | |
32470 | T (Tag_PCS_config), | |
32471 | T (Tag_ABI_PCS_R9_use), | |
32472 | T (Tag_ABI_PCS_RW_data), | |
32473 | T (Tag_ABI_PCS_RO_data), | |
32474 | T (Tag_ABI_PCS_GOT_use), | |
32475 | T (Tag_ABI_PCS_wchar_t), | |
32476 | T (Tag_ABI_FP_rounding), | |
32477 | T (Tag_ABI_FP_denormal), | |
32478 | T (Tag_ABI_FP_exceptions), | |
32479 | T (Tag_ABI_FP_user_exceptions), | |
32480 | T (Tag_ABI_FP_number_model), | |
75375b3e | 32481 | T (Tag_ABI_align_needed), |
f31fef98 | 32482 | T (Tag_ABI_align8_needed), |
75375b3e | 32483 | T (Tag_ABI_align_preserved), |
f31fef98 NC |
32484 | T (Tag_ABI_align8_preserved), |
32485 | T (Tag_ABI_enum_size), | |
32486 | T (Tag_ABI_HardFP_use), | |
32487 | T (Tag_ABI_VFP_args), | |
32488 | T (Tag_ABI_WMMX_args), | |
32489 | T (Tag_ABI_optimization_goals), | |
32490 | T (Tag_ABI_FP_optimization_goals), | |
32491 | T (Tag_compatibility), | |
32492 | T (Tag_CPU_unaligned_access), | |
75375b3e | 32493 | T (Tag_FP_HP_extension), |
f31fef98 NC |
32494 | T (Tag_VFP_HP_extension), |
32495 | T (Tag_ABI_FP_16bit_format), | |
cd21e546 MGD |
32496 | T (Tag_MPextension_use), |
32497 | T (Tag_DIV_use), | |
f31fef98 NC |
32498 | T (Tag_nodefaults), |
32499 | T (Tag_also_compatible_with), | |
32500 | T (Tag_conformance), | |
32501 | T (Tag_T2EE_use), | |
32502 | T (Tag_Virtualization_use), | |
15afaa63 | 32503 | T (Tag_DSP_extension), |
a7ad558c | 32504 | T (Tag_MVE_arch), |
cd21e546 | 32505 | /* We deliberately do not include Tag_MPextension_use_legacy. */ |
e04befd0 | 32506 | #undef T |
f31fef98 | 32507 | }; |
e04befd0 AS |
32508 | unsigned int i; |
32509 | ||
32510 | if (name == NULL) | |
32511 | return -1; | |
32512 | ||
f31fef98 | 32513 | for (i = 0; i < ARRAY_SIZE (attribute_table); i++) |
c921be7d | 32514 | if (streq (name, attribute_table[i].name)) |
e04befd0 AS |
32515 | return attribute_table[i].tag; |
32516 | ||
32517 | return -1; | |
32518 | } | |
267bf995 | 32519 | |
93ef582d NC |
32520 | /* Apply sym value for relocations only in the case that they are for |
32521 | local symbols in the same segment as the fixup and you have the | |
32522 | respective architectural feature for blx and simple switches. */ | |
0198d5e6 | 32523 | |
267bf995 | 32524 | int |
93ef582d | 32525 | arm_apply_sym_value (struct fix * fixP, segT this_seg) |
267bf995 RR |
32526 | { |
32527 | if (fixP->fx_addsy | |
32528 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
93ef582d NC |
32529 | /* PR 17444: If the local symbol is in a different section then a reloc |
32530 | will always be generated for it, so applying the symbol value now | |
32531 | will result in a double offset being stored in the relocation. */ | |
32532 | && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg) | |
34e77a92 | 32533 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)) |
267bf995 RR |
32534 | { |
32535 | switch (fixP->fx_r_type) | |
32536 | { | |
32537 | case BFD_RELOC_ARM_PCREL_BLX: | |
32538 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
32539 | if (ARM_IS_FUNC (fixP->fx_addsy)) | |
32540 | return 1; | |
32541 | break; | |
32542 | ||
32543 | case BFD_RELOC_ARM_PCREL_CALL: | |
32544 | case BFD_RELOC_THUMB_PCREL_BLX: | |
32545 | if (THUMB_IS_FUNC (fixP->fx_addsy)) | |
93ef582d | 32546 | return 1; |
267bf995 RR |
32547 | break; |
32548 | ||
32549 | default: | |
32550 | break; | |
32551 | } | |
32552 | ||
32553 | } | |
32554 | return 0; | |
32555 | } | |
f31fef98 | 32556 | #endif /* OBJ_ELF */ |