Add support for intel SERIALIZE instruction
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright (C) 1994-2020 Free Software Foundation, Inc.
3 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
4 Modified by David Taylor (dtaylor@armltd.co.uk)
5 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
6 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
7 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
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
13 the Free Software Foundation; either version 3, or (at your option)
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
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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
23 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 02110-1301, USA. */
25
26 #include "as.h"
27 #include <limits.h>
28 #include <stdarg.h>
29 #define NO_RELOC 0
30 #include "safe-ctype.h"
31 #include "subsegs.h"
32 #include "obstack.h"
33 #include "libiberty.h"
34 #include "opcode/arm.h"
35 #include "cpu-arm.h"
36
37 #ifdef OBJ_ELF
38 #include "elf/arm.h"
39 #include "dw2gencfi.h"
40 #endif
41
42 #include "dwarf2dbg.h"
43
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 {
52 symbolS * proc_start;
53 symbolS * table_entry;
54 symbolS * personality_routine;
55 int personality_index;
56 /* The segment containing the function. */
57 segT saved_seg;
58 subsegT saved_subseg;
59 /* Opcodes generated from this function. */
60 unsigned char * opcodes;
61 int opcode_count;
62 int opcode_alloc;
63 /* The number of bytes pushed to the stack. */
64 offsetT frame_size;
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. */
68 offsetT pending_offset;
69 /* These two fields are set by both unwind_movsp and unwind_setfp. They
70 hold the reg+offset to use when restoring sp from a frame pointer. */
71 offsetT fp_offset;
72 int fp_reg;
73 /* Nonzero if an unwind_setfp directive has been seen. */
74 unsigned fp_used:1;
75 /* Nonzero if the last opcode restores sp from fp_reg. */
76 unsigned sp_restored:1;
77 } unwind;
78
79 /* Whether --fdpic was given. */
80 static int arm_fdpic;
81
82 #endif /* OBJ_ELF */
83
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
93 enum arm_float_abi
94 {
95 ARM_FLOAT_ABI_HARD,
96 ARM_FLOAT_ABI_SOFTFP,
97 ARM_FLOAT_ABI_SOFT
98 };
99
100 /* Types of processor to assemble for. */
101 #ifndef CPU_DEFAULT
102 /* The code that was here used to select a default CPU depending on compiler
103 pre-defines which were only present when doing native builds, thus
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. */
108 #endif
109
110 /* Perform range checks on positive and negative overflows by checking if the
111 VALUE given fits within the range of an BITS sized immediate. */
112 static bfd_boolean out_of_range_p (offsetT value, offsetT bits)
113 {
114 gas_assert (bits < (offsetT)(sizeof (value) * 8));
115 return (value & ~((1 << bits)-1))
116 && ((value & ~((1 << bits)-1)) != ~((1 << bits)-1));
117 }
118
119 #ifndef FPU_DEFAULT
120 # ifdef TE_LINUX
121 # define FPU_DEFAULT FPU_ARCH_FPA
122 # elif defined (TE_NetBSD)
123 # ifdef OBJ_ELF
124 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
125 # else
126 /* Legacy a.out format. */
127 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
128 # endif
129 # elif defined (TE_VXWORKS)
130 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
131 # else
132 /* For backwards compatibility, default to FPA. */
133 # define FPU_DEFAULT FPU_ARCH_FPA
134 # endif
135 #endif /* ifndef FPU_DEFAULT */
136
137 #define streq(a, b) (strcmp (a, b) == 0)
138
139 /* Current set of feature bits available (CPU+FPU). Different from
140 selected_cpu + selected_fpu in case of autodetection since the CPU
141 feature bits are then all set. */
142 static arm_feature_set cpu_variant;
143 /* Feature bits used in each execution state. Used to set build attribute
144 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
145 static arm_feature_set arm_arch_used;
146 static arm_feature_set thumb_arch_used;
147
148 /* Flags stored in private area of BFD structure. */
149 static int uses_apcs_26 = FALSE;
150 static int atpcs = FALSE;
151 static int support_interwork = FALSE;
152 static int uses_apcs_float = FALSE;
153 static int pic_code = FALSE;
154 static int fix_v4bx = FALSE;
155 /* Warn on using deprecated features. */
156 static int warn_on_deprecated = TRUE;
157 static int warn_on_restrict_it = FALSE;
158
159 /* Understand CodeComposer Studio assembly syntax. */
160 bfd_boolean codecomposer_syntax = FALSE;
161
162 /* Variables that we set while parsing command-line options. Once all
163 options have been read we re-process these values to set the real
164 assembly flags. */
165
166 /* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
167 instead of -mcpu=arm1). */
168 static const arm_feature_set *legacy_cpu = NULL;
169 static const arm_feature_set *legacy_fpu = NULL;
170
171 /* CPU, extension and FPU feature bits selected by -mcpu. */
172 static const arm_feature_set *mcpu_cpu_opt = NULL;
173 static arm_feature_set *mcpu_ext_opt = NULL;
174 static const arm_feature_set *mcpu_fpu_opt = NULL;
175
176 /* CPU, extension and FPU feature bits selected by -march. */
177 static const arm_feature_set *march_cpu_opt = NULL;
178 static arm_feature_set *march_ext_opt = NULL;
179 static const arm_feature_set *march_fpu_opt = NULL;
180
181 /* Feature bits selected by -mfpu. */
182 static const arm_feature_set *mfpu_opt = NULL;
183
184 /* Constants for known architecture features. */
185 static const arm_feature_set fpu_default = FPU_DEFAULT;
186 static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
187 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
188 static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
189 static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
190 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
191 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
192 #ifdef OBJ_ELF
193 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
194 #endif
195 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
196
197 #ifdef CPU_DEFAULT
198 static const arm_feature_set cpu_default = CPU_DEFAULT;
199 #endif
200
201 static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
202 static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
203 static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
204 static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
205 static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
206 static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
207 static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
208 static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
209 static const arm_feature_set arm_ext_v4t_5 =
210 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
211 static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
212 static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
213 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
214 static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
215 static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
216 static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
217 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
218 /* Only for compatability of hint instructions. */
219 static const arm_feature_set arm_ext_v6k_v6t2 =
220 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2);
221 static const arm_feature_set arm_ext_v6_notm =
222 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
223 static const arm_feature_set arm_ext_v6_dsp =
224 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
225 static const arm_feature_set arm_ext_barrier =
226 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
227 static const arm_feature_set arm_ext_msr =
228 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
229 static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
230 static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
231 static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
232 static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
233 #ifdef OBJ_ELF
234 static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
235 #endif
236 static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
237 static const arm_feature_set arm_ext_m =
238 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
239 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
240 static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
241 static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
242 static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
243 static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
244 static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
245 static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
246 static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
247 static const arm_feature_set arm_ext_v8m_main =
248 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
249 static const arm_feature_set arm_ext_v8_1m_main =
250 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
251 /* Instructions in ARMv8-M only found in M profile architectures. */
252 static const arm_feature_set arm_ext_v8m_m_only =
253 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
254 static const arm_feature_set arm_ext_v6t2_v8m =
255 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
256 /* Instructions shared between ARMv8-A and ARMv8-M. */
257 static const arm_feature_set arm_ext_atomics =
258 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
259 #ifdef OBJ_ELF
260 /* DSP instructions Tag_DSP_extension refers to. */
261 static const arm_feature_set arm_ext_dsp =
262 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
263 #endif
264 static const arm_feature_set arm_ext_ras =
265 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
266 /* FP16 instructions. */
267 static const arm_feature_set arm_ext_fp16 =
268 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
269 static const arm_feature_set arm_ext_fp16_fml =
270 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
271 static const arm_feature_set arm_ext_v8_2 =
272 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
273 static const arm_feature_set arm_ext_v8_3 =
274 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
275 static const arm_feature_set arm_ext_sb =
276 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
277 static const arm_feature_set arm_ext_predres =
278 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
279 static const arm_feature_set arm_ext_bf16 =
280 ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16);
281 static const arm_feature_set arm_ext_i8mm =
282 ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM);
283 static const arm_feature_set arm_ext_crc =
284 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC);
285 static const arm_feature_set arm_ext_cde =
286 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE);
287 static const arm_feature_set arm_ext_cde0 =
288 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE0);
289 static const arm_feature_set arm_ext_cde1 =
290 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE1);
291 static const arm_feature_set arm_ext_cde2 =
292 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE2);
293 static const arm_feature_set arm_ext_cde3 =
294 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE3);
295 static const arm_feature_set arm_ext_cde4 =
296 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE4);
297 static const arm_feature_set arm_ext_cde5 =
298 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE5);
299 static const arm_feature_set arm_ext_cde6 =
300 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE6);
301 static const arm_feature_set arm_ext_cde7 =
302 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE7);
303
304 static const arm_feature_set arm_arch_any = ARM_ANY;
305 static const arm_feature_set fpu_any = FPU_ANY;
306 static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
307 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
308 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
309
310 static const arm_feature_set arm_cext_iwmmxt2 =
311 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
312 static const arm_feature_set arm_cext_iwmmxt =
313 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
314 static const arm_feature_set arm_cext_xscale =
315 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
316 static const arm_feature_set arm_cext_maverick =
317 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
318 static const arm_feature_set fpu_fpa_ext_v1 =
319 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
320 static const arm_feature_set fpu_fpa_ext_v2 =
321 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
322 static const arm_feature_set fpu_vfp_ext_v1xd =
323 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
324 static const arm_feature_set fpu_vfp_ext_v1 =
325 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
326 static const arm_feature_set fpu_vfp_ext_v2 =
327 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
328 static const arm_feature_set fpu_vfp_ext_v3xd =
329 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
330 static const arm_feature_set fpu_vfp_ext_v3 =
331 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
332 static const arm_feature_set fpu_vfp_ext_d32 =
333 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
334 static const arm_feature_set fpu_neon_ext_v1 =
335 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
336 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
337 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
338 static const arm_feature_set mve_ext =
339 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE);
340 static const arm_feature_set mve_fp_ext =
341 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE_FP);
342 /* Note: This has more than one bit set, which means using it with
343 mark_feature_used (which returns if *any* of the bits are set in the current
344 cpu variant) can give surprising results. */
345 static const arm_feature_set armv8m_fp =
346 ARM_FEATURE_COPROC (FPU_VFP_V5_SP_D16);
347 #ifdef OBJ_ELF
348 static const arm_feature_set fpu_vfp_fp16 =
349 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
350 static const arm_feature_set fpu_neon_ext_fma =
351 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
352 #endif
353 static const arm_feature_set fpu_vfp_ext_fma =
354 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
355 static const arm_feature_set fpu_vfp_ext_armv8 =
356 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
357 static const arm_feature_set fpu_vfp_ext_armv8xd =
358 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
359 static const arm_feature_set fpu_neon_ext_armv8 =
360 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
361 static const arm_feature_set fpu_crypto_ext_armv8 =
362 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
363 static const arm_feature_set fpu_neon_ext_v8_1 =
364 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
365 static const arm_feature_set fpu_neon_ext_dotprod =
366 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
367
368 static int mfloat_abi_opt = -1;
369 /* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
370 directive. */
371 static arm_feature_set selected_arch = ARM_ARCH_NONE;
372 /* Extension feature bits selected by the last -mcpu/-march or .arch_extension
373 directive. */
374 static arm_feature_set selected_ext = ARM_ARCH_NONE;
375 /* Feature bits selected by the last -mcpu/-march or by the combination of the
376 last .cpu/.arch directive .arch_extension directives since that
377 directive. */
378 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
379 /* FPU feature bits selected by the last -mfpu or .fpu directive. */
380 static arm_feature_set selected_fpu = FPU_NONE;
381 /* Feature bits selected by the last .object_arch directive. */
382 static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
383 /* Must be long enough to hold any of the names in arm_cpus. */
384 static const struct arm_ext_table * selected_ctx_ext_table = NULL;
385 static char selected_cpu_name[20];
386
387 extern FLONUM_TYPE generic_floating_point_number;
388
389 /* Return if no cpu was selected on command-line. */
390 static bfd_boolean
391 no_cpu_selected (void)
392 {
393 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
394 }
395
396 #ifdef OBJ_ELF
397 # ifdef EABI_DEFAULT
398 static int meabi_flags = EABI_DEFAULT;
399 # else
400 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
401 # endif
402
403 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
404
405 bfd_boolean
406 arm_is_eabi (void)
407 {
408 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
409 }
410 #endif
411
412 #ifdef OBJ_ELF
413 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
414 symbolS * GOT_symbol;
415 #endif
416
417 /* 0: assemble for ARM,
418 1: assemble for Thumb,
419 2: assemble for Thumb even though target CPU does not support thumb
420 instructions. */
421 static int thumb_mode = 0;
422 /* A value distinct from the possible values for thumb_mode that we
423 can use to record whether thumb_mode has been copied into the
424 tc_frag_data field of a frag. */
425 #define MODE_RECORDED (1 << 4)
426
427 /* Specifies the intrinsic IT insn behavior mode. */
428 enum implicit_it_mode
429 {
430 IMPLICIT_IT_MODE_NEVER = 0x00,
431 IMPLICIT_IT_MODE_ARM = 0x01,
432 IMPLICIT_IT_MODE_THUMB = 0x02,
433 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
434 };
435 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
436
437 /* If unified_syntax is true, we are processing the new unified
438 ARM/Thumb syntax. Important differences from the old ARM mode:
439
440 - Immediate operands do not require a # prefix.
441 - Conditional affixes always appear at the end of the
442 instruction. (For backward compatibility, those instructions
443 that formerly had them in the middle, continue to accept them
444 there.)
445 - The IT instruction may appear, and if it does is validated
446 against subsequent conditional affixes. It does not generate
447 machine code.
448
449 Important differences from the old Thumb mode:
450
451 - Immediate operands do not require a # prefix.
452 - Most of the V6T2 instructions are only available in unified mode.
453 - The .N and .W suffixes are recognized and honored (it is an error
454 if they cannot be honored).
455 - All instructions set the flags if and only if they have an 's' affix.
456 - Conditional affixes may be used. They are validated against
457 preceding IT instructions. Unlike ARM mode, you cannot use a
458 conditional affix except in the scope of an IT instruction. */
459
460 static bfd_boolean unified_syntax = FALSE;
461
462 /* An immediate operand can start with #, and ld*, st*, pld operands
463 can contain [ and ]. We need to tell APP not to elide whitespace
464 before a [, which can appear as the first operand for pld.
465 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
466 const char arm_symbol_chars[] = "#[]{}";
467
468 enum neon_el_type
469 {
470 NT_invtype,
471 NT_untyped,
472 NT_integer,
473 NT_float,
474 NT_poly,
475 NT_signed,
476 NT_bfloat,
477 NT_unsigned
478 };
479
480 struct neon_type_el
481 {
482 enum neon_el_type type;
483 unsigned size;
484 };
485
486 #define NEON_MAX_TYPE_ELS 5
487
488 struct neon_type
489 {
490 struct neon_type_el el[NEON_MAX_TYPE_ELS];
491 unsigned elems;
492 };
493
494 enum pred_instruction_type
495 {
496 OUTSIDE_PRED_INSN,
497 INSIDE_VPT_INSN,
498 INSIDE_IT_INSN,
499 INSIDE_IT_LAST_INSN,
500 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
501 if inside, should be the last one. */
502 NEUTRAL_IT_INSN, /* This could be either inside or outside,
503 i.e. BKPT and NOP. */
504 IT_INSN, /* The IT insn has been parsed. */
505 VPT_INSN, /* The VPT/VPST insn has been parsed. */
506 MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without
507 a predication code. */
508 MVE_UNPREDICABLE_INSN, /* MVE instruction that is non-predicable. */
509 };
510
511 /* The maximum number of operands we need. */
512 #define ARM_IT_MAX_OPERANDS 6
513 #define ARM_IT_MAX_RELOCS 3
514
515 struct arm_it
516 {
517 const char * error;
518 unsigned long instruction;
519 int size;
520 int size_req;
521 int cond;
522 /* "uncond_value" is set to the value in place of the conditional field in
523 unconditional versions of the instruction, or -1 if nothing is
524 appropriate. */
525 int uncond_value;
526 struct neon_type vectype;
527 /* This does not indicate an actual NEON instruction, only that
528 the mnemonic accepts neon-style type suffixes. */
529 int is_neon;
530 /* Set to the opcode if the instruction needs relaxation.
531 Zero if the instruction is not relaxed. */
532 unsigned long relax;
533 struct
534 {
535 bfd_reloc_code_real_type type;
536 expressionS exp;
537 int pc_rel;
538 } relocs[ARM_IT_MAX_RELOCS];
539
540 enum pred_instruction_type pred_insn_type;
541
542 struct
543 {
544 unsigned reg;
545 signed int imm;
546 struct neon_type_el vectype;
547 unsigned present : 1; /* Operand present. */
548 unsigned isreg : 1; /* Operand was a register. */
549 unsigned immisreg : 2; /* .imm field is a second register.
550 0: imm, 1: gpr, 2: MVE Q-register. */
551 unsigned isscalar : 2; /* Operand is a (SIMD) scalar:
552 0) not scalar,
553 1) Neon scalar,
554 2) MVE scalar. */
555 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
556 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
557 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
558 instructions. This allows us to disambiguate ARM <-> vector insns. */
559 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
560 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
561 unsigned isquad : 1; /* Operand is SIMD quad register. */
562 unsigned issingle : 1; /* Operand is VFP single-precision register. */
563 unsigned iszr : 1; /* Operand is ZR register. */
564 unsigned hasreloc : 1; /* Operand has relocation suffix. */
565 unsigned writeback : 1; /* Operand has trailing ! */
566 unsigned preind : 1; /* Preindexed address. */
567 unsigned postind : 1; /* Postindexed address. */
568 unsigned negative : 1; /* Index register was negated. */
569 unsigned shifted : 1; /* Shift applied to operation. */
570 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
571 } operands[ARM_IT_MAX_OPERANDS];
572 };
573
574 static struct arm_it inst;
575
576 #define NUM_FLOAT_VALS 8
577
578 const char * fp_const[] =
579 {
580 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
581 };
582
583 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
584
585 #define FAIL (-1)
586 #define SUCCESS (0)
587
588 #define SUFF_S 1
589 #define SUFF_D 2
590 #define SUFF_E 3
591 #define SUFF_P 4
592
593 #define CP_T_X 0x00008000
594 #define CP_T_Y 0x00400000
595
596 #define CONDS_BIT 0x00100000
597 #define LOAD_BIT 0x00100000
598
599 #define DOUBLE_LOAD_FLAG 0x00000001
600
601 struct asm_cond
602 {
603 const char * template_name;
604 unsigned long value;
605 };
606
607 #define COND_ALWAYS 0xE
608
609 struct asm_psr
610 {
611 const char * template_name;
612 unsigned long field;
613 };
614
615 struct asm_barrier_opt
616 {
617 const char * template_name;
618 unsigned long value;
619 const arm_feature_set arch;
620 };
621
622 /* The bit that distinguishes CPSR and SPSR. */
623 #define SPSR_BIT (1 << 22)
624
625 /* The individual PSR flag bits. */
626 #define PSR_c (1 << 16)
627 #define PSR_x (1 << 17)
628 #define PSR_s (1 << 18)
629 #define PSR_f (1 << 19)
630
631 struct reloc_entry
632 {
633 const char * name;
634 bfd_reloc_code_real_type reloc;
635 };
636
637 enum vfp_reg_pos
638 {
639 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
640 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
641 };
642
643 enum vfp_ldstm_type
644 {
645 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
646 };
647
648 /* Bits for DEFINED field in neon_typed_alias. */
649 #define NTA_HASTYPE 1
650 #define NTA_HASINDEX 2
651
652 struct neon_typed_alias
653 {
654 unsigned char defined;
655 unsigned char index;
656 struct neon_type_el eltype;
657 };
658
659 /* ARM register categories. This includes coprocessor numbers and various
660 architecture extensions' registers. Each entry should have an error message
661 in reg_expected_msgs below. */
662 enum arm_reg_type
663 {
664 REG_TYPE_RN,
665 REG_TYPE_CP,
666 REG_TYPE_CN,
667 REG_TYPE_FN,
668 REG_TYPE_VFS,
669 REG_TYPE_VFD,
670 REG_TYPE_NQ,
671 REG_TYPE_VFSD,
672 REG_TYPE_NDQ,
673 REG_TYPE_NSD,
674 REG_TYPE_NSDQ,
675 REG_TYPE_VFC,
676 REG_TYPE_MVF,
677 REG_TYPE_MVD,
678 REG_TYPE_MVFX,
679 REG_TYPE_MVDX,
680 REG_TYPE_MVAX,
681 REG_TYPE_MQ,
682 REG_TYPE_DSPSC,
683 REG_TYPE_MMXWR,
684 REG_TYPE_MMXWC,
685 REG_TYPE_MMXWCG,
686 REG_TYPE_XSCALE,
687 REG_TYPE_RNB,
688 REG_TYPE_ZR
689 };
690
691 /* Structure for a hash table entry for a register.
692 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
693 information which states whether a vector type or index is specified (for a
694 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
695 struct reg_entry
696 {
697 const char * name;
698 unsigned int number;
699 unsigned char type;
700 unsigned char builtin;
701 struct neon_typed_alias * neon;
702 };
703
704 /* Diagnostics used when we don't get a register of the expected type. */
705 const char * const reg_expected_msgs[] =
706 {
707 [REG_TYPE_RN] = N_("ARM register expected"),
708 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
709 [REG_TYPE_CN] = N_("co-processor register expected"),
710 [REG_TYPE_FN] = N_("FPA register expected"),
711 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
712 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
713 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
714 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
715 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
716 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
717 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
718 " expected"),
719 [REG_TYPE_VFC] = N_("VFP system register expected"),
720 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
721 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
722 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
723 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
724 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
725 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
726 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
727 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
728 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
729 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
730 [REG_TYPE_MQ] = N_("MVE vector register expected"),
731 [REG_TYPE_RNB] = ""
732 };
733
734 /* Some well known registers that we refer to directly elsewhere. */
735 #define REG_R12 12
736 #define REG_SP 13
737 #define REG_LR 14
738 #define REG_PC 15
739
740 /* ARM instructions take 4bytes in the object file, Thumb instructions
741 take 2: */
742 #define INSN_SIZE 4
743
744 struct asm_opcode
745 {
746 /* Basic string to match. */
747 const char * template_name;
748
749 /* Parameters to instruction. */
750 unsigned int operands[8];
751
752 /* Conditional tag - see opcode_lookup. */
753 unsigned int tag : 4;
754
755 /* Basic instruction code. */
756 unsigned int avalue;
757
758 /* Thumb-format instruction code. */
759 unsigned int tvalue;
760
761 /* Which architecture variant provides this instruction. */
762 const arm_feature_set * avariant;
763 const arm_feature_set * tvariant;
764
765 /* Function to call to encode instruction in ARM format. */
766 void (* aencode) (void);
767
768 /* Function to call to encode instruction in Thumb format. */
769 void (* tencode) (void);
770
771 /* Indicates whether this instruction may be vector predicated. */
772 unsigned int mayBeVecPred : 1;
773 };
774
775 /* Defines for various bits that we will want to toggle. */
776 #define INST_IMMEDIATE 0x02000000
777 #define OFFSET_REG 0x02000000
778 #define HWOFFSET_IMM 0x00400000
779 #define SHIFT_BY_REG 0x00000010
780 #define PRE_INDEX 0x01000000
781 #define INDEX_UP 0x00800000
782 #define WRITE_BACK 0x00200000
783 #define LDM_TYPE_2_OR_3 0x00400000
784 #define CPSI_MMOD 0x00020000
785
786 #define LITERAL_MASK 0xf000f000
787 #define OPCODE_MASK 0xfe1fffff
788 #define V4_STR_BIT 0x00000020
789 #define VLDR_VMOV_SAME 0x0040f000
790
791 #define T2_SUBS_PC_LR 0xf3de8f00
792
793 #define DATA_OP_SHIFT 21
794 #define SBIT_SHIFT 20
795
796 #define T2_OPCODE_MASK 0xfe1fffff
797 #define T2_DATA_OP_SHIFT 21
798 #define T2_SBIT_SHIFT 20
799
800 #define A_COND_MASK 0xf0000000
801 #define A_PUSH_POP_OP_MASK 0x0fff0000
802
803 /* Opcodes for pushing/poping registers to/from the stack. */
804 #define A1_OPCODE_PUSH 0x092d0000
805 #define A2_OPCODE_PUSH 0x052d0004
806 #define A2_OPCODE_POP 0x049d0004
807
808 /* Codes to distinguish the arithmetic instructions. */
809 #define OPCODE_AND 0
810 #define OPCODE_EOR 1
811 #define OPCODE_SUB 2
812 #define OPCODE_RSB 3
813 #define OPCODE_ADD 4
814 #define OPCODE_ADC 5
815 #define OPCODE_SBC 6
816 #define OPCODE_RSC 7
817 #define OPCODE_TST 8
818 #define OPCODE_TEQ 9
819 #define OPCODE_CMP 10
820 #define OPCODE_CMN 11
821 #define OPCODE_ORR 12
822 #define OPCODE_MOV 13
823 #define OPCODE_BIC 14
824 #define OPCODE_MVN 15
825
826 #define T2_OPCODE_AND 0
827 #define T2_OPCODE_BIC 1
828 #define T2_OPCODE_ORR 2
829 #define T2_OPCODE_ORN 3
830 #define T2_OPCODE_EOR 4
831 #define T2_OPCODE_ADD 8
832 #define T2_OPCODE_ADC 10
833 #define T2_OPCODE_SBC 11
834 #define T2_OPCODE_SUB 13
835 #define T2_OPCODE_RSB 14
836
837 #define T_OPCODE_MUL 0x4340
838 #define T_OPCODE_TST 0x4200
839 #define T_OPCODE_CMN 0x42c0
840 #define T_OPCODE_NEG 0x4240
841 #define T_OPCODE_MVN 0x43c0
842
843 #define T_OPCODE_ADD_R3 0x1800
844 #define T_OPCODE_SUB_R3 0x1a00
845 #define T_OPCODE_ADD_HI 0x4400
846 #define T_OPCODE_ADD_ST 0xb000
847 #define T_OPCODE_SUB_ST 0xb080
848 #define T_OPCODE_ADD_SP 0xa800
849 #define T_OPCODE_ADD_PC 0xa000
850 #define T_OPCODE_ADD_I8 0x3000
851 #define T_OPCODE_SUB_I8 0x3800
852 #define T_OPCODE_ADD_I3 0x1c00
853 #define T_OPCODE_SUB_I3 0x1e00
854
855 #define T_OPCODE_ASR_R 0x4100
856 #define T_OPCODE_LSL_R 0x4080
857 #define T_OPCODE_LSR_R 0x40c0
858 #define T_OPCODE_ROR_R 0x41c0
859 #define T_OPCODE_ASR_I 0x1000
860 #define T_OPCODE_LSL_I 0x0000
861 #define T_OPCODE_LSR_I 0x0800
862
863 #define T_OPCODE_MOV_I8 0x2000
864 #define T_OPCODE_CMP_I8 0x2800
865 #define T_OPCODE_CMP_LR 0x4280
866 #define T_OPCODE_MOV_HR 0x4600
867 #define T_OPCODE_CMP_HR 0x4500
868
869 #define T_OPCODE_LDR_PC 0x4800
870 #define T_OPCODE_LDR_SP 0x9800
871 #define T_OPCODE_STR_SP 0x9000
872 #define T_OPCODE_LDR_IW 0x6800
873 #define T_OPCODE_STR_IW 0x6000
874 #define T_OPCODE_LDR_IH 0x8800
875 #define T_OPCODE_STR_IH 0x8000
876 #define T_OPCODE_LDR_IB 0x7800
877 #define T_OPCODE_STR_IB 0x7000
878 #define T_OPCODE_LDR_RW 0x5800
879 #define T_OPCODE_STR_RW 0x5000
880 #define T_OPCODE_LDR_RH 0x5a00
881 #define T_OPCODE_STR_RH 0x5200
882 #define T_OPCODE_LDR_RB 0x5c00
883 #define T_OPCODE_STR_RB 0x5400
884
885 #define T_OPCODE_PUSH 0xb400
886 #define T_OPCODE_POP 0xbc00
887
888 #define T_OPCODE_BRANCH 0xe000
889
890 #define THUMB_SIZE 2 /* Size of thumb instruction. */
891 #define THUMB_PP_PC_LR 0x0100
892 #define THUMB_LOAD_BIT 0x0800
893 #define THUMB2_LOAD_BIT 0x00100000
894
895 #define BAD_SYNTAX _("syntax error")
896 #define BAD_ARGS _("bad arguments to instruction")
897 #define BAD_SP _("r13 not allowed here")
898 #define BAD_PC _("r15 not allowed here")
899 #define BAD_ODD _("Odd register not allowed here")
900 #define BAD_EVEN _("Even register not allowed here")
901 #define BAD_COND _("instruction cannot be conditional")
902 #define BAD_OVERLAP _("registers may not be the same")
903 #define BAD_HIREG _("lo register required")
904 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
905 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode")
906 #define BAD_BRANCH _("branch must be last instruction in IT block")
907 #define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
908 #define BAD_NO_VPT _("instruction not allowed in VPT block")
909 #define BAD_NOT_IT _("instruction not allowed in IT block")
910 #define BAD_NOT_VPT _("instruction missing MVE vector predication code")
911 #define BAD_FPU _("selected FPU does not support instruction")
912 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
913 #define BAD_OUT_VPT \
914 _("vector predicated instruction should be in VPT/VPST block")
915 #define BAD_IT_COND _("incorrect condition in IT block")
916 #define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
917 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
918 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
919 #define BAD_PC_ADDRESSING \
920 _("cannot use register index with PC-relative addressing")
921 #define BAD_PC_WRITEBACK \
922 _("cannot use writeback with PC-relative addressing")
923 #define BAD_RANGE _("branch out of range")
924 #define BAD_FP16 _("selected processor does not support fp16 instruction")
925 #define BAD_BF16 _("selected processor does not support bf16 instruction")
926 #define BAD_CDE _("selected processor does not support cde instruction")
927 #define BAD_CDE_COPROC _("coprocessor for insn is not enabled for cde")
928 #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
929 #define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
930 #define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
931 "block")
932 #define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
933 "block")
934 #define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
935 " operand")
936 #define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
937 " operand")
938 #define BAD_SIMD_TYPE _("bad type in SIMD instruction")
939 #define BAD_MVE_AUTO \
940 _("GAS auto-detection mode and -march=all is deprecated for MVE, please" \
941 " use a valid -march or -mcpu option.")
942 #define BAD_MVE_SRCDEST _("Warning: 32-bit element size and same destination "\
943 "and source operands makes instruction UNPREDICTABLE")
944 #define BAD_EL_TYPE _("bad element type for instruction")
945 #define MVE_BAD_QREG _("MVE vector register Q[0..7] expected")
946
947 static struct hash_control * arm_ops_hsh;
948 static struct hash_control * arm_cond_hsh;
949 static struct hash_control * arm_vcond_hsh;
950 static struct hash_control * arm_shift_hsh;
951 static struct hash_control * arm_psr_hsh;
952 static struct hash_control * arm_v7m_psr_hsh;
953 static struct hash_control * arm_reg_hsh;
954 static struct hash_control * arm_reloc_hsh;
955 static struct hash_control * arm_barrier_opt_hsh;
956
957 /* Stuff needed to resolve the label ambiguity
958 As:
959 ...
960 label: <insn>
961 may differ from:
962 ...
963 label:
964 <insn> */
965
966 symbolS * last_label_seen;
967 static int label_is_thumb_function_name = FALSE;
968
969 /* Literal pool structure. Held on a per-section
970 and per-sub-section basis. */
971
972 #define MAX_LITERAL_POOL_SIZE 1024
973 typedef struct literal_pool
974 {
975 expressionS literals [MAX_LITERAL_POOL_SIZE];
976 unsigned int next_free_entry;
977 unsigned int id;
978 symbolS * symbol;
979 segT section;
980 subsegT sub_section;
981 #ifdef OBJ_ELF
982 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
983 #endif
984 struct literal_pool * next;
985 unsigned int alignment;
986 } literal_pool;
987
988 /* Pointer to a linked list of literal pools. */
989 literal_pool * list_of_pools = NULL;
990
991 typedef enum asmfunc_states
992 {
993 OUTSIDE_ASMFUNC,
994 WAITING_ASMFUNC_NAME,
995 WAITING_ENDASMFUNC
996 } asmfunc_states;
997
998 static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
999
1000 #ifdef OBJ_ELF
1001 # define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
1002 #else
1003 static struct current_pred now_pred;
1004 #endif
1005
1006 static inline int
1007 now_pred_compatible (int cond)
1008 {
1009 return (cond & ~1) == (now_pred.cc & ~1);
1010 }
1011
1012 static inline int
1013 conditional_insn (void)
1014 {
1015 return inst.cond != COND_ALWAYS;
1016 }
1017
1018 static int in_pred_block (void);
1019
1020 static int handle_pred_state (void);
1021
1022 static void force_automatic_it_block_close (void);
1023
1024 static void it_fsm_post_encode (void);
1025
1026 #define set_pred_insn_type(type) \
1027 do \
1028 { \
1029 inst.pred_insn_type = type; \
1030 if (handle_pred_state () == FAIL) \
1031 return; \
1032 } \
1033 while (0)
1034
1035 #define set_pred_insn_type_nonvoid(type, failret) \
1036 do \
1037 { \
1038 inst.pred_insn_type = type; \
1039 if (handle_pred_state () == FAIL) \
1040 return failret; \
1041 } \
1042 while(0)
1043
1044 #define set_pred_insn_type_last() \
1045 do \
1046 { \
1047 if (inst.cond == COND_ALWAYS) \
1048 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
1049 else \
1050 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
1051 } \
1052 while (0)
1053
1054 /* Toggle value[pos]. */
1055 #define TOGGLE_BIT(value, pos) (value ^ (1 << pos))
1056
1057 /* Pure syntax. */
1058
1059 /* This array holds the chars that always start a comment. If the
1060 pre-processor is disabled, these aren't very useful. */
1061 char arm_comment_chars[] = "@";
1062
1063 /* This array holds the chars that only start a comment at the beginning of
1064 a line. If the line seems to have the form '# 123 filename'
1065 .line and .file directives will appear in the pre-processed output. */
1066 /* Note that input_file.c hand checks for '#' at the beginning of the
1067 first line of the input file. This is because the compiler outputs
1068 #NO_APP at the beginning of its output. */
1069 /* Also note that comments like this one will always work. */
1070 const char line_comment_chars[] = "#";
1071
1072 char arm_line_separator_chars[] = ";";
1073
1074 /* Chars that can be used to separate mant
1075 from exp in floating point numbers. */
1076 const char EXP_CHARS[] = "eE";
1077
1078 /* Chars that mean this number is a floating point constant. */
1079 /* As in 0f12.456 */
1080 /* or 0d1.2345e12 */
1081
1082 const char FLT_CHARS[] = "rRsSfFdDxXeEpPHh";
1083
1084 /* Prefix characters that indicate the start of an immediate
1085 value. */
1086 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
1087
1088 /* Separator character handling. */
1089
1090 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1091
1092 enum fp_16bit_format
1093 {
1094 ARM_FP16_FORMAT_IEEE = 0x1,
1095 ARM_FP16_FORMAT_ALTERNATIVE = 0x2,
1096 ARM_FP16_FORMAT_DEFAULT = 0x3
1097 };
1098
1099 static enum fp_16bit_format fp16_format = ARM_FP16_FORMAT_DEFAULT;
1100
1101
1102 static inline int
1103 skip_past_char (char ** str, char c)
1104 {
1105 /* PR gas/14987: Allow for whitespace before the expected character. */
1106 skip_whitespace (*str);
1107
1108 if (**str == c)
1109 {
1110 (*str)++;
1111 return SUCCESS;
1112 }
1113 else
1114 return FAIL;
1115 }
1116
1117 #define skip_past_comma(str) skip_past_char (str, ',')
1118
1119 /* Arithmetic expressions (possibly involving symbols). */
1120
1121 /* Return TRUE if anything in the expression is a bignum. */
1122
1123 static bfd_boolean
1124 walk_no_bignums (symbolS * sp)
1125 {
1126 if (symbol_get_value_expression (sp)->X_op == O_big)
1127 return TRUE;
1128
1129 if (symbol_get_value_expression (sp)->X_add_symbol)
1130 {
1131 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1132 || (symbol_get_value_expression (sp)->X_op_symbol
1133 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
1134 }
1135
1136 return FALSE;
1137 }
1138
1139 static bfd_boolean in_my_get_expression = FALSE;
1140
1141 /* Third argument to my_get_expression. */
1142 #define GE_NO_PREFIX 0
1143 #define GE_IMM_PREFIX 1
1144 #define GE_OPT_PREFIX 2
1145 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1146 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1147 #define GE_OPT_PREFIX_BIG 3
1148
1149 static int
1150 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
1151 {
1152 char * save_in;
1153
1154 /* In unified syntax, all prefixes are optional. */
1155 if (unified_syntax)
1156 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
1157 : GE_OPT_PREFIX;
1158
1159 switch (prefix_mode)
1160 {
1161 case GE_NO_PREFIX: break;
1162 case GE_IMM_PREFIX:
1163 if (!is_immediate_prefix (**str))
1164 {
1165 inst.error = _("immediate expression requires a # prefix");
1166 return FAIL;
1167 }
1168 (*str)++;
1169 break;
1170 case GE_OPT_PREFIX:
1171 case GE_OPT_PREFIX_BIG:
1172 if (is_immediate_prefix (**str))
1173 (*str)++;
1174 break;
1175 default:
1176 abort ();
1177 }
1178
1179 memset (ep, 0, sizeof (expressionS));
1180
1181 save_in = input_line_pointer;
1182 input_line_pointer = *str;
1183 in_my_get_expression = TRUE;
1184 expression (ep);
1185 in_my_get_expression = FALSE;
1186
1187 if (ep->X_op == O_illegal || ep->X_op == O_absent)
1188 {
1189 /* We found a bad or missing expression in md_operand(). */
1190 *str = input_line_pointer;
1191 input_line_pointer = save_in;
1192 if (inst.error == NULL)
1193 inst.error = (ep->X_op == O_absent
1194 ? _("missing expression") :_("bad expression"));
1195 return 1;
1196 }
1197
1198 /* Get rid of any bignums now, so that we don't generate an error for which
1199 we can't establish a line number later on. Big numbers are never valid
1200 in instructions, which is where this routine is always called. */
1201 if (prefix_mode != GE_OPT_PREFIX_BIG
1202 && (ep->X_op == O_big
1203 || (ep->X_add_symbol
1204 && (walk_no_bignums (ep->X_add_symbol)
1205 || (ep->X_op_symbol
1206 && walk_no_bignums (ep->X_op_symbol))))))
1207 {
1208 inst.error = _("invalid constant");
1209 *str = input_line_pointer;
1210 input_line_pointer = save_in;
1211 return 1;
1212 }
1213
1214 *str = input_line_pointer;
1215 input_line_pointer = save_in;
1216 return SUCCESS;
1217 }
1218
1219 /* Turn a string in input_line_pointer into a floating point constant
1220 of type TYPE, and store the appropriate bytes in *LITP. The number
1221 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1222 returned, or NULL on OK.
1223
1224 Note that fp constants aren't represent in the normal way on the ARM.
1225 In big endian mode, things are as expected. However, in little endian
1226 mode fp constants are big-endian word-wise, and little-endian byte-wise
1227 within the words. For example, (double) 1.1 in big endian mode is
1228 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1229 the byte sequence 99 99 f1 3f 9a 99 99 99.
1230
1231 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1232
1233 const char *
1234 md_atof (int type, char * litP, int * sizeP)
1235 {
1236 int prec;
1237 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1238 char *t;
1239 int i;
1240
1241 switch (type)
1242 {
1243 case 'H':
1244 case 'h':
1245 prec = 1;
1246 break;
1247
1248 /* If this is a bfloat16, then parse it slightly differently, as it
1249 does not follow the IEEE specification for floating point numbers
1250 exactly. */
1251 case 'b':
1252 {
1253 FLONUM_TYPE generic_float;
1254
1255 t = atof_ieee_detail (input_line_pointer, 1, 8, words, &generic_float);
1256
1257 if (t)
1258 input_line_pointer = t;
1259 else
1260 return _("invalid floating point number");
1261
1262 switch (generic_float.sign)
1263 {
1264 /* Is +Inf. */
1265 case 'P':
1266 words[0] = 0x7f80;
1267 break;
1268
1269 /* Is -Inf. */
1270 case 'N':
1271 words[0] = 0xff80;
1272 break;
1273
1274 /* Is NaN. */
1275 /* bfloat16 has two types of NaN - quiet and signalling.
1276 Quiet NaN has bit[6] == 1 && faction != 0, whereas
1277 signalling NaN's have bit[0] == 0 && fraction != 0.
1278 Chosen this specific encoding as it is the same form
1279 as used by other IEEE 754 encodings in GAS. */
1280 case 0:
1281 words[0] = 0x7fff;
1282 break;
1283
1284 default:
1285 break;
1286 }
1287
1288 *sizeP = 2;
1289
1290 md_number_to_chars (litP, (valueT) words[0], sizeof (LITTLENUM_TYPE));
1291
1292 return NULL;
1293 }
1294 case 'f':
1295 case 'F':
1296 case 's':
1297 case 'S':
1298 prec = 2;
1299 break;
1300
1301 case 'd':
1302 case 'D':
1303 case 'r':
1304 case 'R':
1305 prec = 4;
1306 break;
1307
1308 case 'x':
1309 case 'X':
1310 prec = 5;
1311 break;
1312
1313 case 'p':
1314 case 'P':
1315 prec = 5;
1316 break;
1317
1318 default:
1319 *sizeP = 0;
1320 return _("Unrecognized or unsupported floating point constant");
1321 }
1322
1323 t = atof_ieee (input_line_pointer, type, words);
1324 if (t)
1325 input_line_pointer = t;
1326 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1327
1328 if (target_big_endian || prec == 1)
1329 for (i = 0; i < prec; i++)
1330 {
1331 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1332 litP += sizeof (LITTLENUM_TYPE);
1333 }
1334 else if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1335 for (i = prec - 1; i >= 0; i--)
1336 {
1337 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1338 litP += sizeof (LITTLENUM_TYPE);
1339 }
1340 else
1341 /* For a 4 byte float the order of elements in `words' is 1 0.
1342 For an 8 byte float the order is 1 0 3 2. */
1343 for (i = 0; i < prec; i += 2)
1344 {
1345 md_number_to_chars (litP, (valueT) words[i + 1],
1346 sizeof (LITTLENUM_TYPE));
1347 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1348 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1349 litP += 2 * sizeof (LITTLENUM_TYPE);
1350 }
1351
1352 return NULL;
1353 }
1354
1355 /* We handle all bad expressions here, so that we can report the faulty
1356 instruction in the error message. */
1357
1358 void
1359 md_operand (expressionS * exp)
1360 {
1361 if (in_my_get_expression)
1362 exp->X_op = O_illegal;
1363 }
1364
1365 /* Immediate values. */
1366
1367 #ifdef OBJ_ELF
1368 /* Generic immediate-value read function for use in directives.
1369 Accepts anything that 'expression' can fold to a constant.
1370 *val receives the number. */
1371
1372 static int
1373 immediate_for_directive (int *val)
1374 {
1375 expressionS exp;
1376 exp.X_op = O_illegal;
1377
1378 if (is_immediate_prefix (*input_line_pointer))
1379 {
1380 input_line_pointer++;
1381 expression (&exp);
1382 }
1383
1384 if (exp.X_op != O_constant)
1385 {
1386 as_bad (_("expected #constant"));
1387 ignore_rest_of_line ();
1388 return FAIL;
1389 }
1390 *val = exp.X_add_number;
1391 return SUCCESS;
1392 }
1393 #endif
1394
1395 /* Register parsing. */
1396
1397 /* Generic register parser. CCP points to what should be the
1398 beginning of a register name. If it is indeed a valid register
1399 name, advance CCP over it and return the reg_entry structure;
1400 otherwise return NULL. Does not issue diagnostics. */
1401
1402 static struct reg_entry *
1403 arm_reg_parse_multi (char **ccp)
1404 {
1405 char *start = *ccp;
1406 char *p;
1407 struct reg_entry *reg;
1408
1409 skip_whitespace (start);
1410
1411 #ifdef REGISTER_PREFIX
1412 if (*start != REGISTER_PREFIX)
1413 return NULL;
1414 start++;
1415 #endif
1416 #ifdef OPTIONAL_REGISTER_PREFIX
1417 if (*start == OPTIONAL_REGISTER_PREFIX)
1418 start++;
1419 #endif
1420
1421 p = start;
1422 if (!ISALPHA (*p) || !is_name_beginner (*p))
1423 return NULL;
1424
1425 do
1426 p++;
1427 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1428
1429 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1430
1431 if (!reg)
1432 return NULL;
1433
1434 *ccp = p;
1435 return reg;
1436 }
1437
1438 static int
1439 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1440 enum arm_reg_type type)
1441 {
1442 /* Alternative syntaxes are accepted for a few register classes. */
1443 switch (type)
1444 {
1445 case REG_TYPE_MVF:
1446 case REG_TYPE_MVD:
1447 case REG_TYPE_MVFX:
1448 case REG_TYPE_MVDX:
1449 /* Generic coprocessor register names are allowed for these. */
1450 if (reg && reg->type == REG_TYPE_CN)
1451 return reg->number;
1452 break;
1453
1454 case REG_TYPE_CP:
1455 /* For backward compatibility, a bare number is valid here. */
1456 {
1457 unsigned long processor = strtoul (start, ccp, 10);
1458 if (*ccp != start && processor <= 15)
1459 return processor;
1460 }
1461 /* Fall through. */
1462
1463 case REG_TYPE_MMXWC:
1464 /* WC includes WCG. ??? I'm not sure this is true for all
1465 instructions that take WC registers. */
1466 if (reg && reg->type == REG_TYPE_MMXWCG)
1467 return reg->number;
1468 break;
1469
1470 default:
1471 break;
1472 }
1473
1474 return FAIL;
1475 }
1476
1477 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1478 return value is the register number or FAIL. */
1479
1480 static int
1481 arm_reg_parse (char **ccp, enum arm_reg_type type)
1482 {
1483 char *start = *ccp;
1484 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1485 int ret;
1486
1487 /* Do not allow a scalar (reg+index) to parse as a register. */
1488 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1489 return FAIL;
1490
1491 if (reg && reg->type == type)
1492 return reg->number;
1493
1494 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1495 return ret;
1496
1497 *ccp = start;
1498 return FAIL;
1499 }
1500
1501 /* Parse a Neon type specifier. *STR should point at the leading '.'
1502 character. Does no verification at this stage that the type fits the opcode
1503 properly. E.g.,
1504
1505 .i32.i32.s16
1506 .s32.f32
1507 .u16
1508
1509 Can all be legally parsed by this function.
1510
1511 Fills in neon_type struct pointer with parsed information, and updates STR
1512 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1513 type, FAIL if not. */
1514
1515 static int
1516 parse_neon_type (struct neon_type *type, char **str)
1517 {
1518 char *ptr = *str;
1519
1520 if (type)
1521 type->elems = 0;
1522
1523 while (type->elems < NEON_MAX_TYPE_ELS)
1524 {
1525 enum neon_el_type thistype = NT_untyped;
1526 unsigned thissize = -1u;
1527
1528 if (*ptr != '.')
1529 break;
1530
1531 ptr++;
1532
1533 /* Just a size without an explicit type. */
1534 if (ISDIGIT (*ptr))
1535 goto parsesize;
1536
1537 switch (TOLOWER (*ptr))
1538 {
1539 case 'i': thistype = NT_integer; break;
1540 case 'f': thistype = NT_float; break;
1541 case 'p': thistype = NT_poly; break;
1542 case 's': thistype = NT_signed; break;
1543 case 'u': thistype = NT_unsigned; break;
1544 case 'd':
1545 thistype = NT_float;
1546 thissize = 64;
1547 ptr++;
1548 goto done;
1549 case 'b':
1550 thistype = NT_bfloat;
1551 switch (TOLOWER (*(++ptr)))
1552 {
1553 case 'f':
1554 ptr += 1;
1555 thissize = strtoul (ptr, &ptr, 10);
1556 if (thissize != 16)
1557 {
1558 as_bad (_("bad size %d in type specifier"), thissize);
1559 return FAIL;
1560 }
1561 goto done;
1562 case '0': case '1': case '2': case '3': case '4':
1563 case '5': case '6': case '7': case '8': case '9':
1564 case ' ': case '.':
1565 as_bad (_("unexpected type character `b' -- did you mean `bf'?"));
1566 return FAIL;
1567 default:
1568 break;
1569 }
1570 break;
1571 default:
1572 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1573 return FAIL;
1574 }
1575
1576 ptr++;
1577
1578 /* .f is an abbreviation for .f32. */
1579 if (thistype == NT_float && !ISDIGIT (*ptr))
1580 thissize = 32;
1581 else
1582 {
1583 parsesize:
1584 thissize = strtoul (ptr, &ptr, 10);
1585
1586 if (thissize != 8 && thissize != 16 && thissize != 32
1587 && thissize != 64)
1588 {
1589 as_bad (_("bad size %d in type specifier"), thissize);
1590 return FAIL;
1591 }
1592 }
1593
1594 done:
1595 if (type)
1596 {
1597 type->el[type->elems].type = thistype;
1598 type->el[type->elems].size = thissize;
1599 type->elems++;
1600 }
1601 }
1602
1603 /* Empty/missing type is not a successful parse. */
1604 if (type->elems == 0)
1605 return FAIL;
1606
1607 *str = ptr;
1608
1609 return SUCCESS;
1610 }
1611
1612 /* Errors may be set multiple times during parsing or bit encoding
1613 (particularly in the Neon bits), but usually the earliest error which is set
1614 will be the most meaningful. Avoid overwriting it with later (cascading)
1615 errors by calling this function. */
1616
1617 static void
1618 first_error (const char *err)
1619 {
1620 if (!inst.error)
1621 inst.error = err;
1622 }
1623
1624 /* Parse a single type, e.g. ".s32", leading period included. */
1625 static int
1626 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1627 {
1628 char *str = *ccp;
1629 struct neon_type optype;
1630
1631 if (*str == '.')
1632 {
1633 if (parse_neon_type (&optype, &str) == SUCCESS)
1634 {
1635 if (optype.elems == 1)
1636 *vectype = optype.el[0];
1637 else
1638 {
1639 first_error (_("only one type should be specified for operand"));
1640 return FAIL;
1641 }
1642 }
1643 else
1644 {
1645 first_error (_("vector type expected"));
1646 return FAIL;
1647 }
1648 }
1649 else
1650 return FAIL;
1651
1652 *ccp = str;
1653
1654 return SUCCESS;
1655 }
1656
1657 /* Special meanings for indices (which have a range of 0-7), which will fit into
1658 a 4-bit integer. */
1659
1660 #define NEON_ALL_LANES 15
1661 #define NEON_INTERLEAVE_LANES 14
1662
1663 /* Record a use of the given feature. */
1664 static void
1665 record_feature_use (const arm_feature_set *feature)
1666 {
1667 if (thumb_mode)
1668 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1669 else
1670 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1671 }
1672
1673 /* If the given feature available in the selected CPU, mark it as used.
1674 Returns TRUE iff feature is available. */
1675 static bfd_boolean
1676 mark_feature_used (const arm_feature_set *feature)
1677 {
1678
1679 /* Do not support the use of MVE only instructions when in auto-detection or
1680 -march=all. */
1681 if (((feature == &mve_ext) || (feature == &mve_fp_ext))
1682 && ARM_CPU_IS_ANY (cpu_variant))
1683 {
1684 first_error (BAD_MVE_AUTO);
1685 return FALSE;
1686 }
1687 /* Ensure the option is valid on the current architecture. */
1688 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1689 return FALSE;
1690
1691 /* Add the appropriate architecture feature for the barrier option used.
1692 */
1693 record_feature_use (feature);
1694
1695 return TRUE;
1696 }
1697
1698 /* Parse either a register or a scalar, with an optional type. Return the
1699 register number, and optionally fill in the actual type of the register
1700 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1701 type/index information in *TYPEINFO. */
1702
1703 static int
1704 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1705 enum arm_reg_type *rtype,
1706 struct neon_typed_alias *typeinfo)
1707 {
1708 char *str = *ccp;
1709 struct reg_entry *reg = arm_reg_parse_multi (&str);
1710 struct neon_typed_alias atype;
1711 struct neon_type_el parsetype;
1712
1713 atype.defined = 0;
1714 atype.index = -1;
1715 atype.eltype.type = NT_invtype;
1716 atype.eltype.size = -1;
1717
1718 /* Try alternate syntax for some types of register. Note these are mutually
1719 exclusive with the Neon syntax extensions. */
1720 if (reg == NULL)
1721 {
1722 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1723 if (altreg != FAIL)
1724 *ccp = str;
1725 if (typeinfo)
1726 *typeinfo = atype;
1727 return altreg;
1728 }
1729
1730 /* Undo polymorphism when a set of register types may be accepted. */
1731 if ((type == REG_TYPE_NDQ
1732 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1733 || (type == REG_TYPE_VFSD
1734 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1735 || (type == REG_TYPE_NSDQ
1736 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1737 || reg->type == REG_TYPE_NQ))
1738 || (type == REG_TYPE_NSD
1739 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1740 || (type == REG_TYPE_MMXWC
1741 && (reg->type == REG_TYPE_MMXWCG)))
1742 type = (enum arm_reg_type) reg->type;
1743
1744 if (type == REG_TYPE_MQ)
1745 {
1746 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1747 return FAIL;
1748
1749 if (!reg || reg->type != REG_TYPE_NQ)
1750 return FAIL;
1751
1752 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1753 {
1754 first_error (_("expected MVE register [q0..q7]"));
1755 return FAIL;
1756 }
1757 type = REG_TYPE_NQ;
1758 }
1759 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1760 && (type == REG_TYPE_NQ))
1761 return FAIL;
1762
1763
1764 if (type != reg->type)
1765 return FAIL;
1766
1767 if (reg->neon)
1768 atype = *reg->neon;
1769
1770 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1771 {
1772 if ((atype.defined & NTA_HASTYPE) != 0)
1773 {
1774 first_error (_("can't redefine type for operand"));
1775 return FAIL;
1776 }
1777 atype.defined |= NTA_HASTYPE;
1778 atype.eltype = parsetype;
1779 }
1780
1781 if (skip_past_char (&str, '[') == SUCCESS)
1782 {
1783 if (type != REG_TYPE_VFD
1784 && !(type == REG_TYPE_VFS
1785 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))
1786 && !(type == REG_TYPE_NQ
1787 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
1788 {
1789 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1790 first_error (_("only D and Q registers may be indexed"));
1791 else
1792 first_error (_("only D registers may be indexed"));
1793 return FAIL;
1794 }
1795
1796 if ((atype.defined & NTA_HASINDEX) != 0)
1797 {
1798 first_error (_("can't change index for operand"));
1799 return FAIL;
1800 }
1801
1802 atype.defined |= NTA_HASINDEX;
1803
1804 if (skip_past_char (&str, ']') == SUCCESS)
1805 atype.index = NEON_ALL_LANES;
1806 else
1807 {
1808 expressionS exp;
1809
1810 my_get_expression (&exp, &str, GE_NO_PREFIX);
1811
1812 if (exp.X_op != O_constant)
1813 {
1814 first_error (_("constant expression required"));
1815 return FAIL;
1816 }
1817
1818 if (skip_past_char (&str, ']') == FAIL)
1819 return FAIL;
1820
1821 atype.index = exp.X_add_number;
1822 }
1823 }
1824
1825 if (typeinfo)
1826 *typeinfo = atype;
1827
1828 if (rtype)
1829 *rtype = type;
1830
1831 *ccp = str;
1832
1833 return reg->number;
1834 }
1835
1836 /* Like arm_reg_parse, but also allow the following extra features:
1837 - If RTYPE is non-zero, return the (possibly restricted) type of the
1838 register (e.g. Neon double or quad reg when either has been requested).
1839 - If this is a Neon vector type with additional type information, fill
1840 in the struct pointed to by VECTYPE (if non-NULL).
1841 This function will fault on encountering a scalar. */
1842
1843 static int
1844 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1845 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1846 {
1847 struct neon_typed_alias atype;
1848 char *str = *ccp;
1849 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1850
1851 if (reg == FAIL)
1852 return FAIL;
1853
1854 /* Do not allow regname(... to parse as a register. */
1855 if (*str == '(')
1856 return FAIL;
1857
1858 /* Do not allow a scalar (reg+index) to parse as a register. */
1859 if ((atype.defined & NTA_HASINDEX) != 0)
1860 {
1861 first_error (_("register operand expected, but got scalar"));
1862 return FAIL;
1863 }
1864
1865 if (vectype)
1866 *vectype = atype.eltype;
1867
1868 *ccp = str;
1869
1870 return reg;
1871 }
1872
1873 #define NEON_SCALAR_REG(X) ((X) >> 4)
1874 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1875
1876 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1877 have enough information to be able to do a good job bounds-checking. So, we
1878 just do easy checks here, and do further checks later. */
1879
1880 static int
1881 parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum
1882 arm_reg_type reg_type)
1883 {
1884 int reg;
1885 char *str = *ccp;
1886 struct neon_typed_alias atype;
1887 unsigned reg_size;
1888
1889 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
1890
1891 switch (reg_type)
1892 {
1893 case REG_TYPE_VFS:
1894 reg_size = 32;
1895 break;
1896 case REG_TYPE_VFD:
1897 reg_size = 64;
1898 break;
1899 case REG_TYPE_MQ:
1900 reg_size = 128;
1901 break;
1902 default:
1903 gas_assert (0);
1904 return FAIL;
1905 }
1906
1907 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1908 return FAIL;
1909
1910 if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES)
1911 {
1912 first_error (_("scalar must have an index"));
1913 return FAIL;
1914 }
1915 else if (atype.index >= reg_size / elsize)
1916 {
1917 first_error (_("scalar index out of range"));
1918 return FAIL;
1919 }
1920
1921 if (type)
1922 *type = atype.eltype;
1923
1924 *ccp = str;
1925
1926 return reg * 16 + atype.index;
1927 }
1928
1929 /* Types of registers in a list. */
1930
1931 enum reg_list_els
1932 {
1933 REGLIST_RN,
1934 REGLIST_CLRM,
1935 REGLIST_VFP_S,
1936 REGLIST_VFP_S_VPR,
1937 REGLIST_VFP_D,
1938 REGLIST_VFP_D_VPR,
1939 REGLIST_NEON_D
1940 };
1941
1942 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1943
1944 static long
1945 parse_reg_list (char ** strp, enum reg_list_els etype)
1946 {
1947 char *str = *strp;
1948 long range = 0;
1949 int another_range;
1950
1951 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM);
1952
1953 /* We come back here if we get ranges concatenated by '+' or '|'. */
1954 do
1955 {
1956 skip_whitespace (str);
1957
1958 another_range = 0;
1959
1960 if (*str == '{')
1961 {
1962 int in_range = 0;
1963 int cur_reg = -1;
1964
1965 str++;
1966 do
1967 {
1968 int reg;
1969 const char apsr_str[] = "apsr";
1970 int apsr_str_len = strlen (apsr_str);
1971
1972 reg = arm_reg_parse (&str, REG_TYPE_RN);
1973 if (etype == REGLIST_CLRM)
1974 {
1975 if (reg == REG_SP || reg == REG_PC)
1976 reg = FAIL;
1977 else if (reg == FAIL
1978 && !strncasecmp (str, apsr_str, apsr_str_len)
1979 && !ISALPHA (*(str + apsr_str_len)))
1980 {
1981 reg = 15;
1982 str += apsr_str_len;
1983 }
1984
1985 if (reg == FAIL)
1986 {
1987 first_error (_("r0-r12, lr or APSR expected"));
1988 return FAIL;
1989 }
1990 }
1991 else /* etype == REGLIST_RN. */
1992 {
1993 if (reg == FAIL)
1994 {
1995 first_error (_(reg_expected_msgs[REGLIST_RN]));
1996 return FAIL;
1997 }
1998 }
1999
2000 if (in_range)
2001 {
2002 int i;
2003
2004 if (reg <= cur_reg)
2005 {
2006 first_error (_("bad range in register list"));
2007 return FAIL;
2008 }
2009
2010 for (i = cur_reg + 1; i < reg; i++)
2011 {
2012 if (range & (1 << i))
2013 as_tsktsk
2014 (_("Warning: duplicated register (r%d) in register list"),
2015 i);
2016 else
2017 range |= 1 << i;
2018 }
2019 in_range = 0;
2020 }
2021
2022 if (range & (1 << reg))
2023 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
2024 reg);
2025 else if (reg <= cur_reg)
2026 as_tsktsk (_("Warning: register range not in ascending order"));
2027
2028 range |= 1 << reg;
2029 cur_reg = reg;
2030 }
2031 while (skip_past_comma (&str) != FAIL
2032 || (in_range = 1, *str++ == '-'));
2033 str--;
2034
2035 if (skip_past_char (&str, '}') == FAIL)
2036 {
2037 first_error (_("missing `}'"));
2038 return FAIL;
2039 }
2040 }
2041 else if (etype == REGLIST_RN)
2042 {
2043 expressionS exp;
2044
2045 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
2046 return FAIL;
2047
2048 if (exp.X_op == O_constant)
2049 {
2050 if (exp.X_add_number
2051 != (exp.X_add_number & 0x0000ffff))
2052 {
2053 inst.error = _("invalid register mask");
2054 return FAIL;
2055 }
2056
2057 if ((range & exp.X_add_number) != 0)
2058 {
2059 int regno = range & exp.X_add_number;
2060
2061 regno &= -regno;
2062 regno = (1 << regno) - 1;
2063 as_tsktsk
2064 (_("Warning: duplicated register (r%d) in register list"),
2065 regno);
2066 }
2067
2068 range |= exp.X_add_number;
2069 }
2070 else
2071 {
2072 if (inst.relocs[0].type != 0)
2073 {
2074 inst.error = _("expression too complex");
2075 return FAIL;
2076 }
2077
2078 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
2079 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
2080 inst.relocs[0].pc_rel = 0;
2081 }
2082 }
2083
2084 if (*str == '|' || *str == '+')
2085 {
2086 str++;
2087 another_range = 1;
2088 }
2089 }
2090 while (another_range);
2091
2092 *strp = str;
2093 return range;
2094 }
2095
2096 /* Parse a VFP register list. If the string is invalid return FAIL.
2097 Otherwise return the number of registers, and set PBASE to the first
2098 register. Parses registers of type ETYPE.
2099 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
2100 - Q registers can be used to specify pairs of D registers
2101 - { } can be omitted from around a singleton register list
2102 FIXME: This is not implemented, as it would require backtracking in
2103 some cases, e.g.:
2104 vtbl.8 d3,d4,d5
2105 This could be done (the meaning isn't really ambiguous), but doesn't
2106 fit in well with the current parsing framework.
2107 - 32 D registers may be used (also true for VFPv3).
2108 FIXME: Types are ignored in these register lists, which is probably a
2109 bug. */
2110
2111 static int
2112 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
2113 bfd_boolean *partial_match)
2114 {
2115 char *str = *ccp;
2116 int base_reg;
2117 int new_base;
2118 enum arm_reg_type regtype = (enum arm_reg_type) 0;
2119 int max_regs = 0;
2120 int count = 0;
2121 int warned = 0;
2122 unsigned long mask = 0;
2123 int i;
2124 bfd_boolean vpr_seen = FALSE;
2125 bfd_boolean expect_vpr =
2126 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
2127
2128 if (skip_past_char (&str, '{') == FAIL)
2129 {
2130 inst.error = _("expecting {");
2131 return FAIL;
2132 }
2133
2134 switch (etype)
2135 {
2136 case REGLIST_VFP_S:
2137 case REGLIST_VFP_S_VPR:
2138 regtype = REG_TYPE_VFS;
2139 max_regs = 32;
2140 break;
2141
2142 case REGLIST_VFP_D:
2143 case REGLIST_VFP_D_VPR:
2144 regtype = REG_TYPE_VFD;
2145 break;
2146
2147 case REGLIST_NEON_D:
2148 regtype = REG_TYPE_NDQ;
2149 break;
2150
2151 default:
2152 gas_assert (0);
2153 }
2154
2155 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
2156 {
2157 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
2158 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
2159 {
2160 max_regs = 32;
2161 if (thumb_mode)
2162 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
2163 fpu_vfp_ext_d32);
2164 else
2165 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
2166 fpu_vfp_ext_d32);
2167 }
2168 else
2169 max_regs = 16;
2170 }
2171
2172 base_reg = max_regs;
2173 *partial_match = FALSE;
2174
2175 do
2176 {
2177 int setmask = 1, addregs = 1;
2178 const char vpr_str[] = "vpr";
2179 int vpr_str_len = strlen (vpr_str);
2180
2181 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
2182
2183 if (expect_vpr)
2184 {
2185 if (new_base == FAIL
2186 && !strncasecmp (str, vpr_str, vpr_str_len)
2187 && !ISALPHA (*(str + vpr_str_len))
2188 && !vpr_seen)
2189 {
2190 vpr_seen = TRUE;
2191 str += vpr_str_len;
2192 if (count == 0)
2193 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2194 }
2195 else if (vpr_seen)
2196 {
2197 first_error (_("VPR expected last"));
2198 return FAIL;
2199 }
2200 else if (new_base == FAIL)
2201 {
2202 if (regtype == REG_TYPE_VFS)
2203 first_error (_("VFP single precision register or VPR "
2204 "expected"));
2205 else /* regtype == REG_TYPE_VFD. */
2206 first_error (_("VFP/Neon double precision register or VPR "
2207 "expected"));
2208 return FAIL;
2209 }
2210 }
2211 else if (new_base == FAIL)
2212 {
2213 first_error (_(reg_expected_msgs[regtype]));
2214 return FAIL;
2215 }
2216
2217 *partial_match = TRUE;
2218 if (vpr_seen)
2219 continue;
2220
2221 if (new_base >= max_regs)
2222 {
2223 first_error (_("register out of range in list"));
2224 return FAIL;
2225 }
2226
2227 /* Note: a value of 2 * n is returned for the register Q<n>. */
2228 if (regtype == REG_TYPE_NQ)
2229 {
2230 setmask = 3;
2231 addregs = 2;
2232 }
2233
2234 if (new_base < base_reg)
2235 base_reg = new_base;
2236
2237 if (mask & (setmask << new_base))
2238 {
2239 first_error (_("invalid register list"));
2240 return FAIL;
2241 }
2242
2243 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
2244 {
2245 as_tsktsk (_("register list not in ascending order"));
2246 warned = 1;
2247 }
2248
2249 mask |= setmask << new_base;
2250 count += addregs;
2251
2252 if (*str == '-') /* We have the start of a range expression */
2253 {
2254 int high_range;
2255
2256 str++;
2257
2258 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
2259 == FAIL)
2260 {
2261 inst.error = gettext (reg_expected_msgs[regtype]);
2262 return FAIL;
2263 }
2264
2265 if (high_range >= max_regs)
2266 {
2267 first_error (_("register out of range in list"));
2268 return FAIL;
2269 }
2270
2271 if (regtype == REG_TYPE_NQ)
2272 high_range = high_range + 1;
2273
2274 if (high_range <= new_base)
2275 {
2276 inst.error = _("register range not in ascending order");
2277 return FAIL;
2278 }
2279
2280 for (new_base += addregs; new_base <= high_range; new_base += addregs)
2281 {
2282 if (mask & (setmask << new_base))
2283 {
2284 inst.error = _("invalid register list");
2285 return FAIL;
2286 }
2287
2288 mask |= setmask << new_base;
2289 count += addregs;
2290 }
2291 }
2292 }
2293 while (skip_past_comma (&str) != FAIL);
2294
2295 str++;
2296
2297 /* Sanity check -- should have raised a parse error above. */
2298 if ((!vpr_seen && count == 0) || count > max_regs)
2299 abort ();
2300
2301 *pbase = base_reg;
2302
2303 if (expect_vpr && !vpr_seen)
2304 {
2305 first_error (_("VPR expected last"));
2306 return FAIL;
2307 }
2308
2309 /* Final test -- the registers must be consecutive. */
2310 mask >>= base_reg;
2311 for (i = 0; i < count; i++)
2312 {
2313 if ((mask & (1u << i)) == 0)
2314 {
2315 inst.error = _("non-contiguous register range");
2316 return FAIL;
2317 }
2318 }
2319
2320 *ccp = str;
2321
2322 return count;
2323 }
2324
2325 /* True if two alias types are the same. */
2326
2327 static bfd_boolean
2328 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2329 {
2330 if (!a && !b)
2331 return TRUE;
2332
2333 if (!a || !b)
2334 return FALSE;
2335
2336 if (a->defined != b->defined)
2337 return FALSE;
2338
2339 if ((a->defined & NTA_HASTYPE) != 0
2340 && (a->eltype.type != b->eltype.type
2341 || a->eltype.size != b->eltype.size))
2342 return FALSE;
2343
2344 if ((a->defined & NTA_HASINDEX) != 0
2345 && (a->index != b->index))
2346 return FALSE;
2347
2348 return TRUE;
2349 }
2350
2351 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2352 The base register is put in *PBASE.
2353 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
2354 the return value.
2355 The register stride (minus one) is put in bit 4 of the return value.
2356 Bits [6:5] encode the list length (minus one).
2357 The type of the list elements is put in *ELTYPE, if non-NULL. */
2358
2359 #define NEON_LANE(X) ((X) & 0xf)
2360 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
2361 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2362
2363 static int
2364 parse_neon_el_struct_list (char **str, unsigned *pbase,
2365 int mve,
2366 struct neon_type_el *eltype)
2367 {
2368 char *ptr = *str;
2369 int base_reg = -1;
2370 int reg_incr = -1;
2371 int count = 0;
2372 int lane = -1;
2373 int leading_brace = 0;
2374 enum arm_reg_type rtype = REG_TYPE_NDQ;
2375 const char *const incr_error = mve ? _("register stride must be 1") :
2376 _("register stride must be 1 or 2");
2377 const char *const type_error = _("mismatched element/structure types in list");
2378 struct neon_typed_alias firsttype;
2379 firsttype.defined = 0;
2380 firsttype.eltype.type = NT_invtype;
2381 firsttype.eltype.size = -1;
2382 firsttype.index = -1;
2383
2384 if (skip_past_char (&ptr, '{') == SUCCESS)
2385 leading_brace = 1;
2386
2387 do
2388 {
2389 struct neon_typed_alias atype;
2390 if (mve)
2391 rtype = REG_TYPE_MQ;
2392 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2393
2394 if (getreg == FAIL)
2395 {
2396 first_error (_(reg_expected_msgs[rtype]));
2397 return FAIL;
2398 }
2399
2400 if (base_reg == -1)
2401 {
2402 base_reg = getreg;
2403 if (rtype == REG_TYPE_NQ)
2404 {
2405 reg_incr = 1;
2406 }
2407 firsttype = atype;
2408 }
2409 else if (reg_incr == -1)
2410 {
2411 reg_incr = getreg - base_reg;
2412 if (reg_incr < 1 || reg_incr > 2)
2413 {
2414 first_error (_(incr_error));
2415 return FAIL;
2416 }
2417 }
2418 else if (getreg != base_reg + reg_incr * count)
2419 {
2420 first_error (_(incr_error));
2421 return FAIL;
2422 }
2423
2424 if (! neon_alias_types_same (&atype, &firsttype))
2425 {
2426 first_error (_(type_error));
2427 return FAIL;
2428 }
2429
2430 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
2431 modes. */
2432 if (ptr[0] == '-')
2433 {
2434 struct neon_typed_alias htype;
2435 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2436 if (lane == -1)
2437 lane = NEON_INTERLEAVE_LANES;
2438 else if (lane != NEON_INTERLEAVE_LANES)
2439 {
2440 first_error (_(type_error));
2441 return FAIL;
2442 }
2443 if (reg_incr == -1)
2444 reg_incr = 1;
2445 else if (reg_incr != 1)
2446 {
2447 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2448 return FAIL;
2449 }
2450 ptr++;
2451 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2452 if (hireg == FAIL)
2453 {
2454 first_error (_(reg_expected_msgs[rtype]));
2455 return FAIL;
2456 }
2457 if (! neon_alias_types_same (&htype, &firsttype))
2458 {
2459 first_error (_(type_error));
2460 return FAIL;
2461 }
2462 count += hireg + dregs - getreg;
2463 continue;
2464 }
2465
2466 /* If we're using Q registers, we can't use [] or [n] syntax. */
2467 if (rtype == REG_TYPE_NQ)
2468 {
2469 count += 2;
2470 continue;
2471 }
2472
2473 if ((atype.defined & NTA_HASINDEX) != 0)
2474 {
2475 if (lane == -1)
2476 lane = atype.index;
2477 else if (lane != atype.index)
2478 {
2479 first_error (_(type_error));
2480 return FAIL;
2481 }
2482 }
2483 else if (lane == -1)
2484 lane = NEON_INTERLEAVE_LANES;
2485 else if (lane != NEON_INTERLEAVE_LANES)
2486 {
2487 first_error (_(type_error));
2488 return FAIL;
2489 }
2490 count++;
2491 }
2492 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2493
2494 /* No lane set by [x]. We must be interleaving structures. */
2495 if (lane == -1)
2496 lane = NEON_INTERLEAVE_LANES;
2497
2498 /* Sanity check. */
2499 if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4)
2500 || (count > 1 && reg_incr == -1))
2501 {
2502 first_error (_("error parsing element/structure list"));
2503 return FAIL;
2504 }
2505
2506 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2507 {
2508 first_error (_("expected }"));
2509 return FAIL;
2510 }
2511
2512 if (reg_incr == -1)
2513 reg_incr = 1;
2514
2515 if (eltype)
2516 *eltype = firsttype.eltype;
2517
2518 *pbase = base_reg;
2519 *str = ptr;
2520
2521 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2522 }
2523
2524 /* Parse an explicit relocation suffix on an expression. This is
2525 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2526 arm_reloc_hsh contains no entries, so this function can only
2527 succeed if there is no () after the word. Returns -1 on error,
2528 BFD_RELOC_UNUSED if there wasn't any suffix. */
2529
2530 static int
2531 parse_reloc (char **str)
2532 {
2533 struct reloc_entry *r;
2534 char *p, *q;
2535
2536 if (**str != '(')
2537 return BFD_RELOC_UNUSED;
2538
2539 p = *str + 1;
2540 q = p;
2541
2542 while (*q && *q != ')' && *q != ',')
2543 q++;
2544 if (*q != ')')
2545 return -1;
2546
2547 if ((r = (struct reloc_entry *)
2548 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2549 return -1;
2550
2551 *str = q + 1;
2552 return r->reloc;
2553 }
2554
2555 /* Directives: register aliases. */
2556
2557 static struct reg_entry *
2558 insert_reg_alias (char *str, unsigned number, int type)
2559 {
2560 struct reg_entry *new_reg;
2561 const char *name;
2562
2563 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2564 {
2565 if (new_reg->builtin)
2566 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2567
2568 /* Only warn about a redefinition if it's not defined as the
2569 same register. */
2570 else if (new_reg->number != number || new_reg->type != type)
2571 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2572
2573 return NULL;
2574 }
2575
2576 name = xstrdup (str);
2577 new_reg = XNEW (struct reg_entry);
2578
2579 new_reg->name = name;
2580 new_reg->number = number;
2581 new_reg->type = type;
2582 new_reg->builtin = FALSE;
2583 new_reg->neon = NULL;
2584
2585 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2586 abort ();
2587
2588 return new_reg;
2589 }
2590
2591 static void
2592 insert_neon_reg_alias (char *str, int number, int type,
2593 struct neon_typed_alias *atype)
2594 {
2595 struct reg_entry *reg = insert_reg_alias (str, number, type);
2596
2597 if (!reg)
2598 {
2599 first_error (_("attempt to redefine typed alias"));
2600 return;
2601 }
2602
2603 if (atype)
2604 {
2605 reg->neon = XNEW (struct neon_typed_alias);
2606 *reg->neon = *atype;
2607 }
2608 }
2609
2610 /* Look for the .req directive. This is of the form:
2611
2612 new_register_name .req existing_register_name
2613
2614 If we find one, or if it looks sufficiently like one that we want to
2615 handle any error here, return TRUE. Otherwise return FALSE. */
2616
2617 static bfd_boolean
2618 create_register_alias (char * newname, char *p)
2619 {
2620 struct reg_entry *old;
2621 char *oldname, *nbuf;
2622 size_t nlen;
2623
2624 /* The input scrubber ensures that whitespace after the mnemonic is
2625 collapsed to single spaces. */
2626 oldname = p;
2627 if (strncmp (oldname, " .req ", 6) != 0)
2628 return FALSE;
2629
2630 oldname += 6;
2631 if (*oldname == '\0')
2632 return FALSE;
2633
2634 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2635 if (!old)
2636 {
2637 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2638 return TRUE;
2639 }
2640
2641 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2642 the desired alias name, and p points to its end. If not, then
2643 the desired alias name is in the global original_case_string. */
2644 #ifdef TC_CASE_SENSITIVE
2645 nlen = p - newname;
2646 #else
2647 newname = original_case_string;
2648 nlen = strlen (newname);
2649 #endif
2650
2651 nbuf = xmemdup0 (newname, nlen);
2652
2653 /* Create aliases under the new name as stated; an all-lowercase
2654 version of the new name; and an all-uppercase version of the new
2655 name. */
2656 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2657 {
2658 for (p = nbuf; *p; p++)
2659 *p = TOUPPER (*p);
2660
2661 if (strncmp (nbuf, newname, nlen))
2662 {
2663 /* If this attempt to create an additional alias fails, do not bother
2664 trying to create the all-lower case alias. We will fail and issue
2665 a second, duplicate error message. This situation arises when the
2666 programmer does something like:
2667 foo .req r0
2668 Foo .req r1
2669 The second .req creates the "Foo" alias but then fails to create
2670 the artificial FOO alias because it has already been created by the
2671 first .req. */
2672 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2673 {
2674 free (nbuf);
2675 return TRUE;
2676 }
2677 }
2678
2679 for (p = nbuf; *p; p++)
2680 *p = TOLOWER (*p);
2681
2682 if (strncmp (nbuf, newname, nlen))
2683 insert_reg_alias (nbuf, old->number, old->type);
2684 }
2685
2686 free (nbuf);
2687 return TRUE;
2688 }
2689
2690 /* Create a Neon typed/indexed register alias using directives, e.g.:
2691 X .dn d5.s32[1]
2692 Y .qn 6.s16
2693 Z .dn d7
2694 T .dn Z[0]
2695 These typed registers can be used instead of the types specified after the
2696 Neon mnemonic, so long as all operands given have types. Types can also be
2697 specified directly, e.g.:
2698 vadd d0.s32, d1.s32, d2.s32 */
2699
2700 static bfd_boolean
2701 create_neon_reg_alias (char *newname, char *p)
2702 {
2703 enum arm_reg_type basetype;
2704 struct reg_entry *basereg;
2705 struct reg_entry mybasereg;
2706 struct neon_type ntype;
2707 struct neon_typed_alias typeinfo;
2708 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2709 int namelen;
2710
2711 typeinfo.defined = 0;
2712 typeinfo.eltype.type = NT_invtype;
2713 typeinfo.eltype.size = -1;
2714 typeinfo.index = -1;
2715
2716 nameend = p;
2717
2718 if (strncmp (p, " .dn ", 5) == 0)
2719 basetype = REG_TYPE_VFD;
2720 else if (strncmp (p, " .qn ", 5) == 0)
2721 basetype = REG_TYPE_NQ;
2722 else
2723 return FALSE;
2724
2725 p += 5;
2726
2727 if (*p == '\0')
2728 return FALSE;
2729
2730 basereg = arm_reg_parse_multi (&p);
2731
2732 if (basereg && basereg->type != basetype)
2733 {
2734 as_bad (_("bad type for register"));
2735 return FALSE;
2736 }
2737
2738 if (basereg == NULL)
2739 {
2740 expressionS exp;
2741 /* Try parsing as an integer. */
2742 my_get_expression (&exp, &p, GE_NO_PREFIX);
2743 if (exp.X_op != O_constant)
2744 {
2745 as_bad (_("expression must be constant"));
2746 return FALSE;
2747 }
2748 basereg = &mybasereg;
2749 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2750 : exp.X_add_number;
2751 basereg->neon = 0;
2752 }
2753
2754 if (basereg->neon)
2755 typeinfo = *basereg->neon;
2756
2757 if (parse_neon_type (&ntype, &p) == SUCCESS)
2758 {
2759 /* We got a type. */
2760 if (typeinfo.defined & NTA_HASTYPE)
2761 {
2762 as_bad (_("can't redefine the type of a register alias"));
2763 return FALSE;
2764 }
2765
2766 typeinfo.defined |= NTA_HASTYPE;
2767 if (ntype.elems != 1)
2768 {
2769 as_bad (_("you must specify a single type only"));
2770 return FALSE;
2771 }
2772 typeinfo.eltype = ntype.el[0];
2773 }
2774
2775 if (skip_past_char (&p, '[') == SUCCESS)
2776 {
2777 expressionS exp;
2778 /* We got a scalar index. */
2779
2780 if (typeinfo.defined & NTA_HASINDEX)
2781 {
2782 as_bad (_("can't redefine the index of a scalar alias"));
2783 return FALSE;
2784 }
2785
2786 my_get_expression (&exp, &p, GE_NO_PREFIX);
2787
2788 if (exp.X_op != O_constant)
2789 {
2790 as_bad (_("scalar index must be constant"));
2791 return FALSE;
2792 }
2793
2794 typeinfo.defined |= NTA_HASINDEX;
2795 typeinfo.index = exp.X_add_number;
2796
2797 if (skip_past_char (&p, ']') == FAIL)
2798 {
2799 as_bad (_("expecting ]"));
2800 return FALSE;
2801 }
2802 }
2803
2804 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2805 the desired alias name, and p points to its end. If not, then
2806 the desired alias name is in the global original_case_string. */
2807 #ifdef TC_CASE_SENSITIVE
2808 namelen = nameend - newname;
2809 #else
2810 newname = original_case_string;
2811 namelen = strlen (newname);
2812 #endif
2813
2814 namebuf = xmemdup0 (newname, namelen);
2815
2816 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2817 typeinfo.defined != 0 ? &typeinfo : NULL);
2818
2819 /* Insert name in all uppercase. */
2820 for (p = namebuf; *p; p++)
2821 *p = TOUPPER (*p);
2822
2823 if (strncmp (namebuf, newname, namelen))
2824 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2825 typeinfo.defined != 0 ? &typeinfo : NULL);
2826
2827 /* Insert name in all lowercase. */
2828 for (p = namebuf; *p; p++)
2829 *p = TOLOWER (*p);
2830
2831 if (strncmp (namebuf, newname, namelen))
2832 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2833 typeinfo.defined != 0 ? &typeinfo : NULL);
2834
2835 free (namebuf);
2836 return TRUE;
2837 }
2838
2839 /* Should never be called, as .req goes between the alias and the
2840 register name, not at the beginning of the line. */
2841
2842 static void
2843 s_req (int a ATTRIBUTE_UNUSED)
2844 {
2845 as_bad (_("invalid syntax for .req directive"));
2846 }
2847
2848 static void
2849 s_dn (int a ATTRIBUTE_UNUSED)
2850 {
2851 as_bad (_("invalid syntax for .dn directive"));
2852 }
2853
2854 static void
2855 s_qn (int a ATTRIBUTE_UNUSED)
2856 {
2857 as_bad (_("invalid syntax for .qn directive"));
2858 }
2859
2860 /* The .unreq directive deletes an alias which was previously defined
2861 by .req. For example:
2862
2863 my_alias .req r11
2864 .unreq my_alias */
2865
2866 static void
2867 s_unreq (int a ATTRIBUTE_UNUSED)
2868 {
2869 char * name;
2870 char saved_char;
2871
2872 name = input_line_pointer;
2873
2874 while (*input_line_pointer != 0
2875 && *input_line_pointer != ' '
2876 && *input_line_pointer != '\n')
2877 ++input_line_pointer;
2878
2879 saved_char = *input_line_pointer;
2880 *input_line_pointer = 0;
2881
2882 if (!*name)
2883 as_bad (_("invalid syntax for .unreq directive"));
2884 else
2885 {
2886 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2887 name);
2888
2889 if (!reg)
2890 as_bad (_("unknown register alias '%s'"), name);
2891 else if (reg->builtin)
2892 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2893 name);
2894 else
2895 {
2896 char * p;
2897 char * nbuf;
2898
2899 hash_delete (arm_reg_hsh, name, FALSE);
2900 free ((char *) reg->name);
2901 if (reg->neon)
2902 free (reg->neon);
2903 free (reg);
2904
2905 /* Also locate the all upper case and all lower case versions.
2906 Do not complain if we cannot find one or the other as it
2907 was probably deleted above. */
2908
2909 nbuf = strdup (name);
2910 for (p = nbuf; *p; p++)
2911 *p = TOUPPER (*p);
2912 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2913 if (reg)
2914 {
2915 hash_delete (arm_reg_hsh, nbuf, FALSE);
2916 free ((char *) reg->name);
2917 if (reg->neon)
2918 free (reg->neon);
2919 free (reg);
2920 }
2921
2922 for (p = nbuf; *p; p++)
2923 *p = TOLOWER (*p);
2924 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2925 if (reg)
2926 {
2927 hash_delete (arm_reg_hsh, nbuf, FALSE);
2928 free ((char *) reg->name);
2929 if (reg->neon)
2930 free (reg->neon);
2931 free (reg);
2932 }
2933
2934 free (nbuf);
2935 }
2936 }
2937
2938 *input_line_pointer = saved_char;
2939 demand_empty_rest_of_line ();
2940 }
2941
2942 /* Directives: Instruction set selection. */
2943
2944 #ifdef OBJ_ELF
2945 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2946 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2947 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2948 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2949
2950 /* Create a new mapping symbol for the transition to STATE. */
2951
2952 static void
2953 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2954 {
2955 symbolS * symbolP;
2956 const char * symname;
2957 int type;
2958
2959 switch (state)
2960 {
2961 case MAP_DATA:
2962 symname = "$d";
2963 type = BSF_NO_FLAGS;
2964 break;
2965 case MAP_ARM:
2966 symname = "$a";
2967 type = BSF_NO_FLAGS;
2968 break;
2969 case MAP_THUMB:
2970 symname = "$t";
2971 type = BSF_NO_FLAGS;
2972 break;
2973 default:
2974 abort ();
2975 }
2976
2977 symbolP = symbol_new (symname, now_seg, value, frag);
2978 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2979
2980 switch (state)
2981 {
2982 case MAP_ARM:
2983 THUMB_SET_FUNC (symbolP, 0);
2984 ARM_SET_THUMB (symbolP, 0);
2985 ARM_SET_INTERWORK (symbolP, support_interwork);
2986 break;
2987
2988 case MAP_THUMB:
2989 THUMB_SET_FUNC (symbolP, 1);
2990 ARM_SET_THUMB (symbolP, 1);
2991 ARM_SET_INTERWORK (symbolP, support_interwork);
2992 break;
2993
2994 case MAP_DATA:
2995 default:
2996 break;
2997 }
2998
2999 /* Save the mapping symbols for future reference. Also check that
3000 we do not place two mapping symbols at the same offset within a
3001 frag. We'll handle overlap between frags in
3002 check_mapping_symbols.
3003
3004 If .fill or other data filling directive generates zero sized data,
3005 the mapping symbol for the following code will have the same value
3006 as the one generated for the data filling directive. In this case,
3007 we replace the old symbol with the new one at the same address. */
3008 if (value == 0)
3009 {
3010 if (frag->tc_frag_data.first_map != NULL)
3011 {
3012 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
3013 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
3014 }
3015 frag->tc_frag_data.first_map = symbolP;
3016 }
3017 if (frag->tc_frag_data.last_map != NULL)
3018 {
3019 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
3020 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
3021 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
3022 }
3023 frag->tc_frag_data.last_map = symbolP;
3024 }
3025
3026 /* We must sometimes convert a region marked as code to data during
3027 code alignment, if an odd number of bytes have to be padded. The
3028 code mapping symbol is pushed to an aligned address. */
3029
3030 static void
3031 insert_data_mapping_symbol (enum mstate state,
3032 valueT value, fragS *frag, offsetT bytes)
3033 {
3034 /* If there was already a mapping symbol, remove it. */
3035 if (frag->tc_frag_data.last_map != NULL
3036 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
3037 {
3038 symbolS *symp = frag->tc_frag_data.last_map;
3039
3040 if (value == 0)
3041 {
3042 know (frag->tc_frag_data.first_map == symp);
3043 frag->tc_frag_data.first_map = NULL;
3044 }
3045 frag->tc_frag_data.last_map = NULL;
3046 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
3047 }
3048
3049 make_mapping_symbol (MAP_DATA, value, frag);
3050 make_mapping_symbol (state, value + bytes, frag);
3051 }
3052
3053 static void mapping_state_2 (enum mstate state, int max_chars);
3054
3055 /* Set the mapping state to STATE. Only call this when about to
3056 emit some STATE bytes to the file. */
3057
3058 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
3059 void
3060 mapping_state (enum mstate state)
3061 {
3062 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3063
3064 if (mapstate == state)
3065 /* The mapping symbol has already been emitted.
3066 There is nothing else to do. */
3067 return;
3068
3069 if (state == MAP_ARM || state == MAP_THUMB)
3070 /* PR gas/12931
3071 All ARM instructions require 4-byte alignment.
3072 (Almost) all Thumb instructions require 2-byte alignment.
3073
3074 When emitting instructions into any section, mark the section
3075 appropriately.
3076
3077 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
3078 but themselves require 2-byte alignment; this applies to some
3079 PC- relative forms. However, these cases will involve implicit
3080 literal pool generation or an explicit .align >=2, both of
3081 which will cause the section to me marked with sufficient
3082 alignment. Thus, we don't handle those cases here. */
3083 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
3084
3085 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
3086 /* This case will be evaluated later. */
3087 return;
3088
3089 mapping_state_2 (state, 0);
3090 }
3091
3092 /* Same as mapping_state, but MAX_CHARS bytes have already been
3093 allocated. Put the mapping symbol that far back. */
3094
3095 static void
3096 mapping_state_2 (enum mstate state, int max_chars)
3097 {
3098 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3099
3100 if (!SEG_NORMAL (now_seg))
3101 return;
3102
3103 if (mapstate == state)
3104 /* The mapping symbol has already been emitted.
3105 There is nothing else to do. */
3106 return;
3107
3108 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
3109 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
3110 {
3111 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
3112 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
3113
3114 if (add_symbol)
3115 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
3116 }
3117
3118 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
3119 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
3120 }
3121 #undef TRANSITION
3122 #else
3123 #define mapping_state(x) ((void)0)
3124 #define mapping_state_2(x, y) ((void)0)
3125 #endif
3126
3127 /* Find the real, Thumb encoded start of a Thumb function. */
3128
3129 #ifdef OBJ_COFF
3130 static symbolS *
3131 find_real_start (symbolS * symbolP)
3132 {
3133 char * real_start;
3134 const char * name = S_GET_NAME (symbolP);
3135 symbolS * new_target;
3136
3137 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
3138 #define STUB_NAME ".real_start_of"
3139
3140 if (name == NULL)
3141 abort ();
3142
3143 /* The compiler may generate BL instructions to local labels because
3144 it needs to perform a branch to a far away location. These labels
3145 do not have a corresponding ".real_start_of" label. We check
3146 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
3147 the ".real_start_of" convention for nonlocal branches. */
3148 if (S_IS_LOCAL (symbolP) || name[0] == '.')
3149 return symbolP;
3150
3151 real_start = concat (STUB_NAME, name, NULL);
3152 new_target = symbol_find (real_start);
3153 free (real_start);
3154
3155 if (new_target == NULL)
3156 {
3157 as_warn (_("Failed to find real start of function: %s\n"), name);
3158 new_target = symbolP;
3159 }
3160
3161 return new_target;
3162 }
3163 #endif
3164
3165 static void
3166 opcode_select (int width)
3167 {
3168 switch (width)
3169 {
3170 case 16:
3171 if (! thumb_mode)
3172 {
3173 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
3174 as_bad (_("selected processor does not support THUMB opcodes"));
3175
3176 thumb_mode = 1;
3177 /* No need to force the alignment, since we will have been
3178 coming from ARM mode, which is word-aligned. */
3179 record_alignment (now_seg, 1);
3180 }
3181 break;
3182
3183 case 32:
3184 if (thumb_mode)
3185 {
3186 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
3187 as_bad (_("selected processor does not support ARM opcodes"));
3188
3189 thumb_mode = 0;
3190
3191 if (!need_pass_2)
3192 frag_align (2, 0, 0);
3193
3194 record_alignment (now_seg, 1);
3195 }
3196 break;
3197
3198 default:
3199 as_bad (_("invalid instruction size selected (%d)"), width);
3200 }
3201 }
3202
3203 static void
3204 s_arm (int ignore ATTRIBUTE_UNUSED)
3205 {
3206 opcode_select (32);
3207 demand_empty_rest_of_line ();
3208 }
3209
3210 static void
3211 s_thumb (int ignore ATTRIBUTE_UNUSED)
3212 {
3213 opcode_select (16);
3214 demand_empty_rest_of_line ();
3215 }
3216
3217 static void
3218 s_code (int unused ATTRIBUTE_UNUSED)
3219 {
3220 int temp;
3221
3222 temp = get_absolute_expression ();
3223 switch (temp)
3224 {
3225 case 16:
3226 case 32:
3227 opcode_select (temp);
3228 break;
3229
3230 default:
3231 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3232 }
3233 }
3234
3235 static void
3236 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3237 {
3238 /* If we are not already in thumb mode go into it, EVEN if
3239 the target processor does not support thumb instructions.
3240 This is used by gcc/config/arm/lib1funcs.asm for example
3241 to compile interworking support functions even if the
3242 target processor should not support interworking. */
3243 if (! thumb_mode)
3244 {
3245 thumb_mode = 2;
3246 record_alignment (now_seg, 1);
3247 }
3248
3249 demand_empty_rest_of_line ();
3250 }
3251
3252 static void
3253 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3254 {
3255 s_thumb (0);
3256
3257 /* The following label is the name/address of the start of a Thumb function.
3258 We need to know this for the interworking support. */
3259 label_is_thumb_function_name = TRUE;
3260 }
3261
3262 /* Perform a .set directive, but also mark the alias as
3263 being a thumb function. */
3264
3265 static void
3266 s_thumb_set (int equiv)
3267 {
3268 /* XXX the following is a duplicate of the code for s_set() in read.c
3269 We cannot just call that code as we need to get at the symbol that
3270 is created. */
3271 char * name;
3272 char delim;
3273 char * end_name;
3274 symbolS * symbolP;
3275
3276 /* Especial apologies for the random logic:
3277 This just grew, and could be parsed much more simply!
3278 Dean - in haste. */
3279 delim = get_symbol_name (& name);
3280 end_name = input_line_pointer;
3281 (void) restore_line_pointer (delim);
3282
3283 if (*input_line_pointer != ',')
3284 {
3285 *end_name = 0;
3286 as_bad (_("expected comma after name \"%s\""), name);
3287 *end_name = delim;
3288 ignore_rest_of_line ();
3289 return;
3290 }
3291
3292 input_line_pointer++;
3293 *end_name = 0;
3294
3295 if (name[0] == '.' && name[1] == '\0')
3296 {
3297 /* XXX - this should not happen to .thumb_set. */
3298 abort ();
3299 }
3300
3301 if ((symbolP = symbol_find (name)) == NULL
3302 && (symbolP = md_undefined_symbol (name)) == NULL)
3303 {
3304 #ifndef NO_LISTING
3305 /* When doing symbol listings, play games with dummy fragments living
3306 outside the normal fragment chain to record the file and line info
3307 for this symbol. */
3308 if (listing & LISTING_SYMBOLS)
3309 {
3310 extern struct list_info_struct * listing_tail;
3311 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
3312
3313 memset (dummy_frag, 0, sizeof (fragS));
3314 dummy_frag->fr_type = rs_fill;
3315 dummy_frag->line = listing_tail;
3316 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
3317 dummy_frag->fr_symbol = symbolP;
3318 }
3319 else
3320 #endif
3321 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
3322
3323 #ifdef OBJ_COFF
3324 /* "set" symbols are local unless otherwise specified. */
3325 SF_SET_LOCAL (symbolP);
3326 #endif /* OBJ_COFF */
3327 } /* Make a new symbol. */
3328
3329 symbol_table_insert (symbolP);
3330
3331 * end_name = delim;
3332
3333 if (equiv
3334 && S_IS_DEFINED (symbolP)
3335 && S_GET_SEGMENT (symbolP) != reg_section)
3336 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3337
3338 pseudo_set (symbolP);
3339
3340 demand_empty_rest_of_line ();
3341
3342 /* XXX Now we come to the Thumb specific bit of code. */
3343
3344 THUMB_SET_FUNC (symbolP, 1);
3345 ARM_SET_THUMB (symbolP, 1);
3346 #if defined OBJ_ELF || defined OBJ_COFF
3347 ARM_SET_INTERWORK (symbolP, support_interwork);
3348 #endif
3349 }
3350
3351 /* Directives: Mode selection. */
3352
3353 /* .syntax [unified|divided] - choose the new unified syntax
3354 (same for Arm and Thumb encoding, modulo slight differences in what
3355 can be represented) or the old divergent syntax for each mode. */
3356 static void
3357 s_syntax (int unused ATTRIBUTE_UNUSED)
3358 {
3359 char *name, delim;
3360
3361 delim = get_symbol_name (& name);
3362
3363 if (!strcasecmp (name, "unified"))
3364 unified_syntax = TRUE;
3365 else if (!strcasecmp (name, "divided"))
3366 unified_syntax = FALSE;
3367 else
3368 {
3369 as_bad (_("unrecognized syntax mode \"%s\""), name);
3370 return;
3371 }
3372 (void) restore_line_pointer (delim);
3373 demand_empty_rest_of_line ();
3374 }
3375
3376 /* Directives: sectioning and alignment. */
3377
3378 static void
3379 s_bss (int ignore ATTRIBUTE_UNUSED)
3380 {
3381 /* We don't support putting frags in the BSS segment, we fake it by
3382 marking in_bss, then looking at s_skip for clues. */
3383 subseg_set (bss_section, 0);
3384 demand_empty_rest_of_line ();
3385
3386 #ifdef md_elf_section_change_hook
3387 md_elf_section_change_hook ();
3388 #endif
3389 }
3390
3391 static void
3392 s_even (int ignore ATTRIBUTE_UNUSED)
3393 {
3394 /* Never make frag if expect extra pass. */
3395 if (!need_pass_2)
3396 frag_align (1, 0, 0);
3397
3398 record_alignment (now_seg, 1);
3399
3400 demand_empty_rest_of_line ();
3401 }
3402
3403 /* Directives: CodeComposer Studio. */
3404
3405 /* .ref (for CodeComposer Studio syntax only). */
3406 static void
3407 s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3408 {
3409 if (codecomposer_syntax)
3410 ignore_rest_of_line ();
3411 else
3412 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3413 }
3414
3415 /* If name is not NULL, then it is used for marking the beginning of a
3416 function, whereas if it is NULL then it means the function end. */
3417 static void
3418 asmfunc_debug (const char * name)
3419 {
3420 static const char * last_name = NULL;
3421
3422 if (name != NULL)
3423 {
3424 gas_assert (last_name == NULL);
3425 last_name = name;
3426
3427 if (debug_type == DEBUG_STABS)
3428 stabs_generate_asm_func (name, name);
3429 }
3430 else
3431 {
3432 gas_assert (last_name != NULL);
3433
3434 if (debug_type == DEBUG_STABS)
3435 stabs_generate_asm_endfunc (last_name, last_name);
3436
3437 last_name = NULL;
3438 }
3439 }
3440
3441 static void
3442 s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3443 {
3444 if (codecomposer_syntax)
3445 {
3446 switch (asmfunc_state)
3447 {
3448 case OUTSIDE_ASMFUNC:
3449 asmfunc_state = WAITING_ASMFUNC_NAME;
3450 break;
3451
3452 case WAITING_ASMFUNC_NAME:
3453 as_bad (_(".asmfunc repeated."));
3454 break;
3455
3456 case WAITING_ENDASMFUNC:
3457 as_bad (_(".asmfunc without function."));
3458 break;
3459 }
3460 demand_empty_rest_of_line ();
3461 }
3462 else
3463 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3464 }
3465
3466 static void
3467 s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3468 {
3469 if (codecomposer_syntax)
3470 {
3471 switch (asmfunc_state)
3472 {
3473 case OUTSIDE_ASMFUNC:
3474 as_bad (_(".endasmfunc without a .asmfunc."));
3475 break;
3476
3477 case WAITING_ASMFUNC_NAME:
3478 as_bad (_(".endasmfunc without function."));
3479 break;
3480
3481 case WAITING_ENDASMFUNC:
3482 asmfunc_state = OUTSIDE_ASMFUNC;
3483 asmfunc_debug (NULL);
3484 break;
3485 }
3486 demand_empty_rest_of_line ();
3487 }
3488 else
3489 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3490 }
3491
3492 static void
3493 s_ccs_def (int name)
3494 {
3495 if (codecomposer_syntax)
3496 s_globl (name);
3497 else
3498 as_bad (_(".def pseudo-op only available with -mccs flag."));
3499 }
3500
3501 /* Directives: Literal pools. */
3502
3503 static literal_pool *
3504 find_literal_pool (void)
3505 {
3506 literal_pool * pool;
3507
3508 for (pool = list_of_pools; pool != NULL; pool = pool->next)
3509 {
3510 if (pool->section == now_seg
3511 && pool->sub_section == now_subseg)
3512 break;
3513 }
3514
3515 return pool;
3516 }
3517
3518 static literal_pool *
3519 find_or_make_literal_pool (void)
3520 {
3521 /* Next literal pool ID number. */
3522 static unsigned int latest_pool_num = 1;
3523 literal_pool * pool;
3524
3525 pool = find_literal_pool ();
3526
3527 if (pool == NULL)
3528 {
3529 /* Create a new pool. */
3530 pool = XNEW (literal_pool);
3531 if (! pool)
3532 return NULL;
3533
3534 pool->next_free_entry = 0;
3535 pool->section = now_seg;
3536 pool->sub_section = now_subseg;
3537 pool->next = list_of_pools;
3538 pool->symbol = NULL;
3539 pool->alignment = 2;
3540
3541 /* Add it to the list. */
3542 list_of_pools = pool;
3543 }
3544
3545 /* New pools, and emptied pools, will have a NULL symbol. */
3546 if (pool->symbol == NULL)
3547 {
3548 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3549 (valueT) 0, &zero_address_frag);
3550 pool->id = latest_pool_num ++;
3551 }
3552
3553 /* Done. */
3554 return pool;
3555 }
3556
3557 /* Add the literal in the global 'inst'
3558 structure to the relevant literal pool. */
3559
3560 static int
3561 add_to_lit_pool (unsigned int nbytes)
3562 {
3563 #define PADDING_SLOT 0x1
3564 #define LIT_ENTRY_SIZE_MASK 0xFF
3565 literal_pool * pool;
3566 unsigned int entry, pool_size = 0;
3567 bfd_boolean padding_slot_p = FALSE;
3568 unsigned imm1 = 0;
3569 unsigned imm2 = 0;
3570
3571 if (nbytes == 8)
3572 {
3573 imm1 = inst.operands[1].imm;
3574 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3575 : inst.relocs[0].exp.X_unsigned ? 0
3576 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
3577 if (target_big_endian)
3578 {
3579 imm1 = imm2;
3580 imm2 = inst.operands[1].imm;
3581 }
3582 }
3583
3584 pool = find_or_make_literal_pool ();
3585
3586 /* Check if this literal value is already in the pool. */
3587 for (entry = 0; entry < pool->next_free_entry; entry ++)
3588 {
3589 if (nbytes == 4)
3590 {
3591 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3592 && (inst.relocs[0].exp.X_op == O_constant)
3593 && (pool->literals[entry].X_add_number
3594 == inst.relocs[0].exp.X_add_number)
3595 && (pool->literals[entry].X_md == nbytes)
3596 && (pool->literals[entry].X_unsigned
3597 == inst.relocs[0].exp.X_unsigned))
3598 break;
3599
3600 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3601 && (inst.relocs[0].exp.X_op == O_symbol)
3602 && (pool->literals[entry].X_add_number
3603 == inst.relocs[0].exp.X_add_number)
3604 && (pool->literals[entry].X_add_symbol
3605 == inst.relocs[0].exp.X_add_symbol)
3606 && (pool->literals[entry].X_op_symbol
3607 == inst.relocs[0].exp.X_op_symbol)
3608 && (pool->literals[entry].X_md == nbytes))
3609 break;
3610 }
3611 else if ((nbytes == 8)
3612 && !(pool_size & 0x7)
3613 && ((entry + 1) != pool->next_free_entry)
3614 && (pool->literals[entry].X_op == O_constant)
3615 && (pool->literals[entry].X_add_number == (offsetT) imm1)
3616 && (pool->literals[entry].X_unsigned
3617 == inst.relocs[0].exp.X_unsigned)
3618 && (pool->literals[entry + 1].X_op == O_constant)
3619 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
3620 && (pool->literals[entry + 1].X_unsigned
3621 == inst.relocs[0].exp.X_unsigned))
3622 break;
3623
3624 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3625 if (padding_slot_p && (nbytes == 4))
3626 break;
3627
3628 pool_size += 4;
3629 }
3630
3631 /* Do we need to create a new entry? */
3632 if (entry == pool->next_free_entry)
3633 {
3634 if (entry >= MAX_LITERAL_POOL_SIZE)
3635 {
3636 inst.error = _("literal pool overflow");
3637 return FAIL;
3638 }
3639
3640 if (nbytes == 8)
3641 {
3642 /* For 8-byte entries, we align to an 8-byte boundary,
3643 and split it into two 4-byte entries, because on 32-bit
3644 host, 8-byte constants are treated as big num, thus
3645 saved in "generic_bignum" which will be overwritten
3646 by later assignments.
3647
3648 We also need to make sure there is enough space for
3649 the split.
3650
3651 We also check to make sure the literal operand is a
3652 constant number. */
3653 if (!(inst.relocs[0].exp.X_op == O_constant
3654 || inst.relocs[0].exp.X_op == O_big))
3655 {
3656 inst.error = _("invalid type for literal pool");
3657 return FAIL;
3658 }
3659 else if (pool_size & 0x7)
3660 {
3661 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3662 {
3663 inst.error = _("literal pool overflow");
3664 return FAIL;
3665 }
3666
3667 pool->literals[entry] = inst.relocs[0].exp;
3668 pool->literals[entry].X_op = O_constant;
3669 pool->literals[entry].X_add_number = 0;
3670 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3671 pool->next_free_entry += 1;
3672 pool_size += 4;
3673 }
3674 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3675 {
3676 inst.error = _("literal pool overflow");
3677 return FAIL;
3678 }
3679
3680 pool->literals[entry] = inst.relocs[0].exp;
3681 pool->literals[entry].X_op = O_constant;
3682 pool->literals[entry].X_add_number = imm1;
3683 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3684 pool->literals[entry++].X_md = 4;
3685 pool->literals[entry] = inst.relocs[0].exp;
3686 pool->literals[entry].X_op = O_constant;
3687 pool->literals[entry].X_add_number = imm2;
3688 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3689 pool->literals[entry].X_md = 4;
3690 pool->alignment = 3;
3691 pool->next_free_entry += 1;
3692 }
3693 else
3694 {
3695 pool->literals[entry] = inst.relocs[0].exp;
3696 pool->literals[entry].X_md = 4;
3697 }
3698
3699 #ifdef OBJ_ELF
3700 /* PR ld/12974: Record the location of the first source line to reference
3701 this entry in the literal pool. If it turns out during linking that the
3702 symbol does not exist we will be able to give an accurate line number for
3703 the (first use of the) missing reference. */
3704 if (debug_type == DEBUG_DWARF2)
3705 dwarf2_where (pool->locs + entry);
3706 #endif
3707 pool->next_free_entry += 1;
3708 }
3709 else if (padding_slot_p)
3710 {
3711 pool->literals[entry] = inst.relocs[0].exp;
3712 pool->literals[entry].X_md = nbytes;
3713 }
3714
3715 inst.relocs[0].exp.X_op = O_symbol;
3716 inst.relocs[0].exp.X_add_number = pool_size;
3717 inst.relocs[0].exp.X_add_symbol = pool->symbol;
3718
3719 return SUCCESS;
3720 }
3721
3722 bfd_boolean
3723 tc_start_label_without_colon (void)
3724 {
3725 bfd_boolean ret = TRUE;
3726
3727 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3728 {
3729 const char *label = input_line_pointer;
3730
3731 while (!is_end_of_line[(int) label[-1]])
3732 --label;
3733
3734 if (*label == '.')
3735 {
3736 as_bad (_("Invalid label '%s'"), label);
3737 ret = FALSE;
3738 }
3739
3740 asmfunc_debug (label);
3741
3742 asmfunc_state = WAITING_ENDASMFUNC;
3743 }
3744
3745 return ret;
3746 }
3747
3748 /* Can't use symbol_new here, so have to create a symbol and then at
3749 a later date assign it a value. That's what these functions do. */
3750
3751 static void
3752 symbol_locate (symbolS * symbolP,
3753 const char * name, /* It is copied, the caller can modify. */
3754 segT segment, /* Segment identifier (SEG_<something>). */
3755 valueT valu, /* Symbol value. */
3756 fragS * frag) /* Associated fragment. */
3757 {
3758 size_t name_length;
3759 char * preserved_copy_of_name;
3760
3761 name_length = strlen (name) + 1; /* +1 for \0. */
3762 obstack_grow (&notes, name, name_length);
3763 preserved_copy_of_name = (char *) obstack_finish (&notes);
3764
3765 #ifdef tc_canonicalize_symbol_name
3766 preserved_copy_of_name =
3767 tc_canonicalize_symbol_name (preserved_copy_of_name);
3768 #endif
3769
3770 S_SET_NAME (symbolP, preserved_copy_of_name);
3771
3772 S_SET_SEGMENT (symbolP, segment);
3773 S_SET_VALUE (symbolP, valu);
3774 symbol_clear_list_pointers (symbolP);
3775
3776 symbol_set_frag (symbolP, frag);
3777
3778 /* Link to end of symbol chain. */
3779 {
3780 extern int symbol_table_frozen;
3781
3782 if (symbol_table_frozen)
3783 abort ();
3784 }
3785
3786 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3787
3788 obj_symbol_new_hook (symbolP);
3789
3790 #ifdef tc_symbol_new_hook
3791 tc_symbol_new_hook (symbolP);
3792 #endif
3793
3794 #ifdef DEBUG_SYMS
3795 verify_symbol_chain (symbol_rootP, symbol_lastP);
3796 #endif /* DEBUG_SYMS */
3797 }
3798
3799 static void
3800 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3801 {
3802 unsigned int entry;
3803 literal_pool * pool;
3804 char sym_name[20];
3805
3806 pool = find_literal_pool ();
3807 if (pool == NULL
3808 || pool->symbol == NULL
3809 || pool->next_free_entry == 0)
3810 return;
3811
3812 /* Align pool as you have word accesses.
3813 Only make a frag if we have to. */
3814 if (!need_pass_2)
3815 frag_align (pool->alignment, 0, 0);
3816
3817 record_alignment (now_seg, 2);
3818
3819 #ifdef OBJ_ELF
3820 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3821 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
3822 #endif
3823 sprintf (sym_name, "$$lit_\002%x", pool->id);
3824
3825 symbol_locate (pool->symbol, sym_name, now_seg,
3826 (valueT) frag_now_fix (), frag_now);
3827 symbol_table_insert (pool->symbol);
3828
3829 ARM_SET_THUMB (pool->symbol, thumb_mode);
3830
3831 #if defined OBJ_COFF || defined OBJ_ELF
3832 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3833 #endif
3834
3835 for (entry = 0; entry < pool->next_free_entry; entry ++)
3836 {
3837 #ifdef OBJ_ELF
3838 if (debug_type == DEBUG_DWARF2)
3839 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3840 #endif
3841 /* First output the expression in the instruction to the pool. */
3842 emit_expr (&(pool->literals[entry]),
3843 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
3844 }
3845
3846 /* Mark the pool as empty. */
3847 pool->next_free_entry = 0;
3848 pool->symbol = NULL;
3849 }
3850
3851 #ifdef OBJ_ELF
3852 /* Forward declarations for functions below, in the MD interface
3853 section. */
3854 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3855 static valueT create_unwind_entry (int);
3856 static void start_unwind_section (const segT, int);
3857 static void add_unwind_opcode (valueT, int);
3858 static void flush_pending_unwind (void);
3859
3860 /* Directives: Data. */
3861
3862 static void
3863 s_arm_elf_cons (int nbytes)
3864 {
3865 expressionS exp;
3866
3867 #ifdef md_flush_pending_output
3868 md_flush_pending_output ();
3869 #endif
3870
3871 if (is_it_end_of_statement ())
3872 {
3873 demand_empty_rest_of_line ();
3874 return;
3875 }
3876
3877 #ifdef md_cons_align
3878 md_cons_align (nbytes);
3879 #endif
3880
3881 mapping_state (MAP_DATA);
3882 do
3883 {
3884 int reloc;
3885 char *base = input_line_pointer;
3886
3887 expression (& exp);
3888
3889 if (exp.X_op != O_symbol)
3890 emit_expr (&exp, (unsigned int) nbytes);
3891 else
3892 {
3893 char *before_reloc = input_line_pointer;
3894 reloc = parse_reloc (&input_line_pointer);
3895 if (reloc == -1)
3896 {
3897 as_bad (_("unrecognized relocation suffix"));
3898 ignore_rest_of_line ();
3899 return;
3900 }
3901 else if (reloc == BFD_RELOC_UNUSED)
3902 emit_expr (&exp, (unsigned int) nbytes);
3903 else
3904 {
3905 reloc_howto_type *howto = (reloc_howto_type *)
3906 bfd_reloc_type_lookup (stdoutput,
3907 (bfd_reloc_code_real_type) reloc);
3908 int size = bfd_get_reloc_size (howto);
3909
3910 if (reloc == BFD_RELOC_ARM_PLT32)
3911 {
3912 as_bad (_("(plt) is only valid on branch targets"));
3913 reloc = BFD_RELOC_UNUSED;
3914 size = 0;
3915 }
3916
3917 if (size > nbytes)
3918 as_bad (ngettext ("%s relocations do not fit in %d byte",
3919 "%s relocations do not fit in %d bytes",
3920 nbytes),
3921 howto->name, nbytes);
3922 else
3923 {
3924 /* We've parsed an expression stopping at O_symbol.
3925 But there may be more expression left now that we
3926 have parsed the relocation marker. Parse it again.
3927 XXX Surely there is a cleaner way to do this. */
3928 char *p = input_line_pointer;
3929 int offset;
3930 char *save_buf = XNEWVEC (char, input_line_pointer - base);
3931
3932 memcpy (save_buf, base, input_line_pointer - base);
3933 memmove (base + (input_line_pointer - before_reloc),
3934 base, before_reloc - base);
3935
3936 input_line_pointer = base + (input_line_pointer-before_reloc);
3937 expression (&exp);
3938 memcpy (base, save_buf, p - base);
3939
3940 offset = nbytes - size;
3941 p = frag_more (nbytes);
3942 memset (p, 0, nbytes);
3943 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3944 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3945 free (save_buf);
3946 }
3947 }
3948 }
3949 }
3950 while (*input_line_pointer++ == ',');
3951
3952 /* Put terminator back into stream. */
3953 input_line_pointer --;
3954 demand_empty_rest_of_line ();
3955 }
3956
3957 /* Emit an expression containing a 32-bit thumb instruction.
3958 Implementation based on put_thumb32_insn. */
3959
3960 static void
3961 emit_thumb32_expr (expressionS * exp)
3962 {
3963 expressionS exp_high = *exp;
3964
3965 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3966 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3967 exp->X_add_number &= 0xffff;
3968 emit_expr (exp, (unsigned int) THUMB_SIZE);
3969 }
3970
3971 /* Guess the instruction size based on the opcode. */
3972
3973 static int
3974 thumb_insn_size (int opcode)
3975 {
3976 if ((unsigned int) opcode < 0xe800u)
3977 return 2;
3978 else if ((unsigned int) opcode >= 0xe8000000u)
3979 return 4;
3980 else
3981 return 0;
3982 }
3983
3984 static bfd_boolean
3985 emit_insn (expressionS *exp, int nbytes)
3986 {
3987 int size = 0;
3988
3989 if (exp->X_op == O_constant)
3990 {
3991 size = nbytes;
3992
3993 if (size == 0)
3994 size = thumb_insn_size (exp->X_add_number);
3995
3996 if (size != 0)
3997 {
3998 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3999 {
4000 as_bad (_(".inst.n operand too big. "\
4001 "Use .inst.w instead"));
4002 size = 0;
4003 }
4004 else
4005 {
4006 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
4007 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
4008 else
4009 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
4010
4011 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
4012 emit_thumb32_expr (exp);
4013 else
4014 emit_expr (exp, (unsigned int) size);
4015
4016 it_fsm_post_encode ();
4017 }
4018 }
4019 else
4020 as_bad (_("cannot determine Thumb instruction size. " \
4021 "Use .inst.n/.inst.w instead"));
4022 }
4023 else
4024 as_bad (_("constant expression required"));
4025
4026 return (size != 0);
4027 }
4028
4029 /* Like s_arm_elf_cons but do not use md_cons_align and
4030 set the mapping state to MAP_ARM/MAP_THUMB. */
4031
4032 static void
4033 s_arm_elf_inst (int nbytes)
4034 {
4035 if (is_it_end_of_statement ())
4036 {
4037 demand_empty_rest_of_line ();
4038 return;
4039 }
4040
4041 /* Calling mapping_state () here will not change ARM/THUMB,
4042 but will ensure not to be in DATA state. */
4043
4044 if (thumb_mode)
4045 mapping_state (MAP_THUMB);
4046 else
4047 {
4048 if (nbytes != 0)
4049 {
4050 as_bad (_("width suffixes are invalid in ARM mode"));
4051 ignore_rest_of_line ();
4052 return;
4053 }
4054
4055 nbytes = 4;
4056
4057 mapping_state (MAP_ARM);
4058 }
4059
4060 do
4061 {
4062 expressionS exp;
4063
4064 expression (& exp);
4065
4066 if (! emit_insn (& exp, nbytes))
4067 {
4068 ignore_rest_of_line ();
4069 return;
4070 }
4071 }
4072 while (*input_line_pointer++ == ',');
4073
4074 /* Put terminator back into stream. */
4075 input_line_pointer --;
4076 demand_empty_rest_of_line ();
4077 }
4078
4079 /* Parse a .rel31 directive. */
4080
4081 static void
4082 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
4083 {
4084 expressionS exp;
4085 char *p;
4086 valueT highbit;
4087
4088 highbit = 0;
4089 if (*input_line_pointer == '1')
4090 highbit = 0x80000000;
4091 else if (*input_line_pointer != '0')
4092 as_bad (_("expected 0 or 1"));
4093
4094 input_line_pointer++;
4095 if (*input_line_pointer != ',')
4096 as_bad (_("missing comma"));
4097 input_line_pointer++;
4098
4099 #ifdef md_flush_pending_output
4100 md_flush_pending_output ();
4101 #endif
4102
4103 #ifdef md_cons_align
4104 md_cons_align (4);
4105 #endif
4106
4107 mapping_state (MAP_DATA);
4108
4109 expression (&exp);
4110
4111 p = frag_more (4);
4112 md_number_to_chars (p, highbit, 4);
4113 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
4114 BFD_RELOC_ARM_PREL31);
4115
4116 demand_empty_rest_of_line ();
4117 }
4118
4119 /* Directives: AEABI stack-unwind tables. */
4120
4121 /* Parse an unwind_fnstart directive. Simply records the current location. */
4122
4123 static void
4124 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
4125 {
4126 demand_empty_rest_of_line ();
4127 if (unwind.proc_start)
4128 {
4129 as_bad (_("duplicate .fnstart directive"));
4130 return;
4131 }
4132
4133 /* Mark the start of the function. */
4134 unwind.proc_start = expr_build_dot ();
4135
4136 /* Reset the rest of the unwind info. */
4137 unwind.opcode_count = 0;
4138 unwind.table_entry = NULL;
4139 unwind.personality_routine = NULL;
4140 unwind.personality_index = -1;
4141 unwind.frame_size = 0;
4142 unwind.fp_offset = 0;
4143 unwind.fp_reg = REG_SP;
4144 unwind.fp_used = 0;
4145 unwind.sp_restored = 0;
4146 }
4147
4148
4149 /* Parse a handlerdata directive. Creates the exception handling table entry
4150 for the function. */
4151
4152 static void
4153 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
4154 {
4155 demand_empty_rest_of_line ();
4156 if (!unwind.proc_start)
4157 as_bad (MISSING_FNSTART);
4158
4159 if (unwind.table_entry)
4160 as_bad (_("duplicate .handlerdata directive"));
4161
4162 create_unwind_entry (1);
4163 }
4164
4165 /* Parse an unwind_fnend directive. Generates the index table entry. */
4166
4167 static void
4168 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
4169 {
4170 long where;
4171 char *ptr;
4172 valueT val;
4173 unsigned int marked_pr_dependency;
4174
4175 demand_empty_rest_of_line ();
4176
4177 if (!unwind.proc_start)
4178 {
4179 as_bad (_(".fnend directive without .fnstart"));
4180 return;
4181 }
4182
4183 /* Add eh table entry. */
4184 if (unwind.table_entry == NULL)
4185 val = create_unwind_entry (0);
4186 else
4187 val = 0;
4188
4189 /* Add index table entry. This is two words. */
4190 start_unwind_section (unwind.saved_seg, 1);
4191 frag_align (2, 0, 0);
4192 record_alignment (now_seg, 2);
4193
4194 ptr = frag_more (8);
4195 memset (ptr, 0, 8);
4196 where = frag_now_fix () - 8;
4197
4198 /* Self relative offset of the function start. */
4199 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4200 BFD_RELOC_ARM_PREL31);
4201
4202 /* Indicate dependency on EHABI-defined personality routines to the
4203 linker, if it hasn't been done already. */
4204 marked_pr_dependency
4205 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
4206 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4207 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4208 {
4209 static const char *const name[] =
4210 {
4211 "__aeabi_unwind_cpp_pr0",
4212 "__aeabi_unwind_cpp_pr1",
4213 "__aeabi_unwind_cpp_pr2"
4214 };
4215 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4216 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
4217 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
4218 |= 1 << unwind.personality_index;
4219 }
4220
4221 if (val)
4222 /* Inline exception table entry. */
4223 md_number_to_chars (ptr + 4, val, 4);
4224 else
4225 /* Self relative offset of the table entry. */
4226 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4227 BFD_RELOC_ARM_PREL31);
4228
4229 /* Restore the original section. */
4230 subseg_set (unwind.saved_seg, unwind.saved_subseg);
4231
4232 unwind.proc_start = NULL;
4233 }
4234
4235
4236 /* Parse an unwind_cantunwind directive. */
4237
4238 static void
4239 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4240 {
4241 demand_empty_rest_of_line ();
4242 if (!unwind.proc_start)
4243 as_bad (MISSING_FNSTART);
4244
4245 if (unwind.personality_routine || unwind.personality_index != -1)
4246 as_bad (_("personality routine specified for cantunwind frame"));
4247
4248 unwind.personality_index = -2;
4249 }
4250
4251
4252 /* Parse a personalityindex directive. */
4253
4254 static void
4255 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4256 {
4257 expressionS exp;
4258
4259 if (!unwind.proc_start)
4260 as_bad (MISSING_FNSTART);
4261
4262 if (unwind.personality_routine || unwind.personality_index != -1)
4263 as_bad (_("duplicate .personalityindex directive"));
4264
4265 expression (&exp);
4266
4267 if (exp.X_op != O_constant
4268 || exp.X_add_number < 0 || exp.X_add_number > 15)
4269 {
4270 as_bad (_("bad personality routine number"));
4271 ignore_rest_of_line ();
4272 return;
4273 }
4274
4275 unwind.personality_index = exp.X_add_number;
4276
4277 demand_empty_rest_of_line ();
4278 }
4279
4280
4281 /* Parse a personality directive. */
4282
4283 static void
4284 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4285 {
4286 char *name, *p, c;
4287
4288 if (!unwind.proc_start)
4289 as_bad (MISSING_FNSTART);
4290
4291 if (unwind.personality_routine || unwind.personality_index != -1)
4292 as_bad (_("duplicate .personality directive"));
4293
4294 c = get_symbol_name (& name);
4295 p = input_line_pointer;
4296 if (c == '"')
4297 ++ input_line_pointer;
4298 unwind.personality_routine = symbol_find_or_make (name);
4299 *p = c;
4300 demand_empty_rest_of_line ();
4301 }
4302
4303
4304 /* Parse a directive saving core registers. */
4305
4306 static void
4307 s_arm_unwind_save_core (void)
4308 {
4309 valueT op;
4310 long range;
4311 int n;
4312
4313 range = parse_reg_list (&input_line_pointer, REGLIST_RN);
4314 if (range == FAIL)
4315 {
4316 as_bad (_("expected register list"));
4317 ignore_rest_of_line ();
4318 return;
4319 }
4320
4321 demand_empty_rest_of_line ();
4322
4323 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4324 into .unwind_save {..., sp...}. We aren't bothered about the value of
4325 ip because it is clobbered by calls. */
4326 if (unwind.sp_restored && unwind.fp_reg == 12
4327 && (range & 0x3000) == 0x1000)
4328 {
4329 unwind.opcode_count--;
4330 unwind.sp_restored = 0;
4331 range = (range | 0x2000) & ~0x1000;
4332 unwind.pending_offset = 0;
4333 }
4334
4335 /* Pop r4-r15. */
4336 if (range & 0xfff0)
4337 {
4338 /* See if we can use the short opcodes. These pop a block of up to 8
4339 registers starting with r4, plus maybe r14. */
4340 for (n = 0; n < 8; n++)
4341 {
4342 /* Break at the first non-saved register. */
4343 if ((range & (1 << (n + 4))) == 0)
4344 break;
4345 }
4346 /* See if there are any other bits set. */
4347 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4348 {
4349 /* Use the long form. */
4350 op = 0x8000 | ((range >> 4) & 0xfff);
4351 add_unwind_opcode (op, 2);
4352 }
4353 else
4354 {
4355 /* Use the short form. */
4356 if (range & 0x4000)
4357 op = 0xa8; /* Pop r14. */
4358 else
4359 op = 0xa0; /* Do not pop r14. */
4360 op |= (n - 1);
4361 add_unwind_opcode (op, 1);
4362 }
4363 }
4364
4365 /* Pop r0-r3. */
4366 if (range & 0xf)
4367 {
4368 op = 0xb100 | (range & 0xf);
4369 add_unwind_opcode (op, 2);
4370 }
4371
4372 /* Record the number of bytes pushed. */
4373 for (n = 0; n < 16; n++)
4374 {
4375 if (range & (1 << n))
4376 unwind.frame_size += 4;
4377 }
4378 }
4379
4380
4381 /* Parse a directive saving FPA registers. */
4382
4383 static void
4384 s_arm_unwind_save_fpa (int reg)
4385 {
4386 expressionS exp;
4387 int num_regs;
4388 valueT op;
4389
4390 /* Get Number of registers to transfer. */
4391 if (skip_past_comma (&input_line_pointer) != FAIL)
4392 expression (&exp);
4393 else
4394 exp.X_op = O_illegal;
4395
4396 if (exp.X_op != O_constant)
4397 {
4398 as_bad (_("expected , <constant>"));
4399 ignore_rest_of_line ();
4400 return;
4401 }
4402
4403 num_regs = exp.X_add_number;
4404
4405 if (num_regs < 1 || num_regs > 4)
4406 {
4407 as_bad (_("number of registers must be in the range [1:4]"));
4408 ignore_rest_of_line ();
4409 return;
4410 }
4411
4412 demand_empty_rest_of_line ();
4413
4414 if (reg == 4)
4415 {
4416 /* Short form. */
4417 op = 0xb4 | (num_regs - 1);
4418 add_unwind_opcode (op, 1);
4419 }
4420 else
4421 {
4422 /* Long form. */
4423 op = 0xc800 | (reg << 4) | (num_regs - 1);
4424 add_unwind_opcode (op, 2);
4425 }
4426 unwind.frame_size += num_regs * 12;
4427 }
4428
4429
4430 /* Parse a directive saving VFP registers for ARMv6 and above. */
4431
4432 static void
4433 s_arm_unwind_save_vfp_armv6 (void)
4434 {
4435 int count;
4436 unsigned int start;
4437 valueT op;
4438 int num_vfpv3_regs = 0;
4439 int num_regs_below_16;
4440 bfd_boolean partial_match;
4441
4442 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4443 &partial_match);
4444 if (count == FAIL)
4445 {
4446 as_bad (_("expected register list"));
4447 ignore_rest_of_line ();
4448 return;
4449 }
4450
4451 demand_empty_rest_of_line ();
4452
4453 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4454 than FSTMX/FLDMX-style ones). */
4455
4456 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4457 if (start >= 16)
4458 num_vfpv3_regs = count;
4459 else if (start + count > 16)
4460 num_vfpv3_regs = start + count - 16;
4461
4462 if (num_vfpv3_regs > 0)
4463 {
4464 int start_offset = start > 16 ? start - 16 : 0;
4465 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4466 add_unwind_opcode (op, 2);
4467 }
4468
4469 /* Generate opcode for registers numbered in the range 0 .. 15. */
4470 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
4471 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
4472 if (num_regs_below_16 > 0)
4473 {
4474 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4475 add_unwind_opcode (op, 2);
4476 }
4477
4478 unwind.frame_size += count * 8;
4479 }
4480
4481
4482 /* Parse a directive saving VFP registers for pre-ARMv6. */
4483
4484 static void
4485 s_arm_unwind_save_vfp (void)
4486 {
4487 int count;
4488 unsigned int reg;
4489 valueT op;
4490 bfd_boolean partial_match;
4491
4492 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4493 &partial_match);
4494 if (count == FAIL)
4495 {
4496 as_bad (_("expected register list"));
4497 ignore_rest_of_line ();
4498 return;
4499 }
4500
4501 demand_empty_rest_of_line ();
4502
4503 if (reg == 8)
4504 {
4505 /* Short form. */
4506 op = 0xb8 | (count - 1);
4507 add_unwind_opcode (op, 1);
4508 }
4509 else
4510 {
4511 /* Long form. */
4512 op = 0xb300 | (reg << 4) | (count - 1);
4513 add_unwind_opcode (op, 2);
4514 }
4515 unwind.frame_size += count * 8 + 4;
4516 }
4517
4518
4519 /* Parse a directive saving iWMMXt data registers. */
4520
4521 static void
4522 s_arm_unwind_save_mmxwr (void)
4523 {
4524 int reg;
4525 int hi_reg;
4526 int i;
4527 unsigned mask = 0;
4528 valueT op;
4529
4530 if (*input_line_pointer == '{')
4531 input_line_pointer++;
4532
4533 do
4534 {
4535 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4536
4537 if (reg == FAIL)
4538 {
4539 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4540 goto error;
4541 }
4542
4543 if (mask >> reg)
4544 as_tsktsk (_("register list not in ascending order"));
4545 mask |= 1 << reg;
4546
4547 if (*input_line_pointer == '-')
4548 {
4549 input_line_pointer++;
4550 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4551 if (hi_reg == FAIL)
4552 {
4553 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4554 goto error;
4555 }
4556 else if (reg >= hi_reg)
4557 {
4558 as_bad (_("bad register range"));
4559 goto error;
4560 }
4561 for (; reg < hi_reg; reg++)
4562 mask |= 1 << reg;
4563 }
4564 }
4565 while (skip_past_comma (&input_line_pointer) != FAIL);
4566
4567 skip_past_char (&input_line_pointer, '}');
4568
4569 demand_empty_rest_of_line ();
4570
4571 /* Generate any deferred opcodes because we're going to be looking at
4572 the list. */
4573 flush_pending_unwind ();
4574
4575 for (i = 0; i < 16; i++)
4576 {
4577 if (mask & (1 << i))
4578 unwind.frame_size += 8;
4579 }
4580
4581 /* Attempt to combine with a previous opcode. We do this because gcc
4582 likes to output separate unwind directives for a single block of
4583 registers. */
4584 if (unwind.opcode_count > 0)
4585 {
4586 i = unwind.opcodes[unwind.opcode_count - 1];
4587 if ((i & 0xf8) == 0xc0)
4588 {
4589 i &= 7;
4590 /* Only merge if the blocks are contiguous. */
4591 if (i < 6)
4592 {
4593 if ((mask & 0xfe00) == (1 << 9))
4594 {
4595 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4596 unwind.opcode_count--;
4597 }
4598 }
4599 else if (i == 6 && unwind.opcode_count >= 2)
4600 {
4601 i = unwind.opcodes[unwind.opcode_count - 2];
4602 reg = i >> 4;
4603 i &= 0xf;
4604
4605 op = 0xffff << (reg - 1);
4606 if (reg > 0
4607 && ((mask & op) == (1u << (reg - 1))))
4608 {
4609 op = (1 << (reg + i + 1)) - 1;
4610 op &= ~((1 << reg) - 1);
4611 mask |= op;
4612 unwind.opcode_count -= 2;
4613 }
4614 }
4615 }
4616 }
4617
4618 hi_reg = 15;
4619 /* We want to generate opcodes in the order the registers have been
4620 saved, ie. descending order. */
4621 for (reg = 15; reg >= -1; reg--)
4622 {
4623 /* Save registers in blocks. */
4624 if (reg < 0
4625 || !(mask & (1 << reg)))
4626 {
4627 /* We found an unsaved reg. Generate opcodes to save the
4628 preceding block. */
4629 if (reg != hi_reg)
4630 {
4631 if (reg == 9)
4632 {
4633 /* Short form. */
4634 op = 0xc0 | (hi_reg - 10);
4635 add_unwind_opcode (op, 1);
4636 }
4637 else
4638 {
4639 /* Long form. */
4640 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4641 add_unwind_opcode (op, 2);
4642 }
4643 }
4644 hi_reg = reg - 1;
4645 }
4646 }
4647
4648 return;
4649 error:
4650 ignore_rest_of_line ();
4651 }
4652
4653 static void
4654 s_arm_unwind_save_mmxwcg (void)
4655 {
4656 int reg;
4657 int hi_reg;
4658 unsigned mask = 0;
4659 valueT op;
4660
4661 if (*input_line_pointer == '{')
4662 input_line_pointer++;
4663
4664 skip_whitespace (input_line_pointer);
4665
4666 do
4667 {
4668 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4669
4670 if (reg == FAIL)
4671 {
4672 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4673 goto error;
4674 }
4675
4676 reg -= 8;
4677 if (mask >> reg)
4678 as_tsktsk (_("register list not in ascending order"));
4679 mask |= 1 << reg;
4680
4681 if (*input_line_pointer == '-')
4682 {
4683 input_line_pointer++;
4684 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4685 if (hi_reg == FAIL)
4686 {
4687 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4688 goto error;
4689 }
4690 else if (reg >= hi_reg)
4691 {
4692 as_bad (_("bad register range"));
4693 goto error;
4694 }
4695 for (; reg < hi_reg; reg++)
4696 mask |= 1 << reg;
4697 }
4698 }
4699 while (skip_past_comma (&input_line_pointer) != FAIL);
4700
4701 skip_past_char (&input_line_pointer, '}');
4702
4703 demand_empty_rest_of_line ();
4704
4705 /* Generate any deferred opcodes because we're going to be looking at
4706 the list. */
4707 flush_pending_unwind ();
4708
4709 for (reg = 0; reg < 16; reg++)
4710 {
4711 if (mask & (1 << reg))
4712 unwind.frame_size += 4;
4713 }
4714 op = 0xc700 | mask;
4715 add_unwind_opcode (op, 2);
4716 return;
4717 error:
4718 ignore_rest_of_line ();
4719 }
4720
4721
4722 /* Parse an unwind_save directive.
4723 If the argument is non-zero, this is a .vsave directive. */
4724
4725 static void
4726 s_arm_unwind_save (int arch_v6)
4727 {
4728 char *peek;
4729 struct reg_entry *reg;
4730 bfd_boolean had_brace = FALSE;
4731
4732 if (!unwind.proc_start)
4733 as_bad (MISSING_FNSTART);
4734
4735 /* Figure out what sort of save we have. */
4736 peek = input_line_pointer;
4737
4738 if (*peek == '{')
4739 {
4740 had_brace = TRUE;
4741 peek++;
4742 }
4743
4744 reg = arm_reg_parse_multi (&peek);
4745
4746 if (!reg)
4747 {
4748 as_bad (_("register expected"));
4749 ignore_rest_of_line ();
4750 return;
4751 }
4752
4753 switch (reg->type)
4754 {
4755 case REG_TYPE_FN:
4756 if (had_brace)
4757 {
4758 as_bad (_("FPA .unwind_save does not take a register list"));
4759 ignore_rest_of_line ();
4760 return;
4761 }
4762 input_line_pointer = peek;
4763 s_arm_unwind_save_fpa (reg->number);
4764 return;
4765
4766 case REG_TYPE_RN:
4767 s_arm_unwind_save_core ();
4768 return;
4769
4770 case REG_TYPE_VFD:
4771 if (arch_v6)
4772 s_arm_unwind_save_vfp_armv6 ();
4773 else
4774 s_arm_unwind_save_vfp ();
4775 return;
4776
4777 case REG_TYPE_MMXWR:
4778 s_arm_unwind_save_mmxwr ();
4779 return;
4780
4781 case REG_TYPE_MMXWCG:
4782 s_arm_unwind_save_mmxwcg ();
4783 return;
4784
4785 default:
4786 as_bad (_(".unwind_save does not support this kind of register"));
4787 ignore_rest_of_line ();
4788 }
4789 }
4790
4791
4792 /* Parse an unwind_movsp directive. */
4793
4794 static void
4795 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4796 {
4797 int reg;
4798 valueT op;
4799 int offset;
4800
4801 if (!unwind.proc_start)
4802 as_bad (MISSING_FNSTART);
4803
4804 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4805 if (reg == FAIL)
4806 {
4807 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4808 ignore_rest_of_line ();
4809 return;
4810 }
4811
4812 /* Optional constant. */
4813 if (skip_past_comma (&input_line_pointer) != FAIL)
4814 {
4815 if (immediate_for_directive (&offset) == FAIL)
4816 return;
4817 }
4818 else
4819 offset = 0;
4820
4821 demand_empty_rest_of_line ();
4822
4823 if (reg == REG_SP || reg == REG_PC)
4824 {
4825 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4826 return;
4827 }
4828
4829 if (unwind.fp_reg != REG_SP)
4830 as_bad (_("unexpected .unwind_movsp directive"));
4831
4832 /* Generate opcode to restore the value. */
4833 op = 0x90 | reg;
4834 add_unwind_opcode (op, 1);
4835
4836 /* Record the information for later. */
4837 unwind.fp_reg = reg;
4838 unwind.fp_offset = unwind.frame_size - offset;
4839 unwind.sp_restored = 1;
4840 }
4841
4842 /* Parse an unwind_pad directive. */
4843
4844 static void
4845 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4846 {
4847 int offset;
4848
4849 if (!unwind.proc_start)
4850 as_bad (MISSING_FNSTART);
4851
4852 if (immediate_for_directive (&offset) == FAIL)
4853 return;
4854
4855 if (offset & 3)
4856 {
4857 as_bad (_("stack increment must be multiple of 4"));
4858 ignore_rest_of_line ();
4859 return;
4860 }
4861
4862 /* Don't generate any opcodes, just record the details for later. */
4863 unwind.frame_size += offset;
4864 unwind.pending_offset += offset;
4865
4866 demand_empty_rest_of_line ();
4867 }
4868
4869 /* Parse an unwind_setfp directive. */
4870
4871 static void
4872 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4873 {
4874 int sp_reg;
4875 int fp_reg;
4876 int offset;
4877
4878 if (!unwind.proc_start)
4879 as_bad (MISSING_FNSTART);
4880
4881 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4882 if (skip_past_comma (&input_line_pointer) == FAIL)
4883 sp_reg = FAIL;
4884 else
4885 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4886
4887 if (fp_reg == FAIL || sp_reg == FAIL)
4888 {
4889 as_bad (_("expected <reg>, <reg>"));
4890 ignore_rest_of_line ();
4891 return;
4892 }
4893
4894 /* Optional constant. */
4895 if (skip_past_comma (&input_line_pointer) != FAIL)
4896 {
4897 if (immediate_for_directive (&offset) == FAIL)
4898 return;
4899 }
4900 else
4901 offset = 0;
4902
4903 demand_empty_rest_of_line ();
4904
4905 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4906 {
4907 as_bad (_("register must be either sp or set by a previous"
4908 "unwind_movsp directive"));
4909 return;
4910 }
4911
4912 /* Don't generate any opcodes, just record the information for later. */
4913 unwind.fp_reg = fp_reg;
4914 unwind.fp_used = 1;
4915 if (sp_reg == REG_SP)
4916 unwind.fp_offset = unwind.frame_size - offset;
4917 else
4918 unwind.fp_offset -= offset;
4919 }
4920
4921 /* Parse an unwind_raw directive. */
4922
4923 static void
4924 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4925 {
4926 expressionS exp;
4927 /* This is an arbitrary limit. */
4928 unsigned char op[16];
4929 int count;
4930
4931 if (!unwind.proc_start)
4932 as_bad (MISSING_FNSTART);
4933
4934 expression (&exp);
4935 if (exp.X_op == O_constant
4936 && skip_past_comma (&input_line_pointer) != FAIL)
4937 {
4938 unwind.frame_size += exp.X_add_number;
4939 expression (&exp);
4940 }
4941 else
4942 exp.X_op = O_illegal;
4943
4944 if (exp.X_op != O_constant)
4945 {
4946 as_bad (_("expected <offset>, <opcode>"));
4947 ignore_rest_of_line ();
4948 return;
4949 }
4950
4951 count = 0;
4952
4953 /* Parse the opcode. */
4954 for (;;)
4955 {
4956 if (count >= 16)
4957 {
4958 as_bad (_("unwind opcode too long"));
4959 ignore_rest_of_line ();
4960 }
4961 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4962 {
4963 as_bad (_("invalid unwind opcode"));
4964 ignore_rest_of_line ();
4965 return;
4966 }
4967 op[count++] = exp.X_add_number;
4968
4969 /* Parse the next byte. */
4970 if (skip_past_comma (&input_line_pointer) == FAIL)
4971 break;
4972
4973 expression (&exp);
4974 }
4975
4976 /* Add the opcode bytes in reverse order. */
4977 while (count--)
4978 add_unwind_opcode (op[count], 1);
4979
4980 demand_empty_rest_of_line ();
4981 }
4982
4983
4984 /* Parse a .eabi_attribute directive. */
4985
4986 static void
4987 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4988 {
4989 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
4990
4991 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4992 attributes_set_explicitly[tag] = 1;
4993 }
4994
4995 /* Emit a tls fix for the symbol. */
4996
4997 static void
4998 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4999 {
5000 char *p;
5001 expressionS exp;
5002 #ifdef md_flush_pending_output
5003 md_flush_pending_output ();
5004 #endif
5005
5006 #ifdef md_cons_align
5007 md_cons_align (4);
5008 #endif
5009
5010 /* Since we're just labelling the code, there's no need to define a
5011 mapping symbol. */
5012 expression (&exp);
5013 p = obstack_next_free (&frchain_now->frch_obstack);
5014 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
5015 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
5016 : BFD_RELOC_ARM_TLS_DESCSEQ);
5017 }
5018 #endif /* OBJ_ELF */
5019
5020 static void s_arm_arch (int);
5021 static void s_arm_object_arch (int);
5022 static void s_arm_cpu (int);
5023 static void s_arm_fpu (int);
5024 static void s_arm_arch_extension (int);
5025
5026 #ifdef TE_PE
5027
5028 static void
5029 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
5030 {
5031 expressionS exp;
5032
5033 do
5034 {
5035 expression (&exp);
5036 if (exp.X_op == O_symbol)
5037 exp.X_op = O_secrel;
5038
5039 emit_expr (&exp, 4);
5040 }
5041 while (*input_line_pointer++ == ',');
5042
5043 input_line_pointer--;
5044 demand_empty_rest_of_line ();
5045 }
5046 #endif /* TE_PE */
5047
5048 int
5049 arm_is_largest_exponent_ok (int precision)
5050 {
5051 /* precision == 1 ensures that this will only return
5052 true for 16 bit floats. */
5053 return (precision == 1) && (fp16_format == ARM_FP16_FORMAT_ALTERNATIVE);
5054 }
5055
5056 static void
5057 set_fp16_format (int dummy ATTRIBUTE_UNUSED)
5058 {
5059 char saved_char;
5060 char* name;
5061 enum fp_16bit_format new_format;
5062
5063 new_format = ARM_FP16_FORMAT_DEFAULT;
5064
5065 name = input_line_pointer;
5066 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
5067 input_line_pointer++;
5068
5069 saved_char = *input_line_pointer;
5070 *input_line_pointer = 0;
5071
5072 if (strcasecmp (name, "ieee") == 0)
5073 new_format = ARM_FP16_FORMAT_IEEE;
5074 else if (strcasecmp (name, "alternative") == 0)
5075 new_format = ARM_FP16_FORMAT_ALTERNATIVE;
5076 else
5077 {
5078 as_bad (_("unrecognised float16 format \"%s\""), name);
5079 goto cleanup;
5080 }
5081
5082 /* Only set fp16_format if it is still the default (aka not already
5083 been set yet). */
5084 if (fp16_format == ARM_FP16_FORMAT_DEFAULT)
5085 fp16_format = new_format;
5086 else
5087 {
5088 if (new_format != fp16_format)
5089 as_warn (_("float16 format cannot be set more than once, ignoring."));
5090 }
5091
5092 cleanup:
5093 *input_line_pointer = saved_char;
5094 ignore_rest_of_line ();
5095 }
5096
5097 /* This table describes all the machine specific pseudo-ops the assembler
5098 has to support. The fields are:
5099 pseudo-op name without dot
5100 function to call to execute this pseudo-op
5101 Integer arg to pass to the function. */
5102
5103 const pseudo_typeS md_pseudo_table[] =
5104 {
5105 /* Never called because '.req' does not start a line. */
5106 { "req", s_req, 0 },
5107 /* Following two are likewise never called. */
5108 { "dn", s_dn, 0 },
5109 { "qn", s_qn, 0 },
5110 { "unreq", s_unreq, 0 },
5111 { "bss", s_bss, 0 },
5112 { "align", s_align_ptwo, 2 },
5113 { "arm", s_arm, 0 },
5114 { "thumb", s_thumb, 0 },
5115 { "code", s_code, 0 },
5116 { "force_thumb", s_force_thumb, 0 },
5117 { "thumb_func", s_thumb_func, 0 },
5118 { "thumb_set", s_thumb_set, 0 },
5119 { "even", s_even, 0 },
5120 { "ltorg", s_ltorg, 0 },
5121 { "pool", s_ltorg, 0 },
5122 { "syntax", s_syntax, 0 },
5123 { "cpu", s_arm_cpu, 0 },
5124 { "arch", s_arm_arch, 0 },
5125 { "object_arch", s_arm_object_arch, 0 },
5126 { "fpu", s_arm_fpu, 0 },
5127 { "arch_extension", s_arm_arch_extension, 0 },
5128 #ifdef OBJ_ELF
5129 { "word", s_arm_elf_cons, 4 },
5130 { "long", s_arm_elf_cons, 4 },
5131 { "inst.n", s_arm_elf_inst, 2 },
5132 { "inst.w", s_arm_elf_inst, 4 },
5133 { "inst", s_arm_elf_inst, 0 },
5134 { "rel31", s_arm_rel31, 0 },
5135 { "fnstart", s_arm_unwind_fnstart, 0 },
5136 { "fnend", s_arm_unwind_fnend, 0 },
5137 { "cantunwind", s_arm_unwind_cantunwind, 0 },
5138 { "personality", s_arm_unwind_personality, 0 },
5139 { "personalityindex", s_arm_unwind_personalityindex, 0 },
5140 { "handlerdata", s_arm_unwind_handlerdata, 0 },
5141 { "save", s_arm_unwind_save, 0 },
5142 { "vsave", s_arm_unwind_save, 1 },
5143 { "movsp", s_arm_unwind_movsp, 0 },
5144 { "pad", s_arm_unwind_pad, 0 },
5145 { "setfp", s_arm_unwind_setfp, 0 },
5146 { "unwind_raw", s_arm_unwind_raw, 0 },
5147 { "eabi_attribute", s_arm_eabi_attribute, 0 },
5148 { "tlsdescseq", s_arm_tls_descseq, 0 },
5149 #else
5150 { "word", cons, 4},
5151
5152 /* These are used for dwarf. */
5153 {"2byte", cons, 2},
5154 {"4byte", cons, 4},
5155 {"8byte", cons, 8},
5156 /* These are used for dwarf2. */
5157 { "file", dwarf2_directive_file, 0 },
5158 { "loc", dwarf2_directive_loc, 0 },
5159 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
5160 #endif
5161 { "extend", float_cons, 'x' },
5162 { "ldouble", float_cons, 'x' },
5163 { "packed", float_cons, 'p' },
5164 { "bfloat16", float_cons, 'b' },
5165 #ifdef TE_PE
5166 {"secrel32", pe_directive_secrel, 0},
5167 #endif
5168
5169 /* These are for compatibility with CodeComposer Studio. */
5170 {"ref", s_ccs_ref, 0},
5171 {"def", s_ccs_def, 0},
5172 {"asmfunc", s_ccs_asmfunc, 0},
5173 {"endasmfunc", s_ccs_endasmfunc, 0},
5174
5175 {"float16", float_cons, 'h' },
5176 {"float16_format", set_fp16_format, 0 },
5177
5178 { 0, 0, 0 }
5179 };
5180
5181 /* Parser functions used exclusively in instruction operands. */
5182
5183 /* Generic immediate-value read function for use in insn parsing.
5184 STR points to the beginning of the immediate (the leading #);
5185 VAL receives the value; if the value is outside [MIN, MAX]
5186 issue an error. PREFIX_OPT is true if the immediate prefix is
5187 optional. */
5188
5189 static int
5190 parse_immediate (char **str, int *val, int min, int max,
5191 bfd_boolean prefix_opt)
5192 {
5193 expressionS exp;
5194
5195 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
5196 if (exp.X_op != O_constant)
5197 {
5198 inst.error = _("constant expression required");
5199 return FAIL;
5200 }
5201
5202 if (exp.X_add_number < min || exp.X_add_number > max)
5203 {
5204 inst.error = _("immediate value out of range");
5205 return FAIL;
5206 }
5207
5208 *val = exp.X_add_number;
5209 return SUCCESS;
5210 }
5211
5212 /* Less-generic immediate-value read function with the possibility of loading a
5213 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5214 instructions. Puts the result directly in inst.operands[i]. */
5215
5216 static int
5217 parse_big_immediate (char **str, int i, expressionS *in_exp,
5218 bfd_boolean allow_symbol_p)
5219 {
5220 expressionS exp;
5221 expressionS *exp_p = in_exp ? in_exp : &exp;
5222 char *ptr = *str;
5223
5224 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5225
5226 if (exp_p->X_op == O_constant)
5227 {
5228 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
5229 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5230 O_constant. We have to be careful not to break compilation for
5231 32-bit X_add_number, though. */
5232 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
5233 {
5234 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5235 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5236 & 0xffffffff);
5237 inst.operands[i].regisimm = 1;
5238 }
5239 }
5240 else if (exp_p->X_op == O_big
5241 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5242 {
5243 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
5244
5245 /* Bignums have their least significant bits in
5246 generic_bignum[0]. Make sure we put 32 bits in imm and
5247 32 bits in reg, in a (hopefully) portable way. */
5248 gas_assert (parts != 0);
5249
5250 /* Make sure that the number is not too big.
5251 PR 11972: Bignums can now be sign-extended to the
5252 size of a .octa so check that the out of range bits
5253 are all zero or all one. */
5254 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
5255 {
5256 LITTLENUM_TYPE m = -1;
5257
5258 if (generic_bignum[parts * 2] != 0
5259 && generic_bignum[parts * 2] != m)
5260 return FAIL;
5261
5262 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
5263 if (generic_bignum[j] != generic_bignum[j-1])
5264 return FAIL;
5265 }
5266
5267 inst.operands[i].imm = 0;
5268 for (j = 0; j < parts; j++, idx++)
5269 inst.operands[i].imm |= generic_bignum[idx]
5270 << (LITTLENUM_NUMBER_OF_BITS * j);
5271 inst.operands[i].reg = 0;
5272 for (j = 0; j < parts; j++, idx++)
5273 inst.operands[i].reg |= generic_bignum[idx]
5274 << (LITTLENUM_NUMBER_OF_BITS * j);
5275 inst.operands[i].regisimm = 1;
5276 }
5277 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5278 return FAIL;
5279
5280 *str = ptr;
5281
5282 return SUCCESS;
5283 }
5284
5285 /* Returns the pseudo-register number of an FPA immediate constant,
5286 or FAIL if there isn't a valid constant here. */
5287
5288 static int
5289 parse_fpa_immediate (char ** str)
5290 {
5291 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5292 char * save_in;
5293 expressionS exp;
5294 int i;
5295 int j;
5296
5297 /* First try and match exact strings, this is to guarantee
5298 that some formats will work even for cross assembly. */
5299
5300 for (i = 0; fp_const[i]; i++)
5301 {
5302 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
5303 {
5304 char *start = *str;
5305
5306 *str += strlen (fp_const[i]);
5307 if (is_end_of_line[(unsigned char) **str])
5308 return i + 8;
5309 *str = start;
5310 }
5311 }
5312
5313 /* Just because we didn't get a match doesn't mean that the constant
5314 isn't valid, just that it is in a format that we don't
5315 automatically recognize. Try parsing it with the standard
5316 expression routines. */
5317
5318 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
5319
5320 /* Look for a raw floating point number. */
5321 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
5322 && is_end_of_line[(unsigned char) *save_in])
5323 {
5324 for (i = 0; i < NUM_FLOAT_VALS; i++)
5325 {
5326 for (j = 0; j < MAX_LITTLENUMS; j++)
5327 {
5328 if (words[j] != fp_values[i][j])
5329 break;
5330 }
5331
5332 if (j == MAX_LITTLENUMS)
5333 {
5334 *str = save_in;
5335 return i + 8;
5336 }
5337 }
5338 }
5339
5340 /* Try and parse a more complex expression, this will probably fail
5341 unless the code uses a floating point prefix (eg "0f"). */
5342 save_in = input_line_pointer;
5343 input_line_pointer = *str;
5344 if (expression (&exp) == absolute_section
5345 && exp.X_op == O_big
5346 && exp.X_add_number < 0)
5347 {
5348 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
5349 Ditto for 15. */
5350 #define X_PRECISION 5
5351 #define E_PRECISION 15L
5352 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
5353 {
5354 for (i = 0; i < NUM_FLOAT_VALS; i++)
5355 {
5356 for (j = 0; j < MAX_LITTLENUMS; j++)
5357 {
5358 if (words[j] != fp_values[i][j])
5359 break;
5360 }
5361
5362 if (j == MAX_LITTLENUMS)
5363 {
5364 *str = input_line_pointer;
5365 input_line_pointer = save_in;
5366 return i + 8;
5367 }
5368 }
5369 }
5370 }
5371
5372 *str = input_line_pointer;
5373 input_line_pointer = save_in;
5374 inst.error = _("invalid FPA immediate expression");
5375 return FAIL;
5376 }
5377
5378 /* Returns 1 if a number has "quarter-precision" float format
5379 0baBbbbbbc defgh000 00000000 00000000. */
5380
5381 static int
5382 is_quarter_float (unsigned imm)
5383 {
5384 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5385 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5386 }
5387
5388
5389 /* Detect the presence of a floating point or integer zero constant,
5390 i.e. #0.0 or #0. */
5391
5392 static bfd_boolean
5393 parse_ifimm_zero (char **in)
5394 {
5395 int error_code;
5396
5397 if (!is_immediate_prefix (**in))
5398 {
5399 /* In unified syntax, all prefixes are optional. */
5400 if (!unified_syntax)
5401 return FALSE;
5402 }
5403 else
5404 ++*in;
5405
5406 /* Accept #0x0 as a synonym for #0. */
5407 if (strncmp (*in, "0x", 2) == 0)
5408 {
5409 int val;
5410 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5411 return FALSE;
5412 return TRUE;
5413 }
5414
5415 error_code = atof_generic (in, ".", EXP_CHARS,
5416 &generic_floating_point_number);
5417
5418 if (!error_code
5419 && generic_floating_point_number.sign == '+'
5420 && (generic_floating_point_number.low
5421 > generic_floating_point_number.leader))
5422 return TRUE;
5423
5424 return FALSE;
5425 }
5426
5427 /* Parse an 8-bit "quarter-precision" floating point number of the form:
5428 0baBbbbbbc defgh000 00000000 00000000.
5429 The zero and minus-zero cases need special handling, since they can't be
5430 encoded in the "quarter-precision" float format, but can nonetheless be
5431 loaded as integer constants. */
5432
5433 static unsigned
5434 parse_qfloat_immediate (char **ccp, int *immed)
5435 {
5436 char *str = *ccp;
5437 char *fpnum;
5438 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5439 int found_fpchar = 0;
5440
5441 skip_past_char (&str, '#');
5442
5443 /* We must not accidentally parse an integer as a floating-point number. Make
5444 sure that the value we parse is not an integer by checking for special
5445 characters '.' or 'e'.
5446 FIXME: This is a horrible hack, but doing better is tricky because type
5447 information isn't in a very usable state at parse time. */
5448 fpnum = str;
5449 skip_whitespace (fpnum);
5450
5451 if (strncmp (fpnum, "0x", 2) == 0)
5452 return FAIL;
5453 else
5454 {
5455 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
5456 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5457 {
5458 found_fpchar = 1;
5459 break;
5460 }
5461
5462 if (!found_fpchar)
5463 return FAIL;
5464 }
5465
5466 if ((str = atof_ieee (str, 's', words)) != NULL)
5467 {
5468 unsigned fpword = 0;
5469 int i;
5470
5471 /* Our FP word must be 32 bits (single-precision FP). */
5472 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
5473 {
5474 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5475 fpword |= words[i];
5476 }
5477
5478 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
5479 *immed = fpword;
5480 else
5481 return FAIL;
5482
5483 *ccp = str;
5484
5485 return SUCCESS;
5486 }
5487
5488 return FAIL;
5489 }
5490
5491 /* Shift operands. */
5492 enum shift_kind
5493 {
5494 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW
5495 };
5496
5497 struct asm_shift_name
5498 {
5499 const char *name;
5500 enum shift_kind kind;
5501 };
5502
5503 /* Third argument to parse_shift. */
5504 enum parse_shift_mode
5505 {
5506 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5507 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5508 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5509 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5510 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5511 SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */
5512 };
5513
5514 /* Parse a <shift> specifier on an ARM data processing instruction.
5515 This has three forms:
5516
5517 (LSL|LSR|ASL|ASR|ROR) Rs
5518 (LSL|LSR|ASL|ASR|ROR) #imm
5519 RRX
5520
5521 Note that ASL is assimilated to LSL in the instruction encoding, and
5522 RRX to ROR #0 (which cannot be written as such). */
5523
5524 static int
5525 parse_shift (char **str, int i, enum parse_shift_mode mode)
5526 {
5527 const struct asm_shift_name *shift_name;
5528 enum shift_kind shift;
5529 char *s = *str;
5530 char *p = s;
5531 int reg;
5532
5533 for (p = *str; ISALPHA (*p); p++)
5534 ;
5535
5536 if (p == *str)
5537 {
5538 inst.error = _("shift expression expected");
5539 return FAIL;
5540 }
5541
5542 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
5543 p - *str);
5544
5545 if (shift_name == NULL)
5546 {
5547 inst.error = _("shift expression expected");
5548 return FAIL;
5549 }
5550
5551 shift = shift_name->kind;
5552
5553 switch (mode)
5554 {
5555 case NO_SHIFT_RESTRICT:
5556 case SHIFT_IMMEDIATE:
5557 if (shift == SHIFT_UXTW)
5558 {
5559 inst.error = _("'UXTW' not allowed here");
5560 return FAIL;
5561 }
5562 break;
5563
5564 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5565 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5566 {
5567 inst.error = _("'LSL' or 'ASR' required");
5568 return FAIL;
5569 }
5570 break;
5571
5572 case SHIFT_LSL_IMMEDIATE:
5573 if (shift != SHIFT_LSL)
5574 {
5575 inst.error = _("'LSL' required");
5576 return FAIL;
5577 }
5578 break;
5579
5580 case SHIFT_ASR_IMMEDIATE:
5581 if (shift != SHIFT_ASR)
5582 {
5583 inst.error = _("'ASR' required");
5584 return FAIL;
5585 }
5586 break;
5587 case SHIFT_UXTW_IMMEDIATE:
5588 if (shift != SHIFT_UXTW)
5589 {
5590 inst.error = _("'UXTW' required");
5591 return FAIL;
5592 }
5593 break;
5594
5595 default: abort ();
5596 }
5597
5598 if (shift != SHIFT_RRX)
5599 {
5600 /* Whitespace can appear here if the next thing is a bare digit. */
5601 skip_whitespace (p);
5602
5603 if (mode == NO_SHIFT_RESTRICT
5604 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5605 {
5606 inst.operands[i].imm = reg;
5607 inst.operands[i].immisreg = 1;
5608 }
5609 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
5610 return FAIL;
5611 }
5612 inst.operands[i].shift_kind = shift;
5613 inst.operands[i].shifted = 1;
5614 *str = p;
5615 return SUCCESS;
5616 }
5617
5618 /* Parse a <shifter_operand> for an ARM data processing instruction:
5619
5620 #<immediate>
5621 #<immediate>, <rotate>
5622 <Rm>
5623 <Rm>, <shift>
5624
5625 where <shift> is defined by parse_shift above, and <rotate> is a
5626 multiple of 2 between 0 and 30. Validation of immediate operands
5627 is deferred to md_apply_fix. */
5628
5629 static int
5630 parse_shifter_operand (char **str, int i)
5631 {
5632 int value;
5633 expressionS exp;
5634
5635 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
5636 {
5637 inst.operands[i].reg = value;
5638 inst.operands[i].isreg = 1;
5639
5640 /* parse_shift will override this if appropriate */
5641 inst.relocs[0].exp.X_op = O_constant;
5642 inst.relocs[0].exp.X_add_number = 0;
5643
5644 if (skip_past_comma (str) == FAIL)
5645 return SUCCESS;
5646
5647 /* Shift operation on register. */
5648 return parse_shift (str, i, NO_SHIFT_RESTRICT);
5649 }
5650
5651 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
5652 return FAIL;
5653
5654 if (skip_past_comma (str) == SUCCESS)
5655 {
5656 /* #x, y -- ie explicit rotation by Y. */
5657 if (my_get_expression (&exp, str, GE_NO_PREFIX))
5658 return FAIL;
5659
5660 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
5661 {
5662 inst.error = _("constant expression expected");
5663 return FAIL;
5664 }
5665
5666 value = exp.X_add_number;
5667 if (value < 0 || value > 30 || value % 2 != 0)
5668 {
5669 inst.error = _("invalid rotation");
5670 return FAIL;
5671 }
5672 if (inst.relocs[0].exp.X_add_number < 0
5673 || inst.relocs[0].exp.X_add_number > 255)
5674 {
5675 inst.error = _("invalid constant");
5676 return FAIL;
5677 }
5678
5679 /* Encode as specified. */
5680 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
5681 return SUCCESS;
5682 }
5683
5684 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5685 inst.relocs[0].pc_rel = 0;
5686 return SUCCESS;
5687 }
5688
5689 /* Group relocation information. Each entry in the table contains the
5690 textual name of the relocation as may appear in assembler source
5691 and must end with a colon.
5692 Along with this textual name are the relocation codes to be used if
5693 the corresponding instruction is an ALU instruction (ADD or SUB only),
5694 an LDR, an LDRS, or an LDC. */
5695
5696 struct group_reloc_table_entry
5697 {
5698 const char *name;
5699 int alu_code;
5700 int ldr_code;
5701 int ldrs_code;
5702 int ldc_code;
5703 };
5704
5705 typedef enum
5706 {
5707 /* Varieties of non-ALU group relocation. */
5708
5709 GROUP_LDR,
5710 GROUP_LDRS,
5711 GROUP_LDC,
5712 GROUP_MVE
5713 } group_reloc_type;
5714
5715 static struct group_reloc_table_entry group_reloc_table[] =
5716 { /* Program counter relative: */
5717 { "pc_g0_nc",
5718 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5719 0, /* LDR */
5720 0, /* LDRS */
5721 0 }, /* LDC */
5722 { "pc_g0",
5723 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5724 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5725 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5726 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5727 { "pc_g1_nc",
5728 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5729 0, /* LDR */
5730 0, /* LDRS */
5731 0 }, /* LDC */
5732 { "pc_g1",
5733 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5734 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5735 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5736 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5737 { "pc_g2",
5738 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5739 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5740 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5741 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5742 /* Section base relative */
5743 { "sb_g0_nc",
5744 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5745 0, /* LDR */
5746 0, /* LDRS */
5747 0 }, /* LDC */
5748 { "sb_g0",
5749 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5750 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5751 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5752 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5753 { "sb_g1_nc",
5754 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5755 0, /* LDR */
5756 0, /* LDRS */
5757 0 }, /* LDC */
5758 { "sb_g1",
5759 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5760 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5761 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5762 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5763 { "sb_g2",
5764 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5765 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5766 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5767 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5768 /* Absolute thumb alu relocations. */
5769 { "lower0_7",
5770 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5771 0, /* LDR. */
5772 0, /* LDRS. */
5773 0 }, /* LDC. */
5774 { "lower8_15",
5775 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5776 0, /* LDR. */
5777 0, /* LDRS. */
5778 0 }, /* LDC. */
5779 { "upper0_7",
5780 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5781 0, /* LDR. */
5782 0, /* LDRS. */
5783 0 }, /* LDC. */
5784 { "upper8_15",
5785 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5786 0, /* LDR. */
5787 0, /* LDRS. */
5788 0 } }; /* LDC. */
5789
5790 /* Given the address of a pointer pointing to the textual name of a group
5791 relocation as may appear in assembler source, attempt to find its details
5792 in group_reloc_table. The pointer will be updated to the character after
5793 the trailing colon. On failure, FAIL will be returned; SUCCESS
5794 otherwise. On success, *entry will be updated to point at the relevant
5795 group_reloc_table entry. */
5796
5797 static int
5798 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5799 {
5800 unsigned int i;
5801 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5802 {
5803 int length = strlen (group_reloc_table[i].name);
5804
5805 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5806 && (*str)[length] == ':')
5807 {
5808 *out = &group_reloc_table[i];
5809 *str += (length + 1);
5810 return SUCCESS;
5811 }
5812 }
5813
5814 return FAIL;
5815 }
5816
5817 /* Parse a <shifter_operand> for an ARM data processing instruction
5818 (as for parse_shifter_operand) where group relocations are allowed:
5819
5820 #<immediate>
5821 #<immediate>, <rotate>
5822 #:<group_reloc>:<expression>
5823 <Rm>
5824 <Rm>, <shift>
5825
5826 where <group_reloc> is one of the strings defined in group_reloc_table.
5827 The hashes are optional.
5828
5829 Everything else is as for parse_shifter_operand. */
5830
5831 static parse_operand_result
5832 parse_shifter_operand_group_reloc (char **str, int i)
5833 {
5834 /* Determine if we have the sequence of characters #: or just :
5835 coming next. If we do, then we check for a group relocation.
5836 If we don't, punt the whole lot to parse_shifter_operand. */
5837
5838 if (((*str)[0] == '#' && (*str)[1] == ':')
5839 || (*str)[0] == ':')
5840 {
5841 struct group_reloc_table_entry *entry;
5842
5843 if ((*str)[0] == '#')
5844 (*str) += 2;
5845 else
5846 (*str)++;
5847
5848 /* Try to parse a group relocation. Anything else is an error. */
5849 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5850 {
5851 inst.error = _("unknown group relocation");
5852 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5853 }
5854
5855 /* We now have the group relocation table entry corresponding to
5856 the name in the assembler source. Next, we parse the expression. */
5857 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
5858 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5859
5860 /* Record the relocation type (always the ALU variant here). */
5861 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5862 gas_assert (inst.relocs[0].type != 0);
5863
5864 return PARSE_OPERAND_SUCCESS;
5865 }
5866 else
5867 return parse_shifter_operand (str, i) == SUCCESS
5868 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5869
5870 /* Never reached. */
5871 }
5872
5873 /* Parse a Neon alignment expression. Information is written to
5874 inst.operands[i]. We assume the initial ':' has been skipped.
5875
5876 align .imm = align << 8, .immisalign=1, .preind=0 */
5877 static parse_operand_result
5878 parse_neon_alignment (char **str, int i)
5879 {
5880 char *p = *str;
5881 expressionS exp;
5882
5883 my_get_expression (&exp, &p, GE_NO_PREFIX);
5884
5885 if (exp.X_op != O_constant)
5886 {
5887 inst.error = _("alignment must be constant");
5888 return PARSE_OPERAND_FAIL;
5889 }
5890
5891 inst.operands[i].imm = exp.X_add_number << 8;
5892 inst.operands[i].immisalign = 1;
5893 /* Alignments are not pre-indexes. */
5894 inst.operands[i].preind = 0;
5895
5896 *str = p;
5897 return PARSE_OPERAND_SUCCESS;
5898 }
5899
5900 /* Parse all forms of an ARM address expression. Information is written
5901 to inst.operands[i] and/or inst.relocs[0].
5902
5903 Preindexed addressing (.preind=1):
5904
5905 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
5906 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5907 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5908 .shift_kind=shift .relocs[0].exp=shift_imm
5909
5910 These three may have a trailing ! which causes .writeback to be set also.
5911
5912 Postindexed addressing (.postind=1, .writeback=1):
5913
5914 [Rn], #offset .reg=Rn .relocs[0].exp=offset
5915 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5916 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5917 .shift_kind=shift .relocs[0].exp=shift_imm
5918
5919 Unindexed addressing (.preind=0, .postind=0):
5920
5921 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5922
5923 Other:
5924
5925 [Rn]{!} shorthand for [Rn,#0]{!}
5926 =immediate .isreg=0 .relocs[0].exp=immediate
5927 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
5928
5929 It is the caller's responsibility to check for addressing modes not
5930 supported by the instruction, and to set inst.relocs[0].type. */
5931
5932 static parse_operand_result
5933 parse_address_main (char **str, int i, int group_relocations,
5934 group_reloc_type group_type)
5935 {
5936 char *p = *str;
5937 int reg;
5938
5939 if (skip_past_char (&p, '[') == FAIL)
5940 {
5941 if (skip_past_char (&p, '=') == FAIL)
5942 {
5943 /* Bare address - translate to PC-relative offset. */
5944 inst.relocs[0].pc_rel = 1;
5945 inst.operands[i].reg = REG_PC;
5946 inst.operands[i].isreg = 1;
5947 inst.operands[i].preind = 1;
5948
5949 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
5950 return PARSE_OPERAND_FAIL;
5951 }
5952 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
5953 /*allow_symbol_p=*/TRUE))
5954 return PARSE_OPERAND_FAIL;
5955
5956 *str = p;
5957 return PARSE_OPERAND_SUCCESS;
5958 }
5959
5960 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5961 skip_whitespace (p);
5962
5963 if (group_type == GROUP_MVE)
5964 {
5965 enum arm_reg_type rtype = REG_TYPE_MQ;
5966 struct neon_type_el et;
5967 if ((reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5968 {
5969 inst.operands[i].isquad = 1;
5970 }
5971 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5972 {
5973 inst.error = BAD_ADDR_MODE;
5974 return PARSE_OPERAND_FAIL;
5975 }
5976 }
5977 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5978 {
5979 if (group_type == GROUP_MVE)
5980 inst.error = BAD_ADDR_MODE;
5981 else
5982 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5983 return PARSE_OPERAND_FAIL;
5984 }
5985 inst.operands[i].reg = reg;
5986 inst.operands[i].isreg = 1;
5987
5988 if (skip_past_comma (&p) == SUCCESS)
5989 {
5990 inst.operands[i].preind = 1;
5991
5992 if (*p == '+') p++;
5993 else if (*p == '-') p++, inst.operands[i].negative = 1;
5994
5995 enum arm_reg_type rtype = REG_TYPE_MQ;
5996 struct neon_type_el et;
5997 if (group_type == GROUP_MVE
5998 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5999 {
6000 inst.operands[i].immisreg = 2;
6001 inst.operands[i].imm = reg;
6002
6003 if (skip_past_comma (&p) == SUCCESS)
6004 {
6005 if (parse_shift (&p, i, SHIFT_UXTW_IMMEDIATE) == SUCCESS)
6006 {
6007 inst.operands[i].imm |= inst.relocs[0].exp.X_add_number << 5;
6008 inst.relocs[0].exp.X_add_number = 0;
6009 }
6010 else
6011 return PARSE_OPERAND_FAIL;
6012 }
6013 }
6014 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
6015 {
6016 inst.operands[i].imm = reg;
6017 inst.operands[i].immisreg = 1;
6018
6019 if (skip_past_comma (&p) == SUCCESS)
6020 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
6021 return PARSE_OPERAND_FAIL;
6022 }
6023 else if (skip_past_char (&p, ':') == SUCCESS)
6024 {
6025 /* FIXME: '@' should be used here, but it's filtered out by generic
6026 code before we get to see it here. This may be subject to
6027 change. */
6028 parse_operand_result result = parse_neon_alignment (&p, i);
6029
6030 if (result != PARSE_OPERAND_SUCCESS)
6031 return result;
6032 }
6033 else
6034 {
6035 if (inst.operands[i].negative)
6036 {
6037 inst.operands[i].negative = 0;
6038 p--;
6039 }
6040
6041 if (group_relocations
6042 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
6043 {
6044 struct group_reloc_table_entry *entry;
6045
6046 /* Skip over the #: or : sequence. */
6047 if (*p == '#')
6048 p += 2;
6049 else
6050 p++;
6051
6052 /* Try to parse a group relocation. Anything else is an
6053 error. */
6054 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
6055 {
6056 inst.error = _("unknown group relocation");
6057 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6058 }
6059
6060 /* We now have the group relocation table entry corresponding to
6061 the name in the assembler source. Next, we parse the
6062 expression. */
6063 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
6064 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6065
6066 /* Record the relocation type. */
6067 switch (group_type)
6068 {
6069 case GROUP_LDR:
6070 inst.relocs[0].type
6071 = (bfd_reloc_code_real_type) entry->ldr_code;
6072 break;
6073
6074 case GROUP_LDRS:
6075 inst.relocs[0].type
6076 = (bfd_reloc_code_real_type) entry->ldrs_code;
6077 break;
6078
6079 case GROUP_LDC:
6080 inst.relocs[0].type
6081 = (bfd_reloc_code_real_type) entry->ldc_code;
6082 break;
6083
6084 default:
6085 gas_assert (0);
6086 }
6087
6088 if (inst.relocs[0].type == 0)
6089 {
6090 inst.error = _("this group relocation is not allowed on this instruction");
6091 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6092 }
6093 }
6094 else
6095 {
6096 char *q = p;
6097
6098 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
6099 return PARSE_OPERAND_FAIL;
6100 /* If the offset is 0, find out if it's a +0 or -0. */
6101 if (inst.relocs[0].exp.X_op == O_constant
6102 && inst.relocs[0].exp.X_add_number == 0)
6103 {
6104 skip_whitespace (q);
6105 if (*q == '#')
6106 {
6107 q++;
6108 skip_whitespace (q);
6109 }
6110 if (*q == '-')
6111 inst.operands[i].negative = 1;
6112 }
6113 }
6114 }
6115 }
6116 else if (skip_past_char (&p, ':') == SUCCESS)
6117 {
6118 /* FIXME: '@' should be used here, but it's filtered out by generic code
6119 before we get to see it here. This may be subject to change. */
6120 parse_operand_result result = parse_neon_alignment (&p, i);
6121
6122 if (result != PARSE_OPERAND_SUCCESS)
6123 return result;
6124 }
6125
6126 if (skip_past_char (&p, ']') == FAIL)
6127 {
6128 inst.error = _("']' expected");
6129 return PARSE_OPERAND_FAIL;
6130 }
6131
6132 if (skip_past_char (&p, '!') == SUCCESS)
6133 inst.operands[i].writeback = 1;
6134
6135 else if (skip_past_comma (&p) == SUCCESS)
6136 {
6137 if (skip_past_char (&p, '{') == SUCCESS)
6138 {
6139 /* [Rn], {expr} - unindexed, with option */
6140 if (parse_immediate (&p, &inst.operands[i].imm,
6141 0, 255, TRUE) == FAIL)
6142 return PARSE_OPERAND_FAIL;
6143
6144 if (skip_past_char (&p, '}') == FAIL)
6145 {
6146 inst.error = _("'}' expected at end of 'option' field");
6147 return PARSE_OPERAND_FAIL;
6148 }
6149 if (inst.operands[i].preind)
6150 {
6151 inst.error = _("cannot combine index with option");
6152 return PARSE_OPERAND_FAIL;
6153 }
6154 *str = p;
6155 return PARSE_OPERAND_SUCCESS;
6156 }
6157 else
6158 {
6159 inst.operands[i].postind = 1;
6160 inst.operands[i].writeback = 1;
6161
6162 if (inst.operands[i].preind)
6163 {
6164 inst.error = _("cannot combine pre- and post-indexing");
6165 return PARSE_OPERAND_FAIL;
6166 }
6167
6168 if (*p == '+') p++;
6169 else if (*p == '-') p++, inst.operands[i].negative = 1;
6170
6171 enum arm_reg_type rtype = REG_TYPE_MQ;
6172 struct neon_type_el et;
6173 if (group_type == GROUP_MVE
6174 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6175 {
6176 inst.operands[i].immisreg = 2;
6177 inst.operands[i].imm = reg;
6178 }
6179 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
6180 {
6181 /* We might be using the immediate for alignment already. If we
6182 are, OR the register number into the low-order bits. */
6183 if (inst.operands[i].immisalign)
6184 inst.operands[i].imm |= reg;
6185 else
6186 inst.operands[i].imm = reg;
6187 inst.operands[i].immisreg = 1;
6188
6189 if (skip_past_comma (&p) == SUCCESS)
6190 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
6191 return PARSE_OPERAND_FAIL;
6192 }
6193 else
6194 {
6195 char *q = p;
6196
6197 if (inst.operands[i].negative)
6198 {
6199 inst.operands[i].negative = 0;
6200 p--;
6201 }
6202 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
6203 return PARSE_OPERAND_FAIL;
6204 /* If the offset is 0, find out if it's a +0 or -0. */
6205 if (inst.relocs[0].exp.X_op == O_constant
6206 && inst.relocs[0].exp.X_add_number == 0)
6207 {
6208 skip_whitespace (q);
6209 if (*q == '#')
6210 {
6211 q++;
6212 skip_whitespace (q);
6213 }
6214 if (*q == '-')
6215 inst.operands[i].negative = 1;
6216 }
6217 }
6218 }
6219 }
6220
6221 /* If at this point neither .preind nor .postind is set, we have a
6222 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
6223 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
6224 {
6225 inst.operands[i].preind = 1;
6226 inst.relocs[0].exp.X_op = O_constant;
6227 inst.relocs[0].exp.X_add_number = 0;
6228 }
6229 *str = p;
6230 return PARSE_OPERAND_SUCCESS;
6231 }
6232
6233 static int
6234 parse_address (char **str, int i)
6235 {
6236 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
6237 ? SUCCESS : FAIL;
6238 }
6239
6240 static parse_operand_result
6241 parse_address_group_reloc (char **str, int i, group_reloc_type type)
6242 {
6243 return parse_address_main (str, i, 1, type);
6244 }
6245
6246 /* Parse an operand for a MOVW or MOVT instruction. */
6247 static int
6248 parse_half (char **str)
6249 {
6250 char * p;
6251
6252 p = *str;
6253 skip_past_char (&p, '#');
6254 if (strncasecmp (p, ":lower16:", 9) == 0)
6255 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
6256 else if (strncasecmp (p, ":upper16:", 9) == 0)
6257 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
6258
6259 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
6260 {
6261 p += 9;
6262 skip_whitespace (p);
6263 }
6264
6265 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
6266 return FAIL;
6267
6268 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
6269 {
6270 if (inst.relocs[0].exp.X_op != O_constant)
6271 {
6272 inst.error = _("constant expression expected");
6273 return FAIL;
6274 }
6275 if (inst.relocs[0].exp.X_add_number < 0
6276 || inst.relocs[0].exp.X_add_number > 0xffff)
6277 {
6278 inst.error = _("immediate value out of range");
6279 return FAIL;
6280 }
6281 }
6282 *str = p;
6283 return SUCCESS;
6284 }
6285
6286 /* Miscellaneous. */
6287
6288 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6289 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6290 static int
6291 parse_psr (char **str, bfd_boolean lhs)
6292 {
6293 char *p;
6294 unsigned long psr_field;
6295 const struct asm_psr *psr;
6296 char *start;
6297 bfd_boolean is_apsr = FALSE;
6298 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
6299
6300 /* PR gas/12698: If the user has specified -march=all then m_profile will
6301 be TRUE, but we want to ignore it in this case as we are building for any
6302 CPU type, including non-m variants. */
6303 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
6304 m_profile = FALSE;
6305
6306 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6307 feature for ease of use and backwards compatibility. */
6308 p = *str;
6309 if (strncasecmp (p, "SPSR", 4) == 0)
6310 {
6311 if (m_profile)
6312 goto unsupported_psr;
6313
6314 psr_field = SPSR_BIT;
6315 }
6316 else if (strncasecmp (p, "CPSR", 4) == 0)
6317 {
6318 if (m_profile)
6319 goto unsupported_psr;
6320
6321 psr_field = 0;
6322 }
6323 else if (strncasecmp (p, "APSR", 4) == 0)
6324 {
6325 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6326 and ARMv7-R architecture CPUs. */
6327 is_apsr = TRUE;
6328 psr_field = 0;
6329 }
6330 else if (m_profile)
6331 {
6332 start = p;
6333 do
6334 p++;
6335 while (ISALNUM (*p) || *p == '_');
6336
6337 if (strncasecmp (start, "iapsr", 5) == 0
6338 || strncasecmp (start, "eapsr", 5) == 0
6339 || strncasecmp (start, "xpsr", 4) == 0
6340 || strncasecmp (start, "psr", 3) == 0)
6341 p = start + strcspn (start, "rR") + 1;
6342
6343 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
6344 p - start);
6345
6346 if (!psr)
6347 return FAIL;
6348
6349 /* If APSR is being written, a bitfield may be specified. Note that
6350 APSR itself is handled above. */
6351 if (psr->field <= 3)
6352 {
6353 psr_field = psr->field;
6354 is_apsr = TRUE;
6355 goto check_suffix;
6356 }
6357
6358 *str = p;
6359 /* M-profile MSR instructions have the mask field set to "10", except
6360 *PSR variants which modify APSR, which may use a different mask (and
6361 have been handled already). Do that by setting the PSR_f field
6362 here. */
6363 return psr->field | (lhs ? PSR_f : 0);
6364 }
6365 else
6366 goto unsupported_psr;
6367
6368 p += 4;
6369 check_suffix:
6370 if (*p == '_')
6371 {
6372 /* A suffix follows. */
6373 p++;
6374 start = p;
6375
6376 do
6377 p++;
6378 while (ISALNUM (*p) || *p == '_');
6379
6380 if (is_apsr)
6381 {
6382 /* APSR uses a notation for bits, rather than fields. */
6383 unsigned int nzcvq_bits = 0;
6384 unsigned int g_bit = 0;
6385 char *bit;
6386
6387 for (bit = start; bit != p; bit++)
6388 {
6389 switch (TOLOWER (*bit))
6390 {
6391 case 'n':
6392 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6393 break;
6394
6395 case 'z':
6396 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6397 break;
6398
6399 case 'c':
6400 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6401 break;
6402
6403 case 'v':
6404 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6405 break;
6406
6407 case 'q':
6408 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6409 break;
6410
6411 case 'g':
6412 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6413 break;
6414
6415 default:
6416 inst.error = _("unexpected bit specified after APSR");
6417 return FAIL;
6418 }
6419 }
6420
6421 if (nzcvq_bits == 0x1f)
6422 psr_field |= PSR_f;
6423
6424 if (g_bit == 0x1)
6425 {
6426 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
6427 {
6428 inst.error = _("selected processor does not "
6429 "support DSP extension");
6430 return FAIL;
6431 }
6432
6433 psr_field |= PSR_s;
6434 }
6435
6436 if ((nzcvq_bits & 0x20) != 0
6437 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6438 || (g_bit & 0x2) != 0)
6439 {
6440 inst.error = _("bad bitmask specified after APSR");
6441 return FAIL;
6442 }
6443 }
6444 else
6445 {
6446 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
6447 p - start);
6448 if (!psr)
6449 goto error;
6450
6451 psr_field |= psr->field;
6452 }
6453 }
6454 else
6455 {
6456 if (ISALNUM (*p))
6457 goto error; /* Garbage after "[CS]PSR". */
6458
6459 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
6460 is deprecated, but allow it anyway. */
6461 if (is_apsr && lhs)
6462 {
6463 psr_field |= PSR_f;
6464 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6465 "deprecated"));
6466 }
6467 else if (!m_profile)
6468 /* These bits are never right for M-profile devices: don't set them
6469 (only code paths which read/write APSR reach here). */
6470 psr_field |= (PSR_c | PSR_f);
6471 }
6472 *str = p;
6473 return psr_field;
6474
6475 unsupported_psr:
6476 inst.error = _("selected processor does not support requested special "
6477 "purpose register");
6478 return FAIL;
6479
6480 error:
6481 inst.error = _("flag for {c}psr instruction expected");
6482 return FAIL;
6483 }
6484
6485 static int
6486 parse_sys_vldr_vstr (char **str)
6487 {
6488 unsigned i;
6489 int val = FAIL;
6490 struct {
6491 const char *name;
6492 int regl;
6493 int regh;
6494 } sysregs[] = {
6495 {"FPSCR", 0x1, 0x0},
6496 {"FPSCR_nzcvqc", 0x2, 0x0},
6497 {"VPR", 0x4, 0x1},
6498 {"P0", 0x5, 0x1},
6499 {"FPCXTNS", 0x6, 0x1},
6500 {"FPCXTS", 0x7, 0x1}
6501 };
6502 char *op_end = strchr (*str, ',');
6503 size_t op_strlen = op_end - *str;
6504
6505 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6506 {
6507 if (!strncmp (*str, sysregs[i].name, op_strlen))
6508 {
6509 val = sysregs[i].regl | (sysregs[i].regh << 3);
6510 *str = op_end;
6511 break;
6512 }
6513 }
6514
6515 return val;
6516 }
6517
6518 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6519 value suitable for splatting into the AIF field of the instruction. */
6520
6521 static int
6522 parse_cps_flags (char **str)
6523 {
6524 int val = 0;
6525 int saw_a_flag = 0;
6526 char *s = *str;
6527
6528 for (;;)
6529 switch (*s++)
6530 {
6531 case '\0': case ',':
6532 goto done;
6533
6534 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6535 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6536 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
6537
6538 default:
6539 inst.error = _("unrecognized CPS flag");
6540 return FAIL;
6541 }
6542
6543 done:
6544 if (saw_a_flag == 0)
6545 {
6546 inst.error = _("missing CPS flags");
6547 return FAIL;
6548 }
6549
6550 *str = s - 1;
6551 return val;
6552 }
6553
6554 /* Parse an endian specifier ("BE" or "LE", case insensitive);
6555 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
6556
6557 static int
6558 parse_endian_specifier (char **str)
6559 {
6560 int little_endian;
6561 char *s = *str;
6562
6563 if (strncasecmp (s, "BE", 2))
6564 little_endian = 0;
6565 else if (strncasecmp (s, "LE", 2))
6566 little_endian = 1;
6567 else
6568 {
6569 inst.error = _("valid endian specifiers are be or le");
6570 return FAIL;
6571 }
6572
6573 if (ISALNUM (s[2]) || s[2] == '_')
6574 {
6575 inst.error = _("valid endian specifiers are be or le");
6576 return FAIL;
6577 }
6578
6579 *str = s + 2;
6580 return little_endian;
6581 }
6582
6583 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6584 value suitable for poking into the rotate field of an sxt or sxta
6585 instruction, or FAIL on error. */
6586
6587 static int
6588 parse_ror (char **str)
6589 {
6590 int rot;
6591 char *s = *str;
6592
6593 if (strncasecmp (s, "ROR", 3) == 0)
6594 s += 3;
6595 else
6596 {
6597 inst.error = _("missing rotation field after comma");
6598 return FAIL;
6599 }
6600
6601 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6602 return FAIL;
6603
6604 switch (rot)
6605 {
6606 case 0: *str = s; return 0x0;
6607 case 8: *str = s; return 0x1;
6608 case 16: *str = s; return 0x2;
6609 case 24: *str = s; return 0x3;
6610
6611 default:
6612 inst.error = _("rotation can only be 0, 8, 16, or 24");
6613 return FAIL;
6614 }
6615 }
6616
6617 /* Parse a conditional code (from conds[] below). The value returned is in the
6618 range 0 .. 14, or FAIL. */
6619 static int
6620 parse_cond (char **str)
6621 {
6622 char *q;
6623 const struct asm_cond *c;
6624 int n;
6625 /* Condition codes are always 2 characters, so matching up to
6626 3 characters is sufficient. */
6627 char cond[3];
6628
6629 q = *str;
6630 n = 0;
6631 while (ISALPHA (*q) && n < 3)
6632 {
6633 cond[n] = TOLOWER (*q);
6634 q++;
6635 n++;
6636 }
6637
6638 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
6639 if (!c)
6640 {
6641 inst.error = _("condition required");
6642 return FAIL;
6643 }
6644
6645 *str = q;
6646 return c->value;
6647 }
6648
6649 /* Parse an option for a barrier instruction. Returns the encoding for the
6650 option, or FAIL. */
6651 static int
6652 parse_barrier (char **str)
6653 {
6654 char *p, *q;
6655 const struct asm_barrier_opt *o;
6656
6657 p = q = *str;
6658 while (ISALPHA (*q))
6659 q++;
6660
6661 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
6662 q - p);
6663 if (!o)
6664 return FAIL;
6665
6666 if (!mark_feature_used (&o->arch))
6667 return FAIL;
6668
6669 *str = q;
6670 return o->value;
6671 }
6672
6673 /* Parse the operands of a table branch instruction. Similar to a memory
6674 operand. */
6675 static int
6676 parse_tb (char **str)
6677 {
6678 char * p = *str;
6679 int reg;
6680
6681 if (skip_past_char (&p, '[') == FAIL)
6682 {
6683 inst.error = _("'[' expected");
6684 return FAIL;
6685 }
6686
6687 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6688 {
6689 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6690 return FAIL;
6691 }
6692 inst.operands[0].reg = reg;
6693
6694 if (skip_past_comma (&p) == FAIL)
6695 {
6696 inst.error = _("',' expected");
6697 return FAIL;
6698 }
6699
6700 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6701 {
6702 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6703 return FAIL;
6704 }
6705 inst.operands[0].imm = reg;
6706
6707 if (skip_past_comma (&p) == SUCCESS)
6708 {
6709 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6710 return FAIL;
6711 if (inst.relocs[0].exp.X_add_number != 1)
6712 {
6713 inst.error = _("invalid shift");
6714 return FAIL;
6715 }
6716 inst.operands[0].shifted = 1;
6717 }
6718
6719 if (skip_past_char (&p, ']') == FAIL)
6720 {
6721 inst.error = _("']' expected");
6722 return FAIL;
6723 }
6724 *str = p;
6725 return SUCCESS;
6726 }
6727
6728 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6729 information on the types the operands can take and how they are encoded.
6730 Up to four operands may be read; this function handles setting the
6731 ".present" field for each read operand itself.
6732 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6733 else returns FAIL. */
6734
6735 static int
6736 parse_neon_mov (char **str, int *which_operand)
6737 {
6738 int i = *which_operand, val;
6739 enum arm_reg_type rtype;
6740 char *ptr = *str;
6741 struct neon_type_el optype;
6742
6743 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6744 {
6745 /* Cases 17 or 19. */
6746 inst.operands[i].reg = val;
6747 inst.operands[i].isvec = 1;
6748 inst.operands[i].isscalar = 2;
6749 inst.operands[i].vectype = optype;
6750 inst.operands[i++].present = 1;
6751
6752 if (skip_past_comma (&ptr) == FAIL)
6753 goto wanted_comma;
6754
6755 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6756 {
6757 /* Case 17: VMOV<c>.<dt> <Qd[idx]>, <Rt> */
6758 inst.operands[i].reg = val;
6759 inst.operands[i].isreg = 1;
6760 inst.operands[i].present = 1;
6761 }
6762 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6763 {
6764 /* Case 19: VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> */
6765 inst.operands[i].reg = val;
6766 inst.operands[i].isvec = 1;
6767 inst.operands[i].isscalar = 2;
6768 inst.operands[i].vectype = optype;
6769 inst.operands[i++].present = 1;
6770
6771 if (skip_past_comma (&ptr) == FAIL)
6772 goto wanted_comma;
6773
6774 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6775 goto wanted_arm;
6776
6777 inst.operands[i].reg = val;
6778 inst.operands[i].isreg = 1;
6779 inst.operands[i++].present = 1;
6780
6781 if (skip_past_comma (&ptr) == FAIL)
6782 goto wanted_comma;
6783
6784 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6785 goto wanted_arm;
6786
6787 inst.operands[i].reg = val;
6788 inst.operands[i].isreg = 1;
6789 inst.operands[i].present = 1;
6790 }
6791 else
6792 {
6793 first_error (_("expected ARM or MVE vector register"));
6794 return FAIL;
6795 }
6796 }
6797 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
6798 {
6799 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6800 inst.operands[i].reg = val;
6801 inst.operands[i].isscalar = 1;
6802 inst.operands[i].vectype = optype;
6803 inst.operands[i++].present = 1;
6804
6805 if (skip_past_comma (&ptr) == FAIL)
6806 goto wanted_comma;
6807
6808 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6809 goto wanted_arm;
6810
6811 inst.operands[i].reg = val;
6812 inst.operands[i].isreg = 1;
6813 inst.operands[i].present = 1;
6814 }
6815 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6816 != FAIL)
6817 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, &optype))
6818 != FAIL))
6819 {
6820 /* Cases 0, 1, 2, 3, 5 (D only). */
6821 if (skip_past_comma (&ptr) == FAIL)
6822 goto wanted_comma;
6823
6824 inst.operands[i].reg = val;
6825 inst.operands[i].isreg = 1;
6826 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6827 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6828 inst.operands[i].isvec = 1;
6829 inst.operands[i].vectype = optype;
6830 inst.operands[i++].present = 1;
6831
6832 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6833 {
6834 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6835 Case 13: VMOV <Sd>, <Rm> */
6836 inst.operands[i].reg = val;
6837 inst.operands[i].isreg = 1;
6838 inst.operands[i].present = 1;
6839
6840 if (rtype == REG_TYPE_NQ)
6841 {
6842 first_error (_("can't use Neon quad register here"));
6843 return FAIL;
6844 }
6845 else if (rtype != REG_TYPE_VFS)
6846 {
6847 i++;
6848 if (skip_past_comma (&ptr) == FAIL)
6849 goto wanted_comma;
6850 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6851 goto wanted_arm;
6852 inst.operands[i].reg = val;
6853 inst.operands[i].isreg = 1;
6854 inst.operands[i].present = 1;
6855 }
6856 }
6857 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6858 &optype)) != FAIL)
6859 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype,
6860 &optype)) != FAIL))
6861 {
6862 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6863 Case 1: VMOV<c><q> <Dd>, <Dm>
6864 Case 8: VMOV.F32 <Sd>, <Sm>
6865 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6866
6867 inst.operands[i].reg = val;
6868 inst.operands[i].isreg = 1;
6869 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6870 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6871 inst.operands[i].isvec = 1;
6872 inst.operands[i].vectype = optype;
6873 inst.operands[i].present = 1;
6874
6875 if (skip_past_comma (&ptr) == SUCCESS)
6876 {
6877 /* Case 15. */
6878 i++;
6879
6880 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6881 goto wanted_arm;
6882
6883 inst.operands[i].reg = val;
6884 inst.operands[i].isreg = 1;
6885 inst.operands[i++].present = 1;
6886
6887 if (skip_past_comma (&ptr) == FAIL)
6888 goto wanted_comma;
6889
6890 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6891 goto wanted_arm;
6892
6893 inst.operands[i].reg = val;
6894 inst.operands[i].isreg = 1;
6895 inst.operands[i].present = 1;
6896 }
6897 }
6898 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
6899 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6900 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6901 Case 10: VMOV.F32 <Sd>, #<imm>
6902 Case 11: VMOV.F64 <Dd>, #<imm> */
6903 inst.operands[i].immisfloat = 1;
6904 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6905 == SUCCESS)
6906 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6907 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6908 ;
6909 else
6910 {
6911 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6912 return FAIL;
6913 }
6914 }
6915 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6916 {
6917 /* Cases 6, 7, 16, 18. */
6918 inst.operands[i].reg = val;
6919 inst.operands[i].isreg = 1;
6920 inst.operands[i++].present = 1;
6921
6922 if (skip_past_comma (&ptr) == FAIL)
6923 goto wanted_comma;
6924
6925 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6926 {
6927 /* Case 18: VMOV<c>.<dt> <Rt>, <Qn[idx]> */
6928 inst.operands[i].reg = val;
6929 inst.operands[i].isscalar = 2;
6930 inst.operands[i].present = 1;
6931 inst.operands[i].vectype = optype;
6932 }
6933 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
6934 {
6935 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6936 inst.operands[i].reg = val;
6937 inst.operands[i].isscalar = 1;
6938 inst.operands[i].present = 1;
6939 inst.operands[i].vectype = optype;
6940 }
6941 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6942 {
6943 inst.operands[i].reg = val;
6944 inst.operands[i].isreg = 1;
6945 inst.operands[i++].present = 1;
6946
6947 if (skip_past_comma (&ptr) == FAIL)
6948 goto wanted_comma;
6949
6950 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6951 != FAIL)
6952 {
6953 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6954
6955 inst.operands[i].reg = val;
6956 inst.operands[i].isreg = 1;
6957 inst.operands[i].isvec = 1;
6958 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6959 inst.operands[i].vectype = optype;
6960 inst.operands[i].present = 1;
6961
6962 if (rtype == REG_TYPE_VFS)
6963 {
6964 /* Case 14. */
6965 i++;
6966 if (skip_past_comma (&ptr) == FAIL)
6967 goto wanted_comma;
6968 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6969 &optype)) == FAIL)
6970 {
6971 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6972 return FAIL;
6973 }
6974 inst.operands[i].reg = val;
6975 inst.operands[i].isreg = 1;
6976 inst.operands[i].isvec = 1;
6977 inst.operands[i].issingle = 1;
6978 inst.operands[i].vectype = optype;
6979 inst.operands[i].present = 1;
6980 }
6981 }
6982 else
6983 {
6984 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6985 != FAIL)
6986 {
6987 /* Case 16: VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> */
6988 inst.operands[i].reg = val;
6989 inst.operands[i].isvec = 1;
6990 inst.operands[i].isscalar = 2;
6991 inst.operands[i].vectype = optype;
6992 inst.operands[i++].present = 1;
6993
6994 if (skip_past_comma (&ptr) == FAIL)
6995 goto wanted_comma;
6996
6997 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6998 == FAIL)
6999 {
7000 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
7001 return FAIL;
7002 }
7003 inst.operands[i].reg = val;
7004 inst.operands[i].isvec = 1;
7005 inst.operands[i].isscalar = 2;
7006 inst.operands[i].vectype = optype;
7007 inst.operands[i].present = 1;
7008 }
7009 else
7010 {
7011 first_error (_("VFP single, double or MVE vector register"
7012 " expected"));
7013 return FAIL;
7014 }
7015 }
7016 }
7017 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
7018 != FAIL)
7019 {
7020 /* Case 13. */
7021 inst.operands[i].reg = val;
7022 inst.operands[i].isreg = 1;
7023 inst.operands[i].isvec = 1;
7024 inst.operands[i].issingle = 1;
7025 inst.operands[i].vectype = optype;
7026 inst.operands[i].present = 1;
7027 }
7028 }
7029 else
7030 {
7031 first_error (_("parse error"));
7032 return FAIL;
7033 }
7034
7035 /* Successfully parsed the operands. Update args. */
7036 *which_operand = i;
7037 *str = ptr;
7038 return SUCCESS;
7039
7040 wanted_comma:
7041 first_error (_("expected comma"));
7042 return FAIL;
7043
7044 wanted_arm:
7045 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
7046 return FAIL;
7047 }
7048
7049 /* Use this macro when the operand constraints are different
7050 for ARM and THUMB (e.g. ldrd). */
7051 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
7052 ((arm_operand) | ((thumb_operand) << 16))
7053
7054 /* Matcher codes for parse_operands. */
7055 enum operand_parse_code
7056 {
7057 OP_stop, /* end of line */
7058
7059 OP_RR, /* ARM register */
7060 OP_RRnpc, /* ARM register, not r15 */
7061 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
7062 OP_RRnpcb, /* ARM register, not r15, in square brackets */
7063 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
7064 optional trailing ! */
7065 OP_RRw, /* ARM register, not r15, optional trailing ! */
7066 OP_RCP, /* Coprocessor number */
7067 OP_RCN, /* Coprocessor register */
7068 OP_RF, /* FPA register */
7069 OP_RVS, /* VFP single precision register */
7070 OP_RVD, /* VFP double precision register (0..15) */
7071 OP_RND, /* Neon double precision register (0..31) */
7072 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
7073 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
7074 */
7075 OP_RNSDMQR, /* Neon single or double precision, MVE vector or ARM register.
7076 */
7077 OP_RNQ, /* Neon quad precision register */
7078 OP_RNQMQ, /* Neon quad or MVE vector register. */
7079 OP_RVSD, /* VFP single or double precision register */
7080 OP_RVSD_COND, /* VFP single, double precision register or condition code. */
7081 OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */
7082 OP_RNSD, /* Neon single or double precision register */
7083 OP_RNDQ, /* Neon double or quad precision register */
7084 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
7085 OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */
7086 OP_RNSDQ, /* Neon single, double or quad precision register */
7087 OP_RNSC, /* Neon scalar D[X] */
7088 OP_RVC, /* VFP control register */
7089 OP_RMF, /* Maverick F register */
7090 OP_RMD, /* Maverick D register */
7091 OP_RMFX, /* Maverick FX register */
7092 OP_RMDX, /* Maverick DX register */
7093 OP_RMAX, /* Maverick AX register */
7094 OP_RMDS, /* Maverick DSPSC register */
7095 OP_RIWR, /* iWMMXt wR register */
7096 OP_RIWC, /* iWMMXt wC register */
7097 OP_RIWG, /* iWMMXt wCG register */
7098 OP_RXA, /* XScale accumulator register */
7099
7100 OP_RNSDMQ, /* Neon single, double or MVE vector register */
7101 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
7102 */
7103 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
7104 GPR (no SP/SP) */
7105 OP_RMQ, /* MVE vector register. */
7106 OP_RMQRZ, /* MVE vector or ARM register including ZR. */
7107 OP_RMQRR, /* MVE vector or ARM register. */
7108
7109 /* New operands for Armv8.1-M Mainline. */
7110 OP_LR, /* ARM LR register */
7111 OP_RRe, /* ARM register, only even numbered. */
7112 OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */
7113 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
7114 OP_RR_ZR, /* ARM register or ZR but no PC */
7115
7116 OP_REGLST, /* ARM register list */
7117 OP_CLRMLST, /* CLRM register list */
7118 OP_VRSLST, /* VFP single-precision register list */
7119 OP_VRDLST, /* VFP double-precision register list */
7120 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
7121 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
7122 OP_NSTRLST, /* Neon element/structure list */
7123 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
7124 OP_MSTRLST2, /* MVE vector list with two elements. */
7125 OP_MSTRLST4, /* MVE vector list with four elements. */
7126
7127 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
7128 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
7129 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
7130 OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate
7131 zero. */
7132 OP_RR_RNSC, /* ARM reg or Neon scalar. */
7133 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
7134 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
7135 OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register.
7136 */
7137 OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon
7138 scalar, or ARM register. */
7139 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
7140 OP_RNDQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, or ARM register. */
7141 OP_RNDQMQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, MVE vector or ARM
7142 register. */
7143 OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */
7144 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
7145 OP_VMOV, /* Neon VMOV operands. */
7146 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
7147 /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */
7148 OP_RNDQMQ_Ibig,
7149 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
7150 OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or
7151 ARM register. */
7152 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
7153 OP_VLDR, /* VLDR operand. */
7154
7155 OP_I0, /* immediate zero */
7156 OP_I7, /* immediate value 0 .. 7 */
7157 OP_I15, /* 0 .. 15 */
7158 OP_I16, /* 1 .. 16 */
7159 OP_I16z, /* 0 .. 16 */
7160 OP_I31, /* 0 .. 31 */
7161 OP_I31w, /* 0 .. 31, optional trailing ! */
7162 OP_I32, /* 1 .. 32 */
7163 OP_I32z, /* 0 .. 32 */
7164 OP_I48_I64, /* 48 or 64 */
7165 OP_I63, /* 0 .. 63 */
7166 OP_I63s, /* -64 .. 63 */
7167 OP_I64, /* 1 .. 64 */
7168 OP_I64z, /* 0 .. 64 */
7169 OP_I127, /* 0 .. 127 */
7170 OP_I255, /* 0 .. 255 */
7171 OP_I511, /* 0 .. 511 */
7172 OP_I4095, /* 0 .. 4095 */
7173 OP_I8191, /* 0 .. 8191 */
7174 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
7175 OP_I7b, /* 0 .. 7 */
7176 OP_I15b, /* 0 .. 15 */
7177 OP_I31b, /* 0 .. 31 */
7178
7179 OP_SH, /* shifter operand */
7180 OP_SHG, /* shifter operand with possible group relocation */
7181 OP_ADDR, /* Memory address expression (any mode) */
7182 OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */
7183 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
7184 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
7185 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
7186 OP_EXP, /* arbitrary expression */
7187 OP_EXPi, /* same, with optional immediate prefix */
7188 OP_EXPr, /* same, with optional relocation suffix */
7189 OP_EXPs, /* same, with optional non-first operand relocation suffix */
7190 OP_HALF, /* 0 .. 65535 or low/high reloc. */
7191 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
7192 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
7193
7194 OP_CPSF, /* CPS flags */
7195 OP_ENDI, /* Endianness specifier */
7196 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
7197 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
7198 OP_COND, /* conditional code */
7199 OP_TB, /* Table branch. */
7200
7201 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
7202
7203 OP_RRnpc_I0, /* ARM register or literal 0 */
7204 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
7205 OP_RR_EXi, /* ARM register or expression with imm prefix */
7206 OP_RF_IF, /* FPA register or immediate */
7207 OP_RIWR_RIWC, /* iWMMXt R or C reg */
7208 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
7209
7210 /* Optional operands. */
7211 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
7212 OP_oI31b, /* 0 .. 31 */
7213 OP_oI32b, /* 1 .. 32 */
7214 OP_oI32z, /* 0 .. 32 */
7215 OP_oIffffb, /* 0 .. 65535 */
7216 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
7217
7218 OP_oRR, /* ARM register */
7219 OP_oLR, /* ARM LR register */
7220 OP_oRRnpc, /* ARM register, not the PC */
7221 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
7222 OP_oRRw, /* ARM register, not r15, optional trailing ! */
7223 OP_oRND, /* Optional Neon double precision register */
7224 OP_oRNQ, /* Optional Neon quad precision register */
7225 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
7226 OP_oRNDQ, /* Optional Neon double or quad precision register */
7227 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
7228 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
7229 register. */
7230 OP_oRNSDMQ, /* Optional single, double register or MVE vector
7231 register. */
7232 OP_oSHll, /* LSL immediate */
7233 OP_oSHar, /* ASR immediate */
7234 OP_oSHllar, /* LSL or ASR immediate */
7235 OP_oROR, /* ROR 0/8/16/24 */
7236 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
7237
7238 OP_oRMQRZ, /* optional MVE vector or ARM register including ZR. */
7239
7240 /* Some pre-defined mixed (ARM/THUMB) operands. */
7241 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
7242 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
7243 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
7244
7245 OP_FIRST_OPTIONAL = OP_oI7b
7246 };
7247
7248 /* Generic instruction operand parser. This does no encoding and no
7249 semantic validation; it merely squirrels values away in the inst
7250 structure. Returns SUCCESS or FAIL depending on whether the
7251 specified grammar matched. */
7252 static int
7253 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
7254 {
7255 unsigned const int *upat = pattern;
7256 char *backtrack_pos = 0;
7257 const char *backtrack_error = 0;
7258 int i, val = 0, backtrack_index = 0;
7259 enum arm_reg_type rtype;
7260 parse_operand_result result;
7261 unsigned int op_parse_code;
7262 bfd_boolean partial_match;
7263
7264 #define po_char_or_fail(chr) \
7265 do \
7266 { \
7267 if (skip_past_char (&str, chr) == FAIL) \
7268 goto bad_args; \
7269 } \
7270 while (0)
7271
7272 #define po_reg_or_fail(regtype) \
7273 do \
7274 { \
7275 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7276 & inst.operands[i].vectype); \
7277 if (val == FAIL) \
7278 { \
7279 first_error (_(reg_expected_msgs[regtype])); \
7280 goto failure; \
7281 } \
7282 inst.operands[i].reg = val; \
7283 inst.operands[i].isreg = 1; \
7284 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7285 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7286 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
7287 || rtype == REG_TYPE_VFD \
7288 || rtype == REG_TYPE_NQ); \
7289 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
7290 } \
7291 while (0)
7292
7293 #define po_reg_or_goto(regtype, label) \
7294 do \
7295 { \
7296 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7297 & inst.operands[i].vectype); \
7298 if (val == FAIL) \
7299 goto label; \
7300 \
7301 inst.operands[i].reg = val; \
7302 inst.operands[i].isreg = 1; \
7303 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7304 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7305 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
7306 || rtype == REG_TYPE_VFD \
7307 || rtype == REG_TYPE_NQ); \
7308 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
7309 } \
7310 while (0)
7311
7312 #define po_imm_or_fail(min, max, popt) \
7313 do \
7314 { \
7315 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
7316 goto failure; \
7317 inst.operands[i].imm = val; \
7318 } \
7319 while (0)
7320
7321 #define po_imm1_or_imm2_or_fail(imm1, imm2, popt) \
7322 do \
7323 { \
7324 expressionS exp; \
7325 my_get_expression (&exp, &str, popt); \
7326 if (exp.X_op != O_constant) \
7327 { \
7328 inst.error = _("constant expression required"); \
7329 goto failure; \
7330 } \
7331 if (exp.X_add_number != imm1 && exp.X_add_number != imm2) \
7332 { \
7333 inst.error = _("immediate value 48 or 64 expected"); \
7334 goto failure; \
7335 } \
7336 inst.operands[i].imm = exp.X_add_number; \
7337 } \
7338 while (0)
7339
7340 #define po_scalar_or_goto(elsz, label, reg_type) \
7341 do \
7342 { \
7343 val = parse_scalar (& str, elsz, & inst.operands[i].vectype, \
7344 reg_type); \
7345 if (val == FAIL) \
7346 goto label; \
7347 inst.operands[i].reg = val; \
7348 inst.operands[i].isscalar = 1; \
7349 } \
7350 while (0)
7351
7352 #define po_misc_or_fail(expr) \
7353 do \
7354 { \
7355 if (expr) \
7356 goto failure; \
7357 } \
7358 while (0)
7359
7360 #define po_misc_or_fail_no_backtrack(expr) \
7361 do \
7362 { \
7363 result = expr; \
7364 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
7365 backtrack_pos = 0; \
7366 if (result != PARSE_OPERAND_SUCCESS) \
7367 goto failure; \
7368 } \
7369 while (0)
7370
7371 #define po_barrier_or_imm(str) \
7372 do \
7373 { \
7374 val = parse_barrier (&str); \
7375 if (val == FAIL && ! ISALPHA (*str)) \
7376 goto immediate; \
7377 if (val == FAIL \
7378 /* ISB can only take SY as an option. */ \
7379 || ((inst.instruction & 0xf0) == 0x60 \
7380 && val != 0xf)) \
7381 { \
7382 inst.error = _("invalid barrier type"); \
7383 backtrack_pos = 0; \
7384 goto failure; \
7385 } \
7386 } \
7387 while (0)
7388
7389 skip_whitespace (str);
7390
7391 for (i = 0; upat[i] != OP_stop; i++)
7392 {
7393 op_parse_code = upat[i];
7394 if (op_parse_code >= 1<<16)
7395 op_parse_code = thumb ? (op_parse_code >> 16)
7396 : (op_parse_code & ((1<<16)-1));
7397
7398 if (op_parse_code >= OP_FIRST_OPTIONAL)
7399 {
7400 /* Remember where we are in case we need to backtrack. */
7401 backtrack_pos = str;
7402 backtrack_error = inst.error;
7403 backtrack_index = i;
7404 }
7405
7406 if (i > 0 && (i > 1 || inst.operands[0].present))
7407 po_char_or_fail (',');
7408
7409 switch (op_parse_code)
7410 {
7411 /* Registers */
7412 case OP_oRRnpc:
7413 case OP_oRRnpcsp:
7414 case OP_RRnpc:
7415 case OP_RRnpcsp:
7416 case OP_oRR:
7417 case OP_RRe:
7418 case OP_RRo:
7419 case OP_LR:
7420 case OP_oLR:
7421 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
7422 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
7423 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
7424 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
7425 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
7426 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
7427 case OP_oRND:
7428 case OP_RNSDMQR:
7429 po_reg_or_goto (REG_TYPE_VFS, try_rndmqr);
7430 break;
7431 try_rndmqr:
7432 case OP_RNDMQR:
7433 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
7434 break;
7435 try_rndmq:
7436 case OP_RNDMQ:
7437 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
7438 break;
7439 try_rnd:
7440 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
7441 case OP_RVC:
7442 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
7443 break;
7444 /* Also accept generic coprocessor regs for unknown registers. */
7445 coproc_reg:
7446 po_reg_or_goto (REG_TYPE_CN, vpr_po);
7447 break;
7448 /* Also accept P0 or p0 for VPR.P0. Since P0 is already an
7449 existing register with a value of 0, this seems like the
7450 best way to parse P0. */
7451 vpr_po:
7452 if (strncasecmp (str, "P0", 2) == 0)
7453 {
7454 str += 2;
7455 inst.operands[i].isreg = 1;
7456 inst.operands[i].reg = 13;
7457 }
7458 else
7459 goto failure;
7460 break;
7461 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
7462 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
7463 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
7464 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
7465 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
7466 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
7467 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7468 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7469 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7470 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
7471 case OP_oRNQ:
7472 case OP_RNQMQ:
7473 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7474 break;
7475 try_nq:
7476 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
7477 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
7478 case OP_RNDQMQR:
7479 po_reg_or_goto (REG_TYPE_RN, try_rndqmq);
7480 break;
7481 try_rndqmq:
7482 case OP_oRNDQMQ:
7483 case OP_RNDQMQ:
7484 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7485 break;
7486 try_rndq:
7487 case OP_oRNDQ:
7488 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
7489 case OP_RVSDMQ:
7490 po_reg_or_goto (REG_TYPE_MQ, try_rvsd);
7491 break;
7492 try_rvsd:
7493 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
7494 case OP_RVSD_COND:
7495 po_reg_or_goto (REG_TYPE_VFSD, try_cond);
7496 break;
7497 case OP_oRNSDMQ:
7498 case OP_RNSDMQ:
7499 po_reg_or_goto (REG_TYPE_NSD, try_mq2);
7500 break;
7501 try_mq2:
7502 po_reg_or_fail (REG_TYPE_MQ);
7503 break;
7504 case OP_oRNSDQ:
7505 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
7506 case OP_RNSDQMQR:
7507 po_reg_or_goto (REG_TYPE_RN, try_mq);
7508 break;
7509 try_mq:
7510 case OP_oRNSDQMQ:
7511 case OP_RNSDQMQ:
7512 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7513 break;
7514 try_nsdq2:
7515 po_reg_or_fail (REG_TYPE_NSDQ);
7516 inst.error = 0;
7517 break;
7518 case OP_RMQRR:
7519 po_reg_or_goto (REG_TYPE_RN, try_rmq);
7520 break;
7521 try_rmq:
7522 case OP_RMQ:
7523 po_reg_or_fail (REG_TYPE_MQ);
7524 break;
7525 /* Neon scalar. Using an element size of 8 means that some invalid
7526 scalars are accepted here, so deal with those in later code. */
7527 case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break;
7528
7529 case OP_RNDQ_I0:
7530 {
7531 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7532 break;
7533 try_imm0:
7534 po_imm_or_fail (0, 0, TRUE);
7535 }
7536 break;
7537
7538 case OP_RVSD_I0:
7539 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7540 break;
7541
7542 case OP_RSVDMQ_FI0:
7543 po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0);
7544 break;
7545 try_rsvd_fi0:
7546 case OP_RSVD_FI0:
7547 {
7548 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7549 break;
7550 try_ifimm0:
7551 if (parse_ifimm_zero (&str))
7552 inst.operands[i].imm = 0;
7553 else
7554 {
7555 inst.error
7556 = _("only floating point zero is allowed as immediate value");
7557 goto failure;
7558 }
7559 }
7560 break;
7561
7562 case OP_RR_RNSC:
7563 {
7564 po_scalar_or_goto (8, try_rr, REG_TYPE_VFD);
7565 break;
7566 try_rr:
7567 po_reg_or_fail (REG_TYPE_RN);
7568 }
7569 break;
7570
7571 case OP_RNSDQ_RNSC_MQ_RR:
7572 po_reg_or_goto (REG_TYPE_RN, try_rnsdq_rnsc_mq);
7573 break;
7574 try_rnsdq_rnsc_mq:
7575 case OP_RNSDQ_RNSC_MQ:
7576 po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc);
7577 break;
7578 try_rnsdq_rnsc:
7579 case OP_RNSDQ_RNSC:
7580 {
7581 po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD);
7582 inst.error = 0;
7583 break;
7584 try_nsdq:
7585 po_reg_or_fail (REG_TYPE_NSDQ);
7586 inst.error = 0;
7587 }
7588 break;
7589
7590 case OP_RNSD_RNSC:
7591 {
7592 po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD);
7593 break;
7594 try_s_scalar:
7595 po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS);
7596 break;
7597 try_nsd:
7598 po_reg_or_fail (REG_TYPE_NSD);
7599 }
7600 break;
7601
7602 case OP_RNDQMQ_RNSC_RR:
7603 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc_rr);
7604 break;
7605 try_rndq_rnsc_rr:
7606 case OP_RNDQ_RNSC_RR:
7607 po_reg_or_goto (REG_TYPE_RN, try_rndq_rnsc);
7608 break;
7609 case OP_RNDQMQ_RNSC:
7610 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc);
7611 break;
7612 try_rndq_rnsc:
7613 case OP_RNDQ_RNSC:
7614 {
7615 po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD);
7616 break;
7617 try_ndq:
7618 po_reg_or_fail (REG_TYPE_NDQ);
7619 }
7620 break;
7621
7622 case OP_RND_RNSC:
7623 {
7624 po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD);
7625 break;
7626 try_vfd:
7627 po_reg_or_fail (REG_TYPE_VFD);
7628 }
7629 break;
7630
7631 case OP_VMOV:
7632 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7633 not careful then bad things might happen. */
7634 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7635 break;
7636
7637 case OP_RNDQMQ_Ibig:
7638 po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig);
7639 break;
7640 try_rndq_ibig:
7641 case OP_RNDQ_Ibig:
7642 {
7643 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7644 break;
7645 try_immbig:
7646 /* There's a possibility of getting a 64-bit immediate here, so
7647 we need special handling. */
7648 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
7649 == FAIL)
7650 {
7651 inst.error = _("immediate value is out of range");
7652 goto failure;
7653 }
7654 }
7655 break;
7656
7657 case OP_RNDQMQ_I63b_RR:
7658 po_reg_or_goto (REG_TYPE_MQ, try_rndq_i63b_rr);
7659 break;
7660 try_rndq_i63b_rr:
7661 po_reg_or_goto (REG_TYPE_RN, try_rndq_i63b);
7662 break;
7663 try_rndq_i63b:
7664 case OP_RNDQ_I63b:
7665 {
7666 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7667 break;
7668 try_shimm:
7669 po_imm_or_fail (0, 63, TRUE);
7670 }
7671 break;
7672
7673 case OP_RRnpcb:
7674 po_char_or_fail ('[');
7675 po_reg_or_fail (REG_TYPE_RN);
7676 po_char_or_fail (']');
7677 break;
7678
7679 case OP_RRnpctw:
7680 case OP_RRw:
7681 case OP_oRRw:
7682 po_reg_or_fail (REG_TYPE_RN);
7683 if (skip_past_char (&str, '!') == SUCCESS)
7684 inst.operands[i].writeback = 1;
7685 break;
7686
7687 /* Immediates */
7688 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
7689 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
7690 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
7691 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
7692 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
7693 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
7694 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
7695 case OP_I48_I64: po_imm1_or_imm2_or_fail (48, 64, FALSE); break;
7696 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
7697 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
7698 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
7699 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
7700 case OP_I127: po_imm_or_fail ( 0, 127, FALSE); break;
7701 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
7702 case OP_I511: po_imm_or_fail ( 0, 511, FALSE); break;
7703 case OP_I4095: po_imm_or_fail ( 0, 4095, FALSE); break;
7704 case OP_I8191: po_imm_or_fail ( 0, 8191, FALSE); break;
7705 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
7706 case OP_oI7b:
7707 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
7708 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
7709 case OP_oI31b:
7710 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
7711 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
7712 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
7713 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
7714
7715 /* Immediate variants */
7716 case OP_oI255c:
7717 po_char_or_fail ('{');
7718 po_imm_or_fail (0, 255, TRUE);
7719 po_char_or_fail ('}');
7720 break;
7721
7722 case OP_I31w:
7723 /* The expression parser chokes on a trailing !, so we have
7724 to find it first and zap it. */
7725 {
7726 char *s = str;
7727 while (*s && *s != ',')
7728 s++;
7729 if (s[-1] == '!')
7730 {
7731 s[-1] = '\0';
7732 inst.operands[i].writeback = 1;
7733 }
7734 po_imm_or_fail (0, 31, TRUE);
7735 if (str == s - 1)
7736 str = s;
7737 }
7738 break;
7739
7740 /* Expressions */
7741 case OP_EXPi: EXPi:
7742 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7743 GE_OPT_PREFIX));
7744 break;
7745
7746 case OP_EXP:
7747 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7748 GE_NO_PREFIX));
7749 break;
7750
7751 case OP_EXPr: EXPr:
7752 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7753 GE_NO_PREFIX));
7754 if (inst.relocs[0].exp.X_op == O_symbol)
7755 {
7756 val = parse_reloc (&str);
7757 if (val == -1)
7758 {
7759 inst.error = _("unrecognized relocation suffix");
7760 goto failure;
7761 }
7762 else if (val != BFD_RELOC_UNUSED)
7763 {
7764 inst.operands[i].imm = val;
7765 inst.operands[i].hasreloc = 1;
7766 }
7767 }
7768 break;
7769
7770 case OP_EXPs:
7771 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7772 GE_NO_PREFIX));
7773 if (inst.relocs[i].exp.X_op == O_symbol)
7774 {
7775 inst.operands[i].hasreloc = 1;
7776 }
7777 else if (inst.relocs[i].exp.X_op == O_constant)
7778 {
7779 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7780 inst.operands[i].hasreloc = 0;
7781 }
7782 break;
7783
7784 /* Operand for MOVW or MOVT. */
7785 case OP_HALF:
7786 po_misc_or_fail (parse_half (&str));
7787 break;
7788
7789 /* Register or expression. */
7790 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7791 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
7792
7793 /* Register or immediate. */
7794 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7795 I0: po_imm_or_fail (0, 0, FALSE); break;
7796
7797 case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break;
7798 I32: po_imm_or_fail (1, 32, FALSE); break;
7799
7800 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7801 IF:
7802 if (!is_immediate_prefix (*str))
7803 goto bad_args;
7804 str++;
7805 val = parse_fpa_immediate (&str);
7806 if (val == FAIL)
7807 goto failure;
7808 /* FPA immediates are encoded as registers 8-15.
7809 parse_fpa_immediate has already applied the offset. */
7810 inst.operands[i].reg = val;
7811 inst.operands[i].isreg = 1;
7812 break;
7813
7814 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7815 I32z: po_imm_or_fail (0, 32, FALSE); break;
7816
7817 /* Two kinds of register. */
7818 case OP_RIWR_RIWC:
7819 {
7820 struct reg_entry *rege = arm_reg_parse_multi (&str);
7821 if (!rege
7822 || (rege->type != REG_TYPE_MMXWR
7823 && rege->type != REG_TYPE_MMXWC
7824 && rege->type != REG_TYPE_MMXWCG))
7825 {
7826 inst.error = _("iWMMXt data or control register expected");
7827 goto failure;
7828 }
7829 inst.operands[i].reg = rege->number;
7830 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7831 }
7832 break;
7833
7834 case OP_RIWC_RIWG:
7835 {
7836 struct reg_entry *rege = arm_reg_parse_multi (&str);
7837 if (!rege
7838 || (rege->type != REG_TYPE_MMXWC
7839 && rege->type != REG_TYPE_MMXWCG))
7840 {
7841 inst.error = _("iWMMXt control register expected");
7842 goto failure;
7843 }
7844 inst.operands[i].reg = rege->number;
7845 inst.operands[i].isreg = 1;
7846 }
7847 break;
7848
7849 /* Misc */
7850 case OP_CPSF: val = parse_cps_flags (&str); break;
7851 case OP_ENDI: val = parse_endian_specifier (&str); break;
7852 case OP_oROR: val = parse_ror (&str); break;
7853 try_cond:
7854 case OP_COND: val = parse_cond (&str); break;
7855 case OP_oBARRIER_I15:
7856 po_barrier_or_imm (str); break;
7857 immediate:
7858 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
7859 goto failure;
7860 break;
7861
7862 case OP_wPSR:
7863 case OP_rPSR:
7864 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7865 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7866 {
7867 inst.error = _("Banked registers are not available with this "
7868 "architecture.");
7869 goto failure;
7870 }
7871 break;
7872 try_psr:
7873 val = parse_psr (&str, op_parse_code == OP_wPSR);
7874 break;
7875
7876 case OP_VLDR:
7877 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7878 break;
7879 try_sysreg:
7880 val = parse_sys_vldr_vstr (&str);
7881 break;
7882
7883 case OP_APSR_RR:
7884 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7885 break;
7886 try_apsr:
7887 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7888 instruction). */
7889 if (strncasecmp (str, "APSR_", 5) == 0)
7890 {
7891 unsigned found = 0;
7892 str += 5;
7893 while (found < 15)
7894 switch (*str++)
7895 {
7896 case 'c': found = (found & 1) ? 16 : found | 1; break;
7897 case 'n': found = (found & 2) ? 16 : found | 2; break;
7898 case 'z': found = (found & 4) ? 16 : found | 4; break;
7899 case 'v': found = (found & 8) ? 16 : found | 8; break;
7900 default: found = 16;
7901 }
7902 if (found != 15)
7903 goto failure;
7904 inst.operands[i].isvec = 1;
7905 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7906 inst.operands[i].reg = REG_PC;
7907 }
7908 else
7909 goto failure;
7910 break;
7911
7912 case OP_TB:
7913 po_misc_or_fail (parse_tb (&str));
7914 break;
7915
7916 /* Register lists. */
7917 case OP_REGLST:
7918 val = parse_reg_list (&str, REGLIST_RN);
7919 if (*str == '^')
7920 {
7921 inst.operands[i].writeback = 1;
7922 str++;
7923 }
7924 break;
7925
7926 case OP_CLRMLST:
7927 val = parse_reg_list (&str, REGLIST_CLRM);
7928 break;
7929
7930 case OP_VRSLST:
7931 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7932 &partial_match);
7933 break;
7934
7935 case OP_VRDLST:
7936 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7937 &partial_match);
7938 break;
7939
7940 case OP_VRSDLST:
7941 /* Allow Q registers too. */
7942 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7943 REGLIST_NEON_D, &partial_match);
7944 if (val == FAIL)
7945 {
7946 inst.error = NULL;
7947 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7948 REGLIST_VFP_S, &partial_match);
7949 inst.operands[i].issingle = 1;
7950 }
7951 break;
7952
7953 case OP_VRSDVLST:
7954 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7955 REGLIST_VFP_D_VPR, &partial_match);
7956 if (val == FAIL && !partial_match)
7957 {
7958 inst.error = NULL;
7959 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7960 REGLIST_VFP_S_VPR, &partial_match);
7961 inst.operands[i].issingle = 1;
7962 }
7963 break;
7964
7965 case OP_NRDLST:
7966 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7967 REGLIST_NEON_D, &partial_match);
7968 break;
7969
7970 case OP_MSTRLST4:
7971 case OP_MSTRLST2:
7972 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7973 1, &inst.operands[i].vectype);
7974 if (val != (((op_parse_code == OP_MSTRLST2) ? 3 : 7) << 5 | 0xe))
7975 goto failure;
7976 break;
7977 case OP_NSTRLST:
7978 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7979 0, &inst.operands[i].vectype);
7980 break;
7981
7982 /* Addressing modes */
7983 case OP_ADDRMVE:
7984 po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE));
7985 break;
7986
7987 case OP_ADDR:
7988 po_misc_or_fail (parse_address (&str, i));
7989 break;
7990
7991 case OP_ADDRGLDR:
7992 po_misc_or_fail_no_backtrack (
7993 parse_address_group_reloc (&str, i, GROUP_LDR));
7994 break;
7995
7996 case OP_ADDRGLDRS:
7997 po_misc_or_fail_no_backtrack (
7998 parse_address_group_reloc (&str, i, GROUP_LDRS));
7999 break;
8000
8001 case OP_ADDRGLDC:
8002 po_misc_or_fail_no_backtrack (
8003 parse_address_group_reloc (&str, i, GROUP_LDC));
8004 break;
8005
8006 case OP_SH:
8007 po_misc_or_fail (parse_shifter_operand (&str, i));
8008 break;
8009
8010 case OP_SHG:
8011 po_misc_or_fail_no_backtrack (
8012 parse_shifter_operand_group_reloc (&str, i));
8013 break;
8014
8015 case OP_oSHll:
8016 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
8017 break;
8018
8019 case OP_oSHar:
8020 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
8021 break;
8022
8023 case OP_oSHllar:
8024 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
8025 break;
8026
8027 case OP_RMQRZ:
8028 case OP_oRMQRZ:
8029 po_reg_or_goto (REG_TYPE_MQ, try_rr_zr);
8030 break;
8031
8032 case OP_RR_ZR:
8033 try_rr_zr:
8034 po_reg_or_goto (REG_TYPE_RN, ZR);
8035 break;
8036 ZR:
8037 po_reg_or_fail (REG_TYPE_ZR);
8038 break;
8039
8040 default:
8041 as_fatal (_("unhandled operand code %d"), op_parse_code);
8042 }
8043
8044 /* Various value-based sanity checks and shared operations. We
8045 do not signal immediate failures for the register constraints;
8046 this allows a syntax error to take precedence. */
8047 switch (op_parse_code)
8048 {
8049 case OP_oRRnpc:
8050 case OP_RRnpc:
8051 case OP_RRnpcb:
8052 case OP_RRw:
8053 case OP_oRRw:
8054 case OP_RRnpc_I0:
8055 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
8056 inst.error = BAD_PC;
8057 break;
8058
8059 case OP_oRRnpcsp:
8060 case OP_RRnpcsp:
8061 case OP_RRnpcsp_I32:
8062 if (inst.operands[i].isreg)
8063 {
8064 if (inst.operands[i].reg == REG_PC)
8065 inst.error = BAD_PC;
8066 else if (inst.operands[i].reg == REG_SP
8067 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
8068 relaxed since ARMv8-A. */
8069 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8070 {
8071 gas_assert (thumb);
8072 inst.error = BAD_SP;
8073 }
8074 }
8075 break;
8076
8077 case OP_RRnpctw:
8078 if (inst.operands[i].isreg
8079 && inst.operands[i].reg == REG_PC
8080 && (inst.operands[i].writeback || thumb))
8081 inst.error = BAD_PC;
8082 break;
8083
8084 case OP_RVSD_COND:
8085 case OP_VLDR:
8086 if (inst.operands[i].isreg)
8087 break;
8088 /* fall through. */
8089
8090 case OP_CPSF:
8091 case OP_ENDI:
8092 case OP_oROR:
8093 case OP_wPSR:
8094 case OP_rPSR:
8095 case OP_COND:
8096 case OP_oBARRIER_I15:
8097 case OP_REGLST:
8098 case OP_CLRMLST:
8099 case OP_VRSLST:
8100 case OP_VRDLST:
8101 case OP_VRSDLST:
8102 case OP_VRSDVLST:
8103 case OP_NRDLST:
8104 case OP_NSTRLST:
8105 case OP_MSTRLST2:
8106 case OP_MSTRLST4:
8107 if (val == FAIL)
8108 goto failure;
8109 inst.operands[i].imm = val;
8110 break;
8111
8112 case OP_LR:
8113 case OP_oLR:
8114 if (inst.operands[i].reg != REG_LR)
8115 inst.error = _("operand must be LR register");
8116 break;
8117
8118 case OP_RMQRZ:
8119 case OP_oRMQRZ:
8120 case OP_RR_ZR:
8121 if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC)
8122 inst.error = BAD_PC;
8123 break;
8124
8125 case OP_RRe:
8126 if (inst.operands[i].isreg
8127 && (inst.operands[i].reg & 0x00000001) != 0)
8128 inst.error = BAD_ODD;
8129 break;
8130
8131 case OP_RRo:
8132 if (inst.operands[i].isreg)
8133 {
8134 if ((inst.operands[i].reg & 0x00000001) != 1)
8135 inst.error = BAD_EVEN;
8136 else if (inst.operands[i].reg == REG_SP)
8137 as_tsktsk (MVE_BAD_SP);
8138 else if (inst.operands[i].reg == REG_PC)
8139 inst.error = BAD_PC;
8140 }
8141 break;
8142
8143 default:
8144 break;
8145 }
8146
8147 /* If we get here, this operand was successfully parsed. */
8148 inst.operands[i].present = 1;
8149 continue;
8150
8151 bad_args:
8152 inst.error = BAD_ARGS;
8153
8154 failure:
8155 if (!backtrack_pos)
8156 {
8157 /* The parse routine should already have set inst.error, but set a
8158 default here just in case. */
8159 if (!inst.error)
8160 inst.error = BAD_SYNTAX;
8161 return FAIL;
8162 }
8163
8164 /* Do not backtrack over a trailing optional argument that
8165 absorbed some text. We will only fail again, with the
8166 'garbage following instruction' error message, which is
8167 probably less helpful than the current one. */
8168 if (backtrack_index == i && backtrack_pos != str
8169 && upat[i+1] == OP_stop)
8170 {
8171 if (!inst.error)
8172 inst.error = BAD_SYNTAX;
8173 return FAIL;
8174 }
8175
8176 /* Try again, skipping the optional argument at backtrack_pos. */
8177 str = backtrack_pos;
8178 inst.error = backtrack_error;
8179 inst.operands[backtrack_index].present = 0;
8180 i = backtrack_index;
8181 backtrack_pos = 0;
8182 }
8183
8184 /* Check that we have parsed all the arguments. */
8185 if (*str != '\0' && !inst.error)
8186 inst.error = _("garbage following instruction");
8187
8188 return inst.error ? FAIL : SUCCESS;
8189 }
8190
8191 #undef po_char_or_fail
8192 #undef po_reg_or_fail
8193 #undef po_reg_or_goto
8194 #undef po_imm_or_fail
8195 #undef po_scalar_or_fail
8196 #undef po_barrier_or_imm
8197
8198 /* Shorthand macro for instruction encoding functions issuing errors. */
8199 #define constraint(expr, err) \
8200 do \
8201 { \
8202 if (expr) \
8203 { \
8204 inst.error = err; \
8205 return; \
8206 } \
8207 } \
8208 while (0)
8209
8210 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
8211 instructions are unpredictable if these registers are used. This
8212 is the BadReg predicate in ARM's Thumb-2 documentation.
8213
8214 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
8215 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
8216 #define reject_bad_reg(reg) \
8217 do \
8218 if (reg == REG_PC) \
8219 { \
8220 inst.error = BAD_PC; \
8221 return; \
8222 } \
8223 else if (reg == REG_SP \
8224 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
8225 { \
8226 inst.error = BAD_SP; \
8227 return; \
8228 } \
8229 while (0)
8230
8231 /* If REG is R13 (the stack pointer), warn that its use is
8232 deprecated. */
8233 #define warn_deprecated_sp(reg) \
8234 do \
8235 if (warn_on_deprecated && reg == REG_SP) \
8236 as_tsktsk (_("use of r13 is deprecated")); \
8237 while (0)
8238
8239 /* Functions for operand encoding. ARM, then Thumb. */
8240
8241 #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
8242
8243 /* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
8244
8245 The only binary encoding difference is the Coprocessor number. Coprocessor
8246 9 is used for half-precision calculations or conversions. The format of the
8247 instruction is the same as the equivalent Coprocessor 10 instruction that
8248 exists for Single-Precision operation. */
8249
8250 static void
8251 do_scalar_fp16_v82_encode (void)
8252 {
8253 if (inst.cond < COND_ALWAYS)
8254 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
8255 " the behaviour is UNPREDICTABLE"));
8256 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
8257 _(BAD_FP16));
8258
8259 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
8260 mark_feature_used (&arm_ext_fp16);
8261 }
8262
8263 /* If VAL can be encoded in the immediate field of an ARM instruction,
8264 return the encoded form. Otherwise, return FAIL. */
8265
8266 static unsigned int
8267 encode_arm_immediate (unsigned int val)
8268 {
8269 unsigned int a, i;
8270
8271 if (val <= 0xff)
8272 return val;
8273
8274 for (i = 2; i < 32; i += 2)
8275 if ((a = rotate_left (val, i)) <= 0xff)
8276 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
8277
8278 return FAIL;
8279 }
8280
8281 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
8282 return the encoded form. Otherwise, return FAIL. */
8283 static unsigned int
8284 encode_thumb32_immediate (unsigned int val)
8285 {
8286 unsigned int a, i;
8287
8288 if (val <= 0xff)
8289 return val;
8290
8291 for (i = 1; i <= 24; i++)
8292 {
8293 a = val >> i;
8294 if ((val & ~(0xff << i)) == 0)
8295 return ((val >> i) & 0x7f) | ((32 - i) << 7);
8296 }
8297
8298 a = val & 0xff;
8299 if (val == ((a << 16) | a))
8300 return 0x100 | a;
8301 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
8302 return 0x300 | a;
8303
8304 a = val & 0xff00;
8305 if (val == ((a << 16) | a))
8306 return 0x200 | (a >> 8);
8307
8308 return FAIL;
8309 }
8310 /* Encode a VFP SP or DP register number into inst.instruction. */
8311
8312 static void
8313 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
8314 {
8315 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
8316 && reg > 15)
8317 {
8318 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
8319 {
8320 if (thumb_mode)
8321 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8322 fpu_vfp_ext_d32);
8323 else
8324 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8325 fpu_vfp_ext_d32);
8326 }
8327 else
8328 {
8329 first_error (_("D register out of range for selected VFP version"));
8330 return;
8331 }
8332 }
8333
8334 switch (pos)
8335 {
8336 case VFP_REG_Sd:
8337 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
8338 break;
8339
8340 case VFP_REG_Sn:
8341 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
8342 break;
8343
8344 case VFP_REG_Sm:
8345 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
8346 break;
8347
8348 case VFP_REG_Dd:
8349 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
8350 break;
8351
8352 case VFP_REG_Dn:
8353 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
8354 break;
8355
8356 case VFP_REG_Dm:
8357 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
8358 break;
8359
8360 default:
8361 abort ();
8362 }
8363 }
8364
8365 /* Encode a <shift> in an ARM-format instruction. The immediate,
8366 if any, is handled by md_apply_fix. */
8367 static void
8368 encode_arm_shift (int i)
8369 {
8370 /* register-shifted register. */
8371 if (inst.operands[i].immisreg)
8372 {
8373 int op_index;
8374 for (op_index = 0; op_index <= i; ++op_index)
8375 {
8376 /* Check the operand only when it's presented. In pre-UAL syntax,
8377 if the destination register is the same as the first operand, two
8378 register form of the instruction can be used. */
8379 if (inst.operands[op_index].present && inst.operands[op_index].isreg
8380 && inst.operands[op_index].reg == REG_PC)
8381 as_warn (UNPRED_REG ("r15"));
8382 }
8383
8384 if (inst.operands[i].imm == REG_PC)
8385 as_warn (UNPRED_REG ("r15"));
8386 }
8387
8388 if (inst.operands[i].shift_kind == SHIFT_RRX)
8389 inst.instruction |= SHIFT_ROR << 5;
8390 else
8391 {
8392 inst.instruction |= inst.operands[i].shift_kind << 5;
8393 if (inst.operands[i].immisreg)
8394 {
8395 inst.instruction |= SHIFT_BY_REG;
8396 inst.instruction |= inst.operands[i].imm << 8;
8397 }
8398 else
8399 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
8400 }
8401 }
8402
8403 static void
8404 encode_arm_shifter_operand (int i)
8405 {
8406 if (inst.operands[i].isreg)
8407 {
8408 inst.instruction |= inst.operands[i].reg;
8409 encode_arm_shift (i);
8410 }
8411 else
8412 {
8413 inst.instruction |= INST_IMMEDIATE;
8414 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
8415 inst.instruction |= inst.operands[i].imm;
8416 }
8417 }
8418
8419 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
8420 static void
8421 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
8422 {
8423 /* PR 14260:
8424 Generate an error if the operand is not a register. */
8425 constraint (!inst.operands[i].isreg,
8426 _("Instruction does not support =N addresses"));
8427
8428 inst.instruction |= inst.operands[i].reg << 16;
8429
8430 if (inst.operands[i].preind)
8431 {
8432 if (is_t)
8433 {
8434 inst.error = _("instruction does not accept preindexed addressing");
8435 return;
8436 }
8437 inst.instruction |= PRE_INDEX;
8438 if (inst.operands[i].writeback)
8439 inst.instruction |= WRITE_BACK;
8440
8441 }
8442 else if (inst.operands[i].postind)
8443 {
8444 gas_assert (inst.operands[i].writeback);
8445 if (is_t)
8446 inst.instruction |= WRITE_BACK;
8447 }
8448 else /* unindexed - only for coprocessor */
8449 {
8450 inst.error = _("instruction does not accept unindexed addressing");
8451 return;
8452 }
8453
8454 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
8455 && (((inst.instruction & 0x000f0000) >> 16)
8456 == ((inst.instruction & 0x0000f000) >> 12)))
8457 as_warn ((inst.instruction & LOAD_BIT)
8458 ? _("destination register same as write-back base")
8459 : _("source register same as write-back base"));
8460 }
8461
8462 /* inst.operands[i] was set up by parse_address. Encode it into an
8463 ARM-format mode 2 load or store instruction. If is_t is true,
8464 reject forms that cannot be used with a T instruction (i.e. not
8465 post-indexed). */
8466 static void
8467 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
8468 {
8469 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8470
8471 encode_arm_addr_mode_common (i, is_t);
8472
8473 if (inst.operands[i].immisreg)
8474 {
8475 constraint ((inst.operands[i].imm == REG_PC
8476 || (is_pc && inst.operands[i].writeback)),
8477 BAD_PC_ADDRESSING);
8478 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
8479 inst.instruction |= inst.operands[i].imm;
8480 if (!inst.operands[i].negative)
8481 inst.instruction |= INDEX_UP;
8482 if (inst.operands[i].shifted)
8483 {
8484 if (inst.operands[i].shift_kind == SHIFT_RRX)
8485 inst.instruction |= SHIFT_ROR << 5;
8486 else
8487 {
8488 inst.instruction |= inst.operands[i].shift_kind << 5;
8489 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
8490 }
8491 }
8492 }
8493 else /* immediate offset in inst.relocs[0] */
8494 {
8495 if (is_pc && !inst.relocs[0].pc_rel)
8496 {
8497 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
8498
8499 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
8500 cannot use PC in addressing.
8501 PC cannot be used in writeback addressing, either. */
8502 constraint ((is_t || inst.operands[i].writeback),
8503 BAD_PC_ADDRESSING);
8504
8505 /* Use of PC in str is deprecated for ARMv7. */
8506 if (warn_on_deprecated
8507 && !is_load
8508 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
8509 as_tsktsk (_("use of PC in this instruction is deprecated"));
8510 }
8511
8512 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
8513 {
8514 /* Prefer + for zero encoded value. */
8515 if (!inst.operands[i].negative)
8516 inst.instruction |= INDEX_UP;
8517 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
8518 }
8519 }
8520 }
8521
8522 /* inst.operands[i] was set up by parse_address. Encode it into an
8523 ARM-format mode 3 load or store instruction. Reject forms that
8524 cannot be used with such instructions. If is_t is true, reject
8525 forms that cannot be used with a T instruction (i.e. not
8526 post-indexed). */
8527 static void
8528 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
8529 {
8530 if (inst.operands[i].immisreg && inst.operands[i].shifted)
8531 {
8532 inst.error = _("instruction does not accept scaled register index");
8533 return;
8534 }
8535
8536 encode_arm_addr_mode_common (i, is_t);
8537
8538 if (inst.operands[i].immisreg)
8539 {
8540 constraint ((inst.operands[i].imm == REG_PC
8541 || (is_t && inst.operands[i].reg == REG_PC)),
8542 BAD_PC_ADDRESSING);
8543 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
8544 BAD_PC_WRITEBACK);
8545 inst.instruction |= inst.operands[i].imm;
8546 if (!inst.operands[i].negative)
8547 inst.instruction |= INDEX_UP;
8548 }
8549 else /* immediate offset in inst.relocs[0] */
8550 {
8551 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
8552 && inst.operands[i].writeback),
8553 BAD_PC_WRITEBACK);
8554 inst.instruction |= HWOFFSET_IMM;
8555 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
8556 {
8557 /* Prefer + for zero encoded value. */
8558 if (!inst.operands[i].negative)
8559 inst.instruction |= INDEX_UP;
8560
8561 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
8562 }
8563 }
8564 }
8565
8566 /* Write immediate bits [7:0] to the following locations:
8567
8568 |28/24|23 19|18 16|15 4|3 0|
8569 | 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|
8570
8571 This function is used by VMOV/VMVN/VORR/VBIC. */
8572
8573 static void
8574 neon_write_immbits (unsigned immbits)
8575 {
8576 inst.instruction |= immbits & 0xf;
8577 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
8578 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
8579 }
8580
8581 /* Invert low-order SIZE bits of XHI:XLO. */
8582
8583 static void
8584 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8585 {
8586 unsigned immlo = xlo ? *xlo : 0;
8587 unsigned immhi = xhi ? *xhi : 0;
8588
8589 switch (size)
8590 {
8591 case 8:
8592 immlo = (~immlo) & 0xff;
8593 break;
8594
8595 case 16:
8596 immlo = (~immlo) & 0xffff;
8597 break;
8598
8599 case 64:
8600 immhi = (~immhi) & 0xffffffff;
8601 /* fall through. */
8602
8603 case 32:
8604 immlo = (~immlo) & 0xffffffff;
8605 break;
8606
8607 default:
8608 abort ();
8609 }
8610
8611 if (xlo)
8612 *xlo = immlo;
8613
8614 if (xhi)
8615 *xhi = immhi;
8616 }
8617
8618 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8619 A, B, C, D. */
8620
8621 static int
8622 neon_bits_same_in_bytes (unsigned imm)
8623 {
8624 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8625 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8626 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8627 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8628 }
8629
8630 /* For immediate of above form, return 0bABCD. */
8631
8632 static unsigned
8633 neon_squash_bits (unsigned imm)
8634 {
8635 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8636 | ((imm & 0x01000000) >> 21);
8637 }
8638
8639 /* Compress quarter-float representation to 0b...000 abcdefgh. */
8640
8641 static unsigned
8642 neon_qfloat_bits (unsigned imm)
8643 {
8644 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8645 }
8646
8647 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8648 the instruction. *OP is passed as the initial value of the op field, and
8649 may be set to a different value depending on the constant (i.e.
8650 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8651 MVN). If the immediate looks like a repeated pattern then also
8652 try smaller element sizes. */
8653
8654 static int
8655 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8656 unsigned *immbits, int *op, int size,
8657 enum neon_el_type type)
8658 {
8659 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8660 float. */
8661 if (type == NT_float && !float_p)
8662 return FAIL;
8663
8664 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
8665 {
8666 if (size != 32 || *op == 1)
8667 return FAIL;
8668 *immbits = neon_qfloat_bits (immlo);
8669 return 0xf;
8670 }
8671
8672 if (size == 64)
8673 {
8674 if (neon_bits_same_in_bytes (immhi)
8675 && neon_bits_same_in_bytes (immlo))
8676 {
8677 if (*op == 1)
8678 return FAIL;
8679 *immbits = (neon_squash_bits (immhi) << 4)
8680 | neon_squash_bits (immlo);
8681 *op = 1;
8682 return 0xe;
8683 }
8684
8685 if (immhi != immlo)
8686 return FAIL;
8687 }
8688
8689 if (size >= 32)
8690 {
8691 if (immlo == (immlo & 0x000000ff))
8692 {
8693 *immbits = immlo;
8694 return 0x0;
8695 }
8696 else if (immlo == (immlo & 0x0000ff00))
8697 {
8698 *immbits = immlo >> 8;
8699 return 0x2;
8700 }
8701 else if (immlo == (immlo & 0x00ff0000))
8702 {
8703 *immbits = immlo >> 16;
8704 return 0x4;
8705 }
8706 else if (immlo == (immlo & 0xff000000))
8707 {
8708 *immbits = immlo >> 24;
8709 return 0x6;
8710 }
8711 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8712 {
8713 *immbits = (immlo >> 8) & 0xff;
8714 return 0xc;
8715 }
8716 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8717 {
8718 *immbits = (immlo >> 16) & 0xff;
8719 return 0xd;
8720 }
8721
8722 if ((immlo & 0xffff) != (immlo >> 16))
8723 return FAIL;
8724 immlo &= 0xffff;
8725 }
8726
8727 if (size >= 16)
8728 {
8729 if (immlo == (immlo & 0x000000ff))
8730 {
8731 *immbits = immlo;
8732 return 0x8;
8733 }
8734 else if (immlo == (immlo & 0x0000ff00))
8735 {
8736 *immbits = immlo >> 8;
8737 return 0xa;
8738 }
8739
8740 if ((immlo & 0xff) != (immlo >> 8))
8741 return FAIL;
8742 immlo &= 0xff;
8743 }
8744
8745 if (immlo == (immlo & 0x000000ff))
8746 {
8747 /* Don't allow MVN with 8-bit immediate. */
8748 if (*op == 1)
8749 return FAIL;
8750 *immbits = immlo;
8751 return 0xe;
8752 }
8753
8754 return FAIL;
8755 }
8756
8757 #if defined BFD_HOST_64_BIT
8758 /* Returns TRUE if double precision value V may be cast
8759 to single precision without loss of accuracy. */
8760
8761 static bfd_boolean
8762 is_double_a_single (bfd_int64_t v)
8763 {
8764 int exp = (int)((v >> 52) & 0x7FF);
8765 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
8766
8767 return (exp == 0 || exp == 0x7FF
8768 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8769 && (mantissa & 0x1FFFFFFFl) == 0;
8770 }
8771
8772 /* Returns a double precision value casted to single precision
8773 (ignoring the least significant bits in exponent and mantissa). */
8774
8775 static int
8776 double_to_single (bfd_int64_t v)
8777 {
8778 int sign = (int) ((v >> 63) & 1l);
8779 int exp = (int) ((v >> 52) & 0x7FF);
8780 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
8781
8782 if (exp == 0x7FF)
8783 exp = 0xFF;
8784 else
8785 {
8786 exp = exp - 1023 + 127;
8787 if (exp >= 0xFF)
8788 {
8789 /* Infinity. */
8790 exp = 0x7F;
8791 mantissa = 0;
8792 }
8793 else if (exp < 0)
8794 {
8795 /* No denormalized numbers. */
8796 exp = 0;
8797 mantissa = 0;
8798 }
8799 }
8800 mantissa >>= 29;
8801 return (sign << 31) | (exp << 23) | mantissa;
8802 }
8803 #endif /* BFD_HOST_64_BIT */
8804
8805 enum lit_type
8806 {
8807 CONST_THUMB,
8808 CONST_ARM,
8809 CONST_VEC
8810 };
8811
8812 static void do_vfp_nsyn_opcode (const char *);
8813
8814 /* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
8815 Determine whether it can be performed with a move instruction; if
8816 it can, convert inst.instruction to that move instruction and
8817 return TRUE; if it can't, convert inst.instruction to a literal-pool
8818 load and return FALSE. If this is not a valid thing to do in the
8819 current context, set inst.error and return TRUE.
8820
8821 inst.operands[i] describes the destination register. */
8822
8823 static bfd_boolean
8824 move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
8825 {
8826 unsigned long tbit;
8827 bfd_boolean thumb_p = (t == CONST_THUMB);
8828 bfd_boolean arm_p = (t == CONST_ARM);
8829
8830 if (thumb_p)
8831 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8832 else
8833 tbit = LOAD_BIT;
8834
8835 if ((inst.instruction & tbit) == 0)
8836 {
8837 inst.error = _("invalid pseudo operation");
8838 return TRUE;
8839 }
8840
8841 if (inst.relocs[0].exp.X_op != O_constant
8842 && inst.relocs[0].exp.X_op != O_symbol
8843 && inst.relocs[0].exp.X_op != O_big)
8844 {
8845 inst.error = _("constant expression expected");
8846 return TRUE;
8847 }
8848
8849 if (inst.relocs[0].exp.X_op == O_constant
8850 || inst.relocs[0].exp.X_op == O_big)
8851 {
8852 #if defined BFD_HOST_64_BIT
8853 bfd_int64_t v;
8854 #else
8855 offsetT v;
8856 #endif
8857 if (inst.relocs[0].exp.X_op == O_big)
8858 {
8859 LITTLENUM_TYPE w[X_PRECISION];
8860 LITTLENUM_TYPE * l;
8861
8862 if (inst.relocs[0].exp.X_add_number == -1)
8863 {
8864 gen_to_words (w, X_PRECISION, E_PRECISION);
8865 l = w;
8866 /* FIXME: Should we check words w[2..5] ? */
8867 }
8868 else
8869 l = generic_bignum;
8870
8871 #if defined BFD_HOST_64_BIT
8872 v =
8873 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8874 << LITTLENUM_NUMBER_OF_BITS)
8875 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8876 << LITTLENUM_NUMBER_OF_BITS)
8877 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8878 << LITTLENUM_NUMBER_OF_BITS)
8879 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8880 #else
8881 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8882 | (l[0] & LITTLENUM_MASK);
8883 #endif
8884 }
8885 else
8886 v = inst.relocs[0].exp.X_add_number;
8887
8888 if (!inst.operands[i].issingle)
8889 {
8890 if (thumb_p)
8891 {
8892 /* LDR should not use lead in a flag-setting instruction being
8893 chosen so we do not check whether movs can be used. */
8894
8895 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
8896 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8897 && inst.operands[i].reg != 13
8898 && inst.operands[i].reg != 15)
8899 {
8900 /* Check if on thumb2 it can be done with a mov.w, mvn or
8901 movw instruction. */
8902 unsigned int newimm;
8903 bfd_boolean isNegated;
8904
8905 newimm = encode_thumb32_immediate (v);
8906 if (newimm != (unsigned int) FAIL)
8907 isNegated = FALSE;
8908 else
8909 {
8910 newimm = encode_thumb32_immediate (~v);
8911 if (newimm != (unsigned int) FAIL)
8912 isNegated = TRUE;
8913 }
8914
8915 /* The number can be loaded with a mov.w or mvn
8916 instruction. */
8917 if (newimm != (unsigned int) FAIL
8918 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
8919 {
8920 inst.instruction = (0xf04f0000 /* MOV.W. */
8921 | (inst.operands[i].reg << 8));
8922 /* Change to MOVN. */
8923 inst.instruction |= (isNegated ? 0x200000 : 0);
8924 inst.instruction |= (newimm & 0x800) << 15;
8925 inst.instruction |= (newimm & 0x700) << 4;
8926 inst.instruction |= (newimm & 0x0ff);
8927 return TRUE;
8928 }
8929 /* The number can be loaded with a movw instruction. */
8930 else if ((v & ~0xFFFF) == 0
8931 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8932 {
8933 int imm = v & 0xFFFF;
8934
8935 inst.instruction = 0xf2400000; /* MOVW. */
8936 inst.instruction |= (inst.operands[i].reg << 8);
8937 inst.instruction |= (imm & 0xf000) << 4;
8938 inst.instruction |= (imm & 0x0800) << 15;
8939 inst.instruction |= (imm & 0x0700) << 4;
8940 inst.instruction |= (imm & 0x00ff);
8941 /* In case this replacement is being done on Armv8-M
8942 Baseline we need to make sure to disable the
8943 instruction size check, as otherwise GAS will reject
8944 the use of this T32 instruction. */
8945 inst.size_req = 0;
8946 return TRUE;
8947 }
8948 }
8949 }
8950 else if (arm_p)
8951 {
8952 int value = encode_arm_immediate (v);
8953
8954 if (value != FAIL)
8955 {
8956 /* This can be done with a mov instruction. */
8957 inst.instruction &= LITERAL_MASK;
8958 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8959 inst.instruction |= value & 0xfff;
8960 return TRUE;
8961 }
8962
8963 value = encode_arm_immediate (~ v);
8964 if (value != FAIL)
8965 {
8966 /* This can be done with a mvn instruction. */
8967 inst.instruction &= LITERAL_MASK;
8968 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8969 inst.instruction |= value & 0xfff;
8970 return TRUE;
8971 }
8972 }
8973 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8974 {
8975 int op = 0;
8976 unsigned immbits = 0;
8977 unsigned immlo = inst.operands[1].imm;
8978 unsigned immhi = inst.operands[1].regisimm
8979 ? inst.operands[1].reg
8980 : inst.relocs[0].exp.X_unsigned
8981 ? 0
8982 : ((bfd_int64_t)((int) immlo)) >> 32;
8983 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8984 &op, 64, NT_invtype);
8985
8986 if (cmode == FAIL)
8987 {
8988 neon_invert_size (&immlo, &immhi, 64);
8989 op = !op;
8990 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8991 &op, 64, NT_invtype);
8992 }
8993
8994 if (cmode != FAIL)
8995 {
8996 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8997 | (1 << 23)
8998 | (cmode << 8)
8999 | (op << 5)
9000 | (1 << 4);
9001
9002 /* Fill other bits in vmov encoding for both thumb and arm. */
9003 if (thumb_mode)
9004 inst.instruction |= (0x7U << 29) | (0xF << 24);
9005 else
9006 inst.instruction |= (0xFU << 28) | (0x1 << 25);
9007 neon_write_immbits (immbits);
9008 return TRUE;
9009 }
9010 }
9011 }
9012
9013 if (t == CONST_VEC)
9014 {
9015 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
9016 if (inst.operands[i].issingle
9017 && is_quarter_float (inst.operands[1].imm)
9018 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
9019 {
9020 inst.operands[1].imm =
9021 neon_qfloat_bits (v);
9022 do_vfp_nsyn_opcode ("fconsts");
9023 return TRUE;
9024 }
9025
9026 /* If our host does not support a 64-bit type then we cannot perform
9027 the following optimization. This mean that there will be a
9028 discrepancy between the output produced by an assembler built for
9029 a 32-bit-only host and the output produced from a 64-bit host, but
9030 this cannot be helped. */
9031 #if defined BFD_HOST_64_BIT
9032 else if (!inst.operands[1].issingle
9033 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
9034 {
9035 if (is_double_a_single (v)
9036 && is_quarter_float (double_to_single (v)))
9037 {
9038 inst.operands[1].imm =
9039 neon_qfloat_bits (double_to_single (v));
9040 do_vfp_nsyn_opcode ("fconstd");
9041 return TRUE;
9042 }
9043 }
9044 #endif
9045 }
9046 }
9047
9048 if (add_to_lit_pool ((!inst.operands[i].isvec
9049 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
9050 return TRUE;
9051
9052 inst.operands[1].reg = REG_PC;
9053 inst.operands[1].isreg = 1;
9054 inst.operands[1].preind = 1;
9055 inst.relocs[0].pc_rel = 1;
9056 inst.relocs[0].type = (thumb_p
9057 ? BFD_RELOC_ARM_THUMB_OFFSET
9058 : (mode_3
9059 ? BFD_RELOC_ARM_HWLITERAL
9060 : BFD_RELOC_ARM_LITERAL));
9061 return FALSE;
9062 }
9063
9064 /* inst.operands[i] was set up by parse_address. Encode it into an
9065 ARM-format instruction. Reject all forms which cannot be encoded
9066 into a coprocessor load/store instruction. If wb_ok is false,
9067 reject use of writeback; if unind_ok is false, reject use of
9068 unindexed addressing. If reloc_override is not 0, use it instead
9069 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
9070 (in which case it is preserved). */
9071
9072 static int
9073 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
9074 {
9075 if (!inst.operands[i].isreg)
9076 {
9077 /* PR 18256 */
9078 if (! inst.operands[0].isvec)
9079 {
9080 inst.error = _("invalid co-processor operand");
9081 return FAIL;
9082 }
9083 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
9084 return SUCCESS;
9085 }
9086
9087 inst.instruction |= inst.operands[i].reg << 16;
9088
9089 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
9090
9091 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
9092 {
9093 gas_assert (!inst.operands[i].writeback);
9094 if (!unind_ok)
9095 {
9096 inst.error = _("instruction does not support unindexed addressing");
9097 return FAIL;
9098 }
9099 inst.instruction |= inst.operands[i].imm;
9100 inst.instruction |= INDEX_UP;
9101 return SUCCESS;
9102 }
9103
9104 if (inst.operands[i].preind)
9105 inst.instruction |= PRE_INDEX;
9106
9107 if (inst.operands[i].writeback)
9108 {
9109 if (inst.operands[i].reg == REG_PC)
9110 {
9111 inst.error = _("pc may not be used with write-back");
9112 return FAIL;
9113 }
9114 if (!wb_ok)
9115 {
9116 inst.error = _("instruction does not support writeback");
9117 return FAIL;
9118 }
9119 inst.instruction |= WRITE_BACK;
9120 }
9121
9122 if (reloc_override)
9123 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
9124 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
9125 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
9126 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
9127 {
9128 if (thumb_mode)
9129 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
9130 else
9131 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
9132 }
9133
9134 /* Prefer + for zero encoded value. */
9135 if (!inst.operands[i].negative)
9136 inst.instruction |= INDEX_UP;
9137
9138 return SUCCESS;
9139 }
9140
9141 /* Functions for instruction encoding, sorted by sub-architecture.
9142 First some generics; their names are taken from the conventional
9143 bit positions for register arguments in ARM format instructions. */
9144
9145 static void
9146 do_noargs (void)
9147 {
9148 }
9149
9150 static void
9151 do_rd (void)
9152 {
9153 inst.instruction |= inst.operands[0].reg << 12;
9154 }
9155
9156 static void
9157 do_rn (void)
9158 {
9159 inst.instruction |= inst.operands[0].reg << 16;
9160 }
9161
9162 static void
9163 do_rd_rm (void)
9164 {
9165 inst.instruction |= inst.operands[0].reg << 12;
9166 inst.instruction |= inst.operands[1].reg;
9167 }
9168
9169 static void
9170 do_rm_rn (void)
9171 {
9172 inst.instruction |= inst.operands[0].reg;
9173 inst.instruction |= inst.operands[1].reg << 16;
9174 }
9175
9176 static void
9177 do_rd_rn (void)
9178 {
9179 inst.instruction |= inst.operands[0].reg << 12;
9180 inst.instruction |= inst.operands[1].reg << 16;
9181 }
9182
9183 static void
9184 do_rn_rd (void)
9185 {
9186 inst.instruction |= inst.operands[0].reg << 16;
9187 inst.instruction |= inst.operands[1].reg << 12;
9188 }
9189
9190 static void
9191 do_tt (void)
9192 {
9193 inst.instruction |= inst.operands[0].reg << 8;
9194 inst.instruction |= inst.operands[1].reg << 16;
9195 }
9196
9197 static bfd_boolean
9198 check_obsolete (const arm_feature_set *feature, const char *msg)
9199 {
9200 if (ARM_CPU_IS_ANY (cpu_variant))
9201 {
9202 as_tsktsk ("%s", msg);
9203 return TRUE;
9204 }
9205 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
9206 {
9207 as_bad ("%s", msg);
9208 return TRUE;
9209 }
9210
9211 return FALSE;
9212 }
9213
9214 static void
9215 do_rd_rm_rn (void)
9216 {
9217 unsigned Rn = inst.operands[2].reg;
9218 /* Enforce restrictions on SWP instruction. */
9219 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
9220 {
9221 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
9222 _("Rn must not overlap other operands"));
9223
9224 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
9225 */
9226 if (!check_obsolete (&arm_ext_v8,
9227 _("swp{b} use is obsoleted for ARMv8 and later"))
9228 && warn_on_deprecated
9229 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
9230 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
9231 }
9232
9233 inst.instruction |= inst.operands[0].reg << 12;
9234 inst.instruction |= inst.operands[1].reg;
9235 inst.instruction |= Rn << 16;
9236 }
9237
9238 static void
9239 do_rd_rn_rm (void)
9240 {
9241 inst.instruction |= inst.operands[0].reg << 12;
9242 inst.instruction |= inst.operands[1].reg << 16;
9243 inst.instruction |= inst.operands[2].reg;
9244 }
9245
9246 static void
9247 do_rm_rd_rn (void)
9248 {
9249 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
9250 constraint (((inst.relocs[0].exp.X_op != O_constant
9251 && inst.relocs[0].exp.X_op != O_illegal)
9252 || inst.relocs[0].exp.X_add_number != 0),
9253 BAD_ADDR_MODE);
9254 inst.instruction |= inst.operands[0].reg;
9255 inst.instruction |= inst.operands[1].reg << 12;
9256 inst.instruction |= inst.operands[2].reg << 16;
9257 }
9258
9259 static void
9260 do_imm0 (void)
9261 {
9262 inst.instruction |= inst.operands[0].imm;
9263 }
9264
9265 static void
9266 do_rd_cpaddr (void)
9267 {
9268 inst.instruction |= inst.operands[0].reg << 12;
9269 encode_arm_cp_address (1, TRUE, TRUE, 0);
9270 }
9271
9272 /* ARM instructions, in alphabetical order by function name (except
9273 that wrapper functions appear immediately after the function they
9274 wrap). */
9275
9276 /* This is a pseudo-op of the form "adr rd, label" to be converted
9277 into a relative address of the form "add rd, pc, #label-.-8". */
9278
9279 static void
9280 do_adr (void)
9281 {
9282 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
9283
9284 /* Frag hacking will turn this into a sub instruction if the offset turns
9285 out to be negative. */
9286 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9287 inst.relocs[0].pc_rel = 1;
9288 inst.relocs[0].exp.X_add_number -= 8;
9289
9290 if (support_interwork
9291 && inst.relocs[0].exp.X_op == O_symbol
9292 && inst.relocs[0].exp.X_add_symbol != NULL
9293 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9294 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9295 inst.relocs[0].exp.X_add_number |= 1;
9296 }
9297
9298 /* This is a pseudo-op of the form "adrl rd, label" to be converted
9299 into a relative address of the form:
9300 add rd, pc, #low(label-.-8)"
9301 add rd, rd, #high(label-.-8)" */
9302
9303 static void
9304 do_adrl (void)
9305 {
9306 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
9307
9308 /* Frag hacking will turn this into a sub instruction if the offset turns
9309 out to be negative. */
9310 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
9311 inst.relocs[0].pc_rel = 1;
9312 inst.size = INSN_SIZE * 2;
9313 inst.relocs[0].exp.X_add_number -= 8;
9314
9315 if (support_interwork
9316 && inst.relocs[0].exp.X_op == O_symbol
9317 && inst.relocs[0].exp.X_add_symbol != NULL
9318 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9319 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9320 inst.relocs[0].exp.X_add_number |= 1;
9321 }
9322
9323 static void
9324 do_arit (void)
9325 {
9326 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9327 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9328 THUMB1_RELOC_ONLY);
9329 if (!inst.operands[1].present)
9330 inst.operands[1].reg = inst.operands[0].reg;
9331 inst.instruction |= inst.operands[0].reg << 12;
9332 inst.instruction |= inst.operands[1].reg << 16;
9333 encode_arm_shifter_operand (2);
9334 }
9335
9336 static void
9337 do_barrier (void)
9338 {
9339 if (inst.operands[0].present)
9340 inst.instruction |= inst.operands[0].imm;
9341 else
9342 inst.instruction |= 0xf;
9343 }
9344
9345 static void
9346 do_bfc (void)
9347 {
9348 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9349 constraint (msb > 32, _("bit-field extends past end of register"));
9350 /* The instruction encoding stores the LSB and MSB,
9351 not the LSB and width. */
9352 inst.instruction |= inst.operands[0].reg << 12;
9353 inst.instruction |= inst.operands[1].imm << 7;
9354 inst.instruction |= (msb - 1) << 16;
9355 }
9356
9357 static void
9358 do_bfi (void)
9359 {
9360 unsigned int msb;
9361
9362 /* #0 in second position is alternative syntax for bfc, which is
9363 the same instruction but with REG_PC in the Rm field. */
9364 if (!inst.operands[1].isreg)
9365 inst.operands[1].reg = REG_PC;
9366
9367 msb = inst.operands[2].imm + inst.operands[3].imm;
9368 constraint (msb > 32, _("bit-field extends past end of register"));
9369 /* The instruction encoding stores the LSB and MSB,
9370 not the LSB and width. */
9371 inst.instruction |= inst.operands[0].reg << 12;
9372 inst.instruction |= inst.operands[1].reg;
9373 inst.instruction |= inst.operands[2].imm << 7;
9374 inst.instruction |= (msb - 1) << 16;
9375 }
9376
9377 static void
9378 do_bfx (void)
9379 {
9380 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9381 _("bit-field extends past end of register"));
9382 inst.instruction |= inst.operands[0].reg << 12;
9383 inst.instruction |= inst.operands[1].reg;
9384 inst.instruction |= inst.operands[2].imm << 7;
9385 inst.instruction |= (inst.operands[3].imm - 1) << 16;
9386 }
9387
9388 /* ARM V5 breakpoint instruction (argument parse)
9389 BKPT <16 bit unsigned immediate>
9390 Instruction is not conditional.
9391 The bit pattern given in insns[] has the COND_ALWAYS condition,
9392 and it is an error if the caller tried to override that. */
9393
9394 static void
9395 do_bkpt (void)
9396 {
9397 /* Top 12 of 16 bits to bits 19:8. */
9398 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
9399
9400 /* Bottom 4 of 16 bits to bits 3:0. */
9401 inst.instruction |= inst.operands[0].imm & 0xf;
9402 }
9403
9404 static void
9405 encode_branch (int default_reloc)
9406 {
9407 if (inst.operands[0].hasreloc)
9408 {
9409 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
9410 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
9411 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
9412 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
9413 ? BFD_RELOC_ARM_PLT32
9414 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
9415 }
9416 else
9417 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
9418 inst.relocs[0].pc_rel = 1;
9419 }
9420
9421 static void
9422 do_branch (void)
9423 {
9424 #ifdef OBJ_ELF
9425 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9426 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9427 else
9428 #endif
9429 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9430 }
9431
9432 static void
9433 do_bl (void)
9434 {
9435 #ifdef OBJ_ELF
9436 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9437 {
9438 if (inst.cond == COND_ALWAYS)
9439 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
9440 else
9441 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9442 }
9443 else
9444 #endif
9445 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9446 }
9447
9448 /* ARM V5 branch-link-exchange instruction (argument parse)
9449 BLX <target_addr> ie BLX(1)
9450 BLX{<condition>} <Rm> ie BLX(2)
9451 Unfortunately, there are two different opcodes for this mnemonic.
9452 So, the insns[].value is not used, and the code here zaps values
9453 into inst.instruction.
9454 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
9455
9456 static void
9457 do_blx (void)
9458 {
9459 if (inst.operands[0].isreg)
9460 {
9461 /* Arg is a register; the opcode provided by insns[] is correct.
9462 It is not illegal to do "blx pc", just useless. */
9463 if (inst.operands[0].reg == REG_PC)
9464 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
9465
9466 inst.instruction |= inst.operands[0].reg;
9467 }
9468 else
9469 {
9470 /* Arg is an address; this instruction cannot be executed
9471 conditionally, and the opcode must be adjusted.
9472 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
9473 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
9474 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9475 inst.instruction = 0xfa000000;
9476 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
9477 }
9478 }
9479
9480 static void
9481 do_bx (void)
9482 {
9483 bfd_boolean want_reloc;
9484
9485 if (inst.operands[0].reg == REG_PC)
9486 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
9487
9488 inst.instruction |= inst.operands[0].reg;
9489 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
9490 it is for ARMv4t or earlier. */
9491 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
9492 if (!ARM_FEATURE_ZERO (selected_object_arch)
9493 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
9494 want_reloc = TRUE;
9495
9496 #ifdef OBJ_ELF
9497 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
9498 #endif
9499 want_reloc = FALSE;
9500
9501 if (want_reloc)
9502 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
9503 }
9504
9505
9506 /* ARM v5TEJ. Jump to Jazelle code. */
9507
9508 static void
9509 do_bxj (void)
9510 {
9511 if (inst.operands[0].reg == REG_PC)
9512 as_tsktsk (_("use of r15 in bxj is not really useful"));
9513
9514 inst.instruction |= inst.operands[0].reg;
9515 }
9516
9517 /* Co-processor data operation:
9518 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
9519 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
9520 static void
9521 do_cdp (void)
9522 {
9523 inst.instruction |= inst.operands[0].reg << 8;
9524 inst.instruction |= inst.operands[1].imm << 20;
9525 inst.instruction |= inst.operands[2].reg << 12;
9526 inst.instruction |= inst.operands[3].reg << 16;
9527 inst.instruction |= inst.operands[4].reg;
9528 inst.instruction |= inst.operands[5].imm << 5;
9529 }
9530
9531 static void
9532 do_cmp (void)
9533 {
9534 inst.instruction |= inst.operands[0].reg << 16;
9535 encode_arm_shifter_operand (1);
9536 }
9537
9538 /* Transfer between coprocessor and ARM registers.
9539 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
9540 MRC2
9541 MCR{cond}
9542 MCR2
9543
9544 No special properties. */
9545
9546 struct deprecated_coproc_regs_s
9547 {
9548 unsigned cp;
9549 int opc1;
9550 unsigned crn;
9551 unsigned crm;
9552 int opc2;
9553 arm_feature_set deprecated;
9554 arm_feature_set obsoleted;
9555 const char *dep_msg;
9556 const char *obs_msg;
9557 };
9558
9559 #define DEPR_ACCESS_V8 \
9560 N_("This coprocessor register access is deprecated in ARMv8")
9561
9562 /* Table of all deprecated coprocessor registers. */
9563 static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
9564 {
9565 {15, 0, 7, 10, 5, /* CP15DMB. */
9566 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9567 DEPR_ACCESS_V8, NULL},
9568 {15, 0, 7, 10, 4, /* CP15DSB. */
9569 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9570 DEPR_ACCESS_V8, NULL},
9571 {15, 0, 7, 5, 4, /* CP15ISB. */
9572 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9573 DEPR_ACCESS_V8, NULL},
9574 {14, 6, 1, 0, 0, /* TEEHBR. */
9575 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9576 DEPR_ACCESS_V8, NULL},
9577 {14, 6, 0, 0, 0, /* TEECR. */
9578 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9579 DEPR_ACCESS_V8, NULL},
9580 };
9581
9582 #undef DEPR_ACCESS_V8
9583
9584 static const size_t deprecated_coproc_reg_count =
9585 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
9586
9587 static void
9588 do_co_reg (void)
9589 {
9590 unsigned Rd;
9591 size_t i;
9592
9593 Rd = inst.operands[2].reg;
9594 if (thumb_mode)
9595 {
9596 if (inst.instruction == 0xee000010
9597 || inst.instruction == 0xfe000010)
9598 /* MCR, MCR2 */
9599 reject_bad_reg (Rd);
9600 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
9601 /* MRC, MRC2 */
9602 constraint (Rd == REG_SP, BAD_SP);
9603 }
9604 else
9605 {
9606 /* MCR */
9607 if (inst.instruction == 0xe000010)
9608 constraint (Rd == REG_PC, BAD_PC);
9609 }
9610
9611 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9612 {
9613 const struct deprecated_coproc_regs_s *r =
9614 deprecated_coproc_regs + i;
9615
9616 if (inst.operands[0].reg == r->cp
9617 && inst.operands[1].imm == r->opc1
9618 && inst.operands[3].reg == r->crn
9619 && inst.operands[4].reg == r->crm
9620 && inst.operands[5].imm == r->opc2)
9621 {
9622 if (! ARM_CPU_IS_ANY (cpu_variant)
9623 && warn_on_deprecated
9624 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
9625 as_tsktsk ("%s", r->dep_msg);
9626 }
9627 }
9628
9629 inst.instruction |= inst.operands[0].reg << 8;
9630 inst.instruction |= inst.operands[1].imm << 21;
9631 inst.instruction |= Rd << 12;
9632 inst.instruction |= inst.operands[3].reg << 16;
9633 inst.instruction |= inst.operands[4].reg;
9634 inst.instruction |= inst.operands[5].imm << 5;
9635 }
9636
9637 /* Transfer between coprocessor register and pair of ARM registers.
9638 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9639 MCRR2
9640 MRRC{cond}
9641 MRRC2
9642
9643 Two XScale instructions are special cases of these:
9644
9645 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9646 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
9647
9648 Result unpredictable if Rd or Rn is R15. */
9649
9650 static void
9651 do_co_reg2c (void)
9652 {
9653 unsigned Rd, Rn;
9654
9655 Rd = inst.operands[2].reg;
9656 Rn = inst.operands[3].reg;
9657
9658 if (thumb_mode)
9659 {
9660 reject_bad_reg (Rd);
9661 reject_bad_reg (Rn);
9662 }
9663 else
9664 {
9665 constraint (Rd == REG_PC, BAD_PC);
9666 constraint (Rn == REG_PC, BAD_PC);
9667 }
9668
9669 /* Only check the MRRC{2} variants. */
9670 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9671 {
9672 /* If Rd == Rn, error that the operation is
9673 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9674 constraint (Rd == Rn, BAD_OVERLAP);
9675 }
9676
9677 inst.instruction |= inst.operands[0].reg << 8;
9678 inst.instruction |= inst.operands[1].imm << 4;
9679 inst.instruction |= Rd << 12;
9680 inst.instruction |= Rn << 16;
9681 inst.instruction |= inst.operands[4].reg;
9682 }
9683
9684 static void
9685 do_cpsi (void)
9686 {
9687 inst.instruction |= inst.operands[0].imm << 6;
9688 if (inst.operands[1].present)
9689 {
9690 inst.instruction |= CPSI_MMOD;
9691 inst.instruction |= inst.operands[1].imm;
9692 }
9693 }
9694
9695 static void
9696 do_dbg (void)
9697 {
9698 inst.instruction |= inst.operands[0].imm;
9699 }
9700
9701 static void
9702 do_div (void)
9703 {
9704 unsigned Rd, Rn, Rm;
9705
9706 Rd = inst.operands[0].reg;
9707 Rn = (inst.operands[1].present
9708 ? inst.operands[1].reg : Rd);
9709 Rm = inst.operands[2].reg;
9710
9711 constraint ((Rd == REG_PC), BAD_PC);
9712 constraint ((Rn == REG_PC), BAD_PC);
9713 constraint ((Rm == REG_PC), BAD_PC);
9714
9715 inst.instruction |= Rd << 16;
9716 inst.instruction |= Rn << 0;
9717 inst.instruction |= Rm << 8;
9718 }
9719
9720 static void
9721 do_it (void)
9722 {
9723 /* There is no IT instruction in ARM mode. We
9724 process it to do the validation as if in
9725 thumb mode, just in case the code gets
9726 assembled for thumb using the unified syntax. */
9727
9728 inst.size = 0;
9729 if (unified_syntax)
9730 {
9731 set_pred_insn_type (IT_INSN);
9732 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9733 now_pred.cc = inst.operands[0].imm;
9734 }
9735 }
9736
9737 /* If there is only one register in the register list,
9738 then return its register number. Otherwise return -1. */
9739 static int
9740 only_one_reg_in_list (int range)
9741 {
9742 int i = ffs (range) - 1;
9743 return (i > 15 || range != (1 << i)) ? -1 : i;
9744 }
9745
9746 static void
9747 encode_ldmstm(int from_push_pop_mnem)
9748 {
9749 int base_reg = inst.operands[0].reg;
9750 int range = inst.operands[1].imm;
9751 int one_reg;
9752
9753 inst.instruction |= base_reg << 16;
9754 inst.instruction |= range;
9755
9756 if (inst.operands[1].writeback)
9757 inst.instruction |= LDM_TYPE_2_OR_3;
9758
9759 if (inst.operands[0].writeback)
9760 {
9761 inst.instruction |= WRITE_BACK;
9762 /* Check for unpredictable uses of writeback. */
9763 if (inst.instruction & LOAD_BIT)
9764 {
9765 /* Not allowed in LDM type 2. */
9766 if ((inst.instruction & LDM_TYPE_2_OR_3)
9767 && ((range & (1 << REG_PC)) == 0))
9768 as_warn (_("writeback of base register is UNPREDICTABLE"));
9769 /* Only allowed if base reg not in list for other types. */
9770 else if (range & (1 << base_reg))
9771 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9772 }
9773 else /* STM. */
9774 {
9775 /* Not allowed for type 2. */
9776 if (inst.instruction & LDM_TYPE_2_OR_3)
9777 as_warn (_("writeback of base register is UNPREDICTABLE"));
9778 /* Only allowed if base reg not in list, or first in list. */
9779 else if ((range & (1 << base_reg))
9780 && (range & ((1 << base_reg) - 1)))
9781 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
9782 }
9783 }
9784
9785 /* If PUSH/POP has only one register, then use the A2 encoding. */
9786 one_reg = only_one_reg_in_list (range);
9787 if (from_push_pop_mnem && one_reg >= 0)
9788 {
9789 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9790
9791 if (is_push && one_reg == 13 /* SP */)
9792 /* PR 22483: The A2 encoding cannot be used when
9793 pushing the stack pointer as this is UNPREDICTABLE. */
9794 return;
9795
9796 inst.instruction &= A_COND_MASK;
9797 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9798 inst.instruction |= one_reg << 12;
9799 }
9800 }
9801
9802 static void
9803 do_ldmstm (void)
9804 {
9805 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
9806 }
9807
9808 /* ARMv5TE load-consecutive (argument parse)
9809 Mode is like LDRH.
9810
9811 LDRccD R, mode
9812 STRccD R, mode. */
9813
9814 static void
9815 do_ldrd (void)
9816 {
9817 constraint (inst.operands[0].reg % 2 != 0,
9818 _("first transfer register must be even"));
9819 constraint (inst.operands[1].present
9820 && inst.operands[1].reg != inst.operands[0].reg + 1,
9821 _("can only transfer two consecutive registers"));
9822 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9823 constraint (!inst.operands[2].isreg, _("'[' expected"));
9824
9825 if (!inst.operands[1].present)
9826 inst.operands[1].reg = inst.operands[0].reg + 1;
9827
9828 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9829 register and the first register written; we have to diagnose
9830 overlap between the base and the second register written here. */
9831
9832 if (inst.operands[2].reg == inst.operands[1].reg
9833 && (inst.operands[2].writeback || inst.operands[2].postind))
9834 as_warn (_("base register written back, and overlaps "
9835 "second transfer register"));
9836
9837 if (!(inst.instruction & V4_STR_BIT))
9838 {
9839 /* For an index-register load, the index register must not overlap the
9840 destination (even if not write-back). */
9841 if (inst.operands[2].immisreg
9842 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9843 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9844 as_warn (_("index register overlaps transfer register"));
9845 }
9846 inst.instruction |= inst.operands[0].reg << 12;
9847 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
9848 }
9849
9850 static void
9851 do_ldrex (void)
9852 {
9853 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9854 || inst.operands[1].postind || inst.operands[1].writeback
9855 || inst.operands[1].immisreg || inst.operands[1].shifted
9856 || inst.operands[1].negative
9857 /* This can arise if the programmer has written
9858 strex rN, rM, foo
9859 or if they have mistakenly used a register name as the last
9860 operand, eg:
9861 strex rN, rM, rX
9862 It is very difficult to distinguish between these two cases
9863 because "rX" might actually be a label. ie the register
9864 name has been occluded by a symbol of the same name. So we
9865 just generate a general 'bad addressing mode' type error
9866 message and leave it up to the programmer to discover the
9867 true cause and fix their mistake. */
9868 || (inst.operands[1].reg == REG_PC),
9869 BAD_ADDR_MODE);
9870
9871 constraint (inst.relocs[0].exp.X_op != O_constant
9872 || inst.relocs[0].exp.X_add_number != 0,
9873 _("offset must be zero in ARM encoding"));
9874
9875 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9876
9877 inst.instruction |= inst.operands[0].reg << 12;
9878 inst.instruction |= inst.operands[1].reg << 16;
9879 inst.relocs[0].type = BFD_RELOC_UNUSED;
9880 }
9881
9882 static void
9883 do_ldrexd (void)
9884 {
9885 constraint (inst.operands[0].reg % 2 != 0,
9886 _("even register required"));
9887 constraint (inst.operands[1].present
9888 && inst.operands[1].reg != inst.operands[0].reg + 1,
9889 _("can only load two consecutive registers"));
9890 /* If op 1 were present and equal to PC, this function wouldn't
9891 have been called in the first place. */
9892 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9893
9894 inst.instruction |= inst.operands[0].reg << 12;
9895 inst.instruction |= inst.operands[2].reg << 16;
9896 }
9897
9898 /* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9899 which is not a multiple of four is UNPREDICTABLE. */
9900 static void
9901 check_ldr_r15_aligned (void)
9902 {
9903 constraint (!(inst.operands[1].immisreg)
9904 && (inst.operands[0].reg == REG_PC
9905 && inst.operands[1].reg == REG_PC
9906 && (inst.relocs[0].exp.X_add_number & 0x3)),
9907 _("ldr to register 15 must be 4-byte aligned"));
9908 }
9909
9910 static void
9911 do_ldst (void)
9912 {
9913 inst.instruction |= inst.operands[0].reg << 12;
9914 if (!inst.operands[1].isreg)
9915 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
9916 return;
9917 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
9918 check_ldr_r15_aligned ();
9919 }
9920
9921 static void
9922 do_ldstt (void)
9923 {
9924 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9925 reject [Rn,...]. */
9926 if (inst.operands[1].preind)
9927 {
9928 constraint (inst.relocs[0].exp.X_op != O_constant
9929 || inst.relocs[0].exp.X_add_number != 0,
9930 _("this instruction requires a post-indexed address"));
9931
9932 inst.operands[1].preind = 0;
9933 inst.operands[1].postind = 1;
9934 inst.operands[1].writeback = 1;
9935 }
9936 inst.instruction |= inst.operands[0].reg << 12;
9937 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9938 }
9939
9940 /* Halfword and signed-byte load/store operations. */
9941
9942 static void
9943 do_ldstv4 (void)
9944 {
9945 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9946 inst.instruction |= inst.operands[0].reg << 12;
9947 if (!inst.operands[1].isreg)
9948 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
9949 return;
9950 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
9951 }
9952
9953 static void
9954 do_ldsttv4 (void)
9955 {
9956 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9957 reject [Rn,...]. */
9958 if (inst.operands[1].preind)
9959 {
9960 constraint (inst.relocs[0].exp.X_op != O_constant
9961 || inst.relocs[0].exp.X_add_number != 0,
9962 _("this instruction requires a post-indexed address"));
9963
9964 inst.operands[1].preind = 0;
9965 inst.operands[1].postind = 1;
9966 inst.operands[1].writeback = 1;
9967 }
9968 inst.instruction |= inst.operands[0].reg << 12;
9969 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9970 }
9971
9972 /* Co-processor register load/store.
9973 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9974 static void
9975 do_lstc (void)
9976 {
9977 inst.instruction |= inst.operands[0].reg << 8;
9978 inst.instruction |= inst.operands[1].reg << 12;
9979 encode_arm_cp_address (2, TRUE, TRUE, 0);
9980 }
9981
9982 static void
9983 do_mlas (void)
9984 {
9985 /* This restriction does not apply to mls (nor to mla in v6 or later). */
9986 if (inst.operands[0].reg == inst.operands[1].reg
9987 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
9988 && !(inst.instruction & 0x00400000))
9989 as_tsktsk (_("Rd and Rm should be different in mla"));
9990
9991 inst.instruction |= inst.operands[0].reg << 16;
9992 inst.instruction |= inst.operands[1].reg;
9993 inst.instruction |= inst.operands[2].reg << 8;
9994 inst.instruction |= inst.operands[3].reg << 12;
9995 }
9996
9997 static void
9998 do_mov (void)
9999 {
10000 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10001 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10002 THUMB1_RELOC_ONLY);
10003 inst.instruction |= inst.operands[0].reg << 12;
10004 encode_arm_shifter_operand (1);
10005 }
10006
10007 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
10008 static void
10009 do_mov16 (void)
10010 {
10011 bfd_vma imm;
10012 bfd_boolean top;
10013
10014 top = (inst.instruction & 0x00400000) != 0;
10015 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
10016 _(":lower16: not allowed in this instruction"));
10017 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
10018 _(":upper16: not allowed in this instruction"));
10019 inst.instruction |= inst.operands[0].reg << 12;
10020 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
10021 {
10022 imm = inst.relocs[0].exp.X_add_number;
10023 /* The value is in two pieces: 0:11, 16:19. */
10024 inst.instruction |= (imm & 0x00000fff);
10025 inst.instruction |= (imm & 0x0000f000) << 4;
10026 }
10027 }
10028
10029 static int
10030 do_vfp_nsyn_mrs (void)
10031 {
10032 if (inst.operands[0].isvec)
10033 {
10034 if (inst.operands[1].reg != 1)
10035 first_error (_("operand 1 must be FPSCR"));
10036 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
10037 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
10038 do_vfp_nsyn_opcode ("fmstat");
10039 }
10040 else if (inst.operands[1].isvec)
10041 do_vfp_nsyn_opcode ("fmrx");
10042 else
10043 return FAIL;
10044
10045 return SUCCESS;
10046 }
10047
10048 static int
10049 do_vfp_nsyn_msr (void)
10050 {
10051 if (inst.operands[0].isvec)
10052 do_vfp_nsyn_opcode ("fmxr");
10053 else
10054 return FAIL;
10055
10056 return SUCCESS;
10057 }
10058
10059 static void
10060 do_vmrs (void)
10061 {
10062 unsigned Rt = inst.operands[0].reg;
10063
10064 if (thumb_mode && Rt == REG_SP)
10065 {
10066 inst.error = BAD_SP;
10067 return;
10068 }
10069
10070 switch (inst.operands[1].reg)
10071 {
10072 /* MVFR2 is only valid for Armv8-A. */
10073 case 5:
10074 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10075 _(BAD_FPU));
10076 break;
10077
10078 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10079 case 1: /* fpscr. */
10080 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10081 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10082 _(BAD_FPU));
10083 break;
10084
10085 case 14: /* fpcxt_ns. */
10086 case 15: /* fpcxt_s. */
10087 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10088 _("selected processor does not support instruction"));
10089 break;
10090
10091 case 2: /* fpscr_nzcvqc. */
10092 case 12: /* vpr. */
10093 case 13: /* p0. */
10094 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10095 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10096 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10097 _("selected processor does not support instruction"));
10098 if (inst.operands[0].reg != 2
10099 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10100 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10101 break;
10102
10103 default:
10104 break;
10105 }
10106
10107 /* APSR_ sets isvec. All other refs to PC are illegal. */
10108 if (!inst.operands[0].isvec && Rt == REG_PC)
10109 {
10110 inst.error = BAD_PC;
10111 return;
10112 }
10113
10114 /* If we get through parsing the register name, we just insert the number
10115 generated into the instruction without further validation. */
10116 inst.instruction |= (inst.operands[1].reg << 16);
10117 inst.instruction |= (Rt << 12);
10118 }
10119
10120 static void
10121 do_vmsr (void)
10122 {
10123 unsigned Rt = inst.operands[1].reg;
10124
10125 if (thumb_mode)
10126 reject_bad_reg (Rt);
10127 else if (Rt == REG_PC)
10128 {
10129 inst.error = BAD_PC;
10130 return;
10131 }
10132
10133 switch (inst.operands[0].reg)
10134 {
10135 /* MVFR2 is only valid for Armv8-A. */
10136 case 5:
10137 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10138 _(BAD_FPU));
10139 break;
10140
10141 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10142 case 1: /* fpcr. */
10143 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10144 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10145 _(BAD_FPU));
10146 break;
10147
10148 case 14: /* fpcxt_ns. */
10149 case 15: /* fpcxt_s. */
10150 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10151 _("selected processor does not support instruction"));
10152 break;
10153
10154 case 2: /* fpscr_nzcvqc. */
10155 case 12: /* vpr. */
10156 case 13: /* p0. */
10157 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10158 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10159 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10160 _("selected processor does not support instruction"));
10161 if (inst.operands[0].reg != 2
10162 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10163 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10164 break;
10165
10166 default:
10167 break;
10168 }
10169
10170 /* If we get through parsing the register name, we just insert the number
10171 generated into the instruction without further validation. */
10172 inst.instruction |= (inst.operands[0].reg << 16);
10173 inst.instruction |= (Rt << 12);
10174 }
10175
10176 static void
10177 do_mrs (void)
10178 {
10179 unsigned br;
10180
10181 if (do_vfp_nsyn_mrs () == SUCCESS)
10182 return;
10183
10184 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10185 inst.instruction |= inst.operands[0].reg << 12;
10186
10187 if (inst.operands[1].isreg)
10188 {
10189 br = inst.operands[1].reg;
10190 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
10191 as_bad (_("bad register for mrs"));
10192 }
10193 else
10194 {
10195 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10196 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
10197 != (PSR_c|PSR_f),
10198 _("'APSR', 'CPSR' or 'SPSR' expected"));
10199 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
10200 }
10201
10202 inst.instruction |= br;
10203 }
10204
10205 /* Two possible forms:
10206 "{C|S}PSR_<field>, Rm",
10207 "{C|S}PSR_f, #expression". */
10208
10209 static void
10210 do_msr (void)
10211 {
10212 if (do_vfp_nsyn_msr () == SUCCESS)
10213 return;
10214
10215 inst.instruction |= inst.operands[0].imm;
10216 if (inst.operands[1].isreg)
10217 inst.instruction |= inst.operands[1].reg;
10218 else
10219 {
10220 inst.instruction |= INST_IMMEDIATE;
10221 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
10222 inst.relocs[0].pc_rel = 0;
10223 }
10224 }
10225
10226 static void
10227 do_mul (void)
10228 {
10229 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
10230
10231 if (!inst.operands[2].present)
10232 inst.operands[2].reg = inst.operands[0].reg;
10233 inst.instruction |= inst.operands[0].reg << 16;
10234 inst.instruction |= inst.operands[1].reg;
10235 inst.instruction |= inst.operands[2].reg << 8;
10236
10237 if (inst.operands[0].reg == inst.operands[1].reg
10238 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10239 as_tsktsk (_("Rd and Rm should be different in mul"));
10240 }
10241
10242 /* Long Multiply Parser
10243 UMULL RdLo, RdHi, Rm, Rs
10244 SMULL RdLo, RdHi, Rm, Rs
10245 UMLAL RdLo, RdHi, Rm, Rs
10246 SMLAL RdLo, RdHi, Rm, Rs. */
10247
10248 static void
10249 do_mull (void)
10250 {
10251 inst.instruction |= inst.operands[0].reg << 12;
10252 inst.instruction |= inst.operands[1].reg << 16;
10253 inst.instruction |= inst.operands[2].reg;
10254 inst.instruction |= inst.operands[3].reg << 8;
10255
10256 /* rdhi and rdlo must be different. */
10257 if (inst.operands[0].reg == inst.operands[1].reg)
10258 as_tsktsk (_("rdhi and rdlo must be different"));
10259
10260 /* rdhi, rdlo and rm must all be different before armv6. */
10261 if ((inst.operands[0].reg == inst.operands[2].reg
10262 || inst.operands[1].reg == inst.operands[2].reg)
10263 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10264 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
10265 }
10266
10267 static void
10268 do_nop (void)
10269 {
10270 if (inst.operands[0].present
10271 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
10272 {
10273 /* Architectural NOP hints are CPSR sets with no bits selected. */
10274 inst.instruction &= 0xf0000000;
10275 inst.instruction |= 0x0320f000;
10276 if (inst.operands[0].present)
10277 inst.instruction |= inst.operands[0].imm;
10278 }
10279 }
10280
10281 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
10282 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
10283 Condition defaults to COND_ALWAYS.
10284 Error if Rd, Rn or Rm are R15. */
10285
10286 static void
10287 do_pkhbt (void)
10288 {
10289 inst.instruction |= inst.operands[0].reg << 12;
10290 inst.instruction |= inst.operands[1].reg << 16;
10291 inst.instruction |= inst.operands[2].reg;
10292 if (inst.operands[3].present)
10293 encode_arm_shift (3);
10294 }
10295
10296 /* ARM V6 PKHTB (Argument Parse). */
10297
10298 static void
10299 do_pkhtb (void)
10300 {
10301 if (!inst.operands[3].present)
10302 {
10303 /* If the shift specifier is omitted, turn the instruction
10304 into pkhbt rd, rm, rn. */
10305 inst.instruction &= 0xfff00010;
10306 inst.instruction |= inst.operands[0].reg << 12;
10307 inst.instruction |= inst.operands[1].reg;
10308 inst.instruction |= inst.operands[2].reg << 16;
10309 }
10310 else
10311 {
10312 inst.instruction |= inst.operands[0].reg << 12;
10313 inst.instruction |= inst.operands[1].reg << 16;
10314 inst.instruction |= inst.operands[2].reg;
10315 encode_arm_shift (3);
10316 }
10317 }
10318
10319 /* ARMv5TE: Preload-Cache
10320 MP Extensions: Preload for write
10321
10322 PLD(W) <addr_mode>
10323
10324 Syntactically, like LDR with B=1, W=0, L=1. */
10325
10326 static void
10327 do_pld (void)
10328 {
10329 constraint (!inst.operands[0].isreg,
10330 _("'[' expected after PLD mnemonic"));
10331 constraint (inst.operands[0].postind,
10332 _("post-indexed expression used in preload instruction"));
10333 constraint (inst.operands[0].writeback,
10334 _("writeback used in preload instruction"));
10335 constraint (!inst.operands[0].preind,
10336 _("unindexed addressing used in preload instruction"));
10337 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10338 }
10339
10340 /* ARMv7: PLI <addr_mode> */
10341 static void
10342 do_pli (void)
10343 {
10344 constraint (!inst.operands[0].isreg,
10345 _("'[' expected after PLI mnemonic"));
10346 constraint (inst.operands[0].postind,
10347 _("post-indexed expression used in preload instruction"));
10348 constraint (inst.operands[0].writeback,
10349 _("writeback used in preload instruction"));
10350 constraint (!inst.operands[0].preind,
10351 _("unindexed addressing used in preload instruction"));
10352 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10353 inst.instruction &= ~PRE_INDEX;
10354 }
10355
10356 static void
10357 do_push_pop (void)
10358 {
10359 constraint (inst.operands[0].writeback,
10360 _("push/pop do not support {reglist}^"));
10361 inst.operands[1] = inst.operands[0];
10362 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
10363 inst.operands[0].isreg = 1;
10364 inst.operands[0].writeback = 1;
10365 inst.operands[0].reg = REG_SP;
10366 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
10367 }
10368
10369 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
10370 word at the specified address and the following word
10371 respectively.
10372 Unconditionally executed.
10373 Error if Rn is R15. */
10374
10375 static void
10376 do_rfe (void)
10377 {
10378 inst.instruction |= inst.operands[0].reg << 16;
10379 if (inst.operands[0].writeback)
10380 inst.instruction |= WRITE_BACK;
10381 }
10382
10383 /* ARM V6 ssat (argument parse). */
10384
10385 static void
10386 do_ssat (void)
10387 {
10388 inst.instruction |= inst.operands[0].reg << 12;
10389 inst.instruction |= (inst.operands[1].imm - 1) << 16;
10390 inst.instruction |= inst.operands[2].reg;
10391
10392 if (inst.operands[3].present)
10393 encode_arm_shift (3);
10394 }
10395
10396 /* ARM V6 usat (argument parse). */
10397
10398 static void
10399 do_usat (void)
10400 {
10401 inst.instruction |= inst.operands[0].reg << 12;
10402 inst.instruction |= inst.operands[1].imm << 16;
10403 inst.instruction |= inst.operands[2].reg;
10404
10405 if (inst.operands[3].present)
10406 encode_arm_shift (3);
10407 }
10408
10409 /* ARM V6 ssat16 (argument parse). */
10410
10411 static void
10412 do_ssat16 (void)
10413 {
10414 inst.instruction |= inst.operands[0].reg << 12;
10415 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
10416 inst.instruction |= inst.operands[2].reg;
10417 }
10418
10419 static void
10420 do_usat16 (void)
10421 {
10422 inst.instruction |= inst.operands[0].reg << 12;
10423 inst.instruction |= inst.operands[1].imm << 16;
10424 inst.instruction |= inst.operands[2].reg;
10425 }
10426
10427 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
10428 preserving the other bits.
10429
10430 setend <endian_specifier>, where <endian_specifier> is either
10431 BE or LE. */
10432
10433 static void
10434 do_setend (void)
10435 {
10436 if (warn_on_deprecated
10437 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10438 as_tsktsk (_("setend use is deprecated for ARMv8"));
10439
10440 if (inst.operands[0].imm)
10441 inst.instruction |= 0x200;
10442 }
10443
10444 static void
10445 do_shift (void)
10446 {
10447 unsigned int Rm = (inst.operands[1].present
10448 ? inst.operands[1].reg
10449 : inst.operands[0].reg);
10450
10451 inst.instruction |= inst.operands[0].reg << 12;
10452 inst.instruction |= Rm;
10453 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
10454 {
10455 inst.instruction |= inst.operands[2].reg << 8;
10456 inst.instruction |= SHIFT_BY_REG;
10457 /* PR 12854: Error on extraneous shifts. */
10458 constraint (inst.operands[2].shifted,
10459 _("extraneous shift as part of operand to shift insn"));
10460 }
10461 else
10462 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
10463 }
10464
10465 static void
10466 do_smc (void)
10467 {
10468 unsigned int value = inst.relocs[0].exp.X_add_number;
10469 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
10470
10471 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
10472 inst.relocs[0].pc_rel = 0;
10473 }
10474
10475 static void
10476 do_hvc (void)
10477 {
10478 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
10479 inst.relocs[0].pc_rel = 0;
10480 }
10481
10482 static void
10483 do_swi (void)
10484 {
10485 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
10486 inst.relocs[0].pc_rel = 0;
10487 }
10488
10489 static void
10490 do_setpan (void)
10491 {
10492 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10493 _("selected processor does not support SETPAN instruction"));
10494
10495 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
10496 }
10497
10498 static void
10499 do_t_setpan (void)
10500 {
10501 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10502 _("selected processor does not support SETPAN instruction"));
10503
10504 inst.instruction |= (inst.operands[0].imm << 3);
10505 }
10506
10507 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
10508 SMLAxy{cond} Rd,Rm,Rs,Rn
10509 SMLAWy{cond} Rd,Rm,Rs,Rn
10510 Error if any register is R15. */
10511
10512 static void
10513 do_smla (void)
10514 {
10515 inst.instruction |= inst.operands[0].reg << 16;
10516 inst.instruction |= inst.operands[1].reg;
10517 inst.instruction |= inst.operands[2].reg << 8;
10518 inst.instruction |= inst.operands[3].reg << 12;
10519 }
10520
10521 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
10522 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
10523 Error if any register is R15.
10524 Warning if Rdlo == Rdhi. */
10525
10526 static void
10527 do_smlal (void)
10528 {
10529 inst.instruction |= inst.operands[0].reg << 12;
10530 inst.instruction |= inst.operands[1].reg << 16;
10531 inst.instruction |= inst.operands[2].reg;
10532 inst.instruction |= inst.operands[3].reg << 8;
10533
10534 if (inst.operands[0].reg == inst.operands[1].reg)
10535 as_tsktsk (_("rdhi and rdlo must be different"));
10536 }
10537
10538 /* ARM V5E (El Segundo) signed-multiply (argument parse)
10539 SMULxy{cond} Rd,Rm,Rs
10540 Error if any register is R15. */
10541
10542 static void
10543 do_smul (void)
10544 {
10545 inst.instruction |= inst.operands[0].reg << 16;
10546 inst.instruction |= inst.operands[1].reg;
10547 inst.instruction |= inst.operands[2].reg << 8;
10548 }
10549
10550 /* ARM V6 srs (argument parse). The variable fields in the encoding are
10551 the same for both ARM and Thumb-2. */
10552
10553 static void
10554 do_srs (void)
10555 {
10556 int reg;
10557
10558 if (inst.operands[0].present)
10559 {
10560 reg = inst.operands[0].reg;
10561 constraint (reg != REG_SP, _("SRS base register must be r13"));
10562 }
10563 else
10564 reg = REG_SP;
10565
10566 inst.instruction |= reg << 16;
10567 inst.instruction |= inst.operands[1].imm;
10568 if (inst.operands[0].writeback || inst.operands[1].writeback)
10569 inst.instruction |= WRITE_BACK;
10570 }
10571
10572 /* ARM V6 strex (argument parse). */
10573
10574 static void
10575 do_strex (void)
10576 {
10577 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10578 || inst.operands[2].postind || inst.operands[2].writeback
10579 || inst.operands[2].immisreg || inst.operands[2].shifted
10580 || inst.operands[2].negative
10581 /* See comment in do_ldrex(). */
10582 || (inst.operands[2].reg == REG_PC),
10583 BAD_ADDR_MODE);
10584
10585 constraint (inst.operands[0].reg == inst.operands[1].reg
10586 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10587
10588 constraint (inst.relocs[0].exp.X_op != O_constant
10589 || inst.relocs[0].exp.X_add_number != 0,
10590 _("offset must be zero in ARM encoding"));
10591
10592 inst.instruction |= inst.operands[0].reg << 12;
10593 inst.instruction |= inst.operands[1].reg;
10594 inst.instruction |= inst.operands[2].reg << 16;
10595 inst.relocs[0].type = BFD_RELOC_UNUSED;
10596 }
10597
10598 static void
10599 do_t_strexbh (void)
10600 {
10601 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10602 || inst.operands[2].postind || inst.operands[2].writeback
10603 || inst.operands[2].immisreg || inst.operands[2].shifted
10604 || inst.operands[2].negative,
10605 BAD_ADDR_MODE);
10606
10607 constraint (inst.operands[0].reg == inst.operands[1].reg
10608 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10609
10610 do_rm_rd_rn ();
10611 }
10612
10613 static void
10614 do_strexd (void)
10615 {
10616 constraint (inst.operands[1].reg % 2 != 0,
10617 _("even register required"));
10618 constraint (inst.operands[2].present
10619 && inst.operands[2].reg != inst.operands[1].reg + 1,
10620 _("can only store two consecutive registers"));
10621 /* If op 2 were present and equal to PC, this function wouldn't
10622 have been called in the first place. */
10623 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
10624
10625 constraint (inst.operands[0].reg == inst.operands[1].reg
10626 || inst.operands[0].reg == inst.operands[1].reg + 1
10627 || inst.operands[0].reg == inst.operands[3].reg,
10628 BAD_OVERLAP);
10629
10630 inst.instruction |= inst.operands[0].reg << 12;
10631 inst.instruction |= inst.operands[1].reg;
10632 inst.instruction |= inst.operands[3].reg << 16;
10633 }
10634
10635 /* ARM V8 STRL. */
10636 static void
10637 do_stlex (void)
10638 {
10639 constraint (inst.operands[0].reg == inst.operands[1].reg
10640 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10641
10642 do_rd_rm_rn ();
10643 }
10644
10645 static void
10646 do_t_stlex (void)
10647 {
10648 constraint (inst.operands[0].reg == inst.operands[1].reg
10649 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10650
10651 do_rm_rd_rn ();
10652 }
10653
10654 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10655 extends it to 32-bits, and adds the result to a value in another
10656 register. You can specify a rotation by 0, 8, 16, or 24 bits
10657 before extracting the 16-bit value.
10658 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10659 Condition defaults to COND_ALWAYS.
10660 Error if any register uses R15. */
10661
10662 static void
10663 do_sxtah (void)
10664 {
10665 inst.instruction |= inst.operands[0].reg << 12;
10666 inst.instruction |= inst.operands[1].reg << 16;
10667 inst.instruction |= inst.operands[2].reg;
10668 inst.instruction |= inst.operands[3].imm << 10;
10669 }
10670
10671 /* ARM V6 SXTH.
10672
10673 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10674 Condition defaults to COND_ALWAYS.
10675 Error if any register uses R15. */
10676
10677 static void
10678 do_sxth (void)
10679 {
10680 inst.instruction |= inst.operands[0].reg << 12;
10681 inst.instruction |= inst.operands[1].reg;
10682 inst.instruction |= inst.operands[2].imm << 10;
10683 }
10684 \f
10685 /* VFP instructions. In a logical order: SP variant first, monad
10686 before dyad, arithmetic then move then load/store. */
10687
10688 static void
10689 do_vfp_sp_monadic (void)
10690 {
10691 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10692 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10693 _(BAD_FPU));
10694
10695 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10696 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
10697 }
10698
10699 static void
10700 do_vfp_sp_dyadic (void)
10701 {
10702 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10703 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10704 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
10705 }
10706
10707 static void
10708 do_vfp_sp_compare_z (void)
10709 {
10710 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10711 }
10712
10713 static void
10714 do_vfp_dp_sp_cvt (void)
10715 {
10716 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10717 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
10718 }
10719
10720 static void
10721 do_vfp_sp_dp_cvt (void)
10722 {
10723 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10724 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10725 }
10726
10727 static void
10728 do_vfp_reg_from_sp (void)
10729 {
10730 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10731 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10732 _(BAD_FPU));
10733
10734 inst.instruction |= inst.operands[0].reg << 12;
10735 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10736 }
10737
10738 static void
10739 do_vfp_reg2_from_sp2 (void)
10740 {
10741 constraint (inst.operands[2].imm != 2,
10742 _("only two consecutive VFP SP registers allowed here"));
10743 inst.instruction |= inst.operands[0].reg << 12;
10744 inst.instruction |= inst.operands[1].reg << 16;
10745 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
10746 }
10747
10748 static void
10749 do_vfp_sp_from_reg (void)
10750 {
10751 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10752 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10753 _(BAD_FPU));
10754
10755 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
10756 inst.instruction |= inst.operands[1].reg << 12;
10757 }
10758
10759 static void
10760 do_vfp_sp2_from_reg2 (void)
10761 {
10762 constraint (inst.operands[0].imm != 2,
10763 _("only two consecutive VFP SP registers allowed here"));
10764 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
10765 inst.instruction |= inst.operands[1].reg << 12;
10766 inst.instruction |= inst.operands[2].reg << 16;
10767 }
10768
10769 static void
10770 do_vfp_sp_ldst (void)
10771 {
10772 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10773 encode_arm_cp_address (1, FALSE, TRUE, 0);
10774 }
10775
10776 static void
10777 do_vfp_dp_ldst (void)
10778 {
10779 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10780 encode_arm_cp_address (1, FALSE, TRUE, 0);
10781 }
10782
10783
10784 static void
10785 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
10786 {
10787 if (inst.operands[0].writeback)
10788 inst.instruction |= WRITE_BACK;
10789 else
10790 constraint (ldstm_type != VFP_LDSTMIA,
10791 _("this addressing mode requires base-register writeback"));
10792 inst.instruction |= inst.operands[0].reg << 16;
10793 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
10794 inst.instruction |= inst.operands[1].imm;
10795 }
10796
10797 static void
10798 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
10799 {
10800 int count;
10801
10802 if (inst.operands[0].writeback)
10803 inst.instruction |= WRITE_BACK;
10804 else
10805 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10806 _("this addressing mode requires base-register writeback"));
10807
10808 inst.instruction |= inst.operands[0].reg << 16;
10809 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10810
10811 count = inst.operands[1].imm << 1;
10812 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10813 count += 1;
10814
10815 inst.instruction |= count;
10816 }
10817
10818 static void
10819 do_vfp_sp_ldstmia (void)
10820 {
10821 vfp_sp_ldstm (VFP_LDSTMIA);
10822 }
10823
10824 static void
10825 do_vfp_sp_ldstmdb (void)
10826 {
10827 vfp_sp_ldstm (VFP_LDSTMDB);
10828 }
10829
10830 static void
10831 do_vfp_dp_ldstmia (void)
10832 {
10833 vfp_dp_ldstm (VFP_LDSTMIA);
10834 }
10835
10836 static void
10837 do_vfp_dp_ldstmdb (void)
10838 {
10839 vfp_dp_ldstm (VFP_LDSTMDB);
10840 }
10841
10842 static void
10843 do_vfp_xp_ldstmia (void)
10844 {
10845 vfp_dp_ldstm (VFP_LDSTMIAX);
10846 }
10847
10848 static void
10849 do_vfp_xp_ldstmdb (void)
10850 {
10851 vfp_dp_ldstm (VFP_LDSTMDBX);
10852 }
10853
10854 static void
10855 do_vfp_dp_rd_rm (void)
10856 {
10857 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
10858 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10859 _(BAD_FPU));
10860
10861 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10862 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10863 }
10864
10865 static void
10866 do_vfp_dp_rn_rd (void)
10867 {
10868 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10869 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10870 }
10871
10872 static void
10873 do_vfp_dp_rd_rn (void)
10874 {
10875 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10876 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10877 }
10878
10879 static void
10880 do_vfp_dp_rd_rn_rm (void)
10881 {
10882 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10883 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10884 _(BAD_FPU));
10885
10886 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10887 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10888 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10889 }
10890
10891 static void
10892 do_vfp_dp_rd (void)
10893 {
10894 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10895 }
10896
10897 static void
10898 do_vfp_dp_rm_rd_rn (void)
10899 {
10900 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10901 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10902 _(BAD_FPU));
10903
10904 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10905 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10906 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10907 }
10908
10909 /* VFPv3 instructions. */
10910 static void
10911 do_vfp_sp_const (void)
10912 {
10913 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10914 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10915 inst.instruction |= (inst.operands[1].imm & 0x0f);
10916 }
10917
10918 static void
10919 do_vfp_dp_const (void)
10920 {
10921 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10922 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10923 inst.instruction |= (inst.operands[1].imm & 0x0f);
10924 }
10925
10926 static void
10927 vfp_conv (int srcsize)
10928 {
10929 int immbits = srcsize - inst.operands[1].imm;
10930
10931 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10932 {
10933 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
10934 i.e. immbits must be in range 0 - 16. */
10935 inst.error = _("immediate value out of range, expected range [0, 16]");
10936 return;
10937 }
10938 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
10939 {
10940 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
10941 i.e. immbits must be in range 0 - 31. */
10942 inst.error = _("immediate value out of range, expected range [1, 32]");
10943 return;
10944 }
10945
10946 inst.instruction |= (immbits & 1) << 5;
10947 inst.instruction |= (immbits >> 1);
10948 }
10949
10950 static void
10951 do_vfp_sp_conv_16 (void)
10952 {
10953 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10954 vfp_conv (16);
10955 }
10956
10957 static void
10958 do_vfp_dp_conv_16 (void)
10959 {
10960 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10961 vfp_conv (16);
10962 }
10963
10964 static void
10965 do_vfp_sp_conv_32 (void)
10966 {
10967 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10968 vfp_conv (32);
10969 }
10970
10971 static void
10972 do_vfp_dp_conv_32 (void)
10973 {
10974 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10975 vfp_conv (32);
10976 }
10977 \f
10978 /* FPA instructions. Also in a logical order. */
10979
10980 static void
10981 do_fpa_cmp (void)
10982 {
10983 inst.instruction |= inst.operands[0].reg << 16;
10984 inst.instruction |= inst.operands[1].reg;
10985 }
10986
10987 static void
10988 do_fpa_ldmstm (void)
10989 {
10990 inst.instruction |= inst.operands[0].reg << 12;
10991 switch (inst.operands[1].imm)
10992 {
10993 case 1: inst.instruction |= CP_T_X; break;
10994 case 2: inst.instruction |= CP_T_Y; break;
10995 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10996 case 4: break;
10997 default: abort ();
10998 }
10999
11000 if (inst.instruction & (PRE_INDEX | INDEX_UP))
11001 {
11002 /* The instruction specified "ea" or "fd", so we can only accept
11003 [Rn]{!}. The instruction does not really support stacking or
11004 unstacking, so we have to emulate these by setting appropriate
11005 bits and offsets. */
11006 constraint (inst.relocs[0].exp.X_op != O_constant
11007 || inst.relocs[0].exp.X_add_number != 0,
11008 _("this instruction does not support indexing"));
11009
11010 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
11011 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
11012
11013 if (!(inst.instruction & INDEX_UP))
11014 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
11015
11016 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
11017 {
11018 inst.operands[2].preind = 0;
11019 inst.operands[2].postind = 1;
11020 }
11021 }
11022
11023 encode_arm_cp_address (2, TRUE, TRUE, 0);
11024 }
11025 \f
11026 /* iWMMXt instructions: strictly in alphabetical order. */
11027
11028 static void
11029 do_iwmmxt_tandorc (void)
11030 {
11031 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
11032 }
11033
11034 static void
11035 do_iwmmxt_textrc (void)
11036 {
11037 inst.instruction |= inst.operands[0].reg << 12;
11038 inst.instruction |= inst.operands[1].imm;
11039 }
11040
11041 static void
11042 do_iwmmxt_textrm (void)
11043 {
11044 inst.instruction |= inst.operands[0].reg << 12;
11045 inst.instruction |= inst.operands[1].reg << 16;
11046 inst.instruction |= inst.operands[2].imm;
11047 }
11048
11049 static void
11050 do_iwmmxt_tinsr (void)
11051 {
11052 inst.instruction |= inst.operands[0].reg << 16;
11053 inst.instruction |= inst.operands[1].reg << 12;
11054 inst.instruction |= inst.operands[2].imm;
11055 }
11056
11057 static void
11058 do_iwmmxt_tmia (void)
11059 {
11060 inst.instruction |= inst.operands[0].reg << 5;
11061 inst.instruction |= inst.operands[1].reg;
11062 inst.instruction |= inst.operands[2].reg << 12;
11063 }
11064
11065 static void
11066 do_iwmmxt_waligni (void)
11067 {
11068 inst.instruction |= inst.operands[0].reg << 12;
11069 inst.instruction |= inst.operands[1].reg << 16;
11070 inst.instruction |= inst.operands[2].reg;
11071 inst.instruction |= inst.operands[3].imm << 20;
11072 }
11073
11074 static void
11075 do_iwmmxt_wmerge (void)
11076 {
11077 inst.instruction |= inst.operands[0].reg << 12;
11078 inst.instruction |= inst.operands[1].reg << 16;
11079 inst.instruction |= inst.operands[2].reg;
11080 inst.instruction |= inst.operands[3].imm << 21;
11081 }
11082
11083 static void
11084 do_iwmmxt_wmov (void)
11085 {
11086 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
11087 inst.instruction |= inst.operands[0].reg << 12;
11088 inst.instruction |= inst.operands[1].reg << 16;
11089 inst.instruction |= inst.operands[1].reg;
11090 }
11091
11092 static void
11093 do_iwmmxt_wldstbh (void)
11094 {
11095 int reloc;
11096 inst.instruction |= inst.operands[0].reg << 12;
11097 if (thumb_mode)
11098 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
11099 else
11100 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
11101 encode_arm_cp_address (1, TRUE, FALSE, reloc);
11102 }
11103
11104 static void
11105 do_iwmmxt_wldstw (void)
11106 {
11107 /* RIWR_RIWC clears .isreg for a control register. */
11108 if (!inst.operands[0].isreg)
11109 {
11110 constraint (inst.cond != COND_ALWAYS, BAD_COND);
11111 inst.instruction |= 0xf0000000;
11112 }
11113
11114 inst.instruction |= inst.operands[0].reg << 12;
11115 encode_arm_cp_address (1, TRUE, TRUE, 0);
11116 }
11117
11118 static void
11119 do_iwmmxt_wldstd (void)
11120 {
11121 inst.instruction |= inst.operands[0].reg << 12;
11122 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
11123 && inst.operands[1].immisreg)
11124 {
11125 inst.instruction &= ~0x1a000ff;
11126 inst.instruction |= (0xfU << 28);
11127 if (inst.operands[1].preind)
11128 inst.instruction |= PRE_INDEX;
11129 if (!inst.operands[1].negative)
11130 inst.instruction |= INDEX_UP;
11131 if (inst.operands[1].writeback)
11132 inst.instruction |= WRITE_BACK;
11133 inst.instruction |= inst.operands[1].reg << 16;
11134 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
11135 inst.instruction |= inst.operands[1].imm;
11136 }
11137 else
11138 encode_arm_cp_address (1, TRUE, FALSE, 0);
11139 }
11140
11141 static void
11142 do_iwmmxt_wshufh (void)
11143 {
11144 inst.instruction |= inst.operands[0].reg << 12;
11145 inst.instruction |= inst.operands[1].reg << 16;
11146 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
11147 inst.instruction |= (inst.operands[2].imm & 0x0f);
11148 }
11149
11150 static void
11151 do_iwmmxt_wzero (void)
11152 {
11153 /* WZERO reg is an alias for WANDN reg, reg, reg. */
11154 inst.instruction |= inst.operands[0].reg;
11155 inst.instruction |= inst.operands[0].reg << 12;
11156 inst.instruction |= inst.operands[0].reg << 16;
11157 }
11158
11159 static void
11160 do_iwmmxt_wrwrwr_or_imm5 (void)
11161 {
11162 if (inst.operands[2].isreg)
11163 do_rd_rn_rm ();
11164 else {
11165 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
11166 _("immediate operand requires iWMMXt2"));
11167 do_rd_rn ();
11168 if (inst.operands[2].imm == 0)
11169 {
11170 switch ((inst.instruction >> 20) & 0xf)
11171 {
11172 case 4:
11173 case 5:
11174 case 6:
11175 case 7:
11176 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
11177 inst.operands[2].imm = 16;
11178 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
11179 break;
11180 case 8:
11181 case 9:
11182 case 10:
11183 case 11:
11184 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
11185 inst.operands[2].imm = 32;
11186 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
11187 break;
11188 case 12:
11189 case 13:
11190 case 14:
11191 case 15:
11192 {
11193 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
11194 unsigned long wrn;
11195 wrn = (inst.instruction >> 16) & 0xf;
11196 inst.instruction &= 0xff0fff0f;
11197 inst.instruction |= wrn;
11198 /* Bail out here; the instruction is now assembled. */
11199 return;
11200 }
11201 }
11202 }
11203 /* Map 32 -> 0, etc. */
11204 inst.operands[2].imm &= 0x1f;
11205 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
11206 }
11207 }
11208 \f
11209 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
11210 operations first, then control, shift, and load/store. */
11211
11212 /* Insns like "foo X,Y,Z". */
11213
11214 static void
11215 do_mav_triple (void)
11216 {
11217 inst.instruction |= inst.operands[0].reg << 16;
11218 inst.instruction |= inst.operands[1].reg;
11219 inst.instruction |= inst.operands[2].reg << 12;
11220 }
11221
11222 /* Insns like "foo W,X,Y,Z".
11223 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
11224
11225 static void
11226 do_mav_quad (void)
11227 {
11228 inst.instruction |= inst.operands[0].reg << 5;
11229 inst.instruction |= inst.operands[1].reg << 12;
11230 inst.instruction |= inst.operands[2].reg << 16;
11231 inst.instruction |= inst.operands[3].reg;
11232 }
11233
11234 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
11235 static void
11236 do_mav_dspsc (void)
11237 {
11238 inst.instruction |= inst.operands[1].reg << 12;
11239 }
11240
11241 /* Maverick shift immediate instructions.
11242 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
11243 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
11244
11245 static void
11246 do_mav_shift (void)
11247 {
11248 int imm = inst.operands[2].imm;
11249
11250 inst.instruction |= inst.operands[0].reg << 12;
11251 inst.instruction |= inst.operands[1].reg << 16;
11252
11253 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
11254 Bits 5-7 of the insn should have bits 4-6 of the immediate.
11255 Bit 4 should be 0. */
11256 imm = (imm & 0xf) | ((imm & 0x70) << 1);
11257
11258 inst.instruction |= imm;
11259 }
11260 \f
11261 /* XScale instructions. Also sorted arithmetic before move. */
11262
11263 /* Xscale multiply-accumulate (argument parse)
11264 MIAcc acc0,Rm,Rs
11265 MIAPHcc acc0,Rm,Rs
11266 MIAxycc acc0,Rm,Rs. */
11267
11268 static void
11269 do_xsc_mia (void)
11270 {
11271 inst.instruction |= inst.operands[1].reg;
11272 inst.instruction |= inst.operands[2].reg << 12;
11273 }
11274
11275 /* Xscale move-accumulator-register (argument parse)
11276
11277 MARcc acc0,RdLo,RdHi. */
11278
11279 static void
11280 do_xsc_mar (void)
11281 {
11282 inst.instruction |= inst.operands[1].reg << 12;
11283 inst.instruction |= inst.operands[2].reg << 16;
11284 }
11285
11286 /* Xscale move-register-accumulator (argument parse)
11287
11288 MRAcc RdLo,RdHi,acc0. */
11289
11290 static void
11291 do_xsc_mra (void)
11292 {
11293 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
11294 inst.instruction |= inst.operands[0].reg << 12;
11295 inst.instruction |= inst.operands[1].reg << 16;
11296 }
11297 \f
11298 /* Encoding functions relevant only to Thumb. */
11299
11300 /* inst.operands[i] is a shifted-register operand; encode
11301 it into inst.instruction in the format used by Thumb32. */
11302
11303 static void
11304 encode_thumb32_shifted_operand (int i)
11305 {
11306 unsigned int value = inst.relocs[0].exp.X_add_number;
11307 unsigned int shift = inst.operands[i].shift_kind;
11308
11309 constraint (inst.operands[i].immisreg,
11310 _("shift by register not allowed in thumb mode"));
11311 inst.instruction |= inst.operands[i].reg;
11312 if (shift == SHIFT_RRX)
11313 inst.instruction |= SHIFT_ROR << 4;
11314 else
11315 {
11316 constraint (inst.relocs[0].exp.X_op != O_constant,
11317 _("expression too complex"));
11318
11319 constraint (value > 32
11320 || (value == 32 && (shift == SHIFT_LSL
11321 || shift == SHIFT_ROR)),
11322 _("shift expression is too large"));
11323
11324 if (value == 0)
11325 shift = SHIFT_LSL;
11326 else if (value == 32)
11327 value = 0;
11328
11329 inst.instruction |= shift << 4;
11330 inst.instruction |= (value & 0x1c) << 10;
11331 inst.instruction |= (value & 0x03) << 6;
11332 }
11333 }
11334
11335
11336 /* inst.operands[i] was set up by parse_address. Encode it into a
11337 Thumb32 format load or store instruction. Reject forms that cannot
11338 be used with such instructions. If is_t is true, reject forms that
11339 cannot be used with a T instruction; if is_d is true, reject forms
11340 that cannot be used with a D instruction. If it is a store insn,
11341 reject PC in Rn. */
11342
11343 static void
11344 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
11345 {
11346 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
11347
11348 constraint (!inst.operands[i].isreg,
11349 _("Instruction does not support =N addresses"));
11350
11351 inst.instruction |= inst.operands[i].reg << 16;
11352 if (inst.operands[i].immisreg)
11353 {
11354 constraint (is_pc, BAD_PC_ADDRESSING);
11355 constraint (is_t || is_d, _("cannot use register index with this instruction"));
11356 constraint (inst.operands[i].negative,
11357 _("Thumb does not support negative register indexing"));
11358 constraint (inst.operands[i].postind,
11359 _("Thumb does not support register post-indexing"));
11360 constraint (inst.operands[i].writeback,
11361 _("Thumb does not support register indexing with writeback"));
11362 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
11363 _("Thumb supports only LSL in shifted register indexing"));
11364
11365 inst.instruction |= inst.operands[i].imm;
11366 if (inst.operands[i].shifted)
11367 {
11368 constraint (inst.relocs[0].exp.X_op != O_constant,
11369 _("expression too complex"));
11370 constraint (inst.relocs[0].exp.X_add_number < 0
11371 || inst.relocs[0].exp.X_add_number > 3,
11372 _("shift out of range"));
11373 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
11374 }
11375 inst.relocs[0].type = BFD_RELOC_UNUSED;
11376 }
11377 else if (inst.operands[i].preind)
11378 {
11379 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
11380 constraint (is_t && inst.operands[i].writeback,
11381 _("cannot use writeback with this instruction"));
11382 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
11383 BAD_PC_ADDRESSING);
11384
11385 if (is_d)
11386 {
11387 inst.instruction |= 0x01000000;
11388 if (inst.operands[i].writeback)
11389 inst.instruction |= 0x00200000;
11390 }
11391 else
11392 {
11393 inst.instruction |= 0x00000c00;
11394 if (inst.operands[i].writeback)
11395 inst.instruction |= 0x00000100;
11396 }
11397 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
11398 }
11399 else if (inst.operands[i].postind)
11400 {
11401 gas_assert (inst.operands[i].writeback);
11402 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
11403 constraint (is_t, _("cannot use post-indexing with this instruction"));
11404
11405 if (is_d)
11406 inst.instruction |= 0x00200000;
11407 else
11408 inst.instruction |= 0x00000900;
11409 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
11410 }
11411 else /* unindexed - only for coprocessor */
11412 inst.error = _("instruction does not accept unindexed addressing");
11413 }
11414
11415 /* Table of Thumb instructions which exist in 16- and/or 32-bit
11416 encodings (the latter only in post-V6T2 cores). The index is the
11417 value used in the insns table below. When there is more than one
11418 possible 16-bit encoding for the instruction, this table always
11419 holds variant (1).
11420 Also contains several pseudo-instructions used during relaxation. */
11421 #define T16_32_TAB \
11422 X(_adc, 4140, eb400000), \
11423 X(_adcs, 4140, eb500000), \
11424 X(_add, 1c00, eb000000), \
11425 X(_adds, 1c00, eb100000), \
11426 X(_addi, 0000, f1000000), \
11427 X(_addis, 0000, f1100000), \
11428 X(_add_pc,000f, f20f0000), \
11429 X(_add_sp,000d, f10d0000), \
11430 X(_adr, 000f, f20f0000), \
11431 X(_and, 4000, ea000000), \
11432 X(_ands, 4000, ea100000), \
11433 X(_asr, 1000, fa40f000), \
11434 X(_asrs, 1000, fa50f000), \
11435 X(_b, e000, f000b000), \
11436 X(_bcond, d000, f0008000), \
11437 X(_bf, 0000, f040e001), \
11438 X(_bfcsel,0000, f000e001), \
11439 X(_bfx, 0000, f060e001), \
11440 X(_bfl, 0000, f000c001), \
11441 X(_bflx, 0000, f070e001), \
11442 X(_bic, 4380, ea200000), \
11443 X(_bics, 4380, ea300000), \
11444 X(_cinc, 0000, ea509000), \
11445 X(_cinv, 0000, ea50a000), \
11446 X(_cmn, 42c0, eb100f00), \
11447 X(_cmp, 2800, ebb00f00), \
11448 X(_cneg, 0000, ea50b000), \
11449 X(_cpsie, b660, f3af8400), \
11450 X(_cpsid, b670, f3af8600), \
11451 X(_cpy, 4600, ea4f0000), \
11452 X(_csel, 0000, ea508000), \
11453 X(_cset, 0000, ea5f900f), \
11454 X(_csetm, 0000, ea5fa00f), \
11455 X(_csinc, 0000, ea509000), \
11456 X(_csinv, 0000, ea50a000), \
11457 X(_csneg, 0000, ea50b000), \
11458 X(_dec_sp,80dd, f1ad0d00), \
11459 X(_dls, 0000, f040e001), \
11460 X(_dlstp, 0000, f000e001), \
11461 X(_eor, 4040, ea800000), \
11462 X(_eors, 4040, ea900000), \
11463 X(_inc_sp,00dd, f10d0d00), \
11464 X(_lctp, 0000, f00fe001), \
11465 X(_ldmia, c800, e8900000), \
11466 X(_ldr, 6800, f8500000), \
11467 X(_ldrb, 7800, f8100000), \
11468 X(_ldrh, 8800, f8300000), \
11469 X(_ldrsb, 5600, f9100000), \
11470 X(_ldrsh, 5e00, f9300000), \
11471 X(_ldr_pc,4800, f85f0000), \
11472 X(_ldr_pc2,4800, f85f0000), \
11473 X(_ldr_sp,9800, f85d0000), \
11474 X(_le, 0000, f00fc001), \
11475 X(_letp, 0000, f01fc001), \
11476 X(_lsl, 0000, fa00f000), \
11477 X(_lsls, 0000, fa10f000), \
11478 X(_lsr, 0800, fa20f000), \
11479 X(_lsrs, 0800, fa30f000), \
11480 X(_mov, 2000, ea4f0000), \
11481 X(_movs, 2000, ea5f0000), \
11482 X(_mul, 4340, fb00f000), \
11483 X(_muls, 4340, ffffffff), /* no 32b muls */ \
11484 X(_mvn, 43c0, ea6f0000), \
11485 X(_mvns, 43c0, ea7f0000), \
11486 X(_neg, 4240, f1c00000), /* rsb #0 */ \
11487 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
11488 X(_orr, 4300, ea400000), \
11489 X(_orrs, 4300, ea500000), \
11490 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
11491 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
11492 X(_rev, ba00, fa90f080), \
11493 X(_rev16, ba40, fa90f090), \
11494 X(_revsh, bac0, fa90f0b0), \
11495 X(_ror, 41c0, fa60f000), \
11496 X(_rors, 41c0, fa70f000), \
11497 X(_sbc, 4180, eb600000), \
11498 X(_sbcs, 4180, eb700000), \
11499 X(_stmia, c000, e8800000), \
11500 X(_str, 6000, f8400000), \
11501 X(_strb, 7000, f8000000), \
11502 X(_strh, 8000, f8200000), \
11503 X(_str_sp,9000, f84d0000), \
11504 X(_sub, 1e00, eba00000), \
11505 X(_subs, 1e00, ebb00000), \
11506 X(_subi, 8000, f1a00000), \
11507 X(_subis, 8000, f1b00000), \
11508 X(_sxtb, b240, fa4ff080), \
11509 X(_sxth, b200, fa0ff080), \
11510 X(_tst, 4200, ea100f00), \
11511 X(_uxtb, b2c0, fa5ff080), \
11512 X(_uxth, b280, fa1ff080), \
11513 X(_nop, bf00, f3af8000), \
11514 X(_yield, bf10, f3af8001), \
11515 X(_wfe, bf20, f3af8002), \
11516 X(_wfi, bf30, f3af8003), \
11517 X(_wls, 0000, f040c001), \
11518 X(_wlstp, 0000, f000c001), \
11519 X(_sev, bf40, f3af8004), \
11520 X(_sevl, bf50, f3af8005), \
11521 X(_udf, de00, f7f0a000)
11522
11523 /* To catch errors in encoding functions, the codes are all offset by
11524 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
11525 as 16-bit instructions. */
11526 #define X(a,b,c) T_MNEM##a
11527 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
11528 #undef X
11529
11530 #define X(a,b,c) 0x##b
11531 static const unsigned short thumb_op16[] = { T16_32_TAB };
11532 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
11533 #undef X
11534
11535 #define X(a,b,c) 0x##c
11536 static const unsigned int thumb_op32[] = { T16_32_TAB };
11537 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
11538 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
11539 #undef X
11540 #undef T16_32_TAB
11541
11542 /* Thumb instruction encoders, in alphabetical order. */
11543
11544 /* ADDW or SUBW. */
11545
11546 static void
11547 do_t_add_sub_w (void)
11548 {
11549 int Rd, Rn;
11550
11551 Rd = inst.operands[0].reg;
11552 Rn = inst.operands[1].reg;
11553
11554 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
11555 is the SP-{plus,minus}-immediate form of the instruction. */
11556 if (Rn == REG_SP)
11557 constraint (Rd == REG_PC, BAD_PC);
11558 else
11559 reject_bad_reg (Rd);
11560
11561 inst.instruction |= (Rn << 16) | (Rd << 8);
11562 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
11563 }
11564
11565 /* Parse an add or subtract instruction. We get here with inst.instruction
11566 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
11567
11568 static void
11569 do_t_add_sub (void)
11570 {
11571 int Rd, Rs, Rn;
11572
11573 Rd = inst.operands[0].reg;
11574 Rs = (inst.operands[1].present
11575 ? inst.operands[1].reg /* Rd, Rs, foo */
11576 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11577
11578 if (Rd == REG_PC)
11579 set_pred_insn_type_last ();
11580
11581 if (unified_syntax)
11582 {
11583 bfd_boolean flags;
11584 bfd_boolean narrow;
11585 int opcode;
11586
11587 flags = (inst.instruction == T_MNEM_adds
11588 || inst.instruction == T_MNEM_subs);
11589 if (flags)
11590 narrow = !in_pred_block ();
11591 else
11592 narrow = in_pred_block ();
11593 if (!inst.operands[2].isreg)
11594 {
11595 int add;
11596
11597 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11598 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
11599
11600 add = (inst.instruction == T_MNEM_add
11601 || inst.instruction == T_MNEM_adds);
11602 opcode = 0;
11603 if (inst.size_req != 4)
11604 {
11605 /* Attempt to use a narrow opcode, with relaxation if
11606 appropriate. */
11607 if (Rd == REG_SP && Rs == REG_SP && !flags)
11608 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
11609 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
11610 opcode = T_MNEM_add_sp;
11611 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
11612 opcode = T_MNEM_add_pc;
11613 else if (Rd <= 7 && Rs <= 7 && narrow)
11614 {
11615 if (flags)
11616 opcode = add ? T_MNEM_addis : T_MNEM_subis;
11617 else
11618 opcode = add ? T_MNEM_addi : T_MNEM_subi;
11619 }
11620 if (opcode)
11621 {
11622 inst.instruction = THUMB_OP16(opcode);
11623 inst.instruction |= (Rd << 4) | Rs;
11624 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11625 || (inst.relocs[0].type
11626 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
11627 {
11628 if (inst.size_req == 2)
11629 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11630 else
11631 inst.relax = opcode;
11632 }
11633 }
11634 else
11635 constraint (inst.size_req == 2, BAD_HIREG);
11636 }
11637 if (inst.size_req == 4
11638 || (inst.size_req != 2 && !opcode))
11639 {
11640 constraint ((inst.relocs[0].type
11641 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
11642 && (inst.relocs[0].type
11643 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
11644 THUMB1_RELOC_ONLY);
11645 if (Rd == REG_PC)
11646 {
11647 constraint (add, BAD_PC);
11648 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
11649 _("only SUBS PC, LR, #const allowed"));
11650 constraint (inst.relocs[0].exp.X_op != O_constant,
11651 _("expression too complex"));
11652 constraint (inst.relocs[0].exp.X_add_number < 0
11653 || inst.relocs[0].exp.X_add_number > 0xff,
11654 _("immediate value out of range"));
11655 inst.instruction = T2_SUBS_PC_LR
11656 | inst.relocs[0].exp.X_add_number;
11657 inst.relocs[0].type = BFD_RELOC_UNUSED;
11658 return;
11659 }
11660 else if (Rs == REG_PC)
11661 {
11662 /* Always use addw/subw. */
11663 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
11664 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
11665 }
11666 else
11667 {
11668 inst.instruction = THUMB_OP32 (inst.instruction);
11669 inst.instruction = (inst.instruction & 0xe1ffffff)
11670 | 0x10000000;
11671 if (flags)
11672 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11673 else
11674 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
11675 }
11676 inst.instruction |= Rd << 8;
11677 inst.instruction |= Rs << 16;
11678 }
11679 }
11680 else
11681 {
11682 unsigned int value = inst.relocs[0].exp.X_add_number;
11683 unsigned int shift = inst.operands[2].shift_kind;
11684
11685 Rn = inst.operands[2].reg;
11686 /* See if we can do this with a 16-bit instruction. */
11687 if (!inst.operands[2].shifted && inst.size_req != 4)
11688 {
11689 if (Rd > 7 || Rs > 7 || Rn > 7)
11690 narrow = FALSE;
11691
11692 if (narrow)
11693 {
11694 inst.instruction = ((inst.instruction == T_MNEM_adds
11695 || inst.instruction == T_MNEM_add)
11696 ? T_OPCODE_ADD_R3
11697 : T_OPCODE_SUB_R3);
11698 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11699 return;
11700 }
11701
11702 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
11703 {
11704 /* Thumb-1 cores (except v6-M) require at least one high
11705 register in a narrow non flag setting add. */
11706 if (Rd > 7 || Rn > 7
11707 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11708 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
11709 {
11710 if (Rd == Rn)
11711 {
11712 Rn = Rs;
11713 Rs = Rd;
11714 }
11715 inst.instruction = T_OPCODE_ADD_HI;
11716 inst.instruction |= (Rd & 8) << 4;
11717 inst.instruction |= (Rd & 7);
11718 inst.instruction |= Rn << 3;
11719 return;
11720 }
11721 }
11722 }
11723
11724 constraint (Rd == REG_PC, BAD_PC);
11725 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11726 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
11727 constraint (Rs == REG_PC, BAD_PC);
11728 reject_bad_reg (Rn);
11729
11730 /* If we get here, it can't be done in 16 bits. */
11731 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11732 _("shift must be constant"));
11733 inst.instruction = THUMB_OP32 (inst.instruction);
11734 inst.instruction |= Rd << 8;
11735 inst.instruction |= Rs << 16;
11736 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11737 _("shift value over 3 not allowed in thumb mode"));
11738 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11739 _("only LSL shift allowed in thumb mode"));
11740 encode_thumb32_shifted_operand (2);
11741 }
11742 }
11743 else
11744 {
11745 constraint (inst.instruction == T_MNEM_adds
11746 || inst.instruction == T_MNEM_subs,
11747 BAD_THUMB32);
11748
11749 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
11750 {
11751 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11752 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11753 BAD_HIREG);
11754
11755 inst.instruction = (inst.instruction == T_MNEM_add
11756 ? 0x0000 : 0x8000);
11757 inst.instruction |= (Rd << 4) | Rs;
11758 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11759 return;
11760 }
11761
11762 Rn = inst.operands[2].reg;
11763 constraint (inst.operands[2].shifted, _("unshifted register required"));
11764
11765 /* We now have Rd, Rs, and Rn set to registers. */
11766 if (Rd > 7 || Rs > 7 || Rn > 7)
11767 {
11768 /* Can't do this for SUB. */
11769 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11770 inst.instruction = T_OPCODE_ADD_HI;
11771 inst.instruction |= (Rd & 8) << 4;
11772 inst.instruction |= (Rd & 7);
11773 if (Rs == Rd)
11774 inst.instruction |= Rn << 3;
11775 else if (Rn == Rd)
11776 inst.instruction |= Rs << 3;
11777 else
11778 constraint (1, _("dest must overlap one source register"));
11779 }
11780 else
11781 {
11782 inst.instruction = (inst.instruction == T_MNEM_add
11783 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11784 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11785 }
11786 }
11787 }
11788
11789 static void
11790 do_t_adr (void)
11791 {
11792 unsigned Rd;
11793
11794 Rd = inst.operands[0].reg;
11795 reject_bad_reg (Rd);
11796
11797 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
11798 {
11799 /* Defer to section relaxation. */
11800 inst.relax = inst.instruction;
11801 inst.instruction = THUMB_OP16 (inst.instruction);
11802 inst.instruction |= Rd << 4;
11803 }
11804 else if (unified_syntax && inst.size_req != 2)
11805 {
11806 /* Generate a 32-bit opcode. */
11807 inst.instruction = THUMB_OP32 (inst.instruction);
11808 inst.instruction |= Rd << 8;
11809 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11810 inst.relocs[0].pc_rel = 1;
11811 }
11812 else
11813 {
11814 /* Generate a 16-bit opcode. */
11815 inst.instruction = THUMB_OP16 (inst.instruction);
11816 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11817 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11818 inst.relocs[0].pc_rel = 1;
11819 inst.instruction |= Rd << 4;
11820 }
11821
11822 if (inst.relocs[0].exp.X_op == O_symbol
11823 && inst.relocs[0].exp.X_add_symbol != NULL
11824 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11825 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11826 inst.relocs[0].exp.X_add_number += 1;
11827 }
11828
11829 /* Arithmetic instructions for which there is just one 16-bit
11830 instruction encoding, and it allows only two low registers.
11831 For maximal compatibility with ARM syntax, we allow three register
11832 operands even when Thumb-32 instructions are not available, as long
11833 as the first two are identical. For instance, both "sbc r0,r1" and
11834 "sbc r0,r0,r1" are allowed. */
11835 static void
11836 do_t_arit3 (void)
11837 {
11838 int Rd, Rs, Rn;
11839
11840 Rd = inst.operands[0].reg;
11841 Rs = (inst.operands[1].present
11842 ? inst.operands[1].reg /* Rd, Rs, foo */
11843 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11844 Rn = inst.operands[2].reg;
11845
11846 reject_bad_reg (Rd);
11847 reject_bad_reg (Rs);
11848 if (inst.operands[2].isreg)
11849 reject_bad_reg (Rn);
11850
11851 if (unified_syntax)
11852 {
11853 if (!inst.operands[2].isreg)
11854 {
11855 /* For an immediate, we always generate a 32-bit opcode;
11856 section relaxation will shrink it later if possible. */
11857 inst.instruction = THUMB_OP32 (inst.instruction);
11858 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11859 inst.instruction |= Rd << 8;
11860 inst.instruction |= Rs << 16;
11861 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11862 }
11863 else
11864 {
11865 bfd_boolean narrow;
11866
11867 /* See if we can do this with a 16-bit instruction. */
11868 if (THUMB_SETS_FLAGS (inst.instruction))
11869 narrow = !in_pred_block ();
11870 else
11871 narrow = in_pred_block ();
11872
11873 if (Rd > 7 || Rn > 7 || Rs > 7)
11874 narrow = FALSE;
11875 if (inst.operands[2].shifted)
11876 narrow = FALSE;
11877 if (inst.size_req == 4)
11878 narrow = FALSE;
11879
11880 if (narrow
11881 && Rd == Rs)
11882 {
11883 inst.instruction = THUMB_OP16 (inst.instruction);
11884 inst.instruction |= Rd;
11885 inst.instruction |= Rn << 3;
11886 return;
11887 }
11888
11889 /* If we get here, it can't be done in 16 bits. */
11890 constraint (inst.operands[2].shifted
11891 && inst.operands[2].immisreg,
11892 _("shift must be constant"));
11893 inst.instruction = THUMB_OP32 (inst.instruction);
11894 inst.instruction |= Rd << 8;
11895 inst.instruction |= Rs << 16;
11896 encode_thumb32_shifted_operand (2);
11897 }
11898 }
11899 else
11900 {
11901 /* On its face this is a lie - the instruction does set the
11902 flags. However, the only supported mnemonic in this mode
11903 says it doesn't. */
11904 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11905
11906 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11907 _("unshifted register required"));
11908 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11909 constraint (Rd != Rs,
11910 _("dest and source1 must be the same register"));
11911
11912 inst.instruction = THUMB_OP16 (inst.instruction);
11913 inst.instruction |= Rd;
11914 inst.instruction |= Rn << 3;
11915 }
11916 }
11917
11918 /* Similarly, but for instructions where the arithmetic operation is
11919 commutative, so we can allow either of them to be different from
11920 the destination operand in a 16-bit instruction. For instance, all
11921 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11922 accepted. */
11923 static void
11924 do_t_arit3c (void)
11925 {
11926 int Rd, Rs, Rn;
11927
11928 Rd = inst.operands[0].reg;
11929 Rs = (inst.operands[1].present
11930 ? inst.operands[1].reg /* Rd, Rs, foo */
11931 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11932 Rn = inst.operands[2].reg;
11933
11934 reject_bad_reg (Rd);
11935 reject_bad_reg (Rs);
11936 if (inst.operands[2].isreg)
11937 reject_bad_reg (Rn);
11938
11939 if (unified_syntax)
11940 {
11941 if (!inst.operands[2].isreg)
11942 {
11943 /* For an immediate, we always generate a 32-bit opcode;
11944 section relaxation will shrink it later if possible. */
11945 inst.instruction = THUMB_OP32 (inst.instruction);
11946 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11947 inst.instruction |= Rd << 8;
11948 inst.instruction |= Rs << 16;
11949 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11950 }
11951 else
11952 {
11953 bfd_boolean narrow;
11954
11955 /* See if we can do this with a 16-bit instruction. */
11956 if (THUMB_SETS_FLAGS (inst.instruction))
11957 narrow = !in_pred_block ();
11958 else
11959 narrow = in_pred_block ();
11960
11961 if (Rd > 7 || Rn > 7 || Rs > 7)
11962 narrow = FALSE;
11963 if (inst.operands[2].shifted)
11964 narrow = FALSE;
11965 if (inst.size_req == 4)
11966 narrow = FALSE;
11967
11968 if (narrow)
11969 {
11970 if (Rd == Rs)
11971 {
11972 inst.instruction = THUMB_OP16 (inst.instruction);
11973 inst.instruction |= Rd;
11974 inst.instruction |= Rn << 3;
11975 return;
11976 }
11977 if (Rd == Rn)
11978 {
11979 inst.instruction = THUMB_OP16 (inst.instruction);
11980 inst.instruction |= Rd;
11981 inst.instruction |= Rs << 3;
11982 return;
11983 }
11984 }
11985
11986 /* If we get here, it can't be done in 16 bits. */
11987 constraint (inst.operands[2].shifted
11988 && inst.operands[2].immisreg,
11989 _("shift must be constant"));
11990 inst.instruction = THUMB_OP32 (inst.instruction);
11991 inst.instruction |= Rd << 8;
11992 inst.instruction |= Rs << 16;
11993 encode_thumb32_shifted_operand (2);
11994 }
11995 }
11996 else
11997 {
11998 /* On its face this is a lie - the instruction does set the
11999 flags. However, the only supported mnemonic in this mode
12000 says it doesn't. */
12001 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12002
12003 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
12004 _("unshifted register required"));
12005 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
12006
12007 inst.instruction = THUMB_OP16 (inst.instruction);
12008 inst.instruction |= Rd;
12009
12010 if (Rd == Rs)
12011 inst.instruction |= Rn << 3;
12012 else if (Rd == Rn)
12013 inst.instruction |= Rs << 3;
12014 else
12015 constraint (1, _("dest must overlap one source register"));
12016 }
12017 }
12018
12019 static void
12020 do_t_bfc (void)
12021 {
12022 unsigned Rd;
12023 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
12024 constraint (msb > 32, _("bit-field extends past end of register"));
12025 /* The instruction encoding stores the LSB and MSB,
12026 not the LSB and width. */
12027 Rd = inst.operands[0].reg;
12028 reject_bad_reg (Rd);
12029 inst.instruction |= Rd << 8;
12030 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
12031 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
12032 inst.instruction |= msb - 1;
12033 }
12034
12035 static void
12036 do_t_bfi (void)
12037 {
12038 int Rd, Rn;
12039 unsigned int msb;
12040
12041 Rd = inst.operands[0].reg;
12042 reject_bad_reg (Rd);
12043
12044 /* #0 in second position is alternative syntax for bfc, which is
12045 the same instruction but with REG_PC in the Rm field. */
12046 if (!inst.operands[1].isreg)
12047 Rn = REG_PC;
12048 else
12049 {
12050 Rn = inst.operands[1].reg;
12051 reject_bad_reg (Rn);
12052 }
12053
12054 msb = inst.operands[2].imm + inst.operands[3].imm;
12055 constraint (msb > 32, _("bit-field extends past end of register"));
12056 /* The instruction encoding stores the LSB and MSB,
12057 not the LSB and width. */
12058 inst.instruction |= Rd << 8;
12059 inst.instruction |= Rn << 16;
12060 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12061 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12062 inst.instruction |= msb - 1;
12063 }
12064
12065 static void
12066 do_t_bfx (void)
12067 {
12068 unsigned Rd, Rn;
12069
12070 Rd = inst.operands[0].reg;
12071 Rn = inst.operands[1].reg;
12072
12073 reject_bad_reg (Rd);
12074 reject_bad_reg (Rn);
12075
12076 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
12077 _("bit-field extends past end of register"));
12078 inst.instruction |= Rd << 8;
12079 inst.instruction |= Rn << 16;
12080 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12081 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12082 inst.instruction |= inst.operands[3].imm - 1;
12083 }
12084
12085 /* ARM V5 Thumb BLX (argument parse)
12086 BLX <target_addr> which is BLX(1)
12087 BLX <Rm> which is BLX(2)
12088 Unfortunately, there are two different opcodes for this mnemonic.
12089 So, the insns[].value is not used, and the code here zaps values
12090 into inst.instruction.
12091
12092 ??? How to take advantage of the additional two bits of displacement
12093 available in Thumb32 mode? Need new relocation? */
12094
12095 static void
12096 do_t_blx (void)
12097 {
12098 set_pred_insn_type_last ();
12099
12100 if (inst.operands[0].isreg)
12101 {
12102 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
12103 /* We have a register, so this is BLX(2). */
12104 inst.instruction |= inst.operands[0].reg << 3;
12105 }
12106 else
12107 {
12108 /* No register. This must be BLX(1). */
12109 inst.instruction = 0xf000e800;
12110 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
12111 }
12112 }
12113
12114 static void
12115 do_t_branch (void)
12116 {
12117 int opcode;
12118 int cond;
12119 bfd_reloc_code_real_type reloc;
12120
12121 cond = inst.cond;
12122 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
12123
12124 if (in_pred_block ())
12125 {
12126 /* Conditional branches inside IT blocks are encoded as unconditional
12127 branches. */
12128 cond = COND_ALWAYS;
12129 }
12130 else
12131 cond = inst.cond;
12132
12133 if (cond != COND_ALWAYS)
12134 opcode = T_MNEM_bcond;
12135 else
12136 opcode = inst.instruction;
12137
12138 if (unified_syntax
12139 && (inst.size_req == 4
12140 || (inst.size_req != 2
12141 && (inst.operands[0].hasreloc
12142 || inst.relocs[0].exp.X_op == O_constant))))
12143 {
12144 inst.instruction = THUMB_OP32(opcode);
12145 if (cond == COND_ALWAYS)
12146 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
12147 else
12148 {
12149 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
12150 _("selected architecture does not support "
12151 "wide conditional branch instruction"));
12152
12153 gas_assert (cond != 0xF);
12154 inst.instruction |= cond << 22;
12155 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
12156 }
12157 }
12158 else
12159 {
12160 inst.instruction = THUMB_OP16(opcode);
12161 if (cond == COND_ALWAYS)
12162 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
12163 else
12164 {
12165 inst.instruction |= cond << 8;
12166 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
12167 }
12168 /* Allow section relaxation. */
12169 if (unified_syntax && inst.size_req != 2)
12170 inst.relax = opcode;
12171 }
12172 inst.relocs[0].type = reloc;
12173 inst.relocs[0].pc_rel = 1;
12174 }
12175
12176 /* Actually do the work for Thumb state bkpt and hlt. The only difference
12177 between the two is the maximum immediate allowed - which is passed in
12178 RANGE. */
12179 static void
12180 do_t_bkpt_hlt1 (int range)
12181 {
12182 constraint (inst.cond != COND_ALWAYS,
12183 _("instruction is always unconditional"));
12184 if (inst.operands[0].present)
12185 {
12186 constraint (inst.operands[0].imm > range,
12187 _("immediate value out of range"));
12188 inst.instruction |= inst.operands[0].imm;
12189 }
12190
12191 set_pred_insn_type (NEUTRAL_IT_INSN);
12192 }
12193
12194 static void
12195 do_t_hlt (void)
12196 {
12197 do_t_bkpt_hlt1 (63);
12198 }
12199
12200 static void
12201 do_t_bkpt (void)
12202 {
12203 do_t_bkpt_hlt1 (255);
12204 }
12205
12206 static void
12207 do_t_branch23 (void)
12208 {
12209 set_pred_insn_type_last ();
12210 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
12211
12212 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
12213 this file. We used to simply ignore the PLT reloc type here --
12214 the branch encoding is now needed to deal with TLSCALL relocs.
12215 So if we see a PLT reloc now, put it back to how it used to be to
12216 keep the preexisting behaviour. */
12217 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
12218 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
12219
12220 #if defined(OBJ_COFF)
12221 /* If the destination of the branch is a defined symbol which does not have
12222 the THUMB_FUNC attribute, then we must be calling a function which has
12223 the (interfacearm) attribute. We look for the Thumb entry point to that
12224 function and change the branch to refer to that function instead. */
12225 if ( inst.relocs[0].exp.X_op == O_symbol
12226 && inst.relocs[0].exp.X_add_symbol != NULL
12227 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
12228 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
12229 inst.relocs[0].exp.X_add_symbol
12230 = find_real_start (inst.relocs[0].exp.X_add_symbol);
12231 #endif
12232 }
12233
12234 static void
12235 do_t_bx (void)
12236 {
12237 set_pred_insn_type_last ();
12238 inst.instruction |= inst.operands[0].reg << 3;
12239 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
12240 should cause the alignment to be checked once it is known. This is
12241 because BX PC only works if the instruction is word aligned. */
12242 }
12243
12244 static void
12245 do_t_bxj (void)
12246 {
12247 int Rm;
12248
12249 set_pred_insn_type_last ();
12250 Rm = inst.operands[0].reg;
12251 reject_bad_reg (Rm);
12252 inst.instruction |= Rm << 16;
12253 }
12254
12255 static void
12256 do_t_clz (void)
12257 {
12258 unsigned Rd;
12259 unsigned Rm;
12260
12261 Rd = inst.operands[0].reg;
12262 Rm = inst.operands[1].reg;
12263
12264 reject_bad_reg (Rd);
12265 reject_bad_reg (Rm);
12266
12267 inst.instruction |= Rd << 8;
12268 inst.instruction |= Rm << 16;
12269 inst.instruction |= Rm;
12270 }
12271
12272 /* For the Armv8.1-M conditional instructions. */
12273 static void
12274 do_t_cond (void)
12275 {
12276 unsigned Rd, Rn, Rm;
12277 signed int cond;
12278
12279 constraint (inst.cond != COND_ALWAYS, BAD_COND);
12280
12281 Rd = inst.operands[0].reg;
12282 switch (inst.instruction)
12283 {
12284 case T_MNEM_csinc:
12285 case T_MNEM_csinv:
12286 case T_MNEM_csneg:
12287 case T_MNEM_csel:
12288 Rn = inst.operands[1].reg;
12289 Rm = inst.operands[2].reg;
12290 cond = inst.operands[3].imm;
12291 constraint (Rn == REG_SP, BAD_SP);
12292 constraint (Rm == REG_SP, BAD_SP);
12293 break;
12294
12295 case T_MNEM_cinc:
12296 case T_MNEM_cinv:
12297 case T_MNEM_cneg:
12298 Rn = inst.operands[1].reg;
12299 cond = inst.operands[2].imm;
12300 /* Invert the last bit to invert the cond. */
12301 cond = TOGGLE_BIT (cond, 0);
12302 constraint (Rn == REG_SP, BAD_SP);
12303 Rm = Rn;
12304 break;
12305
12306 case T_MNEM_csetm:
12307 case T_MNEM_cset:
12308 cond = inst.operands[1].imm;
12309 /* Invert the last bit to invert the cond. */
12310 cond = TOGGLE_BIT (cond, 0);
12311 Rn = REG_PC;
12312 Rm = REG_PC;
12313 break;
12314
12315 default: abort ();
12316 }
12317
12318 set_pred_insn_type (OUTSIDE_PRED_INSN);
12319 inst.instruction = THUMB_OP32 (inst.instruction);
12320 inst.instruction |= Rd << 8;
12321 inst.instruction |= Rn << 16;
12322 inst.instruction |= Rm;
12323 inst.instruction |= cond << 4;
12324 }
12325
12326 static void
12327 do_t_csdb (void)
12328 {
12329 set_pred_insn_type (OUTSIDE_PRED_INSN);
12330 }
12331
12332 static void
12333 do_t_cps (void)
12334 {
12335 set_pred_insn_type (OUTSIDE_PRED_INSN);
12336 inst.instruction |= inst.operands[0].imm;
12337 }
12338
12339 static void
12340 do_t_cpsi (void)
12341 {
12342 set_pred_insn_type (OUTSIDE_PRED_INSN);
12343 if (unified_syntax
12344 && (inst.operands[1].present || inst.size_req == 4)
12345 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
12346 {
12347 unsigned int imod = (inst.instruction & 0x0030) >> 4;
12348 inst.instruction = 0xf3af8000;
12349 inst.instruction |= imod << 9;
12350 inst.instruction |= inst.operands[0].imm << 5;
12351 if (inst.operands[1].present)
12352 inst.instruction |= 0x100 | inst.operands[1].imm;
12353 }
12354 else
12355 {
12356 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
12357 && (inst.operands[0].imm & 4),
12358 _("selected processor does not support 'A' form "
12359 "of this instruction"));
12360 constraint (inst.operands[1].present || inst.size_req == 4,
12361 _("Thumb does not support the 2-argument "
12362 "form of this instruction"));
12363 inst.instruction |= inst.operands[0].imm;
12364 }
12365 }
12366
12367 /* THUMB CPY instruction (argument parse). */
12368
12369 static void
12370 do_t_cpy (void)
12371 {
12372 if (inst.size_req == 4)
12373 {
12374 inst.instruction = THUMB_OP32 (T_MNEM_mov);
12375 inst.instruction |= inst.operands[0].reg << 8;
12376 inst.instruction |= inst.operands[1].reg;
12377 }
12378 else
12379 {
12380 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
12381 inst.instruction |= (inst.operands[0].reg & 0x7);
12382 inst.instruction |= inst.operands[1].reg << 3;
12383 }
12384 }
12385
12386 static void
12387 do_t_cbz (void)
12388 {
12389 set_pred_insn_type (OUTSIDE_PRED_INSN);
12390 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12391 inst.instruction |= inst.operands[0].reg;
12392 inst.relocs[0].pc_rel = 1;
12393 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
12394 }
12395
12396 static void
12397 do_t_dbg (void)
12398 {
12399 inst.instruction |= inst.operands[0].imm;
12400 }
12401
12402 static void
12403 do_t_div (void)
12404 {
12405 unsigned Rd, Rn, Rm;
12406
12407 Rd = inst.operands[0].reg;
12408 Rn = (inst.operands[1].present
12409 ? inst.operands[1].reg : Rd);
12410 Rm = inst.operands[2].reg;
12411
12412 reject_bad_reg (Rd);
12413 reject_bad_reg (Rn);
12414 reject_bad_reg (Rm);
12415
12416 inst.instruction |= Rd << 8;
12417 inst.instruction |= Rn << 16;
12418 inst.instruction |= Rm;
12419 }
12420
12421 static void
12422 do_t_hint (void)
12423 {
12424 if (unified_syntax && inst.size_req == 4)
12425 inst.instruction = THUMB_OP32 (inst.instruction);
12426 else
12427 inst.instruction = THUMB_OP16 (inst.instruction);
12428 }
12429
12430 static void
12431 do_t_it (void)
12432 {
12433 unsigned int cond = inst.operands[0].imm;
12434
12435 set_pred_insn_type (IT_INSN);
12436 now_pred.mask = (inst.instruction & 0xf) | 0x10;
12437 now_pred.cc = cond;
12438 now_pred.warn_deprecated = FALSE;
12439 now_pred.type = SCALAR_PRED;
12440
12441 /* If the condition is a negative condition, invert the mask. */
12442 if ((cond & 0x1) == 0x0)
12443 {
12444 unsigned int mask = inst.instruction & 0x000f;
12445
12446 if ((mask & 0x7) == 0)
12447 {
12448 /* No conversion needed. */
12449 now_pred.block_length = 1;
12450 }
12451 else if ((mask & 0x3) == 0)
12452 {
12453 mask ^= 0x8;
12454 now_pred.block_length = 2;
12455 }
12456 else if ((mask & 0x1) == 0)
12457 {
12458 mask ^= 0xC;
12459 now_pred.block_length = 3;
12460 }
12461 else
12462 {
12463 mask ^= 0xE;
12464 now_pred.block_length = 4;
12465 }
12466
12467 inst.instruction &= 0xfff0;
12468 inst.instruction |= mask;
12469 }
12470
12471 inst.instruction |= cond << 4;
12472 }
12473
12474 /* Helper function used for both push/pop and ldm/stm. */
12475 static void
12476 encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask,
12477 bfd_boolean writeback)
12478 {
12479 bfd_boolean load, store;
12480
12481 gas_assert (base != -1 || !do_io);
12482 load = do_io && ((inst.instruction & (1 << 20)) != 0);
12483 store = do_io && !load;
12484
12485 if (mask & (1 << 13))
12486 inst.error = _("SP not allowed in register list");
12487
12488 if (do_io && (mask & (1 << base)) != 0
12489 && writeback)
12490 inst.error = _("having the base register in the register list when "
12491 "using write back is UNPREDICTABLE");
12492
12493 if (load)
12494 {
12495 if (mask & (1 << 15))
12496 {
12497 if (mask & (1 << 14))
12498 inst.error = _("LR and PC should not both be in register list");
12499 else
12500 set_pred_insn_type_last ();
12501 }
12502 }
12503 else if (store)
12504 {
12505 if (mask & (1 << 15))
12506 inst.error = _("PC not allowed in register list");
12507 }
12508
12509 if (do_io && ((mask & (mask - 1)) == 0))
12510 {
12511 /* Single register transfers implemented as str/ldr. */
12512 if (writeback)
12513 {
12514 if (inst.instruction & (1 << 23))
12515 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
12516 else
12517 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
12518 }
12519 else
12520 {
12521 if (inst.instruction & (1 << 23))
12522 inst.instruction = 0x00800000; /* ia -> [base] */
12523 else
12524 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
12525 }
12526
12527 inst.instruction |= 0xf8400000;
12528 if (load)
12529 inst.instruction |= 0x00100000;
12530
12531 mask = ffs (mask) - 1;
12532 mask <<= 12;
12533 }
12534 else if (writeback)
12535 inst.instruction |= WRITE_BACK;
12536
12537 inst.instruction |= mask;
12538 if (do_io)
12539 inst.instruction |= base << 16;
12540 }
12541
12542 static void
12543 do_t_ldmstm (void)
12544 {
12545 /* This really doesn't seem worth it. */
12546 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
12547 _("expression too complex"));
12548 constraint (inst.operands[1].writeback,
12549 _("Thumb load/store multiple does not support {reglist}^"));
12550
12551 if (unified_syntax)
12552 {
12553 bfd_boolean narrow;
12554 unsigned mask;
12555
12556 narrow = FALSE;
12557 /* See if we can use a 16-bit instruction. */
12558 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
12559 && inst.size_req != 4
12560 && !(inst.operands[1].imm & ~0xff))
12561 {
12562 mask = 1 << inst.operands[0].reg;
12563
12564 if (inst.operands[0].reg <= 7)
12565 {
12566 if (inst.instruction == T_MNEM_stmia
12567 ? inst.operands[0].writeback
12568 : (inst.operands[0].writeback
12569 == !(inst.operands[1].imm & mask)))
12570 {
12571 if (inst.instruction == T_MNEM_stmia
12572 && (inst.operands[1].imm & mask)
12573 && (inst.operands[1].imm & (mask - 1)))
12574 as_warn (_("value stored for r%d is UNKNOWN"),
12575 inst.operands[0].reg);
12576
12577 inst.instruction = THUMB_OP16 (inst.instruction);
12578 inst.instruction |= inst.operands[0].reg << 8;
12579 inst.instruction |= inst.operands[1].imm;
12580 narrow = TRUE;
12581 }
12582 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12583 {
12584 /* This means 1 register in reg list one of 3 situations:
12585 1. Instruction is stmia, but without writeback.
12586 2. lmdia without writeback, but with Rn not in
12587 reglist.
12588 3. ldmia with writeback, but with Rn in reglist.
12589 Case 3 is UNPREDICTABLE behaviour, so we handle
12590 case 1 and 2 which can be converted into a 16-bit
12591 str or ldr. The SP cases are handled below. */
12592 unsigned long opcode;
12593 /* First, record an error for Case 3. */
12594 if (inst.operands[1].imm & mask
12595 && inst.operands[0].writeback)
12596 inst.error =
12597 _("having the base register in the register list when "
12598 "using write back is UNPREDICTABLE");
12599
12600 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
12601 : T_MNEM_ldr);
12602 inst.instruction = THUMB_OP16 (opcode);
12603 inst.instruction |= inst.operands[0].reg << 3;
12604 inst.instruction |= (ffs (inst.operands[1].imm)-1);
12605 narrow = TRUE;
12606 }
12607 }
12608 else if (inst.operands[0] .reg == REG_SP)
12609 {
12610 if (inst.operands[0].writeback)
12611 {
12612 inst.instruction =
12613 THUMB_OP16 (inst.instruction == T_MNEM_stmia
12614 ? T_MNEM_push : T_MNEM_pop);
12615 inst.instruction |= inst.operands[1].imm;
12616 narrow = TRUE;
12617 }
12618 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12619 {
12620 inst.instruction =
12621 THUMB_OP16 (inst.instruction == T_MNEM_stmia
12622 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
12623 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
12624 narrow = TRUE;
12625 }
12626 }
12627 }
12628
12629 if (!narrow)
12630 {
12631 if (inst.instruction < 0xffff)
12632 inst.instruction = THUMB_OP32 (inst.instruction);
12633
12634 encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg,
12635 inst.operands[1].imm,
12636 inst.operands[0].writeback);
12637 }
12638 }
12639 else
12640 {
12641 constraint (inst.operands[0].reg > 7
12642 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
12643 constraint (inst.instruction != T_MNEM_ldmia
12644 && inst.instruction != T_MNEM_stmia,
12645 _("Thumb-2 instruction only valid in unified syntax"));
12646 if (inst.instruction == T_MNEM_stmia)
12647 {
12648 if (!inst.operands[0].writeback)
12649 as_warn (_("this instruction will write back the base register"));
12650 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
12651 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
12652 as_warn (_("value stored for r%d is UNKNOWN"),
12653 inst.operands[0].reg);
12654 }
12655 else
12656 {
12657 if (!inst.operands[0].writeback
12658 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
12659 as_warn (_("this instruction will write back the base register"));
12660 else if (inst.operands[0].writeback
12661 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
12662 as_warn (_("this instruction will not write back the base register"));
12663 }
12664
12665 inst.instruction = THUMB_OP16 (inst.instruction);
12666 inst.instruction |= inst.operands[0].reg << 8;
12667 inst.instruction |= inst.operands[1].imm;
12668 }
12669 }
12670
12671 static void
12672 do_t_ldrex (void)
12673 {
12674 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
12675 || inst.operands[1].postind || inst.operands[1].writeback
12676 || inst.operands[1].immisreg || inst.operands[1].shifted
12677 || inst.operands[1].negative,
12678 BAD_ADDR_MODE);
12679
12680 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
12681
12682 inst.instruction |= inst.operands[0].reg << 12;
12683 inst.instruction |= inst.operands[1].reg << 16;
12684 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
12685 }
12686
12687 static void
12688 do_t_ldrexd (void)
12689 {
12690 if (!inst.operands[1].present)
12691 {
12692 constraint (inst.operands[0].reg == REG_LR,
12693 _("r14 not allowed as first register "
12694 "when second register is omitted"));
12695 inst.operands[1].reg = inst.operands[0].reg + 1;
12696 }
12697 constraint (inst.operands[0].reg == inst.operands[1].reg,
12698 BAD_OVERLAP);
12699
12700 inst.instruction |= inst.operands[0].reg << 12;
12701 inst.instruction |= inst.operands[1].reg << 8;
12702 inst.instruction |= inst.operands[2].reg << 16;
12703 }
12704
12705 static void
12706 do_t_ldst (void)
12707 {
12708 unsigned long opcode;
12709 int Rn;
12710
12711 if (inst.operands[0].isreg
12712 && !inst.operands[0].preind
12713 && inst.operands[0].reg == REG_PC)
12714 set_pred_insn_type_last ();
12715
12716 opcode = inst.instruction;
12717 if (unified_syntax)
12718 {
12719 if (!inst.operands[1].isreg)
12720 {
12721 if (opcode <= 0xffff)
12722 inst.instruction = THUMB_OP32 (opcode);
12723 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
12724 return;
12725 }
12726 if (inst.operands[1].isreg
12727 && !inst.operands[1].writeback
12728 && !inst.operands[1].shifted && !inst.operands[1].postind
12729 && !inst.operands[1].negative && inst.operands[0].reg <= 7
12730 && opcode <= 0xffff
12731 && inst.size_req != 4)
12732 {
12733 /* Insn may have a 16-bit form. */
12734 Rn = inst.operands[1].reg;
12735 if (inst.operands[1].immisreg)
12736 {
12737 inst.instruction = THUMB_OP16 (opcode);
12738 /* [Rn, Rik] */
12739 if (Rn <= 7 && inst.operands[1].imm <= 7)
12740 goto op16;
12741 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12742 reject_bad_reg (inst.operands[1].imm);
12743 }
12744 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12745 && opcode != T_MNEM_ldrsb)
12746 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12747 || (Rn == REG_SP && opcode == T_MNEM_str))
12748 {
12749 /* [Rn, #const] */
12750 if (Rn > 7)
12751 {
12752 if (Rn == REG_PC)
12753 {
12754 if (inst.relocs[0].pc_rel)
12755 opcode = T_MNEM_ldr_pc2;
12756 else
12757 opcode = T_MNEM_ldr_pc;
12758 }
12759 else
12760 {
12761 if (opcode == T_MNEM_ldr)
12762 opcode = T_MNEM_ldr_sp;
12763 else
12764 opcode = T_MNEM_str_sp;
12765 }
12766 inst.instruction = inst.operands[0].reg << 8;
12767 }
12768 else
12769 {
12770 inst.instruction = inst.operands[0].reg;
12771 inst.instruction |= inst.operands[1].reg << 3;
12772 }
12773 inst.instruction |= THUMB_OP16 (opcode);
12774 if (inst.size_req == 2)
12775 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12776 else
12777 inst.relax = opcode;
12778 return;
12779 }
12780 }
12781 /* Definitely a 32-bit variant. */
12782
12783 /* Warning for Erratum 752419. */
12784 if (opcode == T_MNEM_ldr
12785 && inst.operands[0].reg == REG_SP
12786 && inst.operands[1].writeback == 1
12787 && !inst.operands[1].immisreg)
12788 {
12789 if (no_cpu_selected ()
12790 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
12791 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12792 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
12793 as_warn (_("This instruction may be unpredictable "
12794 "if executed on M-profile cores "
12795 "with interrupts enabled."));
12796 }
12797
12798 /* Do some validations regarding addressing modes. */
12799 if (inst.operands[1].immisreg)
12800 reject_bad_reg (inst.operands[1].imm);
12801
12802 constraint (inst.operands[1].writeback == 1
12803 && inst.operands[0].reg == inst.operands[1].reg,
12804 BAD_OVERLAP);
12805
12806 inst.instruction = THUMB_OP32 (opcode);
12807 inst.instruction |= inst.operands[0].reg << 12;
12808 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
12809 check_ldr_r15_aligned ();
12810 return;
12811 }
12812
12813 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12814
12815 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
12816 {
12817 /* Only [Rn,Rm] is acceptable. */
12818 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12819 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12820 || inst.operands[1].postind || inst.operands[1].shifted
12821 || inst.operands[1].negative,
12822 _("Thumb does not support this addressing mode"));
12823 inst.instruction = THUMB_OP16 (inst.instruction);
12824 goto op16;
12825 }
12826
12827 inst.instruction = THUMB_OP16 (inst.instruction);
12828 if (!inst.operands[1].isreg)
12829 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
12830 return;
12831
12832 constraint (!inst.operands[1].preind
12833 || inst.operands[1].shifted
12834 || inst.operands[1].writeback,
12835 _("Thumb does not support this addressing mode"));
12836 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
12837 {
12838 constraint (inst.instruction & 0x0600,
12839 _("byte or halfword not valid for base register"));
12840 constraint (inst.operands[1].reg == REG_PC
12841 && !(inst.instruction & THUMB_LOAD_BIT),
12842 _("r15 based store not allowed"));
12843 constraint (inst.operands[1].immisreg,
12844 _("invalid base register for register offset"));
12845
12846 if (inst.operands[1].reg == REG_PC)
12847 inst.instruction = T_OPCODE_LDR_PC;
12848 else if (inst.instruction & THUMB_LOAD_BIT)
12849 inst.instruction = T_OPCODE_LDR_SP;
12850 else
12851 inst.instruction = T_OPCODE_STR_SP;
12852
12853 inst.instruction |= inst.operands[0].reg << 8;
12854 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12855 return;
12856 }
12857
12858 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12859 if (!inst.operands[1].immisreg)
12860 {
12861 /* Immediate offset. */
12862 inst.instruction |= inst.operands[0].reg;
12863 inst.instruction |= inst.operands[1].reg << 3;
12864 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12865 return;
12866 }
12867
12868 /* Register offset. */
12869 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12870 constraint (inst.operands[1].negative,
12871 _("Thumb does not support this addressing mode"));
12872
12873 op16:
12874 switch (inst.instruction)
12875 {
12876 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12877 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12878 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12879 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12880 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12881 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12882 case 0x5600 /* ldrsb */:
12883 case 0x5e00 /* ldrsh */: break;
12884 default: abort ();
12885 }
12886
12887 inst.instruction |= inst.operands[0].reg;
12888 inst.instruction |= inst.operands[1].reg << 3;
12889 inst.instruction |= inst.operands[1].imm << 6;
12890 }
12891
12892 static void
12893 do_t_ldstd (void)
12894 {
12895 if (!inst.operands[1].present)
12896 {
12897 inst.operands[1].reg = inst.operands[0].reg + 1;
12898 constraint (inst.operands[0].reg == REG_LR,
12899 _("r14 not allowed here"));
12900 constraint (inst.operands[0].reg == REG_R12,
12901 _("r12 not allowed here"));
12902 }
12903
12904 if (inst.operands[2].writeback
12905 && (inst.operands[0].reg == inst.operands[2].reg
12906 || inst.operands[1].reg == inst.operands[2].reg))
12907 as_warn (_("base register written back, and overlaps "
12908 "one of transfer registers"));
12909
12910 inst.instruction |= inst.operands[0].reg << 12;
12911 inst.instruction |= inst.operands[1].reg << 8;
12912 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
12913 }
12914
12915 static void
12916 do_t_ldstt (void)
12917 {
12918 inst.instruction |= inst.operands[0].reg << 12;
12919 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
12920 }
12921
12922 static void
12923 do_t_mla (void)
12924 {
12925 unsigned Rd, Rn, Rm, Ra;
12926
12927 Rd = inst.operands[0].reg;
12928 Rn = inst.operands[1].reg;
12929 Rm = inst.operands[2].reg;
12930 Ra = inst.operands[3].reg;
12931
12932 reject_bad_reg (Rd);
12933 reject_bad_reg (Rn);
12934 reject_bad_reg (Rm);
12935 reject_bad_reg (Ra);
12936
12937 inst.instruction |= Rd << 8;
12938 inst.instruction |= Rn << 16;
12939 inst.instruction |= Rm;
12940 inst.instruction |= Ra << 12;
12941 }
12942
12943 static void
12944 do_t_mlal (void)
12945 {
12946 unsigned RdLo, RdHi, Rn, Rm;
12947
12948 RdLo = inst.operands[0].reg;
12949 RdHi = inst.operands[1].reg;
12950 Rn = inst.operands[2].reg;
12951 Rm = inst.operands[3].reg;
12952
12953 reject_bad_reg (RdLo);
12954 reject_bad_reg (RdHi);
12955 reject_bad_reg (Rn);
12956 reject_bad_reg (Rm);
12957
12958 inst.instruction |= RdLo << 12;
12959 inst.instruction |= RdHi << 8;
12960 inst.instruction |= Rn << 16;
12961 inst.instruction |= Rm;
12962 }
12963
12964 static void
12965 do_t_mov_cmp (void)
12966 {
12967 unsigned Rn, Rm;
12968
12969 Rn = inst.operands[0].reg;
12970 Rm = inst.operands[1].reg;
12971
12972 if (Rn == REG_PC)
12973 set_pred_insn_type_last ();
12974
12975 if (unified_syntax)
12976 {
12977 int r0off = (inst.instruction == T_MNEM_mov
12978 || inst.instruction == T_MNEM_movs) ? 8 : 16;
12979 unsigned long opcode;
12980 bfd_boolean narrow;
12981 bfd_boolean low_regs;
12982
12983 low_regs = (Rn <= 7 && Rm <= 7);
12984 opcode = inst.instruction;
12985 if (in_pred_block ())
12986 narrow = opcode != T_MNEM_movs;
12987 else
12988 narrow = opcode != T_MNEM_movs || low_regs;
12989 if (inst.size_req == 4
12990 || inst.operands[1].shifted)
12991 narrow = FALSE;
12992
12993 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12994 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12995 && !inst.operands[1].shifted
12996 && Rn == REG_PC
12997 && Rm == REG_LR)
12998 {
12999 inst.instruction = T2_SUBS_PC_LR;
13000 return;
13001 }
13002
13003 if (opcode == T_MNEM_cmp)
13004 {
13005 constraint (Rn == REG_PC, BAD_PC);
13006 if (narrow)
13007 {
13008 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
13009 but valid. */
13010 warn_deprecated_sp (Rm);
13011 /* R15 was documented as a valid choice for Rm in ARMv6,
13012 but as UNPREDICTABLE in ARMv7. ARM's proprietary
13013 tools reject R15, so we do too. */
13014 constraint (Rm == REG_PC, BAD_PC);
13015 }
13016 else
13017 reject_bad_reg (Rm);
13018 }
13019 else if (opcode == T_MNEM_mov
13020 || opcode == T_MNEM_movs)
13021 {
13022 if (inst.operands[1].isreg)
13023 {
13024 if (opcode == T_MNEM_movs)
13025 {
13026 reject_bad_reg (Rn);
13027 reject_bad_reg (Rm);
13028 }
13029 else if (narrow)
13030 {
13031 /* This is mov.n. */
13032 if ((Rn == REG_SP || Rn == REG_PC)
13033 && (Rm == REG_SP || Rm == REG_PC))
13034 {
13035 as_tsktsk (_("Use of r%u as a source register is "
13036 "deprecated when r%u is the destination "
13037 "register."), Rm, Rn);
13038 }
13039 }
13040 else
13041 {
13042 /* This is mov.w. */
13043 constraint (Rn == REG_PC, BAD_PC);
13044 constraint (Rm == REG_PC, BAD_PC);
13045 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13046 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
13047 }
13048 }
13049 else
13050 reject_bad_reg (Rn);
13051 }
13052
13053 if (!inst.operands[1].isreg)
13054 {
13055 /* Immediate operand. */
13056 if (!in_pred_block () && opcode == T_MNEM_mov)
13057 narrow = 0;
13058 if (low_regs && narrow)
13059 {
13060 inst.instruction = THUMB_OP16 (opcode);
13061 inst.instruction |= Rn << 8;
13062 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
13063 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
13064 {
13065 if (inst.size_req == 2)
13066 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
13067 else
13068 inst.relax = opcode;
13069 }
13070 }
13071 else
13072 {
13073 constraint ((inst.relocs[0].type
13074 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
13075 && (inst.relocs[0].type
13076 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
13077 THUMB1_RELOC_ONLY);
13078
13079 inst.instruction = THUMB_OP32 (inst.instruction);
13080 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13081 inst.instruction |= Rn << r0off;
13082 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13083 }
13084 }
13085 else if (inst.operands[1].shifted && inst.operands[1].immisreg
13086 && (inst.instruction == T_MNEM_mov
13087 || inst.instruction == T_MNEM_movs))
13088 {
13089 /* Register shifts are encoded as separate shift instructions. */
13090 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
13091
13092 if (in_pred_block ())
13093 narrow = !flags;
13094 else
13095 narrow = flags;
13096
13097 if (inst.size_req == 4)
13098 narrow = FALSE;
13099
13100 if (!low_regs || inst.operands[1].imm > 7)
13101 narrow = FALSE;
13102
13103 if (Rn != Rm)
13104 narrow = FALSE;
13105
13106 switch (inst.operands[1].shift_kind)
13107 {
13108 case SHIFT_LSL:
13109 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
13110 break;
13111 case SHIFT_ASR:
13112 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
13113 break;
13114 case SHIFT_LSR:
13115 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
13116 break;
13117 case SHIFT_ROR:
13118 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
13119 break;
13120 default:
13121 abort ();
13122 }
13123
13124 inst.instruction = opcode;
13125 if (narrow)
13126 {
13127 inst.instruction |= Rn;
13128 inst.instruction |= inst.operands[1].imm << 3;
13129 }
13130 else
13131 {
13132 if (flags)
13133 inst.instruction |= CONDS_BIT;
13134
13135 inst.instruction |= Rn << 8;
13136 inst.instruction |= Rm << 16;
13137 inst.instruction |= inst.operands[1].imm;
13138 }
13139 }
13140 else if (!narrow)
13141 {
13142 /* Some mov with immediate shift have narrow variants.
13143 Register shifts are handled above. */
13144 if (low_regs && inst.operands[1].shifted
13145 && (inst.instruction == T_MNEM_mov
13146 || inst.instruction == T_MNEM_movs))
13147 {
13148 if (in_pred_block ())
13149 narrow = (inst.instruction == T_MNEM_mov);
13150 else
13151 narrow = (inst.instruction == T_MNEM_movs);
13152 }
13153
13154 if (narrow)
13155 {
13156 switch (inst.operands[1].shift_kind)
13157 {
13158 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13159 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13160 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13161 default: narrow = FALSE; break;
13162 }
13163 }
13164
13165 if (narrow)
13166 {
13167 inst.instruction |= Rn;
13168 inst.instruction |= Rm << 3;
13169 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
13170 }
13171 else
13172 {
13173 inst.instruction = THUMB_OP32 (inst.instruction);
13174 inst.instruction |= Rn << r0off;
13175 encode_thumb32_shifted_operand (1);
13176 }
13177 }
13178 else
13179 switch (inst.instruction)
13180 {
13181 case T_MNEM_mov:
13182 /* In v4t or v5t a move of two lowregs produces unpredictable
13183 results. Don't allow this. */
13184 if (low_regs)
13185 {
13186 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
13187 "MOV Rd, Rs with two low registers is not "
13188 "permitted on this architecture");
13189 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
13190 arm_ext_v6);
13191 }
13192
13193 inst.instruction = T_OPCODE_MOV_HR;
13194 inst.instruction |= (Rn & 0x8) << 4;
13195 inst.instruction |= (Rn & 0x7);
13196 inst.instruction |= Rm << 3;
13197 break;
13198
13199 case T_MNEM_movs:
13200 /* We know we have low registers at this point.
13201 Generate LSLS Rd, Rs, #0. */
13202 inst.instruction = T_OPCODE_LSL_I;
13203 inst.instruction |= Rn;
13204 inst.instruction |= Rm << 3;
13205 break;
13206
13207 case T_MNEM_cmp:
13208 if (low_regs)
13209 {
13210 inst.instruction = T_OPCODE_CMP_LR;
13211 inst.instruction |= Rn;
13212 inst.instruction |= Rm << 3;
13213 }
13214 else
13215 {
13216 inst.instruction = T_OPCODE_CMP_HR;
13217 inst.instruction |= (Rn & 0x8) << 4;
13218 inst.instruction |= (Rn & 0x7);
13219 inst.instruction |= Rm << 3;
13220 }
13221 break;
13222 }
13223 return;
13224 }
13225
13226 inst.instruction = THUMB_OP16 (inst.instruction);
13227
13228 /* PR 10443: Do not silently ignore shifted operands. */
13229 constraint (inst.operands[1].shifted,
13230 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
13231
13232 if (inst.operands[1].isreg)
13233 {
13234 if (Rn < 8 && Rm < 8)
13235 {
13236 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
13237 since a MOV instruction produces unpredictable results. */
13238 if (inst.instruction == T_OPCODE_MOV_I8)
13239 inst.instruction = T_OPCODE_ADD_I3;
13240 else
13241 inst.instruction = T_OPCODE_CMP_LR;
13242
13243 inst.instruction |= Rn;
13244 inst.instruction |= Rm << 3;
13245 }
13246 else
13247 {
13248 if (inst.instruction == T_OPCODE_MOV_I8)
13249 inst.instruction = T_OPCODE_MOV_HR;
13250 else
13251 inst.instruction = T_OPCODE_CMP_HR;
13252 do_t_cpy ();
13253 }
13254 }
13255 else
13256 {
13257 constraint (Rn > 7,
13258 _("only lo regs allowed with immediate"));
13259 inst.instruction |= Rn << 8;
13260 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
13261 }
13262 }
13263
13264 static void
13265 do_t_mov16 (void)
13266 {
13267 unsigned Rd;
13268 bfd_vma imm;
13269 bfd_boolean top;
13270
13271 top = (inst.instruction & 0x00800000) != 0;
13272 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
13273 {
13274 constraint (top, _(":lower16: not allowed in this instruction"));
13275 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
13276 }
13277 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
13278 {
13279 constraint (!top, _(":upper16: not allowed in this instruction"));
13280 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
13281 }
13282
13283 Rd = inst.operands[0].reg;
13284 reject_bad_reg (Rd);
13285
13286 inst.instruction |= Rd << 8;
13287 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
13288 {
13289 imm = inst.relocs[0].exp.X_add_number;
13290 inst.instruction |= (imm & 0xf000) << 4;
13291 inst.instruction |= (imm & 0x0800) << 15;
13292 inst.instruction |= (imm & 0x0700) << 4;
13293 inst.instruction |= (imm & 0x00ff);
13294 }
13295 }
13296
13297 static void
13298 do_t_mvn_tst (void)
13299 {
13300 unsigned Rn, Rm;
13301
13302 Rn = inst.operands[0].reg;
13303 Rm = inst.operands[1].reg;
13304
13305 if (inst.instruction == T_MNEM_cmp
13306 || inst.instruction == T_MNEM_cmn)
13307 constraint (Rn == REG_PC, BAD_PC);
13308 else
13309 reject_bad_reg (Rn);
13310 reject_bad_reg (Rm);
13311
13312 if (unified_syntax)
13313 {
13314 int r0off = (inst.instruction == T_MNEM_mvn
13315 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
13316 bfd_boolean narrow;
13317
13318 if (inst.size_req == 4
13319 || inst.instruction > 0xffff
13320 || inst.operands[1].shifted
13321 || Rn > 7 || Rm > 7)
13322 narrow = FALSE;
13323 else if (inst.instruction == T_MNEM_cmn
13324 || inst.instruction == T_MNEM_tst)
13325 narrow = TRUE;
13326 else if (THUMB_SETS_FLAGS (inst.instruction))
13327 narrow = !in_pred_block ();
13328 else
13329 narrow = in_pred_block ();
13330
13331 if (!inst.operands[1].isreg)
13332 {
13333 /* For an immediate, we always generate a 32-bit opcode;
13334 section relaxation will shrink it later if possible. */
13335 if (inst.instruction < 0xffff)
13336 inst.instruction = THUMB_OP32 (inst.instruction);
13337 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13338 inst.instruction |= Rn << r0off;
13339 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13340 }
13341 else
13342 {
13343 /* See if we can do this with a 16-bit instruction. */
13344 if (narrow)
13345 {
13346 inst.instruction = THUMB_OP16 (inst.instruction);
13347 inst.instruction |= Rn;
13348 inst.instruction |= Rm << 3;
13349 }
13350 else
13351 {
13352 constraint (inst.operands[1].shifted
13353 && inst.operands[1].immisreg,
13354 _("shift must be constant"));
13355 if (inst.instruction < 0xffff)
13356 inst.instruction = THUMB_OP32 (inst.instruction);
13357 inst.instruction |= Rn << r0off;
13358 encode_thumb32_shifted_operand (1);
13359 }
13360 }
13361 }
13362 else
13363 {
13364 constraint (inst.instruction > 0xffff
13365 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
13366 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
13367 _("unshifted register required"));
13368 constraint (Rn > 7 || Rm > 7,
13369 BAD_HIREG);
13370
13371 inst.instruction = THUMB_OP16 (inst.instruction);
13372 inst.instruction |= Rn;
13373 inst.instruction |= Rm << 3;
13374 }
13375 }
13376
13377 static void
13378 do_t_mrs (void)
13379 {
13380 unsigned Rd;
13381
13382 if (do_vfp_nsyn_mrs () == SUCCESS)
13383 return;
13384
13385 Rd = inst.operands[0].reg;
13386 reject_bad_reg (Rd);
13387 inst.instruction |= Rd << 8;
13388
13389 if (inst.operands[1].isreg)
13390 {
13391 unsigned br = inst.operands[1].reg;
13392 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
13393 as_bad (_("bad register for mrs"));
13394
13395 inst.instruction |= br & (0xf << 16);
13396 inst.instruction |= (br & 0x300) >> 4;
13397 inst.instruction |= (br & SPSR_BIT) >> 2;
13398 }
13399 else
13400 {
13401 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13402
13403 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
13404 {
13405 /* PR gas/12698: The constraint is only applied for m_profile.
13406 If the user has specified -march=all, we want to ignore it as
13407 we are building for any CPU type, including non-m variants. */
13408 bfd_boolean m_profile =
13409 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
13410 constraint ((flags != 0) && m_profile, _("selected processor does "
13411 "not support requested special purpose register"));
13412 }
13413 else
13414 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
13415 devices). */
13416 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
13417 _("'APSR', 'CPSR' or 'SPSR' expected"));
13418
13419 inst.instruction |= (flags & SPSR_BIT) >> 2;
13420 inst.instruction |= inst.operands[1].imm & 0xff;
13421 inst.instruction |= 0xf0000;
13422 }
13423 }
13424
13425 static void
13426 do_t_msr (void)
13427 {
13428 int flags;
13429 unsigned Rn;
13430
13431 if (do_vfp_nsyn_msr () == SUCCESS)
13432 return;
13433
13434 constraint (!inst.operands[1].isreg,
13435 _("Thumb encoding does not support an immediate here"));
13436
13437 if (inst.operands[0].isreg)
13438 flags = (int)(inst.operands[0].reg);
13439 else
13440 flags = inst.operands[0].imm;
13441
13442 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
13443 {
13444 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13445
13446 /* PR gas/12698: The constraint is only applied for m_profile.
13447 If the user has specified -march=all, we want to ignore it as
13448 we are building for any CPU type, including non-m variants. */
13449 bfd_boolean m_profile =
13450 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
13451 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13452 && (bits & ~(PSR_s | PSR_f)) != 0)
13453 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13454 && bits != PSR_f)) && m_profile,
13455 _("selected processor does not support requested special "
13456 "purpose register"));
13457 }
13458 else
13459 constraint ((flags & 0xff) != 0, _("selected processor does not support "
13460 "requested special purpose register"));
13461
13462 Rn = inst.operands[1].reg;
13463 reject_bad_reg (Rn);
13464
13465 inst.instruction |= (flags & SPSR_BIT) >> 2;
13466 inst.instruction |= (flags & 0xf0000) >> 8;
13467 inst.instruction |= (flags & 0x300) >> 4;
13468 inst.instruction |= (flags & 0xff);
13469 inst.instruction |= Rn << 16;
13470 }
13471
13472 static void
13473 do_t_mul (void)
13474 {
13475 bfd_boolean narrow;
13476 unsigned Rd, Rn, Rm;
13477
13478 if (!inst.operands[2].present)
13479 inst.operands[2].reg = inst.operands[0].reg;
13480
13481 Rd = inst.operands[0].reg;
13482 Rn = inst.operands[1].reg;
13483 Rm = inst.operands[2].reg;
13484
13485 if (unified_syntax)
13486 {
13487 if (inst.size_req == 4
13488 || (Rd != Rn
13489 && Rd != Rm)
13490 || Rn > 7
13491 || Rm > 7)
13492 narrow = FALSE;
13493 else if (inst.instruction == T_MNEM_muls)
13494 narrow = !in_pred_block ();
13495 else
13496 narrow = in_pred_block ();
13497 }
13498 else
13499 {
13500 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
13501 constraint (Rn > 7 || Rm > 7,
13502 BAD_HIREG);
13503 narrow = TRUE;
13504 }
13505
13506 if (narrow)
13507 {
13508 /* 16-bit MULS/Conditional MUL. */
13509 inst.instruction = THUMB_OP16 (inst.instruction);
13510 inst.instruction |= Rd;
13511
13512 if (Rd == Rn)
13513 inst.instruction |= Rm << 3;
13514 else if (Rd == Rm)
13515 inst.instruction |= Rn << 3;
13516 else
13517 constraint (1, _("dest must overlap one source register"));
13518 }
13519 else
13520 {
13521 constraint (inst.instruction != T_MNEM_mul,
13522 _("Thumb-2 MUL must not set flags"));
13523 /* 32-bit MUL. */
13524 inst.instruction = THUMB_OP32 (inst.instruction);
13525 inst.instruction |= Rd << 8;
13526 inst.instruction |= Rn << 16;
13527 inst.instruction |= Rm << 0;
13528
13529 reject_bad_reg (Rd);
13530 reject_bad_reg (Rn);
13531 reject_bad_reg (Rm);
13532 }
13533 }
13534
13535 static void
13536 do_t_mull (void)
13537 {
13538 unsigned RdLo, RdHi, Rn, Rm;
13539
13540 RdLo = inst.operands[0].reg;
13541 RdHi = inst.operands[1].reg;
13542 Rn = inst.operands[2].reg;
13543 Rm = inst.operands[3].reg;
13544
13545 reject_bad_reg (RdLo);
13546 reject_bad_reg (RdHi);
13547 reject_bad_reg (Rn);
13548 reject_bad_reg (Rm);
13549
13550 inst.instruction |= RdLo << 12;
13551 inst.instruction |= RdHi << 8;
13552 inst.instruction |= Rn << 16;
13553 inst.instruction |= Rm;
13554
13555 if (RdLo == RdHi)
13556 as_tsktsk (_("rdhi and rdlo must be different"));
13557 }
13558
13559 static void
13560 do_t_nop (void)
13561 {
13562 set_pred_insn_type (NEUTRAL_IT_INSN);
13563
13564 if (unified_syntax)
13565 {
13566 if (inst.size_req == 4 || inst.operands[0].imm > 15)
13567 {
13568 inst.instruction = THUMB_OP32 (inst.instruction);
13569 inst.instruction |= inst.operands[0].imm;
13570 }
13571 else
13572 {
13573 /* PR9722: Check for Thumb2 availability before
13574 generating a thumb2 nop instruction. */
13575 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
13576 {
13577 inst.instruction = THUMB_OP16 (inst.instruction);
13578 inst.instruction |= inst.operands[0].imm << 4;
13579 }
13580 else
13581 inst.instruction = 0x46c0;
13582 }
13583 }
13584 else
13585 {
13586 constraint (inst.operands[0].present,
13587 _("Thumb does not support NOP with hints"));
13588 inst.instruction = 0x46c0;
13589 }
13590 }
13591
13592 static void
13593 do_t_neg (void)
13594 {
13595 if (unified_syntax)
13596 {
13597 bfd_boolean narrow;
13598
13599 if (THUMB_SETS_FLAGS (inst.instruction))
13600 narrow = !in_pred_block ();
13601 else
13602 narrow = in_pred_block ();
13603 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13604 narrow = FALSE;
13605 if (inst.size_req == 4)
13606 narrow = FALSE;
13607
13608 if (!narrow)
13609 {
13610 inst.instruction = THUMB_OP32 (inst.instruction);
13611 inst.instruction |= inst.operands[0].reg << 8;
13612 inst.instruction |= inst.operands[1].reg << 16;
13613 }
13614 else
13615 {
13616 inst.instruction = THUMB_OP16 (inst.instruction);
13617 inst.instruction |= inst.operands[0].reg;
13618 inst.instruction |= inst.operands[1].reg << 3;
13619 }
13620 }
13621 else
13622 {
13623 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
13624 BAD_HIREG);
13625 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13626
13627 inst.instruction = THUMB_OP16 (inst.instruction);
13628 inst.instruction |= inst.operands[0].reg;
13629 inst.instruction |= inst.operands[1].reg << 3;
13630 }
13631 }
13632
13633 static void
13634 do_t_orn (void)
13635 {
13636 unsigned Rd, Rn;
13637
13638 Rd = inst.operands[0].reg;
13639 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
13640
13641 reject_bad_reg (Rd);
13642 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
13643 reject_bad_reg (Rn);
13644
13645 inst.instruction |= Rd << 8;
13646 inst.instruction |= Rn << 16;
13647
13648 if (!inst.operands[2].isreg)
13649 {
13650 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13651 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13652 }
13653 else
13654 {
13655 unsigned Rm;
13656
13657 Rm = inst.operands[2].reg;
13658 reject_bad_reg (Rm);
13659
13660 constraint (inst.operands[2].shifted
13661 && inst.operands[2].immisreg,
13662 _("shift must be constant"));
13663 encode_thumb32_shifted_operand (2);
13664 }
13665 }
13666
13667 static void
13668 do_t_pkhbt (void)
13669 {
13670 unsigned Rd, Rn, Rm;
13671
13672 Rd = inst.operands[0].reg;
13673 Rn = inst.operands[1].reg;
13674 Rm = inst.operands[2].reg;
13675
13676 reject_bad_reg (Rd);
13677 reject_bad_reg (Rn);
13678 reject_bad_reg (Rm);
13679
13680 inst.instruction |= Rd << 8;
13681 inst.instruction |= Rn << 16;
13682 inst.instruction |= Rm;
13683 if (inst.operands[3].present)
13684 {
13685 unsigned int val = inst.relocs[0].exp.X_add_number;
13686 constraint (inst.relocs[0].exp.X_op != O_constant,
13687 _("expression too complex"));
13688 inst.instruction |= (val & 0x1c) << 10;
13689 inst.instruction |= (val & 0x03) << 6;
13690 }
13691 }
13692
13693 static void
13694 do_t_pkhtb (void)
13695 {
13696 if (!inst.operands[3].present)
13697 {
13698 unsigned Rtmp;
13699
13700 inst.instruction &= ~0x00000020;
13701
13702 /* PR 10168. Swap the Rm and Rn registers. */
13703 Rtmp = inst.operands[1].reg;
13704 inst.operands[1].reg = inst.operands[2].reg;
13705 inst.operands[2].reg = Rtmp;
13706 }
13707 do_t_pkhbt ();
13708 }
13709
13710 static void
13711 do_t_pld (void)
13712 {
13713 if (inst.operands[0].immisreg)
13714 reject_bad_reg (inst.operands[0].imm);
13715
13716 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
13717 }
13718
13719 static void
13720 do_t_push_pop (void)
13721 {
13722 unsigned mask;
13723
13724 constraint (inst.operands[0].writeback,
13725 _("push/pop do not support {reglist}^"));
13726 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
13727 _("expression too complex"));
13728
13729 mask = inst.operands[0].imm;
13730 if (inst.size_req != 4 && (mask & ~0xff) == 0)
13731 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
13732 else if (inst.size_req != 4
13733 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
13734 ? REG_LR : REG_PC)))
13735 {
13736 inst.instruction = THUMB_OP16 (inst.instruction);
13737 inst.instruction |= THUMB_PP_PC_LR;
13738 inst.instruction |= mask & 0xff;
13739 }
13740 else if (unified_syntax)
13741 {
13742 inst.instruction = THUMB_OP32 (inst.instruction);
13743 encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE);
13744 }
13745 else
13746 {
13747 inst.error = _("invalid register list to push/pop instruction");
13748 return;
13749 }
13750 }
13751
13752 static void
13753 do_t_clrm (void)
13754 {
13755 if (unified_syntax)
13756 encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE);
13757 else
13758 {
13759 inst.error = _("invalid register list to push/pop instruction");
13760 return;
13761 }
13762 }
13763
13764 static void
13765 do_t_vscclrm (void)
13766 {
13767 if (inst.operands[0].issingle)
13768 {
13769 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13770 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13771 inst.instruction |= inst.operands[0].imm;
13772 }
13773 else
13774 {
13775 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13776 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13777 inst.instruction |= 1 << 8;
13778 inst.instruction |= inst.operands[0].imm << 1;
13779 }
13780 }
13781
13782 static void
13783 do_t_rbit (void)
13784 {
13785 unsigned Rd, Rm;
13786
13787 Rd = inst.operands[0].reg;
13788 Rm = inst.operands[1].reg;
13789
13790 reject_bad_reg (Rd);
13791 reject_bad_reg (Rm);
13792
13793 inst.instruction |= Rd << 8;
13794 inst.instruction |= Rm << 16;
13795 inst.instruction |= Rm;
13796 }
13797
13798 static void
13799 do_t_rev (void)
13800 {
13801 unsigned Rd, Rm;
13802
13803 Rd = inst.operands[0].reg;
13804 Rm = inst.operands[1].reg;
13805
13806 reject_bad_reg (Rd);
13807 reject_bad_reg (Rm);
13808
13809 if (Rd <= 7 && Rm <= 7
13810 && inst.size_req != 4)
13811 {
13812 inst.instruction = THUMB_OP16 (inst.instruction);
13813 inst.instruction |= Rd;
13814 inst.instruction |= Rm << 3;
13815 }
13816 else if (unified_syntax)
13817 {
13818 inst.instruction = THUMB_OP32 (inst.instruction);
13819 inst.instruction |= Rd << 8;
13820 inst.instruction |= Rm << 16;
13821 inst.instruction |= Rm;
13822 }
13823 else
13824 inst.error = BAD_HIREG;
13825 }
13826
13827 static void
13828 do_t_rrx (void)
13829 {
13830 unsigned Rd, Rm;
13831
13832 Rd = inst.operands[0].reg;
13833 Rm = inst.operands[1].reg;
13834
13835 reject_bad_reg (Rd);
13836 reject_bad_reg (Rm);
13837
13838 inst.instruction |= Rd << 8;
13839 inst.instruction |= Rm;
13840 }
13841
13842 static void
13843 do_t_rsb (void)
13844 {
13845 unsigned Rd, Rs;
13846
13847 Rd = inst.operands[0].reg;
13848 Rs = (inst.operands[1].present
13849 ? inst.operands[1].reg /* Rd, Rs, foo */
13850 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
13851
13852 reject_bad_reg (Rd);
13853 reject_bad_reg (Rs);
13854 if (inst.operands[2].isreg)
13855 reject_bad_reg (inst.operands[2].reg);
13856
13857 inst.instruction |= Rd << 8;
13858 inst.instruction |= Rs << 16;
13859 if (!inst.operands[2].isreg)
13860 {
13861 bfd_boolean narrow;
13862
13863 if ((inst.instruction & 0x00100000) != 0)
13864 narrow = !in_pred_block ();
13865 else
13866 narrow = in_pred_block ();
13867
13868 if (Rd > 7 || Rs > 7)
13869 narrow = FALSE;
13870
13871 if (inst.size_req == 4 || !unified_syntax)
13872 narrow = FALSE;
13873
13874 if (inst.relocs[0].exp.X_op != O_constant
13875 || inst.relocs[0].exp.X_add_number != 0)
13876 narrow = FALSE;
13877
13878 /* Turn rsb #0 into 16-bit neg. We should probably do this via
13879 relaxation, but it doesn't seem worth the hassle. */
13880 if (narrow)
13881 {
13882 inst.relocs[0].type = BFD_RELOC_UNUSED;
13883 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13884 inst.instruction |= Rs << 3;
13885 inst.instruction |= Rd;
13886 }
13887 else
13888 {
13889 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13890 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13891 }
13892 }
13893 else
13894 encode_thumb32_shifted_operand (2);
13895 }
13896
13897 static void
13898 do_t_setend (void)
13899 {
13900 if (warn_on_deprecated
13901 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13902 as_tsktsk (_("setend use is deprecated for ARMv8"));
13903
13904 set_pred_insn_type (OUTSIDE_PRED_INSN);
13905 if (inst.operands[0].imm)
13906 inst.instruction |= 0x8;
13907 }
13908
13909 static void
13910 do_t_shift (void)
13911 {
13912 if (!inst.operands[1].present)
13913 inst.operands[1].reg = inst.operands[0].reg;
13914
13915 if (unified_syntax)
13916 {
13917 bfd_boolean narrow;
13918 int shift_kind;
13919
13920 switch (inst.instruction)
13921 {
13922 case T_MNEM_asr:
13923 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13924 case T_MNEM_lsl:
13925 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13926 case T_MNEM_lsr:
13927 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13928 case T_MNEM_ror:
13929 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13930 default: abort ();
13931 }
13932
13933 if (THUMB_SETS_FLAGS (inst.instruction))
13934 narrow = !in_pred_block ();
13935 else
13936 narrow = in_pred_block ();
13937 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13938 narrow = FALSE;
13939 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13940 narrow = FALSE;
13941 if (inst.operands[2].isreg
13942 && (inst.operands[1].reg != inst.operands[0].reg
13943 || inst.operands[2].reg > 7))
13944 narrow = FALSE;
13945 if (inst.size_req == 4)
13946 narrow = FALSE;
13947
13948 reject_bad_reg (inst.operands[0].reg);
13949 reject_bad_reg (inst.operands[1].reg);
13950
13951 if (!narrow)
13952 {
13953 if (inst.operands[2].isreg)
13954 {
13955 reject_bad_reg (inst.operands[2].reg);
13956 inst.instruction = THUMB_OP32 (inst.instruction);
13957 inst.instruction |= inst.operands[0].reg << 8;
13958 inst.instruction |= inst.operands[1].reg << 16;
13959 inst.instruction |= inst.operands[2].reg;
13960
13961 /* PR 12854: Error on extraneous shifts. */
13962 constraint (inst.operands[2].shifted,
13963 _("extraneous shift as part of operand to shift insn"));
13964 }
13965 else
13966 {
13967 inst.operands[1].shifted = 1;
13968 inst.operands[1].shift_kind = shift_kind;
13969 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13970 ? T_MNEM_movs : T_MNEM_mov);
13971 inst.instruction |= inst.operands[0].reg << 8;
13972 encode_thumb32_shifted_operand (1);
13973 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
13974 inst.relocs[0].type = BFD_RELOC_UNUSED;
13975 }
13976 }
13977 else
13978 {
13979 if (inst.operands[2].isreg)
13980 {
13981 switch (shift_kind)
13982 {
13983 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13984 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13985 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13986 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
13987 default: abort ();
13988 }
13989
13990 inst.instruction |= inst.operands[0].reg;
13991 inst.instruction |= inst.operands[2].reg << 3;
13992
13993 /* PR 12854: Error on extraneous shifts. */
13994 constraint (inst.operands[2].shifted,
13995 _("extraneous shift as part of operand to shift insn"));
13996 }
13997 else
13998 {
13999 switch (shift_kind)
14000 {
14001 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
14002 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
14003 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
14004 default: abort ();
14005 }
14006 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
14007 inst.instruction |= inst.operands[0].reg;
14008 inst.instruction |= inst.operands[1].reg << 3;
14009 }
14010 }
14011 }
14012 else
14013 {
14014 constraint (inst.operands[0].reg > 7
14015 || inst.operands[1].reg > 7, BAD_HIREG);
14016 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
14017
14018 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
14019 {
14020 constraint (inst.operands[2].reg > 7, BAD_HIREG);
14021 constraint (inst.operands[0].reg != inst.operands[1].reg,
14022 _("source1 and dest must be same register"));
14023
14024 switch (inst.instruction)
14025 {
14026 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
14027 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
14028 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
14029 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
14030 default: abort ();
14031 }
14032
14033 inst.instruction |= inst.operands[0].reg;
14034 inst.instruction |= inst.operands[2].reg << 3;
14035
14036 /* PR 12854: Error on extraneous shifts. */
14037 constraint (inst.operands[2].shifted,
14038 _("extraneous shift as part of operand to shift insn"));
14039 }
14040 else
14041 {
14042 switch (inst.instruction)
14043 {
14044 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
14045 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
14046 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
14047 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
14048 default: abort ();
14049 }
14050 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
14051 inst.instruction |= inst.operands[0].reg;
14052 inst.instruction |= inst.operands[1].reg << 3;
14053 }
14054 }
14055 }
14056
14057 static void
14058 do_t_simd (void)
14059 {
14060 unsigned Rd, Rn, Rm;
14061
14062 Rd = inst.operands[0].reg;
14063 Rn = inst.operands[1].reg;
14064 Rm = inst.operands[2].reg;
14065
14066 reject_bad_reg (Rd);
14067 reject_bad_reg (Rn);
14068 reject_bad_reg (Rm);
14069
14070 inst.instruction |= Rd << 8;
14071 inst.instruction |= Rn << 16;
14072 inst.instruction |= Rm;
14073 }
14074
14075 static void
14076 do_t_simd2 (void)
14077 {
14078 unsigned Rd, Rn, Rm;
14079
14080 Rd = inst.operands[0].reg;
14081 Rm = inst.operands[1].reg;
14082 Rn = inst.operands[2].reg;
14083
14084 reject_bad_reg (Rd);
14085 reject_bad_reg (Rn);
14086 reject_bad_reg (Rm);
14087
14088 inst.instruction |= Rd << 8;
14089 inst.instruction |= Rn << 16;
14090 inst.instruction |= Rm;
14091 }
14092
14093 static void
14094 do_t_smc (void)
14095 {
14096 unsigned int value = inst.relocs[0].exp.X_add_number;
14097 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
14098 _("SMC is not permitted on this architecture"));
14099 constraint (inst.relocs[0].exp.X_op != O_constant,
14100 _("expression too complex"));
14101 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
14102
14103 inst.relocs[0].type = BFD_RELOC_UNUSED;
14104 inst.instruction |= (value & 0x000f) << 16;
14105
14106 /* PR gas/15623: SMC instructions must be last in an IT block. */
14107 set_pred_insn_type_last ();
14108 }
14109
14110 static void
14111 do_t_hvc (void)
14112 {
14113 unsigned int value = inst.relocs[0].exp.X_add_number;
14114
14115 inst.relocs[0].type = BFD_RELOC_UNUSED;
14116 inst.instruction |= (value & 0x0fff);
14117 inst.instruction |= (value & 0xf000) << 4;
14118 }
14119
14120 static void
14121 do_t_ssat_usat (int bias)
14122 {
14123 unsigned Rd, Rn;
14124
14125 Rd = inst.operands[0].reg;
14126 Rn = inst.operands[2].reg;
14127
14128 reject_bad_reg (Rd);
14129 reject_bad_reg (Rn);
14130
14131 inst.instruction |= Rd << 8;
14132 inst.instruction |= inst.operands[1].imm - bias;
14133 inst.instruction |= Rn << 16;
14134
14135 if (inst.operands[3].present)
14136 {
14137 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
14138
14139 inst.relocs[0].type = BFD_RELOC_UNUSED;
14140
14141 constraint (inst.relocs[0].exp.X_op != O_constant,
14142 _("expression too complex"));
14143
14144 if (shift_amount != 0)
14145 {
14146 constraint (shift_amount > 31,
14147 _("shift expression is too large"));
14148
14149 if (inst.operands[3].shift_kind == SHIFT_ASR)
14150 inst.instruction |= 0x00200000; /* sh bit. */
14151
14152 inst.instruction |= (shift_amount & 0x1c) << 10;
14153 inst.instruction |= (shift_amount & 0x03) << 6;
14154 }
14155 }
14156 }
14157
14158 static void
14159 do_t_ssat (void)
14160 {
14161 do_t_ssat_usat (1);
14162 }
14163
14164 static void
14165 do_t_ssat16 (void)
14166 {
14167 unsigned Rd, Rn;
14168
14169 Rd = inst.operands[0].reg;
14170 Rn = inst.operands[2].reg;
14171
14172 reject_bad_reg (Rd);
14173 reject_bad_reg (Rn);
14174
14175 inst.instruction |= Rd << 8;
14176 inst.instruction |= inst.operands[1].imm - 1;
14177 inst.instruction |= Rn << 16;
14178 }
14179
14180 static void
14181 do_t_strex (void)
14182 {
14183 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
14184 || inst.operands[2].postind || inst.operands[2].writeback
14185 || inst.operands[2].immisreg || inst.operands[2].shifted
14186 || inst.operands[2].negative,
14187 BAD_ADDR_MODE);
14188
14189 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
14190
14191 inst.instruction |= inst.operands[0].reg << 8;
14192 inst.instruction |= inst.operands[1].reg << 12;
14193 inst.instruction |= inst.operands[2].reg << 16;
14194 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
14195 }
14196
14197 static void
14198 do_t_strexd (void)
14199 {
14200 if (!inst.operands[2].present)
14201 inst.operands[2].reg = inst.operands[1].reg + 1;
14202
14203 constraint (inst.operands[0].reg == inst.operands[1].reg
14204 || inst.operands[0].reg == inst.operands[2].reg
14205 || inst.operands[0].reg == inst.operands[3].reg,
14206 BAD_OVERLAP);
14207
14208 inst.instruction |= inst.operands[0].reg;
14209 inst.instruction |= inst.operands[1].reg << 12;
14210 inst.instruction |= inst.operands[2].reg << 8;
14211 inst.instruction |= inst.operands[3].reg << 16;
14212 }
14213
14214 static void
14215 do_t_sxtah (void)
14216 {
14217 unsigned Rd, Rn, Rm;
14218
14219 Rd = inst.operands[0].reg;
14220 Rn = inst.operands[1].reg;
14221 Rm = inst.operands[2].reg;
14222
14223 reject_bad_reg (Rd);
14224 reject_bad_reg (Rn);
14225 reject_bad_reg (Rm);
14226
14227 inst.instruction |= Rd << 8;
14228 inst.instruction |= Rn << 16;
14229 inst.instruction |= Rm;
14230 inst.instruction |= inst.operands[3].imm << 4;
14231 }
14232
14233 static void
14234 do_t_sxth (void)
14235 {
14236 unsigned Rd, Rm;
14237
14238 Rd = inst.operands[0].reg;
14239 Rm = inst.operands[1].reg;
14240
14241 reject_bad_reg (Rd);
14242 reject_bad_reg (Rm);
14243
14244 if (inst.instruction <= 0xffff
14245 && inst.size_req != 4
14246 && Rd <= 7 && Rm <= 7
14247 && (!inst.operands[2].present || inst.operands[2].imm == 0))
14248 {
14249 inst.instruction = THUMB_OP16 (inst.instruction);
14250 inst.instruction |= Rd;
14251 inst.instruction |= Rm << 3;
14252 }
14253 else if (unified_syntax)
14254 {
14255 if (inst.instruction <= 0xffff)
14256 inst.instruction = THUMB_OP32 (inst.instruction);
14257 inst.instruction |= Rd << 8;
14258 inst.instruction |= Rm;
14259 inst.instruction |= inst.operands[2].imm << 4;
14260 }
14261 else
14262 {
14263 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
14264 _("Thumb encoding does not support rotation"));
14265 constraint (1, BAD_HIREG);
14266 }
14267 }
14268
14269 static void
14270 do_t_swi (void)
14271 {
14272 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
14273 }
14274
14275 static void
14276 do_t_tb (void)
14277 {
14278 unsigned Rn, Rm;
14279 int half;
14280
14281 half = (inst.instruction & 0x10) != 0;
14282 set_pred_insn_type_last ();
14283 constraint (inst.operands[0].immisreg,
14284 _("instruction requires register index"));
14285
14286 Rn = inst.operands[0].reg;
14287 Rm = inst.operands[0].imm;
14288
14289 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
14290 constraint (Rn == REG_SP, BAD_SP);
14291 reject_bad_reg (Rm);
14292
14293 constraint (!half && inst.operands[0].shifted,
14294 _("instruction does not allow shifted index"));
14295 inst.instruction |= (Rn << 16) | Rm;
14296 }
14297
14298 static void
14299 do_t_udf (void)
14300 {
14301 if (!inst.operands[0].present)
14302 inst.operands[0].imm = 0;
14303
14304 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
14305 {
14306 constraint (inst.size_req == 2,
14307 _("immediate value out of range"));
14308 inst.instruction = THUMB_OP32 (inst.instruction);
14309 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
14310 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
14311 }
14312 else
14313 {
14314 inst.instruction = THUMB_OP16 (inst.instruction);
14315 inst.instruction |= inst.operands[0].imm;
14316 }
14317
14318 set_pred_insn_type (NEUTRAL_IT_INSN);
14319 }
14320
14321
14322 static void
14323 do_t_usat (void)
14324 {
14325 do_t_ssat_usat (0);
14326 }
14327
14328 static void
14329 do_t_usat16 (void)
14330 {
14331 unsigned Rd, Rn;
14332
14333 Rd = inst.operands[0].reg;
14334 Rn = inst.operands[2].reg;
14335
14336 reject_bad_reg (Rd);
14337 reject_bad_reg (Rn);
14338
14339 inst.instruction |= Rd << 8;
14340 inst.instruction |= inst.operands[1].imm;
14341 inst.instruction |= Rn << 16;
14342 }
14343
14344 /* Checking the range of the branch offset (VAL) with NBITS bits
14345 and IS_SIGNED signedness. Also checks the LSB to be 0. */
14346 static int
14347 v8_1_branch_value_check (int val, int nbits, int is_signed)
14348 {
14349 gas_assert (nbits > 0 && nbits <= 32);
14350 if (is_signed)
14351 {
14352 int cmp = (1 << (nbits - 1));
14353 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
14354 return FAIL;
14355 }
14356 else
14357 {
14358 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
14359 return FAIL;
14360 }
14361 return SUCCESS;
14362 }
14363
14364 /* For branches in Armv8.1-M Mainline. */
14365 static void
14366 do_t_branch_future (void)
14367 {
14368 unsigned long insn = inst.instruction;
14369
14370 inst.instruction = THUMB_OP32 (inst.instruction);
14371 if (inst.operands[0].hasreloc == 0)
14372 {
14373 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
14374 as_bad (BAD_BRANCH_OFF);
14375
14376 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
14377 }
14378 else
14379 {
14380 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
14381 inst.relocs[0].pc_rel = 1;
14382 }
14383
14384 switch (insn)
14385 {
14386 case T_MNEM_bf:
14387 if (inst.operands[1].hasreloc == 0)
14388 {
14389 int val = inst.operands[1].imm;
14390 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
14391 as_bad (BAD_BRANCH_OFF);
14392
14393 int immA = (val & 0x0001f000) >> 12;
14394 int immB = (val & 0x00000ffc) >> 2;
14395 int immC = (val & 0x00000002) >> 1;
14396 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14397 }
14398 else
14399 {
14400 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
14401 inst.relocs[1].pc_rel = 1;
14402 }
14403 break;
14404
14405 case T_MNEM_bfl:
14406 if (inst.operands[1].hasreloc == 0)
14407 {
14408 int val = inst.operands[1].imm;
14409 if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL)
14410 as_bad (BAD_BRANCH_OFF);
14411
14412 int immA = (val & 0x0007f000) >> 12;
14413 int immB = (val & 0x00000ffc) >> 2;
14414 int immC = (val & 0x00000002) >> 1;
14415 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14416 }
14417 else
14418 {
14419 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
14420 inst.relocs[1].pc_rel = 1;
14421 }
14422 break;
14423
14424 case T_MNEM_bfcsel:
14425 /* Operand 1. */
14426 if (inst.operands[1].hasreloc == 0)
14427 {
14428 int val = inst.operands[1].imm;
14429 int immA = (val & 0x00001000) >> 12;
14430 int immB = (val & 0x00000ffc) >> 2;
14431 int immC = (val & 0x00000002) >> 1;
14432 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14433 }
14434 else
14435 {
14436 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
14437 inst.relocs[1].pc_rel = 1;
14438 }
14439
14440 /* Operand 2. */
14441 if (inst.operands[2].hasreloc == 0)
14442 {
14443 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
14444 int val2 = inst.operands[2].imm;
14445 int val0 = inst.operands[0].imm & 0x1f;
14446 int diff = val2 - val0;
14447 if (diff == 4)
14448 inst.instruction |= 1 << 17; /* T bit. */
14449 else if (diff != 2)
14450 as_bad (_("out of range label-relative fixup value"));
14451 }
14452 else
14453 {
14454 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
14455 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
14456 inst.relocs[2].pc_rel = 1;
14457 }
14458
14459 /* Operand 3. */
14460 constraint (inst.cond != COND_ALWAYS, BAD_COND);
14461 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
14462 break;
14463
14464 case T_MNEM_bfx:
14465 case T_MNEM_bflx:
14466 inst.instruction |= inst.operands[1].reg << 16;
14467 break;
14468
14469 default: abort ();
14470 }
14471 }
14472
14473 /* Helper function for do_t_loloop to handle relocations. */
14474 static void
14475 v8_1_loop_reloc (int is_le)
14476 {
14477 if (inst.relocs[0].exp.X_op == O_constant)
14478 {
14479 int value = inst.relocs[0].exp.X_add_number;
14480 value = (is_le) ? -value : value;
14481
14482 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
14483 as_bad (BAD_BRANCH_OFF);
14484
14485 int imml, immh;
14486
14487 immh = (value & 0x00000ffc) >> 2;
14488 imml = (value & 0x00000002) >> 1;
14489
14490 inst.instruction |= (imml << 11) | (immh << 1);
14491 }
14492 else
14493 {
14494 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
14495 inst.relocs[0].pc_rel = 1;
14496 }
14497 }
14498
14499 /* For shifts with four operands in MVE. */
14500 static void
14501 do_mve_scalar_shift1 (void)
14502 {
14503 unsigned int value = inst.operands[2].imm;
14504
14505 inst.instruction |= inst.operands[0].reg << 16;
14506 inst.instruction |= inst.operands[1].reg << 8;
14507
14508 /* Setting the bit for saturation. */
14509 inst.instruction |= ((value == 64) ? 0: 1) << 7;
14510
14511 /* Assuming Rm is already checked not to be 11x1. */
14512 constraint (inst.operands[3].reg == inst.operands[0].reg, BAD_OVERLAP);
14513 constraint (inst.operands[3].reg == inst.operands[1].reg, BAD_OVERLAP);
14514 inst.instruction |= inst.operands[3].reg << 12;
14515 }
14516
14517 /* For shifts in MVE. */
14518 static void
14519 do_mve_scalar_shift (void)
14520 {
14521 if (!inst.operands[2].present)
14522 {
14523 inst.operands[2] = inst.operands[1];
14524 inst.operands[1].reg = 0xf;
14525 }
14526
14527 inst.instruction |= inst.operands[0].reg << 16;
14528 inst.instruction |= inst.operands[1].reg << 8;
14529
14530 if (inst.operands[2].isreg)
14531 {
14532 /* Assuming Rm is already checked not to be 11x1. */
14533 constraint (inst.operands[2].reg == inst.operands[0].reg, BAD_OVERLAP);
14534 constraint (inst.operands[2].reg == inst.operands[1].reg, BAD_OVERLAP);
14535 inst.instruction |= inst.operands[2].reg << 12;
14536 }
14537 else
14538 {
14539 /* Assuming imm is already checked as [1,32]. */
14540 unsigned int value = inst.operands[2].imm;
14541 inst.instruction |= (value & 0x1c) << 10;
14542 inst.instruction |= (value & 0x03) << 6;
14543 /* Change last 4 bits from 0xd to 0xf. */
14544 inst.instruction |= 0x2;
14545 }
14546 }
14547
14548 /* MVE instruction encoder helpers. */
14549 #define M_MNEM_vabav 0xee800f01
14550 #define M_MNEM_vmladav 0xeef00e00
14551 #define M_MNEM_vmladava 0xeef00e20
14552 #define M_MNEM_vmladavx 0xeef01e00
14553 #define M_MNEM_vmladavax 0xeef01e20
14554 #define M_MNEM_vmlsdav 0xeef00e01
14555 #define M_MNEM_vmlsdava 0xeef00e21
14556 #define M_MNEM_vmlsdavx 0xeef01e01
14557 #define M_MNEM_vmlsdavax 0xeef01e21
14558 #define M_MNEM_vmullt 0xee011e00
14559 #define M_MNEM_vmullb 0xee010e00
14560 #define M_MNEM_vctp 0xf000e801
14561 #define M_MNEM_vst20 0xfc801e00
14562 #define M_MNEM_vst21 0xfc801e20
14563 #define M_MNEM_vst40 0xfc801e01
14564 #define M_MNEM_vst41 0xfc801e21
14565 #define M_MNEM_vst42 0xfc801e41
14566 #define M_MNEM_vst43 0xfc801e61
14567 #define M_MNEM_vld20 0xfc901e00
14568 #define M_MNEM_vld21 0xfc901e20
14569 #define M_MNEM_vld40 0xfc901e01
14570 #define M_MNEM_vld41 0xfc901e21
14571 #define M_MNEM_vld42 0xfc901e41
14572 #define M_MNEM_vld43 0xfc901e61
14573 #define M_MNEM_vstrb 0xec000e00
14574 #define M_MNEM_vstrh 0xec000e10
14575 #define M_MNEM_vstrw 0xec000e40
14576 #define M_MNEM_vstrd 0xec000e50
14577 #define M_MNEM_vldrb 0xec100e00
14578 #define M_MNEM_vldrh 0xec100e10
14579 #define M_MNEM_vldrw 0xec100e40
14580 #define M_MNEM_vldrd 0xec100e50
14581 #define M_MNEM_vmovlt 0xeea01f40
14582 #define M_MNEM_vmovlb 0xeea00f40
14583 #define M_MNEM_vmovnt 0xfe311e81
14584 #define M_MNEM_vmovnb 0xfe310e81
14585 #define M_MNEM_vadc 0xee300f00
14586 #define M_MNEM_vadci 0xee301f00
14587 #define M_MNEM_vbrsr 0xfe011e60
14588 #define M_MNEM_vaddlv 0xee890f00
14589 #define M_MNEM_vaddlva 0xee890f20
14590 #define M_MNEM_vaddv 0xeef10f00
14591 #define M_MNEM_vaddva 0xeef10f20
14592 #define M_MNEM_vddup 0xee011f6e
14593 #define M_MNEM_vdwdup 0xee011f60
14594 #define M_MNEM_vidup 0xee010f6e
14595 #define M_MNEM_viwdup 0xee010f60
14596 #define M_MNEM_vmaxv 0xeee20f00
14597 #define M_MNEM_vmaxav 0xeee00f00
14598 #define M_MNEM_vminv 0xeee20f80
14599 #define M_MNEM_vminav 0xeee00f80
14600 #define M_MNEM_vmlaldav 0xee800e00
14601 #define M_MNEM_vmlaldava 0xee800e20
14602 #define M_MNEM_vmlaldavx 0xee801e00
14603 #define M_MNEM_vmlaldavax 0xee801e20
14604 #define M_MNEM_vmlsldav 0xee800e01
14605 #define M_MNEM_vmlsldava 0xee800e21
14606 #define M_MNEM_vmlsldavx 0xee801e01
14607 #define M_MNEM_vmlsldavax 0xee801e21
14608 #define M_MNEM_vrmlaldavhx 0xee801f00
14609 #define M_MNEM_vrmlaldavhax 0xee801f20
14610 #define M_MNEM_vrmlsldavh 0xfe800e01
14611 #define M_MNEM_vrmlsldavha 0xfe800e21
14612 #define M_MNEM_vrmlsldavhx 0xfe801e01
14613 #define M_MNEM_vrmlsldavhax 0xfe801e21
14614 #define M_MNEM_vqmovnt 0xee331e01
14615 #define M_MNEM_vqmovnb 0xee330e01
14616 #define M_MNEM_vqmovunt 0xee311e81
14617 #define M_MNEM_vqmovunb 0xee310e81
14618 #define M_MNEM_vshrnt 0xee801fc1
14619 #define M_MNEM_vshrnb 0xee800fc1
14620 #define M_MNEM_vrshrnt 0xfe801fc1
14621 #define M_MNEM_vqshrnt 0xee801f40
14622 #define M_MNEM_vqshrnb 0xee800f40
14623 #define M_MNEM_vqshrunt 0xee801fc0
14624 #define M_MNEM_vqshrunb 0xee800fc0
14625 #define M_MNEM_vrshrnb 0xfe800fc1
14626 #define M_MNEM_vqrshrnt 0xee801f41
14627 #define M_MNEM_vqrshrnb 0xee800f41
14628 #define M_MNEM_vqrshrunt 0xfe801fc0
14629 #define M_MNEM_vqrshrunb 0xfe800fc0
14630
14631 /* Bfloat16 instruction encoder helpers. */
14632 #define B_MNEM_vfmat 0xfc300850
14633 #define B_MNEM_vfmab 0xfc300810
14634
14635 /* Neon instruction encoder helpers. */
14636
14637 /* Encodings for the different types for various Neon opcodes. */
14638
14639 /* An "invalid" code for the following tables. */
14640 #define N_INV -1u
14641
14642 struct neon_tab_entry
14643 {
14644 unsigned integer;
14645 unsigned float_or_poly;
14646 unsigned scalar_or_imm;
14647 };
14648
14649 /* Map overloaded Neon opcodes to their respective encodings. */
14650 #define NEON_ENC_TAB \
14651 X(vabd, 0x0000700, 0x1200d00, N_INV), \
14652 X(vabdl, 0x0800700, N_INV, N_INV), \
14653 X(vmax, 0x0000600, 0x0000f00, N_INV), \
14654 X(vmin, 0x0000610, 0x0200f00, N_INV), \
14655 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
14656 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
14657 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
14658 X(vadd, 0x0000800, 0x0000d00, N_INV), \
14659 X(vaddl, 0x0800000, N_INV, N_INV), \
14660 X(vsub, 0x1000800, 0x0200d00, N_INV), \
14661 X(vsubl, 0x0800200, N_INV, N_INV), \
14662 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
14663 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
14664 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
14665 /* Register variants of the following two instructions are encoded as
14666 vcge / vcgt with the operands reversed. */ \
14667 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
14668 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
14669 X(vfma, N_INV, 0x0000c10, N_INV), \
14670 X(vfms, N_INV, 0x0200c10, N_INV), \
14671 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
14672 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
14673 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
14674 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
14675 X(vmlal, 0x0800800, N_INV, 0x0800240), \
14676 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
14677 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
14678 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
14679 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
14680 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
14681 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
14682 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
14683 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
14684 X(vshl, 0x0000400, N_INV, 0x0800510), \
14685 X(vqshl, 0x0000410, N_INV, 0x0800710), \
14686 X(vand, 0x0000110, N_INV, 0x0800030), \
14687 X(vbic, 0x0100110, N_INV, 0x0800030), \
14688 X(veor, 0x1000110, N_INV, N_INV), \
14689 X(vorn, 0x0300110, N_INV, 0x0800010), \
14690 X(vorr, 0x0200110, N_INV, 0x0800010), \
14691 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
14692 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
14693 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
14694 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
14695 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
14696 X(vst1, 0x0000000, 0x0800000, N_INV), \
14697 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
14698 X(vst2, 0x0000100, 0x0800100, N_INV), \
14699 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
14700 X(vst3, 0x0000200, 0x0800200, N_INV), \
14701 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
14702 X(vst4, 0x0000300, 0x0800300, N_INV), \
14703 X(vmovn, 0x1b20200, N_INV, N_INV), \
14704 X(vtrn, 0x1b20080, N_INV, N_INV), \
14705 X(vqmovn, 0x1b20200, N_INV, N_INV), \
14706 X(vqmovun, 0x1b20240, N_INV, N_INV), \
14707 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
14708 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
14709 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
14710 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
14711 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
14712 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
14713 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
14714 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
14715 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
14716 X(vseleq, 0xe000a00, N_INV, N_INV), \
14717 X(vselvs, 0xe100a00, N_INV, N_INV), \
14718 X(vselge, 0xe200a00, N_INV, N_INV), \
14719 X(vselgt, 0xe300a00, N_INV, N_INV), \
14720 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
14721 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
14722 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
14723 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
14724 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
14725 X(aes, 0x3b00300, N_INV, N_INV), \
14726 X(sha3op, 0x2000c00, N_INV, N_INV), \
14727 X(sha1h, 0x3b902c0, N_INV, N_INV), \
14728 X(sha2op, 0x3ba0380, N_INV, N_INV)
14729
14730 enum neon_opc
14731 {
14732 #define X(OPC,I,F,S) N_MNEM_##OPC
14733 NEON_ENC_TAB
14734 #undef X
14735 };
14736
14737 static const struct neon_tab_entry neon_enc_tab[] =
14738 {
14739 #define X(OPC,I,F,S) { (I), (F), (S) }
14740 NEON_ENC_TAB
14741 #undef X
14742 };
14743
14744 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
14745 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14746 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14747 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14748 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14749 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14750 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14751 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14752 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14753 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14754 #define NEON_ENC_SINGLE_(X) \
14755 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
14756 #define NEON_ENC_DOUBLE_(X) \
14757 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
14758 #define NEON_ENC_FPV8_(X) \
14759 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
14760
14761 #define NEON_ENCODE(type, inst) \
14762 do \
14763 { \
14764 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
14765 inst.is_neon = 1; \
14766 } \
14767 while (0)
14768
14769 #define check_neon_suffixes \
14770 do \
14771 { \
14772 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
14773 { \
14774 as_bad (_("invalid neon suffix for non neon instruction")); \
14775 return; \
14776 } \
14777 } \
14778 while (0)
14779
14780 /* Define shapes for instruction operands. The following mnemonic characters
14781 are used in this table:
14782
14783 F - VFP S<n> register
14784 D - Neon D<n> register
14785 Q - Neon Q<n> register
14786 I - Immediate
14787 S - Scalar
14788 R - ARM register
14789 L - D<n> register list
14790
14791 This table is used to generate various data:
14792 - enumerations of the form NS_DDR to be used as arguments to
14793 neon_select_shape.
14794 - a table classifying shapes into single, double, quad, mixed.
14795 - a table used to drive neon_select_shape. */
14796
14797 #define NEON_SHAPE_DEF \
14798 X(4, (R, R, Q, Q), QUAD), \
14799 X(4, (Q, R, R, I), QUAD), \
14800 X(4, (R, R, S, S), QUAD), \
14801 X(4, (S, S, R, R), QUAD), \
14802 X(3, (Q, R, I), QUAD), \
14803 X(3, (I, Q, Q), QUAD), \
14804 X(3, (I, Q, R), QUAD), \
14805 X(3, (R, Q, Q), QUAD), \
14806 X(3, (D, D, D), DOUBLE), \
14807 X(3, (Q, Q, Q), QUAD), \
14808 X(3, (D, D, I), DOUBLE), \
14809 X(3, (Q, Q, I), QUAD), \
14810 X(3, (D, D, S), DOUBLE), \
14811 X(3, (Q, Q, S), QUAD), \
14812 X(3, (Q, Q, R), QUAD), \
14813 X(3, (R, R, Q), QUAD), \
14814 X(2, (R, Q), QUAD), \
14815 X(2, (D, D), DOUBLE), \
14816 X(2, (Q, Q), QUAD), \
14817 X(2, (D, S), DOUBLE), \
14818 X(2, (Q, S), QUAD), \
14819 X(2, (D, R), DOUBLE), \
14820 X(2, (Q, R), QUAD), \
14821 X(2, (D, I), DOUBLE), \
14822 X(2, (Q, I), QUAD), \
14823 X(3, (P, F, I), SINGLE), \
14824 X(3, (P, D, I), DOUBLE), \
14825 X(3, (P, Q, I), QUAD), \
14826 X(4, (P, F, F, I), SINGLE), \
14827 X(4, (P, D, D, I), DOUBLE), \
14828 X(4, (P, Q, Q, I), QUAD), \
14829 X(5, (P, F, F, F, I), SINGLE), \
14830 X(5, (P, D, D, D, I), DOUBLE), \
14831 X(5, (P, Q, Q, Q, I), QUAD), \
14832 X(3, (D, L, D), DOUBLE), \
14833 X(2, (D, Q), MIXED), \
14834 X(2, (Q, D), MIXED), \
14835 X(3, (D, Q, I), MIXED), \
14836 X(3, (Q, D, I), MIXED), \
14837 X(3, (Q, D, D), MIXED), \
14838 X(3, (D, Q, Q), MIXED), \
14839 X(3, (Q, Q, D), MIXED), \
14840 X(3, (Q, D, S), MIXED), \
14841 X(3, (D, Q, S), MIXED), \
14842 X(4, (D, D, D, I), DOUBLE), \
14843 X(4, (Q, Q, Q, I), QUAD), \
14844 X(4, (D, D, S, I), DOUBLE), \
14845 X(4, (Q, Q, S, I), QUAD), \
14846 X(2, (F, F), SINGLE), \
14847 X(3, (F, F, F), SINGLE), \
14848 X(2, (F, I), SINGLE), \
14849 X(2, (F, D), MIXED), \
14850 X(2, (D, F), MIXED), \
14851 X(3, (F, F, I), MIXED), \
14852 X(4, (R, R, F, F), SINGLE), \
14853 X(4, (F, F, R, R), SINGLE), \
14854 X(3, (D, R, R), DOUBLE), \
14855 X(3, (R, R, D), DOUBLE), \
14856 X(2, (S, R), SINGLE), \
14857 X(2, (R, S), SINGLE), \
14858 X(2, (F, R), SINGLE), \
14859 X(2, (R, F), SINGLE), \
14860 /* Used for MVE tail predicated loop instructions. */\
14861 X(2, (R, R), QUAD), \
14862 /* Half float shape supported so far. */\
14863 X (2, (H, D), MIXED), \
14864 X (2, (D, H), MIXED), \
14865 X (2, (H, F), MIXED), \
14866 X (2, (F, H), MIXED), \
14867 X (2, (H, H), HALF), \
14868 X (2, (H, R), HALF), \
14869 X (2, (R, H), HALF), \
14870 X (2, (H, I), HALF), \
14871 X (3, (H, H, H), HALF), \
14872 X (3, (H, F, I), MIXED), \
14873 X (3, (F, H, I), MIXED), \
14874 X (3, (D, H, H), MIXED), \
14875 X (3, (D, H, S), MIXED)
14876
14877 #define S2(A,B) NS_##A##B
14878 #define S3(A,B,C) NS_##A##B##C
14879 #define S4(A,B,C,D) NS_##A##B##C##D
14880 #define S5(A,B,C,D,E) NS_##A##B##C##D##E
14881
14882 #define X(N, L, C) S##N L
14883
14884 enum neon_shape
14885 {
14886 NEON_SHAPE_DEF,
14887 NS_NULL
14888 };
14889
14890 #undef X
14891 #undef S2
14892 #undef S3
14893 #undef S4
14894 #undef S5
14895
14896 enum neon_shape_class
14897 {
14898 SC_HALF,
14899 SC_SINGLE,
14900 SC_DOUBLE,
14901 SC_QUAD,
14902 SC_MIXED
14903 };
14904
14905 #define X(N, L, C) SC_##C
14906
14907 static enum neon_shape_class neon_shape_class[] =
14908 {
14909 NEON_SHAPE_DEF
14910 };
14911
14912 #undef X
14913
14914 enum neon_shape_el
14915 {
14916 SE_H,
14917 SE_F,
14918 SE_D,
14919 SE_Q,
14920 SE_I,
14921 SE_S,
14922 SE_R,
14923 SE_L,
14924 SE_P
14925 };
14926
14927 /* Register widths of above. */
14928 static unsigned neon_shape_el_size[] =
14929 {
14930 16,
14931 32,
14932 64,
14933 128,
14934 0,
14935 32,
14936 32,
14937 0,
14938 0
14939 };
14940
14941 struct neon_shape_info
14942 {
14943 unsigned els;
14944 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14945 };
14946
14947 #define S2(A,B) { SE_##A, SE_##B }
14948 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14949 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
14950 #define S5(A,B,C,D,E) { SE_##A, SE_##B, SE_##C, SE_##D, SE_##E }
14951
14952 #define X(N, L, C) { N, S##N L }
14953
14954 static struct neon_shape_info neon_shape_tab[] =
14955 {
14956 NEON_SHAPE_DEF
14957 };
14958
14959 #undef X
14960 #undef S2
14961 #undef S3
14962 #undef S4
14963 #undef S5
14964
14965 /* Bit masks used in type checking given instructions.
14966 'N_EQK' means the type must be the same as (or based on in some way) the key
14967 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14968 set, various other bits can be set as well in order to modify the meaning of
14969 the type constraint. */
14970
14971 enum neon_type_mask
14972 {
14973 N_S8 = 0x0000001,
14974 N_S16 = 0x0000002,
14975 N_S32 = 0x0000004,
14976 N_S64 = 0x0000008,
14977 N_U8 = 0x0000010,
14978 N_U16 = 0x0000020,
14979 N_U32 = 0x0000040,
14980 N_U64 = 0x0000080,
14981 N_I8 = 0x0000100,
14982 N_I16 = 0x0000200,
14983 N_I32 = 0x0000400,
14984 N_I64 = 0x0000800,
14985 N_8 = 0x0001000,
14986 N_16 = 0x0002000,
14987 N_32 = 0x0004000,
14988 N_64 = 0x0008000,
14989 N_P8 = 0x0010000,
14990 N_P16 = 0x0020000,
14991 N_F16 = 0x0040000,
14992 N_F32 = 0x0080000,
14993 N_F64 = 0x0100000,
14994 N_P64 = 0x0200000,
14995 N_BF16 = 0x0400000,
14996 N_KEY = 0x1000000, /* Key element (main type specifier). */
14997 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
14998 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
14999 N_UNT = 0x8000000, /* Must be explicitly untyped. */
15000 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
15001 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
15002 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
15003 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
15004 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
15005 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
15006 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
15007 N_UTYP = 0,
15008 N_MAX_NONSPECIAL = N_P64
15009 };
15010
15011 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
15012
15013 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
15014 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
15015 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
15016 #define N_S_32 (N_S8 | N_S16 | N_S32)
15017 #define N_F_16_32 (N_F16 | N_F32)
15018 #define N_SUF_32 (N_SU_32 | N_F_16_32)
15019 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
15020 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
15021 #define N_F_ALL (N_F16 | N_F32 | N_F64)
15022 #define N_I_MVE (N_I8 | N_I16 | N_I32)
15023 #define N_F_MVE (N_F16 | N_F32)
15024 #define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
15025
15026 /* Pass this as the first type argument to neon_check_type to ignore types
15027 altogether. */
15028 #define N_IGNORE_TYPE (N_KEY | N_EQK)
15029
15030 /* Select a "shape" for the current instruction (describing register types or
15031 sizes) from a list of alternatives. Return NS_NULL if the current instruction
15032 doesn't fit. For non-polymorphic shapes, checking is usually done as a
15033 function of operand parsing, so this function doesn't need to be called.
15034 Shapes should be listed in order of decreasing length. */
15035
15036 static enum neon_shape
15037 neon_select_shape (enum neon_shape shape, ...)
15038 {
15039 va_list ap;
15040 enum neon_shape first_shape = shape;
15041
15042 /* Fix missing optional operands. FIXME: we don't know at this point how
15043 many arguments we should have, so this makes the assumption that we have
15044 > 1. This is true of all current Neon opcodes, I think, but may not be
15045 true in the future. */
15046 if (!inst.operands[1].present)
15047 inst.operands[1] = inst.operands[0];
15048
15049 va_start (ap, shape);
15050
15051 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
15052 {
15053 unsigned j;
15054 int matches = 1;
15055
15056 for (j = 0; j < neon_shape_tab[shape].els; j++)
15057 {
15058 if (!inst.operands[j].present)
15059 {
15060 matches = 0;
15061 break;
15062 }
15063
15064 switch (neon_shape_tab[shape].el[j])
15065 {
15066 /* If a .f16, .16, .u16, .s16 type specifier is given over
15067 a VFP single precision register operand, it's essentially
15068 means only half of the register is used.
15069
15070 If the type specifier is given after the mnemonics, the
15071 information is stored in inst.vectype. If the type specifier
15072 is given after register operand, the information is stored
15073 in inst.operands[].vectype.
15074
15075 When there is only one type specifier, and all the register
15076 operands are the same type of hardware register, the type
15077 specifier applies to all register operands.
15078
15079 If no type specifier is given, the shape is inferred from
15080 operand information.
15081
15082 for example:
15083 vadd.f16 s0, s1, s2: NS_HHH
15084 vabs.f16 s0, s1: NS_HH
15085 vmov.f16 s0, r1: NS_HR
15086 vmov.f16 r0, s1: NS_RH
15087 vcvt.f16 r0, s1: NS_RH
15088 vcvt.f16.s32 s2, s2, #29: NS_HFI
15089 vcvt.f16.s32 s2, s2: NS_HF
15090 */
15091 case SE_H:
15092 if (!(inst.operands[j].isreg
15093 && inst.operands[j].isvec
15094 && inst.operands[j].issingle
15095 && !inst.operands[j].isquad
15096 && ((inst.vectype.elems == 1
15097 && inst.vectype.el[0].size == 16)
15098 || (inst.vectype.elems > 1
15099 && inst.vectype.el[j].size == 16)
15100 || (inst.vectype.elems == 0
15101 && inst.operands[j].vectype.type != NT_invtype
15102 && inst.operands[j].vectype.size == 16))))
15103 matches = 0;
15104 break;
15105
15106 case SE_F:
15107 if (!(inst.operands[j].isreg
15108 && inst.operands[j].isvec
15109 && inst.operands[j].issingle
15110 && !inst.operands[j].isquad
15111 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
15112 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
15113 || (inst.vectype.elems == 0
15114 && (inst.operands[j].vectype.size == 32
15115 || inst.operands[j].vectype.type == NT_invtype)))))
15116 matches = 0;
15117 break;
15118
15119 case SE_D:
15120 if (!(inst.operands[j].isreg
15121 && inst.operands[j].isvec
15122 && !inst.operands[j].isquad
15123 && !inst.operands[j].issingle))
15124 matches = 0;
15125 break;
15126
15127 case SE_R:
15128 if (!(inst.operands[j].isreg
15129 && !inst.operands[j].isvec))
15130 matches = 0;
15131 break;
15132
15133 case SE_Q:
15134 if (!(inst.operands[j].isreg
15135 && inst.operands[j].isvec
15136 && inst.operands[j].isquad
15137 && !inst.operands[j].issingle))
15138 matches = 0;
15139 break;
15140
15141 case SE_I:
15142 if (!(!inst.operands[j].isreg
15143 && !inst.operands[j].isscalar))
15144 matches = 0;
15145 break;
15146
15147 case SE_S:
15148 if (!(!inst.operands[j].isreg
15149 && inst.operands[j].isscalar))
15150 matches = 0;
15151 break;
15152
15153 case SE_P:
15154 case SE_L:
15155 break;
15156 }
15157 if (!matches)
15158 break;
15159 }
15160 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
15161 /* We've matched all the entries in the shape table, and we don't
15162 have any left over operands which have not been matched. */
15163 break;
15164 }
15165
15166 va_end (ap);
15167
15168 if (shape == NS_NULL && first_shape != NS_NULL)
15169 first_error (_("invalid instruction shape"));
15170
15171 return shape;
15172 }
15173
15174 /* True if SHAPE is predominantly a quadword operation (most of the time, this
15175 means the Q bit should be set). */
15176
15177 static int
15178 neon_quad (enum neon_shape shape)
15179 {
15180 return neon_shape_class[shape] == SC_QUAD;
15181 }
15182
15183 static void
15184 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
15185 unsigned *g_size)
15186 {
15187 /* Allow modification to be made to types which are constrained to be
15188 based on the key element, based on bits set alongside N_EQK. */
15189 if ((typebits & N_EQK) != 0)
15190 {
15191 if ((typebits & N_HLF) != 0)
15192 *g_size /= 2;
15193 else if ((typebits & N_DBL) != 0)
15194 *g_size *= 2;
15195 if ((typebits & N_SGN) != 0)
15196 *g_type = NT_signed;
15197 else if ((typebits & N_UNS) != 0)
15198 *g_type = NT_unsigned;
15199 else if ((typebits & N_INT) != 0)
15200 *g_type = NT_integer;
15201 else if ((typebits & N_FLT) != 0)
15202 *g_type = NT_float;
15203 else if ((typebits & N_SIZ) != 0)
15204 *g_type = NT_untyped;
15205 }
15206 }
15207
15208 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
15209 operand type, i.e. the single type specified in a Neon instruction when it
15210 is the only one given. */
15211
15212 static struct neon_type_el
15213 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
15214 {
15215 struct neon_type_el dest = *key;
15216
15217 gas_assert ((thisarg & N_EQK) != 0);
15218
15219 neon_modify_type_size (thisarg, &dest.type, &dest.size);
15220
15221 return dest;
15222 }
15223
15224 /* Convert Neon type and size into compact bitmask representation. */
15225
15226 static enum neon_type_mask
15227 type_chk_of_el_type (enum neon_el_type type, unsigned size)
15228 {
15229 switch (type)
15230 {
15231 case NT_untyped:
15232 switch (size)
15233 {
15234 case 8: return N_8;
15235 case 16: return N_16;
15236 case 32: return N_32;
15237 case 64: return N_64;
15238 default: ;
15239 }
15240 break;
15241
15242 case NT_integer:
15243 switch (size)
15244 {
15245 case 8: return N_I8;
15246 case 16: return N_I16;
15247 case 32: return N_I32;
15248 case 64: return N_I64;
15249 default: ;
15250 }
15251 break;
15252
15253 case NT_float:
15254 switch (size)
15255 {
15256 case 16: return N_F16;
15257 case 32: return N_F32;
15258 case 64: return N_F64;
15259 default: ;
15260 }
15261 break;
15262
15263 case NT_poly:
15264 switch (size)
15265 {
15266 case 8: return N_P8;
15267 case 16: return N_P16;
15268 case 64: return N_P64;
15269 default: ;
15270 }
15271 break;
15272
15273 case NT_signed:
15274 switch (size)
15275 {
15276 case 8: return N_S8;
15277 case 16: return N_S16;
15278 case 32: return N_S32;
15279 case 64: return N_S64;
15280 default: ;
15281 }
15282 break;
15283
15284 case NT_unsigned:
15285 switch (size)
15286 {
15287 case 8: return N_U8;
15288 case 16: return N_U16;
15289 case 32: return N_U32;
15290 case 64: return N_U64;
15291 default: ;
15292 }
15293 break;
15294
15295 case NT_bfloat:
15296 if (size == 16) return N_BF16;
15297 break;
15298
15299 default: ;
15300 }
15301
15302 return N_UTYP;
15303 }
15304
15305 /* Convert compact Neon bitmask type representation to a type and size. Only
15306 handles the case where a single bit is set in the mask. */
15307
15308 static int
15309 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
15310 enum neon_type_mask mask)
15311 {
15312 if ((mask & N_EQK) != 0)
15313 return FAIL;
15314
15315 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
15316 *size = 8;
15317 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16 | N_BF16))
15318 != 0)
15319 *size = 16;
15320 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
15321 *size = 32;
15322 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
15323 *size = 64;
15324 else
15325 return FAIL;
15326
15327 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
15328 *type = NT_signed;
15329 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
15330 *type = NT_unsigned;
15331 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
15332 *type = NT_integer;
15333 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
15334 *type = NT_untyped;
15335 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
15336 *type = NT_poly;
15337 else if ((mask & (N_F_ALL)) != 0)
15338 *type = NT_float;
15339 else if ((mask & (N_BF16)) != 0)
15340 *type = NT_bfloat;
15341 else
15342 return FAIL;
15343
15344 return SUCCESS;
15345 }
15346
15347 /* Modify a bitmask of allowed types. This is only needed for type
15348 relaxation. */
15349
15350 static unsigned
15351 modify_types_allowed (unsigned allowed, unsigned mods)
15352 {
15353 unsigned size;
15354 enum neon_el_type type;
15355 unsigned destmask;
15356 int i;
15357
15358 destmask = 0;
15359
15360 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
15361 {
15362 if (el_type_of_type_chk (&type, &size,
15363 (enum neon_type_mask) (allowed & i)) == SUCCESS)
15364 {
15365 neon_modify_type_size (mods, &type, &size);
15366 destmask |= type_chk_of_el_type (type, size);
15367 }
15368 }
15369
15370 return destmask;
15371 }
15372
15373 /* Check type and return type classification.
15374 The manual states (paraphrase): If one datatype is given, it indicates the
15375 type given in:
15376 - the second operand, if there is one
15377 - the operand, if there is no second operand
15378 - the result, if there are no operands.
15379 This isn't quite good enough though, so we use a concept of a "key" datatype
15380 which is set on a per-instruction basis, which is the one which matters when
15381 only one data type is written.
15382 Note: this function has side-effects (e.g. filling in missing operands). All
15383 Neon instructions should call it before performing bit encoding. */
15384
15385 static struct neon_type_el
15386 neon_check_type (unsigned els, enum neon_shape ns, ...)
15387 {
15388 va_list ap;
15389 unsigned i, pass, key_el = 0;
15390 unsigned types[NEON_MAX_TYPE_ELS];
15391 enum neon_el_type k_type = NT_invtype;
15392 unsigned k_size = -1u;
15393 struct neon_type_el badtype = {NT_invtype, -1};
15394 unsigned key_allowed = 0;
15395
15396 /* Optional registers in Neon instructions are always (not) in operand 1.
15397 Fill in the missing operand here, if it was omitted. */
15398 if (els > 1 && !inst.operands[1].present)
15399 inst.operands[1] = inst.operands[0];
15400
15401 /* Suck up all the varargs. */
15402 va_start (ap, ns);
15403 for (i = 0; i < els; i++)
15404 {
15405 unsigned thisarg = va_arg (ap, unsigned);
15406 if (thisarg == N_IGNORE_TYPE)
15407 {
15408 va_end (ap);
15409 return badtype;
15410 }
15411 types[i] = thisarg;
15412 if ((thisarg & N_KEY) != 0)
15413 key_el = i;
15414 }
15415 va_end (ap);
15416
15417 if (inst.vectype.elems > 0)
15418 for (i = 0; i < els; i++)
15419 if (inst.operands[i].vectype.type != NT_invtype)
15420 {
15421 first_error (_("types specified in both the mnemonic and operands"));
15422 return badtype;
15423 }
15424
15425 /* Duplicate inst.vectype elements here as necessary.
15426 FIXME: No idea if this is exactly the same as the ARM assembler,
15427 particularly when an insn takes one register and one non-register
15428 operand. */
15429 if (inst.vectype.elems == 1 && els > 1)
15430 {
15431 unsigned j;
15432 inst.vectype.elems = els;
15433 inst.vectype.el[key_el] = inst.vectype.el[0];
15434 for (j = 0; j < els; j++)
15435 if (j != key_el)
15436 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15437 types[j]);
15438 }
15439 else if (inst.vectype.elems == 0 && els > 0)
15440 {
15441 unsigned j;
15442 /* No types were given after the mnemonic, so look for types specified
15443 after each operand. We allow some flexibility here; as long as the
15444 "key" operand has a type, we can infer the others. */
15445 for (j = 0; j < els; j++)
15446 if (inst.operands[j].vectype.type != NT_invtype)
15447 inst.vectype.el[j] = inst.operands[j].vectype;
15448
15449 if (inst.operands[key_el].vectype.type != NT_invtype)
15450 {
15451 for (j = 0; j < els; j++)
15452 if (inst.operands[j].vectype.type == NT_invtype)
15453 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15454 types[j]);
15455 }
15456 else
15457 {
15458 first_error (_("operand types can't be inferred"));
15459 return badtype;
15460 }
15461 }
15462 else if (inst.vectype.elems != els)
15463 {
15464 first_error (_("type specifier has the wrong number of parts"));
15465 return badtype;
15466 }
15467
15468 for (pass = 0; pass < 2; pass++)
15469 {
15470 for (i = 0; i < els; i++)
15471 {
15472 unsigned thisarg = types[i];
15473 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
15474 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
15475 enum neon_el_type g_type = inst.vectype.el[i].type;
15476 unsigned g_size = inst.vectype.el[i].size;
15477
15478 /* Decay more-specific signed & unsigned types to sign-insensitive
15479 integer types if sign-specific variants are unavailable. */
15480 if ((g_type == NT_signed || g_type == NT_unsigned)
15481 && (types_allowed & N_SU_ALL) == 0)
15482 g_type = NT_integer;
15483
15484 /* If only untyped args are allowed, decay any more specific types to
15485 them. Some instructions only care about signs for some element
15486 sizes, so handle that properly. */
15487 if (((types_allowed & N_UNT) == 0)
15488 && ((g_size == 8 && (types_allowed & N_8) != 0)
15489 || (g_size == 16 && (types_allowed & N_16) != 0)
15490 || (g_size == 32 && (types_allowed & N_32) != 0)
15491 || (g_size == 64 && (types_allowed & N_64) != 0)))
15492 g_type = NT_untyped;
15493
15494 if (pass == 0)
15495 {
15496 if ((thisarg & N_KEY) != 0)
15497 {
15498 k_type = g_type;
15499 k_size = g_size;
15500 key_allowed = thisarg & ~N_KEY;
15501
15502 /* Check architecture constraint on FP16 extension. */
15503 if (k_size == 16
15504 && k_type == NT_float
15505 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15506 {
15507 inst.error = _(BAD_FP16);
15508 return badtype;
15509 }
15510 }
15511 }
15512 else
15513 {
15514 if ((thisarg & N_VFP) != 0)
15515 {
15516 enum neon_shape_el regshape;
15517 unsigned regwidth, match;
15518
15519 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
15520 if (ns == NS_NULL)
15521 {
15522 first_error (_("invalid instruction shape"));
15523 return badtype;
15524 }
15525 regshape = neon_shape_tab[ns].el[i];
15526 regwidth = neon_shape_el_size[regshape];
15527
15528 /* In VFP mode, operands must match register widths. If we
15529 have a key operand, use its width, else use the width of
15530 the current operand. */
15531 if (k_size != -1u)
15532 match = k_size;
15533 else
15534 match = g_size;
15535
15536 /* FP16 will use a single precision register. */
15537 if (regwidth == 32 && match == 16)
15538 {
15539 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15540 match = regwidth;
15541 else
15542 {
15543 inst.error = _(BAD_FP16);
15544 return badtype;
15545 }
15546 }
15547
15548 if (regwidth != match)
15549 {
15550 first_error (_("operand size must match register width"));
15551 return badtype;
15552 }
15553 }
15554
15555 if ((thisarg & N_EQK) == 0)
15556 {
15557 unsigned given_type = type_chk_of_el_type (g_type, g_size);
15558
15559 if ((given_type & types_allowed) == 0)
15560 {
15561 first_error (BAD_SIMD_TYPE);
15562 return badtype;
15563 }
15564 }
15565 else
15566 {
15567 enum neon_el_type mod_k_type = k_type;
15568 unsigned mod_k_size = k_size;
15569 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
15570 if (g_type != mod_k_type || g_size != mod_k_size)
15571 {
15572 first_error (_("inconsistent types in Neon instruction"));
15573 return badtype;
15574 }
15575 }
15576 }
15577 }
15578 }
15579
15580 return inst.vectype.el[key_el];
15581 }
15582
15583 /* Neon-style VFP instruction forwarding. */
15584
15585 /* Thumb VFP instructions have 0xE in the condition field. */
15586
15587 static void
15588 do_vfp_cond_or_thumb (void)
15589 {
15590 inst.is_neon = 1;
15591
15592 if (thumb_mode)
15593 inst.instruction |= 0xe0000000;
15594 else
15595 inst.instruction |= inst.cond << 28;
15596 }
15597
15598 /* Look up and encode a simple mnemonic, for use as a helper function for the
15599 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
15600 etc. It is assumed that operand parsing has already been done, and that the
15601 operands are in the form expected by the given opcode (this isn't necessarily
15602 the same as the form in which they were parsed, hence some massaging must
15603 take place before this function is called).
15604 Checks current arch version against that in the looked-up opcode. */
15605
15606 static void
15607 do_vfp_nsyn_opcode (const char *opname)
15608 {
15609 const struct asm_opcode *opcode;
15610
15611 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
15612
15613 if (!opcode)
15614 abort ();
15615
15616 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
15617 thumb_mode ? *opcode->tvariant : *opcode->avariant),
15618 _(BAD_FPU));
15619
15620 inst.is_neon = 1;
15621
15622 if (thumb_mode)
15623 {
15624 inst.instruction = opcode->tvalue;
15625 opcode->tencode ();
15626 }
15627 else
15628 {
15629 inst.instruction = (inst.cond << 28) | opcode->avalue;
15630 opcode->aencode ();
15631 }
15632 }
15633
15634 static void
15635 do_vfp_nsyn_add_sub (enum neon_shape rs)
15636 {
15637 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
15638
15639 if (rs == NS_FFF || rs == NS_HHH)
15640 {
15641 if (is_add)
15642 do_vfp_nsyn_opcode ("fadds");
15643 else
15644 do_vfp_nsyn_opcode ("fsubs");
15645
15646 /* ARMv8.2 fp16 instruction. */
15647 if (rs == NS_HHH)
15648 do_scalar_fp16_v82_encode ();
15649 }
15650 else
15651 {
15652 if (is_add)
15653 do_vfp_nsyn_opcode ("faddd");
15654 else
15655 do_vfp_nsyn_opcode ("fsubd");
15656 }
15657 }
15658
15659 /* Check operand types to see if this is a VFP instruction, and if so call
15660 PFN (). */
15661
15662 static int
15663 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
15664 {
15665 enum neon_shape rs;
15666 struct neon_type_el et;
15667
15668 switch (args)
15669 {
15670 case 2:
15671 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15672 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
15673 break;
15674
15675 case 3:
15676 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15677 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15678 N_F_ALL | N_KEY | N_VFP);
15679 break;
15680
15681 default:
15682 abort ();
15683 }
15684
15685 if (et.type != NT_invtype)
15686 {
15687 pfn (rs);
15688 return SUCCESS;
15689 }
15690
15691 inst.error = NULL;
15692 return FAIL;
15693 }
15694
15695 static void
15696 do_vfp_nsyn_mla_mls (enum neon_shape rs)
15697 {
15698 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
15699
15700 if (rs == NS_FFF || rs == NS_HHH)
15701 {
15702 if (is_mla)
15703 do_vfp_nsyn_opcode ("fmacs");
15704 else
15705 do_vfp_nsyn_opcode ("fnmacs");
15706
15707 /* ARMv8.2 fp16 instruction. */
15708 if (rs == NS_HHH)
15709 do_scalar_fp16_v82_encode ();
15710 }
15711 else
15712 {
15713 if (is_mla)
15714 do_vfp_nsyn_opcode ("fmacd");
15715 else
15716 do_vfp_nsyn_opcode ("fnmacd");
15717 }
15718 }
15719
15720 static void
15721 do_vfp_nsyn_fma_fms (enum neon_shape rs)
15722 {
15723 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
15724
15725 if (rs == NS_FFF || rs == NS_HHH)
15726 {
15727 if (is_fma)
15728 do_vfp_nsyn_opcode ("ffmas");
15729 else
15730 do_vfp_nsyn_opcode ("ffnmas");
15731
15732 /* ARMv8.2 fp16 instruction. */
15733 if (rs == NS_HHH)
15734 do_scalar_fp16_v82_encode ();
15735 }
15736 else
15737 {
15738 if (is_fma)
15739 do_vfp_nsyn_opcode ("ffmad");
15740 else
15741 do_vfp_nsyn_opcode ("ffnmad");
15742 }
15743 }
15744
15745 static void
15746 do_vfp_nsyn_mul (enum neon_shape rs)
15747 {
15748 if (rs == NS_FFF || rs == NS_HHH)
15749 {
15750 do_vfp_nsyn_opcode ("fmuls");
15751
15752 /* ARMv8.2 fp16 instruction. */
15753 if (rs == NS_HHH)
15754 do_scalar_fp16_v82_encode ();
15755 }
15756 else
15757 do_vfp_nsyn_opcode ("fmuld");
15758 }
15759
15760 static void
15761 do_vfp_nsyn_abs_neg (enum neon_shape rs)
15762 {
15763 int is_neg = (inst.instruction & 0x80) != 0;
15764 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
15765
15766 if (rs == NS_FF || rs == NS_HH)
15767 {
15768 if (is_neg)
15769 do_vfp_nsyn_opcode ("fnegs");
15770 else
15771 do_vfp_nsyn_opcode ("fabss");
15772
15773 /* ARMv8.2 fp16 instruction. */
15774 if (rs == NS_HH)
15775 do_scalar_fp16_v82_encode ();
15776 }
15777 else
15778 {
15779 if (is_neg)
15780 do_vfp_nsyn_opcode ("fnegd");
15781 else
15782 do_vfp_nsyn_opcode ("fabsd");
15783 }
15784 }
15785
15786 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
15787 insns belong to Neon, and are handled elsewhere. */
15788
15789 static void
15790 do_vfp_nsyn_ldm_stm (int is_dbmode)
15791 {
15792 int is_ldm = (inst.instruction & (1 << 20)) != 0;
15793 if (is_ldm)
15794 {
15795 if (is_dbmode)
15796 do_vfp_nsyn_opcode ("fldmdbs");
15797 else
15798 do_vfp_nsyn_opcode ("fldmias");
15799 }
15800 else
15801 {
15802 if (is_dbmode)
15803 do_vfp_nsyn_opcode ("fstmdbs");
15804 else
15805 do_vfp_nsyn_opcode ("fstmias");
15806 }
15807 }
15808
15809 static void
15810 do_vfp_nsyn_sqrt (void)
15811 {
15812 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15813 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
15814
15815 if (rs == NS_FF || rs == NS_HH)
15816 {
15817 do_vfp_nsyn_opcode ("fsqrts");
15818
15819 /* ARMv8.2 fp16 instruction. */
15820 if (rs == NS_HH)
15821 do_scalar_fp16_v82_encode ();
15822 }
15823 else
15824 do_vfp_nsyn_opcode ("fsqrtd");
15825 }
15826
15827 static void
15828 do_vfp_nsyn_div (void)
15829 {
15830 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15831 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15832 N_F_ALL | N_KEY | N_VFP);
15833
15834 if (rs == NS_FFF || rs == NS_HHH)
15835 {
15836 do_vfp_nsyn_opcode ("fdivs");
15837
15838 /* ARMv8.2 fp16 instruction. */
15839 if (rs == NS_HHH)
15840 do_scalar_fp16_v82_encode ();
15841 }
15842 else
15843 do_vfp_nsyn_opcode ("fdivd");
15844 }
15845
15846 static void
15847 do_vfp_nsyn_nmul (void)
15848 {
15849 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15850 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15851 N_F_ALL | N_KEY | N_VFP);
15852
15853 if (rs == NS_FFF || rs == NS_HHH)
15854 {
15855 NEON_ENCODE (SINGLE, inst);
15856 do_vfp_sp_dyadic ();
15857
15858 /* ARMv8.2 fp16 instruction. */
15859 if (rs == NS_HHH)
15860 do_scalar_fp16_v82_encode ();
15861 }
15862 else
15863 {
15864 NEON_ENCODE (DOUBLE, inst);
15865 do_vfp_dp_rd_rn_rm ();
15866 }
15867 do_vfp_cond_or_thumb ();
15868
15869 }
15870
15871 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15872 (0, 1, 2, 3). */
15873
15874 static unsigned
15875 neon_logbits (unsigned x)
15876 {
15877 return ffs (x) - 4;
15878 }
15879
15880 #define LOW4(R) ((R) & 0xf)
15881 #define HI1(R) (((R) >> 4) & 1)
15882 #define LOW1(R) ((R) & 0x1)
15883 #define HI4(R) (((R) >> 1) & 0xf)
15884
15885 static unsigned
15886 mve_get_vcmp_vpt_cond (struct neon_type_el et)
15887 {
15888 switch (et.type)
15889 {
15890 default:
15891 first_error (BAD_EL_TYPE);
15892 return 0;
15893 case NT_float:
15894 switch (inst.operands[0].imm)
15895 {
15896 default:
15897 first_error (_("invalid condition"));
15898 return 0;
15899 case 0x0:
15900 /* eq. */
15901 return 0;
15902 case 0x1:
15903 /* ne. */
15904 return 1;
15905 case 0xa:
15906 /* ge/ */
15907 return 4;
15908 case 0xb:
15909 /* lt. */
15910 return 5;
15911 case 0xc:
15912 /* gt. */
15913 return 6;
15914 case 0xd:
15915 /* le. */
15916 return 7;
15917 }
15918 case NT_integer:
15919 /* only accept eq and ne. */
15920 if (inst.operands[0].imm > 1)
15921 {
15922 first_error (_("invalid condition"));
15923 return 0;
15924 }
15925 return inst.operands[0].imm;
15926 case NT_unsigned:
15927 if (inst.operands[0].imm == 0x2)
15928 return 2;
15929 else if (inst.operands[0].imm == 0x8)
15930 return 3;
15931 else
15932 {
15933 first_error (_("invalid condition"));
15934 return 0;
15935 }
15936 case NT_signed:
15937 switch (inst.operands[0].imm)
15938 {
15939 default:
15940 first_error (_("invalid condition"));
15941 return 0;
15942 case 0xa:
15943 /* ge. */
15944 return 4;
15945 case 0xb:
15946 /* lt. */
15947 return 5;
15948 case 0xc:
15949 /* gt. */
15950 return 6;
15951 case 0xd:
15952 /* le. */
15953 return 7;
15954 }
15955 }
15956 /* Should be unreachable. */
15957 abort ();
15958 }
15959
15960 /* For VCTP (create vector tail predicate) in MVE. */
15961 static void
15962 do_mve_vctp (void)
15963 {
15964 int dt = 0;
15965 unsigned size = 0x0;
15966
15967 if (inst.cond > COND_ALWAYS)
15968 inst.pred_insn_type = INSIDE_VPT_INSN;
15969 else
15970 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15971
15972 /* This is a typical MVE instruction which has no type but have size 8, 16,
15973 32 and 64. For instructions with no type, inst.vectype.el[j].type is set
15974 to NT_untyped and size is updated in inst.vectype.el[j].size. */
15975 if ((inst.operands[0].present) && (inst.vectype.el[0].type == NT_untyped))
15976 dt = inst.vectype.el[0].size;
15977
15978 /* Setting this does not indicate an actual NEON instruction, but only
15979 indicates that the mnemonic accepts neon-style type suffixes. */
15980 inst.is_neon = 1;
15981
15982 switch (dt)
15983 {
15984 case 8:
15985 break;
15986 case 16:
15987 size = 0x1; break;
15988 case 32:
15989 size = 0x2; break;
15990 case 64:
15991 size = 0x3; break;
15992 default:
15993 first_error (_("Type is not allowed for this instruction"));
15994 }
15995 inst.instruction |= size << 20;
15996 inst.instruction |= inst.operands[0].reg << 16;
15997 }
15998
15999 static void
16000 do_mve_vpt (void)
16001 {
16002 /* We are dealing with a vector predicated block. */
16003 if (inst.operands[0].present)
16004 {
16005 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
16006 struct neon_type_el et
16007 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16008 N_EQK);
16009
16010 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16011
16012 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16013
16014 if (et.type == NT_invtype)
16015 return;
16016
16017 if (et.type == NT_float)
16018 {
16019 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16020 BAD_FPU);
16021 constraint (et.size != 16 && et.size != 32, BAD_EL_TYPE);
16022 inst.instruction |= (et.size == 16) << 28;
16023 inst.instruction |= 0x3 << 20;
16024 }
16025 else
16026 {
16027 constraint (et.size != 8 && et.size != 16 && et.size != 32,
16028 BAD_EL_TYPE);
16029 inst.instruction |= 1 << 28;
16030 inst.instruction |= neon_logbits (et.size) << 20;
16031 }
16032
16033 if (inst.operands[2].isquad)
16034 {
16035 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16036 inst.instruction |= LOW4 (inst.operands[2].reg);
16037 inst.instruction |= (fcond & 0x2) >> 1;
16038 }
16039 else
16040 {
16041 if (inst.operands[2].reg == REG_SP)
16042 as_tsktsk (MVE_BAD_SP);
16043 inst.instruction |= 1 << 6;
16044 inst.instruction |= (fcond & 0x2) << 4;
16045 inst.instruction |= inst.operands[2].reg;
16046 }
16047 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16048 inst.instruction |= (fcond & 0x4) << 10;
16049 inst.instruction |= (fcond & 0x1) << 7;
16050
16051 }
16052 set_pred_insn_type (VPT_INSN);
16053 now_pred.cc = 0;
16054 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
16055 | ((inst.instruction & 0xe000) >> 13);
16056 now_pred.warn_deprecated = FALSE;
16057 now_pred.type = VECTOR_PRED;
16058 inst.is_neon = 1;
16059 }
16060
16061 static void
16062 do_mve_vcmp (void)
16063 {
16064 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
16065 if (!inst.operands[1].isreg || !inst.operands[1].isquad)
16066 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
16067 if (!inst.operands[2].present)
16068 first_error (_("MVE vector or ARM register expected"));
16069 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16070
16071 /* Deal with 'else' conditional MVE's vcmp, it will be parsed as vcmpe. */
16072 if ((inst.instruction & 0xffffffff) == N_MNEM_vcmpe
16073 && inst.operands[1].isquad)
16074 {
16075 inst.instruction = N_MNEM_vcmp;
16076 inst.cond = 0x10;
16077 }
16078
16079 if (inst.cond > COND_ALWAYS)
16080 inst.pred_insn_type = INSIDE_VPT_INSN;
16081 else
16082 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16083
16084 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
16085 struct neon_type_el et
16086 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16087 N_EQK);
16088
16089 constraint (rs == NS_IQR && inst.operands[2].reg == REG_PC
16090 && !inst.operands[2].iszr, BAD_PC);
16091
16092 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16093
16094 inst.instruction = 0xee010f00;
16095 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16096 inst.instruction |= (fcond & 0x4) << 10;
16097 inst.instruction |= (fcond & 0x1) << 7;
16098 if (et.type == NT_float)
16099 {
16100 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16101 BAD_FPU);
16102 inst.instruction |= (et.size == 16) << 28;
16103 inst.instruction |= 0x3 << 20;
16104 }
16105 else
16106 {
16107 inst.instruction |= 1 << 28;
16108 inst.instruction |= neon_logbits (et.size) << 20;
16109 }
16110 if (inst.operands[2].isquad)
16111 {
16112 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16113 inst.instruction |= (fcond & 0x2) >> 1;
16114 inst.instruction |= LOW4 (inst.operands[2].reg);
16115 }
16116 else
16117 {
16118 if (inst.operands[2].reg == REG_SP)
16119 as_tsktsk (MVE_BAD_SP);
16120 inst.instruction |= 1 << 6;
16121 inst.instruction |= (fcond & 0x2) << 4;
16122 inst.instruction |= inst.operands[2].reg;
16123 }
16124
16125 inst.is_neon = 1;
16126 return;
16127 }
16128
16129 static void
16130 do_mve_vmaxa_vmina (void)
16131 {
16132 if (inst.cond > COND_ALWAYS)
16133 inst.pred_insn_type = INSIDE_VPT_INSN;
16134 else
16135 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16136
16137 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16138 struct neon_type_el et
16139 = neon_check_type (2, rs, N_EQK, N_KEY | N_S8 | N_S16 | N_S32);
16140
16141 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16142 inst.instruction |= neon_logbits (et.size) << 18;
16143 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16144 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16145 inst.instruction |= LOW4 (inst.operands[1].reg);
16146 inst.is_neon = 1;
16147 }
16148
16149 static void
16150 do_mve_vfmas (void)
16151 {
16152 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16153 struct neon_type_el et
16154 = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, N_EQK);
16155
16156 if (inst.cond > COND_ALWAYS)
16157 inst.pred_insn_type = INSIDE_VPT_INSN;
16158 else
16159 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16160
16161 if (inst.operands[2].reg == REG_SP)
16162 as_tsktsk (MVE_BAD_SP);
16163 else if (inst.operands[2].reg == REG_PC)
16164 as_tsktsk (MVE_BAD_PC);
16165
16166 inst.instruction |= (et.size == 16) << 28;
16167 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16168 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16169 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16170 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16171 inst.instruction |= inst.operands[2].reg;
16172 inst.is_neon = 1;
16173 }
16174
16175 static void
16176 do_mve_viddup (void)
16177 {
16178 if (inst.cond > COND_ALWAYS)
16179 inst.pred_insn_type = INSIDE_VPT_INSN;
16180 else
16181 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16182
16183 unsigned imm = inst.relocs[0].exp.X_add_number;
16184 constraint (imm != 1 && imm != 2 && imm != 4 && imm != 8,
16185 _("immediate must be either 1, 2, 4 or 8"));
16186
16187 enum neon_shape rs;
16188 struct neon_type_el et;
16189 unsigned Rm;
16190 if (inst.instruction == M_MNEM_vddup || inst.instruction == M_MNEM_vidup)
16191 {
16192 rs = neon_select_shape (NS_QRI, NS_NULL);
16193 et = neon_check_type (2, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK);
16194 Rm = 7;
16195 }
16196 else
16197 {
16198 constraint ((inst.operands[2].reg % 2) != 1, BAD_EVEN);
16199 if (inst.operands[2].reg == REG_SP)
16200 as_tsktsk (MVE_BAD_SP);
16201 else if (inst.operands[2].reg == REG_PC)
16202 first_error (BAD_PC);
16203
16204 rs = neon_select_shape (NS_QRRI, NS_NULL);
16205 et = neon_check_type (3, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK, N_EQK);
16206 Rm = inst.operands[2].reg >> 1;
16207 }
16208 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16209 inst.instruction |= neon_logbits (et.size) << 20;
16210 inst.instruction |= inst.operands[1].reg << 16;
16211 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16212 inst.instruction |= (imm > 2) << 7;
16213 inst.instruction |= Rm << 1;
16214 inst.instruction |= (imm == 2 || imm == 8);
16215 inst.is_neon = 1;
16216 }
16217
16218 static void
16219 do_mve_vmlas (void)
16220 {
16221 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16222 struct neon_type_el et
16223 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16224
16225 if (inst.operands[2].reg == REG_PC)
16226 as_tsktsk (MVE_BAD_PC);
16227 else if (inst.operands[2].reg == REG_SP)
16228 as_tsktsk (MVE_BAD_SP);
16229
16230 if (inst.cond > COND_ALWAYS)
16231 inst.pred_insn_type = INSIDE_VPT_INSN;
16232 else
16233 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16234
16235 inst.instruction |= (et.type == NT_unsigned) << 28;
16236 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16237 inst.instruction |= neon_logbits (et.size) << 20;
16238 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16239 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16240 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16241 inst.instruction |= inst.operands[2].reg;
16242 inst.is_neon = 1;
16243 }
16244
16245 static void
16246 do_mve_vshll (void)
16247 {
16248 struct neon_type_el et
16249 = neon_check_type (2, NS_QQI, N_EQK, N_S8 | N_U8 | N_S16 | N_U16 | N_KEY);
16250
16251 if (inst.cond > COND_ALWAYS)
16252 inst.pred_insn_type = INSIDE_VPT_INSN;
16253 else
16254 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16255
16256 int imm = inst.operands[2].imm;
16257 constraint (imm < 1 || (unsigned)imm > et.size,
16258 _("immediate value out of range"));
16259
16260 if ((unsigned)imm == et.size)
16261 {
16262 inst.instruction |= neon_logbits (et.size) << 18;
16263 inst.instruction |= 0x110001;
16264 }
16265 else
16266 {
16267 inst.instruction |= (et.size + imm) << 16;
16268 inst.instruction |= 0x800140;
16269 }
16270
16271 inst.instruction |= (et.type == NT_unsigned) << 28;
16272 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16273 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16274 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16275 inst.instruction |= LOW4 (inst.operands[1].reg);
16276 inst.is_neon = 1;
16277 }
16278
16279 static void
16280 do_mve_vshlc (void)
16281 {
16282 if (inst.cond > COND_ALWAYS)
16283 inst.pred_insn_type = INSIDE_VPT_INSN;
16284 else
16285 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16286
16287 if (inst.operands[1].reg == REG_PC)
16288 as_tsktsk (MVE_BAD_PC);
16289 else if (inst.operands[1].reg == REG_SP)
16290 as_tsktsk (MVE_BAD_SP);
16291
16292 int imm = inst.operands[2].imm;
16293 constraint (imm < 1 || imm > 32, _("immediate value out of range"));
16294
16295 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16296 inst.instruction |= (imm & 0x1f) << 16;
16297 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16298 inst.instruction |= inst.operands[1].reg;
16299 inst.is_neon = 1;
16300 }
16301
16302 static void
16303 do_mve_vshrn (void)
16304 {
16305 unsigned types;
16306 switch (inst.instruction)
16307 {
16308 case M_MNEM_vshrnt:
16309 case M_MNEM_vshrnb:
16310 case M_MNEM_vrshrnt:
16311 case M_MNEM_vrshrnb:
16312 types = N_I16 | N_I32;
16313 break;
16314 case M_MNEM_vqshrnt:
16315 case M_MNEM_vqshrnb:
16316 case M_MNEM_vqrshrnt:
16317 case M_MNEM_vqrshrnb:
16318 types = N_U16 | N_U32 | N_S16 | N_S32;
16319 break;
16320 case M_MNEM_vqshrunt:
16321 case M_MNEM_vqshrunb:
16322 case M_MNEM_vqrshrunt:
16323 case M_MNEM_vqrshrunb:
16324 types = N_S16 | N_S32;
16325 break;
16326 default:
16327 abort ();
16328 }
16329
16330 struct neon_type_el et = neon_check_type (2, NS_QQI, N_EQK, types | N_KEY);
16331
16332 if (inst.cond > COND_ALWAYS)
16333 inst.pred_insn_type = INSIDE_VPT_INSN;
16334 else
16335 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16336
16337 unsigned Qd = inst.operands[0].reg;
16338 unsigned Qm = inst.operands[1].reg;
16339 unsigned imm = inst.operands[2].imm;
16340 constraint (imm < 1 || ((unsigned) imm) > (et.size / 2),
16341 et.size == 16
16342 ? _("immediate operand expected in the range [1,8]")
16343 : _("immediate operand expected in the range [1,16]"));
16344
16345 inst.instruction |= (et.type == NT_unsigned) << 28;
16346 inst.instruction |= HI1 (Qd) << 22;
16347 inst.instruction |= (et.size - imm) << 16;
16348 inst.instruction |= LOW4 (Qd) << 12;
16349 inst.instruction |= HI1 (Qm) << 5;
16350 inst.instruction |= LOW4 (Qm);
16351 inst.is_neon = 1;
16352 }
16353
16354 static void
16355 do_mve_vqmovn (void)
16356 {
16357 struct neon_type_el et;
16358 if (inst.instruction == M_MNEM_vqmovnt
16359 || inst.instruction == M_MNEM_vqmovnb)
16360 et = neon_check_type (2, NS_QQ, N_EQK,
16361 N_U16 | N_U32 | N_S16 | N_S32 | N_KEY);
16362 else
16363 et = neon_check_type (2, NS_QQ, N_EQK, N_S16 | N_S32 | N_KEY);
16364
16365 if (inst.cond > COND_ALWAYS)
16366 inst.pred_insn_type = INSIDE_VPT_INSN;
16367 else
16368 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16369
16370 inst.instruction |= (et.type == NT_unsigned) << 28;
16371 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16372 inst.instruction |= (et.size == 32) << 18;
16373 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16374 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16375 inst.instruction |= LOW4 (inst.operands[1].reg);
16376 inst.is_neon = 1;
16377 }
16378
16379 static void
16380 do_mve_vpsel (void)
16381 {
16382 neon_select_shape (NS_QQQ, NS_NULL);
16383
16384 if (inst.cond > COND_ALWAYS)
16385 inst.pred_insn_type = INSIDE_VPT_INSN;
16386 else
16387 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16388
16389 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16390 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16391 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16392 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16393 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16394 inst.instruction |= LOW4 (inst.operands[2].reg);
16395 inst.is_neon = 1;
16396 }
16397
16398 static void
16399 do_mve_vpnot (void)
16400 {
16401 if (inst.cond > COND_ALWAYS)
16402 inst.pred_insn_type = INSIDE_VPT_INSN;
16403 else
16404 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16405 }
16406
16407 static void
16408 do_mve_vmaxnma_vminnma (void)
16409 {
16410 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16411 struct neon_type_el et
16412 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
16413
16414 if (inst.cond > COND_ALWAYS)
16415 inst.pred_insn_type = INSIDE_VPT_INSN;
16416 else
16417 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16418
16419 inst.instruction |= (et.size == 16) << 28;
16420 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16421 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16422 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16423 inst.instruction |= LOW4 (inst.operands[1].reg);
16424 inst.is_neon = 1;
16425 }
16426
16427 static void
16428 do_mve_vcmul (void)
16429 {
16430 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
16431 struct neon_type_el et
16432 = neon_check_type (3, rs, N_EQK, N_EQK, N_F_MVE | N_KEY);
16433
16434 if (inst.cond > COND_ALWAYS)
16435 inst.pred_insn_type = INSIDE_VPT_INSN;
16436 else
16437 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16438
16439 unsigned rot = inst.relocs[0].exp.X_add_number;
16440 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
16441 _("immediate out of range"));
16442
16443 if (et.size == 32 && (inst.operands[0].reg == inst.operands[1].reg
16444 || inst.operands[0].reg == inst.operands[2].reg))
16445 as_tsktsk (BAD_MVE_SRCDEST);
16446
16447 inst.instruction |= (et.size == 32) << 28;
16448 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16449 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16450 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16451 inst.instruction |= (rot > 90) << 12;
16452 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16453 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16454 inst.instruction |= LOW4 (inst.operands[2].reg);
16455 inst.instruction |= (rot == 90 || rot == 270);
16456 inst.is_neon = 1;
16457 }
16458
16459 /* To handle the Low Overhead Loop instructions
16460 in Armv8.1-M Mainline and MVE. */
16461 static void
16462 do_t_loloop (void)
16463 {
16464 unsigned long insn = inst.instruction;
16465
16466 inst.instruction = THUMB_OP32 (inst.instruction);
16467
16468 if (insn == T_MNEM_lctp)
16469 return;
16470
16471 set_pred_insn_type (MVE_OUTSIDE_PRED_INSN);
16472
16473 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16474 {
16475 struct neon_type_el et
16476 = neon_check_type (2, NS_RR, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16477 inst.instruction |= neon_logbits (et.size) << 20;
16478 inst.is_neon = 1;
16479 }
16480
16481 switch (insn)
16482 {
16483 case T_MNEM_letp:
16484 constraint (!inst.operands[0].present,
16485 _("expected LR"));
16486 /* fall through. */
16487 case T_MNEM_le:
16488 /* le <label>. */
16489 if (!inst.operands[0].present)
16490 inst.instruction |= 1 << 21;
16491
16492 v8_1_loop_reloc (TRUE);
16493 break;
16494
16495 case T_MNEM_wls:
16496 case T_MNEM_wlstp:
16497 v8_1_loop_reloc (FALSE);
16498 /* fall through. */
16499 case T_MNEM_dlstp:
16500 case T_MNEM_dls:
16501 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
16502
16503 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16504 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16505 else if (inst.operands[1].reg == REG_PC)
16506 as_tsktsk (MVE_BAD_PC);
16507 if (inst.operands[1].reg == REG_SP)
16508 as_tsktsk (MVE_BAD_SP);
16509
16510 inst.instruction |= (inst.operands[1].reg << 16);
16511 break;
16512
16513 default:
16514 abort ();
16515 }
16516 }
16517
16518
16519 static void
16520 do_vfp_nsyn_cmp (void)
16521 {
16522 enum neon_shape rs;
16523 if (!inst.operands[0].isreg)
16524 {
16525 do_mve_vcmp ();
16526 return;
16527 }
16528 else
16529 {
16530 constraint (inst.operands[2].present, BAD_SYNTAX);
16531 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
16532 BAD_FPU);
16533 }
16534
16535 if (inst.operands[1].isreg)
16536 {
16537 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
16538 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
16539
16540 if (rs == NS_FF || rs == NS_HH)
16541 {
16542 NEON_ENCODE (SINGLE, inst);
16543 do_vfp_sp_monadic ();
16544 }
16545 else
16546 {
16547 NEON_ENCODE (DOUBLE, inst);
16548 do_vfp_dp_rd_rm ();
16549 }
16550 }
16551 else
16552 {
16553 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
16554 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
16555
16556 switch (inst.instruction & 0x0fffffff)
16557 {
16558 case N_MNEM_vcmp:
16559 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
16560 break;
16561 case N_MNEM_vcmpe:
16562 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
16563 break;
16564 default:
16565 abort ();
16566 }
16567
16568 if (rs == NS_FI || rs == NS_HI)
16569 {
16570 NEON_ENCODE (SINGLE, inst);
16571 do_vfp_sp_compare_z ();
16572 }
16573 else
16574 {
16575 NEON_ENCODE (DOUBLE, inst);
16576 do_vfp_dp_rd ();
16577 }
16578 }
16579 do_vfp_cond_or_thumb ();
16580
16581 /* ARMv8.2 fp16 instruction. */
16582 if (rs == NS_HI || rs == NS_HH)
16583 do_scalar_fp16_v82_encode ();
16584 }
16585
16586 static void
16587 nsyn_insert_sp (void)
16588 {
16589 inst.operands[1] = inst.operands[0];
16590 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
16591 inst.operands[0].reg = REG_SP;
16592 inst.operands[0].isreg = 1;
16593 inst.operands[0].writeback = 1;
16594 inst.operands[0].present = 1;
16595 }
16596
16597 /* Fix up Neon data-processing instructions, ORing in the correct bits for
16598 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
16599
16600 static void
16601 neon_dp_fixup (struct arm_it* insn)
16602 {
16603 unsigned int i = insn->instruction;
16604 insn->is_neon = 1;
16605
16606 if (thumb_mode)
16607 {
16608 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
16609 if (i & (1 << 24))
16610 i |= 1 << 28;
16611
16612 i &= ~(1 << 24);
16613
16614 i |= 0xef000000;
16615 }
16616 else
16617 i |= 0xf2000000;
16618
16619 insn->instruction = i;
16620 }
16621
16622 static void
16623 mve_encode_qqr (int size, int U, int fp)
16624 {
16625 if (inst.operands[2].reg == REG_SP)
16626 as_tsktsk (MVE_BAD_SP);
16627 else if (inst.operands[2].reg == REG_PC)
16628 as_tsktsk (MVE_BAD_PC);
16629
16630 if (fp)
16631 {
16632 /* vadd. */
16633 if (((unsigned)inst.instruction) == 0xd00)
16634 inst.instruction = 0xee300f40;
16635 /* vsub. */
16636 else if (((unsigned)inst.instruction) == 0x200d00)
16637 inst.instruction = 0xee301f40;
16638 /* vmul. */
16639 else if (((unsigned)inst.instruction) == 0x1000d10)
16640 inst.instruction = 0xee310e60;
16641
16642 /* Setting size which is 1 for F16 and 0 for F32. */
16643 inst.instruction |= (size == 16) << 28;
16644 }
16645 else
16646 {
16647 /* vadd. */
16648 if (((unsigned)inst.instruction) == 0x800)
16649 inst.instruction = 0xee010f40;
16650 /* vsub. */
16651 else if (((unsigned)inst.instruction) == 0x1000800)
16652 inst.instruction = 0xee011f40;
16653 /* vhadd. */
16654 else if (((unsigned)inst.instruction) == 0)
16655 inst.instruction = 0xee000f40;
16656 /* vhsub. */
16657 else if (((unsigned)inst.instruction) == 0x200)
16658 inst.instruction = 0xee001f40;
16659 /* vmla. */
16660 else if (((unsigned)inst.instruction) == 0x900)
16661 inst.instruction = 0xee010e40;
16662 /* vmul. */
16663 else if (((unsigned)inst.instruction) == 0x910)
16664 inst.instruction = 0xee011e60;
16665 /* vqadd. */
16666 else if (((unsigned)inst.instruction) == 0x10)
16667 inst.instruction = 0xee000f60;
16668 /* vqsub. */
16669 else if (((unsigned)inst.instruction) == 0x210)
16670 inst.instruction = 0xee001f60;
16671 /* vqrdmlah. */
16672 else if (((unsigned)inst.instruction) == 0x3000b10)
16673 inst.instruction = 0xee000e40;
16674 /* vqdmulh. */
16675 else if (((unsigned)inst.instruction) == 0x0000b00)
16676 inst.instruction = 0xee010e60;
16677 /* vqrdmulh. */
16678 else if (((unsigned)inst.instruction) == 0x1000b00)
16679 inst.instruction = 0xfe010e60;
16680
16681 /* Set U-bit. */
16682 inst.instruction |= U << 28;
16683
16684 /* Setting bits for size. */
16685 inst.instruction |= neon_logbits (size) << 20;
16686 }
16687 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16688 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16689 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16690 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16691 inst.instruction |= inst.operands[2].reg;
16692 inst.is_neon = 1;
16693 }
16694
16695 static void
16696 mve_encode_rqq (unsigned bit28, unsigned size)
16697 {
16698 inst.instruction |= bit28 << 28;
16699 inst.instruction |= neon_logbits (size) << 20;
16700 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16701 inst.instruction |= inst.operands[0].reg << 12;
16702 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16703 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16704 inst.instruction |= LOW4 (inst.operands[2].reg);
16705 inst.is_neon = 1;
16706 }
16707
16708 static void
16709 mve_encode_qqq (int ubit, int size)
16710 {
16711
16712 inst.instruction |= (ubit != 0) << 28;
16713 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16714 inst.instruction |= neon_logbits (size) << 20;
16715 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16716 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16717 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16718 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16719 inst.instruction |= LOW4 (inst.operands[2].reg);
16720
16721 inst.is_neon = 1;
16722 }
16723
16724 static void
16725 mve_encode_rq (unsigned bit28, unsigned size)
16726 {
16727 inst.instruction |= bit28 << 28;
16728 inst.instruction |= neon_logbits (size) << 18;
16729 inst.instruction |= inst.operands[0].reg << 12;
16730 inst.instruction |= LOW4 (inst.operands[1].reg);
16731 inst.is_neon = 1;
16732 }
16733
16734 static void
16735 mve_encode_rrqq (unsigned U, unsigned size)
16736 {
16737 constraint (inst.operands[3].reg > 14, MVE_BAD_QREG);
16738
16739 inst.instruction |= U << 28;
16740 inst.instruction |= (inst.operands[1].reg >> 1) << 20;
16741 inst.instruction |= LOW4 (inst.operands[2].reg) << 16;
16742 inst.instruction |= (size == 32) << 16;
16743 inst.instruction |= inst.operands[0].reg << 12;
16744 inst.instruction |= HI1 (inst.operands[2].reg) << 7;
16745 inst.instruction |= inst.operands[3].reg;
16746 inst.is_neon = 1;
16747 }
16748
16749 /* Helper function for neon_three_same handling the operands. */
16750 static void
16751 neon_three_args (int isquad)
16752 {
16753 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16754 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16755 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16756 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16757 inst.instruction |= LOW4 (inst.operands[2].reg);
16758 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16759 inst.instruction |= (isquad != 0) << 6;
16760 inst.is_neon = 1;
16761 }
16762
16763 /* Encode insns with bit pattern:
16764
16765 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16766 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
16767
16768 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
16769 different meaning for some instruction. */
16770
16771 static void
16772 neon_three_same (int isquad, int ubit, int size)
16773 {
16774 neon_three_args (isquad);
16775 inst.instruction |= (ubit != 0) << 24;
16776 if (size != -1)
16777 inst.instruction |= neon_logbits (size) << 20;
16778
16779 neon_dp_fixup (&inst);
16780 }
16781
16782 /* Encode instructions of the form:
16783
16784 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
16785 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
16786
16787 Don't write size if SIZE == -1. */
16788
16789 static void
16790 neon_two_same (int qbit, int ubit, int size)
16791 {
16792 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16793 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16794 inst.instruction |= LOW4 (inst.operands[1].reg);
16795 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16796 inst.instruction |= (qbit != 0) << 6;
16797 inst.instruction |= (ubit != 0) << 24;
16798
16799 if (size != -1)
16800 inst.instruction |= neon_logbits (size) << 18;
16801
16802 neon_dp_fixup (&inst);
16803 }
16804
16805 enum vfp_or_neon_is_neon_bits
16806 {
16807 NEON_CHECK_CC = 1,
16808 NEON_CHECK_ARCH = 2,
16809 NEON_CHECK_ARCH8 = 4
16810 };
16811
16812 /* Call this function if an instruction which may have belonged to the VFP or
16813 Neon instruction sets, but turned out to be a Neon instruction (due to the
16814 operand types involved, etc.). We have to check and/or fix-up a couple of
16815 things:
16816
16817 - Make sure the user hasn't attempted to make a Neon instruction
16818 conditional.
16819 - Alter the value in the condition code field if necessary.
16820 - Make sure that the arch supports Neon instructions.
16821
16822 Which of these operations take place depends on bits from enum
16823 vfp_or_neon_is_neon_bits.
16824
16825 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
16826 current instruction's condition is COND_ALWAYS, the condition field is
16827 changed to inst.uncond_value. This is necessary because instructions shared
16828 between VFP and Neon may be conditional for the VFP variants only, and the
16829 unconditional Neon version must have, e.g., 0xF in the condition field. */
16830
16831 static int
16832 vfp_or_neon_is_neon (unsigned check)
16833 {
16834 /* Conditions are always legal in Thumb mode (IT blocks). */
16835 if (!thumb_mode && (check & NEON_CHECK_CC))
16836 {
16837 if (inst.cond != COND_ALWAYS)
16838 {
16839 first_error (_(BAD_COND));
16840 return FAIL;
16841 }
16842 if (inst.uncond_value != -1)
16843 inst.instruction |= inst.uncond_value << 28;
16844 }
16845
16846
16847 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
16848 || ((check & NEON_CHECK_ARCH8)
16849 && !mark_feature_used (&fpu_neon_ext_armv8)))
16850 {
16851 first_error (_(BAD_FPU));
16852 return FAIL;
16853 }
16854
16855 return SUCCESS;
16856 }
16857
16858
16859 /* Return TRUE if the SIMD instruction is available for the current
16860 cpu_variant. FP is set to TRUE if this is a SIMD floating-point
16861 instruction. CHECK contains th. CHECK contains the set of bits to pass to
16862 vfp_or_neon_is_neon for the NEON specific checks. */
16863
16864 static bfd_boolean
16865 check_simd_pred_availability (int fp, unsigned check)
16866 {
16867 if (inst.cond > COND_ALWAYS)
16868 {
16869 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16870 {
16871 inst.error = BAD_FPU;
16872 return FALSE;
16873 }
16874 inst.pred_insn_type = INSIDE_VPT_INSN;
16875 }
16876 else if (inst.cond < COND_ALWAYS)
16877 {
16878 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16879 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16880 else if (vfp_or_neon_is_neon (check) == FAIL)
16881 return FALSE;
16882 }
16883 else
16884 {
16885 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
16886 && vfp_or_neon_is_neon (check) == FAIL)
16887 return FALSE;
16888
16889 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16890 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16891 }
16892 return TRUE;
16893 }
16894
16895 /* Neon instruction encoders, in approximate order of appearance. */
16896
16897 static void
16898 do_neon_dyadic_i_su (void)
16899 {
16900 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
16901 return;
16902
16903 enum neon_shape rs;
16904 struct neon_type_el et;
16905 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16906 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16907 else
16908 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16909
16910 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_32 | N_KEY);
16911
16912
16913 if (rs != NS_QQR)
16914 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16915 else
16916 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16917 }
16918
16919 static void
16920 do_neon_dyadic_i64_su (void)
16921 {
16922 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
16923 return;
16924 enum neon_shape rs;
16925 struct neon_type_el et;
16926 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16927 {
16928 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16929 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16930 }
16931 else
16932 {
16933 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16934 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16935 }
16936 if (rs == NS_QQR)
16937 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16938 else
16939 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16940 }
16941
16942 static void
16943 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
16944 unsigned immbits)
16945 {
16946 unsigned size = et.size >> 3;
16947 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16948 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16949 inst.instruction |= LOW4 (inst.operands[1].reg);
16950 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16951 inst.instruction |= (isquad != 0) << 6;
16952 inst.instruction |= immbits << 16;
16953 inst.instruction |= (size >> 3) << 7;
16954 inst.instruction |= (size & 0x7) << 19;
16955 if (write_ubit)
16956 inst.instruction |= (uval != 0) << 24;
16957
16958 neon_dp_fixup (&inst);
16959 }
16960
16961 static void
16962 do_neon_shl (void)
16963 {
16964 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
16965 return;
16966
16967 if (!inst.operands[2].isreg)
16968 {
16969 enum neon_shape rs;
16970 struct neon_type_el et;
16971 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16972 {
16973 rs = neon_select_shape (NS_QQI, NS_NULL);
16974 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_MVE);
16975 }
16976 else
16977 {
16978 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16979 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
16980 }
16981 int imm = inst.operands[2].imm;
16982
16983 constraint (imm < 0 || (unsigned)imm >= et.size,
16984 _("immediate out of range for shift"));
16985 NEON_ENCODE (IMMED, inst);
16986 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
16987 }
16988 else
16989 {
16990 enum neon_shape rs;
16991 struct neon_type_el et;
16992 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16993 {
16994 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16995 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16996 }
16997 else
16998 {
16999 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17000 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
17001 }
17002
17003
17004 if (rs == NS_QQR)
17005 {
17006 constraint (inst.operands[0].reg != inst.operands[1].reg,
17007 _("invalid instruction shape"));
17008 if (inst.operands[2].reg == REG_SP)
17009 as_tsktsk (MVE_BAD_SP);
17010 else if (inst.operands[2].reg == REG_PC)
17011 as_tsktsk (MVE_BAD_PC);
17012
17013 inst.instruction = 0xee311e60;
17014 inst.instruction |= (et.type == NT_unsigned) << 28;
17015 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17016 inst.instruction |= neon_logbits (et.size) << 18;
17017 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17018 inst.instruction |= inst.operands[2].reg;
17019 inst.is_neon = 1;
17020 }
17021 else
17022 {
17023 unsigned int tmp;
17024
17025 /* VSHL/VQSHL 3-register variants have syntax such as:
17026 vshl.xx Dd, Dm, Dn
17027 whereas other 3-register operations encoded by neon_three_same have
17028 syntax like:
17029 vadd.xx Dd, Dn, Dm
17030 (i.e. with Dn & Dm reversed). Swap operands[1].reg and
17031 operands[2].reg here. */
17032 tmp = inst.operands[2].reg;
17033 inst.operands[2].reg = inst.operands[1].reg;
17034 inst.operands[1].reg = tmp;
17035 NEON_ENCODE (INTEGER, inst);
17036 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17037 }
17038 }
17039 }
17040
17041 static void
17042 do_neon_qshl (void)
17043 {
17044 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
17045 return;
17046
17047 if (!inst.operands[2].isreg)
17048 {
17049 enum neon_shape rs;
17050 struct neon_type_el et;
17051 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17052 {
17053 rs = neon_select_shape (NS_QQI, NS_NULL);
17054 et = neon_check_type (2, rs, N_EQK, N_KEY | N_SU_MVE);
17055 }
17056 else
17057 {
17058 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17059 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
17060 }
17061 int imm = inst.operands[2].imm;
17062
17063 constraint (imm < 0 || (unsigned)imm >= et.size,
17064 _("immediate out of range for shift"));
17065 NEON_ENCODE (IMMED, inst);
17066 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
17067 }
17068 else
17069 {
17070 enum neon_shape rs;
17071 struct neon_type_el et;
17072
17073 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17074 {
17075 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17076 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
17077 }
17078 else
17079 {
17080 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17081 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
17082 }
17083
17084 if (rs == NS_QQR)
17085 {
17086 constraint (inst.operands[0].reg != inst.operands[1].reg,
17087 _("invalid instruction shape"));
17088 if (inst.operands[2].reg == REG_SP)
17089 as_tsktsk (MVE_BAD_SP);
17090 else if (inst.operands[2].reg == REG_PC)
17091 as_tsktsk (MVE_BAD_PC);
17092
17093 inst.instruction = 0xee311ee0;
17094 inst.instruction |= (et.type == NT_unsigned) << 28;
17095 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17096 inst.instruction |= neon_logbits (et.size) << 18;
17097 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17098 inst.instruction |= inst.operands[2].reg;
17099 inst.is_neon = 1;
17100 }
17101 else
17102 {
17103 unsigned int tmp;
17104
17105 /* See note in do_neon_shl. */
17106 tmp = inst.operands[2].reg;
17107 inst.operands[2].reg = inst.operands[1].reg;
17108 inst.operands[1].reg = tmp;
17109 NEON_ENCODE (INTEGER, inst);
17110 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17111 }
17112 }
17113 }
17114
17115 static void
17116 do_neon_rshl (void)
17117 {
17118 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
17119 return;
17120
17121 enum neon_shape rs;
17122 struct neon_type_el et;
17123 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17124 {
17125 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17126 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17127 }
17128 else
17129 {
17130 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17131 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
17132 }
17133
17134 unsigned int tmp;
17135
17136 if (rs == NS_QQR)
17137 {
17138 if (inst.operands[2].reg == REG_PC)
17139 as_tsktsk (MVE_BAD_PC);
17140 else if (inst.operands[2].reg == REG_SP)
17141 as_tsktsk (MVE_BAD_SP);
17142
17143 constraint (inst.operands[0].reg != inst.operands[1].reg,
17144 _("invalid instruction shape"));
17145
17146 if (inst.instruction == 0x0000510)
17147 /* We are dealing with vqrshl. */
17148 inst.instruction = 0xee331ee0;
17149 else
17150 /* We are dealing with vrshl. */
17151 inst.instruction = 0xee331e60;
17152
17153 inst.instruction |= (et.type == NT_unsigned) << 28;
17154 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17155 inst.instruction |= neon_logbits (et.size) << 18;
17156 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17157 inst.instruction |= inst.operands[2].reg;
17158 inst.is_neon = 1;
17159 }
17160 else
17161 {
17162 tmp = inst.operands[2].reg;
17163 inst.operands[2].reg = inst.operands[1].reg;
17164 inst.operands[1].reg = tmp;
17165 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17166 }
17167 }
17168
17169 static int
17170 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
17171 {
17172 /* Handle .I8 pseudo-instructions. */
17173 if (size == 8)
17174 {
17175 /* Unfortunately, this will make everything apart from zero out-of-range.
17176 FIXME is this the intended semantics? There doesn't seem much point in
17177 accepting .I8 if so. */
17178 immediate |= immediate << 8;
17179 size = 16;
17180 }
17181
17182 if (size >= 32)
17183 {
17184 if (immediate == (immediate & 0x000000ff))
17185 {
17186 *immbits = immediate;
17187 return 0x1;
17188 }
17189 else if (immediate == (immediate & 0x0000ff00))
17190 {
17191 *immbits = immediate >> 8;
17192 return 0x3;
17193 }
17194 else if (immediate == (immediate & 0x00ff0000))
17195 {
17196 *immbits = immediate >> 16;
17197 return 0x5;
17198 }
17199 else if (immediate == (immediate & 0xff000000))
17200 {
17201 *immbits = immediate >> 24;
17202 return 0x7;
17203 }
17204 if ((immediate & 0xffff) != (immediate >> 16))
17205 goto bad_immediate;
17206 immediate &= 0xffff;
17207 }
17208
17209 if (immediate == (immediate & 0x000000ff))
17210 {
17211 *immbits = immediate;
17212 return 0x9;
17213 }
17214 else if (immediate == (immediate & 0x0000ff00))
17215 {
17216 *immbits = immediate >> 8;
17217 return 0xb;
17218 }
17219
17220 bad_immediate:
17221 first_error (_("immediate value out of range"));
17222 return FAIL;
17223 }
17224
17225 static void
17226 do_neon_logic (void)
17227 {
17228 if (inst.operands[2].present && inst.operands[2].isreg)
17229 {
17230 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17231 if (rs == NS_QQQ
17232 && !check_simd_pred_availability (FALSE,
17233 NEON_CHECK_ARCH | NEON_CHECK_CC))
17234 return;
17235 else if (rs != NS_QQQ
17236 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17237 first_error (BAD_FPU);
17238
17239 neon_check_type (3, rs, N_IGNORE_TYPE);
17240 /* U bit and size field were set as part of the bitmask. */
17241 NEON_ENCODE (INTEGER, inst);
17242 neon_three_same (neon_quad (rs), 0, -1);
17243 }
17244 else
17245 {
17246 const int three_ops_form = (inst.operands[2].present
17247 && !inst.operands[2].isreg);
17248 const int immoperand = (three_ops_form ? 2 : 1);
17249 enum neon_shape rs = (three_ops_form
17250 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
17251 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
17252 /* Because neon_select_shape makes the second operand a copy of the first
17253 if the second operand is not present. */
17254 if (rs == NS_QQI
17255 && !check_simd_pred_availability (FALSE,
17256 NEON_CHECK_ARCH | NEON_CHECK_CC))
17257 return;
17258 else if (rs != NS_QQI
17259 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17260 first_error (BAD_FPU);
17261
17262 struct neon_type_el et;
17263 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17264 et = neon_check_type (2, rs, N_I32 | N_I16 | N_KEY, N_EQK);
17265 else
17266 et = neon_check_type (2, rs, N_I8 | N_I16 | N_I32 | N_I64 | N_F32
17267 | N_KEY, N_EQK);
17268
17269 if (et.type == NT_invtype)
17270 return;
17271 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
17272 unsigned immbits;
17273 int cmode;
17274
17275
17276 if (three_ops_form)
17277 constraint (inst.operands[0].reg != inst.operands[1].reg,
17278 _("first and second operands shall be the same register"));
17279
17280 NEON_ENCODE (IMMED, inst);
17281
17282 immbits = inst.operands[immoperand].imm;
17283 if (et.size == 64)
17284 {
17285 /* .i64 is a pseudo-op, so the immediate must be a repeating
17286 pattern. */
17287 if (immbits != (inst.operands[immoperand].regisimm ?
17288 inst.operands[immoperand].reg : 0))
17289 {
17290 /* Set immbits to an invalid constant. */
17291 immbits = 0xdeadbeef;
17292 }
17293 }
17294
17295 switch (opcode)
17296 {
17297 case N_MNEM_vbic:
17298 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17299 break;
17300
17301 case N_MNEM_vorr:
17302 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17303 break;
17304
17305 case N_MNEM_vand:
17306 /* Pseudo-instruction for VBIC. */
17307 neon_invert_size (&immbits, 0, et.size);
17308 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17309 break;
17310
17311 case N_MNEM_vorn:
17312 /* Pseudo-instruction for VORR. */
17313 neon_invert_size (&immbits, 0, et.size);
17314 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17315 break;
17316
17317 default:
17318 abort ();
17319 }
17320
17321 if (cmode == FAIL)
17322 return;
17323
17324 inst.instruction |= neon_quad (rs) << 6;
17325 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17326 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17327 inst.instruction |= cmode << 8;
17328 neon_write_immbits (immbits);
17329
17330 neon_dp_fixup (&inst);
17331 }
17332 }
17333
17334 static void
17335 do_neon_bitfield (void)
17336 {
17337 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17338 neon_check_type (3, rs, N_IGNORE_TYPE);
17339 neon_three_same (neon_quad (rs), 0, -1);
17340 }
17341
17342 static void
17343 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
17344 unsigned destbits)
17345 {
17346 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17347 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
17348 types | N_KEY);
17349 if (et.type == NT_float)
17350 {
17351 NEON_ENCODE (FLOAT, inst);
17352 if (rs == NS_QQR)
17353 mve_encode_qqr (et.size, 0, 1);
17354 else
17355 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
17356 }
17357 else
17358 {
17359 NEON_ENCODE (INTEGER, inst);
17360 if (rs == NS_QQR)
17361 mve_encode_qqr (et.size, et.type == ubit_meaning, 0);
17362 else
17363 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
17364 }
17365 }
17366
17367
17368 static void
17369 do_neon_dyadic_if_su_d (void)
17370 {
17371 /* This version only allow D registers, but that constraint is enforced during
17372 operand parsing so we don't need to do anything extra here. */
17373 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17374 }
17375
17376 static void
17377 do_neon_dyadic_if_i_d (void)
17378 {
17379 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17380 affected if we specify unsigned args. */
17381 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17382 }
17383
17384 static void
17385 do_mve_vstr_vldr_QI (int size, int elsize, int load)
17386 {
17387 constraint (size < 32, BAD_ADDR_MODE);
17388 constraint (size != elsize, BAD_EL_TYPE);
17389 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17390 constraint (!inst.operands[1].preind, BAD_ADDR_MODE);
17391 constraint (load && inst.operands[0].reg == inst.operands[1].reg,
17392 _("destination register and offset register may not be the"
17393 " same"));
17394
17395 int imm = inst.relocs[0].exp.X_add_number;
17396 int add = 1;
17397 if (imm < 0)
17398 {
17399 add = 0;
17400 imm = -imm;
17401 }
17402 constraint ((imm % (size / 8) != 0)
17403 || imm > (0x7f << neon_logbits (size)),
17404 (size == 32) ? _("immediate must be a multiple of 4 in the"
17405 " range of +/-[0,508]")
17406 : _("immediate must be a multiple of 8 in the"
17407 " range of +/-[0,1016]"));
17408 inst.instruction |= 0x11 << 24;
17409 inst.instruction |= add << 23;
17410 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17411 inst.instruction |= inst.operands[1].writeback << 21;
17412 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17413 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17414 inst.instruction |= 1 << 12;
17415 inst.instruction |= (size == 64) << 8;
17416 inst.instruction &= 0xffffff00;
17417 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17418 inst.instruction |= imm >> neon_logbits (size);
17419 }
17420
17421 static void
17422 do_mve_vstr_vldr_RQ (int size, int elsize, int load)
17423 {
17424 unsigned os = inst.operands[1].imm >> 5;
17425 unsigned type = inst.vectype.el[0].type;
17426 constraint (os != 0 && size == 8,
17427 _("can not shift offsets when accessing less than half-word"));
17428 constraint (os && os != neon_logbits (size),
17429 _("shift immediate must be 1, 2 or 3 for half-word, word"
17430 " or double-word accesses respectively"));
17431 if (inst.operands[1].reg == REG_PC)
17432 as_tsktsk (MVE_BAD_PC);
17433
17434 switch (size)
17435 {
17436 case 8:
17437 constraint (elsize >= 64, BAD_EL_TYPE);
17438 break;
17439 case 16:
17440 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17441 break;
17442 case 32:
17443 case 64:
17444 constraint (elsize != size, BAD_EL_TYPE);
17445 break;
17446 default:
17447 break;
17448 }
17449 constraint (inst.operands[1].writeback || !inst.operands[1].preind,
17450 BAD_ADDR_MODE);
17451 if (load)
17452 {
17453 constraint (inst.operands[0].reg == (inst.operands[1].imm & 0x1f),
17454 _("destination register and offset register may not be"
17455 " the same"));
17456 constraint (size == elsize && type == NT_signed, BAD_EL_TYPE);
17457 constraint (size != elsize && type != NT_unsigned && type != NT_signed,
17458 BAD_EL_TYPE);
17459 inst.instruction |= ((size == elsize) || (type == NT_unsigned)) << 28;
17460 }
17461 else
17462 {
17463 constraint (type != NT_untyped, BAD_EL_TYPE);
17464 }
17465
17466 inst.instruction |= 1 << 23;
17467 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17468 inst.instruction |= inst.operands[1].reg << 16;
17469 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17470 inst.instruction |= neon_logbits (elsize) << 7;
17471 inst.instruction |= HI1 (inst.operands[1].imm) << 5;
17472 inst.instruction |= LOW4 (inst.operands[1].imm);
17473 inst.instruction |= !!os;
17474 }
17475
17476 static void
17477 do_mve_vstr_vldr_RI (int size, int elsize, int load)
17478 {
17479 enum neon_el_type type = inst.vectype.el[0].type;
17480
17481 constraint (size >= 64, BAD_ADDR_MODE);
17482 switch (size)
17483 {
17484 case 16:
17485 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17486 break;
17487 case 32:
17488 constraint (elsize != size, BAD_EL_TYPE);
17489 break;
17490 default:
17491 break;
17492 }
17493 if (load)
17494 {
17495 constraint (elsize != size && type != NT_unsigned
17496 && type != NT_signed, BAD_EL_TYPE);
17497 }
17498 else
17499 {
17500 constraint (elsize != size && type != NT_untyped, BAD_EL_TYPE);
17501 }
17502
17503 int imm = inst.relocs[0].exp.X_add_number;
17504 int add = 1;
17505 if (imm < 0)
17506 {
17507 add = 0;
17508 imm = -imm;
17509 }
17510
17511 if ((imm % (size / 8) != 0) || imm > (0x7f << neon_logbits (size)))
17512 {
17513 switch (size)
17514 {
17515 case 8:
17516 constraint (1, _("immediate must be in the range of +/-[0,127]"));
17517 break;
17518 case 16:
17519 constraint (1, _("immediate must be a multiple of 2 in the"
17520 " range of +/-[0,254]"));
17521 break;
17522 case 32:
17523 constraint (1, _("immediate must be a multiple of 4 in the"
17524 " range of +/-[0,508]"));
17525 break;
17526 }
17527 }
17528
17529 if (size != elsize)
17530 {
17531 constraint (inst.operands[1].reg > 7, BAD_HIREG);
17532 constraint (inst.operands[0].reg > 14,
17533 _("MVE vector register in the range [Q0..Q7] expected"));
17534 inst.instruction |= (load && type == NT_unsigned) << 28;
17535 inst.instruction |= (size == 16) << 19;
17536 inst.instruction |= neon_logbits (elsize) << 7;
17537 }
17538 else
17539 {
17540 if (inst.operands[1].reg == REG_PC)
17541 as_tsktsk (MVE_BAD_PC);
17542 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17543 as_tsktsk (MVE_BAD_SP);
17544 inst.instruction |= 1 << 12;
17545 inst.instruction |= neon_logbits (size) << 7;
17546 }
17547 inst.instruction |= inst.operands[1].preind << 24;
17548 inst.instruction |= add << 23;
17549 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17550 inst.instruction |= inst.operands[1].writeback << 21;
17551 inst.instruction |= inst.operands[1].reg << 16;
17552 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17553 inst.instruction &= 0xffffff80;
17554 inst.instruction |= imm >> neon_logbits (size);
17555
17556 }
17557
17558 static void
17559 do_mve_vstr_vldr (void)
17560 {
17561 unsigned size;
17562 int load = 0;
17563
17564 if (inst.cond > COND_ALWAYS)
17565 inst.pred_insn_type = INSIDE_VPT_INSN;
17566 else
17567 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17568
17569 switch (inst.instruction)
17570 {
17571 default:
17572 gas_assert (0);
17573 break;
17574 case M_MNEM_vldrb:
17575 load = 1;
17576 /* fall through. */
17577 case M_MNEM_vstrb:
17578 size = 8;
17579 break;
17580 case M_MNEM_vldrh:
17581 load = 1;
17582 /* fall through. */
17583 case M_MNEM_vstrh:
17584 size = 16;
17585 break;
17586 case M_MNEM_vldrw:
17587 load = 1;
17588 /* fall through. */
17589 case M_MNEM_vstrw:
17590 size = 32;
17591 break;
17592 case M_MNEM_vldrd:
17593 load = 1;
17594 /* fall through. */
17595 case M_MNEM_vstrd:
17596 size = 64;
17597 break;
17598 }
17599 unsigned elsize = inst.vectype.el[0].size;
17600
17601 if (inst.operands[1].isquad)
17602 {
17603 /* We are dealing with [Q, imm]{!} cases. */
17604 do_mve_vstr_vldr_QI (size, elsize, load);
17605 }
17606 else
17607 {
17608 if (inst.operands[1].immisreg == 2)
17609 {
17610 /* We are dealing with [R, Q, {UXTW #os}] cases. */
17611 do_mve_vstr_vldr_RQ (size, elsize, load);
17612 }
17613 else if (!inst.operands[1].immisreg)
17614 {
17615 /* We are dealing with [R, Imm]{!}/[R], Imm cases. */
17616 do_mve_vstr_vldr_RI (size, elsize, load);
17617 }
17618 else
17619 constraint (1, BAD_ADDR_MODE);
17620 }
17621
17622 inst.is_neon = 1;
17623 }
17624
17625 static void
17626 do_mve_vst_vld (void)
17627 {
17628 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17629 return;
17630
17631 constraint (!inst.operands[1].preind || inst.relocs[0].exp.X_add_symbol != 0
17632 || inst.relocs[0].exp.X_add_number != 0
17633 || inst.operands[1].immisreg != 0,
17634 BAD_ADDR_MODE);
17635 constraint (inst.vectype.el[0].size > 32, BAD_EL_TYPE);
17636 if (inst.operands[1].reg == REG_PC)
17637 as_tsktsk (MVE_BAD_PC);
17638 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17639 as_tsktsk (MVE_BAD_SP);
17640
17641
17642 /* These instructions are one of the "exceptions" mentioned in
17643 handle_pred_state. They are MVE instructions that are not VPT compatible
17644 and do not accept a VPT code, thus appending such a code is a syntax
17645 error. */
17646 if (inst.cond > COND_ALWAYS)
17647 first_error (BAD_SYNTAX);
17648 /* If we append a scalar condition code we can set this to
17649 MVE_OUTSIDE_PRED_INSN as it will also lead to a syntax error. */
17650 else if (inst.cond < COND_ALWAYS)
17651 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17652 else
17653 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
17654
17655 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17656 inst.instruction |= inst.operands[1].writeback << 21;
17657 inst.instruction |= inst.operands[1].reg << 16;
17658 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17659 inst.instruction |= neon_logbits (inst.vectype.el[0].size) << 7;
17660 inst.is_neon = 1;
17661 }
17662
17663 static void
17664 do_mve_vaddlv (void)
17665 {
17666 enum neon_shape rs = neon_select_shape (NS_RRQ, NS_NULL);
17667 struct neon_type_el et
17668 = neon_check_type (3, rs, N_EQK, N_EQK, N_S32 | N_U32 | N_KEY);
17669
17670 if (et.type == NT_invtype)
17671 first_error (BAD_EL_TYPE);
17672
17673 if (inst.cond > COND_ALWAYS)
17674 inst.pred_insn_type = INSIDE_VPT_INSN;
17675 else
17676 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17677
17678 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17679
17680 inst.instruction |= (et.type == NT_unsigned) << 28;
17681 inst.instruction |= inst.operands[1].reg << 19;
17682 inst.instruction |= inst.operands[0].reg << 12;
17683 inst.instruction |= inst.operands[2].reg;
17684 inst.is_neon = 1;
17685 }
17686
17687 static void
17688 do_neon_dyadic_if_su (void)
17689 {
17690 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17691 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17692 N_SUF_32 | N_KEY);
17693
17694 constraint ((inst.instruction == ((unsigned) N_MNEM_vmax)
17695 || inst.instruction == ((unsigned) N_MNEM_vmin))
17696 && et.type == NT_float
17697 && !ARM_CPU_HAS_FEATURE (cpu_variant,fpu_neon_ext_v1), BAD_FPU);
17698
17699 if (!check_simd_pred_availability (et.type == NT_float,
17700 NEON_CHECK_ARCH | NEON_CHECK_CC))
17701 return;
17702
17703 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17704 }
17705
17706 static void
17707 do_neon_addsub_if_i (void)
17708 {
17709 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
17710 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
17711 return;
17712
17713 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17714 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
17715 N_EQK, N_IF_32 | N_I64 | N_KEY);
17716
17717 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
17718 /* If we are parsing Q registers and the element types match MVE, which NEON
17719 also supports, then we must check whether this is an instruction that can
17720 be used by both MVE/NEON. This distinction can be made based on whether
17721 they are predicated or not. */
17722 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
17723 {
17724 if (!check_simd_pred_availability (et.type == NT_float,
17725 NEON_CHECK_ARCH | NEON_CHECK_CC))
17726 return;
17727 }
17728 else
17729 {
17730 /* If they are either in a D register or are using an unsupported. */
17731 if (rs != NS_QQR
17732 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17733 return;
17734 }
17735
17736 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17737 affected if we specify unsigned args. */
17738 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
17739 }
17740
17741 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
17742 result to be:
17743 V<op> A,B (A is operand 0, B is operand 2)
17744 to mean:
17745 V<op> A,B,A
17746 not:
17747 V<op> A,B,B
17748 so handle that case specially. */
17749
17750 static void
17751 neon_exchange_operands (void)
17752 {
17753 if (inst.operands[1].present)
17754 {
17755 void *scratch = xmalloc (sizeof (inst.operands[0]));
17756
17757 /* Swap operands[1] and operands[2]. */
17758 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
17759 inst.operands[1] = inst.operands[2];
17760 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
17761 free (scratch);
17762 }
17763 else
17764 {
17765 inst.operands[1] = inst.operands[2];
17766 inst.operands[2] = inst.operands[0];
17767 }
17768 }
17769
17770 static void
17771 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
17772 {
17773 if (inst.operands[2].isreg)
17774 {
17775 if (invert)
17776 neon_exchange_operands ();
17777 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
17778 }
17779 else
17780 {
17781 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17782 struct neon_type_el et = neon_check_type (2, rs,
17783 N_EQK | N_SIZ, immtypes | N_KEY);
17784
17785 NEON_ENCODE (IMMED, inst);
17786 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17787 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17788 inst.instruction |= LOW4 (inst.operands[1].reg);
17789 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17790 inst.instruction |= neon_quad (rs) << 6;
17791 inst.instruction |= (et.type == NT_float) << 10;
17792 inst.instruction |= neon_logbits (et.size) << 18;
17793
17794 neon_dp_fixup (&inst);
17795 }
17796 }
17797
17798 static void
17799 do_neon_cmp (void)
17800 {
17801 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
17802 }
17803
17804 static void
17805 do_neon_cmp_inv (void)
17806 {
17807 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
17808 }
17809
17810 static void
17811 do_neon_ceq (void)
17812 {
17813 neon_compare (N_IF_32, N_IF_32, FALSE);
17814 }
17815
17816 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
17817 scalars, which are encoded in 5 bits, M : Rm.
17818 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
17819 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
17820 index in M.
17821
17822 Dot Product instructions are similar to multiply instructions except elsize
17823 should always be 32.
17824
17825 This function translates SCALAR, which is GAS's internal encoding of indexed
17826 scalar register, to raw encoding. There is also register and index range
17827 check based on ELSIZE. */
17828
17829 static unsigned
17830 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
17831 {
17832 unsigned regno = NEON_SCALAR_REG (scalar);
17833 unsigned elno = NEON_SCALAR_INDEX (scalar);
17834
17835 switch (elsize)
17836 {
17837 case 16:
17838 if (regno > 7 || elno > 3)
17839 goto bad_scalar;
17840 return regno | (elno << 3);
17841
17842 case 32:
17843 if (regno > 15 || elno > 1)
17844 goto bad_scalar;
17845 return regno | (elno << 4);
17846
17847 default:
17848 bad_scalar:
17849 first_error (_("scalar out of range for multiply instruction"));
17850 }
17851
17852 return 0;
17853 }
17854
17855 /* Encode multiply / multiply-accumulate scalar instructions. */
17856
17857 static void
17858 neon_mul_mac (struct neon_type_el et, int ubit)
17859 {
17860 unsigned scalar;
17861
17862 /* Give a more helpful error message if we have an invalid type. */
17863 if (et.type == NT_invtype)
17864 return;
17865
17866 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
17867 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17868 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17869 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17870 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17871 inst.instruction |= LOW4 (scalar);
17872 inst.instruction |= HI1 (scalar) << 5;
17873 inst.instruction |= (et.type == NT_float) << 8;
17874 inst.instruction |= neon_logbits (et.size) << 20;
17875 inst.instruction |= (ubit != 0) << 24;
17876
17877 neon_dp_fixup (&inst);
17878 }
17879
17880 static void
17881 do_neon_mac_maybe_scalar (void)
17882 {
17883 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
17884 return;
17885
17886 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
17887 return;
17888
17889 if (inst.operands[2].isscalar)
17890 {
17891 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17892 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17893 struct neon_type_el et = neon_check_type (3, rs,
17894 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
17895 NEON_ENCODE (SCALAR, inst);
17896 neon_mul_mac (et, neon_quad (rs));
17897 }
17898 else if (!inst.operands[2].isvec)
17899 {
17900 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17901
17902 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17903 neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17904
17905 neon_dyadic_misc (NT_unsigned, N_SU_MVE, 0);
17906 }
17907 else
17908 {
17909 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17910 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17911 affected if we specify unsigned args. */
17912 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17913 }
17914 }
17915
17916 static void
17917 do_bfloat_vfma (void)
17918 {
17919 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
17920 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
17921 enum neon_shape rs;
17922 int t_bit = 0;
17923
17924 if (inst.instruction != B_MNEM_vfmab)
17925 {
17926 t_bit = 1;
17927 inst.instruction = B_MNEM_vfmat;
17928 }
17929
17930 if (inst.operands[2].isscalar)
17931 {
17932 rs = neon_select_shape (NS_QQS, NS_NULL);
17933 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17934
17935 inst.instruction |= (1 << 25);
17936 int index = inst.operands[2].reg & 0xf;
17937 constraint (!(index < 4), _("index must be in the range 0 to 3"));
17938 inst.operands[2].reg >>= 4;
17939 constraint (!(inst.operands[2].reg < 8),
17940 _("indexed register must be less than 8"));
17941 neon_three_args (t_bit);
17942 inst.instruction |= ((index & 1) << 3);
17943 inst.instruction |= ((index & 2) << 4);
17944 }
17945 else
17946 {
17947 rs = neon_select_shape (NS_QQQ, NS_NULL);
17948 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17949 neon_three_args (t_bit);
17950 }
17951
17952 }
17953
17954 static void
17955 do_neon_fmac (void)
17956 {
17957 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma)
17958 && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
17959 return;
17960
17961 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH))
17962 return;
17963
17964 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
17965 {
17966 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17967 struct neon_type_el et = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK,
17968 N_EQK);
17969
17970 if (rs == NS_QQR)
17971 {
17972
17973 if (inst.operands[2].reg == REG_SP)
17974 as_tsktsk (MVE_BAD_SP);
17975 else if (inst.operands[2].reg == REG_PC)
17976 as_tsktsk (MVE_BAD_PC);
17977
17978 inst.instruction = 0xee310e40;
17979 inst.instruction |= (et.size == 16) << 28;
17980 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17981 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17982 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17983 inst.instruction |= HI1 (inst.operands[1].reg) << 6;
17984 inst.instruction |= inst.operands[2].reg;
17985 inst.is_neon = 1;
17986 return;
17987 }
17988 }
17989 else
17990 {
17991 constraint (!inst.operands[2].isvec, BAD_FPU);
17992 }
17993
17994 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17995 }
17996
17997 static void
17998 do_mve_vfma (void)
17999 {
18000 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_bf16) &&
18001 inst.cond == COND_ALWAYS)
18002 {
18003 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
18004 inst.instruction = N_MNEM_vfma;
18005 inst.pred_insn_type = INSIDE_VPT_INSN;
18006 inst.cond = 0xf;
18007 return do_neon_fmac();
18008 }
18009 else
18010 {
18011 do_bfloat_vfma();
18012 }
18013 }
18014
18015 static void
18016 do_neon_tst (void)
18017 {
18018 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18019 struct neon_type_el et = neon_check_type (3, rs,
18020 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18021 neon_three_same (neon_quad (rs), 0, et.size);
18022 }
18023
18024 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
18025 same types as the MAC equivalents. The polynomial type for this instruction
18026 is encoded the same as the integer type. */
18027
18028 static void
18029 do_neon_mul (void)
18030 {
18031 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
18032 return;
18033
18034 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
18035 return;
18036
18037 if (inst.operands[2].isscalar)
18038 {
18039 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
18040 do_neon_mac_maybe_scalar ();
18041 }
18042 else
18043 {
18044 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18045 {
18046 enum neon_shape rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18047 struct neon_type_el et
18048 = neon_check_type (3, rs, N_EQK, N_EQK, N_I_MVE | N_F_MVE | N_KEY);
18049 if (et.type == NT_float)
18050 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
18051 BAD_FPU);
18052
18053 neon_dyadic_misc (NT_float, N_I_MVE | N_F_MVE, 0);
18054 }
18055 else
18056 {
18057 constraint (!inst.operands[2].isvec, BAD_FPU);
18058 neon_dyadic_misc (NT_poly,
18059 N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
18060 }
18061 }
18062 }
18063
18064 static void
18065 do_neon_qdmulh (void)
18066 {
18067 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18068 return;
18069
18070 if (inst.operands[2].isscalar)
18071 {
18072 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
18073 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18074 struct neon_type_el et = neon_check_type (3, rs,
18075 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18076 NEON_ENCODE (SCALAR, inst);
18077 neon_mul_mac (et, neon_quad (rs));
18078 }
18079 else
18080 {
18081 enum neon_shape rs;
18082 struct neon_type_el et;
18083 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18084 {
18085 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18086 et = neon_check_type (3, rs,
18087 N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18088 }
18089 else
18090 {
18091 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18092 et = neon_check_type (3, rs,
18093 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18094 }
18095
18096 NEON_ENCODE (INTEGER, inst);
18097 if (rs == NS_QQR)
18098 mve_encode_qqr (et.size, 0, 0);
18099 else
18100 /* The U bit (rounding) comes from bit mask. */
18101 neon_three_same (neon_quad (rs), 0, et.size);
18102 }
18103 }
18104
18105 static void
18106 do_mve_vaddv (void)
18107 {
18108 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18109 struct neon_type_el et
18110 = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
18111
18112 if (et.type == NT_invtype)
18113 first_error (BAD_EL_TYPE);
18114
18115 if (inst.cond > COND_ALWAYS)
18116 inst.pred_insn_type = INSIDE_VPT_INSN;
18117 else
18118 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18119
18120 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
18121
18122 mve_encode_rq (et.type == NT_unsigned, et.size);
18123 }
18124
18125 static void
18126 do_mve_vhcadd (void)
18127 {
18128 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
18129 struct neon_type_el et
18130 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18131
18132 if (inst.cond > COND_ALWAYS)
18133 inst.pred_insn_type = INSIDE_VPT_INSN;
18134 else
18135 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18136
18137 unsigned rot = inst.relocs[0].exp.X_add_number;
18138 constraint (rot != 90 && rot != 270, _("immediate out of range"));
18139
18140 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
18141 as_tsktsk (_("Warning: 32-bit element size and same first and third "
18142 "operand makes instruction UNPREDICTABLE"));
18143
18144 mve_encode_qqq (0, et.size);
18145 inst.instruction |= (rot == 270) << 12;
18146 inst.is_neon = 1;
18147 }
18148
18149 static void
18150 do_mve_vqdmull (void)
18151 {
18152 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
18153 struct neon_type_el et
18154 = neon_check_type (3, rs, N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18155
18156 if (et.size == 32
18157 && (inst.operands[0].reg == inst.operands[1].reg
18158 || (rs == NS_QQQ && inst.operands[0].reg == inst.operands[2].reg)))
18159 as_tsktsk (BAD_MVE_SRCDEST);
18160
18161 if (inst.cond > COND_ALWAYS)
18162 inst.pred_insn_type = INSIDE_VPT_INSN;
18163 else
18164 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18165
18166 if (rs == NS_QQQ)
18167 {
18168 mve_encode_qqq (et.size == 32, 64);
18169 inst.instruction |= 1;
18170 }
18171 else
18172 {
18173 mve_encode_qqr (64, et.size == 32, 0);
18174 inst.instruction |= 0x3 << 5;
18175 }
18176 }
18177
18178 static void
18179 do_mve_vadc (void)
18180 {
18181 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18182 struct neon_type_el et
18183 = neon_check_type (3, rs, N_KEY | N_I32, N_EQK, N_EQK);
18184
18185 if (et.type == NT_invtype)
18186 first_error (BAD_EL_TYPE);
18187
18188 if (inst.cond > COND_ALWAYS)
18189 inst.pred_insn_type = INSIDE_VPT_INSN;
18190 else
18191 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18192
18193 mve_encode_qqq (0, 64);
18194 }
18195
18196 static void
18197 do_mve_vbrsr (void)
18198 {
18199 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18200 struct neon_type_el et
18201 = neon_check_type (3, rs, N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18202
18203 if (inst.cond > COND_ALWAYS)
18204 inst.pred_insn_type = INSIDE_VPT_INSN;
18205 else
18206 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18207
18208 mve_encode_qqr (et.size, 0, 0);
18209 }
18210
18211 static void
18212 do_mve_vsbc (void)
18213 {
18214 neon_check_type (3, NS_QQQ, N_EQK, N_EQK, N_I32 | N_KEY);
18215
18216 if (inst.cond > COND_ALWAYS)
18217 inst.pred_insn_type = INSIDE_VPT_INSN;
18218 else
18219 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18220
18221 mve_encode_qqq (1, 64);
18222 }
18223
18224 static void
18225 do_mve_vmulh (void)
18226 {
18227 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18228 struct neon_type_el et
18229 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
18230
18231 if (inst.cond > COND_ALWAYS)
18232 inst.pred_insn_type = INSIDE_VPT_INSN;
18233 else
18234 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18235
18236 mve_encode_qqq (et.type == NT_unsigned, et.size);
18237 }
18238
18239 static void
18240 do_mve_vqdmlah (void)
18241 {
18242 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18243 struct neon_type_el et
18244 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
18245
18246 if (inst.cond > COND_ALWAYS)
18247 inst.pred_insn_type = INSIDE_VPT_INSN;
18248 else
18249 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18250
18251 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18252 }
18253
18254 static void
18255 do_mve_vqdmladh (void)
18256 {
18257 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18258 struct neon_type_el et
18259 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | 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 mve_encode_qqq (0, et.size);
18267 }
18268
18269
18270 static void
18271 do_mve_vmull (void)
18272 {
18273
18274 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_DDS,
18275 NS_QQS, NS_QQQ, NS_QQR, NS_NULL);
18276 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
18277 && inst.cond == COND_ALWAYS
18278 && ((unsigned)inst.instruction) == M_MNEM_vmullt)
18279 {
18280 if (rs == NS_QQQ)
18281 {
18282
18283 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18284 N_SUF_32 | N_F64 | N_P8
18285 | N_P16 | N_I_MVE | N_KEY);
18286 if (((et.type == NT_poly) && et.size == 8
18287 && ARM_CPU_IS_ANY (cpu_variant))
18288 || (et.type == NT_integer) || (et.type == NT_float))
18289 goto neon_vmul;
18290 }
18291 else
18292 goto neon_vmul;
18293 }
18294
18295 constraint (rs != NS_QQQ, BAD_FPU);
18296 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18297 N_SU_32 | N_P8 | N_P16 | N_KEY);
18298
18299 /* We are dealing with MVE's vmullt. */
18300 if (et.size == 32
18301 && (inst.operands[0].reg == inst.operands[1].reg
18302 || inst.operands[0].reg == inst.operands[2].reg))
18303 as_tsktsk (BAD_MVE_SRCDEST);
18304
18305 if (inst.cond > COND_ALWAYS)
18306 inst.pred_insn_type = INSIDE_VPT_INSN;
18307 else
18308 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18309
18310 if (et.type == NT_poly)
18311 mve_encode_qqq (neon_logbits (et.size), 64);
18312 else
18313 mve_encode_qqq (et.type == NT_unsigned, et.size);
18314
18315 return;
18316
18317 neon_vmul:
18318 inst.instruction = N_MNEM_vmul;
18319 inst.cond = 0xb;
18320 if (thumb_mode)
18321 inst.pred_insn_type = INSIDE_IT_INSN;
18322 do_neon_mul ();
18323 }
18324
18325 static void
18326 do_mve_vabav (void)
18327 {
18328 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18329
18330 if (rs == NS_NULL)
18331 return;
18332
18333 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18334 return;
18335
18336 struct neon_type_el et = neon_check_type (2, NS_NULL, N_EQK, N_KEY | N_S8
18337 | N_S16 | N_S32 | N_U8 | N_U16
18338 | N_U32);
18339
18340 if (inst.cond > COND_ALWAYS)
18341 inst.pred_insn_type = INSIDE_VPT_INSN;
18342 else
18343 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18344
18345 mve_encode_rqq (et.type == NT_unsigned, et.size);
18346 }
18347
18348 static void
18349 do_mve_vmladav (void)
18350 {
18351 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18352 struct neon_type_el et = neon_check_type (3, rs,
18353 N_EQK, N_EQK, N_SU_MVE | N_KEY);
18354
18355 if (et.type == NT_unsigned
18356 && (inst.instruction == M_MNEM_vmladavx
18357 || inst.instruction == M_MNEM_vmladavax
18358 || inst.instruction == M_MNEM_vmlsdav
18359 || inst.instruction == M_MNEM_vmlsdava
18360 || inst.instruction == M_MNEM_vmlsdavx
18361 || inst.instruction == M_MNEM_vmlsdavax))
18362 first_error (BAD_SIMD_TYPE);
18363
18364 constraint (inst.operands[2].reg > 14,
18365 _("MVE vector register in the range [Q0..Q7] expected"));
18366
18367 if (inst.cond > COND_ALWAYS)
18368 inst.pred_insn_type = INSIDE_VPT_INSN;
18369 else
18370 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18371
18372 if (inst.instruction == M_MNEM_vmlsdav
18373 || inst.instruction == M_MNEM_vmlsdava
18374 || inst.instruction == M_MNEM_vmlsdavx
18375 || inst.instruction == M_MNEM_vmlsdavax)
18376 inst.instruction |= (et.size == 8) << 28;
18377 else
18378 inst.instruction |= (et.size == 8) << 8;
18379
18380 mve_encode_rqq (et.type == NT_unsigned, 64);
18381 inst.instruction |= (et.size == 32) << 16;
18382 }
18383
18384 static void
18385 do_mve_vmlaldav (void)
18386 {
18387 enum neon_shape rs = neon_select_shape (NS_RRQQ, NS_NULL);
18388 struct neon_type_el et
18389 = neon_check_type (4, rs, N_EQK, N_EQK, N_EQK,
18390 N_S16 | N_S32 | N_U16 | N_U32 | N_KEY);
18391
18392 if (et.type == NT_unsigned
18393 && (inst.instruction == M_MNEM_vmlsldav
18394 || inst.instruction == M_MNEM_vmlsldava
18395 || inst.instruction == M_MNEM_vmlsldavx
18396 || inst.instruction == M_MNEM_vmlsldavax))
18397 first_error (BAD_SIMD_TYPE);
18398
18399 if (inst.cond > COND_ALWAYS)
18400 inst.pred_insn_type = INSIDE_VPT_INSN;
18401 else
18402 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18403
18404 mve_encode_rrqq (et.type == NT_unsigned, et.size);
18405 }
18406
18407 static void
18408 do_mve_vrmlaldavh (void)
18409 {
18410 struct neon_type_el et;
18411 if (inst.instruction == M_MNEM_vrmlsldavh
18412 || inst.instruction == M_MNEM_vrmlsldavha
18413 || inst.instruction == M_MNEM_vrmlsldavhx
18414 || inst.instruction == M_MNEM_vrmlsldavhax)
18415 {
18416 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18417 if (inst.operands[1].reg == REG_SP)
18418 as_tsktsk (MVE_BAD_SP);
18419 }
18420 else
18421 {
18422 if (inst.instruction == M_MNEM_vrmlaldavhx
18423 || inst.instruction == M_MNEM_vrmlaldavhax)
18424 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18425 else
18426 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK,
18427 N_U32 | N_S32 | N_KEY);
18428 /* vrmlaldavh's encoding with SP as the second, odd, GPR operand may alias
18429 with vmax/min instructions, making the use of SP in assembly really
18430 nonsensical, so instead of issuing a warning like we do for other uses
18431 of SP for the odd register operand we error out. */
18432 constraint (inst.operands[1].reg == REG_SP, BAD_SP);
18433 }
18434
18435 /* Make sure we still check the second operand is an odd one and that PC is
18436 disallowed. This because we are parsing for any GPR operand, to be able
18437 to distinguish between giving a warning or an error for SP as described
18438 above. */
18439 constraint ((inst.operands[1].reg % 2) != 1, BAD_EVEN);
18440 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18441
18442 if (inst.cond > COND_ALWAYS)
18443 inst.pred_insn_type = INSIDE_VPT_INSN;
18444 else
18445 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18446
18447 mve_encode_rrqq (et.type == NT_unsigned, 0);
18448 }
18449
18450
18451 static void
18452 do_mve_vmaxnmv (void)
18453 {
18454 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18455 struct neon_type_el et
18456 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
18457
18458 if (inst.cond > COND_ALWAYS)
18459 inst.pred_insn_type = INSIDE_VPT_INSN;
18460 else
18461 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18462
18463 if (inst.operands[0].reg == REG_SP)
18464 as_tsktsk (MVE_BAD_SP);
18465 else if (inst.operands[0].reg == REG_PC)
18466 as_tsktsk (MVE_BAD_PC);
18467
18468 mve_encode_rq (et.size == 16, 64);
18469 }
18470
18471 static void
18472 do_mve_vmaxv (void)
18473 {
18474 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18475 struct neon_type_el et;
18476
18477 if (inst.instruction == M_MNEM_vmaxv || inst.instruction == M_MNEM_vminv)
18478 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
18479 else
18480 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18481
18482 if (inst.cond > COND_ALWAYS)
18483 inst.pred_insn_type = INSIDE_VPT_INSN;
18484 else
18485 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18486
18487 if (inst.operands[0].reg == REG_SP)
18488 as_tsktsk (MVE_BAD_SP);
18489 else if (inst.operands[0].reg == REG_PC)
18490 as_tsktsk (MVE_BAD_PC);
18491
18492 mve_encode_rq (et.type == NT_unsigned, et.size);
18493 }
18494
18495
18496 static void
18497 do_neon_qrdmlah (void)
18498 {
18499 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18500 return;
18501 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18502 {
18503 /* Check we're on the correct architecture. */
18504 if (!mark_feature_used (&fpu_neon_ext_armv8))
18505 inst.error
18506 = _("instruction form not available on this architecture.");
18507 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
18508 {
18509 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
18510 record_feature_use (&fpu_neon_ext_v8_1);
18511 }
18512 if (inst.operands[2].isscalar)
18513 {
18514 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18515 struct neon_type_el et = neon_check_type (3, rs,
18516 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18517 NEON_ENCODE (SCALAR, inst);
18518 neon_mul_mac (et, neon_quad (rs));
18519 }
18520 else
18521 {
18522 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18523 struct neon_type_el et = neon_check_type (3, rs,
18524 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18525 NEON_ENCODE (INTEGER, inst);
18526 /* The U bit (rounding) comes from bit mask. */
18527 neon_three_same (neon_quad (rs), 0, et.size);
18528 }
18529 }
18530 else
18531 {
18532 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18533 struct neon_type_el et
18534 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
18535
18536 NEON_ENCODE (INTEGER, inst);
18537 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18538 }
18539 }
18540
18541 static void
18542 do_neon_fcmp_absolute (void)
18543 {
18544 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18545 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18546 N_F_16_32 | N_KEY);
18547 /* Size field comes from bit mask. */
18548 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
18549 }
18550
18551 static void
18552 do_neon_fcmp_absolute_inv (void)
18553 {
18554 neon_exchange_operands ();
18555 do_neon_fcmp_absolute ();
18556 }
18557
18558 static void
18559 do_neon_step (void)
18560 {
18561 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18562 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18563 N_F_16_32 | N_KEY);
18564 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
18565 }
18566
18567 static void
18568 do_neon_abs_neg (void)
18569 {
18570 enum neon_shape rs;
18571 struct neon_type_el et;
18572
18573 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
18574 return;
18575
18576 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
18577 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
18578
18579 if (!check_simd_pred_availability (et.type == NT_float,
18580 NEON_CHECK_ARCH | NEON_CHECK_CC))
18581 return;
18582
18583 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18584 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18585 inst.instruction |= LOW4 (inst.operands[1].reg);
18586 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18587 inst.instruction |= neon_quad (rs) << 6;
18588 inst.instruction |= (et.type == NT_float) << 10;
18589 inst.instruction |= neon_logbits (et.size) << 18;
18590
18591 neon_dp_fixup (&inst);
18592 }
18593
18594 static void
18595 do_neon_sli (void)
18596 {
18597 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18598 return;
18599
18600 enum neon_shape rs;
18601 struct neon_type_el et;
18602 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18603 {
18604 rs = neon_select_shape (NS_QQI, NS_NULL);
18605 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18606 }
18607 else
18608 {
18609 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18610 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18611 }
18612
18613
18614 int imm = inst.operands[2].imm;
18615 constraint (imm < 0 || (unsigned)imm >= et.size,
18616 _("immediate out of range for insert"));
18617 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
18618 }
18619
18620 static void
18621 do_neon_sri (void)
18622 {
18623 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18624 return;
18625
18626 enum neon_shape rs;
18627 struct neon_type_el et;
18628 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18629 {
18630 rs = neon_select_shape (NS_QQI, NS_NULL);
18631 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18632 }
18633 else
18634 {
18635 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18636 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18637 }
18638
18639 int imm = inst.operands[2].imm;
18640 constraint (imm < 1 || (unsigned)imm > et.size,
18641 _("immediate out of range for insert"));
18642 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
18643 }
18644
18645 static void
18646 do_neon_qshlu_imm (void)
18647 {
18648 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18649 return;
18650
18651 enum neon_shape rs;
18652 struct neon_type_el et;
18653 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18654 {
18655 rs = neon_select_shape (NS_QQI, NS_NULL);
18656 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18657 }
18658 else
18659 {
18660 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18661 et = neon_check_type (2, rs, N_EQK | N_UNS,
18662 N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
18663 }
18664
18665 int imm = inst.operands[2].imm;
18666 constraint (imm < 0 || (unsigned)imm >= et.size,
18667 _("immediate out of range for shift"));
18668 /* Only encodes the 'U present' variant of the instruction.
18669 In this case, signed types have OP (bit 8) set to 0.
18670 Unsigned types have OP set to 1. */
18671 inst.instruction |= (et.type == NT_unsigned) << 8;
18672 /* The rest of the bits are the same as other immediate shifts. */
18673 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
18674 }
18675
18676 static void
18677 do_neon_qmovn (void)
18678 {
18679 struct neon_type_el et = neon_check_type (2, NS_DQ,
18680 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18681 /* Saturating move where operands can be signed or unsigned, and the
18682 destination has the same signedness. */
18683 NEON_ENCODE (INTEGER, inst);
18684 if (et.type == NT_unsigned)
18685 inst.instruction |= 0xc0;
18686 else
18687 inst.instruction |= 0x80;
18688 neon_two_same (0, 1, et.size / 2);
18689 }
18690
18691 static void
18692 do_neon_qmovun (void)
18693 {
18694 struct neon_type_el et = neon_check_type (2, NS_DQ,
18695 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18696 /* Saturating move with unsigned results. Operands must be signed. */
18697 NEON_ENCODE (INTEGER, inst);
18698 neon_two_same (0, 1, et.size / 2);
18699 }
18700
18701 static void
18702 do_neon_rshift_sat_narrow (void)
18703 {
18704 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18705 or unsigned. If operands are unsigned, results must also be unsigned. */
18706 struct neon_type_el et = neon_check_type (2, NS_DQI,
18707 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18708 int imm = inst.operands[2].imm;
18709 /* This gets the bounds check, size encoding and immediate bits calculation
18710 right. */
18711 et.size /= 2;
18712
18713 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
18714 VQMOVN.I<size> <Dd>, <Qm>. */
18715 if (imm == 0)
18716 {
18717 inst.operands[2].present = 0;
18718 inst.instruction = N_MNEM_vqmovn;
18719 do_neon_qmovn ();
18720 return;
18721 }
18722
18723 constraint (imm < 1 || (unsigned)imm > et.size,
18724 _("immediate out of range"));
18725 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
18726 }
18727
18728 static void
18729 do_neon_rshift_sat_narrow_u (void)
18730 {
18731 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18732 or unsigned. If operands are unsigned, results must also be unsigned. */
18733 struct neon_type_el et = neon_check_type (2, NS_DQI,
18734 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18735 int imm = inst.operands[2].imm;
18736 /* This gets the bounds check, size encoding and immediate bits calculation
18737 right. */
18738 et.size /= 2;
18739
18740 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
18741 VQMOVUN.I<size> <Dd>, <Qm>. */
18742 if (imm == 0)
18743 {
18744 inst.operands[2].present = 0;
18745 inst.instruction = N_MNEM_vqmovun;
18746 do_neon_qmovun ();
18747 return;
18748 }
18749
18750 constraint (imm < 1 || (unsigned)imm > et.size,
18751 _("immediate out of range"));
18752 /* FIXME: The manual is kind of unclear about what value U should have in
18753 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
18754 must be 1. */
18755 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
18756 }
18757
18758 static void
18759 do_neon_movn (void)
18760 {
18761 struct neon_type_el et = neon_check_type (2, NS_DQ,
18762 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18763 NEON_ENCODE (INTEGER, inst);
18764 neon_two_same (0, 1, et.size / 2);
18765 }
18766
18767 static void
18768 do_neon_rshift_narrow (void)
18769 {
18770 struct neon_type_el et = neon_check_type (2, NS_DQI,
18771 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18772 int imm = inst.operands[2].imm;
18773 /* This gets the bounds check, size encoding and immediate bits calculation
18774 right. */
18775 et.size /= 2;
18776
18777 /* If immediate is zero then we are a pseudo-instruction for
18778 VMOVN.I<size> <Dd>, <Qm> */
18779 if (imm == 0)
18780 {
18781 inst.operands[2].present = 0;
18782 inst.instruction = N_MNEM_vmovn;
18783 do_neon_movn ();
18784 return;
18785 }
18786
18787 constraint (imm < 1 || (unsigned)imm > et.size,
18788 _("immediate out of range for narrowing operation"));
18789 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
18790 }
18791
18792 static void
18793 do_neon_shll (void)
18794 {
18795 /* FIXME: Type checking when lengthening. */
18796 struct neon_type_el et = neon_check_type (2, NS_QDI,
18797 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
18798 unsigned imm = inst.operands[2].imm;
18799
18800 if (imm == et.size)
18801 {
18802 /* Maximum shift variant. */
18803 NEON_ENCODE (INTEGER, inst);
18804 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18805 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18806 inst.instruction |= LOW4 (inst.operands[1].reg);
18807 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18808 inst.instruction |= neon_logbits (et.size) << 18;
18809
18810 neon_dp_fixup (&inst);
18811 }
18812 else
18813 {
18814 /* A more-specific type check for non-max versions. */
18815 et = neon_check_type (2, NS_QDI,
18816 N_EQK | N_DBL, N_SU_32 | N_KEY);
18817 NEON_ENCODE (IMMED, inst);
18818 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
18819 }
18820 }
18821
18822 /* Check the various types for the VCVT instruction, and return which version
18823 the current instruction is. */
18824
18825 #define CVT_FLAVOUR_VAR \
18826 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
18827 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
18828 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
18829 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
18830 /* Half-precision conversions. */ \
18831 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18832 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18833 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
18834 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
18835 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
18836 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
18837 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
18838 Compared with single/double precision variants, only the co-processor \
18839 field is different, so the encoding flow is reused here. */ \
18840 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
18841 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
18842 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
18843 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
18844 CVT_VAR (bf16_f32, N_BF16, N_F32, whole_reg, NULL, NULL, NULL) \
18845 /* VFP instructions. */ \
18846 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
18847 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
18848 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
18849 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
18850 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
18851 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
18852 /* VFP instructions with bitshift. */ \
18853 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
18854 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
18855 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
18856 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
18857 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
18858 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
18859 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
18860 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
18861
18862 #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
18863 neon_cvt_flavour_##C,
18864
18865 /* The different types of conversions we can do. */
18866 enum neon_cvt_flavour
18867 {
18868 CVT_FLAVOUR_VAR
18869 neon_cvt_flavour_invalid,
18870 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
18871 };
18872
18873 #undef CVT_VAR
18874
18875 static enum neon_cvt_flavour
18876 get_neon_cvt_flavour (enum neon_shape rs)
18877 {
18878 #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
18879 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
18880 if (et.type != NT_invtype) \
18881 { \
18882 inst.error = NULL; \
18883 return (neon_cvt_flavour_##C); \
18884 }
18885
18886 struct neon_type_el et;
18887 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
18888 || rs == NS_FF) ? N_VFP : 0;
18889 /* The instruction versions which take an immediate take one register
18890 argument, which is extended to the width of the full register. Thus the
18891 "source" and "destination" registers must have the same width. Hack that
18892 here by making the size equal to the key (wider, in this case) operand. */
18893 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
18894
18895 CVT_FLAVOUR_VAR;
18896
18897 return neon_cvt_flavour_invalid;
18898 #undef CVT_VAR
18899 }
18900
18901 enum neon_cvt_mode
18902 {
18903 neon_cvt_mode_a,
18904 neon_cvt_mode_n,
18905 neon_cvt_mode_p,
18906 neon_cvt_mode_m,
18907 neon_cvt_mode_z,
18908 neon_cvt_mode_x,
18909 neon_cvt_mode_r
18910 };
18911
18912 /* Neon-syntax VFP conversions. */
18913
18914 static void
18915 do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
18916 {
18917 const char *opname = 0;
18918
18919 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
18920 || rs == NS_FHI || rs == NS_HFI)
18921 {
18922 /* Conversions with immediate bitshift. */
18923 const char *enc[] =
18924 {
18925 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
18926 CVT_FLAVOUR_VAR
18927 NULL
18928 #undef CVT_VAR
18929 };
18930
18931 if (flavour < (int) ARRAY_SIZE (enc))
18932 {
18933 opname = enc[flavour];
18934 constraint (inst.operands[0].reg != inst.operands[1].reg,
18935 _("operands 0 and 1 must be the same register"));
18936 inst.operands[1] = inst.operands[2];
18937 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
18938 }
18939 }
18940 else
18941 {
18942 /* Conversions without bitshift. */
18943 const char *enc[] =
18944 {
18945 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
18946 CVT_FLAVOUR_VAR
18947 NULL
18948 #undef CVT_VAR
18949 };
18950
18951 if (flavour < (int) ARRAY_SIZE (enc))
18952 opname = enc[flavour];
18953 }
18954
18955 if (opname)
18956 do_vfp_nsyn_opcode (opname);
18957
18958 /* ARMv8.2 fp16 VCVT instruction. */
18959 if (flavour == neon_cvt_flavour_s32_f16
18960 || flavour == neon_cvt_flavour_u32_f16
18961 || flavour == neon_cvt_flavour_f16_u32
18962 || flavour == neon_cvt_flavour_f16_s32)
18963 do_scalar_fp16_v82_encode ();
18964 }
18965
18966 static void
18967 do_vfp_nsyn_cvtz (void)
18968 {
18969 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
18970 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
18971 const char *enc[] =
18972 {
18973 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
18974 CVT_FLAVOUR_VAR
18975 NULL
18976 #undef CVT_VAR
18977 };
18978
18979 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
18980 do_vfp_nsyn_opcode (enc[flavour]);
18981 }
18982
18983 static void
18984 do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
18985 enum neon_cvt_mode mode)
18986 {
18987 int sz, op;
18988 int rm;
18989
18990 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18991 D register operands. */
18992 if (flavour == neon_cvt_flavour_s32_f64
18993 || flavour == neon_cvt_flavour_u32_f64)
18994 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18995 _(BAD_FPU));
18996
18997 if (flavour == neon_cvt_flavour_s32_f16
18998 || flavour == neon_cvt_flavour_u32_f16)
18999 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
19000 _(BAD_FP16));
19001
19002 set_pred_insn_type (OUTSIDE_PRED_INSN);
19003
19004 switch (flavour)
19005 {
19006 case neon_cvt_flavour_s32_f64:
19007 sz = 1;
19008 op = 1;
19009 break;
19010 case neon_cvt_flavour_s32_f32:
19011 sz = 0;
19012 op = 1;
19013 break;
19014 case neon_cvt_flavour_s32_f16:
19015 sz = 0;
19016 op = 1;
19017 break;
19018 case neon_cvt_flavour_u32_f64:
19019 sz = 1;
19020 op = 0;
19021 break;
19022 case neon_cvt_flavour_u32_f32:
19023 sz = 0;
19024 op = 0;
19025 break;
19026 case neon_cvt_flavour_u32_f16:
19027 sz = 0;
19028 op = 0;
19029 break;
19030 default:
19031 first_error (_("invalid instruction shape"));
19032 return;
19033 }
19034
19035 switch (mode)
19036 {
19037 case neon_cvt_mode_a: rm = 0; break;
19038 case neon_cvt_mode_n: rm = 1; break;
19039 case neon_cvt_mode_p: rm = 2; break;
19040 case neon_cvt_mode_m: rm = 3; break;
19041 default: first_error (_("invalid rounding mode")); return;
19042 }
19043
19044 NEON_ENCODE (FPV8, inst);
19045 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
19046 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
19047 inst.instruction |= sz << 8;
19048
19049 /* ARMv8.2 fp16 VCVT instruction. */
19050 if (flavour == neon_cvt_flavour_s32_f16
19051 ||flavour == neon_cvt_flavour_u32_f16)
19052 do_scalar_fp16_v82_encode ();
19053 inst.instruction |= op << 7;
19054 inst.instruction |= rm << 16;
19055 inst.instruction |= 0xf0000000;
19056 inst.is_neon = TRUE;
19057 }
19058
19059 static void
19060 do_neon_cvt_1 (enum neon_cvt_mode mode)
19061 {
19062 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
19063 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
19064 NS_FH, NS_HF, NS_FHI, NS_HFI,
19065 NS_NULL);
19066 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19067
19068 if (flavour == neon_cvt_flavour_invalid)
19069 return;
19070
19071 /* PR11109: Handle round-to-zero for VCVT conversions. */
19072 if (mode == neon_cvt_mode_z
19073 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
19074 && (flavour == neon_cvt_flavour_s16_f16
19075 || flavour == neon_cvt_flavour_u16_f16
19076 || flavour == neon_cvt_flavour_s32_f32
19077 || flavour == neon_cvt_flavour_u32_f32
19078 || flavour == neon_cvt_flavour_s32_f64
19079 || flavour == neon_cvt_flavour_u32_f64)
19080 && (rs == NS_FD || rs == NS_FF))
19081 {
19082 do_vfp_nsyn_cvtz ();
19083 return;
19084 }
19085
19086 /* ARMv8.2 fp16 VCVT conversions. */
19087 if (mode == neon_cvt_mode_z
19088 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
19089 && (flavour == neon_cvt_flavour_s32_f16
19090 || flavour == neon_cvt_flavour_u32_f16)
19091 && (rs == NS_FH))
19092 {
19093 do_vfp_nsyn_cvtz ();
19094 do_scalar_fp16_v82_encode ();
19095 return;
19096 }
19097
19098 /* VFP rather than Neon conversions. */
19099 if (flavour >= neon_cvt_flavour_first_fp)
19100 {
19101 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19102 do_vfp_nsyn_cvt (rs, flavour);
19103 else
19104 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
19105
19106 return;
19107 }
19108
19109 switch (rs)
19110 {
19111 case NS_QQI:
19112 if (mode == neon_cvt_mode_z
19113 && (flavour == neon_cvt_flavour_f16_s16
19114 || flavour == neon_cvt_flavour_f16_u16
19115 || flavour == neon_cvt_flavour_s16_f16
19116 || flavour == neon_cvt_flavour_u16_f16
19117 || flavour == neon_cvt_flavour_f32_u32
19118 || flavour == neon_cvt_flavour_f32_s32
19119 || flavour == neon_cvt_flavour_s32_f32
19120 || flavour == neon_cvt_flavour_u32_f32))
19121 {
19122 if (!check_simd_pred_availability (TRUE,
19123 NEON_CHECK_CC | NEON_CHECK_ARCH))
19124 return;
19125 }
19126 else if (mode == neon_cvt_mode_n)
19127 {
19128 /* We are dealing with vcvt with the 'ne' condition. */
19129 inst.cond = 0x1;
19130 inst.instruction = N_MNEM_vcvt;
19131 do_neon_cvt_1 (neon_cvt_mode_z);
19132 return;
19133 }
19134 /* fall through. */
19135 case NS_DDI:
19136 {
19137 unsigned immbits;
19138 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
19139 0x0000100, 0x1000100, 0x0, 0x1000000};
19140
19141 if ((rs != NS_QQI || !ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19142 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19143 return;
19144
19145 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19146 {
19147 constraint (inst.operands[2].present && inst.operands[2].imm == 0,
19148 _("immediate value out of range"));
19149 switch (flavour)
19150 {
19151 case neon_cvt_flavour_f16_s16:
19152 case neon_cvt_flavour_f16_u16:
19153 case neon_cvt_flavour_s16_f16:
19154 case neon_cvt_flavour_u16_f16:
19155 constraint (inst.operands[2].imm > 16,
19156 _("immediate value out of range"));
19157 break;
19158 case neon_cvt_flavour_f32_u32:
19159 case neon_cvt_flavour_f32_s32:
19160 case neon_cvt_flavour_s32_f32:
19161 case neon_cvt_flavour_u32_f32:
19162 constraint (inst.operands[2].imm > 32,
19163 _("immediate value out of range"));
19164 break;
19165 default:
19166 inst.error = BAD_FPU;
19167 return;
19168 }
19169 }
19170
19171 /* Fixed-point conversion with #0 immediate is encoded as an
19172 integer conversion. */
19173 if (inst.operands[2].present && inst.operands[2].imm == 0)
19174 goto int_encode;
19175 NEON_ENCODE (IMMED, inst);
19176 if (flavour != neon_cvt_flavour_invalid)
19177 inst.instruction |= enctab[flavour];
19178 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19179 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19180 inst.instruction |= LOW4 (inst.operands[1].reg);
19181 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19182 inst.instruction |= neon_quad (rs) << 6;
19183 inst.instruction |= 1 << 21;
19184 if (flavour < neon_cvt_flavour_s16_f16)
19185 {
19186 inst.instruction |= 1 << 21;
19187 immbits = 32 - inst.operands[2].imm;
19188 inst.instruction |= immbits << 16;
19189 }
19190 else
19191 {
19192 inst.instruction |= 3 << 20;
19193 immbits = 16 - inst.operands[2].imm;
19194 inst.instruction |= immbits << 16;
19195 inst.instruction &= ~(1 << 9);
19196 }
19197
19198 neon_dp_fixup (&inst);
19199 }
19200 break;
19201
19202 case NS_QQ:
19203 if ((mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
19204 || mode == neon_cvt_mode_m || mode == neon_cvt_mode_p)
19205 && (flavour == neon_cvt_flavour_s16_f16
19206 || flavour == neon_cvt_flavour_u16_f16
19207 || flavour == neon_cvt_flavour_s32_f32
19208 || flavour == neon_cvt_flavour_u32_f32))
19209 {
19210 if (!check_simd_pred_availability (TRUE,
19211 NEON_CHECK_CC | NEON_CHECK_ARCH8))
19212 return;
19213 }
19214 else if (mode == neon_cvt_mode_z
19215 && (flavour == neon_cvt_flavour_f16_s16
19216 || flavour == neon_cvt_flavour_f16_u16
19217 || flavour == neon_cvt_flavour_s16_f16
19218 || flavour == neon_cvt_flavour_u16_f16
19219 || flavour == neon_cvt_flavour_f32_u32
19220 || flavour == neon_cvt_flavour_f32_s32
19221 || flavour == neon_cvt_flavour_s32_f32
19222 || flavour == neon_cvt_flavour_u32_f32))
19223 {
19224 if (!check_simd_pred_availability (TRUE,
19225 NEON_CHECK_CC | NEON_CHECK_ARCH))
19226 return;
19227 }
19228 /* fall through. */
19229 case NS_DD:
19230 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
19231 {
19232
19233 NEON_ENCODE (FLOAT, inst);
19234 if (!check_simd_pred_availability (TRUE,
19235 NEON_CHECK_CC | NEON_CHECK_ARCH8))
19236 return;
19237
19238 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19239 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19240 inst.instruction |= LOW4 (inst.operands[1].reg);
19241 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19242 inst.instruction |= neon_quad (rs) << 6;
19243 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
19244 || flavour == neon_cvt_flavour_u32_f32) << 7;
19245 inst.instruction |= mode << 8;
19246 if (flavour == neon_cvt_flavour_u16_f16
19247 || flavour == neon_cvt_flavour_s16_f16)
19248 /* Mask off the original size bits and reencode them. */
19249 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
19250
19251 if (thumb_mode)
19252 inst.instruction |= 0xfc000000;
19253 else
19254 inst.instruction |= 0xf0000000;
19255 }
19256 else
19257 {
19258 int_encode:
19259 {
19260 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
19261 0x100, 0x180, 0x0, 0x080};
19262
19263 NEON_ENCODE (INTEGER, inst);
19264
19265 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19266 {
19267 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19268 return;
19269 }
19270
19271 if (flavour != neon_cvt_flavour_invalid)
19272 inst.instruction |= enctab[flavour];
19273
19274 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19275 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19276 inst.instruction |= LOW4 (inst.operands[1].reg);
19277 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19278 inst.instruction |= neon_quad (rs) << 6;
19279 if (flavour >= neon_cvt_flavour_s16_f16
19280 && flavour <= neon_cvt_flavour_f16_u16)
19281 /* Half precision. */
19282 inst.instruction |= 1 << 18;
19283 else
19284 inst.instruction |= 2 << 18;
19285
19286 neon_dp_fixup (&inst);
19287 }
19288 }
19289 break;
19290
19291 /* Half-precision conversions for Advanced SIMD -- neon. */
19292 case NS_QD:
19293 case NS_DQ:
19294 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19295 return;
19296
19297 if ((rs == NS_DQ)
19298 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
19299 {
19300 as_bad (_("operand size must match register width"));
19301 break;
19302 }
19303
19304 if ((rs == NS_QD)
19305 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
19306 {
19307 as_bad (_("operand size must match register width"));
19308 break;
19309 }
19310
19311 if (rs == NS_DQ)
19312 {
19313 if (flavour == neon_cvt_flavour_bf16_f32)
19314 {
19315 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH8) == FAIL)
19316 return;
19317 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19318 /* VCVT.bf16.f32. */
19319 inst.instruction = 0x11b60640;
19320 }
19321 else
19322 /* VCVT.f16.f32. */
19323 inst.instruction = 0x3b60600;
19324 }
19325 else
19326 /* VCVT.f32.f16. */
19327 inst.instruction = 0x3b60700;
19328
19329 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19330 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19331 inst.instruction |= LOW4 (inst.operands[1].reg);
19332 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19333 neon_dp_fixup (&inst);
19334 break;
19335
19336 default:
19337 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
19338 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19339 do_vfp_nsyn_cvt (rs, flavour);
19340 else
19341 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
19342 }
19343 }
19344
19345 static void
19346 do_neon_cvtr (void)
19347 {
19348 do_neon_cvt_1 (neon_cvt_mode_x);
19349 }
19350
19351 static void
19352 do_neon_cvt (void)
19353 {
19354 do_neon_cvt_1 (neon_cvt_mode_z);
19355 }
19356
19357 static void
19358 do_neon_cvta (void)
19359 {
19360 do_neon_cvt_1 (neon_cvt_mode_a);
19361 }
19362
19363 static void
19364 do_neon_cvtn (void)
19365 {
19366 do_neon_cvt_1 (neon_cvt_mode_n);
19367 }
19368
19369 static void
19370 do_neon_cvtp (void)
19371 {
19372 do_neon_cvt_1 (neon_cvt_mode_p);
19373 }
19374
19375 static void
19376 do_neon_cvtm (void)
19377 {
19378 do_neon_cvt_1 (neon_cvt_mode_m);
19379 }
19380
19381 static void
19382 do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
19383 {
19384 if (is_double)
19385 mark_feature_used (&fpu_vfp_ext_armv8);
19386
19387 encode_arm_vfp_reg (inst.operands[0].reg,
19388 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
19389 encode_arm_vfp_reg (inst.operands[1].reg,
19390 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
19391 inst.instruction |= to ? 0x10000 : 0;
19392 inst.instruction |= t ? 0x80 : 0;
19393 inst.instruction |= is_double ? 0x100 : 0;
19394 do_vfp_cond_or_thumb ();
19395 }
19396
19397 static void
19398 do_neon_cvttb_1 (bfd_boolean t)
19399 {
19400 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
19401 NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL);
19402
19403 if (rs == NS_NULL)
19404 return;
19405 else if (rs == NS_QQ || rs == NS_QQI)
19406 {
19407 int single_to_half = 0;
19408 if (!check_simd_pred_availability (TRUE, NEON_CHECK_ARCH))
19409 return;
19410
19411 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19412
19413 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19414 && (flavour == neon_cvt_flavour_u16_f16
19415 || flavour == neon_cvt_flavour_s16_f16
19416 || flavour == neon_cvt_flavour_f16_s16
19417 || flavour == neon_cvt_flavour_f16_u16
19418 || flavour == neon_cvt_flavour_u32_f32
19419 || flavour == neon_cvt_flavour_s32_f32
19420 || flavour == neon_cvt_flavour_f32_s32
19421 || flavour == neon_cvt_flavour_f32_u32))
19422 {
19423 inst.cond = 0xf;
19424 inst.instruction = N_MNEM_vcvt;
19425 set_pred_insn_type (INSIDE_VPT_INSN);
19426 do_neon_cvt_1 (neon_cvt_mode_z);
19427 return;
19428 }
19429 else if (rs == NS_QQ && flavour == neon_cvt_flavour_f32_f16)
19430 single_to_half = 1;
19431 else if (rs == NS_QQ && flavour != neon_cvt_flavour_f16_f32)
19432 {
19433 first_error (BAD_FPU);
19434 return;
19435 }
19436
19437 inst.instruction = 0xee3f0e01;
19438 inst.instruction |= single_to_half << 28;
19439 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19440 inst.instruction |= LOW4 (inst.operands[0].reg) << 13;
19441 inst.instruction |= t << 12;
19442 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19443 inst.instruction |= LOW4 (inst.operands[1].reg) << 1;
19444 inst.is_neon = 1;
19445 }
19446 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
19447 {
19448 inst.error = NULL;
19449 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19450 }
19451 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
19452 {
19453 inst.error = NULL;
19454 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
19455 }
19456 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
19457 {
19458 /* The VCVTB and VCVTT instructions with D-register operands
19459 don't work for SP only targets. */
19460 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19461 _(BAD_FPU));
19462
19463 inst.error = NULL;
19464 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
19465 }
19466 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
19467 {
19468 /* The VCVTB and VCVTT instructions with D-register operands
19469 don't work for SP only targets. */
19470 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19471 _(BAD_FPU));
19472
19473 inst.error = NULL;
19474 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
19475 }
19476 else if (neon_check_type (2, rs, N_BF16 | N_VFP, N_F32).type != NT_invtype)
19477 {
19478 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19479 inst.error = NULL;
19480 inst.instruction |= (1 << 8);
19481 inst.instruction &= ~(1 << 9);
19482 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19483 }
19484 else
19485 return;
19486 }
19487
19488 static void
19489 do_neon_cvtb (void)
19490 {
19491 do_neon_cvttb_1 (FALSE);
19492 }
19493
19494
19495 static void
19496 do_neon_cvtt (void)
19497 {
19498 do_neon_cvttb_1 (TRUE);
19499 }
19500
19501 static void
19502 neon_move_immediate (void)
19503 {
19504 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
19505 struct neon_type_el et = neon_check_type (2, rs,
19506 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
19507 unsigned immlo, immhi = 0, immbits;
19508 int op, cmode, float_p;
19509
19510 constraint (et.type == NT_invtype,
19511 _("operand size must be specified for immediate VMOV"));
19512
19513 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
19514 op = (inst.instruction & (1 << 5)) != 0;
19515
19516 immlo = inst.operands[1].imm;
19517 if (inst.operands[1].regisimm)
19518 immhi = inst.operands[1].reg;
19519
19520 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
19521 _("immediate has bits set outside the operand size"));
19522
19523 float_p = inst.operands[1].immisfloat;
19524
19525 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
19526 et.size, et.type)) == FAIL)
19527 {
19528 /* Invert relevant bits only. */
19529 neon_invert_size (&immlo, &immhi, et.size);
19530 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
19531 with one or the other; those cases are caught by
19532 neon_cmode_for_move_imm. */
19533 op = !op;
19534 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
19535 &op, et.size, et.type)) == FAIL)
19536 {
19537 first_error (_("immediate out of range"));
19538 return;
19539 }
19540 }
19541
19542 inst.instruction &= ~(1 << 5);
19543 inst.instruction |= op << 5;
19544
19545 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19546 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19547 inst.instruction |= neon_quad (rs) << 6;
19548 inst.instruction |= cmode << 8;
19549
19550 neon_write_immbits (immbits);
19551 }
19552
19553 static void
19554 do_neon_mvn (void)
19555 {
19556 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
19557 return;
19558
19559 if (inst.operands[1].isreg)
19560 {
19561 enum neon_shape rs;
19562 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19563 rs = neon_select_shape (NS_QQ, NS_NULL);
19564 else
19565 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19566
19567 NEON_ENCODE (INTEGER, inst);
19568 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19569 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19570 inst.instruction |= LOW4 (inst.operands[1].reg);
19571 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19572 inst.instruction |= neon_quad (rs) << 6;
19573 }
19574 else
19575 {
19576 NEON_ENCODE (IMMED, inst);
19577 neon_move_immediate ();
19578 }
19579
19580 neon_dp_fixup (&inst);
19581
19582 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19583 {
19584 constraint (!inst.operands[1].isreg && !inst.operands[0].isquad, BAD_FPU);
19585 }
19586 }
19587
19588 /* Encode instructions of form:
19589
19590 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
19591 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
19592
19593 static void
19594 neon_mixed_length (struct neon_type_el et, unsigned size)
19595 {
19596 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19597 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19598 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19599 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19600 inst.instruction |= LOW4 (inst.operands[2].reg);
19601 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19602 inst.instruction |= (et.type == NT_unsigned) << 24;
19603 inst.instruction |= neon_logbits (size) << 20;
19604
19605 neon_dp_fixup (&inst);
19606 }
19607
19608 static void
19609 do_neon_dyadic_long (void)
19610 {
19611 enum neon_shape rs = neon_select_shape (NS_QDD, NS_HHH, NS_FFF, NS_DDD, NS_NULL);
19612 if (rs == NS_QDD)
19613 {
19614 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
19615 return;
19616
19617 NEON_ENCODE (INTEGER, inst);
19618 /* FIXME: Type checking for lengthening op. */
19619 struct neon_type_el et = neon_check_type (3, NS_QDD,
19620 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
19621 neon_mixed_length (et, et.size);
19622 }
19623 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19624 && (inst.cond == 0xf || inst.cond == 0x10))
19625 {
19626 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
19627 in an IT block with le/lt conditions. */
19628
19629 if (inst.cond == 0xf)
19630 inst.cond = 0xb;
19631 else if (inst.cond == 0x10)
19632 inst.cond = 0xd;
19633
19634 inst.pred_insn_type = INSIDE_IT_INSN;
19635
19636 if (inst.instruction == N_MNEM_vaddl)
19637 {
19638 inst.instruction = N_MNEM_vadd;
19639 do_neon_addsub_if_i ();
19640 }
19641 else if (inst.instruction == N_MNEM_vsubl)
19642 {
19643 inst.instruction = N_MNEM_vsub;
19644 do_neon_addsub_if_i ();
19645 }
19646 else if (inst.instruction == N_MNEM_vabdl)
19647 {
19648 inst.instruction = N_MNEM_vabd;
19649 do_neon_dyadic_if_su ();
19650 }
19651 }
19652 else
19653 first_error (BAD_FPU);
19654 }
19655
19656 static void
19657 do_neon_abal (void)
19658 {
19659 struct neon_type_el et = neon_check_type (3, NS_QDD,
19660 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
19661 neon_mixed_length (et, et.size);
19662 }
19663
19664 static void
19665 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
19666 {
19667 if (inst.operands[2].isscalar)
19668 {
19669 struct neon_type_el et = neon_check_type (3, NS_QDS,
19670 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
19671 NEON_ENCODE (SCALAR, inst);
19672 neon_mul_mac (et, et.type == NT_unsigned);
19673 }
19674 else
19675 {
19676 struct neon_type_el et = neon_check_type (3, NS_QDD,
19677 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
19678 NEON_ENCODE (INTEGER, inst);
19679 neon_mixed_length (et, et.size);
19680 }
19681 }
19682
19683 static void
19684 do_neon_mac_maybe_scalar_long (void)
19685 {
19686 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
19687 }
19688
19689 /* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
19690 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
19691
19692 static unsigned
19693 neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
19694 {
19695 unsigned regno = NEON_SCALAR_REG (scalar);
19696 unsigned elno = NEON_SCALAR_INDEX (scalar);
19697
19698 if (quad_p)
19699 {
19700 if (regno > 7 || elno > 3)
19701 goto bad_scalar;
19702
19703 return ((regno & 0x7)
19704 | ((elno & 0x1) << 3)
19705 | (((elno >> 1) & 0x1) << 5));
19706 }
19707 else
19708 {
19709 if (regno > 15 || elno > 1)
19710 goto bad_scalar;
19711
19712 return (((regno & 0x1) << 5)
19713 | ((regno >> 1) & 0x7)
19714 | ((elno & 0x1) << 3));
19715 }
19716
19717 bad_scalar:
19718 first_error (_("scalar out of range for multiply instruction"));
19719 return 0;
19720 }
19721
19722 static void
19723 do_neon_fmac_maybe_scalar_long (int subtype)
19724 {
19725 enum neon_shape rs;
19726 int high8;
19727 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
19728 field (bits[21:20]) has different meaning. For scalar index variant, it's
19729 used to differentiate add and subtract, otherwise it's with fixed value
19730 0x2. */
19731 int size = -1;
19732
19733 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
19734 be a scalar index register. */
19735 if (inst.operands[2].isscalar)
19736 {
19737 high8 = 0xfe000000;
19738 if (subtype)
19739 size = 16;
19740 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
19741 }
19742 else
19743 {
19744 high8 = 0xfc000000;
19745 size = 32;
19746 if (subtype)
19747 inst.instruction |= (0x1 << 23);
19748 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
19749 }
19750
19751
19752 if (inst.cond != COND_ALWAYS)
19753 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
19754 "behaviour is UNPREDICTABLE"));
19755
19756 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
19757 _(BAD_FP16));
19758
19759 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
19760 _(BAD_FPU));
19761
19762 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
19763 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
19764 so we simply pass -1 as size. */
19765 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
19766 neon_three_same (quad_p, 0, size);
19767
19768 /* Undo neon_dp_fixup. Redo the high eight bits. */
19769 inst.instruction &= 0x00ffffff;
19770 inst.instruction |= high8;
19771
19772 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
19773 whether the instruction is in Q form and whether Vm is a scalar indexed
19774 operand. */
19775 if (inst.operands[2].isscalar)
19776 {
19777 unsigned rm
19778 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
19779 inst.instruction &= 0xffffffd0;
19780 inst.instruction |= rm;
19781
19782 if (!quad_p)
19783 {
19784 /* Redo Rn as well. */
19785 inst.instruction &= 0xfff0ff7f;
19786 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19787 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19788 }
19789 }
19790 else if (!quad_p)
19791 {
19792 /* Redo Rn and Rm. */
19793 inst.instruction &= 0xfff0ff50;
19794 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19795 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19796 inst.instruction |= HI4 (inst.operands[2].reg);
19797 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
19798 }
19799 }
19800
19801 static void
19802 do_neon_vfmal (void)
19803 {
19804 return do_neon_fmac_maybe_scalar_long (0);
19805 }
19806
19807 static void
19808 do_neon_vfmsl (void)
19809 {
19810 return do_neon_fmac_maybe_scalar_long (1);
19811 }
19812
19813 static void
19814 do_neon_dyadic_wide (void)
19815 {
19816 struct neon_type_el et = neon_check_type (3, NS_QQD,
19817 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
19818 neon_mixed_length (et, et.size);
19819 }
19820
19821 static void
19822 do_neon_dyadic_narrow (void)
19823 {
19824 struct neon_type_el et = neon_check_type (3, NS_QDD,
19825 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
19826 /* Operand sign is unimportant, and the U bit is part of the opcode,
19827 so force the operand type to integer. */
19828 et.type = NT_integer;
19829 neon_mixed_length (et, et.size / 2);
19830 }
19831
19832 static void
19833 do_neon_mul_sat_scalar_long (void)
19834 {
19835 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
19836 }
19837
19838 static void
19839 do_neon_vmull (void)
19840 {
19841 if (inst.operands[2].isscalar)
19842 do_neon_mac_maybe_scalar_long ();
19843 else
19844 {
19845 struct neon_type_el et = neon_check_type (3, NS_QDD,
19846 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
19847
19848 if (et.type == NT_poly)
19849 NEON_ENCODE (POLY, inst);
19850 else
19851 NEON_ENCODE (INTEGER, inst);
19852
19853 /* For polynomial encoding the U bit must be zero, and the size must
19854 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
19855 obviously, as 0b10). */
19856 if (et.size == 64)
19857 {
19858 /* Check we're on the correct architecture. */
19859 if (!mark_feature_used (&fpu_crypto_ext_armv8))
19860 inst.error =
19861 _("Instruction form not available on this architecture.");
19862
19863 et.size = 32;
19864 }
19865
19866 neon_mixed_length (et, et.size);
19867 }
19868 }
19869
19870 static void
19871 do_neon_ext (void)
19872 {
19873 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
19874 struct neon_type_el et = neon_check_type (3, rs,
19875 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
19876 unsigned imm = (inst.operands[3].imm * et.size) / 8;
19877
19878 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
19879 _("shift out of range"));
19880 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19881 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19882 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19883 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19884 inst.instruction |= LOW4 (inst.operands[2].reg);
19885 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19886 inst.instruction |= neon_quad (rs) << 6;
19887 inst.instruction |= imm << 8;
19888
19889 neon_dp_fixup (&inst);
19890 }
19891
19892 static void
19893 do_neon_rev (void)
19894 {
19895 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
19896 return;
19897
19898 enum neon_shape rs;
19899 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19900 rs = neon_select_shape (NS_QQ, NS_NULL);
19901 else
19902 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19903
19904 struct neon_type_el et = neon_check_type (2, rs,
19905 N_EQK, N_8 | N_16 | N_32 | N_KEY);
19906
19907 unsigned op = (inst.instruction >> 7) & 3;
19908 /* N (width of reversed regions) is encoded as part of the bitmask. We
19909 extract it here to check the elements to be reversed are smaller.
19910 Otherwise we'd get a reserved instruction. */
19911 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
19912
19913 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) && elsize == 64
19914 && inst.operands[0].reg == inst.operands[1].reg)
19915 as_tsktsk (_("Warning: 64-bit element size and same destination and source"
19916 " operands makes instruction UNPREDICTABLE"));
19917
19918 gas_assert (elsize != 0);
19919 constraint (et.size >= elsize,
19920 _("elements must be smaller than reversal region"));
19921 neon_two_same (neon_quad (rs), 1, et.size);
19922 }
19923
19924 static void
19925 do_neon_dup (void)
19926 {
19927 if (inst.operands[1].isscalar)
19928 {
19929 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19930 BAD_FPU);
19931 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
19932 struct neon_type_el et = neon_check_type (2, rs,
19933 N_EQK, N_8 | N_16 | N_32 | N_KEY);
19934 unsigned sizebits = et.size >> 3;
19935 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
19936 int logsize = neon_logbits (et.size);
19937 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
19938
19939 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
19940 return;
19941
19942 NEON_ENCODE (SCALAR, inst);
19943 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19944 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19945 inst.instruction |= LOW4 (dm);
19946 inst.instruction |= HI1 (dm) << 5;
19947 inst.instruction |= neon_quad (rs) << 6;
19948 inst.instruction |= x << 17;
19949 inst.instruction |= sizebits << 16;
19950
19951 neon_dp_fixup (&inst);
19952 }
19953 else
19954 {
19955 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
19956 struct neon_type_el et = neon_check_type (2, rs,
19957 N_8 | N_16 | N_32 | N_KEY, N_EQK);
19958 if (rs == NS_QR)
19959 {
19960 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH))
19961 return;
19962 }
19963 else
19964 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19965 BAD_FPU);
19966
19967 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19968 {
19969 if (inst.operands[1].reg == REG_SP)
19970 as_tsktsk (MVE_BAD_SP);
19971 else if (inst.operands[1].reg == REG_PC)
19972 as_tsktsk (MVE_BAD_PC);
19973 }
19974
19975 /* Duplicate ARM register to lanes of vector. */
19976 NEON_ENCODE (ARMREG, inst);
19977 switch (et.size)
19978 {
19979 case 8: inst.instruction |= 0x400000; break;
19980 case 16: inst.instruction |= 0x000020; break;
19981 case 32: inst.instruction |= 0x000000; break;
19982 default: break;
19983 }
19984 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
19985 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
19986 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
19987 inst.instruction |= neon_quad (rs) << 21;
19988 /* The encoding for this instruction is identical for the ARM and Thumb
19989 variants, except for the condition field. */
19990 do_vfp_cond_or_thumb ();
19991 }
19992 }
19993
19994 static void
19995 do_mve_mov (int toQ)
19996 {
19997 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19998 return;
19999 if (inst.cond > COND_ALWAYS)
20000 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
20001
20002 unsigned Rt = 0, Rt2 = 1, Q0 = 2, Q1 = 3;
20003 if (toQ)
20004 {
20005 Q0 = 0;
20006 Q1 = 1;
20007 Rt = 2;
20008 Rt2 = 3;
20009 }
20010
20011 constraint (inst.operands[Q0].reg != inst.operands[Q1].reg + 2,
20012 _("Index one must be [2,3] and index two must be two less than"
20013 " index one."));
20014 constraint (inst.operands[Rt].reg == inst.operands[Rt2].reg,
20015 _("General purpose registers may not be the same"));
20016 constraint (inst.operands[Rt].reg == REG_SP
20017 || inst.operands[Rt2].reg == REG_SP,
20018 BAD_SP);
20019 constraint (inst.operands[Rt].reg == REG_PC
20020 || inst.operands[Rt2].reg == REG_PC,
20021 BAD_PC);
20022
20023 inst.instruction = 0xec000f00;
20024 inst.instruction |= HI1 (inst.operands[Q1].reg / 32) << 23;
20025 inst.instruction |= !!toQ << 20;
20026 inst.instruction |= inst.operands[Rt2].reg << 16;
20027 inst.instruction |= LOW4 (inst.operands[Q1].reg / 32) << 13;
20028 inst.instruction |= (inst.operands[Q1].reg % 4) << 4;
20029 inst.instruction |= inst.operands[Rt].reg;
20030 }
20031
20032 static void
20033 do_mve_movn (void)
20034 {
20035 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20036 return;
20037
20038 if (inst.cond > COND_ALWAYS)
20039 inst.pred_insn_type = INSIDE_VPT_INSN;
20040 else
20041 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
20042
20043 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_I16 | N_I32
20044 | N_KEY);
20045
20046 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20047 inst.instruction |= (neon_logbits (et.size) - 1) << 18;
20048 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20049 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20050 inst.instruction |= LOW4 (inst.operands[1].reg);
20051 inst.is_neon = 1;
20052
20053 }
20054
20055 /* VMOV has particularly many variations. It can be one of:
20056 0. VMOV<c><q> <Qd>, <Qm>
20057 1. VMOV<c><q> <Dd>, <Dm>
20058 (Register operations, which are VORR with Rm = Rn.)
20059 2. VMOV<c><q>.<dt> <Qd>, #<imm>
20060 3. VMOV<c><q>.<dt> <Dd>, #<imm>
20061 (Immediate loads.)
20062 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
20063 (ARM register to scalar.)
20064 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
20065 (Two ARM registers to vector.)
20066 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
20067 (Scalar to ARM register.)
20068 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
20069 (Vector to two ARM registers.)
20070 8. VMOV.F32 <Sd>, <Sm>
20071 9. VMOV.F64 <Dd>, <Dm>
20072 (VFP register moves.)
20073 10. VMOV.F32 <Sd>, #imm
20074 11. VMOV.F64 <Dd>, #imm
20075 (VFP float immediate load.)
20076 12. VMOV <Rd>, <Sm>
20077 (VFP single to ARM reg.)
20078 13. VMOV <Sd>, <Rm>
20079 (ARM reg to VFP single.)
20080 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
20081 (Two ARM regs to two VFP singles.)
20082 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
20083 (Two VFP singles to two ARM regs.)
20084 16. VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]>
20085 17. VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2>
20086 18. VMOV<c>.<dt> <Rt>, <Qn[idx]>
20087 19. VMOV<c>.<dt> <Qd[idx]>, <Rt>
20088
20089 These cases can be disambiguated using neon_select_shape, except cases 1/9
20090 and 3/11 which depend on the operand type too.
20091
20092 All the encoded bits are hardcoded by this function.
20093
20094 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
20095 Cases 5, 7 may be used with VFPv2 and above.
20096
20097 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
20098 can specify a type where it doesn't make sense to, and is ignored). */
20099
20100 static void
20101 do_neon_mov (void)
20102 {
20103 enum neon_shape rs = neon_select_shape (NS_RRSS, NS_SSRR, NS_RRFF, NS_FFRR,
20104 NS_DRR, NS_RRD, NS_QQ, NS_DD, NS_QI,
20105 NS_DI, NS_SR, NS_RS, NS_FF, NS_FI,
20106 NS_RF, NS_FR, NS_HR, NS_RH, NS_HI,
20107 NS_NULL);
20108 struct neon_type_el et;
20109 const char *ldconst = 0;
20110
20111 switch (rs)
20112 {
20113 case NS_DD: /* case 1/9. */
20114 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20115 /* It is not an error here if no type is given. */
20116 inst.error = NULL;
20117
20118 /* In MVE we interpret the following instructions as same, so ignoring
20119 the following type (float) and size (64) checks.
20120 a: VMOV<c><q> <Dd>, <Dm>
20121 b: VMOV<c><q>.F64 <Dd>, <Dm>. */
20122 if ((et.type == NT_float && et.size == 64)
20123 || (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
20124 {
20125 do_vfp_nsyn_opcode ("fcpyd");
20126 break;
20127 }
20128 /* fall through. */
20129
20130 case NS_QQ: /* case 0/1. */
20131 {
20132 if (!check_simd_pred_availability (FALSE,
20133 NEON_CHECK_CC | NEON_CHECK_ARCH))
20134 return;
20135 /* The architecture manual I have doesn't explicitly state which
20136 value the U bit should have for register->register moves, but
20137 the equivalent VORR instruction has U = 0, so do that. */
20138 inst.instruction = 0x0200110;
20139 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20140 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20141 inst.instruction |= LOW4 (inst.operands[1].reg);
20142 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20143 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20144 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20145 inst.instruction |= neon_quad (rs) << 6;
20146
20147 neon_dp_fixup (&inst);
20148 }
20149 break;
20150
20151 case NS_DI: /* case 3/11. */
20152 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20153 inst.error = NULL;
20154 if (et.type == NT_float && et.size == 64)
20155 {
20156 /* case 11 (fconstd). */
20157 ldconst = "fconstd";
20158 goto encode_fconstd;
20159 }
20160 /* fall through. */
20161
20162 case NS_QI: /* case 2/3. */
20163 if (!check_simd_pred_availability (FALSE,
20164 NEON_CHECK_CC | NEON_CHECK_ARCH))
20165 return;
20166 inst.instruction = 0x0800010;
20167 neon_move_immediate ();
20168 neon_dp_fixup (&inst);
20169 break;
20170
20171 case NS_SR: /* case 4. */
20172 {
20173 unsigned bcdebits = 0;
20174 int logsize;
20175 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
20176 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
20177
20178 /* .<size> is optional here, defaulting to .32. */
20179 if (inst.vectype.elems == 0
20180 && inst.operands[0].vectype.type == NT_invtype
20181 && inst.operands[1].vectype.type == NT_invtype)
20182 {
20183 inst.vectype.el[0].type = NT_untyped;
20184 inst.vectype.el[0].size = 32;
20185 inst.vectype.elems = 1;
20186 }
20187
20188 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
20189 logsize = neon_logbits (et.size);
20190
20191 if (et.size != 32)
20192 {
20193 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20194 && vfp_or_neon_is_neon (NEON_CHECK_ARCH) == FAIL)
20195 return;
20196 }
20197 else
20198 {
20199 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20200 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20201 _(BAD_FPU));
20202 }
20203
20204 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20205 {
20206 if (inst.operands[1].reg == REG_SP)
20207 as_tsktsk (MVE_BAD_SP);
20208 else if (inst.operands[1].reg == REG_PC)
20209 as_tsktsk (MVE_BAD_PC);
20210 }
20211 unsigned size = inst.operands[0].isscalar == 1 ? 64 : 128;
20212
20213 constraint (et.type == NT_invtype, _("bad type for scalar"));
20214 constraint (x >= size / et.size, _("scalar index out of range"));
20215
20216
20217 switch (et.size)
20218 {
20219 case 8: bcdebits = 0x8; break;
20220 case 16: bcdebits = 0x1; break;
20221 case 32: bcdebits = 0x0; break;
20222 default: ;
20223 }
20224
20225 bcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
20226
20227 inst.instruction = 0xe000b10;
20228 do_vfp_cond_or_thumb ();
20229 inst.instruction |= LOW4 (dn) << 16;
20230 inst.instruction |= HI1 (dn) << 7;
20231 inst.instruction |= inst.operands[1].reg << 12;
20232 inst.instruction |= (bcdebits & 3) << 5;
20233 inst.instruction |= ((bcdebits >> 2) & 3) << 21;
20234 inst.instruction |= (x >> (3-logsize)) << 16;
20235 }
20236 break;
20237
20238 case NS_DRR: /* case 5 (fmdrr). */
20239 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20240 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20241 _(BAD_FPU));
20242
20243 inst.instruction = 0xc400b10;
20244 do_vfp_cond_or_thumb ();
20245 inst.instruction |= LOW4 (inst.operands[0].reg);
20246 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
20247 inst.instruction |= inst.operands[1].reg << 12;
20248 inst.instruction |= inst.operands[2].reg << 16;
20249 break;
20250
20251 case NS_RS: /* case 6. */
20252 {
20253 unsigned logsize;
20254 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
20255 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
20256 unsigned abcdebits = 0;
20257
20258 /* .<dt> is optional here, defaulting to .32. */
20259 if (inst.vectype.elems == 0
20260 && inst.operands[0].vectype.type == NT_invtype
20261 && inst.operands[1].vectype.type == NT_invtype)
20262 {
20263 inst.vectype.el[0].type = NT_untyped;
20264 inst.vectype.el[0].size = 32;
20265 inst.vectype.elems = 1;
20266 }
20267
20268 et = neon_check_type (2, NS_NULL,
20269 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
20270 logsize = neon_logbits (et.size);
20271
20272 if (et.size != 32)
20273 {
20274 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20275 && vfp_or_neon_is_neon (NEON_CHECK_CC
20276 | NEON_CHECK_ARCH) == FAIL)
20277 return;
20278 }
20279 else
20280 {
20281 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20282 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20283 _(BAD_FPU));
20284 }
20285
20286 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20287 {
20288 if (inst.operands[0].reg == REG_SP)
20289 as_tsktsk (MVE_BAD_SP);
20290 else if (inst.operands[0].reg == REG_PC)
20291 as_tsktsk (MVE_BAD_PC);
20292 }
20293
20294 unsigned size = inst.operands[1].isscalar == 1 ? 64 : 128;
20295
20296 constraint (et.type == NT_invtype, _("bad type for scalar"));
20297 constraint (x >= size / et.size, _("scalar index out of range"));
20298
20299 switch (et.size)
20300 {
20301 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
20302 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
20303 case 32: abcdebits = 0x00; break;
20304 default: ;
20305 }
20306
20307 abcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
20308 inst.instruction = 0xe100b10;
20309 do_vfp_cond_or_thumb ();
20310 inst.instruction |= LOW4 (dn) << 16;
20311 inst.instruction |= HI1 (dn) << 7;
20312 inst.instruction |= inst.operands[0].reg << 12;
20313 inst.instruction |= (abcdebits & 3) << 5;
20314 inst.instruction |= (abcdebits >> 2) << 21;
20315 inst.instruction |= (x >> (3-logsize)) << 16;
20316 }
20317 break;
20318
20319 case NS_RRD: /* case 7 (fmrrd). */
20320 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20321 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20322 _(BAD_FPU));
20323
20324 inst.instruction = 0xc500b10;
20325 do_vfp_cond_or_thumb ();
20326 inst.instruction |= inst.operands[0].reg << 12;
20327 inst.instruction |= inst.operands[1].reg << 16;
20328 inst.instruction |= LOW4 (inst.operands[2].reg);
20329 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20330 break;
20331
20332 case NS_FF: /* case 8 (fcpys). */
20333 do_vfp_nsyn_opcode ("fcpys");
20334 break;
20335
20336 case NS_HI:
20337 case NS_FI: /* case 10 (fconsts). */
20338 ldconst = "fconsts";
20339 encode_fconstd:
20340 if (!inst.operands[1].immisfloat)
20341 {
20342 unsigned new_imm;
20343 /* Immediate has to fit in 8 bits so float is enough. */
20344 float imm = (float) inst.operands[1].imm;
20345 memcpy (&new_imm, &imm, sizeof (float));
20346 /* But the assembly may have been written to provide an integer
20347 bit pattern that equates to a float, so check that the
20348 conversion has worked. */
20349 if (is_quarter_float (new_imm))
20350 {
20351 if (is_quarter_float (inst.operands[1].imm))
20352 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
20353
20354 inst.operands[1].imm = new_imm;
20355 inst.operands[1].immisfloat = 1;
20356 }
20357 }
20358
20359 if (is_quarter_float (inst.operands[1].imm))
20360 {
20361 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
20362 do_vfp_nsyn_opcode (ldconst);
20363
20364 /* ARMv8.2 fp16 vmov.f16 instruction. */
20365 if (rs == NS_HI)
20366 do_scalar_fp16_v82_encode ();
20367 }
20368 else
20369 first_error (_("immediate out of range"));
20370 break;
20371
20372 case NS_RH:
20373 case NS_RF: /* case 12 (fmrs). */
20374 do_vfp_nsyn_opcode ("fmrs");
20375 /* ARMv8.2 fp16 vmov.f16 instruction. */
20376 if (rs == NS_RH)
20377 do_scalar_fp16_v82_encode ();
20378 break;
20379
20380 case NS_HR:
20381 case NS_FR: /* case 13 (fmsr). */
20382 do_vfp_nsyn_opcode ("fmsr");
20383 /* ARMv8.2 fp16 vmov.f16 instruction. */
20384 if (rs == NS_HR)
20385 do_scalar_fp16_v82_encode ();
20386 break;
20387
20388 case NS_RRSS:
20389 do_mve_mov (0);
20390 break;
20391 case NS_SSRR:
20392 do_mve_mov (1);
20393 break;
20394
20395 /* The encoders for the fmrrs and fmsrr instructions expect three operands
20396 (one of which is a list), but we have parsed four. Do some fiddling to
20397 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
20398 expect. */
20399 case NS_RRFF: /* case 14 (fmrrs). */
20400 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20401 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20402 _(BAD_FPU));
20403 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
20404 _("VFP registers must be adjacent"));
20405 inst.operands[2].imm = 2;
20406 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20407 do_vfp_nsyn_opcode ("fmrrs");
20408 break;
20409
20410 case NS_FFRR: /* case 15 (fmsrr). */
20411 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20412 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20413 _(BAD_FPU));
20414 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
20415 _("VFP registers must be adjacent"));
20416 inst.operands[1] = inst.operands[2];
20417 inst.operands[2] = inst.operands[3];
20418 inst.operands[0].imm = 2;
20419 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20420 do_vfp_nsyn_opcode ("fmsrr");
20421 break;
20422
20423 case NS_NULL:
20424 /* neon_select_shape has determined that the instruction
20425 shape is wrong and has already set the error message. */
20426 break;
20427
20428 default:
20429 abort ();
20430 }
20431 }
20432
20433 static void
20434 do_mve_movl (void)
20435 {
20436 if (!(inst.operands[0].present && inst.operands[0].isquad
20437 && inst.operands[1].present && inst.operands[1].isquad
20438 && !inst.operands[2].present))
20439 {
20440 inst.instruction = 0;
20441 inst.cond = 0xb;
20442 if (thumb_mode)
20443 set_pred_insn_type (INSIDE_IT_INSN);
20444 do_neon_mov ();
20445 return;
20446 }
20447
20448 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20449 return;
20450
20451 if (inst.cond != COND_ALWAYS)
20452 inst.pred_insn_type = INSIDE_VPT_INSN;
20453
20454 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_S8 | N_U8
20455 | N_S16 | N_U16 | N_KEY);
20456
20457 inst.instruction |= (et.type == NT_unsigned) << 28;
20458 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20459 inst.instruction |= (neon_logbits (et.size) + 1) << 19;
20460 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20461 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20462 inst.instruction |= LOW4 (inst.operands[1].reg);
20463 inst.is_neon = 1;
20464 }
20465
20466 static void
20467 do_neon_rshift_round_imm (void)
20468 {
20469 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
20470 return;
20471
20472 enum neon_shape rs;
20473 struct neon_type_el et;
20474
20475 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20476 {
20477 rs = neon_select_shape (NS_QQI, NS_NULL);
20478 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
20479 }
20480 else
20481 {
20482 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
20483 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
20484 }
20485 int imm = inst.operands[2].imm;
20486
20487 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
20488 if (imm == 0)
20489 {
20490 inst.operands[2].present = 0;
20491 do_neon_mov ();
20492 return;
20493 }
20494
20495 constraint (imm < 1 || (unsigned)imm > et.size,
20496 _("immediate out of range for shift"));
20497 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
20498 et.size - imm);
20499 }
20500
20501 static void
20502 do_neon_movhf (void)
20503 {
20504 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
20505 constraint (rs != NS_HH, _("invalid suffix"));
20506
20507 if (inst.cond != COND_ALWAYS)
20508 {
20509 if (thumb_mode)
20510 {
20511 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
20512 " the behaviour is UNPREDICTABLE"));
20513 }
20514 else
20515 {
20516 inst.error = BAD_COND;
20517 return;
20518 }
20519 }
20520
20521 do_vfp_sp_monadic ();
20522
20523 inst.is_neon = 1;
20524 inst.instruction |= 0xf0000000;
20525 }
20526
20527 static void
20528 do_neon_movl (void)
20529 {
20530 struct neon_type_el et = neon_check_type (2, NS_QD,
20531 N_EQK | N_DBL, N_SU_32 | N_KEY);
20532 unsigned sizebits = et.size >> 3;
20533 inst.instruction |= sizebits << 19;
20534 neon_two_same (0, et.type == NT_unsigned, -1);
20535 }
20536
20537 static void
20538 do_neon_trn (void)
20539 {
20540 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20541 struct neon_type_el et = neon_check_type (2, rs,
20542 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20543 NEON_ENCODE (INTEGER, inst);
20544 neon_two_same (neon_quad (rs), 1, et.size);
20545 }
20546
20547 static void
20548 do_neon_zip_uzp (void)
20549 {
20550 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20551 struct neon_type_el et = neon_check_type (2, rs,
20552 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20553 if (rs == NS_DD && et.size == 32)
20554 {
20555 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
20556 inst.instruction = N_MNEM_vtrn;
20557 do_neon_trn ();
20558 return;
20559 }
20560 neon_two_same (neon_quad (rs), 1, et.size);
20561 }
20562
20563 static void
20564 do_neon_sat_abs_neg (void)
20565 {
20566 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
20567 return;
20568
20569 enum neon_shape rs;
20570 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20571 rs = neon_select_shape (NS_QQ, NS_NULL);
20572 else
20573 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20574 struct neon_type_el et = neon_check_type (2, rs,
20575 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
20576 neon_two_same (neon_quad (rs), 1, et.size);
20577 }
20578
20579 static void
20580 do_neon_pair_long (void)
20581 {
20582 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20583 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
20584 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
20585 inst.instruction |= (et.type == NT_unsigned) << 7;
20586 neon_two_same (neon_quad (rs), 1, et.size);
20587 }
20588
20589 static void
20590 do_neon_recip_est (void)
20591 {
20592 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20593 struct neon_type_el et = neon_check_type (2, rs,
20594 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
20595 inst.instruction |= (et.type == NT_float) << 8;
20596 neon_two_same (neon_quad (rs), 1, et.size);
20597 }
20598
20599 static void
20600 do_neon_cls (void)
20601 {
20602 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
20603 return;
20604
20605 enum neon_shape rs;
20606 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20607 rs = neon_select_shape (NS_QQ, NS_NULL);
20608 else
20609 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20610
20611 struct neon_type_el et = neon_check_type (2, rs,
20612 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
20613 neon_two_same (neon_quad (rs), 1, et.size);
20614 }
20615
20616 static void
20617 do_neon_clz (void)
20618 {
20619 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
20620 return;
20621
20622 enum neon_shape rs;
20623 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20624 rs = neon_select_shape (NS_QQ, NS_NULL);
20625 else
20626 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20627
20628 struct neon_type_el et = neon_check_type (2, rs,
20629 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
20630 neon_two_same (neon_quad (rs), 1, et.size);
20631 }
20632
20633 static void
20634 do_neon_cnt (void)
20635 {
20636 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20637 struct neon_type_el et = neon_check_type (2, rs,
20638 N_EQK | N_INT, N_8 | N_KEY);
20639 neon_two_same (neon_quad (rs), 1, et.size);
20640 }
20641
20642 static void
20643 do_neon_swp (void)
20644 {
20645 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20646 neon_two_same (neon_quad (rs), 1, -1);
20647 }
20648
20649 static void
20650 do_neon_tbl_tbx (void)
20651 {
20652 unsigned listlenbits;
20653 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
20654
20655 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
20656 {
20657 first_error (_("bad list length for table lookup"));
20658 return;
20659 }
20660
20661 listlenbits = inst.operands[1].imm - 1;
20662 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20663 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20664 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20665 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20666 inst.instruction |= LOW4 (inst.operands[2].reg);
20667 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20668 inst.instruction |= listlenbits << 8;
20669
20670 neon_dp_fixup (&inst);
20671 }
20672
20673 static void
20674 do_neon_ldm_stm (void)
20675 {
20676 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
20677 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20678 _(BAD_FPU));
20679 /* P, U and L bits are part of bitmask. */
20680 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
20681 unsigned offsetbits = inst.operands[1].imm * 2;
20682
20683 if (inst.operands[1].issingle)
20684 {
20685 do_vfp_nsyn_ldm_stm (is_dbmode);
20686 return;
20687 }
20688
20689 constraint (is_dbmode && !inst.operands[0].writeback,
20690 _("writeback (!) must be used for VLDMDB and VSTMDB"));
20691
20692 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20693 _("register list must contain at least 1 and at most 16 "
20694 "registers"));
20695
20696 inst.instruction |= inst.operands[0].reg << 16;
20697 inst.instruction |= inst.operands[0].writeback << 21;
20698 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
20699 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
20700
20701 inst.instruction |= offsetbits;
20702
20703 do_vfp_cond_or_thumb ();
20704 }
20705
20706 static void
20707 do_vfp_nsyn_pop (void)
20708 {
20709 nsyn_insert_sp ();
20710 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20711 return do_vfp_nsyn_opcode ("vldm");
20712 }
20713
20714 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20715 _(BAD_FPU));
20716
20717 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20718 _("register list must contain at least 1 and at most 16 "
20719 "registers"));
20720
20721 if (inst.operands[1].issingle)
20722 do_vfp_nsyn_opcode ("fldmias");
20723 else
20724 do_vfp_nsyn_opcode ("fldmiad");
20725 }
20726
20727 static void
20728 do_vfp_nsyn_push (void)
20729 {
20730 nsyn_insert_sp ();
20731 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20732 return do_vfp_nsyn_opcode ("vstmdb");
20733 }
20734
20735 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20736 _(BAD_FPU));
20737
20738 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20739 _("register list must contain at least 1 and at most 16 "
20740 "registers"));
20741
20742 if (inst.operands[1].issingle)
20743 do_vfp_nsyn_opcode ("fstmdbs");
20744 else
20745 do_vfp_nsyn_opcode ("fstmdbd");
20746 }
20747
20748
20749 static void
20750 do_neon_ldr_str (void)
20751 {
20752 int is_ldr = (inst.instruction & (1 << 20)) != 0;
20753
20754 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
20755 And is UNPREDICTABLE in thumb mode. */
20756 if (!is_ldr
20757 && inst.operands[1].reg == REG_PC
20758 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
20759 {
20760 if (thumb_mode)
20761 inst.error = _("Use of PC here is UNPREDICTABLE");
20762 else if (warn_on_deprecated)
20763 as_tsktsk (_("Use of PC here is deprecated"));
20764 }
20765
20766 if (inst.operands[0].issingle)
20767 {
20768 if (is_ldr)
20769 do_vfp_nsyn_opcode ("flds");
20770 else
20771 do_vfp_nsyn_opcode ("fsts");
20772
20773 /* ARMv8.2 vldr.16/vstr.16 instruction. */
20774 if (inst.vectype.el[0].size == 16)
20775 do_scalar_fp16_v82_encode ();
20776 }
20777 else
20778 {
20779 if (is_ldr)
20780 do_vfp_nsyn_opcode ("fldd");
20781 else
20782 do_vfp_nsyn_opcode ("fstd");
20783 }
20784 }
20785
20786 static void
20787 do_t_vldr_vstr_sysreg (void)
20788 {
20789 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
20790 bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
20791
20792 /* Use of PC is UNPREDICTABLE. */
20793 if (inst.operands[1].reg == REG_PC)
20794 inst.error = _("Use of PC here is UNPREDICTABLE");
20795
20796 if (inst.operands[1].immisreg)
20797 inst.error = _("instruction does not accept register index");
20798
20799 if (!inst.operands[1].isreg)
20800 inst.error = _("instruction does not accept PC-relative addressing");
20801
20802 if (abs (inst.operands[1].imm) >= (1 << 7))
20803 inst.error = _("immediate value out of range");
20804
20805 inst.instruction = 0xec000f80;
20806 if (is_vldr)
20807 inst.instruction |= 1 << sysreg_vldr_bitno;
20808 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
20809 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
20810 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
20811 }
20812
20813 static void
20814 do_vldr_vstr (void)
20815 {
20816 bfd_boolean sysreg_op = !inst.operands[0].isreg;
20817
20818 /* VLDR/VSTR (System Register). */
20819 if (sysreg_op)
20820 {
20821 if (!mark_feature_used (&arm_ext_v8_1m_main))
20822 as_bad (_("Instruction not permitted on this architecture"));
20823
20824 do_t_vldr_vstr_sysreg ();
20825 }
20826 /* VLDR/VSTR. */
20827 else
20828 {
20829 if (!mark_feature_used (&fpu_vfp_ext_v1xd)
20830 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20831 as_bad (_("Instruction not permitted on this architecture"));
20832 do_neon_ldr_str ();
20833 }
20834 }
20835
20836 /* "interleave" version also handles non-interleaving register VLD1/VST1
20837 instructions. */
20838
20839 static void
20840 do_neon_ld_st_interleave (void)
20841 {
20842 struct neon_type_el et = neon_check_type (1, NS_NULL,
20843 N_8 | N_16 | N_32 | N_64);
20844 unsigned alignbits = 0;
20845 unsigned idx;
20846 /* The bits in this table go:
20847 0: register stride of one (0) or two (1)
20848 1,2: register list length, minus one (1, 2, 3, 4).
20849 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
20850 We use -1 for invalid entries. */
20851 const int typetable[] =
20852 {
20853 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
20854 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
20855 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
20856 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
20857 };
20858 int typebits;
20859
20860 if (et.type == NT_invtype)
20861 return;
20862
20863 if (inst.operands[1].immisalign)
20864 switch (inst.operands[1].imm >> 8)
20865 {
20866 case 64: alignbits = 1; break;
20867 case 128:
20868 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
20869 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20870 goto bad_alignment;
20871 alignbits = 2;
20872 break;
20873 case 256:
20874 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20875 goto bad_alignment;
20876 alignbits = 3;
20877 break;
20878 default:
20879 bad_alignment:
20880 first_error (_("bad alignment"));
20881 return;
20882 }
20883
20884 inst.instruction |= alignbits << 4;
20885 inst.instruction |= neon_logbits (et.size) << 6;
20886
20887 /* Bits [4:6] of the immediate in a list specifier encode register stride
20888 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
20889 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
20890 up the right value for "type" in a table based on this value and the given
20891 list style, then stick it back. */
20892 idx = ((inst.operands[0].imm >> 4) & 7)
20893 | (((inst.instruction >> 8) & 3) << 3);
20894
20895 typebits = typetable[idx];
20896
20897 constraint (typebits == -1, _("bad list type for instruction"));
20898 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
20899 BAD_EL_TYPE);
20900
20901 inst.instruction &= ~0xf00;
20902 inst.instruction |= typebits << 8;
20903 }
20904
20905 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
20906 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
20907 otherwise. The variable arguments are a list of pairs of legal (size, align)
20908 values, terminated with -1. */
20909
20910 static int
20911 neon_alignment_bit (int size, int align, int *do_alignment, ...)
20912 {
20913 va_list ap;
20914 int result = FAIL, thissize, thisalign;
20915
20916 if (!inst.operands[1].immisalign)
20917 {
20918 *do_alignment = 0;
20919 return SUCCESS;
20920 }
20921
20922 va_start (ap, do_alignment);
20923
20924 do
20925 {
20926 thissize = va_arg (ap, int);
20927 if (thissize == -1)
20928 break;
20929 thisalign = va_arg (ap, int);
20930
20931 if (size == thissize && align == thisalign)
20932 result = SUCCESS;
20933 }
20934 while (result != SUCCESS);
20935
20936 va_end (ap);
20937
20938 if (result == SUCCESS)
20939 *do_alignment = 1;
20940 else
20941 first_error (_("unsupported alignment for instruction"));
20942
20943 return result;
20944 }
20945
20946 static void
20947 do_neon_ld_st_lane (void)
20948 {
20949 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
20950 int align_good, do_alignment = 0;
20951 int logsize = neon_logbits (et.size);
20952 int align = inst.operands[1].imm >> 8;
20953 int n = (inst.instruction >> 8) & 3;
20954 int max_el = 64 / et.size;
20955
20956 if (et.type == NT_invtype)
20957 return;
20958
20959 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
20960 _("bad list length"));
20961 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
20962 _("scalar index out of range"));
20963 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
20964 && et.size == 8,
20965 _("stride of 2 unavailable when element size is 8"));
20966
20967 switch (n)
20968 {
20969 case 0: /* VLD1 / VST1. */
20970 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
20971 32, 32, -1);
20972 if (align_good == FAIL)
20973 return;
20974 if (do_alignment)
20975 {
20976 unsigned alignbits = 0;
20977 switch (et.size)
20978 {
20979 case 16: alignbits = 0x1; break;
20980 case 32: alignbits = 0x3; break;
20981 default: ;
20982 }
20983 inst.instruction |= alignbits << 4;
20984 }
20985 break;
20986
20987 case 1: /* VLD2 / VST2. */
20988 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
20989 16, 32, 32, 64, -1);
20990 if (align_good == FAIL)
20991 return;
20992 if (do_alignment)
20993 inst.instruction |= 1 << 4;
20994 break;
20995
20996 case 2: /* VLD3 / VST3. */
20997 constraint (inst.operands[1].immisalign,
20998 _("can't use alignment with this instruction"));
20999 break;
21000
21001 case 3: /* VLD4 / VST4. */
21002 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
21003 16, 64, 32, 64, 32, 128, -1);
21004 if (align_good == FAIL)
21005 return;
21006 if (do_alignment)
21007 {
21008 unsigned alignbits = 0;
21009 switch (et.size)
21010 {
21011 case 8: alignbits = 0x1; break;
21012 case 16: alignbits = 0x1; break;
21013 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
21014 default: ;
21015 }
21016 inst.instruction |= alignbits << 4;
21017 }
21018 break;
21019
21020 default: ;
21021 }
21022
21023 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
21024 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21025 inst.instruction |= 1 << (4 + logsize);
21026
21027 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
21028 inst.instruction |= logsize << 10;
21029 }
21030
21031 /* Encode single n-element structure to all lanes VLD<n> instructions. */
21032
21033 static void
21034 do_neon_ld_dup (void)
21035 {
21036 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
21037 int align_good, do_alignment = 0;
21038
21039 if (et.type == NT_invtype)
21040 return;
21041
21042 switch ((inst.instruction >> 8) & 3)
21043 {
21044 case 0: /* VLD1. */
21045 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
21046 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
21047 &do_alignment, 16, 16, 32, 32, -1);
21048 if (align_good == FAIL)
21049 return;
21050 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
21051 {
21052 case 1: break;
21053 case 2: inst.instruction |= 1 << 5; break;
21054 default: first_error (_("bad list length")); return;
21055 }
21056 inst.instruction |= neon_logbits (et.size) << 6;
21057 break;
21058
21059 case 1: /* VLD2. */
21060 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
21061 &do_alignment, 8, 16, 16, 32, 32, 64,
21062 -1);
21063 if (align_good == FAIL)
21064 return;
21065 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
21066 _("bad list length"));
21067 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21068 inst.instruction |= 1 << 5;
21069 inst.instruction |= neon_logbits (et.size) << 6;
21070 break;
21071
21072 case 2: /* VLD3. */
21073 constraint (inst.operands[1].immisalign,
21074 _("can't use alignment with this instruction"));
21075 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
21076 _("bad list length"));
21077 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21078 inst.instruction |= 1 << 5;
21079 inst.instruction |= neon_logbits (et.size) << 6;
21080 break;
21081
21082 case 3: /* VLD4. */
21083 {
21084 int align = inst.operands[1].imm >> 8;
21085 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
21086 16, 64, 32, 64, 32, 128, -1);
21087 if (align_good == FAIL)
21088 return;
21089 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
21090 _("bad list length"));
21091 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21092 inst.instruction |= 1 << 5;
21093 if (et.size == 32 && align == 128)
21094 inst.instruction |= 0x3 << 6;
21095 else
21096 inst.instruction |= neon_logbits (et.size) << 6;
21097 }
21098 break;
21099
21100 default: ;
21101 }
21102
21103 inst.instruction |= do_alignment << 4;
21104 }
21105
21106 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
21107 apart from bits [11:4]. */
21108
21109 static void
21110 do_neon_ldx_stx (void)
21111 {
21112 if (inst.operands[1].isreg)
21113 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
21114
21115 switch (NEON_LANE (inst.operands[0].imm))
21116 {
21117 case NEON_INTERLEAVE_LANES:
21118 NEON_ENCODE (INTERLV, inst);
21119 do_neon_ld_st_interleave ();
21120 break;
21121
21122 case NEON_ALL_LANES:
21123 NEON_ENCODE (DUP, inst);
21124 if (inst.instruction == N_INV)
21125 {
21126 first_error ("only loads support such operands");
21127 break;
21128 }
21129 do_neon_ld_dup ();
21130 break;
21131
21132 default:
21133 NEON_ENCODE (LANE, inst);
21134 do_neon_ld_st_lane ();
21135 }
21136
21137 /* L bit comes from bit mask. */
21138 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21139 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21140 inst.instruction |= inst.operands[1].reg << 16;
21141
21142 if (inst.operands[1].postind)
21143 {
21144 int postreg = inst.operands[1].imm & 0xf;
21145 constraint (!inst.operands[1].immisreg,
21146 _("post-index must be a register"));
21147 constraint (postreg == 0xd || postreg == 0xf,
21148 _("bad register for post-index"));
21149 inst.instruction |= postreg;
21150 }
21151 else
21152 {
21153 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
21154 constraint (inst.relocs[0].exp.X_op != O_constant
21155 || inst.relocs[0].exp.X_add_number != 0,
21156 BAD_ADDR_MODE);
21157
21158 if (inst.operands[1].writeback)
21159 {
21160 inst.instruction |= 0xd;
21161 }
21162 else
21163 inst.instruction |= 0xf;
21164 }
21165
21166 if (thumb_mode)
21167 inst.instruction |= 0xf9000000;
21168 else
21169 inst.instruction |= 0xf4000000;
21170 }
21171
21172 /* FP v8. */
21173 static void
21174 do_vfp_nsyn_fpv8 (enum neon_shape rs)
21175 {
21176 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21177 D register operands. */
21178 if (neon_shape_class[rs] == SC_DOUBLE)
21179 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21180 _(BAD_FPU));
21181
21182 NEON_ENCODE (FPV8, inst);
21183
21184 if (rs == NS_FFF || rs == NS_HHH)
21185 {
21186 do_vfp_sp_dyadic ();
21187
21188 /* ARMv8.2 fp16 instruction. */
21189 if (rs == NS_HHH)
21190 do_scalar_fp16_v82_encode ();
21191 }
21192 else
21193 do_vfp_dp_rd_rn_rm ();
21194
21195 if (rs == NS_DDD)
21196 inst.instruction |= 0x100;
21197
21198 inst.instruction |= 0xf0000000;
21199 }
21200
21201 static void
21202 do_vsel (void)
21203 {
21204 set_pred_insn_type (OUTSIDE_PRED_INSN);
21205
21206 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
21207 first_error (_("invalid instruction shape"));
21208 }
21209
21210 static void
21211 do_vmaxnm (void)
21212 {
21213 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21214 set_pred_insn_type (OUTSIDE_PRED_INSN);
21215
21216 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
21217 return;
21218
21219 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH8))
21220 return;
21221
21222 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
21223 }
21224
21225 static void
21226 do_vrint_1 (enum neon_cvt_mode mode)
21227 {
21228 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
21229 struct neon_type_el et;
21230
21231 if (rs == NS_NULL)
21232 return;
21233
21234 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21235 D register operands. */
21236 if (neon_shape_class[rs] == SC_DOUBLE)
21237 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21238 _(BAD_FPU));
21239
21240 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
21241 | N_VFP);
21242 if (et.type != NT_invtype)
21243 {
21244 /* VFP encodings. */
21245 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
21246 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
21247 set_pred_insn_type (OUTSIDE_PRED_INSN);
21248
21249 NEON_ENCODE (FPV8, inst);
21250 if (rs == NS_FF || rs == NS_HH)
21251 do_vfp_sp_monadic ();
21252 else
21253 do_vfp_dp_rd_rm ();
21254
21255 switch (mode)
21256 {
21257 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
21258 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
21259 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
21260 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
21261 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
21262 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
21263 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
21264 default: abort ();
21265 }
21266
21267 inst.instruction |= (rs == NS_DD) << 8;
21268 do_vfp_cond_or_thumb ();
21269
21270 /* ARMv8.2 fp16 vrint instruction. */
21271 if (rs == NS_HH)
21272 do_scalar_fp16_v82_encode ();
21273 }
21274 else
21275 {
21276 /* Neon encodings (or something broken...). */
21277 inst.error = NULL;
21278 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
21279
21280 if (et.type == NT_invtype)
21281 return;
21282
21283 if (!check_simd_pred_availability (TRUE,
21284 NEON_CHECK_CC | NEON_CHECK_ARCH8))
21285 return;
21286
21287 NEON_ENCODE (FLOAT, inst);
21288
21289 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21290 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21291 inst.instruction |= LOW4 (inst.operands[1].reg);
21292 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21293 inst.instruction |= neon_quad (rs) << 6;
21294 /* Mask off the original size bits and reencode them. */
21295 inst.instruction = ((inst.instruction & 0xfff3ffff)
21296 | neon_logbits (et.size) << 18);
21297
21298 switch (mode)
21299 {
21300 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
21301 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
21302 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
21303 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
21304 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
21305 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
21306 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
21307 default: abort ();
21308 }
21309
21310 if (thumb_mode)
21311 inst.instruction |= 0xfc000000;
21312 else
21313 inst.instruction |= 0xf0000000;
21314 }
21315 }
21316
21317 static void
21318 do_vrintx (void)
21319 {
21320 do_vrint_1 (neon_cvt_mode_x);
21321 }
21322
21323 static void
21324 do_vrintz (void)
21325 {
21326 do_vrint_1 (neon_cvt_mode_z);
21327 }
21328
21329 static void
21330 do_vrintr (void)
21331 {
21332 do_vrint_1 (neon_cvt_mode_r);
21333 }
21334
21335 static void
21336 do_vrinta (void)
21337 {
21338 do_vrint_1 (neon_cvt_mode_a);
21339 }
21340
21341 static void
21342 do_vrintn (void)
21343 {
21344 do_vrint_1 (neon_cvt_mode_n);
21345 }
21346
21347 static void
21348 do_vrintp (void)
21349 {
21350 do_vrint_1 (neon_cvt_mode_p);
21351 }
21352
21353 static void
21354 do_vrintm (void)
21355 {
21356 do_vrint_1 (neon_cvt_mode_m);
21357 }
21358
21359 static unsigned
21360 neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
21361 {
21362 unsigned regno = NEON_SCALAR_REG (opnd);
21363 unsigned elno = NEON_SCALAR_INDEX (opnd);
21364
21365 if (elsize == 16 && elno < 2 && regno < 16)
21366 return regno | (elno << 4);
21367 else if (elsize == 32 && elno == 0)
21368 return regno;
21369
21370 first_error (_("scalar out of range"));
21371 return 0;
21372 }
21373
21374 static void
21375 do_vcmla (void)
21376 {
21377 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)
21378 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21379 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
21380 constraint (inst.relocs[0].exp.X_op != O_constant,
21381 _("expression too complex"));
21382 unsigned rot = inst.relocs[0].exp.X_add_number;
21383 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
21384 _("immediate out of range"));
21385 rot /= 90;
21386
21387 if (!check_simd_pred_availability (TRUE,
21388 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
21389 return;
21390
21391 if (inst.operands[2].isscalar)
21392 {
21393 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21394 first_error (_("invalid instruction shape"));
21395 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
21396 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21397 N_KEY | N_F16 | N_F32).size;
21398 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
21399 inst.is_neon = 1;
21400 inst.instruction = 0xfe000800;
21401 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21402 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21403 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21404 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21405 inst.instruction |= LOW4 (m);
21406 inst.instruction |= HI1 (m) << 5;
21407 inst.instruction |= neon_quad (rs) << 6;
21408 inst.instruction |= rot << 20;
21409 inst.instruction |= (size == 32) << 23;
21410 }
21411 else
21412 {
21413 enum neon_shape rs;
21414 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21415 rs = neon_select_shape (NS_QQQI, NS_NULL);
21416 else
21417 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21418
21419 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21420 N_KEY | N_F16 | N_F32).size;
21421 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) && size == 32
21422 && (inst.operands[0].reg == inst.operands[1].reg
21423 || inst.operands[0].reg == inst.operands[2].reg))
21424 as_tsktsk (BAD_MVE_SRCDEST);
21425
21426 neon_three_same (neon_quad (rs), 0, -1);
21427 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21428 inst.instruction |= 0xfc200800;
21429 inst.instruction |= rot << 23;
21430 inst.instruction |= (size == 32) << 20;
21431 }
21432 }
21433
21434 static void
21435 do_vcadd (void)
21436 {
21437 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
21438 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21439 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
21440 constraint (inst.relocs[0].exp.X_op != O_constant,
21441 _("expression too complex"));
21442
21443 unsigned rot = inst.relocs[0].exp.X_add_number;
21444 constraint (rot != 90 && rot != 270, _("immediate out of range"));
21445 enum neon_shape rs;
21446 struct neon_type_el et;
21447 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21448 {
21449 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21450 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32);
21451 }
21452 else
21453 {
21454 rs = neon_select_shape (NS_QQQI, NS_NULL);
21455 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32 | N_I8
21456 | N_I16 | N_I32);
21457 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
21458 as_tsktsk (_("Warning: 32-bit element size and same first and third "
21459 "operand makes instruction UNPREDICTABLE"));
21460 }
21461
21462 if (et.type == NT_invtype)
21463 return;
21464
21465 if (!check_simd_pred_availability (et.type == NT_float,
21466 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
21467 return;
21468
21469 if (et.type == NT_float)
21470 {
21471 neon_three_same (neon_quad (rs), 0, -1);
21472 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21473 inst.instruction |= 0xfc800800;
21474 inst.instruction |= (rot == 270) << 24;
21475 inst.instruction |= (et.size == 32) << 20;
21476 }
21477 else
21478 {
21479 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
21480 inst.instruction = 0xfe000f00;
21481 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21482 inst.instruction |= neon_logbits (et.size) << 20;
21483 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21484 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21485 inst.instruction |= (rot == 270) << 12;
21486 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21487 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
21488 inst.instruction |= LOW4 (inst.operands[2].reg);
21489 inst.is_neon = 1;
21490 }
21491 }
21492
21493 /* Dot Product instructions encoding support. */
21494
21495 static void
21496 do_neon_dotproduct (int unsigned_p)
21497 {
21498 enum neon_shape rs;
21499 unsigned scalar_oprd2 = 0;
21500 int high8;
21501
21502 if (inst.cond != COND_ALWAYS)
21503 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
21504 "is UNPREDICTABLE"));
21505
21506 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
21507 _(BAD_FPU));
21508
21509 /* Dot Product instructions are in three-same D/Q register format or the third
21510 operand can be a scalar index register. */
21511 if (inst.operands[2].isscalar)
21512 {
21513 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
21514 high8 = 0xfe000000;
21515 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21516 }
21517 else
21518 {
21519 high8 = 0xfc000000;
21520 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21521 }
21522
21523 if (unsigned_p)
21524 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
21525 else
21526 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
21527
21528 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
21529 Product instruction, so we pass 0 as the "ubit" parameter. And the
21530 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
21531 neon_three_same (neon_quad (rs), 0, 32);
21532
21533 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
21534 different NEON three-same encoding. */
21535 inst.instruction &= 0x00ffffff;
21536 inst.instruction |= high8;
21537 /* Encode 'U' bit which indicates signedness. */
21538 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
21539 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
21540 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
21541 the instruction encoding. */
21542 if (inst.operands[2].isscalar)
21543 {
21544 inst.instruction &= 0xffffffd0;
21545 inst.instruction |= LOW4 (scalar_oprd2);
21546 inst.instruction |= HI1 (scalar_oprd2) << 5;
21547 }
21548 }
21549
21550 /* Dot Product instructions for signed integer. */
21551
21552 static void
21553 do_neon_dotproduct_s (void)
21554 {
21555 return do_neon_dotproduct (0);
21556 }
21557
21558 /* Dot Product instructions for unsigned integer. */
21559
21560 static void
21561 do_neon_dotproduct_u (void)
21562 {
21563 return do_neon_dotproduct (1);
21564 }
21565
21566 static void
21567 do_vusdot (void)
21568 {
21569 enum neon_shape rs;
21570 set_pred_insn_type (OUTSIDE_PRED_INSN);
21571 if (inst.operands[2].isscalar)
21572 {
21573 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21574 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21575
21576 inst.instruction |= (1 << 25);
21577 int index = inst.operands[2].reg & 0xf;
21578 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21579 inst.operands[2].reg >>= 4;
21580 constraint (!(inst.operands[2].reg < 16),
21581 _("indexed register must be less than 16"));
21582 neon_three_args (rs == NS_QQS);
21583 inst.instruction |= (index << 5);
21584 }
21585 else
21586 {
21587 inst.instruction |= (1 << 21);
21588 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21589 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21590 neon_three_args (rs == NS_QQQ);
21591 }
21592 }
21593
21594 static void
21595 do_vsudot (void)
21596 {
21597 enum neon_shape rs;
21598 set_pred_insn_type (OUTSIDE_PRED_INSN);
21599 if (inst.operands[2].isscalar)
21600 {
21601 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21602 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21603
21604 inst.instruction |= (1 << 25);
21605 int index = inst.operands[2].reg & 0xf;
21606 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21607 inst.operands[2].reg >>= 4;
21608 constraint (!(inst.operands[2].reg < 16),
21609 _("indexed register must be less than 16"));
21610 neon_three_args (rs == NS_QQS);
21611 inst.instruction |= (index << 5);
21612 }
21613 }
21614
21615 static void
21616 do_vsmmla (void)
21617 {
21618 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21619 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21620
21621 set_pred_insn_type (OUTSIDE_PRED_INSN);
21622
21623 neon_three_args (1);
21624
21625 }
21626
21627 static void
21628 do_vummla (void)
21629 {
21630 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21631 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21632
21633 set_pred_insn_type (OUTSIDE_PRED_INSN);
21634
21635 neon_three_args (1);
21636
21637 }
21638
21639 static void
21640 check_cde_operand (size_t index, int is_dual)
21641 {
21642 unsigned Rx = inst.operands[index].reg;
21643 bfd_boolean isvec = inst.operands[index].isvec;
21644 if (is_dual == 0 && thumb_mode)
21645 constraint (
21646 !((Rx <= 14 && Rx != 13) || (Rx == REG_PC && isvec)),
21647 _("Register must be r0-r14 except r13, or APSR_nzcv."));
21648 else
21649 constraint ( !((Rx <= 10 && Rx % 2 == 0 )),
21650 _("Register must be an even register between r0-r10."));
21651 }
21652
21653 static bfd_boolean
21654 cde_coproc_enabled (unsigned coproc)
21655 {
21656 switch (coproc)
21657 {
21658 case 0: return mark_feature_used (&arm_ext_cde0);
21659 case 1: return mark_feature_used (&arm_ext_cde1);
21660 case 2: return mark_feature_used (&arm_ext_cde2);
21661 case 3: return mark_feature_used (&arm_ext_cde3);
21662 case 4: return mark_feature_used (&arm_ext_cde4);
21663 case 5: return mark_feature_used (&arm_ext_cde5);
21664 case 6: return mark_feature_used (&arm_ext_cde6);
21665 case 7: return mark_feature_used (&arm_ext_cde7);
21666 default: return FALSE;
21667 }
21668 }
21669
21670 #define cde_coproc_pos 8
21671 static void
21672 cde_handle_coproc (void)
21673 {
21674 unsigned coproc = inst.operands[0].reg;
21675 constraint (coproc > 7, _("CDE Coprocessor must be in range 0-7"));
21676 constraint (!(cde_coproc_enabled (coproc)), BAD_CDE_COPROC);
21677 inst.instruction |= coproc << cde_coproc_pos;
21678 }
21679 #undef cde_coproc_pos
21680
21681 static void
21682 cxn_handle_predication (bfd_boolean is_accum)
21683 {
21684 if (is_accum && conditional_insn ())
21685 set_pred_insn_type (INSIDE_IT_INSN);
21686 else if (conditional_insn ())
21687 /* conditional_insn essentially checks for a suffix, not whether the
21688 instruction is inside an IT block or not.
21689 The non-accumulator versions should not have suffixes. */
21690 inst.error = BAD_SYNTAX;
21691 else
21692 set_pred_insn_type (OUTSIDE_PRED_INSN);
21693 }
21694
21695 static void
21696 do_custom_instruction_1 (int is_dual, bfd_boolean is_accum)
21697 {
21698
21699 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21700
21701 unsigned imm, Rd;
21702
21703 Rd = inst.operands[1].reg;
21704 check_cde_operand (1, is_dual);
21705
21706 if (is_dual == 1)
21707 {
21708 constraint (inst.operands[2].reg != Rd + 1,
21709 _("cx1d requires consecutive destination registers."));
21710 imm = inst.operands[3].imm;
21711 }
21712 else if (is_dual == 0)
21713 imm = inst.operands[2].imm;
21714 else
21715 abort ();
21716
21717 inst.instruction |= Rd << 12;
21718 inst.instruction |= (imm & 0x1F80) << 9;
21719 inst.instruction |= (imm & 0x0040) << 1;
21720 inst.instruction |= (imm & 0x003f);
21721
21722 cde_handle_coproc ();
21723 cxn_handle_predication (is_accum);
21724 }
21725
21726 static void
21727 do_custom_instruction_2 (int is_dual, bfd_boolean is_accum)
21728 {
21729
21730 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21731
21732 unsigned imm, Rd, Rn;
21733
21734 Rd = inst.operands[1].reg;
21735
21736 if (is_dual == 1)
21737 {
21738 constraint (inst.operands[2].reg != Rd + 1,
21739 _("cx2d requires consecutive destination registers."));
21740 imm = inst.operands[4].imm;
21741 Rn = inst.operands[3].reg;
21742 }
21743 else if (is_dual == 0)
21744 {
21745 imm = inst.operands[3].imm;
21746 Rn = inst.operands[2].reg;
21747 }
21748 else
21749 abort ();
21750
21751 check_cde_operand (2 + is_dual, /* is_dual = */0);
21752 check_cde_operand (1, is_dual);
21753
21754 inst.instruction |= Rd << 12;
21755 inst.instruction |= Rn << 16;
21756
21757 inst.instruction |= (imm & 0x0380) << 13;
21758 inst.instruction |= (imm & 0x0040) << 1;
21759 inst.instruction |= (imm & 0x003f);
21760
21761 cde_handle_coproc ();
21762 cxn_handle_predication (is_accum);
21763 }
21764
21765 static void
21766 do_custom_instruction_3 (int is_dual, bfd_boolean is_accum)
21767 {
21768
21769 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21770
21771 unsigned imm, Rd, Rn, Rm;
21772
21773 Rd = inst.operands[1].reg;
21774
21775 if (is_dual == 1)
21776 {
21777 constraint (inst.operands[2].reg != Rd + 1,
21778 _("cx3d requires consecutive destination registers."));
21779 imm = inst.operands[5].imm;
21780 Rn = inst.operands[3].reg;
21781 Rm = inst.operands[4].reg;
21782 }
21783 else if (is_dual == 0)
21784 {
21785 imm = inst.operands[4].imm;
21786 Rn = inst.operands[2].reg;
21787 Rm = inst.operands[3].reg;
21788 }
21789 else
21790 abort ();
21791
21792 check_cde_operand (1, is_dual);
21793 check_cde_operand (2 + is_dual, /* is_dual = */0);
21794 check_cde_operand (3 + is_dual, /* is_dual = */0);
21795
21796 inst.instruction |= Rd;
21797 inst.instruction |= Rn << 16;
21798 inst.instruction |= Rm << 12;
21799
21800 inst.instruction |= (imm & 0x0038) << 17;
21801 inst.instruction |= (imm & 0x0004) << 5;
21802 inst.instruction |= (imm & 0x0003) << 4;
21803
21804 cde_handle_coproc ();
21805 cxn_handle_predication (is_accum);
21806 }
21807
21808 static void
21809 do_cx1 (void)
21810 {
21811 return do_custom_instruction_1 (0, 0);
21812 }
21813
21814 static void
21815 do_cx1a (void)
21816 {
21817 return do_custom_instruction_1 (0, 1);
21818 }
21819
21820 static void
21821 do_cx1d (void)
21822 {
21823 return do_custom_instruction_1 (1, 0);
21824 }
21825
21826 static void
21827 do_cx1da (void)
21828 {
21829 return do_custom_instruction_1 (1, 1);
21830 }
21831
21832 static void
21833 do_cx2 (void)
21834 {
21835 return do_custom_instruction_2 (0, 0);
21836 }
21837
21838 static void
21839 do_cx2a (void)
21840 {
21841 return do_custom_instruction_2 (0, 1);
21842 }
21843
21844 static void
21845 do_cx2d (void)
21846 {
21847 return do_custom_instruction_2 (1, 0);
21848 }
21849
21850 static void
21851 do_cx2da (void)
21852 {
21853 return do_custom_instruction_2 (1, 1);
21854 }
21855
21856 static void
21857 do_cx3 (void)
21858 {
21859 return do_custom_instruction_3 (0, 0);
21860 }
21861
21862 static void
21863 do_cx3a (void)
21864 {
21865 return do_custom_instruction_3 (0, 1);
21866 }
21867
21868 static void
21869 do_cx3d (void)
21870 {
21871 return do_custom_instruction_3 (1, 0);
21872 }
21873
21874 static void
21875 do_cx3da (void)
21876 {
21877 return do_custom_instruction_3 (1, 1);
21878 }
21879
21880 static void
21881 vcx_assign_vec_d (unsigned regnum)
21882 {
21883 inst.instruction |= HI4 (regnum) << 12;
21884 inst.instruction |= LOW1 (regnum) << 22;
21885 }
21886
21887 static void
21888 vcx_assign_vec_m (unsigned regnum)
21889 {
21890 inst.instruction |= HI4 (regnum);
21891 inst.instruction |= LOW1 (regnum) << 5;
21892 }
21893
21894 static void
21895 vcx_assign_vec_n (unsigned regnum)
21896 {
21897 inst.instruction |= HI4 (regnum) << 16;
21898 inst.instruction |= LOW1 (regnum) << 7;
21899 }
21900
21901 enum vcx_reg_type {
21902 q_reg,
21903 d_reg,
21904 s_reg
21905 };
21906
21907 static enum vcx_reg_type
21908 vcx_get_reg_type (enum neon_shape ns)
21909 {
21910 gas_assert (ns == NS_PQI
21911 || ns == NS_PDI
21912 || ns == NS_PFI
21913 || ns == NS_PQQI
21914 || ns == NS_PDDI
21915 || ns == NS_PFFI
21916 || ns == NS_PQQQI
21917 || ns == NS_PDDDI
21918 || ns == NS_PFFFI);
21919 if (ns == NS_PQI || ns == NS_PQQI || ns == NS_PQQQI)
21920 return q_reg;
21921 if (ns == NS_PDI || ns == NS_PDDI || ns == NS_PDDDI)
21922 return d_reg;
21923 return s_reg;
21924 }
21925
21926 #define vcx_size_pos 24
21927 #define vcx_vec_pos 6
21928 static unsigned
21929 vcx_handle_shape (enum vcx_reg_type reg_type)
21930 {
21931 unsigned mult = 2;
21932 if (reg_type == q_reg)
21933 inst.instruction |= 1 << vcx_vec_pos;
21934 else if (reg_type == d_reg)
21935 inst.instruction |= 1 << vcx_size_pos;
21936 else
21937 mult = 1;
21938 /* NOTE:
21939 The documentation says that the Q registers are encoded as 2*N in the D:Vd
21940 bits (or equivalent for N and M registers).
21941 Similarly the D registers are encoded as N in D:Vd bits.
21942 While the S registers are encoded as N in the Vd:D bits.
21943
21944 Taking into account the maximum values of these registers we can see a
21945 nicer pattern for calculation:
21946 Q -> 7, D -> 15, S -> 31
21947
21948 If we say that everything is encoded in the Vd:D bits, then we can say
21949 that Q is encoded as 4*N, and D is encoded as 2*N.
21950 This way the bits will end up the same, and calculation is simpler.
21951 (calculation is now:
21952 1. Multiply by a number determined by the register letter.
21953 2. Encode resulting number in Vd:D bits.)
21954
21955 This is made a little more complicated by automatic handling of 'Q'
21956 registers elsewhere, which means the register number is already 2*N where
21957 N is the number the user wrote after the register letter.
21958 */
21959 return mult;
21960 }
21961 #undef vcx_vec_pos
21962 #undef vcx_size_pos
21963
21964 static void
21965 vcx_ensure_register_in_range (unsigned R, enum vcx_reg_type reg_type)
21966 {
21967 if (reg_type == q_reg)
21968 {
21969 gas_assert (R % 2 == 0);
21970 constraint (R >= 16, _("'q' register must be in range 0-7"));
21971 }
21972 else if (reg_type == d_reg)
21973 constraint (R >= 16, _("'d' register must be in range 0-15"));
21974 else
21975 constraint (R >= 32, _("'s' register must be in range 0-31"));
21976 }
21977
21978 static void (*vcx_assign_vec[3]) (unsigned) = {
21979 vcx_assign_vec_d,
21980 vcx_assign_vec_m,
21981 vcx_assign_vec_n
21982 };
21983
21984 static void
21985 vcx_handle_register_arguments (unsigned num_registers,
21986 enum vcx_reg_type reg_type)
21987 {
21988 unsigned R, i;
21989 unsigned reg_mult = vcx_handle_shape (reg_type);
21990 for (i = 0; i < num_registers; i++)
21991 {
21992 R = inst.operands[i+1].reg;
21993 vcx_ensure_register_in_range (R, reg_type);
21994 if (num_registers == 3 && i > 0)
21995 {
21996 if (i == 2)
21997 vcx_assign_vec[1] (R * reg_mult);
21998 else
21999 vcx_assign_vec[2] (R * reg_mult);
22000 continue;
22001 }
22002 vcx_assign_vec[i](R * reg_mult);
22003 }
22004 }
22005
22006 static void
22007 vcx_handle_insn_block (enum vcx_reg_type reg_type)
22008 {
22009 if (reg_type == q_reg)
22010 if (inst.cond > COND_ALWAYS)
22011 inst.pred_insn_type = INSIDE_VPT_INSN;
22012 else
22013 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
22014 else if (inst.cond == COND_ALWAYS)
22015 inst.pred_insn_type = OUTSIDE_PRED_INSN;
22016 else
22017 inst.error = BAD_NOT_IT;
22018 }
22019
22020 static void
22021 vcx_handle_common_checks (unsigned num_args, enum neon_shape rs)
22022 {
22023 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
22024 cde_handle_coproc ();
22025 enum vcx_reg_type reg_type = vcx_get_reg_type (rs);
22026 vcx_handle_register_arguments (num_args, reg_type);
22027 vcx_handle_insn_block (reg_type);
22028 if (reg_type == q_reg)
22029 constraint (!mark_feature_used (&mve_ext),
22030 _("vcx instructions with Q registers require MVE"));
22031 else
22032 constraint (!(ARM_FSET_CPU_SUBSET (armv8m_fp, cpu_variant)
22033 && mark_feature_used (&armv8m_fp))
22034 && !mark_feature_used (&mve_ext),
22035 _("vcx instructions with S or D registers require either MVE"
22036 " or Armv8-M floating point etension."));
22037 }
22038
22039 static void
22040 do_vcx1 (void)
22041 {
22042 enum neon_shape rs = neon_select_shape (NS_PQI, NS_PDI, NS_PFI, NS_NULL);
22043 vcx_handle_common_checks (1, rs);
22044
22045 unsigned imm = inst.operands[2].imm;
22046 inst.instruction |= (imm & 0x03f);
22047 inst.instruction |= (imm & 0x040) << 1;
22048 inst.instruction |= (imm & 0x780) << 9;
22049 if (rs != NS_PQI)
22050 constraint (imm >= 2048,
22051 _("vcx1 with S or D registers takes immediate within 0-2047"));
22052 inst.instruction |= (imm & 0x800) << 13;
22053 }
22054
22055 static void
22056 do_vcx2 (void)
22057 {
22058 enum neon_shape rs = neon_select_shape (NS_PQQI, NS_PDDI, NS_PFFI, NS_NULL);
22059 vcx_handle_common_checks (2, rs);
22060
22061 unsigned imm = inst.operands[3].imm;
22062 inst.instruction |= (imm & 0x01) << 4;
22063 inst.instruction |= (imm & 0x02) << 6;
22064 inst.instruction |= (imm & 0x3c) << 14;
22065 if (rs != NS_PQQI)
22066 constraint (imm >= 64,
22067 _("vcx2 with S or D registers takes immediate within 0-63"));
22068 inst.instruction |= (imm & 0x40) << 18;
22069 }
22070
22071 static void
22072 do_vcx3 (void)
22073 {
22074 enum neon_shape rs = neon_select_shape (NS_PQQQI, NS_PDDDI, NS_PFFFI, NS_NULL);
22075 vcx_handle_common_checks (3, rs);
22076
22077 unsigned imm = inst.operands[4].imm;
22078 inst.instruction |= (imm & 0x1) << 4;
22079 inst.instruction |= (imm & 0x6) << 19;
22080 if (rs != NS_PQQQI)
22081 constraint (imm >= 8,
22082 _("vcx2 with S or D registers takes immediate within 0-7"));
22083 inst.instruction |= (imm & 0x8) << 21;
22084 }
22085
22086 /* Crypto v1 instructions. */
22087 static void
22088 do_crypto_2op_1 (unsigned elttype, int op)
22089 {
22090 set_pred_insn_type (OUTSIDE_PRED_INSN);
22091
22092 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
22093 == NT_invtype)
22094 return;
22095
22096 inst.error = NULL;
22097
22098 NEON_ENCODE (INTEGER, inst);
22099 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
22100 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
22101 inst.instruction |= LOW4 (inst.operands[1].reg);
22102 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
22103 if (op != -1)
22104 inst.instruction |= op << 6;
22105
22106 if (thumb_mode)
22107 inst.instruction |= 0xfc000000;
22108 else
22109 inst.instruction |= 0xf0000000;
22110 }
22111
22112 static void
22113 do_crypto_3op_1 (int u, int op)
22114 {
22115 set_pred_insn_type (OUTSIDE_PRED_INSN);
22116
22117 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
22118 N_32 | N_UNT | N_KEY).type == NT_invtype)
22119 return;
22120
22121 inst.error = NULL;
22122
22123 NEON_ENCODE (INTEGER, inst);
22124 neon_three_same (1, u, 8 << op);
22125 }
22126
22127 static void
22128 do_aese (void)
22129 {
22130 do_crypto_2op_1 (N_8, 0);
22131 }
22132
22133 static void
22134 do_aesd (void)
22135 {
22136 do_crypto_2op_1 (N_8, 1);
22137 }
22138
22139 static void
22140 do_aesmc (void)
22141 {
22142 do_crypto_2op_1 (N_8, 2);
22143 }
22144
22145 static void
22146 do_aesimc (void)
22147 {
22148 do_crypto_2op_1 (N_8, 3);
22149 }
22150
22151 static void
22152 do_sha1c (void)
22153 {
22154 do_crypto_3op_1 (0, 0);
22155 }
22156
22157 static void
22158 do_sha1p (void)
22159 {
22160 do_crypto_3op_1 (0, 1);
22161 }
22162
22163 static void
22164 do_sha1m (void)
22165 {
22166 do_crypto_3op_1 (0, 2);
22167 }
22168
22169 static void
22170 do_sha1su0 (void)
22171 {
22172 do_crypto_3op_1 (0, 3);
22173 }
22174
22175 static void
22176 do_sha256h (void)
22177 {
22178 do_crypto_3op_1 (1, 0);
22179 }
22180
22181 static void
22182 do_sha256h2 (void)
22183 {
22184 do_crypto_3op_1 (1, 1);
22185 }
22186
22187 static void
22188 do_sha256su1 (void)
22189 {
22190 do_crypto_3op_1 (1, 2);
22191 }
22192
22193 static void
22194 do_sha1h (void)
22195 {
22196 do_crypto_2op_1 (N_32, -1);
22197 }
22198
22199 static void
22200 do_sha1su1 (void)
22201 {
22202 do_crypto_2op_1 (N_32, 0);
22203 }
22204
22205 static void
22206 do_sha256su0 (void)
22207 {
22208 do_crypto_2op_1 (N_32, 1);
22209 }
22210
22211 static void
22212 do_crc32_1 (unsigned int poly, unsigned int sz)
22213 {
22214 unsigned int Rd = inst.operands[0].reg;
22215 unsigned int Rn = inst.operands[1].reg;
22216 unsigned int Rm = inst.operands[2].reg;
22217
22218 set_pred_insn_type (OUTSIDE_PRED_INSN);
22219 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
22220 inst.instruction |= LOW4 (Rn) << 16;
22221 inst.instruction |= LOW4 (Rm);
22222 inst.instruction |= sz << (thumb_mode ? 4 : 21);
22223 inst.instruction |= poly << (thumb_mode ? 20 : 9);
22224
22225 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
22226 as_warn (UNPRED_REG ("r15"));
22227 }
22228
22229 static void
22230 do_crc32b (void)
22231 {
22232 do_crc32_1 (0, 0);
22233 }
22234
22235 static void
22236 do_crc32h (void)
22237 {
22238 do_crc32_1 (0, 1);
22239 }
22240
22241 static void
22242 do_crc32w (void)
22243 {
22244 do_crc32_1 (0, 2);
22245 }
22246
22247 static void
22248 do_crc32cb (void)
22249 {
22250 do_crc32_1 (1, 0);
22251 }
22252
22253 static void
22254 do_crc32ch (void)
22255 {
22256 do_crc32_1 (1, 1);
22257 }
22258
22259 static void
22260 do_crc32cw (void)
22261 {
22262 do_crc32_1 (1, 2);
22263 }
22264
22265 static void
22266 do_vjcvt (void)
22267 {
22268 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
22269 _(BAD_FPU));
22270 neon_check_type (2, NS_FD, N_S32, N_F64);
22271 do_vfp_sp_dp_cvt ();
22272 do_vfp_cond_or_thumb ();
22273 }
22274
22275 static void
22276 do_vdot (void)
22277 {
22278 enum neon_shape rs;
22279 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22280 set_pred_insn_type (OUTSIDE_PRED_INSN);
22281 if (inst.operands[2].isscalar)
22282 {
22283 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
22284 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22285
22286 inst.instruction |= (1 << 25);
22287 int index = inst.operands[2].reg & 0xf;
22288 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
22289 inst.operands[2].reg >>= 4;
22290 constraint (!(inst.operands[2].reg < 16),
22291 _("indexed register must be less than 16"));
22292 neon_three_args (rs == NS_QQS);
22293 inst.instruction |= (index << 5);
22294 }
22295 else
22296 {
22297 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
22298 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22299 neon_three_args (rs == NS_QQQ);
22300 }
22301 }
22302
22303 static void
22304 do_vmmla (void)
22305 {
22306 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
22307 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22308
22309 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22310 set_pred_insn_type (OUTSIDE_PRED_INSN);
22311
22312 neon_three_args (1);
22313 }
22314
22315 \f
22316 /* Overall per-instruction processing. */
22317
22318 /* We need to be able to fix up arbitrary expressions in some statements.
22319 This is so that we can handle symbols that are an arbitrary distance from
22320 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
22321 which returns part of an address in a form which will be valid for
22322 a data instruction. We do this by pushing the expression into a symbol
22323 in the expr_section, and creating a fix for that. */
22324
22325 static void
22326 fix_new_arm (fragS * frag,
22327 int where,
22328 short int size,
22329 expressionS * exp,
22330 int pc_rel,
22331 int reloc)
22332 {
22333 fixS * new_fix;
22334
22335 switch (exp->X_op)
22336 {
22337 case O_constant:
22338 if (pc_rel)
22339 {
22340 /* Create an absolute valued symbol, so we have something to
22341 refer to in the object file. Unfortunately for us, gas's
22342 generic expression parsing will already have folded out
22343 any use of .set foo/.type foo %function that may have
22344 been used to set type information of the target location,
22345 that's being specified symbolically. We have to presume
22346 the user knows what they are doing. */
22347 char name[16 + 8];
22348 symbolS *symbol;
22349
22350 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
22351
22352 symbol = symbol_find_or_make (name);
22353 S_SET_SEGMENT (symbol, absolute_section);
22354 symbol_set_frag (symbol, &zero_address_frag);
22355 S_SET_VALUE (symbol, exp->X_add_number);
22356 exp->X_op = O_symbol;
22357 exp->X_add_symbol = symbol;
22358 exp->X_add_number = 0;
22359 }
22360 /* FALLTHROUGH */
22361 case O_symbol:
22362 case O_add:
22363 case O_subtract:
22364 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
22365 (enum bfd_reloc_code_real) reloc);
22366 break;
22367
22368 default:
22369 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
22370 pc_rel, (enum bfd_reloc_code_real) reloc);
22371 break;
22372 }
22373
22374 /* Mark whether the fix is to a THUMB instruction, or an ARM
22375 instruction. */
22376 new_fix->tc_fix_data = thumb_mode;
22377 }
22378
22379 /* Create a frg for an instruction requiring relaxation. */
22380 static void
22381 output_relax_insn (void)
22382 {
22383 char * to;
22384 symbolS *sym;
22385 int offset;
22386
22387 /* The size of the instruction is unknown, so tie the debug info to the
22388 start of the instruction. */
22389 dwarf2_emit_insn (0);
22390
22391 switch (inst.relocs[0].exp.X_op)
22392 {
22393 case O_symbol:
22394 sym = inst.relocs[0].exp.X_add_symbol;
22395 offset = inst.relocs[0].exp.X_add_number;
22396 break;
22397 case O_constant:
22398 sym = NULL;
22399 offset = inst.relocs[0].exp.X_add_number;
22400 break;
22401 default:
22402 sym = make_expr_symbol (&inst.relocs[0].exp);
22403 offset = 0;
22404 break;
22405 }
22406 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
22407 inst.relax, sym, offset, NULL/*offset, opcode*/);
22408 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
22409 }
22410
22411 /* Write a 32-bit thumb instruction to buf. */
22412 static void
22413 put_thumb32_insn (char * buf, unsigned long insn)
22414 {
22415 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
22416 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
22417 }
22418
22419 static void
22420 output_inst (const char * str)
22421 {
22422 char * to = NULL;
22423
22424 if (inst.error)
22425 {
22426 as_bad ("%s -- `%s'", inst.error, str);
22427 return;
22428 }
22429 if (inst.relax)
22430 {
22431 output_relax_insn ();
22432 return;
22433 }
22434 if (inst.size == 0)
22435 return;
22436
22437 to = frag_more (inst.size);
22438 /* PR 9814: Record the thumb mode into the current frag so that we know
22439 what type of NOP padding to use, if necessary. We override any previous
22440 setting so that if the mode has changed then the NOPS that we use will
22441 match the encoding of the last instruction in the frag. */
22442 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22443
22444 if (thumb_mode && (inst.size > THUMB_SIZE))
22445 {
22446 gas_assert (inst.size == (2 * THUMB_SIZE));
22447 put_thumb32_insn (to, inst.instruction);
22448 }
22449 else if (inst.size > INSN_SIZE)
22450 {
22451 gas_assert (inst.size == (2 * INSN_SIZE));
22452 md_number_to_chars (to, inst.instruction, INSN_SIZE);
22453 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
22454 }
22455 else
22456 md_number_to_chars (to, inst.instruction, inst.size);
22457
22458 int r;
22459 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
22460 {
22461 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
22462 fix_new_arm (frag_now, to - frag_now->fr_literal,
22463 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
22464 inst.relocs[r].type);
22465 }
22466
22467 dwarf2_emit_insn (inst.size);
22468 }
22469
22470 static char *
22471 output_it_inst (int cond, int mask, char * to)
22472 {
22473 unsigned long instruction = 0xbf00;
22474
22475 mask &= 0xf;
22476 instruction |= mask;
22477 instruction |= cond << 4;
22478
22479 if (to == NULL)
22480 {
22481 to = frag_more (2);
22482 #ifdef OBJ_ELF
22483 dwarf2_emit_insn (2);
22484 #endif
22485 }
22486
22487 md_number_to_chars (to, instruction, 2);
22488
22489 return to;
22490 }
22491
22492 /* Tag values used in struct asm_opcode's tag field. */
22493 enum opcode_tag
22494 {
22495 OT_unconditional, /* Instruction cannot be conditionalized.
22496 The ARM condition field is still 0xE. */
22497 OT_unconditionalF, /* Instruction cannot be conditionalized
22498 and carries 0xF in its ARM condition field. */
22499 OT_csuffix, /* Instruction takes a conditional suffix. */
22500 OT_csuffixF, /* Some forms of the instruction take a scalar
22501 conditional suffix, others place 0xF where the
22502 condition field would be, others take a vector
22503 conditional suffix. */
22504 OT_cinfix3, /* Instruction takes a conditional infix,
22505 beginning at character index 3. (In
22506 unified mode, it becomes a suffix.) */
22507 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
22508 tsts, cmps, cmns, and teqs. */
22509 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
22510 character index 3, even in unified mode. Used for
22511 legacy instructions where suffix and infix forms
22512 may be ambiguous. */
22513 OT_csuf_or_in3, /* Instruction takes either a conditional
22514 suffix or an infix at character index 3. */
22515 OT_odd_infix_unc, /* This is the unconditional variant of an
22516 instruction that takes a conditional infix
22517 at an unusual position. In unified mode,
22518 this variant will accept a suffix. */
22519 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
22520 are the conditional variants of instructions that
22521 take conditional infixes in unusual positions.
22522 The infix appears at character index
22523 (tag - OT_odd_infix_0). These are not accepted
22524 in unified mode. */
22525 };
22526
22527 /* Subroutine of md_assemble, responsible for looking up the primary
22528 opcode from the mnemonic the user wrote. STR points to the
22529 beginning of the mnemonic.
22530
22531 This is not simply a hash table lookup, because of conditional
22532 variants. Most instructions have conditional variants, which are
22533 expressed with a _conditional affix_ to the mnemonic. If we were
22534 to encode each conditional variant as a literal string in the opcode
22535 table, it would have approximately 20,000 entries.
22536
22537 Most mnemonics take this affix as a suffix, and in unified syntax,
22538 'most' is upgraded to 'all'. However, in the divided syntax, some
22539 instructions take the affix as an infix, notably the s-variants of
22540 the arithmetic instructions. Of those instructions, all but six
22541 have the infix appear after the third character of the mnemonic.
22542
22543 Accordingly, the algorithm for looking up primary opcodes given
22544 an identifier is:
22545
22546 1. Look up the identifier in the opcode table.
22547 If we find a match, go to step U.
22548
22549 2. Look up the last two characters of the identifier in the
22550 conditions table. If we find a match, look up the first N-2
22551 characters of the identifier in the opcode table. If we
22552 find a match, go to step CE.
22553
22554 3. Look up the fourth and fifth characters of the identifier in
22555 the conditions table. If we find a match, extract those
22556 characters from the identifier, and look up the remaining
22557 characters in the opcode table. If we find a match, go
22558 to step CM.
22559
22560 4. Fail.
22561
22562 U. Examine the tag field of the opcode structure, in case this is
22563 one of the six instructions with its conditional infix in an
22564 unusual place. If it is, the tag tells us where to find the
22565 infix; look it up in the conditions table and set inst.cond
22566 accordingly. Otherwise, this is an unconditional instruction.
22567 Again set inst.cond accordingly. Return the opcode structure.
22568
22569 CE. Examine the tag field to make sure this is an instruction that
22570 should receive a conditional suffix. If it is not, fail.
22571 Otherwise, set inst.cond from the suffix we already looked up,
22572 and return the opcode structure.
22573
22574 CM. Examine the tag field to make sure this is an instruction that
22575 should receive a conditional infix after the third character.
22576 If it is not, fail. Otherwise, undo the edits to the current
22577 line of input and proceed as for case CE. */
22578
22579 static const struct asm_opcode *
22580 opcode_lookup (char **str)
22581 {
22582 char *end, *base;
22583 char *affix;
22584 const struct asm_opcode *opcode;
22585 const struct asm_cond *cond;
22586 char save[2];
22587
22588 /* Scan up to the end of the mnemonic, which must end in white space,
22589 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
22590 for (base = end = *str; *end != '\0'; end++)
22591 if (*end == ' ' || *end == '.')
22592 break;
22593
22594 if (end == base)
22595 return NULL;
22596
22597 /* Handle a possible width suffix and/or Neon type suffix. */
22598 if (end[0] == '.')
22599 {
22600 int offset = 2;
22601
22602 /* The .w and .n suffixes are only valid if the unified syntax is in
22603 use. */
22604 if (unified_syntax && end[1] == 'w')
22605 inst.size_req = 4;
22606 else if (unified_syntax && end[1] == 'n')
22607 inst.size_req = 2;
22608 else
22609 offset = 0;
22610
22611 inst.vectype.elems = 0;
22612
22613 *str = end + offset;
22614
22615 if (end[offset] == '.')
22616 {
22617 /* See if we have a Neon type suffix (possible in either unified or
22618 non-unified ARM syntax mode). */
22619 if (parse_neon_type (&inst.vectype, str) == FAIL)
22620 return NULL;
22621 }
22622 else if (end[offset] != '\0' && end[offset] != ' ')
22623 return NULL;
22624 }
22625 else
22626 *str = end;
22627
22628 /* Look for unaffixed or special-case affixed mnemonic. */
22629 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22630 end - base);
22631 if (opcode)
22632 {
22633 /* step U */
22634 if (opcode->tag < OT_odd_infix_0)
22635 {
22636 inst.cond = COND_ALWAYS;
22637 return opcode;
22638 }
22639
22640 if (warn_on_deprecated && unified_syntax)
22641 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
22642 affix = base + (opcode->tag - OT_odd_infix_0);
22643 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
22644 gas_assert (cond);
22645
22646 inst.cond = cond->value;
22647 return opcode;
22648 }
22649 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
22650 {
22651 /* Cannot have a conditional suffix on a mnemonic of less than a character.
22652 */
22653 if (end - base < 2)
22654 return NULL;
22655 affix = end - 1;
22656 cond = (const struct asm_cond *) hash_find_n (arm_vcond_hsh, affix, 1);
22657 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22658 affix - base);
22659 /* If this opcode can not be vector predicated then don't accept it with a
22660 vector predication code. */
22661 if (opcode && !opcode->mayBeVecPred)
22662 opcode = NULL;
22663 }
22664 if (!opcode || !cond)
22665 {
22666 /* Cannot have a conditional suffix on a mnemonic of less than two
22667 characters. */
22668 if (end - base < 3)
22669 return NULL;
22670
22671 /* Look for suffixed mnemonic. */
22672 affix = end - 2;
22673 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
22674 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22675 affix - base);
22676 }
22677
22678 if (opcode && cond)
22679 {
22680 /* step CE */
22681 switch (opcode->tag)
22682 {
22683 case OT_cinfix3_legacy:
22684 /* Ignore conditional suffixes matched on infix only mnemonics. */
22685 break;
22686
22687 case OT_cinfix3:
22688 case OT_cinfix3_deprecated:
22689 case OT_odd_infix_unc:
22690 if (!unified_syntax)
22691 return NULL;
22692 /* Fall through. */
22693
22694 case OT_csuffix:
22695 case OT_csuffixF:
22696 case OT_csuf_or_in3:
22697 inst.cond = cond->value;
22698 return opcode;
22699
22700 case OT_unconditional:
22701 case OT_unconditionalF:
22702 if (thumb_mode)
22703 inst.cond = cond->value;
22704 else
22705 {
22706 /* Delayed diagnostic. */
22707 inst.error = BAD_COND;
22708 inst.cond = COND_ALWAYS;
22709 }
22710 return opcode;
22711
22712 default:
22713 return NULL;
22714 }
22715 }
22716
22717 /* Cannot have a usual-position infix on a mnemonic of less than
22718 six characters (five would be a suffix). */
22719 if (end - base < 6)
22720 return NULL;
22721
22722 /* Look for infixed mnemonic in the usual position. */
22723 affix = base + 3;
22724 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
22725 if (!cond)
22726 return NULL;
22727
22728 memcpy (save, affix, 2);
22729 memmove (affix, affix + 2, (end - affix) - 2);
22730 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22731 (end - base) - 2);
22732 memmove (affix + 2, affix, (end - affix) - 2);
22733 memcpy (affix, save, 2);
22734
22735 if (opcode
22736 && (opcode->tag == OT_cinfix3
22737 || opcode->tag == OT_cinfix3_deprecated
22738 || opcode->tag == OT_csuf_or_in3
22739 || opcode->tag == OT_cinfix3_legacy))
22740 {
22741 /* Step CM. */
22742 if (warn_on_deprecated && unified_syntax
22743 && (opcode->tag == OT_cinfix3
22744 || opcode->tag == OT_cinfix3_deprecated))
22745 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
22746
22747 inst.cond = cond->value;
22748 return opcode;
22749 }
22750
22751 return NULL;
22752 }
22753
22754 /* This function generates an initial IT instruction, leaving its block
22755 virtually open for the new instructions. Eventually,
22756 the mask will be updated by now_pred_add_mask () each time
22757 a new instruction needs to be included in the IT block.
22758 Finally, the block is closed with close_automatic_it_block ().
22759 The block closure can be requested either from md_assemble (),
22760 a tencode (), or due to a label hook. */
22761
22762 static void
22763 new_automatic_it_block (int cond)
22764 {
22765 now_pred.state = AUTOMATIC_PRED_BLOCK;
22766 now_pred.mask = 0x18;
22767 now_pred.cc = cond;
22768 now_pred.block_length = 1;
22769 mapping_state (MAP_THUMB);
22770 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
22771 now_pred.warn_deprecated = FALSE;
22772 now_pred.insn_cond = TRUE;
22773 }
22774
22775 /* Close an automatic IT block.
22776 See comments in new_automatic_it_block (). */
22777
22778 static void
22779 close_automatic_it_block (void)
22780 {
22781 now_pred.mask = 0x10;
22782 now_pred.block_length = 0;
22783 }
22784
22785 /* Update the mask of the current automatically-generated IT
22786 instruction. See comments in new_automatic_it_block (). */
22787
22788 static void
22789 now_pred_add_mask (int cond)
22790 {
22791 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
22792 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
22793 | ((bitvalue) << (nbit)))
22794 const int resulting_bit = (cond & 1);
22795
22796 now_pred.mask &= 0xf;
22797 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
22798 resulting_bit,
22799 (5 - now_pred.block_length));
22800 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
22801 1,
22802 ((5 - now_pred.block_length) - 1));
22803 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
22804
22805 #undef CLEAR_BIT
22806 #undef SET_BIT_VALUE
22807 }
22808
22809 /* The IT blocks handling machinery is accessed through the these functions:
22810 it_fsm_pre_encode () from md_assemble ()
22811 set_pred_insn_type () optional, from the tencode functions
22812 set_pred_insn_type_last () ditto
22813 in_pred_block () ditto
22814 it_fsm_post_encode () from md_assemble ()
22815 force_automatic_it_block_close () from label handling functions
22816
22817 Rationale:
22818 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
22819 initializing the IT insn type with a generic initial value depending
22820 on the inst.condition.
22821 2) During the tencode function, two things may happen:
22822 a) The tencode function overrides the IT insn type by
22823 calling either set_pred_insn_type (type) or
22824 set_pred_insn_type_last ().
22825 b) The tencode function queries the IT block state by
22826 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
22827
22828 Both set_pred_insn_type and in_pred_block run the internal FSM state
22829 handling function (handle_pred_state), because: a) setting the IT insn
22830 type may incur in an invalid state (exiting the function),
22831 and b) querying the state requires the FSM to be updated.
22832 Specifically we want to avoid creating an IT block for conditional
22833 branches, so it_fsm_pre_encode is actually a guess and we can't
22834 determine whether an IT block is required until the tencode () routine
22835 has decided what type of instruction this actually it.
22836 Because of this, if set_pred_insn_type and in_pred_block have to be
22837 used, set_pred_insn_type has to be called first.
22838
22839 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
22840 that determines the insn IT type depending on the inst.cond code.
22841 When a tencode () routine encodes an instruction that can be
22842 either outside an IT block, or, in the case of being inside, has to be
22843 the last one, set_pred_insn_type_last () will determine the proper
22844 IT instruction type based on the inst.cond code. Otherwise,
22845 set_pred_insn_type can be called for overriding that logic or
22846 for covering other cases.
22847
22848 Calling handle_pred_state () may not transition the IT block state to
22849 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
22850 still queried. Instead, if the FSM determines that the state should
22851 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
22852 after the tencode () function: that's what it_fsm_post_encode () does.
22853
22854 Since in_pred_block () calls the state handling function to get an
22855 updated state, an error may occur (due to invalid insns combination).
22856 In that case, inst.error is set.
22857 Therefore, inst.error has to be checked after the execution of
22858 the tencode () routine.
22859
22860 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
22861 any pending state change (if any) that didn't take place in
22862 handle_pred_state () as explained above. */
22863
22864 static void
22865 it_fsm_pre_encode (void)
22866 {
22867 if (inst.cond != COND_ALWAYS)
22868 inst.pred_insn_type = INSIDE_IT_INSN;
22869 else
22870 inst.pred_insn_type = OUTSIDE_PRED_INSN;
22871
22872 now_pred.state_handled = 0;
22873 }
22874
22875 /* IT state FSM handling function. */
22876 /* MVE instructions and non-MVE instructions are handled differently because of
22877 the introduction of VPT blocks.
22878 Specifications say that any non-MVE instruction inside a VPT block is
22879 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
22880 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
22881 few exceptions we have MVE_UNPREDICABLE_INSN.
22882 The error messages provided depending on the different combinations possible
22883 are described in the cases below:
22884 For 'most' MVE instructions:
22885 1) In an IT block, with an IT code: syntax error
22886 2) In an IT block, with a VPT code: error: must be in a VPT block
22887 3) In an IT block, with no code: warning: UNPREDICTABLE
22888 4) In a VPT block, with an IT code: syntax error
22889 5) In a VPT block, with a VPT code: OK!
22890 6) In a VPT block, with no code: error: missing code
22891 7) Outside a pred block, with an IT code: error: syntax error
22892 8) Outside a pred block, with a VPT code: error: should be in a VPT block
22893 9) Outside a pred block, with no code: OK!
22894 For non-MVE instructions:
22895 10) In an IT block, with an IT code: OK!
22896 11) In an IT block, with a VPT code: syntax error
22897 12) In an IT block, with no code: error: missing code
22898 13) In a VPT block, with an IT code: error: should be in an IT block
22899 14) In a VPT block, with a VPT code: syntax error
22900 15) In a VPT block, with no code: UNPREDICTABLE
22901 16) Outside a pred block, with an IT code: error: should be in an IT block
22902 17) Outside a pred block, with a VPT code: syntax error
22903 18) Outside a pred block, with no code: OK!
22904 */
22905
22906
22907 static int
22908 handle_pred_state (void)
22909 {
22910 now_pred.state_handled = 1;
22911 now_pred.insn_cond = FALSE;
22912
22913 switch (now_pred.state)
22914 {
22915 case OUTSIDE_PRED_BLOCK:
22916 switch (inst.pred_insn_type)
22917 {
22918 case MVE_UNPREDICABLE_INSN:
22919 case MVE_OUTSIDE_PRED_INSN:
22920 if (inst.cond < COND_ALWAYS)
22921 {
22922 /* Case 7: Outside a pred block, with an IT code: error: syntax
22923 error. */
22924 inst.error = BAD_SYNTAX;
22925 return FAIL;
22926 }
22927 /* Case 9: Outside a pred block, with no code: OK! */
22928 break;
22929 case OUTSIDE_PRED_INSN:
22930 if (inst.cond > COND_ALWAYS)
22931 {
22932 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22933 */
22934 inst.error = BAD_SYNTAX;
22935 return FAIL;
22936 }
22937 /* Case 18: Outside a pred block, with no code: OK! */
22938 break;
22939
22940 case INSIDE_VPT_INSN:
22941 /* Case 8: Outside a pred block, with a VPT code: error: should be in
22942 a VPT block. */
22943 inst.error = BAD_OUT_VPT;
22944 return FAIL;
22945
22946 case INSIDE_IT_INSN:
22947 case INSIDE_IT_LAST_INSN:
22948 if (inst.cond < COND_ALWAYS)
22949 {
22950 /* Case 16: Outside a pred block, with an IT code: error: should
22951 be in an IT block. */
22952 if (thumb_mode == 0)
22953 {
22954 if (unified_syntax
22955 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
22956 as_tsktsk (_("Warning: conditional outside an IT block"\
22957 " for Thumb."));
22958 }
22959 else
22960 {
22961 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
22962 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
22963 {
22964 /* Automatically generate the IT instruction. */
22965 new_automatic_it_block (inst.cond);
22966 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
22967 close_automatic_it_block ();
22968 }
22969 else
22970 {
22971 inst.error = BAD_OUT_IT;
22972 return FAIL;
22973 }
22974 }
22975 break;
22976 }
22977 else if (inst.cond > COND_ALWAYS)
22978 {
22979 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22980 */
22981 inst.error = BAD_SYNTAX;
22982 return FAIL;
22983 }
22984 else
22985 gas_assert (0);
22986 case IF_INSIDE_IT_LAST_INSN:
22987 case NEUTRAL_IT_INSN:
22988 break;
22989
22990 case VPT_INSN:
22991 if (inst.cond != COND_ALWAYS)
22992 first_error (BAD_SYNTAX);
22993 now_pred.state = MANUAL_PRED_BLOCK;
22994 now_pred.block_length = 0;
22995 now_pred.type = VECTOR_PRED;
22996 now_pred.cc = 0;
22997 break;
22998 case IT_INSN:
22999 now_pred.state = MANUAL_PRED_BLOCK;
23000 now_pred.block_length = 0;
23001 now_pred.type = SCALAR_PRED;
23002 break;
23003 }
23004 break;
23005
23006 case AUTOMATIC_PRED_BLOCK:
23007 /* Three things may happen now:
23008 a) We should increment current it block size;
23009 b) We should close current it block (closing insn or 4 insns);
23010 c) We should close current it block and start a new one (due
23011 to incompatible conditions or
23012 4 insns-length block reached). */
23013
23014 switch (inst.pred_insn_type)
23015 {
23016 case INSIDE_VPT_INSN:
23017 case VPT_INSN:
23018 case MVE_UNPREDICABLE_INSN:
23019 case MVE_OUTSIDE_PRED_INSN:
23020 gas_assert (0);
23021 case OUTSIDE_PRED_INSN:
23022 /* The closure of the block shall happen immediately,
23023 so any in_pred_block () call reports the block as closed. */
23024 force_automatic_it_block_close ();
23025 break;
23026
23027 case INSIDE_IT_INSN:
23028 case INSIDE_IT_LAST_INSN:
23029 case IF_INSIDE_IT_LAST_INSN:
23030 now_pred.block_length++;
23031
23032 if (now_pred.block_length > 4
23033 || !now_pred_compatible (inst.cond))
23034 {
23035 force_automatic_it_block_close ();
23036 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
23037 new_automatic_it_block (inst.cond);
23038 }
23039 else
23040 {
23041 now_pred.insn_cond = TRUE;
23042 now_pred_add_mask (inst.cond);
23043 }
23044
23045 if (now_pred.state == AUTOMATIC_PRED_BLOCK
23046 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
23047 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
23048 close_automatic_it_block ();
23049 break;
23050
23051 /* Fallthrough. */
23052 case NEUTRAL_IT_INSN:
23053 now_pred.block_length++;
23054 now_pred.insn_cond = TRUE;
23055
23056 if (now_pred.block_length > 4)
23057 force_automatic_it_block_close ();
23058 else
23059 now_pred_add_mask (now_pred.cc & 1);
23060 break;
23061
23062 case IT_INSN:
23063 close_automatic_it_block ();
23064 now_pred.state = MANUAL_PRED_BLOCK;
23065 break;
23066 }
23067 break;
23068
23069 case MANUAL_PRED_BLOCK:
23070 {
23071 int cond, is_last;
23072 if (now_pred.type == SCALAR_PRED)
23073 {
23074 /* Check conditional suffixes. */
23075 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
23076 now_pred.mask <<= 1;
23077 now_pred.mask &= 0x1f;
23078 is_last = (now_pred.mask == 0x10);
23079 }
23080 else
23081 {
23082 now_pred.cc ^= (now_pred.mask >> 4);
23083 cond = now_pred.cc + 0xf;
23084 now_pred.mask <<= 1;
23085 now_pred.mask &= 0x1f;
23086 is_last = now_pred.mask == 0x10;
23087 }
23088 now_pred.insn_cond = TRUE;
23089
23090 switch (inst.pred_insn_type)
23091 {
23092 case OUTSIDE_PRED_INSN:
23093 if (now_pred.type == SCALAR_PRED)
23094 {
23095 if (inst.cond == COND_ALWAYS)
23096 {
23097 /* Case 12: In an IT block, with no code: error: missing
23098 code. */
23099 inst.error = BAD_NOT_IT;
23100 return FAIL;
23101 }
23102 else if (inst.cond > COND_ALWAYS)
23103 {
23104 /* Case 11: In an IT block, with a VPT code: syntax error.
23105 */
23106 inst.error = BAD_SYNTAX;
23107 return FAIL;
23108 }
23109 else if (thumb_mode)
23110 {
23111 /* This is for some special cases where a non-MVE
23112 instruction is not allowed in an IT block, such as cbz,
23113 but are put into one with a condition code.
23114 You could argue this should be a syntax error, but we
23115 gave the 'not allowed in IT block' diagnostic in the
23116 past so we will keep doing so. */
23117 inst.error = BAD_NOT_IT;
23118 return FAIL;
23119 }
23120 break;
23121 }
23122 else
23123 {
23124 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
23125 as_tsktsk (MVE_NOT_VPT);
23126 return SUCCESS;
23127 }
23128 case MVE_OUTSIDE_PRED_INSN:
23129 if (now_pred.type == SCALAR_PRED)
23130 {
23131 if (inst.cond == COND_ALWAYS)
23132 {
23133 /* Case 3: In an IT block, with no code: warning:
23134 UNPREDICTABLE. */
23135 as_tsktsk (MVE_NOT_IT);
23136 return SUCCESS;
23137 }
23138 else if (inst.cond < COND_ALWAYS)
23139 {
23140 /* Case 1: In an IT block, with an IT code: syntax error.
23141 */
23142 inst.error = BAD_SYNTAX;
23143 return FAIL;
23144 }
23145 else
23146 gas_assert (0);
23147 }
23148 else
23149 {
23150 if (inst.cond < COND_ALWAYS)
23151 {
23152 /* Case 4: In a VPT block, with an IT code: syntax error.
23153 */
23154 inst.error = BAD_SYNTAX;
23155 return FAIL;
23156 }
23157 else if (inst.cond == COND_ALWAYS)
23158 {
23159 /* Case 6: In a VPT block, with no code: error: missing
23160 code. */
23161 inst.error = BAD_NOT_VPT;
23162 return FAIL;
23163 }
23164 else
23165 {
23166 gas_assert (0);
23167 }
23168 }
23169 case MVE_UNPREDICABLE_INSN:
23170 as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT);
23171 return SUCCESS;
23172 case INSIDE_IT_INSN:
23173 if (inst.cond > COND_ALWAYS)
23174 {
23175 /* Case 11: In an IT block, with a VPT code: syntax error. */
23176 /* Case 14: In a VPT block, with a VPT code: syntax error. */
23177 inst.error = BAD_SYNTAX;
23178 return FAIL;
23179 }
23180 else if (now_pred.type == SCALAR_PRED)
23181 {
23182 /* Case 10: In an IT block, with an IT code: OK! */
23183 if (cond != inst.cond)
23184 {
23185 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
23186 BAD_VPT_COND;
23187 return FAIL;
23188 }
23189 }
23190 else
23191 {
23192 /* Case 13: In a VPT block, with an IT code: error: should be
23193 in an IT block. */
23194 inst.error = BAD_OUT_IT;
23195 return FAIL;
23196 }
23197 break;
23198
23199 case INSIDE_VPT_INSN:
23200 if (now_pred.type == SCALAR_PRED)
23201 {
23202 /* Case 2: In an IT block, with a VPT code: error: must be in a
23203 VPT block. */
23204 inst.error = BAD_OUT_VPT;
23205 return FAIL;
23206 }
23207 /* Case 5: In a VPT block, with a VPT code: OK! */
23208 else if (cond != inst.cond)
23209 {
23210 inst.error = BAD_VPT_COND;
23211 return FAIL;
23212 }
23213 break;
23214 case INSIDE_IT_LAST_INSN:
23215 case IF_INSIDE_IT_LAST_INSN:
23216 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
23217 {
23218 /* Case 4: In a VPT block, with an IT code: syntax error. */
23219 /* Case 11: In an IT block, with a VPT code: syntax error. */
23220 inst.error = BAD_SYNTAX;
23221 return FAIL;
23222 }
23223 else if (cond != inst.cond)
23224 {
23225 inst.error = BAD_IT_COND;
23226 return FAIL;
23227 }
23228 if (!is_last)
23229 {
23230 inst.error = BAD_BRANCH;
23231 return FAIL;
23232 }
23233 break;
23234
23235 case NEUTRAL_IT_INSN:
23236 /* The BKPT instruction is unconditional even in a IT or VPT
23237 block. */
23238 break;
23239
23240 case IT_INSN:
23241 if (now_pred.type == SCALAR_PRED)
23242 {
23243 inst.error = BAD_IT_IT;
23244 return FAIL;
23245 }
23246 /* fall through. */
23247 case VPT_INSN:
23248 if (inst.cond == COND_ALWAYS)
23249 {
23250 /* Executing a VPT/VPST instruction inside an IT block or a
23251 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
23252 */
23253 if (now_pred.type == SCALAR_PRED)
23254 as_tsktsk (MVE_NOT_IT);
23255 else
23256 as_tsktsk (MVE_NOT_VPT);
23257 return SUCCESS;
23258 }
23259 else
23260 {
23261 /* VPT/VPST do not accept condition codes. */
23262 inst.error = BAD_SYNTAX;
23263 return FAIL;
23264 }
23265 }
23266 }
23267 break;
23268 }
23269
23270 return SUCCESS;
23271 }
23272
23273 struct depr_insn_mask
23274 {
23275 unsigned long pattern;
23276 unsigned long mask;
23277 const char* description;
23278 };
23279
23280 /* List of 16-bit instruction patterns deprecated in an IT block in
23281 ARMv8. */
23282 static const struct depr_insn_mask depr_it_insns[] = {
23283 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
23284 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
23285 { 0xa000, 0xb800, N_("ADR") },
23286 { 0x4800, 0xf800, N_("Literal loads") },
23287 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
23288 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
23289 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
23290 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
23291 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
23292 { 0, 0, NULL }
23293 };
23294
23295 static void
23296 it_fsm_post_encode (void)
23297 {
23298 int is_last;
23299
23300 if (!now_pred.state_handled)
23301 handle_pred_state ();
23302
23303 if (now_pred.insn_cond
23304 && warn_on_restrict_it
23305 && !now_pred.warn_deprecated
23306 && warn_on_deprecated
23307 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
23308 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
23309 {
23310 if (inst.instruction >= 0x10000)
23311 {
23312 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
23313 "performance deprecated in ARMv8-A and ARMv8-R"));
23314 now_pred.warn_deprecated = TRUE;
23315 }
23316 else
23317 {
23318 const struct depr_insn_mask *p = depr_it_insns;
23319
23320 while (p->mask != 0)
23321 {
23322 if ((inst.instruction & p->mask) == p->pattern)
23323 {
23324 as_tsktsk (_("IT blocks containing 16-bit Thumb "
23325 "instructions of the following class are "
23326 "performance deprecated in ARMv8-A and "
23327 "ARMv8-R: %s"), p->description);
23328 now_pred.warn_deprecated = TRUE;
23329 break;
23330 }
23331
23332 ++p;
23333 }
23334 }
23335
23336 if (now_pred.block_length > 1)
23337 {
23338 as_tsktsk (_("IT blocks containing more than one conditional "
23339 "instruction are performance deprecated in ARMv8-A and "
23340 "ARMv8-R"));
23341 now_pred.warn_deprecated = TRUE;
23342 }
23343 }
23344
23345 is_last = (now_pred.mask == 0x10);
23346 if (is_last)
23347 {
23348 now_pred.state = OUTSIDE_PRED_BLOCK;
23349 now_pred.mask = 0;
23350 }
23351 }
23352
23353 static void
23354 force_automatic_it_block_close (void)
23355 {
23356 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
23357 {
23358 close_automatic_it_block ();
23359 now_pred.state = OUTSIDE_PRED_BLOCK;
23360 now_pred.mask = 0;
23361 }
23362 }
23363
23364 static int
23365 in_pred_block (void)
23366 {
23367 if (!now_pred.state_handled)
23368 handle_pred_state ();
23369
23370 return now_pred.state != OUTSIDE_PRED_BLOCK;
23371 }
23372
23373 /* Whether OPCODE only has T32 encoding. Since this function is only used by
23374 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
23375 here, hence the "known" in the function name. */
23376
23377 static bfd_boolean
23378 known_t32_only_insn (const struct asm_opcode *opcode)
23379 {
23380 /* Original Thumb-1 wide instruction. */
23381 if (opcode->tencode == do_t_blx
23382 || opcode->tencode == do_t_branch23
23383 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
23384 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
23385 return TRUE;
23386
23387 /* Wide-only instruction added to ARMv8-M Baseline. */
23388 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
23389 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
23390 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
23391 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
23392 return TRUE;
23393
23394 return FALSE;
23395 }
23396
23397 /* Whether wide instruction variant can be used if available for a valid OPCODE
23398 in ARCH. */
23399
23400 static bfd_boolean
23401 t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
23402 {
23403 if (known_t32_only_insn (opcode))
23404 return TRUE;
23405
23406 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
23407 of variant T3 of B.W is checked in do_t_branch. */
23408 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23409 && opcode->tencode == do_t_branch)
23410 return TRUE;
23411
23412 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
23413 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23414 && opcode->tencode == do_t_mov_cmp
23415 /* Make sure CMP instruction is not affected. */
23416 && opcode->aencode == do_mov)
23417 return TRUE;
23418
23419 /* Wide instruction variants of all instructions with narrow *and* wide
23420 variants become available with ARMv6t2. Other opcodes are either
23421 narrow-only or wide-only and are thus available if OPCODE is valid. */
23422 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
23423 return TRUE;
23424
23425 /* OPCODE with narrow only instruction variant or wide variant not
23426 available. */
23427 return FALSE;
23428 }
23429
23430 void
23431 md_assemble (char *str)
23432 {
23433 char *p = str;
23434 const struct asm_opcode * opcode;
23435
23436 /* Align the previous label if needed. */
23437 if (last_label_seen != NULL)
23438 {
23439 symbol_set_frag (last_label_seen, frag_now);
23440 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
23441 S_SET_SEGMENT (last_label_seen, now_seg);
23442 }
23443
23444 memset (&inst, '\0', sizeof (inst));
23445 int r;
23446 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
23447 inst.relocs[r].type = BFD_RELOC_UNUSED;
23448
23449 opcode = opcode_lookup (&p);
23450 if (!opcode)
23451 {
23452 /* It wasn't an instruction, but it might be a register alias of
23453 the form alias .req reg, or a Neon .dn/.qn directive. */
23454 if (! create_register_alias (str, p)
23455 && ! create_neon_reg_alias (str, p))
23456 as_bad (_("bad instruction `%s'"), str);
23457
23458 return;
23459 }
23460
23461 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
23462 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
23463
23464 /* The value which unconditional instructions should have in place of the
23465 condition field. */
23466 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
23467
23468 if (thumb_mode)
23469 {
23470 arm_feature_set variant;
23471
23472 variant = cpu_variant;
23473 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
23474 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
23475 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
23476 /* Check that this instruction is supported for this CPU. */
23477 if (!opcode->tvariant
23478 || (thumb_mode == 1
23479 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
23480 {
23481 if (opcode->tencode == do_t_swi)
23482 as_bad (_("SVC is not permitted on this architecture"));
23483 else
23484 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
23485 return;
23486 }
23487 if (inst.cond != COND_ALWAYS && !unified_syntax
23488 && opcode->tencode != do_t_branch)
23489 {
23490 as_bad (_("Thumb does not support conditional execution"));
23491 return;
23492 }
23493
23494 /* Two things are addressed here:
23495 1) Implicit require narrow instructions on Thumb-1.
23496 This avoids relaxation accidentally introducing Thumb-2
23497 instructions.
23498 2) Reject wide instructions in non Thumb-2 cores.
23499
23500 Only instructions with narrow and wide variants need to be handled
23501 but selecting all non wide-only instructions is easier. */
23502 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
23503 && !t32_insn_ok (variant, opcode))
23504 {
23505 if (inst.size_req == 0)
23506 inst.size_req = 2;
23507 else if (inst.size_req == 4)
23508 {
23509 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
23510 as_bad (_("selected processor does not support 32bit wide "
23511 "variant of instruction `%s'"), str);
23512 else
23513 as_bad (_("selected processor does not support `%s' in "
23514 "Thumb-2 mode"), str);
23515 return;
23516 }
23517 }
23518
23519 inst.instruction = opcode->tvalue;
23520
23521 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
23522 {
23523 /* Prepare the pred_insn_type for those encodings that don't set
23524 it. */
23525 it_fsm_pre_encode ();
23526
23527 opcode->tencode ();
23528
23529 it_fsm_post_encode ();
23530 }
23531
23532 if (!(inst.error || inst.relax))
23533 {
23534 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
23535 inst.size = (inst.instruction > 0xffff ? 4 : 2);
23536 if (inst.size_req && inst.size_req != inst.size)
23537 {
23538 as_bad (_("cannot honor width suffix -- `%s'"), str);
23539 return;
23540 }
23541 }
23542
23543 /* Something has gone badly wrong if we try to relax a fixed size
23544 instruction. */
23545 gas_assert (inst.size_req == 0 || !inst.relax);
23546
23547 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23548 *opcode->tvariant);
23549 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
23550 set those bits when Thumb-2 32-bit instructions are seen. The impact
23551 of relaxable instructions will be considered later after we finish all
23552 relaxation. */
23553 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
23554 variant = arm_arch_none;
23555 else
23556 variant = cpu_variant;
23557 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
23558 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23559 arm_ext_v6t2);
23560
23561 check_neon_suffixes;
23562
23563 if (!inst.error)
23564 {
23565 mapping_state (MAP_THUMB);
23566 }
23567 }
23568 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
23569 {
23570 bfd_boolean is_bx;
23571
23572 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
23573 is_bx = (opcode->aencode == do_bx);
23574
23575 /* Check that this instruction is supported for this CPU. */
23576 if (!(is_bx && fix_v4bx)
23577 && !(opcode->avariant &&
23578 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
23579 {
23580 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
23581 return;
23582 }
23583 if (inst.size_req)
23584 {
23585 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
23586 return;
23587 }
23588
23589 inst.instruction = opcode->avalue;
23590 if (opcode->tag == OT_unconditionalF)
23591 inst.instruction |= 0xFU << 28;
23592 else
23593 inst.instruction |= inst.cond << 28;
23594 inst.size = INSN_SIZE;
23595 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
23596 {
23597 it_fsm_pre_encode ();
23598 opcode->aencode ();
23599 it_fsm_post_encode ();
23600 }
23601 /* Arm mode bx is marked as both v4T and v5 because it's still required
23602 on a hypothetical non-thumb v5 core. */
23603 if (is_bx)
23604 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
23605 else
23606 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
23607 *opcode->avariant);
23608
23609 check_neon_suffixes;
23610
23611 if (!inst.error)
23612 {
23613 mapping_state (MAP_ARM);
23614 }
23615 }
23616 else
23617 {
23618 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
23619 "-- `%s'"), str);
23620 return;
23621 }
23622 output_inst (str);
23623 }
23624
23625 static void
23626 check_pred_blocks_finished (void)
23627 {
23628 #ifdef OBJ_ELF
23629 asection *sect;
23630
23631 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
23632 if (seg_info (sect)->tc_segment_info_data.current_pred.state
23633 == MANUAL_PRED_BLOCK)
23634 {
23635 if (now_pred.type == SCALAR_PRED)
23636 as_warn (_("section '%s' finished with an open IT block."),
23637 sect->name);
23638 else
23639 as_warn (_("section '%s' finished with an open VPT/VPST block."),
23640 sect->name);
23641 }
23642 #else
23643 if (now_pred.state == MANUAL_PRED_BLOCK)
23644 {
23645 if (now_pred.type == SCALAR_PRED)
23646 as_warn (_("file finished with an open IT block."));
23647 else
23648 as_warn (_("file finished with an open VPT/VPST block."));
23649 }
23650 #endif
23651 }
23652
23653 /* Various frobbings of labels and their addresses. */
23654
23655 void
23656 arm_start_line_hook (void)
23657 {
23658 last_label_seen = NULL;
23659 }
23660
23661 void
23662 arm_frob_label (symbolS * sym)
23663 {
23664 last_label_seen = sym;
23665
23666 ARM_SET_THUMB (sym, thumb_mode);
23667
23668 #if defined OBJ_COFF || defined OBJ_ELF
23669 ARM_SET_INTERWORK (sym, support_interwork);
23670 #endif
23671
23672 force_automatic_it_block_close ();
23673
23674 /* Note - do not allow local symbols (.Lxxx) to be labelled
23675 as Thumb functions. This is because these labels, whilst
23676 they exist inside Thumb code, are not the entry points for
23677 possible ARM->Thumb calls. Also, these labels can be used
23678 as part of a computed goto or switch statement. eg gcc
23679 can generate code that looks like this:
23680
23681 ldr r2, [pc, .Laaa]
23682 lsl r3, r3, #2
23683 ldr r2, [r3, r2]
23684 mov pc, r2
23685
23686 .Lbbb: .word .Lxxx
23687 .Lccc: .word .Lyyy
23688 ..etc...
23689 .Laaa: .word Lbbb
23690
23691 The first instruction loads the address of the jump table.
23692 The second instruction converts a table index into a byte offset.
23693 The third instruction gets the jump address out of the table.
23694 The fourth instruction performs the jump.
23695
23696 If the address stored at .Laaa is that of a symbol which has the
23697 Thumb_Func bit set, then the linker will arrange for this address
23698 to have the bottom bit set, which in turn would mean that the
23699 address computation performed by the third instruction would end
23700 up with the bottom bit set. Since the ARM is capable of unaligned
23701 word loads, the instruction would then load the incorrect address
23702 out of the jump table, and chaos would ensue. */
23703 if (label_is_thumb_function_name
23704 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
23705 && (bfd_section_flags (now_seg) & SEC_CODE) != 0)
23706 {
23707 /* When the address of a Thumb function is taken the bottom
23708 bit of that address should be set. This will allow
23709 interworking between Arm and Thumb functions to work
23710 correctly. */
23711
23712 THUMB_SET_FUNC (sym, 1);
23713
23714 label_is_thumb_function_name = FALSE;
23715 }
23716
23717 dwarf2_emit_label (sym);
23718 }
23719
23720 bfd_boolean
23721 arm_data_in_code (void)
23722 {
23723 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
23724 {
23725 *input_line_pointer = '/';
23726 input_line_pointer += 5;
23727 *input_line_pointer = 0;
23728 return TRUE;
23729 }
23730
23731 return FALSE;
23732 }
23733
23734 char *
23735 arm_canonicalize_symbol_name (char * name)
23736 {
23737 int len;
23738
23739 if (thumb_mode && (len = strlen (name)) > 5
23740 && streq (name + len - 5, "/data"))
23741 *(name + len - 5) = 0;
23742
23743 return name;
23744 }
23745 \f
23746 /* Table of all register names defined by default. The user can
23747 define additional names with .req. Note that all register names
23748 should appear in both upper and lowercase variants. Some registers
23749 also have mixed-case names. */
23750
23751 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
23752 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
23753 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
23754 #define REGSET(p,t) \
23755 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
23756 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
23757 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
23758 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
23759 #define REGSETH(p,t) \
23760 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
23761 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
23762 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
23763 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
23764 #define REGSET2(p,t) \
23765 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
23766 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
23767 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
23768 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
23769 #define SPLRBANK(base,bank,t) \
23770 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
23771 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
23772 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
23773 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
23774 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
23775 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
23776
23777 static const struct reg_entry reg_names[] =
23778 {
23779 /* ARM integer registers. */
23780 REGSET(r, RN), REGSET(R, RN),
23781
23782 /* ATPCS synonyms. */
23783 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
23784 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
23785 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
23786
23787 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
23788 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
23789 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
23790
23791 /* Well-known aliases. */
23792 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
23793 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
23794
23795 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
23796 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
23797
23798 /* Defining the new Zero register from ARMv8.1-M. */
23799 REGDEF(zr,15,ZR),
23800 REGDEF(ZR,15,ZR),
23801
23802 /* Coprocessor numbers. */
23803 REGSET(p, CP), REGSET(P, CP),
23804
23805 /* Coprocessor register numbers. The "cr" variants are for backward
23806 compatibility. */
23807 REGSET(c, CN), REGSET(C, CN),
23808 REGSET(cr, CN), REGSET(CR, CN),
23809
23810 /* ARM banked registers. */
23811 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
23812 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
23813 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
23814 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
23815 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
23816 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
23817 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
23818
23819 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
23820 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
23821 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
23822 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
23823 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
23824 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
23825 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
23826 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
23827
23828 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
23829 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
23830 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
23831 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
23832 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
23833 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
23834 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
23835 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
23836 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
23837
23838 /* FPA registers. */
23839 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
23840 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
23841
23842 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
23843 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
23844
23845 /* VFP SP registers. */
23846 REGSET(s,VFS), REGSET(S,VFS),
23847 REGSETH(s,VFS), REGSETH(S,VFS),
23848
23849 /* VFP DP Registers. */
23850 REGSET(d,VFD), REGSET(D,VFD),
23851 /* Extra Neon DP registers. */
23852 REGSETH(d,VFD), REGSETH(D,VFD),
23853
23854 /* Neon QP registers. */
23855 REGSET2(q,NQ), REGSET2(Q,NQ),
23856
23857 /* VFP control registers. */
23858 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
23859 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
23860 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
23861 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
23862 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
23863 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
23864 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
23865 REGDEF(fpscr_nzcvqc,2,VFC), REGDEF(FPSCR_nzcvqc,2,VFC),
23866 REGDEF(vpr,12,VFC), REGDEF(VPR,12,VFC),
23867 REGDEF(fpcxt_ns,14,VFC), REGDEF(FPCXT_NS,14,VFC),
23868 REGDEF(fpcxt_s,15,VFC), REGDEF(FPCXT_S,15,VFC),
23869
23870 /* Maverick DSP coprocessor registers. */
23871 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
23872 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
23873
23874 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
23875 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
23876 REGDEF(dspsc,0,DSPSC),
23877
23878 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
23879 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
23880 REGDEF(DSPSC,0,DSPSC),
23881
23882 /* iWMMXt data registers - p0, c0-15. */
23883 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
23884
23885 /* iWMMXt control registers - p1, c0-3. */
23886 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
23887 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
23888 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
23889 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
23890
23891 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
23892 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
23893 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
23894 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
23895 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
23896
23897 /* XScale accumulator registers. */
23898 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
23899 };
23900 #undef REGDEF
23901 #undef REGNUM
23902 #undef REGSET
23903
23904 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
23905 within psr_required_here. */
23906 static const struct asm_psr psrs[] =
23907 {
23908 /* Backward compatibility notation. Note that "all" is no longer
23909 truly all possible PSR bits. */
23910 {"all", PSR_c | PSR_f},
23911 {"flg", PSR_f},
23912 {"ctl", PSR_c},
23913
23914 /* Individual flags. */
23915 {"f", PSR_f},
23916 {"c", PSR_c},
23917 {"x", PSR_x},
23918 {"s", PSR_s},
23919
23920 /* Combinations of flags. */
23921 {"fs", PSR_f | PSR_s},
23922 {"fx", PSR_f | PSR_x},
23923 {"fc", PSR_f | PSR_c},
23924 {"sf", PSR_s | PSR_f},
23925 {"sx", PSR_s | PSR_x},
23926 {"sc", PSR_s | PSR_c},
23927 {"xf", PSR_x | PSR_f},
23928 {"xs", PSR_x | PSR_s},
23929 {"xc", PSR_x | PSR_c},
23930 {"cf", PSR_c | PSR_f},
23931 {"cs", PSR_c | PSR_s},
23932 {"cx", PSR_c | PSR_x},
23933 {"fsx", PSR_f | PSR_s | PSR_x},
23934 {"fsc", PSR_f | PSR_s | PSR_c},
23935 {"fxs", PSR_f | PSR_x | PSR_s},
23936 {"fxc", PSR_f | PSR_x | PSR_c},
23937 {"fcs", PSR_f | PSR_c | PSR_s},
23938 {"fcx", PSR_f | PSR_c | PSR_x},
23939 {"sfx", PSR_s | PSR_f | PSR_x},
23940 {"sfc", PSR_s | PSR_f | PSR_c},
23941 {"sxf", PSR_s | PSR_x | PSR_f},
23942 {"sxc", PSR_s | PSR_x | PSR_c},
23943 {"scf", PSR_s | PSR_c | PSR_f},
23944 {"scx", PSR_s | PSR_c | PSR_x},
23945 {"xfs", PSR_x | PSR_f | PSR_s},
23946 {"xfc", PSR_x | PSR_f | PSR_c},
23947 {"xsf", PSR_x | PSR_s | PSR_f},
23948 {"xsc", PSR_x | PSR_s | PSR_c},
23949 {"xcf", PSR_x | PSR_c | PSR_f},
23950 {"xcs", PSR_x | PSR_c | PSR_s},
23951 {"cfs", PSR_c | PSR_f | PSR_s},
23952 {"cfx", PSR_c | PSR_f | PSR_x},
23953 {"csf", PSR_c | PSR_s | PSR_f},
23954 {"csx", PSR_c | PSR_s | PSR_x},
23955 {"cxf", PSR_c | PSR_x | PSR_f},
23956 {"cxs", PSR_c | PSR_x | PSR_s},
23957 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
23958 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
23959 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
23960 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
23961 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
23962 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
23963 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
23964 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
23965 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
23966 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
23967 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
23968 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
23969 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
23970 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
23971 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
23972 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
23973 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
23974 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
23975 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
23976 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
23977 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
23978 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
23979 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
23980 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
23981 };
23982
23983 /* Table of V7M psr names. */
23984 static const struct asm_psr v7m_psrs[] =
23985 {
23986 {"apsr", 0x0 }, {"APSR", 0x0 },
23987 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
23988 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
23989 {"psr", 0x3 }, {"PSR", 0x3 },
23990 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
23991 {"ipsr", 0x5 }, {"IPSR", 0x5 },
23992 {"epsr", 0x6 }, {"EPSR", 0x6 },
23993 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
23994 {"msp", 0x8 }, {"MSP", 0x8 },
23995 {"psp", 0x9 }, {"PSP", 0x9 },
23996 {"msplim", 0xa }, {"MSPLIM", 0xa },
23997 {"psplim", 0xb }, {"PSPLIM", 0xb },
23998 {"primask", 0x10}, {"PRIMASK", 0x10},
23999 {"basepri", 0x11}, {"BASEPRI", 0x11},
24000 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
24001 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
24002 {"control", 0x14}, {"CONTROL", 0x14},
24003 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
24004 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
24005 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
24006 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
24007 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
24008 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
24009 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
24010 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
24011 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
24012 };
24013
24014 /* Table of all shift-in-operand names. */
24015 static const struct asm_shift_name shift_names [] =
24016 {
24017 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
24018 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
24019 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
24020 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
24021 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
24022 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX },
24023 { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW}
24024 };
24025
24026 /* Table of all explicit relocation names. */
24027 #ifdef OBJ_ELF
24028 static struct reloc_entry reloc_names[] =
24029 {
24030 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
24031 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
24032 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
24033 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
24034 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
24035 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
24036 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
24037 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
24038 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
24039 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
24040 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
24041 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
24042 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
24043 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
24044 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
24045 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
24046 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
24047 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
24048 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
24049 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
24050 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24051 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24052 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
24053 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
24054 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
24055 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
24056 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
24057 };
24058 #endif
24059
24060 /* Table of all conditional affixes. */
24061 static const struct asm_cond conds[] =
24062 {
24063 {"eq", 0x0},
24064 {"ne", 0x1},
24065 {"cs", 0x2}, {"hs", 0x2},
24066 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
24067 {"mi", 0x4},
24068 {"pl", 0x5},
24069 {"vs", 0x6},
24070 {"vc", 0x7},
24071 {"hi", 0x8},
24072 {"ls", 0x9},
24073 {"ge", 0xa},
24074 {"lt", 0xb},
24075 {"gt", 0xc},
24076 {"le", 0xd},
24077 {"al", 0xe}
24078 };
24079 static const struct asm_cond vconds[] =
24080 {
24081 {"t", 0xf},
24082 {"e", 0x10}
24083 };
24084
24085 #define UL_BARRIER(L,U,CODE,FEAT) \
24086 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
24087 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
24088
24089 static struct asm_barrier_opt barrier_opt_names[] =
24090 {
24091 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
24092 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
24093 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
24094 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
24095 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
24096 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
24097 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
24098 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
24099 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
24100 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
24101 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
24102 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
24103 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
24104 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
24105 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
24106 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
24107 };
24108
24109 #undef UL_BARRIER
24110
24111 /* Table of ARM-format instructions. */
24112
24113 /* Macros for gluing together operand strings. N.B. In all cases
24114 other than OPS0, the trailing OP_stop comes from default
24115 zero-initialization of the unspecified elements of the array. */
24116 #define OPS0() { OP_stop, }
24117 #define OPS1(a) { OP_##a, }
24118 #define OPS2(a,b) { OP_##a,OP_##b, }
24119 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
24120 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
24121 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
24122 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
24123
24124 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
24125 This is useful when mixing operands for ARM and THUMB, i.e. using the
24126 MIX_ARM_THUMB_OPERANDS macro.
24127 In order to use these macros, prefix the number of operands with _
24128 e.g. _3. */
24129 #define OPS_1(a) { a, }
24130 #define OPS_2(a,b) { a,b, }
24131 #define OPS_3(a,b,c) { a,b,c, }
24132 #define OPS_4(a,b,c,d) { a,b,c,d, }
24133 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
24134 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
24135
24136 /* These macros abstract out the exact format of the mnemonic table and
24137 save some repeated characters. */
24138
24139 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
24140 #define TxCE(mnem, op, top, nops, ops, ae, te) \
24141 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
24142 THUMB_VARIANT, do_##ae, do_##te, 0 }
24143
24144 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
24145 a T_MNEM_xyz enumerator. */
24146 #define TCE(mnem, aop, top, nops, ops, ae, te) \
24147 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
24148 #define tCE(mnem, aop, top, nops, ops, ae, te) \
24149 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
24150
24151 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
24152 infix after the third character. */
24153 #define TxC3(mnem, op, top, nops, ops, ae, te) \
24154 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
24155 THUMB_VARIANT, do_##ae, do_##te, 0 }
24156 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
24157 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
24158 THUMB_VARIANT, do_##ae, do_##te, 0 }
24159 #define TC3(mnem, aop, top, nops, ops, ae, te) \
24160 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
24161 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
24162 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
24163 #define tC3(mnem, aop, top, nops, ops, ae, te) \
24164 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
24165 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
24166 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
24167
24168 /* Mnemonic that cannot be conditionalized. The ARM condition-code
24169 field is still 0xE. Many of the Thumb variants can be executed
24170 conditionally, so this is checked separately. */
24171 #define TUE(mnem, op, top, nops, ops, ae, te) \
24172 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
24173 THUMB_VARIANT, do_##ae, do_##te, 0 }
24174
24175 /* Same as TUE but the encoding function for ARM and Thumb modes is the same.
24176 Used by mnemonics that have very minimal differences in the encoding for
24177 ARM and Thumb variants and can be handled in a common function. */
24178 #define TUEc(mnem, op, top, nops, ops, en) \
24179 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
24180 THUMB_VARIANT, do_##en, do_##en, 0 }
24181
24182 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
24183 condition code field. */
24184 #define TUF(mnem, op, top, nops, ops, ae, te) \
24185 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
24186 THUMB_VARIANT, do_##ae, do_##te, 0 }
24187
24188 /* ARM-only variants of all the above. */
24189 #define CE(mnem, op, nops, ops, ae) \
24190 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24191
24192 #define C3(mnem, op, nops, ops, ae) \
24193 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24194
24195 /* Thumb-only variants of TCE and TUE. */
24196 #define ToC(mnem, top, nops, ops, te) \
24197 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
24198 do_##te, 0 }
24199
24200 #define ToU(mnem, top, nops, ops, te) \
24201 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
24202 NULL, do_##te, 0 }
24203
24204 /* T_MNEM_xyz enumerator variants of ToC. */
24205 #define toC(mnem, top, nops, ops, te) \
24206 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
24207 do_##te, 0 }
24208
24209 /* T_MNEM_xyz enumerator variants of ToU. */
24210 #define toU(mnem, top, nops, ops, te) \
24211 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
24212 NULL, do_##te, 0 }
24213
24214 /* Legacy mnemonics that always have conditional infix after the third
24215 character. */
24216 #define CL(mnem, op, nops, ops, ae) \
24217 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
24218 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24219
24220 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
24221 #define cCE(mnem, op, nops, ops, ae) \
24222 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
24223
24224 /* mov instructions that are shared between coprocessor and MVE. */
24225 #define mcCE(mnem, op, nops, ops, ae) \
24226 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##ae, 0 }
24227
24228 /* Legacy coprocessor instructions where conditional infix and conditional
24229 suffix are ambiguous. For consistency this includes all FPA instructions,
24230 not just the potentially ambiguous ones. */
24231 #define cCL(mnem, op, nops, ops, ae) \
24232 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
24233 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
24234
24235 /* Coprocessor, takes either a suffix or a position-3 infix
24236 (for an FPA corner case). */
24237 #define C3E(mnem, op, nops, ops, ae) \
24238 { mnem, OPS##nops ops, OT_csuf_or_in3, \
24239 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
24240
24241 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
24242 { m1 #m2 m3, OPS##nops ops, \
24243 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
24244 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24245
24246 #define CM(m1, m2, op, nops, ops, ae) \
24247 xCM_ (m1, , m2, op, nops, ops, ae), \
24248 xCM_ (m1, eq, m2, op, nops, ops, ae), \
24249 xCM_ (m1, ne, m2, op, nops, ops, ae), \
24250 xCM_ (m1, cs, m2, op, nops, ops, ae), \
24251 xCM_ (m1, hs, m2, op, nops, ops, ae), \
24252 xCM_ (m1, cc, m2, op, nops, ops, ae), \
24253 xCM_ (m1, ul, m2, op, nops, ops, ae), \
24254 xCM_ (m1, lo, m2, op, nops, ops, ae), \
24255 xCM_ (m1, mi, m2, op, nops, ops, ae), \
24256 xCM_ (m1, pl, m2, op, nops, ops, ae), \
24257 xCM_ (m1, vs, m2, op, nops, ops, ae), \
24258 xCM_ (m1, vc, m2, op, nops, ops, ae), \
24259 xCM_ (m1, hi, m2, op, nops, ops, ae), \
24260 xCM_ (m1, ls, m2, op, nops, ops, ae), \
24261 xCM_ (m1, ge, m2, op, nops, ops, ae), \
24262 xCM_ (m1, lt, m2, op, nops, ops, ae), \
24263 xCM_ (m1, gt, m2, op, nops, ops, ae), \
24264 xCM_ (m1, le, m2, op, nops, ops, ae), \
24265 xCM_ (m1, al, m2, op, nops, ops, ae)
24266
24267 #define UE(mnem, op, nops, ops, ae) \
24268 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24269
24270 #define UF(mnem, op, nops, ops, ae) \
24271 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24272
24273 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
24274 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
24275 use the same encoding function for each. */
24276 #define NUF(mnem, op, nops, ops, enc) \
24277 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
24278 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
24279
24280 /* Neon data processing, version which indirects through neon_enc_tab for
24281 the various overloaded versions of opcodes. */
24282 #define nUF(mnem, op, nops, ops, enc) \
24283 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
24284 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
24285
24286 /* Neon insn with conditional suffix for the ARM version, non-overloaded
24287 version. */
24288 #define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
24289 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
24290 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
24291
24292 #define NCE(mnem, op, nops, ops, enc) \
24293 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
24294
24295 #define NCEF(mnem, op, nops, ops, enc) \
24296 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
24297
24298 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
24299 #define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
24300 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
24301 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
24302
24303 #define nCE(mnem, op, nops, ops, enc) \
24304 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
24305
24306 #define nCEF(mnem, op, nops, ops, enc) \
24307 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
24308
24309 /* */
24310 #define mCEF(mnem, op, nops, ops, enc) \
24311 { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \
24312 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24313
24314
24315 /* nCEF but for MVE predicated instructions. */
24316 #define mnCEF(mnem, op, nops, ops, enc) \
24317 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
24318
24319 /* nCE but for MVE predicated instructions. */
24320 #define mnCE(mnem, op, nops, ops, enc) \
24321 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
24322
24323 /* NUF but for potentially MVE predicated instructions. */
24324 #define MNUF(mnem, op, nops, ops, enc) \
24325 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
24326 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24327
24328 /* nUF but for potentially MVE predicated instructions. */
24329 #define mnUF(mnem, op, nops, ops, enc) \
24330 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
24331 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24332
24333 /* ToC but for potentially MVE predicated instructions. */
24334 #define mToC(mnem, top, nops, ops, te) \
24335 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
24336 do_##te, 1 }
24337
24338 /* NCE but for MVE predicated instructions. */
24339 #define MNCE(mnem, op, nops, ops, enc) \
24340 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
24341
24342 /* NCEF but for MVE predicated instructions. */
24343 #define MNCEF(mnem, op, nops, ops, enc) \
24344 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
24345 #define do_0 0
24346
24347 static const struct asm_opcode insns[] =
24348 {
24349 #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
24350 #define THUMB_VARIANT & arm_ext_v4t
24351 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
24352 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
24353 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
24354 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
24355 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
24356 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
24357 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
24358 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
24359 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
24360 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
24361 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
24362 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
24363 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
24364 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
24365 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
24366 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
24367
24368 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
24369 for setting PSR flag bits. They are obsolete in V6 and do not
24370 have Thumb equivalents. */
24371 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24372 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24373 CL("tstp", 110f000, 2, (RR, SH), cmp),
24374 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24375 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24376 CL("cmpp", 150f000, 2, (RR, SH), cmp),
24377 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24378 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24379 CL("cmnp", 170f000, 2, (RR, SH), cmp),
24380
24381 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
24382 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
24383 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
24384 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
24385
24386 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
24387 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
24388 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
24389 OP_RRnpc),
24390 OP_ADDRGLDR),ldst, t_ldst),
24391 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
24392
24393 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24394 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24395 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24396 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24397 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24398 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24399
24400 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
24401 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
24402
24403 /* Pseudo ops. */
24404 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
24405 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
24406 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
24407 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
24408
24409 /* Thumb-compatibility pseudo ops. */
24410 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
24411 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
24412 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
24413 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
24414 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
24415 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
24416 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
24417 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
24418 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
24419 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
24420 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
24421 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
24422
24423 /* These may simplify to neg. */
24424 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
24425 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
24426
24427 #undef THUMB_VARIANT
24428 #define THUMB_VARIANT & arm_ext_os
24429
24430 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
24431 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
24432
24433 #undef THUMB_VARIANT
24434 #define THUMB_VARIANT & arm_ext_v6
24435
24436 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
24437
24438 /* V1 instructions with no Thumb analogue prior to V6T2. */
24439 #undef THUMB_VARIANT
24440 #define THUMB_VARIANT & arm_ext_v6t2
24441
24442 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24443 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24444 CL("teqp", 130f000, 2, (RR, SH), cmp),
24445
24446 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24447 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24448 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
24449 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24450
24451 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24452 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24453
24454 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24455 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24456
24457 /* V1 instructions with no Thumb analogue at all. */
24458 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
24459 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
24460
24461 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
24462 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
24463 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
24464 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
24465 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
24466 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
24467 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
24468 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
24469
24470 #undef ARM_VARIANT
24471 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
24472 #undef THUMB_VARIANT
24473 #define THUMB_VARIANT & arm_ext_v4t
24474
24475 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
24476 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
24477
24478 #undef THUMB_VARIANT
24479 #define THUMB_VARIANT & arm_ext_v6t2
24480
24481 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
24482 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
24483
24484 /* Generic coprocessor instructions. */
24485 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24486 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24487 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24488 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24489 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24490 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24491 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
24492
24493 #undef ARM_VARIANT
24494 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
24495
24496 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
24497 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
24498
24499 #undef ARM_VARIANT
24500 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
24501 #undef THUMB_VARIANT
24502 #define THUMB_VARIANT & arm_ext_msr
24503
24504 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
24505 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
24506
24507 #undef ARM_VARIANT
24508 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
24509 #undef THUMB_VARIANT
24510 #define THUMB_VARIANT & arm_ext_v6t2
24511
24512 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24513 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24514 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24515 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24516 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24517 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24518 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24519 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24520
24521 #undef ARM_VARIANT
24522 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
24523 #undef THUMB_VARIANT
24524 #define THUMB_VARIANT & arm_ext_v4t
24525
24526 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24527 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24528 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24529 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24530 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24531 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24532
24533 #undef ARM_VARIANT
24534 #define ARM_VARIANT & arm_ext_v4t_5
24535
24536 /* ARM Architecture 4T. */
24537 /* Note: bx (and blx) are required on V5, even if the processor does
24538 not support Thumb. */
24539 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
24540
24541 #undef ARM_VARIANT
24542 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
24543 #undef THUMB_VARIANT
24544 #define THUMB_VARIANT & arm_ext_v5t
24545
24546 /* Note: blx has 2 variants; the .value coded here is for
24547 BLX(2). Only this variant has conditional execution. */
24548 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
24549 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
24550
24551 #undef THUMB_VARIANT
24552 #define THUMB_VARIANT & arm_ext_v6t2
24553
24554 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
24555 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24556 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24557 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24558 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24559 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24560 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24561 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24562
24563 #undef ARM_VARIANT
24564 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
24565 #undef THUMB_VARIANT
24566 #define THUMB_VARIANT & arm_ext_v5exp
24567
24568 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24569 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24570 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24571 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24572
24573 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24574 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24575
24576 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24577 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24578 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24579 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24580
24581 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24582 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24583 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24584 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24585
24586 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24587 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24588
24589 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24590 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24591 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24592 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24593
24594 #undef ARM_VARIANT
24595 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
24596 #undef THUMB_VARIANT
24597 #define THUMB_VARIANT & arm_ext_v6t2
24598
24599 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
24600 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
24601 ldrd, t_ldstd),
24602 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
24603 ADDRGLDRS), ldrd, t_ldstd),
24604
24605 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24606 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24607
24608 #undef ARM_VARIANT
24609 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
24610
24611 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
24612
24613 #undef ARM_VARIANT
24614 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
24615 #undef THUMB_VARIANT
24616 #define THUMB_VARIANT & arm_ext_v6
24617
24618 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
24619 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
24620 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24621 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24622 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24623 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24624 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24625 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24626 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24627 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
24628
24629 #undef THUMB_VARIANT
24630 #define THUMB_VARIANT & arm_ext_v6t2_v8m
24631
24632 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
24633 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24634 strex, t_strex),
24635 #undef THUMB_VARIANT
24636 #define THUMB_VARIANT & arm_ext_v6t2
24637
24638 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24639 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24640
24641 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
24642 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
24643
24644 /* ARM V6 not included in V7M. */
24645 #undef THUMB_VARIANT
24646 #define THUMB_VARIANT & arm_ext_v6_notm
24647 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
24648 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
24649 UF(rfeib, 9900a00, 1, (RRw), rfe),
24650 UF(rfeda, 8100a00, 1, (RRw), rfe),
24651 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24652 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
24653 UF(rfefa, 8100a00, 1, (RRw), rfe),
24654 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24655 UF(rfeed, 9900a00, 1, (RRw), rfe),
24656 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24657 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24658 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24659 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
24660 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
24661 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
24662 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
24663 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
24664 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
24665 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
24666
24667 /* ARM V6 not included in V7M (eg. integer SIMD). */
24668 #undef THUMB_VARIANT
24669 #define THUMB_VARIANT & arm_ext_v6_dsp
24670 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
24671 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
24672 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24673 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24674 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24675 /* Old name for QASX. */
24676 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24677 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24678 /* Old name for QSAX. */
24679 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24680 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24681 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24682 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24683 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24684 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24685 /* Old name for SASX. */
24686 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24687 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24688 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24689 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24690 /* Old name for SHASX. */
24691 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24692 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24693 /* Old name for SHSAX. */
24694 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24695 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24696 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24697 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24698 /* Old name for SSAX. */
24699 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24700 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24701 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24702 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24703 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24704 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24705 /* Old name for UASX. */
24706 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24707 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24708 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24709 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24710 /* Old name for UHASX. */
24711 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24712 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24713 /* Old name for UHSAX. */
24714 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24715 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24716 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24717 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24718 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24719 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24720 /* Old name for UQASX. */
24721 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24722 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24723 /* Old name for UQSAX. */
24724 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24725 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24726 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24727 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24728 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24729 /* Old name for USAX. */
24730 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24731 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24732 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24733 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24734 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24735 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24736 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24737 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24738 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24739 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24740 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24741 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24742 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24743 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24744 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24745 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24746 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24747 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24748 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24749 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24750 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24751 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24752 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24753 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24754 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24755 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24756 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24757 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24758 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24759 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
24760 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
24761 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24762 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24763 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
24764
24765 #undef ARM_VARIANT
24766 #define ARM_VARIANT & arm_ext_v6k_v6t2
24767 #undef THUMB_VARIANT
24768 #define THUMB_VARIANT & arm_ext_v6k_v6t2
24769
24770 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
24771 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
24772 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
24773 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
24774
24775 #undef THUMB_VARIANT
24776 #define THUMB_VARIANT & arm_ext_v6_notm
24777 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
24778 ldrexd, t_ldrexd),
24779 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
24780 RRnpcb), strexd, t_strexd),
24781
24782 #undef THUMB_VARIANT
24783 #define THUMB_VARIANT & arm_ext_v6t2_v8m
24784 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
24785 rd_rn, rd_rn),
24786 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
24787 rd_rn, rd_rn),
24788 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24789 strex, t_strexbh),
24790 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24791 strex, t_strexbh),
24792 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
24793
24794 #undef ARM_VARIANT
24795 #define ARM_VARIANT & arm_ext_sec
24796 #undef THUMB_VARIANT
24797 #define THUMB_VARIANT & arm_ext_sec
24798
24799 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
24800
24801 #undef ARM_VARIANT
24802 #define ARM_VARIANT & arm_ext_virt
24803 #undef THUMB_VARIANT
24804 #define THUMB_VARIANT & arm_ext_virt
24805
24806 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
24807 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
24808
24809 #undef ARM_VARIANT
24810 #define ARM_VARIANT & arm_ext_pan
24811 #undef THUMB_VARIANT
24812 #define THUMB_VARIANT & arm_ext_pan
24813
24814 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
24815
24816 #undef ARM_VARIANT
24817 #define ARM_VARIANT & arm_ext_v6t2
24818 #undef THUMB_VARIANT
24819 #define THUMB_VARIANT & arm_ext_v6t2
24820
24821 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
24822 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
24823 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24824 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24825
24826 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
24827 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
24828
24829 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24830 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24831 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24832 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24833
24834 #undef ARM_VARIANT
24835 #define ARM_VARIANT & arm_ext_v3
24836 #undef THUMB_VARIANT
24837 #define THUMB_VARIANT & arm_ext_v6t2
24838
24839 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
24840 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
24841 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
24842
24843 #undef ARM_VARIANT
24844 #define ARM_VARIANT & arm_ext_v6t2
24845 #undef THUMB_VARIANT
24846 #define THUMB_VARIANT & arm_ext_v6t2_v8m
24847 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
24848 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
24849
24850 /* Thumb-only instructions. */
24851 #undef ARM_VARIANT
24852 #define ARM_VARIANT NULL
24853 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
24854 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
24855
24856 /* ARM does not really have an IT instruction, so always allow it.
24857 The opcode is copied from Thumb in order to allow warnings in
24858 -mimplicit-it=[never | arm] modes. */
24859 #undef ARM_VARIANT
24860 #define ARM_VARIANT & arm_ext_v1
24861 #undef THUMB_VARIANT
24862 #define THUMB_VARIANT & arm_ext_v6t2
24863
24864 TUE("it", bf08, bf08, 1, (COND), it, t_it),
24865 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
24866 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
24867 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
24868 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
24869 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
24870 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
24871 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
24872 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
24873 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
24874 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
24875 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
24876 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
24877 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
24878 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
24879 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
24880 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
24881 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
24882
24883 /* Thumb2 only instructions. */
24884 #undef ARM_VARIANT
24885 #define ARM_VARIANT NULL
24886
24887 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24888 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24889 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
24890 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
24891 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
24892 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
24893
24894 /* Hardware division instructions. */
24895 #undef ARM_VARIANT
24896 #define ARM_VARIANT & arm_ext_adiv
24897 #undef THUMB_VARIANT
24898 #define THUMB_VARIANT & arm_ext_div
24899
24900 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
24901 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
24902
24903 /* ARM V6M/V7 instructions. */
24904 #undef ARM_VARIANT
24905 #define ARM_VARIANT & arm_ext_barrier
24906 #undef THUMB_VARIANT
24907 #define THUMB_VARIANT & arm_ext_barrier
24908
24909 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
24910 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
24911 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
24912
24913 /* ARM V7 instructions. */
24914 #undef ARM_VARIANT
24915 #define ARM_VARIANT & arm_ext_v7
24916 #undef THUMB_VARIANT
24917 #define THUMB_VARIANT & arm_ext_v7
24918
24919 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
24920 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
24921
24922 #undef ARM_VARIANT
24923 #define ARM_VARIANT & arm_ext_mp
24924 #undef THUMB_VARIANT
24925 #define THUMB_VARIANT & arm_ext_mp
24926
24927 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
24928
24929 /* AArchv8 instructions. */
24930 #undef ARM_VARIANT
24931 #define ARM_VARIANT & arm_ext_v8
24932
24933 /* Instructions shared between armv8-a and armv8-m. */
24934 #undef THUMB_VARIANT
24935 #define THUMB_VARIANT & arm_ext_atomics
24936
24937 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24938 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24939 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24940 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24941 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24942 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24943 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24944 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
24945 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24946 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
24947 stlex, t_stlex),
24948 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
24949 stlex, t_stlex),
24950 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
24951 stlex, t_stlex),
24952 #undef THUMB_VARIANT
24953 #define THUMB_VARIANT & arm_ext_v8
24954
24955 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
24956 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
24957 ldrexd, t_ldrexd),
24958 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
24959 strexd, t_strexd),
24960
24961 /* Defined in V8 but is in undefined encoding space for earlier
24962 architectures. However earlier architectures are required to treat
24963 this instuction as a semihosting trap as well. Hence while not explicitly
24964 defined as such, it is in fact correct to define the instruction for all
24965 architectures. */
24966 #undef THUMB_VARIANT
24967 #define THUMB_VARIANT & arm_ext_v1
24968 #undef ARM_VARIANT
24969 #define ARM_VARIANT & arm_ext_v1
24970 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
24971
24972 /* ARMv8 T32 only. */
24973 #undef ARM_VARIANT
24974 #define ARM_VARIANT NULL
24975 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
24976 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
24977 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
24978
24979 /* FP for ARMv8. */
24980 #undef ARM_VARIANT
24981 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
24982 #undef THUMB_VARIANT
24983 #define THUMB_VARIANT & fpu_vfp_ext_armv8xd
24984
24985 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
24986 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
24987 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
24988 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
24989 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
24990 mnCE(vrintz, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintz),
24991 mnCE(vrintx, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintx),
24992 mnUF(vrinta, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrinta),
24993 mnUF(vrintn, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintn),
24994 mnUF(vrintp, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintp),
24995 mnUF(vrintm, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintm),
24996
24997 /* Crypto v1 extensions. */
24998 #undef ARM_VARIANT
24999 #define ARM_VARIANT & fpu_crypto_ext_armv8
25000 #undef THUMB_VARIANT
25001 #define THUMB_VARIANT & fpu_crypto_ext_armv8
25002
25003 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
25004 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
25005 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
25006 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
25007 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
25008 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
25009 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
25010 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
25011 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
25012 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
25013 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
25014 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
25015 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
25016 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
25017
25018 #undef ARM_VARIANT
25019 #define ARM_VARIANT & arm_ext_crc
25020 #undef THUMB_VARIANT
25021 #define THUMB_VARIANT & arm_ext_crc
25022 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
25023 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
25024 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
25025 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
25026 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
25027 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
25028
25029 /* ARMv8.2 RAS extension. */
25030 #undef ARM_VARIANT
25031 #define ARM_VARIANT & arm_ext_ras
25032 #undef THUMB_VARIANT
25033 #define THUMB_VARIANT & arm_ext_ras
25034 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
25035
25036 #undef ARM_VARIANT
25037 #define ARM_VARIANT & arm_ext_v8_3
25038 #undef THUMB_VARIANT
25039 #define THUMB_VARIANT & arm_ext_v8_3
25040 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
25041
25042 #undef ARM_VARIANT
25043 #define ARM_VARIANT & fpu_neon_ext_dotprod
25044 #undef THUMB_VARIANT
25045 #define THUMB_VARIANT & fpu_neon_ext_dotprod
25046 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
25047 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
25048
25049 #undef ARM_VARIANT
25050 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
25051 #undef THUMB_VARIANT
25052 #define THUMB_VARIANT NULL
25053
25054 cCE("wfs", e200110, 1, (RR), rd),
25055 cCE("rfs", e300110, 1, (RR), rd),
25056 cCE("wfc", e400110, 1, (RR), rd),
25057 cCE("rfc", e500110, 1, (RR), rd),
25058
25059 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
25060 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
25061 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
25062 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
25063
25064 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
25065 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
25066 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
25067 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
25068
25069 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
25070 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
25071 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
25072 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
25073 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
25074 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
25075 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
25076 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
25077 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
25078 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
25079 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
25080 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
25081
25082 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
25083 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
25084 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
25085 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
25086 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
25087 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
25088 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
25089 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
25090 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
25091 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
25092 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
25093 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
25094
25095 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
25096 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
25097 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
25098 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
25099 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
25100 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
25101 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
25102 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
25103 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
25104 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
25105 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
25106 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
25107
25108 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
25109 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
25110 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
25111 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
25112 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
25113 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
25114 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
25115 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
25116 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
25117 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
25118 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
25119 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
25120
25121 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
25122 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
25123 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
25124 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
25125 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
25126 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
25127 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
25128 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
25129 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
25130 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
25131 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
25132 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
25133
25134 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
25135 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
25136 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
25137 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
25138 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
25139 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
25140 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
25141 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
25142 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
25143 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
25144 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
25145 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
25146
25147 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
25148 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
25149 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
25150 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
25151 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
25152 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
25153 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
25154 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
25155 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
25156 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
25157 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
25158 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
25159
25160 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
25161 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
25162 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
25163 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
25164 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
25165 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
25166 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
25167 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
25168 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
25169 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
25170 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
25171 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
25172
25173 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
25174 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
25175 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
25176 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
25177 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
25178 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
25179 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
25180 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
25181 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
25182 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
25183 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
25184 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
25185
25186 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
25187 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
25188 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
25189 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
25190 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
25191 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
25192 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
25193 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
25194 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
25195 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
25196 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
25197 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
25198
25199 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
25200 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
25201 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
25202 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
25203 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
25204 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
25205 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
25206 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
25207 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
25208 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
25209 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
25210 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
25211
25212 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
25213 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
25214 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
25215 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
25216 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
25217 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
25218 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
25219 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
25220 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
25221 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
25222 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
25223 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
25224
25225 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
25226 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
25227 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
25228 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
25229 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
25230 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
25231 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
25232 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
25233 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
25234 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
25235 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
25236 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
25237
25238 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
25239 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
25240 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
25241 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
25242 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
25243 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
25244 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
25245 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
25246 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
25247 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
25248 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
25249 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
25250
25251 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
25252 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
25253 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
25254 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
25255 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
25256 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
25257 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
25258 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
25259 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
25260 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
25261 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
25262 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
25263
25264 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
25265 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
25266 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
25267 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
25268 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
25269 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
25270 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
25271 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
25272 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
25273 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
25274 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
25275 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
25276
25277 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
25278 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
25279 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
25280 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
25281 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
25282 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25283 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25284 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25285 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
25286 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
25287 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
25288 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
25289
25290 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
25291 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
25292 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
25293 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
25294 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
25295 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25296 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25297 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25298 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
25299 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
25300 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
25301 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
25302
25303 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
25304 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
25305 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
25306 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
25307 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
25308 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25309 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25310 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25311 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
25312 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
25313 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
25314 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
25315
25316 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
25317 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
25318 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
25319 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
25320 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
25321 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25322 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25323 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25324 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
25325 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
25326 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
25327 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
25328
25329 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
25330 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
25331 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
25332 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
25333 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
25334 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25335 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25336 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25337 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
25338 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
25339 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
25340 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
25341
25342 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
25343 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
25344 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
25345 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
25346 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
25347 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25348 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25349 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25350 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
25351 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
25352 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
25353 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
25354
25355 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
25356 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
25357 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
25358 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
25359 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
25360 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25361 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25362 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25363 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
25364 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
25365 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
25366 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
25367
25368 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
25369 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
25370 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
25371 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
25372 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
25373 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25374 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25375 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25376 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
25377 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
25378 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
25379 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
25380
25381 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
25382 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
25383 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
25384 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
25385 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
25386 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25387 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25388 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25389 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
25390 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
25391 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
25392 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
25393
25394 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
25395 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
25396 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
25397 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
25398 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
25399 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25400 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25401 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25402 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
25403 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
25404 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
25405 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
25406
25407 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25408 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25409 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25410 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25411 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25412 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25413 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25414 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25415 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25416 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25417 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25418 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25419
25420 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25421 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25422 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25423 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25424 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25425 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25426 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25427 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25428 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25429 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25430 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25431 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25432
25433 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25434 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25435 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25436 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25437 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25438 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25439 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25440 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25441 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25442 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25443 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25444 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25445
25446 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
25447 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
25448 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
25449 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
25450
25451 cCL("flts", e000110, 2, (RF, RR), rn_rd),
25452 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
25453 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
25454 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
25455 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
25456 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
25457 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
25458 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
25459 cCL("flte", e080110, 2, (RF, RR), rn_rd),
25460 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
25461 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
25462 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
25463
25464 /* The implementation of the FIX instruction is broken on some
25465 assemblers, in that it accepts a precision specifier as well as a
25466 rounding specifier, despite the fact that this is meaningless.
25467 To be more compatible, we accept it as well, though of course it
25468 does not set any bits. */
25469 cCE("fix", e100110, 2, (RR, RF), rd_rm),
25470 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
25471 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
25472 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
25473 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
25474 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
25475 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
25476 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
25477 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
25478 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
25479 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
25480 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
25481 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
25482
25483 /* Instructions that were new with the real FPA, call them V2. */
25484 #undef ARM_VARIANT
25485 #define ARM_VARIANT & fpu_fpa_ext_v2
25486
25487 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25488 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25489 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25490 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25491 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25492 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25493
25494 #undef ARM_VARIANT
25495 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
25496 #undef THUMB_VARIANT
25497 #define THUMB_VARIANT & arm_ext_v6t2
25498 mcCE(vmrs, ef00a10, 2, (APSR_RR, RVC), vmrs),
25499 mcCE(vmsr, ee00a10, 2, (RVC, RR), vmsr),
25500 mcCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25501 mcCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25502 mcCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
25503 mcCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
25504
25505 /* Memory operations. */
25506 mcCE(fldmias, c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25507 mcCE(fldmdbs, d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25508 mcCE(fstmias, c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25509 mcCE(fstmdbs, d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25510 #undef THUMB_VARIANT
25511
25512 /* Moves and type conversions. */
25513 cCE("fmstat", ef1fa10, 0, (), noargs),
25514 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
25515 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
25516 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
25517 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25518 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
25519 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25520 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
25521 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
25522
25523 /* Memory operations. */
25524 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25525 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25526 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25527 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25528 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25529 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25530 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25531 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25532 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25533 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25534 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25535 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25536
25537 /* Monadic operations. */
25538 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
25539 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
25540 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
25541
25542 /* Dyadic operations. */
25543 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25544 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25545 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25546 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25547 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25548 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25549 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25550 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25551 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25552
25553 /* Comparisons. */
25554 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
25555 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
25556 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
25557 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
25558
25559 /* Double precision load/store are still present on single precision
25560 implementations. */
25561 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25562 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25563 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25564 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25565 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25566 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25567 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25568 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25569
25570 #undef ARM_VARIANT
25571 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
25572
25573 /* Moves and type conversions. */
25574 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25575 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25576 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
25577 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
25578 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
25579 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
25580 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25581 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
25582 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25583 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25584 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25585 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25586
25587 /* Monadic operations. */
25588 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25589 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25590 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25591
25592 /* Dyadic operations. */
25593 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25594 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25595 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25596 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25597 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25598 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25599 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25600 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25601 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25602
25603 /* Comparisons. */
25604 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25605 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
25606 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25607 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
25608
25609 /* Instructions which may belong to either the Neon or VFP instruction sets.
25610 Individual encoder functions perform additional architecture checks. */
25611 #undef ARM_VARIANT
25612 #define ARM_VARIANT & fpu_vfp_ext_v1xd
25613 #undef THUMB_VARIANT
25614 #define THUMB_VARIANT & arm_ext_v6t2
25615
25616 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25617 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25618 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25619 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25620 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25621 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25622
25623 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
25624 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
25625
25626 #undef THUMB_VARIANT
25627 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
25628
25629 /* These mnemonics are unique to VFP. */
25630 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
25631 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
25632 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25633 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25634 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25635 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
25636
25637 /* Mnemonics shared by Neon and VFP. */
25638 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
25639
25640 mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt),
25641 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
25642 MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb),
25643 MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt),
25644
25645
25646 /* NOTE: All VMOV encoding is special-cased! */
25647 NCE(vmovq, 0, 1, (VMOV), neon_mov),
25648
25649 #undef THUMB_VARIANT
25650 /* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
25651 by different feature bits. Since we are setting the Thumb guard, we can
25652 require Thumb-1 which makes it a nop guard and set the right feature bit in
25653 do_vldr_vstr (). */
25654 #define THUMB_VARIANT & arm_ext_v4t
25655 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25656 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25657
25658 #undef ARM_VARIANT
25659 #define ARM_VARIANT & arm_ext_fp16
25660 #undef THUMB_VARIANT
25661 #define THUMB_VARIANT & arm_ext_fp16
25662 /* New instructions added from v8.2, allowing the extraction and insertion of
25663 the upper 16 bits of a 32-bit vector register. */
25664 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
25665 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
25666
25667 /* New backported fma/fms instructions optional in v8.2. */
25668 NUF (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
25669 NUF (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
25670
25671 #undef THUMB_VARIANT
25672 #define THUMB_VARIANT & fpu_neon_ext_v1
25673 #undef ARM_VARIANT
25674 #define ARM_VARIANT & fpu_neon_ext_v1
25675
25676 /* Data processing with three registers of the same length. */
25677 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
25678 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
25679 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
25680 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25681 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25682 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25683 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
25684 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
25685 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
25686 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
25687 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
25688 /* If not immediate, fall back to neon_dyadic_i64_su.
25689 shl should accept I8 I16 I32 I64,
25690 qshl should accept S8 S16 S32 S64 U8 U16 U32 U64. */
25691 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl),
25692 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl),
25693 /* Logic ops, types optional & ignored. */
25694 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25695 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25696 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25697 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25698 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
25699 /* Bitfield ops, untyped. */
25700 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25701 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25702 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25703 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25704 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25705 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25706 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
25707 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
25708 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
25709 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
25710 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
25711 back to neon_dyadic_if_su. */
25712 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25713 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25714 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25715 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25716 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25717 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
25718 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25719 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
25720 /* Comparison. Type I8 I16 I32 F32. */
25721 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
25722 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
25723 /* As above, D registers only. */
25724 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
25725 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
25726 /* Int and float variants, signedness unimportant. */
25727 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25728 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25729 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
25730 /* Add/sub take types I8 I16 I32 I64 F32. */
25731 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
25732 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
25733 /* vtst takes sizes 8, 16, 32. */
25734 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
25735 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
25736 /* VMUL takes I8 I16 I32 F32 P8. */
25737 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
25738 /* VQD{R}MULH takes S16 S32. */
25739 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
25740 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
25741 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25742 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
25743 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25744 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
25745 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25746 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
25747 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25748 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
25749 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25750 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
25751 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25752 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
25753 /* ARM v8.1 extension. */
25754 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
25755 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
25756 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
25757
25758 /* Two address, int/float. Types S8 S16 S32 F32. */
25759 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
25760 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
25761
25762 /* Data processing with two registers and a shift amount. */
25763 /* Right shifts, and variants with rounding.
25764 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
25765 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
25766 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
25767 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25768 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25769 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25770 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25771 /* Shift and insert. Sizes accepted 8 16 32 64. */
25772 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
25773 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
25774 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
25775 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
25776 /* Right shift immediate, saturating & narrowing, with rounding variants.
25777 Types accepted S16 S32 S64 U16 U32 U64. */
25778 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25779 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25780 /* As above, unsigned. Types accepted S16 S32 S64. */
25781 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25782 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25783 /* Right shift narrowing. Types accepted I16 I32 I64. */
25784 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25785 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25786 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
25787 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
25788 /* CVT with optional immediate for fixed-point variant. */
25789 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
25790
25791 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
25792
25793 /* Data processing, three registers of different lengths. */
25794 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
25795 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
25796 /* If not scalar, fall back to neon_dyadic_long.
25797 Vector types as above, scalar types S16 S32 U16 U32. */
25798 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
25799 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
25800 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
25801 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25802 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25803 /* Dyadic, narrowing insns. Types I16 I32 I64. */
25804 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25805 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25806 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25807 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25808 /* Saturating doubling multiplies. Types S16 S32. */
25809 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25810 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25811 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25812 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
25813 S16 S32 U16 U32. */
25814 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
25815
25816 /* Extract. Size 8. */
25817 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
25818 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
25819
25820 /* Two registers, miscellaneous. */
25821 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
25822 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
25823 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
25824 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
25825 /* Vector replicate. Sizes 8 16 32. */
25826 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
25827 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
25828 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
25829 /* VMOVN. Types I16 I32 I64. */
25830 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
25831 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
25832 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
25833 /* VQMOVUN. Types S16 S32 S64. */
25834 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
25835 /* VZIP / VUZP. Sizes 8 16 32. */
25836 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
25837 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
25838 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
25839 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
25840 /* VQABS / VQNEG. Types S8 S16 S32. */
25841 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
25842 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
25843 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
25844 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
25845 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
25846 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
25847 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
25848 /* Reciprocal estimates. Types U32 F16 F32. */
25849 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
25850 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
25851 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
25852 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
25853 /* VCLS. Types S8 S16 S32. */
25854 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
25855 /* VCLZ. Types I8 I16 I32. */
25856 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
25857 /* VCNT. Size 8. */
25858 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
25859 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
25860 /* Two address, untyped. */
25861 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
25862 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
25863 /* VTRN. Sizes 8 16 32. */
25864 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
25865 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
25866
25867 /* Table lookup. Size 8. */
25868 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25869 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25870
25871 #undef THUMB_VARIANT
25872 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
25873 #undef ARM_VARIANT
25874 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
25875
25876 /* Neon element/structure load/store. */
25877 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25878 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25879 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25880 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25881 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25882 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25883 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25884 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25885
25886 #undef THUMB_VARIANT
25887 #define THUMB_VARIANT & fpu_vfp_ext_v3xd
25888 #undef ARM_VARIANT
25889 #define ARM_VARIANT & fpu_vfp_ext_v3xd
25890 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
25891 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25892 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25893 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25894 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25895 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25896 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25897 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25898 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25899
25900 #undef THUMB_VARIANT
25901 #define THUMB_VARIANT & fpu_vfp_ext_v3
25902 #undef ARM_VARIANT
25903 #define ARM_VARIANT & fpu_vfp_ext_v3
25904
25905 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
25906 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25907 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25908 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25909 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25910 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25911 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25912 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25913 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25914
25915 #undef ARM_VARIANT
25916 #define ARM_VARIANT & fpu_vfp_ext_fma
25917 #undef THUMB_VARIANT
25918 #define THUMB_VARIANT & fpu_vfp_ext_fma
25919 /* Mnemonics shared by Neon, VFP, MVE and BF16. These are included in the
25920 VFP FMA variant; NEON and VFP FMA always includes the NEON
25921 FMA instructions. */
25922 mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac),
25923 TUF ("vfmat", c300850, fc300850, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), mve_vfma, mve_vfma),
25924 mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac),
25925
25926 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
25927 the v form should always be used. */
25928 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25929 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25930 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25931 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25932 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25933 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25934
25935 #undef THUMB_VARIANT
25936 #undef ARM_VARIANT
25937 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
25938
25939 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25940 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25941 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25942 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25943 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25944 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25945 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
25946 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
25947
25948 #undef ARM_VARIANT
25949 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
25950
25951 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
25952 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
25953 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
25954 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
25955 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
25956 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
25957 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
25958 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
25959 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
25960 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25961 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25962 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25963 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25964 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25965 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25966 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25967 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25968 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25969 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
25970 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
25971 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25972 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25973 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25974 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25975 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25976 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25977 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
25978 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
25979 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
25980 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
25981 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
25982 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
25983 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
25984 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
25985 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
25986 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
25987 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
25988 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25989 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25990 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25991 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25992 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25993 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25994 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25995 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25996 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25997 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
25998 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25999 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26000 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26001 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26002 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26003 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26004 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26005 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26006 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26007 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26008 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26009 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26010 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26011 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26012 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26013 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26014 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26015 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26016 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26017 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26018 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26019 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26020 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26021 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26022 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26023 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26024 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26025 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26026 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26027 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26028 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26029 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26030 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26031 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26032 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26033 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26034 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26035 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26036 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26037 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26038 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26039 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
26040 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26041 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26042 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26043 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26044 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26045 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26046 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26047 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26048 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26049 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26050 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26051 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26052 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26053 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26054 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26055 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26056 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26057 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26058 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26059 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26060 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26061 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
26062 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26063 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26064 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26065 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26066 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26067 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26068 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26069 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26070 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26071 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26072 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26073 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26074 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26075 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26076 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26077 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26078 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26079 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26080 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26081 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26082 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26083 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26084 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26085 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26086 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26087 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26088 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26089 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26090 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26091 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26092 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26093 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
26094 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
26095 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
26096 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
26097 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
26098 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
26099 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26100 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26101 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26102 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
26103 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
26104 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
26105 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
26106 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
26107 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
26108 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26109 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26110 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26111 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26112 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
26113
26114 #undef ARM_VARIANT
26115 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
26116
26117 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
26118 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
26119 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
26120 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
26121 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
26122 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
26123 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26124 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26125 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26126 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26127 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26128 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26129 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26130 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26131 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26132 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26133 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26134 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26135 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26136 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26137 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
26138 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26139 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26140 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26141 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26142 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26143 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26144 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26145 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26146 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26147 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26148 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26149 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26150 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26151 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26152 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26153 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26154 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26155 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26156 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26157 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26158 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26159 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26160 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26161 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26162 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26163 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26164 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26165 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26166 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26167 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26168 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26169 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26170 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26171 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26172 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26173 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26174
26175 #undef ARM_VARIANT
26176 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
26177
26178 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26179 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26180 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26181 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26182 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26183 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26184 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26185 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26186 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
26187 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
26188 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
26189 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
26190 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
26191 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
26192 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
26193 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
26194 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
26195 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
26196 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
26197 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
26198 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
26199 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
26200 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
26201 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
26202 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
26203 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
26204 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
26205 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
26206 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
26207 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
26208 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
26209 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
26210 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
26211 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
26212 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
26213 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
26214 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
26215 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
26216 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
26217 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
26218 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
26219 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
26220 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
26221 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
26222 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
26223 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
26224 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
26225 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
26226 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
26227 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
26228 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
26229 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
26230 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
26231 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
26232 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
26233 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
26234 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
26235 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
26236 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
26237 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
26238 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
26239 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
26240 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
26241 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
26242 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26243 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26244 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26245 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26246 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26247 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26248 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26249 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26250 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
26251 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
26252 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
26253 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
26254
26255 /* ARMv8.5-A instructions. */
26256 #undef ARM_VARIANT
26257 #define ARM_VARIANT & arm_ext_sb
26258 #undef THUMB_VARIANT
26259 #define THUMB_VARIANT & arm_ext_sb
26260 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
26261
26262 #undef ARM_VARIANT
26263 #define ARM_VARIANT & arm_ext_predres
26264 #undef THUMB_VARIANT
26265 #define THUMB_VARIANT & arm_ext_predres
26266 CE("cfprctx", e070f93, 1, (RRnpc), rd),
26267 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
26268 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
26269
26270 /* ARMv8-M instructions. */
26271 #undef ARM_VARIANT
26272 #define ARM_VARIANT NULL
26273 #undef THUMB_VARIANT
26274 #define THUMB_VARIANT & arm_ext_v8m
26275 ToU("sg", e97fe97f, 0, (), noargs),
26276 ToC("blxns", 4784, 1, (RRnpc), t_blx),
26277 ToC("bxns", 4704, 1, (RRnpc), t_bx),
26278 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
26279 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
26280 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
26281 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
26282
26283 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
26284 instructions behave as nop if no VFP is present. */
26285 #undef THUMB_VARIANT
26286 #define THUMB_VARIANT & arm_ext_v8m_main
26287 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
26288 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
26289
26290 /* Armv8.1-M Mainline instructions. */
26291 #undef THUMB_VARIANT
26292 #define THUMB_VARIANT & arm_ext_v8_1m_main
26293 toU("cinc", _cinc, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26294 toU("cinv", _cinv, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26295 toU("cneg", _cneg, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26296 toU("csel", _csel, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26297 toU("csetm", _csetm, 2, (RRnpcsp, COND), t_cond),
26298 toU("cset", _cset, 2, (RRnpcsp, COND), t_cond),
26299 toU("csinc", _csinc, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26300 toU("csinv", _csinv, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26301 toU("csneg", _csneg, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26302
26303 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
26304 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
26305 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
26306 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
26307 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
26308
26309 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
26310 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
26311 toU("le", _le, 2, (oLR, EXP), t_loloop),
26312
26313 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
26314 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
26315
26316 #undef THUMB_VARIANT
26317 #define THUMB_VARIANT & mve_ext
26318 ToC("lsll", ea50010d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
26319 ToC("lsrl", ea50011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26320 ToC("asrl", ea50012d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
26321 ToC("uqrshll", ea51010d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
26322 ToC("sqrshrl", ea51012d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
26323 ToC("uqshll", ea51010f, 3, (RRe, RRo, I32), mve_scalar_shift),
26324 ToC("urshrl", ea51011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26325 ToC("srshrl", ea51012f, 3, (RRe, RRo, I32), mve_scalar_shift),
26326 ToC("sqshll", ea51013f, 3, (RRe, RRo, I32), mve_scalar_shift),
26327 ToC("uqrshl", ea500f0d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26328 ToC("sqrshr", ea500f2d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26329 ToC("uqshl", ea500f0f, 2, (RRnpcsp, I32), mve_scalar_shift),
26330 ToC("urshr", ea500f1f, 2, (RRnpcsp, I32), mve_scalar_shift),
26331 ToC("srshr", ea500f2f, 2, (RRnpcsp, I32), mve_scalar_shift),
26332 ToC("sqshl", ea500f3f, 2, (RRnpcsp, I32), mve_scalar_shift),
26333
26334 ToC("vpt", ee410f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26335 ToC("vptt", ee018f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26336 ToC("vpte", ee418f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26337 ToC("vpttt", ee014f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26338 ToC("vptte", ee01cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26339 ToC("vptet", ee41cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26340 ToC("vptee", ee414f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26341 ToC("vptttt", ee012f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26342 ToC("vpttte", ee016f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26343 ToC("vpttet", ee01ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26344 ToC("vpttee", ee01af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26345 ToC("vptett", ee41af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26346 ToC("vptete", ee41ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26347 ToC("vpteet", ee416f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26348 ToC("vpteee", ee412f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26349
26350 ToC("vpst", fe710f4d, 0, (), mve_vpt),
26351 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
26352 ToC("vpste", fe718f4d, 0, (), mve_vpt),
26353 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
26354 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
26355 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
26356 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
26357 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
26358 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
26359 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
26360 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
26361 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
26362 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
26363 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
26364 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
26365
26366 /* MVE and MVE FP only. */
26367 mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd),
26368 mCEF(vctp, _vctp, 1, (RRnpc), mve_vctp),
26369 mCEF(vadc, _vadc, 3, (RMQ, RMQ, RMQ), mve_vadc),
26370 mCEF(vadci, _vadci, 3, (RMQ, RMQ, RMQ), mve_vadc),
26371 mToC("vsbc", fe300f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
26372 mToC("vsbci", fe301f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
26373 mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull),
26374 mCEF(vabav, _vabav, 3, (RRnpcsp, RMQ, RMQ), mve_vabav),
26375 mCEF(vmladav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26376 mCEF(vmladava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26377 mCEF(vmladavx, _vmladavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26378 mCEF(vmladavax, _vmladavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26379 mCEF(vmlav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26380 mCEF(vmlava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26381 mCEF(vmlsdav, _vmlsdav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26382 mCEF(vmlsdava, _vmlsdava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26383 mCEF(vmlsdavx, _vmlsdavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26384 mCEF(vmlsdavax, _vmlsdavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26385
26386 mCEF(vst20, _vst20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26387 mCEF(vst21, _vst21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26388 mCEF(vst40, _vst40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26389 mCEF(vst41, _vst41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26390 mCEF(vst42, _vst42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26391 mCEF(vst43, _vst43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26392 mCEF(vld20, _vld20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26393 mCEF(vld21, _vld21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26394 mCEF(vld40, _vld40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26395 mCEF(vld41, _vld41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26396 mCEF(vld42, _vld42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26397 mCEF(vld43, _vld43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26398 mCEF(vstrb, _vstrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26399 mCEF(vstrh, _vstrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26400 mCEF(vstrw, _vstrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26401 mCEF(vstrd, _vstrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26402 mCEF(vldrb, _vldrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26403 mCEF(vldrh, _vldrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26404 mCEF(vldrw, _vldrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26405 mCEF(vldrd, _vldrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26406
26407 mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn),
26408 mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn),
26409 mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr),
26410 mCEF(vaddlv, _vaddlv, 3, (RRe, RRo, RMQ), mve_vaddlv),
26411 mCEF(vaddlva, _vaddlva, 3, (RRe, RRo, RMQ), mve_vaddlv),
26412 mCEF(vaddv, _vaddv, 2, (RRe, RMQ), mve_vaddv),
26413 mCEF(vaddva, _vaddva, 2, (RRe, RMQ), mve_vaddv),
26414 mCEF(vddup, _vddup, 3, (RMQ, RRe, EXPi), mve_viddup),
26415 mCEF(vdwdup, _vdwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
26416 mCEF(vidup, _vidup, 3, (RMQ, RRe, EXPi), mve_viddup),
26417 mCEF(viwdup, _viwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
26418 mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
26419 mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
26420 mCEF(vmaxv, _vmaxv, 2, (RR, RMQ), mve_vmaxv),
26421 mCEF(vmaxav, _vmaxav, 2, (RR, RMQ), mve_vmaxv),
26422 mCEF(vminv, _vminv, 2, (RR, RMQ), mve_vmaxv),
26423 mCEF(vminav, _vminav, 2, (RR, RMQ), mve_vmaxv),
26424
26425 mCEF(vmlaldav, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26426 mCEF(vmlaldava, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26427 mCEF(vmlaldavx, _vmlaldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26428 mCEF(vmlaldavax, _vmlaldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26429 mCEF(vmlalv, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26430 mCEF(vmlalva, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26431 mCEF(vmlsldav, _vmlsldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26432 mCEF(vmlsldava, _vmlsldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26433 mCEF(vmlsldavx, _vmlsldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26434 mCEF(vmlsldavax, _vmlsldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26435 mToC("vrmlaldavh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26436 mToC("vrmlaldavha",ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26437 mCEF(vrmlaldavhx, _vrmlaldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26438 mCEF(vrmlaldavhax, _vrmlaldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26439 mToC("vrmlalvh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26440 mToC("vrmlalvha", ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26441 mCEF(vrmlsldavh, _vrmlsldavh, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26442 mCEF(vrmlsldavha, _vrmlsldavha, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26443 mCEF(vrmlsldavhx, _vrmlsldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26444 mCEF(vrmlsldavhax, _vrmlsldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26445
26446 mToC("vmlas", ee011e40, 3, (RMQ, RMQ, RR), mve_vmlas),
26447 mToC("vmulh", ee010e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
26448 mToC("vrmulh", ee011e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
26449 mToC("vpnot", fe310f4d, 0, (), mve_vpnot),
26450 mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel),
26451
26452 mToC("vqdmladh", ee000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26453 mToC("vqdmladhx", ee001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26454 mToC("vqrdmladh", ee000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26455 mToC("vqrdmladhx",ee001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26456 mToC("vqdmlsdh", fe000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26457 mToC("vqdmlsdhx", fe001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26458 mToC("vqrdmlsdh", fe000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26459 mToC("vqrdmlsdhx",fe001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26460 mToC("vqdmlah", ee000e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26461 mToC("vqdmlash", ee001e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26462 mToC("vqrdmlash", ee001e40, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26463 mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
26464 mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
26465 mCEF(vqmovnt, _vqmovnt, 2, (RMQ, RMQ), mve_vqmovn),
26466 mCEF(vqmovnb, _vqmovnb, 2, (RMQ, RMQ), mve_vqmovn),
26467 mCEF(vqmovunt, _vqmovunt, 2, (RMQ, RMQ), mve_vqmovn),
26468 mCEF(vqmovunb, _vqmovunb, 2, (RMQ, RMQ), mve_vqmovn),
26469
26470 mCEF(vshrnt, _vshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26471 mCEF(vshrnb, _vshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26472 mCEF(vrshrnt, _vrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26473 mCEF(vrshrnb, _vrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26474 mCEF(vqshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26475 mCEF(vqshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26476 mCEF(vqshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26477 mCEF(vqshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26478 mCEF(vqrshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26479 mCEF(vqrshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26480 mCEF(vqrshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26481 mCEF(vqrshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26482
26483 mToC("vshlc", eea00fc0, 3, (RMQ, RR, I32z), mve_vshlc),
26484 mToC("vshllt", ee201e00, 3, (RMQ, RMQ, I32), mve_vshll),
26485 mToC("vshllb", ee200e00, 3, (RMQ, RMQ, I32), mve_vshll),
26486
26487 toU("dlstp", _dlstp, 2, (LR, RR), t_loloop),
26488 toU("wlstp", _wlstp, 3, (LR, RR, EXP), t_loloop),
26489 toU("letp", _letp, 2, (LR, EXP), t_loloop),
26490 toU("lctp", _lctp, 0, (), t_loloop),
26491
26492 #undef THUMB_VARIANT
26493 #define THUMB_VARIANT & mve_fp_ext
26494 mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul),
26495 mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas),
26496 mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
26497 mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
26498 mToC("vmaxnmv", eeee0f00, 2, (RR, RMQ), mve_vmaxnmv),
26499 mToC("vmaxnmav",eeec0f00, 2, (RR, RMQ), mve_vmaxnmv),
26500 mToC("vminnmv", eeee0f80, 2, (RR, RMQ), mve_vmaxnmv),
26501 mToC("vminnmav",eeec0f80, 2, (RR, RMQ), mve_vmaxnmv),
26502
26503 #undef ARM_VARIANT
26504 #define ARM_VARIANT & fpu_vfp_ext_v1
26505 #undef THUMB_VARIANT
26506 #define THUMB_VARIANT & arm_ext_v6t2
26507 mnCEF(vmla, _vmla, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mac_maybe_scalar),
26508 mnCEF(vmul, _vmul, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mul),
26509
26510 mcCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
26511
26512 #undef ARM_VARIANT
26513 #define ARM_VARIANT & fpu_vfp_ext_v1xd
26514
26515 MNCE(vmov, 0, 1, (VMOV), neon_mov),
26516 mcCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
26517 mcCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
26518 mcCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
26519
26520 mCEF(vmullt, _vmullt, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ), mve_vmull),
26521 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
26522 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
26523
26524 MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26525 MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26526
26527 mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl),
26528 mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl),
26529
26530 mnCE(vcmp, _vcmp, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26531 mnCE(vcmpe, _vcmpe, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26532
26533 #undef ARM_VARIANT
26534 #define ARM_VARIANT & fpu_vfp_ext_v2
26535
26536 mcCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
26537 mcCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
26538 mcCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
26539 mcCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
26540
26541 #undef ARM_VARIANT
26542 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
26543 mnUF(vcvta, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvta),
26544 mnUF(vcvtp, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtp),
26545 mnUF(vcvtn, _vcvta, 3, (RNSDQMQ, oRNSDQMQ, oI32z), neon_cvtn),
26546 mnUF(vcvtm, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtm),
26547 mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
26548 mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
26549
26550 #undef ARM_VARIANT
26551 #define ARM_VARIANT & fpu_neon_ext_v1
26552 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26553 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
26554 mnUF(vaddl, _vaddl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long),
26555 mnUF(vsubl, _vsubl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long),
26556 mnUF(vand, _vand, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26557 mnUF(vbic, _vbic, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26558 mnUF(vorr, _vorr, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26559 mnUF(vorn, _vorn, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26560 mnUF(veor, _veor, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_logic),
26561 MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls),
26562 MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz),
26563 mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup),
26564 MNUF(vhadd, 00000000, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
26565 MNUF(vrhadd, 00000100, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_i_su),
26566 MNUF(vhsub, 00000200, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
26567 mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26568 mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26569 MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
26570 MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
26571 mnUF(vmvn, _vmvn, 2, (RNDQMQ, RNDQMQ_Ibig), neon_mvn),
26572 MNUF(vqabs, 1b00700, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
26573 MNUF(vqneg, 1b00780, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
26574 mnUF(vqrdmlah, _vqrdmlah,3, (RNDQMQ, oRNDQMQ, RNDQ_RNSC_RR), neon_qrdmlah),
26575 mnUF(vqdmulh, _vqdmulh, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
26576 mnUF(vqrdmulh, _vqrdmulh,3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
26577 MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
26578 MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
26579 MNUF(vshr, 0800010, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26580 MNUF(vrshr, 0800210, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26581 MNUF(vsli, 1800510, 3, (RNDQMQ, oRNDQMQ, I63), neon_sli),
26582 MNUF(vsri, 1800410, 3, (RNDQMQ, oRNDQMQ, I64z), neon_sri),
26583 MNUF(vrev64, 1b00000, 2, (RNDQMQ, RNDQMQ), neon_rev),
26584 MNUF(vrev32, 1b00080, 2, (RNDQMQ, RNDQMQ), neon_rev),
26585 MNUF(vrev16, 1b00100, 2, (RNDQMQ, RNDQMQ), neon_rev),
26586 mnUF(vshl, _vshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_shl),
26587 mnUF(vqshl, _vqshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_qshl),
26588 MNUF(vqshlu, 1800610, 3, (RNDQMQ, oRNDQMQ, I63), neon_qshlu_imm),
26589
26590 #undef ARM_VARIANT
26591 #define ARM_VARIANT & arm_ext_v8_3
26592 #undef THUMB_VARIANT
26593 #define THUMB_VARIANT & arm_ext_v6t2_v8m
26594 MNUF (vcadd, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ, EXPi), vcadd),
26595 MNUF (vcmla, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ_RNSC, EXPi), vcmla),
26596
26597 #undef ARM_VARIANT
26598 #define ARM_VARIANT &arm_ext_bf16
26599 #undef THUMB_VARIANT
26600 #define THUMB_VARIANT &arm_ext_bf16
26601 TUF ("vdot", c000d00, fc000d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vdot, vdot),
26602 TUF ("vmmla", c000c40, fc000c40, 3, (RNQ, RNQ, RNQ), vmmla, vmmla),
26603 TUF ("vfmab", c300810, fc300810, 3, (RNDQ, RNDQ, RNDQ_RNSC), bfloat_vfma, bfloat_vfma),
26604
26605 #undef ARM_VARIANT
26606 #define ARM_VARIANT &arm_ext_i8mm
26607 #undef THUMB_VARIANT
26608 #define THUMB_VARIANT &arm_ext_i8mm
26609 TUF ("vsmmla", c200c40, fc200c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
26610 TUF ("vummla", c200c50, fc200c50, 3, (RNQ, RNQ, RNQ), vummla, vummla),
26611 TUF ("vusmmla", ca00c40, fca00c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
26612 TUF ("vusdot", c800d00, fc800d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vusdot, vusdot),
26613 TUF ("vsudot", c800d10, fc800d10, 3, (RNDQ, RNDQ, RNSC), vsudot, vsudot),
26614
26615 #undef ARM_VARIANT
26616 #undef THUMB_VARIANT
26617 #define THUMB_VARIANT &arm_ext_cde
26618 ToC ("cx1", ee000000, 3, (RCP, APSR_RR, I8191), cx1),
26619 ToC ("cx1a", fe000000, 3, (RCP, APSR_RR, I8191), cx1a),
26620 ToC ("cx1d", ee000040, 4, (RCP, RR, APSR_RR, I8191), cx1d),
26621 ToC ("cx1da", fe000040, 4, (RCP, RR, APSR_RR, I8191), cx1da),
26622
26623 ToC ("cx2", ee400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2),
26624 ToC ("cx2a", fe400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2a),
26625 ToC ("cx2d", ee400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2d),
26626 ToC ("cx2da", fe400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2da),
26627
26628 ToC ("cx3", ee800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3),
26629 ToC ("cx3a", fe800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3a),
26630 ToC ("cx3d", ee800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3d),
26631 ToC ("cx3da", fe800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3da),
26632
26633 mToC ("vcx1", ec200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26634 mToC ("vcx1a", fc200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26635
26636 mToC ("vcx2", ec300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26637 mToC ("vcx2a", fc300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26638
26639 mToC ("vcx3", ec800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
26640 mToC ("vcx3a", fc800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
26641 };
26642
26643 #undef ARM_VARIANT
26644 #undef THUMB_VARIANT
26645 #undef TCE
26646 #undef TUE
26647 #undef TUF
26648 #undef TCC
26649 #undef cCE
26650 #undef cCL
26651 #undef C3E
26652 #undef C3
26653 #undef CE
26654 #undef CM
26655 #undef CL
26656 #undef UE
26657 #undef UF
26658 #undef UT
26659 #undef NUF
26660 #undef nUF
26661 #undef NCE
26662 #undef nCE
26663 #undef OPS0
26664 #undef OPS1
26665 #undef OPS2
26666 #undef OPS3
26667 #undef OPS4
26668 #undef OPS5
26669 #undef OPS6
26670 #undef do_0
26671 #undef ToC
26672 #undef toC
26673 #undef ToU
26674 #undef toU
26675 \f
26676 /* MD interface: bits in the object file. */
26677
26678 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
26679 for use in the a.out file, and stores them in the array pointed to by buf.
26680 This knows about the endian-ness of the target machine and does
26681 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
26682 2 (short) and 4 (long) Floating numbers are put out as a series of
26683 LITTLENUMS (shorts, here at least). */
26684
26685 void
26686 md_number_to_chars (char * buf, valueT val, int n)
26687 {
26688 if (target_big_endian)
26689 number_to_chars_bigendian (buf, val, n);
26690 else
26691 number_to_chars_littleendian (buf, val, n);
26692 }
26693
26694 static valueT
26695 md_chars_to_number (char * buf, int n)
26696 {
26697 valueT result = 0;
26698 unsigned char * where = (unsigned char *) buf;
26699
26700 if (target_big_endian)
26701 {
26702 while (n--)
26703 {
26704 result <<= 8;
26705 result |= (*where++ & 255);
26706 }
26707 }
26708 else
26709 {
26710 while (n--)
26711 {
26712 result <<= 8;
26713 result |= (where[n] & 255);
26714 }
26715 }
26716
26717 return result;
26718 }
26719
26720 /* MD interface: Sections. */
26721
26722 /* Calculate the maximum variable size (i.e., excluding fr_fix)
26723 that an rs_machine_dependent frag may reach. */
26724
26725 unsigned int
26726 arm_frag_max_var (fragS *fragp)
26727 {
26728 /* We only use rs_machine_dependent for variable-size Thumb instructions,
26729 which are either THUMB_SIZE (2) or INSN_SIZE (4).
26730
26731 Note that we generate relaxable instructions even for cases that don't
26732 really need it, like an immediate that's a trivial constant. So we're
26733 overestimating the instruction size for some of those cases. Rather
26734 than putting more intelligence here, it would probably be better to
26735 avoid generating a relaxation frag in the first place when it can be
26736 determined up front that a short instruction will suffice. */
26737
26738 gas_assert (fragp->fr_type == rs_machine_dependent);
26739 return INSN_SIZE;
26740 }
26741
26742 /* Estimate the size of a frag before relaxing. Assume everything fits in
26743 2 bytes. */
26744
26745 int
26746 md_estimate_size_before_relax (fragS * fragp,
26747 segT segtype ATTRIBUTE_UNUSED)
26748 {
26749 fragp->fr_var = 2;
26750 return 2;
26751 }
26752
26753 /* Convert a machine dependent frag. */
26754
26755 void
26756 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
26757 {
26758 unsigned long insn;
26759 unsigned long old_op;
26760 char *buf;
26761 expressionS exp;
26762 fixS *fixp;
26763 int reloc_type;
26764 int pc_rel;
26765 int opcode;
26766
26767 buf = fragp->fr_literal + fragp->fr_fix;
26768
26769 old_op = bfd_get_16(abfd, buf);
26770 if (fragp->fr_symbol)
26771 {
26772 exp.X_op = O_symbol;
26773 exp.X_add_symbol = fragp->fr_symbol;
26774 }
26775 else
26776 {
26777 exp.X_op = O_constant;
26778 }
26779 exp.X_add_number = fragp->fr_offset;
26780 opcode = fragp->fr_subtype;
26781 switch (opcode)
26782 {
26783 case T_MNEM_ldr_pc:
26784 case T_MNEM_ldr_pc2:
26785 case T_MNEM_ldr_sp:
26786 case T_MNEM_str_sp:
26787 case T_MNEM_ldr:
26788 case T_MNEM_ldrb:
26789 case T_MNEM_ldrh:
26790 case T_MNEM_str:
26791 case T_MNEM_strb:
26792 case T_MNEM_strh:
26793 if (fragp->fr_var == 4)
26794 {
26795 insn = THUMB_OP32 (opcode);
26796 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
26797 {
26798 insn |= (old_op & 0x700) << 4;
26799 }
26800 else
26801 {
26802 insn |= (old_op & 7) << 12;
26803 insn |= (old_op & 0x38) << 13;
26804 }
26805 insn |= 0x00000c00;
26806 put_thumb32_insn (buf, insn);
26807 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
26808 }
26809 else
26810 {
26811 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
26812 }
26813 pc_rel = (opcode == T_MNEM_ldr_pc2);
26814 break;
26815 case T_MNEM_adr:
26816 if (fragp->fr_var == 4)
26817 {
26818 insn = THUMB_OP32 (opcode);
26819 insn |= (old_op & 0xf0) << 4;
26820 put_thumb32_insn (buf, insn);
26821 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
26822 }
26823 else
26824 {
26825 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26826 exp.X_add_number -= 4;
26827 }
26828 pc_rel = 1;
26829 break;
26830 case T_MNEM_mov:
26831 case T_MNEM_movs:
26832 case T_MNEM_cmp:
26833 case T_MNEM_cmn:
26834 if (fragp->fr_var == 4)
26835 {
26836 int r0off = (opcode == T_MNEM_mov
26837 || opcode == T_MNEM_movs) ? 0 : 8;
26838 insn = THUMB_OP32 (opcode);
26839 insn = (insn & 0xe1ffffff) | 0x10000000;
26840 insn |= (old_op & 0x700) << r0off;
26841 put_thumb32_insn (buf, insn);
26842 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26843 }
26844 else
26845 {
26846 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
26847 }
26848 pc_rel = 0;
26849 break;
26850 case T_MNEM_b:
26851 if (fragp->fr_var == 4)
26852 {
26853 insn = THUMB_OP32(opcode);
26854 put_thumb32_insn (buf, insn);
26855 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
26856 }
26857 else
26858 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
26859 pc_rel = 1;
26860 break;
26861 case T_MNEM_bcond:
26862 if (fragp->fr_var == 4)
26863 {
26864 insn = THUMB_OP32(opcode);
26865 insn |= (old_op & 0xf00) << 14;
26866 put_thumb32_insn (buf, insn);
26867 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
26868 }
26869 else
26870 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
26871 pc_rel = 1;
26872 break;
26873 case T_MNEM_add_sp:
26874 case T_MNEM_add_pc:
26875 case T_MNEM_inc_sp:
26876 case T_MNEM_dec_sp:
26877 if (fragp->fr_var == 4)
26878 {
26879 /* ??? Choose between add and addw. */
26880 insn = THUMB_OP32 (opcode);
26881 insn |= (old_op & 0xf0) << 4;
26882 put_thumb32_insn (buf, insn);
26883 if (opcode == T_MNEM_add_pc)
26884 reloc_type = BFD_RELOC_ARM_T32_IMM12;
26885 else
26886 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26887 }
26888 else
26889 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26890 pc_rel = 0;
26891 break;
26892
26893 case T_MNEM_addi:
26894 case T_MNEM_addis:
26895 case T_MNEM_subi:
26896 case T_MNEM_subis:
26897 if (fragp->fr_var == 4)
26898 {
26899 insn = THUMB_OP32 (opcode);
26900 insn |= (old_op & 0xf0) << 4;
26901 insn |= (old_op & 0xf) << 16;
26902 put_thumb32_insn (buf, insn);
26903 if (insn & (1 << 20))
26904 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26905 else
26906 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26907 }
26908 else
26909 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26910 pc_rel = 0;
26911 break;
26912 default:
26913 abort ();
26914 }
26915 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
26916 (enum bfd_reloc_code_real) reloc_type);
26917 fixp->fx_file = fragp->fr_file;
26918 fixp->fx_line = fragp->fr_line;
26919 fragp->fr_fix += fragp->fr_var;
26920
26921 /* Set whether we use thumb-2 ISA based on final relaxation results. */
26922 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
26923 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
26924 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
26925 }
26926
26927 /* Return the size of a relaxable immediate operand instruction.
26928 SHIFT and SIZE specify the form of the allowable immediate. */
26929 static int
26930 relax_immediate (fragS *fragp, int size, int shift)
26931 {
26932 offsetT offset;
26933 offsetT mask;
26934 offsetT low;
26935
26936 /* ??? Should be able to do better than this. */
26937 if (fragp->fr_symbol)
26938 return 4;
26939
26940 low = (1 << shift) - 1;
26941 mask = (1 << (shift + size)) - (1 << shift);
26942 offset = fragp->fr_offset;
26943 /* Force misaligned offsets to 32-bit variant. */
26944 if (offset & low)
26945 return 4;
26946 if (offset & ~mask)
26947 return 4;
26948 return 2;
26949 }
26950
26951 /* Get the address of a symbol during relaxation. */
26952 static addressT
26953 relaxed_symbol_addr (fragS *fragp, long stretch)
26954 {
26955 fragS *sym_frag;
26956 addressT addr;
26957 symbolS *sym;
26958
26959 sym = fragp->fr_symbol;
26960 sym_frag = symbol_get_frag (sym);
26961 know (S_GET_SEGMENT (sym) != absolute_section
26962 || sym_frag == &zero_address_frag);
26963 addr = S_GET_VALUE (sym) + fragp->fr_offset;
26964
26965 /* If frag has yet to be reached on this pass, assume it will
26966 move by STRETCH just as we did. If this is not so, it will
26967 be because some frag between grows, and that will force
26968 another pass. */
26969
26970 if (stretch != 0
26971 && sym_frag->relax_marker != fragp->relax_marker)
26972 {
26973 fragS *f;
26974
26975 /* Adjust stretch for any alignment frag. Note that if have
26976 been expanding the earlier code, the symbol may be
26977 defined in what appears to be an earlier frag. FIXME:
26978 This doesn't handle the fr_subtype field, which specifies
26979 a maximum number of bytes to skip when doing an
26980 alignment. */
26981 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
26982 {
26983 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
26984 {
26985 if (stretch < 0)
26986 stretch = - ((- stretch)
26987 & ~ ((1 << (int) f->fr_offset) - 1));
26988 else
26989 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
26990 if (stretch == 0)
26991 break;
26992 }
26993 }
26994 if (f != NULL)
26995 addr += stretch;
26996 }
26997
26998 return addr;
26999 }
27000
27001 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
27002 load. */
27003 static int
27004 relax_adr (fragS *fragp, asection *sec, long stretch)
27005 {
27006 addressT addr;
27007 offsetT val;
27008
27009 /* Assume worst case for symbols not known to be in the same section. */
27010 if (fragp->fr_symbol == NULL
27011 || !S_IS_DEFINED (fragp->fr_symbol)
27012 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27013 || S_IS_WEAK (fragp->fr_symbol))
27014 return 4;
27015
27016 val = relaxed_symbol_addr (fragp, stretch);
27017 addr = fragp->fr_address + fragp->fr_fix;
27018 addr = (addr + 4) & ~3;
27019 /* Force misaligned targets to 32-bit variant. */
27020 if (val & 3)
27021 return 4;
27022 val -= addr;
27023 if (val < 0 || val > 1020)
27024 return 4;
27025 return 2;
27026 }
27027
27028 /* Return the size of a relaxable add/sub immediate instruction. */
27029 static int
27030 relax_addsub (fragS *fragp, asection *sec)
27031 {
27032 char *buf;
27033 int op;
27034
27035 buf = fragp->fr_literal + fragp->fr_fix;
27036 op = bfd_get_16(sec->owner, buf);
27037 if ((op & 0xf) == ((op >> 4) & 0xf))
27038 return relax_immediate (fragp, 8, 0);
27039 else
27040 return relax_immediate (fragp, 3, 0);
27041 }
27042
27043 /* Return TRUE iff the definition of symbol S could be pre-empted
27044 (overridden) at link or load time. */
27045 static bfd_boolean
27046 symbol_preemptible (symbolS *s)
27047 {
27048 /* Weak symbols can always be pre-empted. */
27049 if (S_IS_WEAK (s))
27050 return TRUE;
27051
27052 /* Non-global symbols cannot be pre-empted. */
27053 if (! S_IS_EXTERNAL (s))
27054 return FALSE;
27055
27056 #ifdef OBJ_ELF
27057 /* In ELF, a global symbol can be marked protected, or private. In that
27058 case it can't be pre-empted (other definitions in the same link unit
27059 would violate the ODR). */
27060 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
27061 return FALSE;
27062 #endif
27063
27064 /* Other global symbols might be pre-empted. */
27065 return TRUE;
27066 }
27067
27068 /* Return the size of a relaxable branch instruction. BITS is the
27069 size of the offset field in the narrow instruction. */
27070
27071 static int
27072 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
27073 {
27074 addressT addr;
27075 offsetT val;
27076 offsetT limit;
27077
27078 /* Assume worst case for symbols not known to be in the same section. */
27079 if (!S_IS_DEFINED (fragp->fr_symbol)
27080 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27081 || S_IS_WEAK (fragp->fr_symbol))
27082 return 4;
27083
27084 #ifdef OBJ_ELF
27085 /* A branch to a function in ARM state will require interworking. */
27086 if (S_IS_DEFINED (fragp->fr_symbol)
27087 && ARM_IS_FUNC (fragp->fr_symbol))
27088 return 4;
27089 #endif
27090
27091 if (symbol_preemptible (fragp->fr_symbol))
27092 return 4;
27093
27094 val = relaxed_symbol_addr (fragp, stretch);
27095 addr = fragp->fr_address + fragp->fr_fix + 4;
27096 val -= addr;
27097
27098 /* Offset is a signed value *2 */
27099 limit = 1 << bits;
27100 if (val >= limit || val < -limit)
27101 return 4;
27102 return 2;
27103 }
27104
27105
27106 /* Relax a machine dependent frag. This returns the amount by which
27107 the current size of the frag should change. */
27108
27109 int
27110 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
27111 {
27112 int oldsize;
27113 int newsize;
27114
27115 oldsize = fragp->fr_var;
27116 switch (fragp->fr_subtype)
27117 {
27118 case T_MNEM_ldr_pc2:
27119 newsize = relax_adr (fragp, sec, stretch);
27120 break;
27121 case T_MNEM_ldr_pc:
27122 case T_MNEM_ldr_sp:
27123 case T_MNEM_str_sp:
27124 newsize = relax_immediate (fragp, 8, 2);
27125 break;
27126 case T_MNEM_ldr:
27127 case T_MNEM_str:
27128 newsize = relax_immediate (fragp, 5, 2);
27129 break;
27130 case T_MNEM_ldrh:
27131 case T_MNEM_strh:
27132 newsize = relax_immediate (fragp, 5, 1);
27133 break;
27134 case T_MNEM_ldrb:
27135 case T_MNEM_strb:
27136 newsize = relax_immediate (fragp, 5, 0);
27137 break;
27138 case T_MNEM_adr:
27139 newsize = relax_adr (fragp, sec, stretch);
27140 break;
27141 case T_MNEM_mov:
27142 case T_MNEM_movs:
27143 case T_MNEM_cmp:
27144 case T_MNEM_cmn:
27145 newsize = relax_immediate (fragp, 8, 0);
27146 break;
27147 case T_MNEM_b:
27148 newsize = relax_branch (fragp, sec, 11, stretch);
27149 break;
27150 case T_MNEM_bcond:
27151 newsize = relax_branch (fragp, sec, 8, stretch);
27152 break;
27153 case T_MNEM_add_sp:
27154 case T_MNEM_add_pc:
27155 newsize = relax_immediate (fragp, 8, 2);
27156 break;
27157 case T_MNEM_inc_sp:
27158 case T_MNEM_dec_sp:
27159 newsize = relax_immediate (fragp, 7, 2);
27160 break;
27161 case T_MNEM_addi:
27162 case T_MNEM_addis:
27163 case T_MNEM_subi:
27164 case T_MNEM_subis:
27165 newsize = relax_addsub (fragp, sec);
27166 break;
27167 default:
27168 abort ();
27169 }
27170
27171 fragp->fr_var = newsize;
27172 /* Freeze wide instructions that are at or before the same location as
27173 in the previous pass. This avoids infinite loops.
27174 Don't freeze them unconditionally because targets may be artificially
27175 misaligned by the expansion of preceding frags. */
27176 if (stretch <= 0 && newsize > 2)
27177 {
27178 md_convert_frag (sec->owner, sec, fragp);
27179 frag_wane (fragp);
27180 }
27181
27182 return newsize - oldsize;
27183 }
27184
27185 /* Round up a section size to the appropriate boundary. */
27186
27187 valueT
27188 md_section_align (segT segment ATTRIBUTE_UNUSED,
27189 valueT size)
27190 {
27191 return size;
27192 }
27193
27194 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
27195 of an rs_align_code fragment. */
27196
27197 void
27198 arm_handle_align (fragS * fragP)
27199 {
27200 static unsigned char const arm_noop[2][2][4] =
27201 {
27202 { /* ARMv1 */
27203 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
27204 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
27205 },
27206 { /* ARMv6k */
27207 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
27208 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
27209 },
27210 };
27211 static unsigned char const thumb_noop[2][2][2] =
27212 {
27213 { /* Thumb-1 */
27214 {0xc0, 0x46}, /* LE */
27215 {0x46, 0xc0}, /* BE */
27216 },
27217 { /* Thumb-2 */
27218 {0x00, 0xbf}, /* LE */
27219 {0xbf, 0x00} /* BE */
27220 }
27221 };
27222 static unsigned char const wide_thumb_noop[2][4] =
27223 { /* Wide Thumb-2 */
27224 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
27225 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
27226 };
27227
27228 unsigned bytes, fix, noop_size;
27229 char * p;
27230 const unsigned char * noop;
27231 const unsigned char *narrow_noop = NULL;
27232 #ifdef OBJ_ELF
27233 enum mstate state;
27234 #endif
27235
27236 if (fragP->fr_type != rs_align_code)
27237 return;
27238
27239 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
27240 p = fragP->fr_literal + fragP->fr_fix;
27241 fix = 0;
27242
27243 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
27244 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
27245
27246 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
27247
27248 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
27249 {
27250 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27251 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
27252 {
27253 narrow_noop = thumb_noop[1][target_big_endian];
27254 noop = wide_thumb_noop[target_big_endian];
27255 }
27256 else
27257 noop = thumb_noop[0][target_big_endian];
27258 noop_size = 2;
27259 #ifdef OBJ_ELF
27260 state = MAP_THUMB;
27261 #endif
27262 }
27263 else
27264 {
27265 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27266 ? selected_cpu : arm_arch_none,
27267 arm_ext_v6k) != 0]
27268 [target_big_endian];
27269 noop_size = 4;
27270 #ifdef OBJ_ELF
27271 state = MAP_ARM;
27272 #endif
27273 }
27274
27275 fragP->fr_var = noop_size;
27276
27277 if (bytes & (noop_size - 1))
27278 {
27279 fix = bytes & (noop_size - 1);
27280 #ifdef OBJ_ELF
27281 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
27282 #endif
27283 memset (p, 0, fix);
27284 p += fix;
27285 bytes -= fix;
27286 }
27287
27288 if (narrow_noop)
27289 {
27290 if (bytes & noop_size)
27291 {
27292 /* Insert a narrow noop. */
27293 memcpy (p, narrow_noop, noop_size);
27294 p += noop_size;
27295 bytes -= noop_size;
27296 fix += noop_size;
27297 }
27298
27299 /* Use wide noops for the remainder */
27300 noop_size = 4;
27301 }
27302
27303 while (bytes >= noop_size)
27304 {
27305 memcpy (p, noop, noop_size);
27306 p += noop_size;
27307 bytes -= noop_size;
27308 fix += noop_size;
27309 }
27310
27311 fragP->fr_fix += fix;
27312 }
27313
27314 /* Called from md_do_align. Used to create an alignment
27315 frag in a code section. */
27316
27317 void
27318 arm_frag_align_code (int n, int max)
27319 {
27320 char * p;
27321
27322 /* We assume that there will never be a requirement
27323 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
27324 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
27325 {
27326 char err_msg[128];
27327
27328 sprintf (err_msg,
27329 _("alignments greater than %d bytes not supported in .text sections."),
27330 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
27331 as_fatal ("%s", err_msg);
27332 }
27333
27334 p = frag_var (rs_align_code,
27335 MAX_MEM_FOR_RS_ALIGN_CODE,
27336 1,
27337 (relax_substateT) max,
27338 (symbolS *) NULL,
27339 (offsetT) n,
27340 (char *) NULL);
27341 *p = 0;
27342 }
27343
27344 /* Perform target specific initialisation of a frag.
27345 Note - despite the name this initialisation is not done when the frag
27346 is created, but only when its type is assigned. A frag can be created
27347 and used a long time before its type is set, so beware of assuming that
27348 this initialisation is performed first. */
27349
27350 #ifndef OBJ_ELF
27351 void
27352 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
27353 {
27354 /* Record whether this frag is in an ARM or a THUMB area. */
27355 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
27356 }
27357
27358 #else /* OBJ_ELF is defined. */
27359 void
27360 arm_init_frag (fragS * fragP, int max_chars)
27361 {
27362 bfd_boolean frag_thumb_mode;
27363
27364 /* If the current ARM vs THUMB mode has not already
27365 been recorded into this frag then do so now. */
27366 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
27367 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
27368
27369 /* PR 21809: Do not set a mapping state for debug sections
27370 - it just confuses other tools. */
27371 if (bfd_section_flags (now_seg) & SEC_DEBUGGING)
27372 return;
27373
27374 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
27375
27376 /* Record a mapping symbol for alignment frags. We will delete this
27377 later if the alignment ends up empty. */
27378 switch (fragP->fr_type)
27379 {
27380 case rs_align:
27381 case rs_align_test:
27382 case rs_fill:
27383 mapping_state_2 (MAP_DATA, max_chars);
27384 break;
27385 case rs_align_code:
27386 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
27387 break;
27388 default:
27389 break;
27390 }
27391 }
27392
27393 /* When we change sections we need to issue a new mapping symbol. */
27394
27395 void
27396 arm_elf_change_section (void)
27397 {
27398 /* Link an unlinked unwind index table section to the .text section. */
27399 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
27400 && elf_linked_to_section (now_seg) == NULL)
27401 elf_linked_to_section (now_seg) = text_section;
27402 }
27403
27404 int
27405 arm_elf_section_type (const char * str, size_t len)
27406 {
27407 if (len == 5 && strncmp (str, "exidx", 5) == 0)
27408 return SHT_ARM_EXIDX;
27409
27410 return -1;
27411 }
27412 \f
27413 /* Code to deal with unwinding tables. */
27414
27415 static void add_unwind_adjustsp (offsetT);
27416
27417 /* Generate any deferred unwind frame offset. */
27418
27419 static void
27420 flush_pending_unwind (void)
27421 {
27422 offsetT offset;
27423
27424 offset = unwind.pending_offset;
27425 unwind.pending_offset = 0;
27426 if (offset != 0)
27427 add_unwind_adjustsp (offset);
27428 }
27429
27430 /* Add an opcode to this list for this function. Two-byte opcodes should
27431 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
27432 order. */
27433
27434 static void
27435 add_unwind_opcode (valueT op, int length)
27436 {
27437 /* Add any deferred stack adjustment. */
27438 if (unwind.pending_offset)
27439 flush_pending_unwind ();
27440
27441 unwind.sp_restored = 0;
27442
27443 if (unwind.opcode_count + length > unwind.opcode_alloc)
27444 {
27445 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
27446 if (unwind.opcodes)
27447 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
27448 unwind.opcode_alloc);
27449 else
27450 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
27451 }
27452 while (length > 0)
27453 {
27454 length--;
27455 unwind.opcodes[unwind.opcode_count] = op & 0xff;
27456 op >>= 8;
27457 unwind.opcode_count++;
27458 }
27459 }
27460
27461 /* Add unwind opcodes to adjust the stack pointer. */
27462
27463 static void
27464 add_unwind_adjustsp (offsetT offset)
27465 {
27466 valueT op;
27467
27468 if (offset > 0x200)
27469 {
27470 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
27471 char bytes[5];
27472 int n;
27473 valueT o;
27474
27475 /* Long form: 0xb2, uleb128. */
27476 /* This might not fit in a word so add the individual bytes,
27477 remembering the list is built in reverse order. */
27478 o = (valueT) ((offset - 0x204) >> 2);
27479 if (o == 0)
27480 add_unwind_opcode (0, 1);
27481
27482 /* Calculate the uleb128 encoding of the offset. */
27483 n = 0;
27484 while (o)
27485 {
27486 bytes[n] = o & 0x7f;
27487 o >>= 7;
27488 if (o)
27489 bytes[n] |= 0x80;
27490 n++;
27491 }
27492 /* Add the insn. */
27493 for (; n; n--)
27494 add_unwind_opcode (bytes[n - 1], 1);
27495 add_unwind_opcode (0xb2, 1);
27496 }
27497 else if (offset > 0x100)
27498 {
27499 /* Two short opcodes. */
27500 add_unwind_opcode (0x3f, 1);
27501 op = (offset - 0x104) >> 2;
27502 add_unwind_opcode (op, 1);
27503 }
27504 else if (offset > 0)
27505 {
27506 /* Short opcode. */
27507 op = (offset - 4) >> 2;
27508 add_unwind_opcode (op, 1);
27509 }
27510 else if (offset < 0)
27511 {
27512 offset = -offset;
27513 while (offset > 0x100)
27514 {
27515 add_unwind_opcode (0x7f, 1);
27516 offset -= 0x100;
27517 }
27518 op = ((offset - 4) >> 2) | 0x40;
27519 add_unwind_opcode (op, 1);
27520 }
27521 }
27522
27523 /* Finish the list of unwind opcodes for this function. */
27524
27525 static void
27526 finish_unwind_opcodes (void)
27527 {
27528 valueT op;
27529
27530 if (unwind.fp_used)
27531 {
27532 /* Adjust sp as necessary. */
27533 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
27534 flush_pending_unwind ();
27535
27536 /* After restoring sp from the frame pointer. */
27537 op = 0x90 | unwind.fp_reg;
27538 add_unwind_opcode (op, 1);
27539 }
27540 else
27541 flush_pending_unwind ();
27542 }
27543
27544
27545 /* Start an exception table entry. If idx is nonzero this is an index table
27546 entry. */
27547
27548 static void
27549 start_unwind_section (const segT text_seg, int idx)
27550 {
27551 const char * text_name;
27552 const char * prefix;
27553 const char * prefix_once;
27554 struct elf_section_match match;
27555 char * sec_name;
27556 int type;
27557 int flags;
27558 int linkonce;
27559
27560 if (idx)
27561 {
27562 prefix = ELF_STRING_ARM_unwind;
27563 prefix_once = ELF_STRING_ARM_unwind_once;
27564 type = SHT_ARM_EXIDX;
27565 }
27566 else
27567 {
27568 prefix = ELF_STRING_ARM_unwind_info;
27569 prefix_once = ELF_STRING_ARM_unwind_info_once;
27570 type = SHT_PROGBITS;
27571 }
27572
27573 text_name = segment_name (text_seg);
27574 if (streq (text_name, ".text"))
27575 text_name = "";
27576
27577 if (strncmp (text_name, ".gnu.linkonce.t.",
27578 strlen (".gnu.linkonce.t.")) == 0)
27579 {
27580 prefix = prefix_once;
27581 text_name += strlen (".gnu.linkonce.t.");
27582 }
27583
27584 sec_name = concat (prefix, text_name, (char *) NULL);
27585
27586 flags = SHF_ALLOC;
27587 linkonce = 0;
27588 memset (&match, 0, sizeof (match));
27589
27590 /* Handle COMDAT group. */
27591 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
27592 {
27593 match.group_name = elf_group_name (text_seg);
27594 if (match.group_name == NULL)
27595 {
27596 as_bad (_("Group section `%s' has no group signature"),
27597 segment_name (text_seg));
27598 ignore_rest_of_line ();
27599 return;
27600 }
27601 flags |= SHF_GROUP;
27602 linkonce = 1;
27603 }
27604
27605 obj_elf_change_section (sec_name, type, flags, 0, &match,
27606 linkonce, 0);
27607
27608 /* Set the section link for index tables. */
27609 if (idx)
27610 elf_linked_to_section (now_seg) = text_seg;
27611 }
27612
27613
27614 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
27615 personality routine data. Returns zero, or the index table value for
27616 an inline entry. */
27617
27618 static valueT
27619 create_unwind_entry (int have_data)
27620 {
27621 int size;
27622 addressT where;
27623 char *ptr;
27624 /* The current word of data. */
27625 valueT data;
27626 /* The number of bytes left in this word. */
27627 int n;
27628
27629 finish_unwind_opcodes ();
27630
27631 /* Remember the current text section. */
27632 unwind.saved_seg = now_seg;
27633 unwind.saved_subseg = now_subseg;
27634
27635 start_unwind_section (now_seg, 0);
27636
27637 if (unwind.personality_routine == NULL)
27638 {
27639 if (unwind.personality_index == -2)
27640 {
27641 if (have_data)
27642 as_bad (_("handlerdata in cantunwind frame"));
27643 return 1; /* EXIDX_CANTUNWIND. */
27644 }
27645
27646 /* Use a default personality routine if none is specified. */
27647 if (unwind.personality_index == -1)
27648 {
27649 if (unwind.opcode_count > 3)
27650 unwind.personality_index = 1;
27651 else
27652 unwind.personality_index = 0;
27653 }
27654
27655 /* Space for the personality routine entry. */
27656 if (unwind.personality_index == 0)
27657 {
27658 if (unwind.opcode_count > 3)
27659 as_bad (_("too many unwind opcodes for personality routine 0"));
27660
27661 if (!have_data)
27662 {
27663 /* All the data is inline in the index table. */
27664 data = 0x80;
27665 n = 3;
27666 while (unwind.opcode_count > 0)
27667 {
27668 unwind.opcode_count--;
27669 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27670 n--;
27671 }
27672
27673 /* Pad with "finish" opcodes. */
27674 while (n--)
27675 data = (data << 8) | 0xb0;
27676
27677 return data;
27678 }
27679 size = 0;
27680 }
27681 else
27682 /* We get two opcodes "free" in the first word. */
27683 size = unwind.opcode_count - 2;
27684 }
27685 else
27686 {
27687 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
27688 if (unwind.personality_index != -1)
27689 {
27690 as_bad (_("attempt to recreate an unwind entry"));
27691 return 1;
27692 }
27693
27694 /* An extra byte is required for the opcode count. */
27695 size = unwind.opcode_count + 1;
27696 }
27697
27698 size = (size + 3) >> 2;
27699 if (size > 0xff)
27700 as_bad (_("too many unwind opcodes"));
27701
27702 frag_align (2, 0, 0);
27703 record_alignment (now_seg, 2);
27704 unwind.table_entry = expr_build_dot ();
27705
27706 /* Allocate the table entry. */
27707 ptr = frag_more ((size << 2) + 4);
27708 /* PR 13449: Zero the table entries in case some of them are not used. */
27709 memset (ptr, 0, (size << 2) + 4);
27710 where = frag_now_fix () - ((size << 2) + 4);
27711
27712 switch (unwind.personality_index)
27713 {
27714 case -1:
27715 /* ??? Should this be a PLT generating relocation? */
27716 /* Custom personality routine. */
27717 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
27718 BFD_RELOC_ARM_PREL31);
27719
27720 where += 4;
27721 ptr += 4;
27722
27723 /* Set the first byte to the number of additional words. */
27724 data = size > 0 ? size - 1 : 0;
27725 n = 3;
27726 break;
27727
27728 /* ABI defined personality routines. */
27729 case 0:
27730 /* Three opcodes bytes are packed into the first word. */
27731 data = 0x80;
27732 n = 3;
27733 break;
27734
27735 case 1:
27736 case 2:
27737 /* The size and first two opcode bytes go in the first word. */
27738 data = ((0x80 + unwind.personality_index) << 8) | size;
27739 n = 2;
27740 break;
27741
27742 default:
27743 /* Should never happen. */
27744 abort ();
27745 }
27746
27747 /* Pack the opcodes into words (MSB first), reversing the list at the same
27748 time. */
27749 while (unwind.opcode_count > 0)
27750 {
27751 if (n == 0)
27752 {
27753 md_number_to_chars (ptr, data, 4);
27754 ptr += 4;
27755 n = 4;
27756 data = 0;
27757 }
27758 unwind.opcode_count--;
27759 n--;
27760 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27761 }
27762
27763 /* Finish off the last word. */
27764 if (n < 4)
27765 {
27766 /* Pad with "finish" opcodes. */
27767 while (n--)
27768 data = (data << 8) | 0xb0;
27769
27770 md_number_to_chars (ptr, data, 4);
27771 }
27772
27773 if (!have_data)
27774 {
27775 /* Add an empty descriptor if there is no user-specified data. */
27776 ptr = frag_more (4);
27777 md_number_to_chars (ptr, 0, 4);
27778 }
27779
27780 return 0;
27781 }
27782
27783
27784 /* Initialize the DWARF-2 unwind information for this procedure. */
27785
27786 void
27787 tc_arm_frame_initial_instructions (void)
27788 {
27789 cfi_add_CFA_def_cfa (REG_SP, 0);
27790 }
27791 #endif /* OBJ_ELF */
27792
27793 /* Convert REGNAME to a DWARF-2 register number. */
27794
27795 int
27796 tc_arm_regname_to_dw2regnum (char *regname)
27797 {
27798 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
27799 if (reg != FAIL)
27800 return reg;
27801
27802 /* PR 16694: Allow VFP registers as well. */
27803 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
27804 if (reg != FAIL)
27805 return 64 + reg;
27806
27807 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
27808 if (reg != FAIL)
27809 return reg + 256;
27810
27811 return FAIL;
27812 }
27813
27814 #ifdef TE_PE
27815 void
27816 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
27817 {
27818 expressionS exp;
27819
27820 exp.X_op = O_secrel;
27821 exp.X_add_symbol = symbol;
27822 exp.X_add_number = 0;
27823 emit_expr (&exp, size);
27824 }
27825 #endif
27826
27827 /* MD interface: Symbol and relocation handling. */
27828
27829 /* Return the address within the segment that a PC-relative fixup is
27830 relative to. For ARM, PC-relative fixups applied to instructions
27831 are generally relative to the location of the fixup plus 8 bytes.
27832 Thumb branches are offset by 4, and Thumb loads relative to PC
27833 require special handling. */
27834
27835 long
27836 md_pcrel_from_section (fixS * fixP, segT seg)
27837 {
27838 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
27839
27840 /* If this is pc-relative and we are going to emit a relocation
27841 then we just want to put out any pipeline compensation that the linker
27842 will need. Otherwise we want to use the calculated base.
27843 For WinCE we skip the bias for externals as well, since this
27844 is how the MS ARM-CE assembler behaves and we want to be compatible. */
27845 if (fixP->fx_pcrel
27846 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
27847 || (arm_force_relocation (fixP)
27848 #ifdef TE_WINCE
27849 && !S_IS_EXTERNAL (fixP->fx_addsy)
27850 #endif
27851 )))
27852 base = 0;
27853
27854
27855 switch (fixP->fx_r_type)
27856 {
27857 /* PC relative addressing on the Thumb is slightly odd as the
27858 bottom two bits of the PC are forced to zero for the
27859 calculation. This happens *after* application of the
27860 pipeline offset. However, Thumb adrl already adjusts for
27861 this, so we need not do it again. */
27862 case BFD_RELOC_ARM_THUMB_ADD:
27863 return base & ~3;
27864
27865 case BFD_RELOC_ARM_THUMB_OFFSET:
27866 case BFD_RELOC_ARM_T32_OFFSET_IMM:
27867 case BFD_RELOC_ARM_T32_ADD_PC12:
27868 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
27869 return (base + 4) & ~3;
27870
27871 /* Thumb branches are simply offset by +4. */
27872 case BFD_RELOC_THUMB_PCREL_BRANCH5:
27873 case BFD_RELOC_THUMB_PCREL_BRANCH7:
27874 case BFD_RELOC_THUMB_PCREL_BRANCH9:
27875 case BFD_RELOC_THUMB_PCREL_BRANCH12:
27876 case BFD_RELOC_THUMB_PCREL_BRANCH20:
27877 case BFD_RELOC_THUMB_PCREL_BRANCH25:
27878 case BFD_RELOC_THUMB_PCREL_BFCSEL:
27879 case BFD_RELOC_ARM_THUMB_BF17:
27880 case BFD_RELOC_ARM_THUMB_BF19:
27881 case BFD_RELOC_ARM_THUMB_BF13:
27882 case BFD_RELOC_ARM_THUMB_LOOP12:
27883 return base + 4;
27884
27885 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27886 if (fixP->fx_addsy
27887 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27888 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27889 && ARM_IS_FUNC (fixP->fx_addsy)
27890 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27891 base = fixP->fx_where + fixP->fx_frag->fr_address;
27892 return base + 4;
27893
27894 /* BLX is like branches above, but forces the low two bits of PC to
27895 zero. */
27896 case BFD_RELOC_THUMB_PCREL_BLX:
27897 if (fixP->fx_addsy
27898 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27899 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27900 && THUMB_IS_FUNC (fixP->fx_addsy)
27901 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27902 base = fixP->fx_where + fixP->fx_frag->fr_address;
27903 return (base + 4) & ~3;
27904
27905 /* ARM mode branches are offset by +8. However, the Windows CE
27906 loader expects the relocation not to take this into account. */
27907 case BFD_RELOC_ARM_PCREL_BLX:
27908 if (fixP->fx_addsy
27909 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27910 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27911 && ARM_IS_FUNC (fixP->fx_addsy)
27912 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27913 base = fixP->fx_where + fixP->fx_frag->fr_address;
27914 return base + 8;
27915
27916 case BFD_RELOC_ARM_PCREL_CALL:
27917 if (fixP->fx_addsy
27918 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27919 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27920 && THUMB_IS_FUNC (fixP->fx_addsy)
27921 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27922 base = fixP->fx_where + fixP->fx_frag->fr_address;
27923 return base + 8;
27924
27925 case BFD_RELOC_ARM_PCREL_BRANCH:
27926 case BFD_RELOC_ARM_PCREL_JUMP:
27927 case BFD_RELOC_ARM_PLT32:
27928 #ifdef TE_WINCE
27929 /* When handling fixups immediately, because we have already
27930 discovered the value of a symbol, or the address of the frag involved
27931 we must account for the offset by +8, as the OS loader will never see the reloc.
27932 see fixup_segment() in write.c
27933 The S_IS_EXTERNAL test handles the case of global symbols.
27934 Those need the calculated base, not just the pipe compensation the linker will need. */
27935 if (fixP->fx_pcrel
27936 && fixP->fx_addsy != NULL
27937 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27938 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
27939 return base + 8;
27940 return base;
27941 #else
27942 return base + 8;
27943 #endif
27944
27945
27946 /* ARM mode loads relative to PC are also offset by +8. Unlike
27947 branches, the Windows CE loader *does* expect the relocation
27948 to take this into account. */
27949 case BFD_RELOC_ARM_OFFSET_IMM:
27950 case BFD_RELOC_ARM_OFFSET_IMM8:
27951 case BFD_RELOC_ARM_HWLITERAL:
27952 case BFD_RELOC_ARM_LITERAL:
27953 case BFD_RELOC_ARM_CP_OFF_IMM:
27954 return base + 8;
27955
27956
27957 /* Other PC-relative relocations are un-offset. */
27958 default:
27959 return base;
27960 }
27961 }
27962
27963 static bfd_boolean flag_warn_syms = TRUE;
27964
27965 bfd_boolean
27966 arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
27967 {
27968 /* PR 18347 - Warn if the user attempts to create a symbol with the same
27969 name as an ARM instruction. Whilst strictly speaking it is allowed, it
27970 does mean that the resulting code might be very confusing to the reader.
27971 Also this warning can be triggered if the user omits an operand before
27972 an immediate address, eg:
27973
27974 LDR =foo
27975
27976 GAS treats this as an assignment of the value of the symbol foo to a
27977 symbol LDR, and so (without this code) it will not issue any kind of
27978 warning or error message.
27979
27980 Note - ARM instructions are case-insensitive but the strings in the hash
27981 table are all stored in lower case, so we must first ensure that name is
27982 lower case too. */
27983 if (flag_warn_syms && arm_ops_hsh)
27984 {
27985 char * nbuf = strdup (name);
27986 char * p;
27987
27988 for (p = nbuf; *p; p++)
27989 *p = TOLOWER (*p);
27990 if (hash_find (arm_ops_hsh, nbuf) != NULL)
27991 {
27992 static struct hash_control * already_warned = NULL;
27993
27994 if (already_warned == NULL)
27995 already_warned = hash_new ();
27996 /* Only warn about the symbol once. To keep the code
27997 simple we let hash_insert do the lookup for us. */
27998 if (hash_insert (already_warned, nbuf, NULL) == NULL)
27999 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
28000 }
28001 else
28002 free (nbuf);
28003 }
28004
28005 return FALSE;
28006 }
28007
28008 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
28009 Otherwise we have no need to default values of symbols. */
28010
28011 symbolS *
28012 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
28013 {
28014 #ifdef OBJ_ELF
28015 if (name[0] == '_' && name[1] == 'G'
28016 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
28017 {
28018 if (!GOT_symbol)
28019 {
28020 if (symbol_find (name))
28021 as_bad (_("GOT already in the symbol table"));
28022
28023 GOT_symbol = symbol_new (name, undefined_section,
28024 (valueT) 0, & zero_address_frag);
28025 }
28026
28027 return GOT_symbol;
28028 }
28029 #endif
28030
28031 return NULL;
28032 }
28033
28034 /* Subroutine of md_apply_fix. Check to see if an immediate can be
28035 computed as two separate immediate values, added together. We
28036 already know that this value cannot be computed by just one ARM
28037 instruction. */
28038
28039 static unsigned int
28040 validate_immediate_twopart (unsigned int val,
28041 unsigned int * highpart)
28042 {
28043 unsigned int a;
28044 unsigned int i;
28045
28046 for (i = 0; i < 32; i += 2)
28047 if (((a = rotate_left (val, i)) & 0xff) != 0)
28048 {
28049 if (a & 0xff00)
28050 {
28051 if (a & ~ 0xffff)
28052 continue;
28053 * highpart = (a >> 8) | ((i + 24) << 7);
28054 }
28055 else if (a & 0xff0000)
28056 {
28057 if (a & 0xff000000)
28058 continue;
28059 * highpart = (a >> 16) | ((i + 16) << 7);
28060 }
28061 else
28062 {
28063 gas_assert (a & 0xff000000);
28064 * highpart = (a >> 24) | ((i + 8) << 7);
28065 }
28066
28067 return (a & 0xff) | (i << 7);
28068 }
28069
28070 return FAIL;
28071 }
28072
28073 static int
28074 validate_offset_imm (unsigned int val, int hwse)
28075 {
28076 if ((hwse && val > 255) || val > 4095)
28077 return FAIL;
28078 return val;
28079 }
28080
28081 /* Subroutine of md_apply_fix. Do those data_ops which can take a
28082 negative immediate constant by altering the instruction. A bit of
28083 a hack really.
28084 MOV <-> MVN
28085 AND <-> BIC
28086 ADC <-> SBC
28087 by inverting the second operand, and
28088 ADD <-> SUB
28089 CMP <-> CMN
28090 by negating the second operand. */
28091
28092 static int
28093 negate_data_op (unsigned long * instruction,
28094 unsigned long value)
28095 {
28096 int op, new_inst;
28097 unsigned long negated, inverted;
28098
28099 negated = encode_arm_immediate (-value);
28100 inverted = encode_arm_immediate (~value);
28101
28102 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
28103 switch (op)
28104 {
28105 /* First negates. */
28106 case OPCODE_SUB: /* ADD <-> SUB */
28107 new_inst = OPCODE_ADD;
28108 value = negated;
28109 break;
28110
28111 case OPCODE_ADD:
28112 new_inst = OPCODE_SUB;
28113 value = negated;
28114 break;
28115
28116 case OPCODE_CMP: /* CMP <-> CMN */
28117 new_inst = OPCODE_CMN;
28118 value = negated;
28119 break;
28120
28121 case OPCODE_CMN:
28122 new_inst = OPCODE_CMP;
28123 value = negated;
28124 break;
28125
28126 /* Now Inverted ops. */
28127 case OPCODE_MOV: /* MOV <-> MVN */
28128 new_inst = OPCODE_MVN;
28129 value = inverted;
28130 break;
28131
28132 case OPCODE_MVN:
28133 new_inst = OPCODE_MOV;
28134 value = inverted;
28135 break;
28136
28137 case OPCODE_AND: /* AND <-> BIC */
28138 new_inst = OPCODE_BIC;
28139 value = inverted;
28140 break;
28141
28142 case OPCODE_BIC:
28143 new_inst = OPCODE_AND;
28144 value = inverted;
28145 break;
28146
28147 case OPCODE_ADC: /* ADC <-> SBC */
28148 new_inst = OPCODE_SBC;
28149 value = inverted;
28150 break;
28151
28152 case OPCODE_SBC:
28153 new_inst = OPCODE_ADC;
28154 value = inverted;
28155 break;
28156
28157 /* We cannot do anything. */
28158 default:
28159 return FAIL;
28160 }
28161
28162 if (value == (unsigned) FAIL)
28163 return FAIL;
28164
28165 *instruction &= OPCODE_MASK;
28166 *instruction |= new_inst << DATA_OP_SHIFT;
28167 return value;
28168 }
28169
28170 /* Like negate_data_op, but for Thumb-2. */
28171
28172 static unsigned int
28173 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
28174 {
28175 int op, new_inst;
28176 int rd;
28177 unsigned int negated, inverted;
28178
28179 negated = encode_thumb32_immediate (-value);
28180 inverted = encode_thumb32_immediate (~value);
28181
28182 rd = (*instruction >> 8) & 0xf;
28183 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
28184 switch (op)
28185 {
28186 /* ADD <-> SUB. Includes CMP <-> CMN. */
28187 case T2_OPCODE_SUB:
28188 new_inst = T2_OPCODE_ADD;
28189 value = negated;
28190 break;
28191
28192 case T2_OPCODE_ADD:
28193 new_inst = T2_OPCODE_SUB;
28194 value = negated;
28195 break;
28196
28197 /* ORR <-> ORN. Includes MOV <-> MVN. */
28198 case T2_OPCODE_ORR:
28199 new_inst = T2_OPCODE_ORN;
28200 value = inverted;
28201 break;
28202
28203 case T2_OPCODE_ORN:
28204 new_inst = T2_OPCODE_ORR;
28205 value = inverted;
28206 break;
28207
28208 /* AND <-> BIC. TST has no inverted equivalent. */
28209 case T2_OPCODE_AND:
28210 new_inst = T2_OPCODE_BIC;
28211 if (rd == 15)
28212 value = FAIL;
28213 else
28214 value = inverted;
28215 break;
28216
28217 case T2_OPCODE_BIC:
28218 new_inst = T2_OPCODE_AND;
28219 value = inverted;
28220 break;
28221
28222 /* ADC <-> SBC */
28223 case T2_OPCODE_ADC:
28224 new_inst = T2_OPCODE_SBC;
28225 value = inverted;
28226 break;
28227
28228 case T2_OPCODE_SBC:
28229 new_inst = T2_OPCODE_ADC;
28230 value = inverted;
28231 break;
28232
28233 /* We cannot do anything. */
28234 default:
28235 return FAIL;
28236 }
28237
28238 if (value == (unsigned int)FAIL)
28239 return FAIL;
28240
28241 *instruction &= T2_OPCODE_MASK;
28242 *instruction |= new_inst << T2_DATA_OP_SHIFT;
28243 return value;
28244 }
28245
28246 /* Read a 32-bit thumb instruction from buf. */
28247
28248 static unsigned long
28249 get_thumb32_insn (char * buf)
28250 {
28251 unsigned long insn;
28252 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
28253 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28254
28255 return insn;
28256 }
28257
28258 /* We usually want to set the low bit on the address of thumb function
28259 symbols. In particular .word foo - . should have the low bit set.
28260 Generic code tries to fold the difference of two symbols to
28261 a constant. Prevent this and force a relocation when the first symbols
28262 is a thumb function. */
28263
28264 bfd_boolean
28265 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
28266 {
28267 if (op == O_subtract
28268 && l->X_op == O_symbol
28269 && r->X_op == O_symbol
28270 && THUMB_IS_FUNC (l->X_add_symbol))
28271 {
28272 l->X_op = O_subtract;
28273 l->X_op_symbol = r->X_add_symbol;
28274 l->X_add_number -= r->X_add_number;
28275 return TRUE;
28276 }
28277
28278 /* Process as normal. */
28279 return FALSE;
28280 }
28281
28282 /* Encode Thumb2 unconditional branches and calls. The encoding
28283 for the 2 are identical for the immediate values. */
28284
28285 static void
28286 encode_thumb2_b_bl_offset (char * buf, offsetT value)
28287 {
28288 #define T2I1I2MASK ((1 << 13) | (1 << 11))
28289 offsetT newval;
28290 offsetT newval2;
28291 addressT S, I1, I2, lo, hi;
28292
28293 S = (value >> 24) & 0x01;
28294 I1 = (value >> 23) & 0x01;
28295 I2 = (value >> 22) & 0x01;
28296 hi = (value >> 12) & 0x3ff;
28297 lo = (value >> 1) & 0x7ff;
28298 newval = md_chars_to_number (buf, THUMB_SIZE);
28299 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28300 newval |= (S << 10) | hi;
28301 newval2 &= ~T2I1I2MASK;
28302 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
28303 md_number_to_chars (buf, newval, THUMB_SIZE);
28304 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28305 }
28306
28307 void
28308 md_apply_fix (fixS * fixP,
28309 valueT * valP,
28310 segT seg)
28311 {
28312 offsetT value = * valP;
28313 offsetT newval;
28314 unsigned int newimm;
28315 unsigned long temp;
28316 int sign;
28317 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
28318
28319 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
28320
28321 /* Note whether this will delete the relocation. */
28322
28323 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
28324 fixP->fx_done = 1;
28325
28326 /* On a 64-bit host, silently truncate 'value' to 32 bits for
28327 consistency with the behaviour on 32-bit hosts. Remember value
28328 for emit_reloc. */
28329 value &= 0xffffffff;
28330 value ^= 0x80000000;
28331 value -= 0x80000000;
28332
28333 *valP = value;
28334 fixP->fx_addnumber = value;
28335
28336 /* Same treatment for fixP->fx_offset. */
28337 fixP->fx_offset &= 0xffffffff;
28338 fixP->fx_offset ^= 0x80000000;
28339 fixP->fx_offset -= 0x80000000;
28340
28341 switch (fixP->fx_r_type)
28342 {
28343 case BFD_RELOC_NONE:
28344 /* This will need to go in the object file. */
28345 fixP->fx_done = 0;
28346 break;
28347
28348 case BFD_RELOC_ARM_IMMEDIATE:
28349 /* We claim that this fixup has been processed here,
28350 even if in fact we generate an error because we do
28351 not have a reloc for it, so tc_gen_reloc will reject it. */
28352 fixP->fx_done = 1;
28353
28354 if (fixP->fx_addsy)
28355 {
28356 const char *msg = 0;
28357
28358 if (! S_IS_DEFINED (fixP->fx_addsy))
28359 msg = _("undefined symbol %s used as an immediate value");
28360 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28361 msg = _("symbol %s is in a different section");
28362 else if (S_IS_WEAK (fixP->fx_addsy))
28363 msg = _("symbol %s is weak and may be overridden later");
28364
28365 if (msg)
28366 {
28367 as_bad_where (fixP->fx_file, fixP->fx_line,
28368 msg, S_GET_NAME (fixP->fx_addsy));
28369 break;
28370 }
28371 }
28372
28373 temp = md_chars_to_number (buf, INSN_SIZE);
28374
28375 /* If the offset is negative, we should use encoding A2 for ADR. */
28376 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
28377 newimm = negate_data_op (&temp, value);
28378 else
28379 {
28380 newimm = encode_arm_immediate (value);
28381
28382 /* If the instruction will fail, see if we can fix things up by
28383 changing the opcode. */
28384 if (newimm == (unsigned int) FAIL)
28385 newimm = negate_data_op (&temp, value);
28386 /* MOV accepts both ARM modified immediate (A1 encoding) and
28387 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
28388 When disassembling, MOV is preferred when there is no encoding
28389 overlap. */
28390 if (newimm == (unsigned int) FAIL
28391 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
28392 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
28393 && !((temp >> SBIT_SHIFT) & 0x1)
28394 && value >= 0 && value <= 0xffff)
28395 {
28396 /* Clear bits[23:20] to change encoding from A1 to A2. */
28397 temp &= 0xff0fffff;
28398 /* Encoding high 4bits imm. Code below will encode the remaining
28399 low 12bits. */
28400 temp |= (value & 0x0000f000) << 4;
28401 newimm = value & 0x00000fff;
28402 }
28403 }
28404
28405 if (newimm == (unsigned int) FAIL)
28406 {
28407 as_bad_where (fixP->fx_file, fixP->fx_line,
28408 _("invalid constant (%lx) after fixup"),
28409 (unsigned long) value);
28410 break;
28411 }
28412
28413 newimm |= (temp & 0xfffff000);
28414 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
28415 break;
28416
28417 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
28418 {
28419 unsigned int highpart = 0;
28420 unsigned int newinsn = 0xe1a00000; /* nop. */
28421
28422 if (fixP->fx_addsy)
28423 {
28424 const char *msg = 0;
28425
28426 if (! S_IS_DEFINED (fixP->fx_addsy))
28427 msg = _("undefined symbol %s used as an immediate value");
28428 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28429 msg = _("symbol %s is in a different section");
28430 else if (S_IS_WEAK (fixP->fx_addsy))
28431 msg = _("symbol %s is weak and may be overridden later");
28432
28433 if (msg)
28434 {
28435 as_bad_where (fixP->fx_file, fixP->fx_line,
28436 msg, S_GET_NAME (fixP->fx_addsy));
28437 break;
28438 }
28439 }
28440
28441 newimm = encode_arm_immediate (value);
28442 temp = md_chars_to_number (buf, INSN_SIZE);
28443
28444 /* If the instruction will fail, see if we can fix things up by
28445 changing the opcode. */
28446 if (newimm == (unsigned int) FAIL
28447 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
28448 {
28449 /* No ? OK - try using two ADD instructions to generate
28450 the value. */
28451 newimm = validate_immediate_twopart (value, & highpart);
28452
28453 /* Yes - then make sure that the second instruction is
28454 also an add. */
28455 if (newimm != (unsigned int) FAIL)
28456 newinsn = temp;
28457 /* Still No ? Try using a negated value. */
28458 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
28459 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
28460 /* Otherwise - give up. */
28461 else
28462 {
28463 as_bad_where (fixP->fx_file, fixP->fx_line,
28464 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
28465 (long) value);
28466 break;
28467 }
28468
28469 /* Replace the first operand in the 2nd instruction (which
28470 is the PC) with the destination register. We have
28471 already added in the PC in the first instruction and we
28472 do not want to do it again. */
28473 newinsn &= ~ 0xf0000;
28474 newinsn |= ((newinsn & 0x0f000) << 4);
28475 }
28476
28477 newimm |= (temp & 0xfffff000);
28478 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
28479
28480 highpart |= (newinsn & 0xfffff000);
28481 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
28482 }
28483 break;
28484
28485 case BFD_RELOC_ARM_OFFSET_IMM:
28486 if (!fixP->fx_done && seg->use_rela_p)
28487 value = 0;
28488 /* Fall through. */
28489
28490 case BFD_RELOC_ARM_LITERAL:
28491 sign = value > 0;
28492
28493 if (value < 0)
28494 value = - value;
28495
28496 if (validate_offset_imm (value, 0) == FAIL)
28497 {
28498 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
28499 as_bad_where (fixP->fx_file, fixP->fx_line,
28500 _("invalid literal constant: pool needs to be closer"));
28501 else
28502 as_bad_where (fixP->fx_file, fixP->fx_line,
28503 _("bad immediate value for offset (%ld)"),
28504 (long) value);
28505 break;
28506 }
28507
28508 newval = md_chars_to_number (buf, INSN_SIZE);
28509 if (value == 0)
28510 newval &= 0xfffff000;
28511 else
28512 {
28513 newval &= 0xff7ff000;
28514 newval |= value | (sign ? INDEX_UP : 0);
28515 }
28516 md_number_to_chars (buf, newval, INSN_SIZE);
28517 break;
28518
28519 case BFD_RELOC_ARM_OFFSET_IMM8:
28520 case BFD_RELOC_ARM_HWLITERAL:
28521 sign = value > 0;
28522
28523 if (value < 0)
28524 value = - value;
28525
28526 if (validate_offset_imm (value, 1) == FAIL)
28527 {
28528 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
28529 as_bad_where (fixP->fx_file, fixP->fx_line,
28530 _("invalid literal constant: pool needs to be closer"));
28531 else
28532 as_bad_where (fixP->fx_file, fixP->fx_line,
28533 _("bad immediate value for 8-bit offset (%ld)"),
28534 (long) value);
28535 break;
28536 }
28537
28538 newval = md_chars_to_number (buf, INSN_SIZE);
28539 if (value == 0)
28540 newval &= 0xfffff0f0;
28541 else
28542 {
28543 newval &= 0xff7ff0f0;
28544 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
28545 }
28546 md_number_to_chars (buf, newval, INSN_SIZE);
28547 break;
28548
28549 case BFD_RELOC_ARM_T32_OFFSET_U8:
28550 if (value < 0 || value > 1020 || value % 4 != 0)
28551 as_bad_where (fixP->fx_file, fixP->fx_line,
28552 _("bad immediate value for offset (%ld)"), (long) value);
28553 value /= 4;
28554
28555 newval = md_chars_to_number (buf+2, THUMB_SIZE);
28556 newval |= value;
28557 md_number_to_chars (buf+2, newval, THUMB_SIZE);
28558 break;
28559
28560 case BFD_RELOC_ARM_T32_OFFSET_IMM:
28561 /* This is a complicated relocation used for all varieties of Thumb32
28562 load/store instruction with immediate offset:
28563
28564 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
28565 *4, optional writeback(W)
28566 (doubleword load/store)
28567
28568 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
28569 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
28570 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
28571 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
28572 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
28573
28574 Uppercase letters indicate bits that are already encoded at
28575 this point. Lowercase letters are our problem. For the
28576 second block of instructions, the secondary opcode nybble
28577 (bits 8..11) is present, and bit 23 is zero, even if this is
28578 a PC-relative operation. */
28579 newval = md_chars_to_number (buf, THUMB_SIZE);
28580 newval <<= 16;
28581 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
28582
28583 if ((newval & 0xf0000000) == 0xe0000000)
28584 {
28585 /* Doubleword load/store: 8-bit offset, scaled by 4. */
28586 if (value >= 0)
28587 newval |= (1 << 23);
28588 else
28589 value = -value;
28590 if (value % 4 != 0)
28591 {
28592 as_bad_where (fixP->fx_file, fixP->fx_line,
28593 _("offset not a multiple of 4"));
28594 break;
28595 }
28596 value /= 4;
28597 if (value > 0xff)
28598 {
28599 as_bad_where (fixP->fx_file, fixP->fx_line,
28600 _("offset out of range"));
28601 break;
28602 }
28603 newval &= ~0xff;
28604 }
28605 else if ((newval & 0x000f0000) == 0x000f0000)
28606 {
28607 /* PC-relative, 12-bit offset. */
28608 if (value >= 0)
28609 newval |= (1 << 23);
28610 else
28611 value = -value;
28612 if (value > 0xfff)
28613 {
28614 as_bad_where (fixP->fx_file, fixP->fx_line,
28615 _("offset out of range"));
28616 break;
28617 }
28618 newval &= ~0xfff;
28619 }
28620 else if ((newval & 0x00000100) == 0x00000100)
28621 {
28622 /* Writeback: 8-bit, +/- offset. */
28623 if (value >= 0)
28624 newval |= (1 << 9);
28625 else
28626 value = -value;
28627 if (value > 0xff)
28628 {
28629 as_bad_where (fixP->fx_file, fixP->fx_line,
28630 _("offset out of range"));
28631 break;
28632 }
28633 newval &= ~0xff;
28634 }
28635 else if ((newval & 0x00000f00) == 0x00000e00)
28636 {
28637 /* T-instruction: positive 8-bit offset. */
28638 if (value < 0 || value > 0xff)
28639 {
28640 as_bad_where (fixP->fx_file, fixP->fx_line,
28641 _("offset out of range"));
28642 break;
28643 }
28644 newval &= ~0xff;
28645 newval |= value;
28646 }
28647 else
28648 {
28649 /* Positive 12-bit or negative 8-bit offset. */
28650 int limit;
28651 if (value >= 0)
28652 {
28653 newval |= (1 << 23);
28654 limit = 0xfff;
28655 }
28656 else
28657 {
28658 value = -value;
28659 limit = 0xff;
28660 }
28661 if (value > limit)
28662 {
28663 as_bad_where (fixP->fx_file, fixP->fx_line,
28664 _("offset out of range"));
28665 break;
28666 }
28667 newval &= ~limit;
28668 }
28669
28670 newval |= value;
28671 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
28672 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
28673 break;
28674
28675 case BFD_RELOC_ARM_SHIFT_IMM:
28676 newval = md_chars_to_number (buf, INSN_SIZE);
28677 if (((unsigned long) value) > 32
28678 || (value == 32
28679 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
28680 {
28681 as_bad_where (fixP->fx_file, fixP->fx_line,
28682 _("shift expression is too large"));
28683 break;
28684 }
28685
28686 if (value == 0)
28687 /* Shifts of zero must be done as lsl. */
28688 newval &= ~0x60;
28689 else if (value == 32)
28690 value = 0;
28691 newval &= 0xfffff07f;
28692 newval |= (value & 0x1f) << 7;
28693 md_number_to_chars (buf, newval, INSN_SIZE);
28694 break;
28695
28696 case BFD_RELOC_ARM_T32_IMMEDIATE:
28697 case BFD_RELOC_ARM_T32_ADD_IMM:
28698 case BFD_RELOC_ARM_T32_IMM12:
28699 case BFD_RELOC_ARM_T32_ADD_PC12:
28700 /* We claim that this fixup has been processed here,
28701 even if in fact we generate an error because we do
28702 not have a reloc for it, so tc_gen_reloc will reject it. */
28703 fixP->fx_done = 1;
28704
28705 if (fixP->fx_addsy
28706 && ! S_IS_DEFINED (fixP->fx_addsy))
28707 {
28708 as_bad_where (fixP->fx_file, fixP->fx_line,
28709 _("undefined symbol %s used as an immediate value"),
28710 S_GET_NAME (fixP->fx_addsy));
28711 break;
28712 }
28713
28714 newval = md_chars_to_number (buf, THUMB_SIZE);
28715 newval <<= 16;
28716 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
28717
28718 newimm = FAIL;
28719 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
28720 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
28721 Thumb2 modified immediate encoding (T2). */
28722 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
28723 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
28724 {
28725 newimm = encode_thumb32_immediate (value);
28726 if (newimm == (unsigned int) FAIL)
28727 newimm = thumb32_negate_data_op (&newval, value);
28728 }
28729 if (newimm == (unsigned int) FAIL)
28730 {
28731 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
28732 {
28733 /* Turn add/sum into addw/subw. */
28734 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
28735 newval = (newval & 0xfeffffff) | 0x02000000;
28736 /* No flat 12-bit imm encoding for addsw/subsw. */
28737 if ((newval & 0x00100000) == 0)
28738 {
28739 /* 12 bit immediate for addw/subw. */
28740 if (value < 0)
28741 {
28742 value = -value;
28743 newval ^= 0x00a00000;
28744 }
28745 if (value > 0xfff)
28746 newimm = (unsigned int) FAIL;
28747 else
28748 newimm = value;
28749 }
28750 }
28751 else
28752 {
28753 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
28754 UINT16 (T3 encoding), MOVW only accepts UINT16. When
28755 disassembling, MOV is preferred when there is no encoding
28756 overlap. */
28757 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
28758 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
28759 but with the Rn field [19:16] set to 1111. */
28760 && (((newval >> 16) & 0xf) == 0xf)
28761 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
28762 && !((newval >> T2_SBIT_SHIFT) & 0x1)
28763 && value >= 0 && value <= 0xffff)
28764 {
28765 /* Toggle bit[25] to change encoding from T2 to T3. */
28766 newval ^= 1 << 25;
28767 /* Clear bits[19:16]. */
28768 newval &= 0xfff0ffff;
28769 /* Encoding high 4bits imm. Code below will encode the
28770 remaining low 12bits. */
28771 newval |= (value & 0x0000f000) << 4;
28772 newimm = value & 0x00000fff;
28773 }
28774 }
28775 }
28776
28777 if (newimm == (unsigned int)FAIL)
28778 {
28779 as_bad_where (fixP->fx_file, fixP->fx_line,
28780 _("invalid constant (%lx) after fixup"),
28781 (unsigned long) value);
28782 break;
28783 }
28784
28785 newval |= (newimm & 0x800) << 15;
28786 newval |= (newimm & 0x700) << 4;
28787 newval |= (newimm & 0x0ff);
28788
28789 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
28790 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
28791 break;
28792
28793 case BFD_RELOC_ARM_SMC:
28794 if (((unsigned long) value) > 0xf)
28795 as_bad_where (fixP->fx_file, fixP->fx_line,
28796 _("invalid smc expression"));
28797
28798 newval = md_chars_to_number (buf, INSN_SIZE);
28799 newval |= (value & 0xf);
28800 md_number_to_chars (buf, newval, INSN_SIZE);
28801 break;
28802
28803 case BFD_RELOC_ARM_HVC:
28804 if (((unsigned long) value) > 0xffff)
28805 as_bad_where (fixP->fx_file, fixP->fx_line,
28806 _("invalid hvc expression"));
28807 newval = md_chars_to_number (buf, INSN_SIZE);
28808 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
28809 md_number_to_chars (buf, newval, INSN_SIZE);
28810 break;
28811
28812 case BFD_RELOC_ARM_SWI:
28813 if (fixP->tc_fix_data != 0)
28814 {
28815 if (((unsigned long) value) > 0xff)
28816 as_bad_where (fixP->fx_file, fixP->fx_line,
28817 _("invalid swi expression"));
28818 newval = md_chars_to_number (buf, THUMB_SIZE);
28819 newval |= value;
28820 md_number_to_chars (buf, newval, THUMB_SIZE);
28821 }
28822 else
28823 {
28824 if (((unsigned long) value) > 0x00ffffff)
28825 as_bad_where (fixP->fx_file, fixP->fx_line,
28826 _("invalid swi expression"));
28827 newval = md_chars_to_number (buf, INSN_SIZE);
28828 newval |= value;
28829 md_number_to_chars (buf, newval, INSN_SIZE);
28830 }
28831 break;
28832
28833 case BFD_RELOC_ARM_MULTI:
28834 if (((unsigned long) value) > 0xffff)
28835 as_bad_where (fixP->fx_file, fixP->fx_line,
28836 _("invalid expression in load/store multiple"));
28837 newval = value | md_chars_to_number (buf, INSN_SIZE);
28838 md_number_to_chars (buf, newval, INSN_SIZE);
28839 break;
28840
28841 #ifdef OBJ_ELF
28842 case BFD_RELOC_ARM_PCREL_CALL:
28843
28844 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28845 && fixP->fx_addsy
28846 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28847 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28848 && THUMB_IS_FUNC (fixP->fx_addsy))
28849 /* Flip the bl to blx. This is a simple flip
28850 bit here because we generate PCREL_CALL for
28851 unconditional bls. */
28852 {
28853 newval = md_chars_to_number (buf, INSN_SIZE);
28854 newval = newval | 0x10000000;
28855 md_number_to_chars (buf, newval, INSN_SIZE);
28856 temp = 1;
28857 fixP->fx_done = 1;
28858 }
28859 else
28860 temp = 3;
28861 goto arm_branch_common;
28862
28863 case BFD_RELOC_ARM_PCREL_JUMP:
28864 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28865 && fixP->fx_addsy
28866 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28867 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28868 && THUMB_IS_FUNC (fixP->fx_addsy))
28869 {
28870 /* This would map to a bl<cond>, b<cond>,
28871 b<always> to a Thumb function. We
28872 need to force a relocation for this particular
28873 case. */
28874 newval = md_chars_to_number (buf, INSN_SIZE);
28875 fixP->fx_done = 0;
28876 }
28877 /* Fall through. */
28878
28879 case BFD_RELOC_ARM_PLT32:
28880 #endif
28881 case BFD_RELOC_ARM_PCREL_BRANCH:
28882 temp = 3;
28883 goto arm_branch_common;
28884
28885 case BFD_RELOC_ARM_PCREL_BLX:
28886
28887 temp = 1;
28888 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28889 && fixP->fx_addsy
28890 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28891 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28892 && ARM_IS_FUNC (fixP->fx_addsy))
28893 {
28894 /* Flip the blx to a bl and warn. */
28895 const char *name = S_GET_NAME (fixP->fx_addsy);
28896 newval = 0xeb000000;
28897 as_warn_where (fixP->fx_file, fixP->fx_line,
28898 _("blx to '%s' an ARM ISA state function changed to bl"),
28899 name);
28900 md_number_to_chars (buf, newval, INSN_SIZE);
28901 temp = 3;
28902 fixP->fx_done = 1;
28903 }
28904
28905 #ifdef OBJ_ELF
28906 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
28907 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
28908 #endif
28909
28910 arm_branch_common:
28911 /* We are going to store value (shifted right by two) in the
28912 instruction, in a 24 bit, signed field. Bits 26 through 32 either
28913 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
28914 also be clear. */
28915 if (value & temp)
28916 as_bad_where (fixP->fx_file, fixP->fx_line,
28917 _("misaligned branch destination"));
28918 if ((value & (offsetT)0xfe000000) != (offsetT)0
28919 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
28920 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28921
28922 if (fixP->fx_done || !seg->use_rela_p)
28923 {
28924 newval = md_chars_to_number (buf, INSN_SIZE);
28925 newval |= (value >> 2) & 0x00ffffff;
28926 /* Set the H bit on BLX instructions. */
28927 if (temp == 1)
28928 {
28929 if (value & 2)
28930 newval |= 0x01000000;
28931 else
28932 newval &= ~0x01000000;
28933 }
28934 md_number_to_chars (buf, newval, INSN_SIZE);
28935 }
28936 break;
28937
28938 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
28939 /* CBZ can only branch forward. */
28940
28941 /* Attempts to use CBZ to branch to the next instruction
28942 (which, strictly speaking, are prohibited) will be turned into
28943 no-ops.
28944
28945 FIXME: It may be better to remove the instruction completely and
28946 perform relaxation. */
28947 if (value == -2)
28948 {
28949 newval = md_chars_to_number (buf, THUMB_SIZE);
28950 newval = 0xbf00; /* NOP encoding T1 */
28951 md_number_to_chars (buf, newval, THUMB_SIZE);
28952 }
28953 else
28954 {
28955 if (value & ~0x7e)
28956 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28957
28958 if (fixP->fx_done || !seg->use_rela_p)
28959 {
28960 newval = md_chars_to_number (buf, THUMB_SIZE);
28961 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
28962 md_number_to_chars (buf, newval, THUMB_SIZE);
28963 }
28964 }
28965 break;
28966
28967 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
28968 if (out_of_range_p (value, 8))
28969 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28970
28971 if (fixP->fx_done || !seg->use_rela_p)
28972 {
28973 newval = md_chars_to_number (buf, THUMB_SIZE);
28974 newval |= (value & 0x1ff) >> 1;
28975 md_number_to_chars (buf, newval, THUMB_SIZE);
28976 }
28977 break;
28978
28979 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
28980 if (out_of_range_p (value, 11))
28981 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28982
28983 if (fixP->fx_done || !seg->use_rela_p)
28984 {
28985 newval = md_chars_to_number (buf, THUMB_SIZE);
28986 newval |= (value & 0xfff) >> 1;
28987 md_number_to_chars (buf, newval, THUMB_SIZE);
28988 }
28989 break;
28990
28991 /* This relocation is misnamed, it should be BRANCH21. */
28992 case BFD_RELOC_THUMB_PCREL_BRANCH20:
28993 if (fixP->fx_addsy
28994 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28995 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28996 && ARM_IS_FUNC (fixP->fx_addsy)
28997 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
28998 {
28999 /* Force a relocation for a branch 20 bits wide. */
29000 fixP->fx_done = 0;
29001 }
29002 if (out_of_range_p (value, 20))
29003 as_bad_where (fixP->fx_file, fixP->fx_line,
29004 _("conditional branch out of range"));
29005
29006 if (fixP->fx_done || !seg->use_rela_p)
29007 {
29008 offsetT newval2;
29009 addressT S, J1, J2, lo, hi;
29010
29011 S = (value & 0x00100000) >> 20;
29012 J2 = (value & 0x00080000) >> 19;
29013 J1 = (value & 0x00040000) >> 18;
29014 hi = (value & 0x0003f000) >> 12;
29015 lo = (value & 0x00000ffe) >> 1;
29016
29017 newval = md_chars_to_number (buf, THUMB_SIZE);
29018 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29019 newval |= (S << 10) | hi;
29020 newval2 |= (J1 << 13) | (J2 << 11) | lo;
29021 md_number_to_chars (buf, newval, THUMB_SIZE);
29022 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29023 }
29024 break;
29025
29026 case BFD_RELOC_THUMB_PCREL_BLX:
29027 /* If there is a blx from a thumb state function to
29028 another thumb function flip this to a bl and warn
29029 about it. */
29030
29031 if (fixP->fx_addsy
29032 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29033 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29034 && THUMB_IS_FUNC (fixP->fx_addsy))
29035 {
29036 const char *name = S_GET_NAME (fixP->fx_addsy);
29037 as_warn_where (fixP->fx_file, fixP->fx_line,
29038 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
29039 name);
29040 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29041 newval = newval | 0x1000;
29042 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
29043 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
29044 fixP->fx_done = 1;
29045 }
29046
29047
29048 goto thumb_bl_common;
29049
29050 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29051 /* A bl from Thumb state ISA to an internal ARM state function
29052 is converted to a blx. */
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_v5t))
29058 {
29059 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29060 newval = newval & ~0x1000;
29061 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
29062 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
29063 fixP->fx_done = 1;
29064 }
29065
29066 thumb_bl_common:
29067
29068 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
29069 /* For a BLX instruction, make sure that the relocation is rounded up
29070 to a word boundary. This follows the semantics of the instruction
29071 which specifies that bit 1 of the target address will come from bit
29072 1 of the base address. */
29073 value = (value + 3) & ~ 3;
29074
29075 #ifdef OBJ_ELF
29076 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
29077 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
29078 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
29079 #endif
29080
29081 if (out_of_range_p (value, 22))
29082 {
29083 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
29084 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
29085 else if (out_of_range_p (value, 24))
29086 as_bad_where (fixP->fx_file, fixP->fx_line,
29087 _("Thumb2 branch out of range"));
29088 }
29089
29090 if (fixP->fx_done || !seg->use_rela_p)
29091 encode_thumb2_b_bl_offset (buf, value);
29092
29093 break;
29094
29095 case BFD_RELOC_THUMB_PCREL_BRANCH25:
29096 if (out_of_range_p (value, 24))
29097 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
29098
29099 if (fixP->fx_done || !seg->use_rela_p)
29100 encode_thumb2_b_bl_offset (buf, value);
29101
29102 break;
29103
29104 case BFD_RELOC_8:
29105 if (fixP->fx_done || !seg->use_rela_p)
29106 *buf = value;
29107 break;
29108
29109 case BFD_RELOC_16:
29110 if (fixP->fx_done || !seg->use_rela_p)
29111 md_number_to_chars (buf, value, 2);
29112 break;
29113
29114 #ifdef OBJ_ELF
29115 case BFD_RELOC_ARM_TLS_CALL:
29116 case BFD_RELOC_ARM_THM_TLS_CALL:
29117 case BFD_RELOC_ARM_TLS_DESCSEQ:
29118 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
29119 case BFD_RELOC_ARM_TLS_GOTDESC:
29120 case BFD_RELOC_ARM_TLS_GD32:
29121 case BFD_RELOC_ARM_TLS_LE32:
29122 case BFD_RELOC_ARM_TLS_IE32:
29123 case BFD_RELOC_ARM_TLS_LDM32:
29124 case BFD_RELOC_ARM_TLS_LDO32:
29125 S_SET_THREAD_LOCAL (fixP->fx_addsy);
29126 break;
29127
29128 /* Same handling as above, but with the arm_fdpic guard. */
29129 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
29130 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
29131 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
29132 if (arm_fdpic)
29133 {
29134 S_SET_THREAD_LOCAL (fixP->fx_addsy);
29135 }
29136 else
29137 {
29138 as_bad_where (fixP->fx_file, fixP->fx_line,
29139 _("Relocation supported only in FDPIC mode"));
29140 }
29141 break;
29142
29143 case BFD_RELOC_ARM_GOT32:
29144 case BFD_RELOC_ARM_GOTOFF:
29145 break;
29146
29147 case BFD_RELOC_ARM_GOT_PREL:
29148 if (fixP->fx_done || !seg->use_rela_p)
29149 md_number_to_chars (buf, value, 4);
29150 break;
29151
29152 case BFD_RELOC_ARM_TARGET2:
29153 /* TARGET2 is not partial-inplace, so we need to write the
29154 addend here for REL targets, because it won't be written out
29155 during reloc processing later. */
29156 if (fixP->fx_done || !seg->use_rela_p)
29157 md_number_to_chars (buf, fixP->fx_offset, 4);
29158 break;
29159
29160 /* Relocations for FDPIC. */
29161 case BFD_RELOC_ARM_GOTFUNCDESC:
29162 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
29163 case BFD_RELOC_ARM_FUNCDESC:
29164 if (arm_fdpic)
29165 {
29166 if (fixP->fx_done || !seg->use_rela_p)
29167 md_number_to_chars (buf, 0, 4);
29168 }
29169 else
29170 {
29171 as_bad_where (fixP->fx_file, fixP->fx_line,
29172 _("Relocation supported only in FDPIC mode"));
29173 }
29174 break;
29175 #endif
29176
29177 case BFD_RELOC_RVA:
29178 case BFD_RELOC_32:
29179 case BFD_RELOC_ARM_TARGET1:
29180 case BFD_RELOC_ARM_ROSEGREL32:
29181 case BFD_RELOC_ARM_SBREL32:
29182 case BFD_RELOC_32_PCREL:
29183 #ifdef TE_PE
29184 case BFD_RELOC_32_SECREL:
29185 #endif
29186 if (fixP->fx_done || !seg->use_rela_p)
29187 #ifdef TE_WINCE
29188 /* For WinCE we only do this for pcrel fixups. */
29189 if (fixP->fx_done || fixP->fx_pcrel)
29190 #endif
29191 md_number_to_chars (buf, value, 4);
29192 break;
29193
29194 #ifdef OBJ_ELF
29195 case BFD_RELOC_ARM_PREL31:
29196 if (fixP->fx_done || !seg->use_rela_p)
29197 {
29198 newval = md_chars_to_number (buf, 4) & 0x80000000;
29199 if ((value ^ (value >> 1)) & 0x40000000)
29200 {
29201 as_bad_where (fixP->fx_file, fixP->fx_line,
29202 _("rel31 relocation overflow"));
29203 }
29204 newval |= value & 0x7fffffff;
29205 md_number_to_chars (buf, newval, 4);
29206 }
29207 break;
29208 #endif
29209
29210 case BFD_RELOC_ARM_CP_OFF_IMM:
29211 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
29212 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
29213 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
29214 newval = md_chars_to_number (buf, INSN_SIZE);
29215 else
29216 newval = get_thumb32_insn (buf);
29217 if ((newval & 0x0f200f00) == 0x0d000900)
29218 {
29219 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
29220 has permitted values that are multiples of 2, in the range 0
29221 to 510. */
29222 if (value < -510 || value > 510 || (value & 1))
29223 as_bad_where (fixP->fx_file, fixP->fx_line,
29224 _("co-processor offset out of range"));
29225 }
29226 else if ((newval & 0xfe001f80) == 0xec000f80)
29227 {
29228 if (value < -511 || value > 512 || (value & 3))
29229 as_bad_where (fixP->fx_file, fixP->fx_line,
29230 _("co-processor offset out of range"));
29231 }
29232 else if (value < -1023 || value > 1023 || (value & 3))
29233 as_bad_where (fixP->fx_file, fixP->fx_line,
29234 _("co-processor offset out of range"));
29235 cp_off_common:
29236 sign = value > 0;
29237 if (value < 0)
29238 value = -value;
29239 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29240 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29241 newval = md_chars_to_number (buf, INSN_SIZE);
29242 else
29243 newval = get_thumb32_insn (buf);
29244 if (value == 0)
29245 {
29246 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29247 newval &= 0xffffff80;
29248 else
29249 newval &= 0xffffff00;
29250 }
29251 else
29252 {
29253 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29254 newval &= 0xff7fff80;
29255 else
29256 newval &= 0xff7fff00;
29257 if ((newval & 0x0f200f00) == 0x0d000900)
29258 {
29259 /* This is a fp16 vstr/vldr.
29260
29261 It requires the immediate offset in the instruction is shifted
29262 left by 1 to be a half-word offset.
29263
29264 Here, left shift by 1 first, and later right shift by 2
29265 should get the right offset. */
29266 value <<= 1;
29267 }
29268 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
29269 }
29270 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29271 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29272 md_number_to_chars (buf, newval, INSN_SIZE);
29273 else
29274 put_thumb32_insn (buf, newval);
29275 break;
29276
29277 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
29278 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
29279 if (value < -255 || value > 255)
29280 as_bad_where (fixP->fx_file, fixP->fx_line,
29281 _("co-processor offset out of range"));
29282 value *= 4;
29283 goto cp_off_common;
29284
29285 case BFD_RELOC_ARM_THUMB_OFFSET:
29286 newval = md_chars_to_number (buf, THUMB_SIZE);
29287 /* Exactly what ranges, and where the offset is inserted depends
29288 on the type of instruction, we can establish this from the
29289 top 4 bits. */
29290 switch (newval >> 12)
29291 {
29292 case 4: /* PC load. */
29293 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
29294 forced to zero for these loads; md_pcrel_from has already
29295 compensated for this. */
29296 if (value & 3)
29297 as_bad_where (fixP->fx_file, fixP->fx_line,
29298 _("invalid offset, target not word aligned (0x%08lX)"),
29299 (((unsigned long) fixP->fx_frag->fr_address
29300 + (unsigned long) fixP->fx_where) & ~3)
29301 + (unsigned long) value);
29302 else if (get_recorded_alignment (seg) < 2)
29303 as_warn_where (fixP->fx_file, fixP->fx_line,
29304 _("section does not have enough alignment to ensure safe PC-relative loads"));
29305
29306 if (value & ~0x3fc)
29307 as_bad_where (fixP->fx_file, fixP->fx_line,
29308 _("invalid offset, value too big (0x%08lX)"),
29309 (long) value);
29310
29311 newval |= value >> 2;
29312 break;
29313
29314 case 9: /* SP load/store. */
29315 if (value & ~0x3fc)
29316 as_bad_where (fixP->fx_file, fixP->fx_line,
29317 _("invalid offset, value too big (0x%08lX)"),
29318 (long) value);
29319 newval |= value >> 2;
29320 break;
29321
29322 case 6: /* Word load/store. */
29323 if (value & ~0x7c)
29324 as_bad_where (fixP->fx_file, fixP->fx_line,
29325 _("invalid offset, value too big (0x%08lX)"),
29326 (long) value);
29327 newval |= value << 4; /* 6 - 2. */
29328 break;
29329
29330 case 7: /* Byte load/store. */
29331 if (value & ~0x1f)
29332 as_bad_where (fixP->fx_file, fixP->fx_line,
29333 _("invalid offset, value too big (0x%08lX)"),
29334 (long) value);
29335 newval |= value << 6;
29336 break;
29337
29338 case 8: /* Halfword load/store. */
29339 if (value & ~0x3e)
29340 as_bad_where (fixP->fx_file, fixP->fx_line,
29341 _("invalid offset, value too big (0x%08lX)"),
29342 (long) value);
29343 newval |= value << 5; /* 6 - 1. */
29344 break;
29345
29346 default:
29347 as_bad_where (fixP->fx_file, fixP->fx_line,
29348 "Unable to process relocation for thumb opcode: %lx",
29349 (unsigned long) newval);
29350 break;
29351 }
29352 md_number_to_chars (buf, newval, THUMB_SIZE);
29353 break;
29354
29355 case BFD_RELOC_ARM_THUMB_ADD:
29356 /* This is a complicated relocation, since we use it for all of
29357 the following immediate relocations:
29358
29359 3bit ADD/SUB
29360 8bit ADD/SUB
29361 9bit ADD/SUB SP word-aligned
29362 10bit ADD PC/SP word-aligned
29363
29364 The type of instruction being processed is encoded in the
29365 instruction field:
29366
29367 0x8000 SUB
29368 0x00F0 Rd
29369 0x000F Rs
29370 */
29371 newval = md_chars_to_number (buf, THUMB_SIZE);
29372 {
29373 int rd = (newval >> 4) & 0xf;
29374 int rs = newval & 0xf;
29375 int subtract = !!(newval & 0x8000);
29376
29377 /* Check for HI regs, only very restricted cases allowed:
29378 Adjusting SP, and using PC or SP to get an address. */
29379 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
29380 || (rs > 7 && rs != REG_SP && rs != REG_PC))
29381 as_bad_where (fixP->fx_file, fixP->fx_line,
29382 _("invalid Hi register with immediate"));
29383
29384 /* If value is negative, choose the opposite instruction. */
29385 if (value < 0)
29386 {
29387 value = -value;
29388 subtract = !subtract;
29389 if (value < 0)
29390 as_bad_where (fixP->fx_file, fixP->fx_line,
29391 _("immediate value out of range"));
29392 }
29393
29394 if (rd == REG_SP)
29395 {
29396 if (value & ~0x1fc)
29397 as_bad_where (fixP->fx_file, fixP->fx_line,
29398 _("invalid immediate for stack address calculation"));
29399 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
29400 newval |= value >> 2;
29401 }
29402 else if (rs == REG_PC || rs == REG_SP)
29403 {
29404 /* PR gas/18541. If the addition is for a defined symbol
29405 within range of an ADR instruction then accept it. */
29406 if (subtract
29407 && value == 4
29408 && fixP->fx_addsy != NULL)
29409 {
29410 subtract = 0;
29411
29412 if (! S_IS_DEFINED (fixP->fx_addsy)
29413 || S_GET_SEGMENT (fixP->fx_addsy) != seg
29414 || S_IS_WEAK (fixP->fx_addsy))
29415 {
29416 as_bad_where (fixP->fx_file, fixP->fx_line,
29417 _("address calculation needs a strongly defined nearby symbol"));
29418 }
29419 else
29420 {
29421 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
29422
29423 /* Round up to the next 4-byte boundary. */
29424 if (v & 3)
29425 v = (v + 3) & ~ 3;
29426 else
29427 v += 4;
29428 v = S_GET_VALUE (fixP->fx_addsy) - v;
29429
29430 if (v & ~0x3fc)
29431 {
29432 as_bad_where (fixP->fx_file, fixP->fx_line,
29433 _("symbol too far away"));
29434 }
29435 else
29436 {
29437 fixP->fx_done = 1;
29438 value = v;
29439 }
29440 }
29441 }
29442
29443 if (subtract || value & ~0x3fc)
29444 as_bad_where (fixP->fx_file, fixP->fx_line,
29445 _("invalid immediate for address calculation (value = 0x%08lX)"),
29446 (unsigned long) (subtract ? - value : value));
29447 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
29448 newval |= rd << 8;
29449 newval |= value >> 2;
29450 }
29451 else if (rs == rd)
29452 {
29453 if (value & ~0xff)
29454 as_bad_where (fixP->fx_file, fixP->fx_line,
29455 _("immediate value out of range"));
29456 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
29457 newval |= (rd << 8) | value;
29458 }
29459 else
29460 {
29461 if (value & ~0x7)
29462 as_bad_where (fixP->fx_file, fixP->fx_line,
29463 _("immediate value out of range"));
29464 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
29465 newval |= rd | (rs << 3) | (value << 6);
29466 }
29467 }
29468 md_number_to_chars (buf, newval, THUMB_SIZE);
29469 break;
29470
29471 case BFD_RELOC_ARM_THUMB_IMM:
29472 newval = md_chars_to_number (buf, THUMB_SIZE);
29473 if (value < 0 || value > 255)
29474 as_bad_where (fixP->fx_file, fixP->fx_line,
29475 _("invalid immediate: %ld is out of range"),
29476 (long) value);
29477 newval |= value;
29478 md_number_to_chars (buf, newval, THUMB_SIZE);
29479 break;
29480
29481 case BFD_RELOC_ARM_THUMB_SHIFT:
29482 /* 5bit shift value (0..32). LSL cannot take 32. */
29483 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
29484 temp = newval & 0xf800;
29485 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
29486 as_bad_where (fixP->fx_file, fixP->fx_line,
29487 _("invalid shift value: %ld"), (long) value);
29488 /* Shifts of zero must be encoded as LSL. */
29489 if (value == 0)
29490 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
29491 /* Shifts of 32 are encoded as zero. */
29492 else if (value == 32)
29493 value = 0;
29494 newval |= value << 6;
29495 md_number_to_chars (buf, newval, THUMB_SIZE);
29496 break;
29497
29498 case BFD_RELOC_VTABLE_INHERIT:
29499 case BFD_RELOC_VTABLE_ENTRY:
29500 fixP->fx_done = 0;
29501 return;
29502
29503 case BFD_RELOC_ARM_MOVW:
29504 case BFD_RELOC_ARM_MOVT:
29505 case BFD_RELOC_ARM_THUMB_MOVW:
29506 case BFD_RELOC_ARM_THUMB_MOVT:
29507 if (fixP->fx_done || !seg->use_rela_p)
29508 {
29509 /* REL format relocations are limited to a 16-bit addend. */
29510 if (!fixP->fx_done)
29511 {
29512 if (value < -0x8000 || value > 0x7fff)
29513 as_bad_where (fixP->fx_file, fixP->fx_line,
29514 _("offset out of range"));
29515 }
29516 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
29517 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29518 {
29519 value >>= 16;
29520 }
29521
29522 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
29523 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29524 {
29525 newval = get_thumb32_insn (buf);
29526 newval &= 0xfbf08f00;
29527 newval |= (value & 0xf000) << 4;
29528 newval |= (value & 0x0800) << 15;
29529 newval |= (value & 0x0700) << 4;
29530 newval |= (value & 0x00ff);
29531 put_thumb32_insn (buf, newval);
29532 }
29533 else
29534 {
29535 newval = md_chars_to_number (buf, 4);
29536 newval &= 0xfff0f000;
29537 newval |= value & 0x0fff;
29538 newval |= (value & 0xf000) << 4;
29539 md_number_to_chars (buf, newval, 4);
29540 }
29541 }
29542 return;
29543
29544 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
29545 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
29546 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
29547 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
29548 gas_assert (!fixP->fx_done);
29549 {
29550 bfd_vma insn;
29551 bfd_boolean is_mov;
29552 bfd_vma encoded_addend = value;
29553
29554 /* Check that addend can be encoded in instruction. */
29555 if (!seg->use_rela_p && (value < 0 || value > 255))
29556 as_bad_where (fixP->fx_file, fixP->fx_line,
29557 _("the offset 0x%08lX is not representable"),
29558 (unsigned long) encoded_addend);
29559
29560 /* Extract the instruction. */
29561 insn = md_chars_to_number (buf, THUMB_SIZE);
29562 is_mov = (insn & 0xf800) == 0x2000;
29563
29564 /* Encode insn. */
29565 if (is_mov)
29566 {
29567 if (!seg->use_rela_p)
29568 insn |= encoded_addend;
29569 }
29570 else
29571 {
29572 int rd, rs;
29573
29574 /* Extract the instruction. */
29575 /* Encoding is the following
29576 0x8000 SUB
29577 0x00F0 Rd
29578 0x000F Rs
29579 */
29580 /* The following conditions must be true :
29581 - ADD
29582 - Rd == Rs
29583 - Rd <= 7
29584 */
29585 rd = (insn >> 4) & 0xf;
29586 rs = insn & 0xf;
29587 if ((insn & 0x8000) || (rd != rs) || rd > 7)
29588 as_bad_where (fixP->fx_file, fixP->fx_line,
29589 _("Unable to process relocation for thumb opcode: %lx"),
29590 (unsigned long) insn);
29591
29592 /* Encode as ADD immediate8 thumb 1 code. */
29593 insn = 0x3000 | (rd << 8);
29594
29595 /* Place the encoded addend into the first 8 bits of the
29596 instruction. */
29597 if (!seg->use_rela_p)
29598 insn |= encoded_addend;
29599 }
29600
29601 /* Update the instruction. */
29602 md_number_to_chars (buf, insn, THUMB_SIZE);
29603 }
29604 break;
29605
29606 case BFD_RELOC_ARM_ALU_PC_G0_NC:
29607 case BFD_RELOC_ARM_ALU_PC_G0:
29608 case BFD_RELOC_ARM_ALU_PC_G1_NC:
29609 case BFD_RELOC_ARM_ALU_PC_G1:
29610 case BFD_RELOC_ARM_ALU_PC_G2:
29611 case BFD_RELOC_ARM_ALU_SB_G0_NC:
29612 case BFD_RELOC_ARM_ALU_SB_G0:
29613 case BFD_RELOC_ARM_ALU_SB_G1_NC:
29614 case BFD_RELOC_ARM_ALU_SB_G1:
29615 case BFD_RELOC_ARM_ALU_SB_G2:
29616 gas_assert (!fixP->fx_done);
29617 if (!seg->use_rela_p)
29618 {
29619 bfd_vma insn;
29620 bfd_vma encoded_addend;
29621 bfd_vma addend_abs = llabs (value);
29622
29623 /* Check that the absolute value of the addend can be
29624 expressed as an 8-bit constant plus a rotation. */
29625 encoded_addend = encode_arm_immediate (addend_abs);
29626 if (encoded_addend == (unsigned int) FAIL)
29627 as_bad_where (fixP->fx_file, fixP->fx_line,
29628 _("the offset 0x%08lX is not representable"),
29629 (unsigned long) addend_abs);
29630
29631 /* Extract the instruction. */
29632 insn = md_chars_to_number (buf, INSN_SIZE);
29633
29634 /* If the addend is positive, use an ADD instruction.
29635 Otherwise use a SUB. Take care not to destroy the S bit. */
29636 insn &= 0xff1fffff;
29637 if (value < 0)
29638 insn |= 1 << 22;
29639 else
29640 insn |= 1 << 23;
29641
29642 /* Place the encoded addend into the first 12 bits of the
29643 instruction. */
29644 insn &= 0xfffff000;
29645 insn |= encoded_addend;
29646
29647 /* Update the instruction. */
29648 md_number_to_chars (buf, insn, INSN_SIZE);
29649 }
29650 break;
29651
29652 case BFD_RELOC_ARM_LDR_PC_G0:
29653 case BFD_RELOC_ARM_LDR_PC_G1:
29654 case BFD_RELOC_ARM_LDR_PC_G2:
29655 case BFD_RELOC_ARM_LDR_SB_G0:
29656 case BFD_RELOC_ARM_LDR_SB_G1:
29657 case BFD_RELOC_ARM_LDR_SB_G2:
29658 gas_assert (!fixP->fx_done);
29659 if (!seg->use_rela_p)
29660 {
29661 bfd_vma insn;
29662 bfd_vma addend_abs = llabs (value);
29663
29664 /* Check that the absolute value of the addend can be
29665 encoded in 12 bits. */
29666 if (addend_abs >= 0x1000)
29667 as_bad_where (fixP->fx_file, fixP->fx_line,
29668 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
29669 (unsigned long) addend_abs);
29670
29671 /* Extract the instruction. */
29672 insn = md_chars_to_number (buf, INSN_SIZE);
29673
29674 /* If the addend is negative, clear bit 23 of the instruction.
29675 Otherwise set it. */
29676 if (value < 0)
29677 insn &= ~(1 << 23);
29678 else
29679 insn |= 1 << 23;
29680
29681 /* Place the absolute value of the addend into the first 12 bits
29682 of the instruction. */
29683 insn &= 0xfffff000;
29684 insn |= addend_abs;
29685
29686 /* Update the instruction. */
29687 md_number_to_chars (buf, insn, INSN_SIZE);
29688 }
29689 break;
29690
29691 case BFD_RELOC_ARM_LDRS_PC_G0:
29692 case BFD_RELOC_ARM_LDRS_PC_G1:
29693 case BFD_RELOC_ARM_LDRS_PC_G2:
29694 case BFD_RELOC_ARM_LDRS_SB_G0:
29695 case BFD_RELOC_ARM_LDRS_SB_G1:
29696 case BFD_RELOC_ARM_LDRS_SB_G2:
29697 gas_assert (!fixP->fx_done);
29698 if (!seg->use_rela_p)
29699 {
29700 bfd_vma insn;
29701 bfd_vma addend_abs = llabs (value);
29702
29703 /* Check that the absolute value of the addend can be
29704 encoded in 8 bits. */
29705 if (addend_abs >= 0x100)
29706 as_bad_where (fixP->fx_file, fixP->fx_line,
29707 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
29708 (unsigned long) addend_abs);
29709
29710 /* Extract the instruction. */
29711 insn = md_chars_to_number (buf, INSN_SIZE);
29712
29713 /* If the addend is negative, clear bit 23 of the instruction.
29714 Otherwise set it. */
29715 if (value < 0)
29716 insn &= ~(1 << 23);
29717 else
29718 insn |= 1 << 23;
29719
29720 /* Place the first four bits of the absolute value of the addend
29721 into the first 4 bits of the instruction, and the remaining
29722 four into bits 8 .. 11. */
29723 insn &= 0xfffff0f0;
29724 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
29725
29726 /* Update the instruction. */
29727 md_number_to_chars (buf, insn, INSN_SIZE);
29728 }
29729 break;
29730
29731 case BFD_RELOC_ARM_LDC_PC_G0:
29732 case BFD_RELOC_ARM_LDC_PC_G1:
29733 case BFD_RELOC_ARM_LDC_PC_G2:
29734 case BFD_RELOC_ARM_LDC_SB_G0:
29735 case BFD_RELOC_ARM_LDC_SB_G1:
29736 case BFD_RELOC_ARM_LDC_SB_G2:
29737 gas_assert (!fixP->fx_done);
29738 if (!seg->use_rela_p)
29739 {
29740 bfd_vma insn;
29741 bfd_vma addend_abs = llabs (value);
29742
29743 /* Check that the absolute value of the addend is a multiple of
29744 four and, when divided by four, fits in 8 bits. */
29745 if (addend_abs & 0x3)
29746 as_bad_where (fixP->fx_file, fixP->fx_line,
29747 _("bad offset 0x%08lX (must be word-aligned)"),
29748 (unsigned long) addend_abs);
29749
29750 if ((addend_abs >> 2) > 0xff)
29751 as_bad_where (fixP->fx_file, fixP->fx_line,
29752 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
29753 (unsigned long) addend_abs);
29754
29755 /* Extract the instruction. */
29756 insn = md_chars_to_number (buf, INSN_SIZE);
29757
29758 /* If the addend is negative, clear bit 23 of the instruction.
29759 Otherwise set it. */
29760 if (value < 0)
29761 insn &= ~(1 << 23);
29762 else
29763 insn |= 1 << 23;
29764
29765 /* Place the addend (divided by four) into the first eight
29766 bits of the instruction. */
29767 insn &= 0xfffffff0;
29768 insn |= addend_abs >> 2;
29769
29770 /* Update the instruction. */
29771 md_number_to_chars (buf, insn, INSN_SIZE);
29772 }
29773 break;
29774
29775 case BFD_RELOC_THUMB_PCREL_BRANCH5:
29776 if (fixP->fx_addsy
29777 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29778 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29779 && ARM_IS_FUNC (fixP->fx_addsy)
29780 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29781 {
29782 /* Force a relocation for a branch 5 bits wide. */
29783 fixP->fx_done = 0;
29784 }
29785 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
29786 as_bad_where (fixP->fx_file, fixP->fx_line,
29787 BAD_BRANCH_OFF);
29788
29789 if (fixP->fx_done || !seg->use_rela_p)
29790 {
29791 addressT boff = value >> 1;
29792
29793 newval = md_chars_to_number (buf, THUMB_SIZE);
29794 newval |= (boff << 7);
29795 md_number_to_chars (buf, newval, THUMB_SIZE);
29796 }
29797 break;
29798
29799 case BFD_RELOC_THUMB_PCREL_BFCSEL:
29800 if (fixP->fx_addsy
29801 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29802 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29803 && ARM_IS_FUNC (fixP->fx_addsy)
29804 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29805 {
29806 fixP->fx_done = 0;
29807 }
29808 if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f))
29809 as_bad_where (fixP->fx_file, fixP->fx_line,
29810 _("branch out of range"));
29811
29812 if (fixP->fx_done || !seg->use_rela_p)
29813 {
29814 newval = md_chars_to_number (buf, THUMB_SIZE);
29815
29816 addressT boff = ((newval & 0x0780) >> 7) << 1;
29817 addressT diff = value - boff;
29818
29819 if (diff == 4)
29820 {
29821 newval |= 1 << 1; /* T bit. */
29822 }
29823 else if (diff != 2)
29824 {
29825 as_bad_where (fixP->fx_file, fixP->fx_line,
29826 _("out of range label-relative fixup value"));
29827 }
29828 md_number_to_chars (buf, newval, THUMB_SIZE);
29829 }
29830 break;
29831
29832 case BFD_RELOC_ARM_THUMB_BF17:
29833 if (fixP->fx_addsy
29834 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29835 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29836 && ARM_IS_FUNC (fixP->fx_addsy)
29837 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29838 {
29839 /* Force a relocation for a branch 17 bits wide. */
29840 fixP->fx_done = 0;
29841 }
29842
29843 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
29844 as_bad_where (fixP->fx_file, fixP->fx_line,
29845 BAD_BRANCH_OFF);
29846
29847 if (fixP->fx_done || !seg->use_rela_p)
29848 {
29849 offsetT newval2;
29850 addressT immA, immB, immC;
29851
29852 immA = (value & 0x0001f000) >> 12;
29853 immB = (value & 0x00000ffc) >> 2;
29854 immC = (value & 0x00000002) >> 1;
29855
29856 newval = md_chars_to_number (buf, THUMB_SIZE);
29857 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29858 newval |= immA;
29859 newval2 |= (immC << 11) | (immB << 1);
29860 md_number_to_chars (buf, newval, THUMB_SIZE);
29861 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29862 }
29863 break;
29864
29865 case BFD_RELOC_ARM_THUMB_BF19:
29866 if (fixP->fx_addsy
29867 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29868 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29869 && ARM_IS_FUNC (fixP->fx_addsy)
29870 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29871 {
29872 /* Force a relocation for a branch 19 bits wide. */
29873 fixP->fx_done = 0;
29874 }
29875
29876 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
29877 as_bad_where (fixP->fx_file, fixP->fx_line,
29878 BAD_BRANCH_OFF);
29879
29880 if (fixP->fx_done || !seg->use_rela_p)
29881 {
29882 offsetT newval2;
29883 addressT immA, immB, immC;
29884
29885 immA = (value & 0x0007f000) >> 12;
29886 immB = (value & 0x00000ffc) >> 2;
29887 immC = (value & 0x00000002) >> 1;
29888
29889 newval = md_chars_to_number (buf, THUMB_SIZE);
29890 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29891 newval |= immA;
29892 newval2 |= (immC << 11) | (immB << 1);
29893 md_number_to_chars (buf, newval, THUMB_SIZE);
29894 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29895 }
29896 break;
29897
29898 case BFD_RELOC_ARM_THUMB_BF13:
29899 if (fixP->fx_addsy
29900 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29901 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29902 && ARM_IS_FUNC (fixP->fx_addsy)
29903 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29904 {
29905 /* Force a relocation for a branch 13 bits wide. */
29906 fixP->fx_done = 0;
29907 }
29908
29909 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
29910 as_bad_where (fixP->fx_file, fixP->fx_line,
29911 BAD_BRANCH_OFF);
29912
29913 if (fixP->fx_done || !seg->use_rela_p)
29914 {
29915 offsetT newval2;
29916 addressT immA, immB, immC;
29917
29918 immA = (value & 0x00001000) >> 12;
29919 immB = (value & 0x00000ffc) >> 2;
29920 immC = (value & 0x00000002) >> 1;
29921
29922 newval = md_chars_to_number (buf, THUMB_SIZE);
29923 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29924 newval |= immA;
29925 newval2 |= (immC << 11) | (immB << 1);
29926 md_number_to_chars (buf, newval, THUMB_SIZE);
29927 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29928 }
29929 break;
29930
29931 case BFD_RELOC_ARM_THUMB_LOOP12:
29932 if (fixP->fx_addsy
29933 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29934 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29935 && ARM_IS_FUNC (fixP->fx_addsy)
29936 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29937 {
29938 /* Force a relocation for a branch 12 bits wide. */
29939 fixP->fx_done = 0;
29940 }
29941
29942 bfd_vma insn = get_thumb32_insn (buf);
29943 /* le lr, <label>, le <label> or letp lr, <label> */
29944 if (((insn & 0xffffffff) == 0xf00fc001)
29945 || ((insn & 0xffffffff) == 0xf02fc001)
29946 || ((insn & 0xffffffff) == 0xf01fc001))
29947 value = -value;
29948
29949 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
29950 as_bad_where (fixP->fx_file, fixP->fx_line,
29951 BAD_BRANCH_OFF);
29952 if (fixP->fx_done || !seg->use_rela_p)
29953 {
29954 addressT imml, immh;
29955
29956 immh = (value & 0x00000ffc) >> 2;
29957 imml = (value & 0x00000002) >> 1;
29958
29959 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29960 newval |= (imml << 11) | (immh << 1);
29961 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
29962 }
29963 break;
29964
29965 case BFD_RELOC_ARM_V4BX:
29966 /* This will need to go in the object file. */
29967 fixP->fx_done = 0;
29968 break;
29969
29970 case BFD_RELOC_UNUSED:
29971 default:
29972 as_bad_where (fixP->fx_file, fixP->fx_line,
29973 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
29974 }
29975 }
29976
29977 /* Translate internal representation of relocation info to BFD target
29978 format. */
29979
29980 arelent *
29981 tc_gen_reloc (asection *section, fixS *fixp)
29982 {
29983 arelent * reloc;
29984 bfd_reloc_code_real_type code;
29985
29986 reloc = XNEW (arelent);
29987
29988 reloc->sym_ptr_ptr = XNEW (asymbol *);
29989 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
29990 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
29991
29992 if (fixp->fx_pcrel)
29993 {
29994 if (section->use_rela_p)
29995 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
29996 else
29997 fixp->fx_offset = reloc->address;
29998 }
29999 reloc->addend = fixp->fx_offset;
30000
30001 switch (fixp->fx_r_type)
30002 {
30003 case BFD_RELOC_8:
30004 if (fixp->fx_pcrel)
30005 {
30006 code = BFD_RELOC_8_PCREL;
30007 break;
30008 }
30009 /* Fall through. */
30010
30011 case BFD_RELOC_16:
30012 if (fixp->fx_pcrel)
30013 {
30014 code = BFD_RELOC_16_PCREL;
30015 break;
30016 }
30017 /* Fall through. */
30018
30019 case BFD_RELOC_32:
30020 if (fixp->fx_pcrel)
30021 {
30022 code = BFD_RELOC_32_PCREL;
30023 break;
30024 }
30025 /* Fall through. */
30026
30027 case BFD_RELOC_ARM_MOVW:
30028 if (fixp->fx_pcrel)
30029 {
30030 code = BFD_RELOC_ARM_MOVW_PCREL;
30031 break;
30032 }
30033 /* Fall through. */
30034
30035 case BFD_RELOC_ARM_MOVT:
30036 if (fixp->fx_pcrel)
30037 {
30038 code = BFD_RELOC_ARM_MOVT_PCREL;
30039 break;
30040 }
30041 /* Fall through. */
30042
30043 case BFD_RELOC_ARM_THUMB_MOVW:
30044 if (fixp->fx_pcrel)
30045 {
30046 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
30047 break;
30048 }
30049 /* Fall through. */
30050
30051 case BFD_RELOC_ARM_THUMB_MOVT:
30052 if (fixp->fx_pcrel)
30053 {
30054 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
30055 break;
30056 }
30057 /* Fall through. */
30058
30059 case BFD_RELOC_NONE:
30060 case BFD_RELOC_ARM_PCREL_BRANCH:
30061 case BFD_RELOC_ARM_PCREL_BLX:
30062 case BFD_RELOC_RVA:
30063 case BFD_RELOC_THUMB_PCREL_BRANCH7:
30064 case BFD_RELOC_THUMB_PCREL_BRANCH9:
30065 case BFD_RELOC_THUMB_PCREL_BRANCH12:
30066 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30067 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30068 case BFD_RELOC_THUMB_PCREL_BRANCH25:
30069 case BFD_RELOC_VTABLE_ENTRY:
30070 case BFD_RELOC_VTABLE_INHERIT:
30071 #ifdef TE_PE
30072 case BFD_RELOC_32_SECREL:
30073 #endif
30074 code = fixp->fx_r_type;
30075 break;
30076
30077 case BFD_RELOC_THUMB_PCREL_BLX:
30078 #ifdef OBJ_ELF
30079 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
30080 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
30081 else
30082 #endif
30083 code = BFD_RELOC_THUMB_PCREL_BLX;
30084 break;
30085
30086 case BFD_RELOC_ARM_LITERAL:
30087 case BFD_RELOC_ARM_HWLITERAL:
30088 /* If this is called then the a literal has
30089 been referenced across a section boundary. */
30090 as_bad_where (fixp->fx_file, fixp->fx_line,
30091 _("literal referenced across section boundary"));
30092 return NULL;
30093
30094 #ifdef OBJ_ELF
30095 case BFD_RELOC_ARM_TLS_CALL:
30096 case BFD_RELOC_ARM_THM_TLS_CALL:
30097 case BFD_RELOC_ARM_TLS_DESCSEQ:
30098 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
30099 case BFD_RELOC_ARM_GOT32:
30100 case BFD_RELOC_ARM_GOTOFF:
30101 case BFD_RELOC_ARM_GOT_PREL:
30102 case BFD_RELOC_ARM_PLT32:
30103 case BFD_RELOC_ARM_TARGET1:
30104 case BFD_RELOC_ARM_ROSEGREL32:
30105 case BFD_RELOC_ARM_SBREL32:
30106 case BFD_RELOC_ARM_PREL31:
30107 case BFD_RELOC_ARM_TARGET2:
30108 case BFD_RELOC_ARM_TLS_LDO32:
30109 case BFD_RELOC_ARM_PCREL_CALL:
30110 case BFD_RELOC_ARM_PCREL_JUMP:
30111 case BFD_RELOC_ARM_ALU_PC_G0_NC:
30112 case BFD_RELOC_ARM_ALU_PC_G0:
30113 case BFD_RELOC_ARM_ALU_PC_G1_NC:
30114 case BFD_RELOC_ARM_ALU_PC_G1:
30115 case BFD_RELOC_ARM_ALU_PC_G2:
30116 case BFD_RELOC_ARM_LDR_PC_G0:
30117 case BFD_RELOC_ARM_LDR_PC_G1:
30118 case BFD_RELOC_ARM_LDR_PC_G2:
30119 case BFD_RELOC_ARM_LDRS_PC_G0:
30120 case BFD_RELOC_ARM_LDRS_PC_G1:
30121 case BFD_RELOC_ARM_LDRS_PC_G2:
30122 case BFD_RELOC_ARM_LDC_PC_G0:
30123 case BFD_RELOC_ARM_LDC_PC_G1:
30124 case BFD_RELOC_ARM_LDC_PC_G2:
30125 case BFD_RELOC_ARM_ALU_SB_G0_NC:
30126 case BFD_RELOC_ARM_ALU_SB_G0:
30127 case BFD_RELOC_ARM_ALU_SB_G1_NC:
30128 case BFD_RELOC_ARM_ALU_SB_G1:
30129 case BFD_RELOC_ARM_ALU_SB_G2:
30130 case BFD_RELOC_ARM_LDR_SB_G0:
30131 case BFD_RELOC_ARM_LDR_SB_G1:
30132 case BFD_RELOC_ARM_LDR_SB_G2:
30133 case BFD_RELOC_ARM_LDRS_SB_G0:
30134 case BFD_RELOC_ARM_LDRS_SB_G1:
30135 case BFD_RELOC_ARM_LDRS_SB_G2:
30136 case BFD_RELOC_ARM_LDC_SB_G0:
30137 case BFD_RELOC_ARM_LDC_SB_G1:
30138 case BFD_RELOC_ARM_LDC_SB_G2:
30139 case BFD_RELOC_ARM_V4BX:
30140 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
30141 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
30142 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
30143 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
30144 case BFD_RELOC_ARM_GOTFUNCDESC:
30145 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
30146 case BFD_RELOC_ARM_FUNCDESC:
30147 case BFD_RELOC_ARM_THUMB_BF17:
30148 case BFD_RELOC_ARM_THUMB_BF19:
30149 case BFD_RELOC_ARM_THUMB_BF13:
30150 code = fixp->fx_r_type;
30151 break;
30152
30153 case BFD_RELOC_ARM_TLS_GOTDESC:
30154 case BFD_RELOC_ARM_TLS_GD32:
30155 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
30156 case BFD_RELOC_ARM_TLS_LE32:
30157 case BFD_RELOC_ARM_TLS_IE32:
30158 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
30159 case BFD_RELOC_ARM_TLS_LDM32:
30160 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
30161 /* BFD will include the symbol's address in the addend.
30162 But we don't want that, so subtract it out again here. */
30163 if (!S_IS_COMMON (fixp->fx_addsy))
30164 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
30165 code = fixp->fx_r_type;
30166 break;
30167 #endif
30168
30169 case BFD_RELOC_ARM_IMMEDIATE:
30170 as_bad_where (fixp->fx_file, fixp->fx_line,
30171 _("internal relocation (type: IMMEDIATE) not fixed up"));
30172 return NULL;
30173
30174 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
30175 as_bad_where (fixp->fx_file, fixp->fx_line,
30176 _("ADRL used for a symbol not defined in the same file"));
30177 return NULL;
30178
30179 case BFD_RELOC_THUMB_PCREL_BRANCH5:
30180 case BFD_RELOC_THUMB_PCREL_BFCSEL:
30181 case BFD_RELOC_ARM_THUMB_LOOP12:
30182 as_bad_where (fixp->fx_file, fixp->fx_line,
30183 _("%s used for a symbol not defined in the same file"),
30184 bfd_get_reloc_code_name (fixp->fx_r_type));
30185 return NULL;
30186
30187 case BFD_RELOC_ARM_OFFSET_IMM:
30188 if (section->use_rela_p)
30189 {
30190 code = fixp->fx_r_type;
30191 break;
30192 }
30193
30194 if (fixp->fx_addsy != NULL
30195 && !S_IS_DEFINED (fixp->fx_addsy)
30196 && S_IS_LOCAL (fixp->fx_addsy))
30197 {
30198 as_bad_where (fixp->fx_file, fixp->fx_line,
30199 _("undefined local label `%s'"),
30200 S_GET_NAME (fixp->fx_addsy));
30201 return NULL;
30202 }
30203
30204 as_bad_where (fixp->fx_file, fixp->fx_line,
30205 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
30206 return NULL;
30207
30208 default:
30209 {
30210 const char * type;
30211
30212 switch (fixp->fx_r_type)
30213 {
30214 case BFD_RELOC_NONE: type = "NONE"; break;
30215 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
30216 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
30217 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
30218 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
30219 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
30220 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
30221 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
30222 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
30223 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
30224 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
30225 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
30226 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
30227 default: type = _("<unknown>"); break;
30228 }
30229 as_bad_where (fixp->fx_file, fixp->fx_line,
30230 _("cannot represent %s relocation in this object file format"),
30231 type);
30232 return NULL;
30233 }
30234 }
30235
30236 #ifdef OBJ_ELF
30237 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
30238 && GOT_symbol
30239 && fixp->fx_addsy == GOT_symbol)
30240 {
30241 code = BFD_RELOC_ARM_GOTPC;
30242 reloc->addend = fixp->fx_offset = reloc->address;
30243 }
30244 #endif
30245
30246 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
30247
30248 if (reloc->howto == NULL)
30249 {
30250 as_bad_where (fixp->fx_file, fixp->fx_line,
30251 _("cannot represent %s relocation in this object file format"),
30252 bfd_get_reloc_code_name (code));
30253 return NULL;
30254 }
30255
30256 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
30257 vtable entry to be used in the relocation's section offset. */
30258 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
30259 reloc->address = fixp->fx_offset;
30260
30261 return reloc;
30262 }
30263
30264 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
30265
30266 void
30267 cons_fix_new_arm (fragS * frag,
30268 int where,
30269 int size,
30270 expressionS * exp,
30271 bfd_reloc_code_real_type reloc)
30272 {
30273 int pcrel = 0;
30274
30275 /* Pick a reloc.
30276 FIXME: @@ Should look at CPU word size. */
30277 switch (size)
30278 {
30279 case 1:
30280 reloc = BFD_RELOC_8;
30281 break;
30282 case 2:
30283 reloc = BFD_RELOC_16;
30284 break;
30285 case 4:
30286 default:
30287 reloc = BFD_RELOC_32;
30288 break;
30289 case 8:
30290 reloc = BFD_RELOC_64;
30291 break;
30292 }
30293
30294 #ifdef TE_PE
30295 if (exp->X_op == O_secrel)
30296 {
30297 exp->X_op = O_symbol;
30298 reloc = BFD_RELOC_32_SECREL;
30299 }
30300 #endif
30301
30302 fix_new_exp (frag, where, size, exp, pcrel, reloc);
30303 }
30304
30305 #if defined (OBJ_COFF)
30306 void
30307 arm_validate_fix (fixS * fixP)
30308 {
30309 /* If the destination of the branch is a defined symbol which does not have
30310 the THUMB_FUNC attribute, then we must be calling a function which has
30311 the (interfacearm) attribute. We look for the Thumb entry point to that
30312 function and change the branch to refer to that function instead. */
30313 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
30314 && fixP->fx_addsy != NULL
30315 && S_IS_DEFINED (fixP->fx_addsy)
30316 && ! THUMB_IS_FUNC (fixP->fx_addsy))
30317 {
30318 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
30319 }
30320 }
30321 #endif
30322
30323
30324 int
30325 arm_force_relocation (struct fix * fixp)
30326 {
30327 #if defined (OBJ_COFF) && defined (TE_PE)
30328 if (fixp->fx_r_type == BFD_RELOC_RVA)
30329 return 1;
30330 #endif
30331
30332 /* In case we have a call or a branch to a function in ARM ISA mode from
30333 a thumb function or vice-versa force the relocation. These relocations
30334 are cleared off for some cores that might have blx and simple transformations
30335 are possible. */
30336
30337 #ifdef OBJ_ELF
30338 switch (fixp->fx_r_type)
30339 {
30340 case BFD_RELOC_ARM_PCREL_JUMP:
30341 case BFD_RELOC_ARM_PCREL_CALL:
30342 case BFD_RELOC_THUMB_PCREL_BLX:
30343 if (THUMB_IS_FUNC (fixp->fx_addsy))
30344 return 1;
30345 break;
30346
30347 case BFD_RELOC_ARM_PCREL_BLX:
30348 case BFD_RELOC_THUMB_PCREL_BRANCH25:
30349 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30350 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30351 if (ARM_IS_FUNC (fixp->fx_addsy))
30352 return 1;
30353 break;
30354
30355 default:
30356 break;
30357 }
30358 #endif
30359
30360 /* Resolve these relocations even if the symbol is extern or weak.
30361 Technically this is probably wrong due to symbol preemption.
30362 In practice these relocations do not have enough range to be useful
30363 at dynamic link time, and some code (e.g. in the Linux kernel)
30364 expects these references to be resolved. */
30365 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
30366 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
30367 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
30368 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
30369 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
30370 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
30371 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
30372 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
30373 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
30374 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
30375 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
30376 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
30377 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
30378 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
30379 return 0;
30380
30381 /* Always leave these relocations for the linker. */
30382 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30383 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30384 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
30385 return 1;
30386
30387 /* Always generate relocations against function symbols. */
30388 if (fixp->fx_r_type == BFD_RELOC_32
30389 && fixp->fx_addsy
30390 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
30391 return 1;
30392
30393 return generic_force_reloc (fixp);
30394 }
30395
30396 #if defined (OBJ_ELF) || defined (OBJ_COFF)
30397 /* Relocations against function names must be left unadjusted,
30398 so that the linker can use this information to generate interworking
30399 stubs. The MIPS version of this function
30400 also prevents relocations that are mips-16 specific, but I do not
30401 know why it does this.
30402
30403 FIXME:
30404 There is one other problem that ought to be addressed here, but
30405 which currently is not: Taking the address of a label (rather
30406 than a function) and then later jumping to that address. Such
30407 addresses also ought to have their bottom bit set (assuming that
30408 they reside in Thumb code), but at the moment they will not. */
30409
30410 bfd_boolean
30411 arm_fix_adjustable (fixS * fixP)
30412 {
30413 if (fixP->fx_addsy == NULL)
30414 return 1;
30415
30416 /* Preserve relocations against symbols with function type. */
30417 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
30418 return FALSE;
30419
30420 if (THUMB_IS_FUNC (fixP->fx_addsy)
30421 && fixP->fx_subsy == NULL)
30422 return FALSE;
30423
30424 /* We need the symbol name for the VTABLE entries. */
30425 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
30426 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
30427 return FALSE;
30428
30429 /* Don't allow symbols to be discarded on GOT related relocs. */
30430 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
30431 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
30432 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
30433 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
30434 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
30435 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
30436 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
30437 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
30438 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
30439 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
30440 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
30441 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
30442 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
30443 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
30444 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
30445 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
30446 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
30447 return FALSE;
30448
30449 /* Similarly for group relocations. */
30450 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30451 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30452 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
30453 return FALSE;
30454
30455 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
30456 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
30457 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
30458 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
30459 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
30460 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
30461 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
30462 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
30463 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
30464 return FALSE;
30465
30466 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
30467 offsets, so keep these symbols. */
30468 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
30469 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
30470 return FALSE;
30471
30472 return TRUE;
30473 }
30474 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
30475
30476 #ifdef OBJ_ELF
30477 const char *
30478 elf32_arm_target_format (void)
30479 {
30480 #ifdef TE_SYMBIAN
30481 return (target_big_endian
30482 ? "elf32-bigarm-symbian"
30483 : "elf32-littlearm-symbian");
30484 #elif defined (TE_VXWORKS)
30485 return (target_big_endian
30486 ? "elf32-bigarm-vxworks"
30487 : "elf32-littlearm-vxworks");
30488 #elif defined (TE_NACL)
30489 return (target_big_endian
30490 ? "elf32-bigarm-nacl"
30491 : "elf32-littlearm-nacl");
30492 #else
30493 if (arm_fdpic)
30494 {
30495 if (target_big_endian)
30496 return "elf32-bigarm-fdpic";
30497 else
30498 return "elf32-littlearm-fdpic";
30499 }
30500 else
30501 {
30502 if (target_big_endian)
30503 return "elf32-bigarm";
30504 else
30505 return "elf32-littlearm";
30506 }
30507 #endif
30508 }
30509
30510 void
30511 armelf_frob_symbol (symbolS * symp,
30512 int * puntp)
30513 {
30514 elf_frob_symbol (symp, puntp);
30515 }
30516 #endif
30517
30518 /* MD interface: Finalization. */
30519
30520 void
30521 arm_cleanup (void)
30522 {
30523 literal_pool * pool;
30524
30525 /* Ensure that all the predication blocks are properly closed. */
30526 check_pred_blocks_finished ();
30527
30528 for (pool = list_of_pools; pool; pool = pool->next)
30529 {
30530 /* Put it at the end of the relevant section. */
30531 subseg_set (pool->section, pool->sub_section);
30532 #ifdef OBJ_ELF
30533 arm_elf_change_section ();
30534 #endif
30535 s_ltorg (0);
30536 }
30537 }
30538
30539 #ifdef OBJ_ELF
30540 /* Remove any excess mapping symbols generated for alignment frags in
30541 SEC. We may have created a mapping symbol before a zero byte
30542 alignment; remove it if there's a mapping symbol after the
30543 alignment. */
30544 static void
30545 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
30546 void *dummy ATTRIBUTE_UNUSED)
30547 {
30548 segment_info_type *seginfo = seg_info (sec);
30549 fragS *fragp;
30550
30551 if (seginfo == NULL || seginfo->frchainP == NULL)
30552 return;
30553
30554 for (fragp = seginfo->frchainP->frch_root;
30555 fragp != NULL;
30556 fragp = fragp->fr_next)
30557 {
30558 symbolS *sym = fragp->tc_frag_data.last_map;
30559 fragS *next = fragp->fr_next;
30560
30561 /* Variable-sized frags have been converted to fixed size by
30562 this point. But if this was variable-sized to start with,
30563 there will be a fixed-size frag after it. So don't handle
30564 next == NULL. */
30565 if (sym == NULL || next == NULL)
30566 continue;
30567
30568 if (S_GET_VALUE (sym) < next->fr_address)
30569 /* Not at the end of this frag. */
30570 continue;
30571 know (S_GET_VALUE (sym) == next->fr_address);
30572
30573 do
30574 {
30575 if (next->tc_frag_data.first_map != NULL)
30576 {
30577 /* Next frag starts with a mapping symbol. Discard this
30578 one. */
30579 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30580 break;
30581 }
30582
30583 if (next->fr_next == NULL)
30584 {
30585 /* This mapping symbol is at the end of the section. Discard
30586 it. */
30587 know (next->fr_fix == 0 && next->fr_var == 0);
30588 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30589 break;
30590 }
30591
30592 /* As long as we have empty frags without any mapping symbols,
30593 keep looking. */
30594 /* If the next frag is non-empty and does not start with a
30595 mapping symbol, then this mapping symbol is required. */
30596 if (next->fr_address != next->fr_next->fr_address)
30597 break;
30598
30599 next = next->fr_next;
30600 }
30601 while (next != NULL);
30602 }
30603 }
30604 #endif
30605
30606 /* Adjust the symbol table. This marks Thumb symbols as distinct from
30607 ARM ones. */
30608
30609 void
30610 arm_adjust_symtab (void)
30611 {
30612 #ifdef OBJ_COFF
30613 symbolS * sym;
30614
30615 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
30616 {
30617 if (ARM_IS_THUMB (sym))
30618 {
30619 if (THUMB_IS_FUNC (sym))
30620 {
30621 /* Mark the symbol as a Thumb function. */
30622 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
30623 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
30624 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
30625
30626 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
30627 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
30628 else
30629 as_bad (_("%s: unexpected function type: %d"),
30630 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
30631 }
30632 else switch (S_GET_STORAGE_CLASS (sym))
30633 {
30634 case C_EXT:
30635 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
30636 break;
30637 case C_STAT:
30638 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
30639 break;
30640 case C_LABEL:
30641 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
30642 break;
30643 default:
30644 /* Do nothing. */
30645 break;
30646 }
30647 }
30648
30649 if (ARM_IS_INTERWORK (sym))
30650 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
30651 }
30652 #endif
30653 #ifdef OBJ_ELF
30654 symbolS * sym;
30655 char bind;
30656
30657 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
30658 {
30659 if (ARM_IS_THUMB (sym))
30660 {
30661 elf_symbol_type * elf_sym;
30662
30663 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
30664 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
30665
30666 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
30667 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
30668 {
30669 /* If it's a .thumb_func, declare it as so,
30670 otherwise tag label as .code 16. */
30671 if (THUMB_IS_FUNC (sym))
30672 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
30673 ST_BRANCH_TO_THUMB);
30674 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
30675 elf_sym->internal_elf_sym.st_info =
30676 ELF_ST_INFO (bind, STT_ARM_16BIT);
30677 }
30678 }
30679 }
30680
30681 /* Remove any overlapping mapping symbols generated by alignment frags. */
30682 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
30683 /* Now do generic ELF adjustments. */
30684 elf_adjust_symtab ();
30685 #endif
30686 }
30687
30688 /* MD interface: Initialization. */
30689
30690 static void
30691 set_constant_flonums (void)
30692 {
30693 int i;
30694
30695 for (i = 0; i < NUM_FLOAT_VALS; i++)
30696 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
30697 abort ();
30698 }
30699
30700 /* Auto-select Thumb mode if it's the only available instruction set for the
30701 given architecture. */
30702
30703 static void
30704 autoselect_thumb_from_cpu_variant (void)
30705 {
30706 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
30707 opcode_select (16);
30708 }
30709
30710 void
30711 md_begin (void)
30712 {
30713 unsigned mach;
30714 unsigned int i;
30715
30716 if ( (arm_ops_hsh = hash_new ()) == NULL
30717 || (arm_cond_hsh = hash_new ()) == NULL
30718 || (arm_vcond_hsh = hash_new ()) == NULL
30719 || (arm_shift_hsh = hash_new ()) == NULL
30720 || (arm_psr_hsh = hash_new ()) == NULL
30721 || (arm_v7m_psr_hsh = hash_new ()) == NULL
30722 || (arm_reg_hsh = hash_new ()) == NULL
30723 || (arm_reloc_hsh = hash_new ()) == NULL
30724 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
30725 as_fatal (_("virtual memory exhausted"));
30726
30727 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
30728 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
30729 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
30730 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
30731 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
30732 hash_insert (arm_vcond_hsh, vconds[i].template_name, (void *) (vconds + i));
30733 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
30734 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
30735 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
30736 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
30737 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
30738 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
30739 (void *) (v7m_psrs + i));
30740 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
30741 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
30742 for (i = 0;
30743 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
30744 i++)
30745 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
30746 (void *) (barrier_opt_names + i));
30747 #ifdef OBJ_ELF
30748 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
30749 {
30750 struct reloc_entry * entry = reloc_names + i;
30751
30752 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
30753 /* This makes encode_branch() use the EABI versions of this relocation. */
30754 entry->reloc = BFD_RELOC_UNUSED;
30755
30756 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
30757 }
30758 #endif
30759
30760 set_constant_flonums ();
30761
30762 /* Set the cpu variant based on the command-line options. We prefer
30763 -mcpu= over -march= if both are set (as for GCC); and we prefer
30764 -mfpu= over any other way of setting the floating point unit.
30765 Use of legacy options with new options are faulted. */
30766 if (legacy_cpu)
30767 {
30768 if (mcpu_cpu_opt || march_cpu_opt)
30769 as_bad (_("use of old and new-style options to set CPU type"));
30770
30771 selected_arch = *legacy_cpu;
30772 }
30773 else if (mcpu_cpu_opt)
30774 {
30775 selected_arch = *mcpu_cpu_opt;
30776 selected_ext = *mcpu_ext_opt;
30777 }
30778 else if (march_cpu_opt)
30779 {
30780 selected_arch = *march_cpu_opt;
30781 selected_ext = *march_ext_opt;
30782 }
30783 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
30784
30785 if (legacy_fpu)
30786 {
30787 if (mfpu_opt)
30788 as_bad (_("use of old and new-style options to set FPU type"));
30789
30790 selected_fpu = *legacy_fpu;
30791 }
30792 else if (mfpu_opt)
30793 selected_fpu = *mfpu_opt;
30794 else
30795 {
30796 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
30797 || defined (TE_NetBSD) || defined (TE_VXWORKS))
30798 /* Some environments specify a default FPU. If they don't, infer it
30799 from the processor. */
30800 if (mcpu_fpu_opt)
30801 selected_fpu = *mcpu_fpu_opt;
30802 else if (march_fpu_opt)
30803 selected_fpu = *march_fpu_opt;
30804 #else
30805 selected_fpu = fpu_default;
30806 #endif
30807 }
30808
30809 if (ARM_FEATURE_ZERO (selected_fpu))
30810 {
30811 if (!no_cpu_selected ())
30812 selected_fpu = fpu_default;
30813 else
30814 selected_fpu = fpu_arch_fpa;
30815 }
30816
30817 #ifdef CPU_DEFAULT
30818 if (ARM_FEATURE_ZERO (selected_arch))
30819 {
30820 selected_arch = cpu_default;
30821 selected_cpu = selected_arch;
30822 }
30823 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
30824 #else
30825 /* Autodection of feature mode: allow all features in cpu_variant but leave
30826 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
30827 after all instruction have been processed and we can decide what CPU
30828 should be selected. */
30829 if (ARM_FEATURE_ZERO (selected_arch))
30830 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
30831 else
30832 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
30833 #endif
30834
30835 autoselect_thumb_from_cpu_variant ();
30836
30837 arm_arch_used = thumb_arch_used = arm_arch_none;
30838
30839 #if defined OBJ_COFF || defined OBJ_ELF
30840 {
30841 unsigned int flags = 0;
30842
30843 #if defined OBJ_ELF
30844 flags = meabi_flags;
30845
30846 switch (meabi_flags)
30847 {
30848 case EF_ARM_EABI_UNKNOWN:
30849 #endif
30850 /* Set the flags in the private structure. */
30851 if (uses_apcs_26) flags |= F_APCS26;
30852 if (support_interwork) flags |= F_INTERWORK;
30853 if (uses_apcs_float) flags |= F_APCS_FLOAT;
30854 if (pic_code) flags |= F_PIC;
30855 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
30856 flags |= F_SOFT_FLOAT;
30857
30858 switch (mfloat_abi_opt)
30859 {
30860 case ARM_FLOAT_ABI_SOFT:
30861 case ARM_FLOAT_ABI_SOFTFP:
30862 flags |= F_SOFT_FLOAT;
30863 break;
30864
30865 case ARM_FLOAT_ABI_HARD:
30866 if (flags & F_SOFT_FLOAT)
30867 as_bad (_("hard-float conflicts with specified fpu"));
30868 break;
30869 }
30870
30871 /* Using pure-endian doubles (even if soft-float). */
30872 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
30873 flags |= F_VFP_FLOAT;
30874
30875 #if defined OBJ_ELF
30876 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
30877 flags |= EF_ARM_MAVERICK_FLOAT;
30878 break;
30879
30880 case EF_ARM_EABI_VER4:
30881 case EF_ARM_EABI_VER5:
30882 /* No additional flags to set. */
30883 break;
30884
30885 default:
30886 abort ();
30887 }
30888 #endif
30889 bfd_set_private_flags (stdoutput, flags);
30890
30891 /* We have run out flags in the COFF header to encode the
30892 status of ATPCS support, so instead we create a dummy,
30893 empty, debug section called .arm.atpcs. */
30894 if (atpcs)
30895 {
30896 asection * sec;
30897
30898 sec = bfd_make_section (stdoutput, ".arm.atpcs");
30899
30900 if (sec != NULL)
30901 {
30902 bfd_set_section_flags (sec, SEC_READONLY | SEC_DEBUGGING);
30903 bfd_set_section_size (sec, 0);
30904 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
30905 }
30906 }
30907 }
30908 #endif
30909
30910 /* Record the CPU type as well. */
30911 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
30912 mach = bfd_mach_arm_iWMMXt2;
30913 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
30914 mach = bfd_mach_arm_iWMMXt;
30915 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
30916 mach = bfd_mach_arm_XScale;
30917 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
30918 mach = bfd_mach_arm_ep9312;
30919 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
30920 mach = bfd_mach_arm_5TE;
30921 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
30922 {
30923 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
30924 mach = bfd_mach_arm_5T;
30925 else
30926 mach = bfd_mach_arm_5;
30927 }
30928 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
30929 {
30930 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
30931 mach = bfd_mach_arm_4T;
30932 else
30933 mach = bfd_mach_arm_4;
30934 }
30935 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
30936 mach = bfd_mach_arm_3M;
30937 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
30938 mach = bfd_mach_arm_3;
30939 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
30940 mach = bfd_mach_arm_2a;
30941 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
30942 mach = bfd_mach_arm_2;
30943 else
30944 mach = bfd_mach_arm_unknown;
30945
30946 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
30947 }
30948
30949 /* Command line processing. */
30950
30951 /* md_parse_option
30952 Invocation line includes a switch not recognized by the base assembler.
30953 See if it's a processor-specific option.
30954
30955 This routine is somewhat complicated by the need for backwards
30956 compatibility (since older releases of gcc can't be changed).
30957 The new options try to make the interface as compatible as
30958 possible with GCC.
30959
30960 New options (supported) are:
30961
30962 -mcpu=<cpu name> Assemble for selected processor
30963 -march=<architecture name> Assemble for selected architecture
30964 -mfpu=<fpu architecture> Assemble for selected FPU.
30965 -EB/-mbig-endian Big-endian
30966 -EL/-mlittle-endian Little-endian
30967 -k Generate PIC code
30968 -mthumb Start in Thumb mode
30969 -mthumb-interwork Code supports ARM/Thumb interworking
30970
30971 -m[no-]warn-deprecated Warn about deprecated features
30972 -m[no-]warn-syms Warn when symbols match instructions
30973
30974 For now we will also provide support for:
30975
30976 -mapcs-32 32-bit Program counter
30977 -mapcs-26 26-bit Program counter
30978 -macps-float Floats passed in FP registers
30979 -mapcs-reentrant Reentrant code
30980 -matpcs
30981 (sometime these will probably be replaced with -mapcs=<list of options>
30982 and -matpcs=<list of options>)
30983
30984 The remaining options are only supported for back-wards compatibility.
30985 Cpu variants, the arm part is optional:
30986 -m[arm]1 Currently not supported.
30987 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
30988 -m[arm]3 Arm 3 processor
30989 -m[arm]6[xx], Arm 6 processors
30990 -m[arm]7[xx][t][[d]m] Arm 7 processors
30991 -m[arm]8[10] Arm 8 processors
30992 -m[arm]9[20][tdmi] Arm 9 processors
30993 -mstrongarm[110[0]] StrongARM processors
30994 -mxscale XScale processors
30995 -m[arm]v[2345[t[e]]] Arm architectures
30996 -mall All (except the ARM1)
30997 FP variants:
30998 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
30999 -mfpe-old (No float load/store multiples)
31000 -mvfpxd VFP Single precision
31001 -mvfp All VFP
31002 -mno-fpu Disable all floating point instructions
31003
31004 The following CPU names are recognized:
31005 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
31006 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
31007 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
31008 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
31009 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
31010 arm10t arm10e, arm1020t, arm1020e, arm10200e,
31011 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
31012
31013 */
31014
31015 const char * md_shortopts = "m:k";
31016
31017 #ifdef ARM_BI_ENDIAN
31018 #define OPTION_EB (OPTION_MD_BASE + 0)
31019 #define OPTION_EL (OPTION_MD_BASE + 1)
31020 #else
31021 #if TARGET_BYTES_BIG_ENDIAN
31022 #define OPTION_EB (OPTION_MD_BASE + 0)
31023 #else
31024 #define OPTION_EL (OPTION_MD_BASE + 1)
31025 #endif
31026 #endif
31027 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
31028 #define OPTION_FDPIC (OPTION_MD_BASE + 3)
31029
31030 struct option md_longopts[] =
31031 {
31032 #ifdef OPTION_EB
31033 {"EB", no_argument, NULL, OPTION_EB},
31034 #endif
31035 #ifdef OPTION_EL
31036 {"EL", no_argument, NULL, OPTION_EL},
31037 #endif
31038 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
31039 #ifdef OBJ_ELF
31040 {"fdpic", no_argument, NULL, OPTION_FDPIC},
31041 #endif
31042 {NULL, no_argument, NULL, 0}
31043 };
31044
31045 size_t md_longopts_size = sizeof (md_longopts);
31046
31047 struct arm_option_table
31048 {
31049 const char * option; /* Option name to match. */
31050 const char * help; /* Help information. */
31051 int * var; /* Variable to change. */
31052 int value; /* What to change it to. */
31053 const char * deprecated; /* If non-null, print this message. */
31054 };
31055
31056 struct arm_option_table arm_opts[] =
31057 {
31058 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
31059 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
31060 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
31061 &support_interwork, 1, NULL},
31062 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
31063 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
31064 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
31065 1, NULL},
31066 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
31067 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
31068 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
31069 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
31070 NULL},
31071
31072 /* These are recognized by the assembler, but have no affect on code. */
31073 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
31074 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
31075
31076 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
31077 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
31078 &warn_on_deprecated, 0, NULL},
31079
31080 {"mwarn-restrict-it", N_("warn about performance deprecated IT instructions"
31081 " in ARMv8-A and ARMv8-R"), &warn_on_restrict_it, 1, NULL},
31082 {"mno-warn-restrict-it", NULL, &warn_on_restrict_it, 0, NULL},
31083
31084 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
31085 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
31086 {NULL, NULL, NULL, 0, NULL}
31087 };
31088
31089 struct arm_legacy_option_table
31090 {
31091 const char * option; /* Option name to match. */
31092 const arm_feature_set ** var; /* Variable to change. */
31093 const arm_feature_set value; /* What to change it to. */
31094 const char * deprecated; /* If non-null, print this message. */
31095 };
31096
31097 const struct arm_legacy_option_table arm_legacy_opts[] =
31098 {
31099 /* DON'T add any new processors to this list -- we want the whole list
31100 to go away... Add them to the processors table instead. */
31101 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31102 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31103 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31104 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31105 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31106 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31107 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31108 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31109 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31110 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31111 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31112 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31113 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31114 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31115 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31116 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31117 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31118 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31119 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31120 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31121 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31122 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31123 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31124 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31125 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31126 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31127 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31128 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31129 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31130 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31131 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31132 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31133 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31134 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31135 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31136 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31137 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31138 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31139 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31140 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31141 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31142 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31143 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31144 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31145 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31146 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31147 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31148 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31149 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31150 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31151 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31152 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31153 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31154 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31155 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31156 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31157 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31158 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31159 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31160 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31161 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31162 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31163 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31164 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31165 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31166 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31167 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31168 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31169 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
31170 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
31171 N_("use -mcpu=strongarm110")},
31172 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
31173 N_("use -mcpu=strongarm1100")},
31174 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
31175 N_("use -mcpu=strongarm1110")},
31176 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
31177 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
31178 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
31179
31180 /* Architecture variants -- don't add any more to this list either. */
31181 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31182 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31183 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31184 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31185 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31186 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31187 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31188 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31189 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31190 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31191 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31192 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31193 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31194 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31195 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31196 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31197 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
31198 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
31199
31200 /* Floating point variants -- don't add any more to this list either. */
31201 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
31202 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
31203 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
31204 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
31205 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
31206
31207 {NULL, NULL, ARM_ARCH_NONE, NULL}
31208 };
31209
31210 struct arm_cpu_option_table
31211 {
31212 const char * name;
31213 size_t name_len;
31214 const arm_feature_set value;
31215 const arm_feature_set ext;
31216 /* For some CPUs we assume an FPU unless the user explicitly sets
31217 -mfpu=... */
31218 const arm_feature_set default_fpu;
31219 /* The canonical name of the CPU, or NULL to use NAME converted to upper
31220 case. */
31221 const char * canonical_name;
31222 };
31223
31224 /* This list should, at a minimum, contain all the cpu names
31225 recognized by GCC. */
31226 #define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
31227
31228 static const struct arm_cpu_option_table arm_cpus[] =
31229 {
31230 ARM_CPU_OPT ("all", NULL, ARM_ANY,
31231 ARM_ARCH_NONE,
31232 FPU_ARCH_FPA),
31233 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
31234 ARM_ARCH_NONE,
31235 FPU_ARCH_FPA),
31236 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
31237 ARM_ARCH_NONE,
31238 FPU_ARCH_FPA),
31239 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
31240 ARM_ARCH_NONE,
31241 FPU_ARCH_FPA),
31242 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
31243 ARM_ARCH_NONE,
31244 FPU_ARCH_FPA),
31245 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
31246 ARM_ARCH_NONE,
31247 FPU_ARCH_FPA),
31248 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
31249 ARM_ARCH_NONE,
31250 FPU_ARCH_FPA),
31251 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
31252 ARM_ARCH_NONE,
31253 FPU_ARCH_FPA),
31254 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
31255 ARM_ARCH_NONE,
31256 FPU_ARCH_FPA),
31257 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
31258 ARM_ARCH_NONE,
31259 FPU_ARCH_FPA),
31260 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
31261 ARM_ARCH_NONE,
31262 FPU_ARCH_FPA),
31263 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
31264 ARM_ARCH_NONE,
31265 FPU_ARCH_FPA),
31266 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
31267 ARM_ARCH_NONE,
31268 FPU_ARCH_FPA),
31269 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
31270 ARM_ARCH_NONE,
31271 FPU_ARCH_FPA),
31272 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
31273 ARM_ARCH_NONE,
31274 FPU_ARCH_FPA),
31275 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
31276 ARM_ARCH_NONE,
31277 FPU_ARCH_FPA),
31278 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
31279 ARM_ARCH_NONE,
31280 FPU_ARCH_FPA),
31281 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
31282 ARM_ARCH_NONE,
31283 FPU_ARCH_FPA),
31284 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
31285 ARM_ARCH_NONE,
31286 FPU_ARCH_FPA),
31287 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
31288 ARM_ARCH_NONE,
31289 FPU_ARCH_FPA),
31290 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
31291 ARM_ARCH_NONE,
31292 FPU_ARCH_FPA),
31293 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
31294 ARM_ARCH_NONE,
31295 FPU_ARCH_FPA),
31296 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
31297 ARM_ARCH_NONE,
31298 FPU_ARCH_FPA),
31299 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
31300 ARM_ARCH_NONE,
31301 FPU_ARCH_FPA),
31302 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
31303 ARM_ARCH_NONE,
31304 FPU_ARCH_FPA),
31305 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
31306 ARM_ARCH_NONE,
31307 FPU_ARCH_FPA),
31308 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
31309 ARM_ARCH_NONE,
31310 FPU_ARCH_FPA),
31311 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
31312 ARM_ARCH_NONE,
31313 FPU_ARCH_FPA),
31314 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
31315 ARM_ARCH_NONE,
31316 FPU_ARCH_FPA),
31317 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
31318 ARM_ARCH_NONE,
31319 FPU_ARCH_FPA),
31320 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
31321 ARM_ARCH_NONE,
31322 FPU_ARCH_FPA),
31323 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
31324 ARM_ARCH_NONE,
31325 FPU_ARCH_FPA),
31326 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
31327 ARM_ARCH_NONE,
31328 FPU_ARCH_FPA),
31329 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
31330 ARM_ARCH_NONE,
31331 FPU_ARCH_FPA),
31332 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
31333 ARM_ARCH_NONE,
31334 FPU_ARCH_FPA),
31335 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
31336 ARM_ARCH_NONE,
31337 FPU_ARCH_FPA),
31338 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
31339 ARM_ARCH_NONE,
31340 FPU_ARCH_FPA),
31341 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
31342 ARM_ARCH_NONE,
31343 FPU_ARCH_FPA),
31344 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
31345 ARM_ARCH_NONE,
31346 FPU_ARCH_FPA),
31347 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
31348 ARM_ARCH_NONE,
31349 FPU_ARCH_FPA),
31350 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
31351 ARM_ARCH_NONE,
31352 FPU_ARCH_FPA),
31353 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
31354 ARM_ARCH_NONE,
31355 FPU_ARCH_FPA),
31356 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
31357 ARM_ARCH_NONE,
31358 FPU_ARCH_FPA),
31359 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
31360 ARM_ARCH_NONE,
31361 FPU_ARCH_FPA),
31362 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
31363 ARM_ARCH_NONE,
31364 FPU_ARCH_FPA),
31365 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
31366 ARM_ARCH_NONE,
31367 FPU_ARCH_FPA),
31368
31369 /* For V5 or later processors we default to using VFP; but the user
31370 should really set the FPU type explicitly. */
31371 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
31372 ARM_ARCH_NONE,
31373 FPU_ARCH_VFP_V2),
31374 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
31375 ARM_ARCH_NONE,
31376 FPU_ARCH_VFP_V2),
31377 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31378 ARM_ARCH_NONE,
31379 FPU_ARCH_VFP_V2),
31380 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31381 ARM_ARCH_NONE,
31382 FPU_ARCH_VFP_V2),
31383 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
31384 ARM_ARCH_NONE,
31385 FPU_ARCH_VFP_V2),
31386 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
31387 ARM_ARCH_NONE,
31388 FPU_ARCH_VFP_V2),
31389 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
31390 ARM_ARCH_NONE,
31391 FPU_ARCH_VFP_V2),
31392 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
31393 ARM_ARCH_NONE,
31394 FPU_ARCH_VFP_V2),
31395 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
31396 ARM_ARCH_NONE,
31397 FPU_ARCH_VFP_V2),
31398 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
31399 ARM_ARCH_NONE,
31400 FPU_ARCH_VFP_V2),
31401 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
31402 ARM_ARCH_NONE,
31403 FPU_ARCH_VFP_V2),
31404 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
31405 ARM_ARCH_NONE,
31406 FPU_ARCH_VFP_V2),
31407 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
31408 ARM_ARCH_NONE,
31409 FPU_ARCH_VFP_V1),
31410 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
31411 ARM_ARCH_NONE,
31412 FPU_ARCH_VFP_V1),
31413 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
31414 ARM_ARCH_NONE,
31415 FPU_ARCH_VFP_V2),
31416 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
31417 ARM_ARCH_NONE,
31418 FPU_ARCH_VFP_V2),
31419 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
31420 ARM_ARCH_NONE,
31421 FPU_ARCH_VFP_V1),
31422 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
31423 ARM_ARCH_NONE,
31424 FPU_ARCH_VFP_V2),
31425 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
31426 ARM_ARCH_NONE,
31427 FPU_ARCH_VFP_V2),
31428 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
31429 ARM_ARCH_NONE,
31430 FPU_ARCH_VFP_V2),
31431 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
31432 ARM_ARCH_NONE,
31433 FPU_ARCH_VFP_V2),
31434 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
31435 ARM_ARCH_NONE,
31436 FPU_ARCH_VFP_V2),
31437 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
31438 ARM_ARCH_NONE,
31439 FPU_ARCH_VFP_V2),
31440 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
31441 ARM_ARCH_NONE,
31442 FPU_ARCH_VFP_V2),
31443 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
31444 ARM_ARCH_NONE,
31445 FPU_ARCH_VFP_V2),
31446 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
31447 ARM_ARCH_NONE,
31448 FPU_ARCH_VFP_V2),
31449 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
31450 ARM_ARCH_NONE,
31451 FPU_NONE),
31452 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
31453 ARM_ARCH_NONE,
31454 FPU_NONE),
31455 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
31456 ARM_ARCH_NONE,
31457 FPU_ARCH_VFP_V2),
31458 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
31459 ARM_ARCH_NONE,
31460 FPU_ARCH_VFP_V2),
31461 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
31462 ARM_ARCH_NONE,
31463 FPU_ARCH_VFP_V2),
31464 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
31465 ARM_ARCH_NONE,
31466 FPU_NONE),
31467 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
31468 ARM_ARCH_NONE,
31469 FPU_NONE),
31470 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
31471 ARM_ARCH_NONE,
31472 FPU_ARCH_VFP_V2),
31473 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
31474 ARM_ARCH_NONE,
31475 FPU_NONE),
31476 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
31477 ARM_ARCH_NONE,
31478 FPU_ARCH_VFP_V2),
31479 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
31480 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31481 FPU_NONE),
31482 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
31483 ARM_ARCH_NONE,
31484 FPU_ARCH_NEON_VFP_V4),
31485 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
31486 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
31487 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31488 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
31489 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31490 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31491 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
31492 ARM_ARCH_NONE,
31493 FPU_ARCH_NEON_VFP_V4),
31494 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
31495 ARM_ARCH_NONE,
31496 FPU_ARCH_NEON_VFP_V4),
31497 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
31498 ARM_ARCH_NONE,
31499 FPU_ARCH_NEON_VFP_V4),
31500 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
31501 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31502 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31503 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
31504 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31505 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31506 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
31507 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31508 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31509 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
31510 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31511 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31512 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
31513 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31514 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31515 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
31516 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31517 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31518 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
31519 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31520 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31521 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
31522 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31523 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31524 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
31525 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31526 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31527 ARM_CPU_OPT ("cortex-a76ae", "Cortex-A76AE", ARM_ARCH_V8_2A,
31528 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31529 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31530 ARM_CPU_OPT ("cortex-a77", "Cortex-A77", ARM_ARCH_V8_2A,
31531 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31532 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31533 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
31534 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31535 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31536 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
31537 ARM_ARCH_NONE,
31538 FPU_NONE),
31539 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
31540 ARM_ARCH_NONE,
31541 FPU_ARCH_VFP_V3D16),
31542 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
31543 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31544 FPU_NONE),
31545 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
31546 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31547 FPU_ARCH_VFP_V3D16),
31548 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
31549 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31550 FPU_ARCH_VFP_V3D16),
31551 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
31552 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31553 FPU_ARCH_NEON_VFP_ARMV8),
31554 ARM_CPU_OPT ("cortex-m35p", "Cortex-M35P", ARM_ARCH_V8M_MAIN,
31555 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31556 FPU_NONE),
31557 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
31558 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31559 FPU_NONE),
31560 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
31561 ARM_ARCH_NONE,
31562 FPU_NONE),
31563 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
31564 ARM_ARCH_NONE,
31565 FPU_NONE),
31566 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
31567 ARM_ARCH_NONE,
31568 FPU_NONE),
31569 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
31570 ARM_ARCH_NONE,
31571 FPU_NONE),
31572 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
31573 ARM_ARCH_NONE,
31574 FPU_NONE),
31575 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
31576 ARM_ARCH_NONE,
31577 FPU_NONE),
31578 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
31579 ARM_ARCH_NONE,
31580 FPU_NONE),
31581 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
31582 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31583 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31584 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
31585 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31586 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31587 /* ??? XSCALE is really an architecture. */
31588 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
31589 ARM_ARCH_NONE,
31590 FPU_ARCH_VFP_V2),
31591
31592 /* ??? iwmmxt is not a processor. */
31593 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
31594 ARM_ARCH_NONE,
31595 FPU_ARCH_VFP_V2),
31596 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
31597 ARM_ARCH_NONE,
31598 FPU_ARCH_VFP_V2),
31599 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
31600 ARM_ARCH_NONE,
31601 FPU_ARCH_VFP_V2),
31602
31603 /* Maverick. */
31604 ARM_CPU_OPT ("ep9312", "ARM920T",
31605 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
31606 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
31607
31608 /* Marvell processors. */
31609 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
31610 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31611 FPU_ARCH_VFP_V3D16),
31612 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
31613 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31614 FPU_ARCH_NEON_VFP_V4),
31615
31616 /* APM X-Gene family. */
31617 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
31618 ARM_ARCH_NONE,
31619 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31620 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
31621 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31622 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31623
31624 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
31625 };
31626 #undef ARM_CPU_OPT
31627
31628 struct arm_ext_table
31629 {
31630 const char * name;
31631 size_t name_len;
31632 const arm_feature_set merge;
31633 const arm_feature_set clear;
31634 };
31635
31636 struct arm_arch_option_table
31637 {
31638 const char * name;
31639 size_t name_len;
31640 const arm_feature_set value;
31641 const arm_feature_set default_fpu;
31642 const struct arm_ext_table * ext_table;
31643 };
31644
31645 /* Used to add support for +E and +noE extension. */
31646 #define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
31647 /* Used to add support for a +E extension. */
31648 #define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
31649 /* Used to add support for a +noE extension. */
31650 #define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
31651
31652 #define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
31653 ~0 & ~FPU_ENDIAN_PURE)
31654
31655 static const struct arm_ext_table armv5te_ext_table[] =
31656 {
31657 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
31658 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31659 };
31660
31661 static const struct arm_ext_table armv7_ext_table[] =
31662 {
31663 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31664 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31665 };
31666
31667 static const struct arm_ext_table armv7ve_ext_table[] =
31668 {
31669 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
31670 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
31671 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31672 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31673 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31674 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
31675 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31676
31677 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
31678 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31679
31680 /* Aliases for +simd. */
31681 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31682
31683 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31684 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31685 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31686
31687 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31688 };
31689
31690 static const struct arm_ext_table armv7a_ext_table[] =
31691 {
31692 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31693 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31694 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31695 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31696 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31697 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
31698 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31699
31700 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
31701 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31702
31703 /* Aliases for +simd. */
31704 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31705 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31706
31707 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31708 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31709
31710 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
31711 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
31712 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31713 };
31714
31715 static const struct arm_ext_table armv7r_ext_table[] =
31716 {
31717 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
31718 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
31719 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31720 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31721 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
31722 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31723 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
31724 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
31725 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31726 };
31727
31728 static const struct arm_ext_table armv7em_ext_table[] =
31729 {
31730 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
31731 /* Alias for +fp, used to be known as fpv4-sp-d16. */
31732 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
31733 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
31734 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
31735 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
31736 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31737 };
31738
31739 static const struct arm_ext_table armv8a_ext_table[] =
31740 {
31741 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
31742 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31743 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31744 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31745
31746 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31747 should use the +simd option to turn on FP. */
31748 ARM_REMOVE ("fp", ALL_FP),
31749 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31750 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31751 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31752 };
31753
31754
31755 static const struct arm_ext_table armv81a_ext_table[] =
31756 {
31757 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31758 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31759 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31760
31761 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31762 should use the +simd option to turn on FP. */
31763 ARM_REMOVE ("fp", ALL_FP),
31764 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31765 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31766 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31767 };
31768
31769 static const struct arm_ext_table armv82a_ext_table[] =
31770 {
31771 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31772 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
31773 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
31774 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31775 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31776 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31777 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31778 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31779
31780 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31781 should use the +simd option to turn on FP. */
31782 ARM_REMOVE ("fp", ALL_FP),
31783 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31784 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31785 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31786 };
31787
31788 static const struct arm_ext_table armv84a_ext_table[] =
31789 {
31790 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31791 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
31792 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31793 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31794 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31795 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31796
31797 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31798 should use the +simd option to turn on FP. */
31799 ARM_REMOVE ("fp", ALL_FP),
31800 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31801 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31802 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31803 };
31804
31805 static const struct arm_ext_table armv85a_ext_table[] =
31806 {
31807 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31808 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
31809 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31810 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31811 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31812 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31813
31814 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31815 should use the +simd option to turn on FP. */
31816 ARM_REMOVE ("fp", ALL_FP),
31817 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31818 };
31819
31820 static const struct arm_ext_table armv86a_ext_table[] =
31821 {
31822 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31823 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31824 };
31825
31826 #define CDE_EXTENSIONS \
31827 ARM_ADD ("cdecp0", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE0)), \
31828 ARM_ADD ("cdecp1", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE1)), \
31829 ARM_ADD ("cdecp2", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE2)), \
31830 ARM_ADD ("cdecp3", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE3)), \
31831 ARM_ADD ("cdecp4", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE4)), \
31832 ARM_ADD ("cdecp5", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE5)), \
31833 ARM_ADD ("cdecp6", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE6)), \
31834 ARM_ADD ("cdecp7", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE7))
31835
31836 static const struct arm_ext_table armv8m_main_ext_table[] =
31837 {
31838 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31839 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
31840 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
31841 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
31842 CDE_EXTENSIONS,
31843 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31844 };
31845
31846
31847 static const struct arm_ext_table armv8_1m_main_ext_table[] =
31848 {
31849 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31850 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
31851 ARM_EXT ("fp",
31852 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31853 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
31854 ALL_FP),
31855 ARM_ADD ("fp.dp",
31856 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31857 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
31858 ARM_EXT ("mve", ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP, ARM_EXT2_MVE, 0),
31859 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE | ARM_EXT2_MVE_FP)),
31860 ARM_ADD ("mve.fp",
31861 ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP,
31862 ARM_EXT2_FP16_INST | ARM_EXT2_MVE | ARM_EXT2_MVE_FP,
31863 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
31864 CDE_EXTENSIONS,
31865 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31866 };
31867
31868 #undef CDE_EXTENSIONS
31869
31870 static const struct arm_ext_table armv8r_ext_table[] =
31871 {
31872 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
31873 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31874 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31875 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31876 ARM_REMOVE ("fp", ALL_FP),
31877 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
31878 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31879 };
31880
31881 /* This list should, at a minimum, contain all the architecture names
31882 recognized by GCC. */
31883 #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
31884 #define ARM_ARCH_OPT2(N, V, DF, ext) \
31885 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
31886
31887 static const struct arm_arch_option_table arm_archs[] =
31888 {
31889 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
31890 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
31891 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
31892 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
31893 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
31894 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
31895 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
31896 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
31897 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
31898 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
31899 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
31900 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
31901 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
31902 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
31903 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
31904 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
31905 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
31906 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31907 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31908 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
31909 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
31910 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
31911 kept to preserve existing behaviour. */
31912 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31913 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31914 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
31915 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
31916 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
31917 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
31918 kept to preserve existing behaviour. */
31919 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
31920 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
31921 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
31922 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
31923 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
31924 /* The official spelling of the ARMv7 profile variants is the dashed form.
31925 Accept the non-dashed form for compatibility with old toolchains. */
31926 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31927 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
31928 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
31929 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
31930 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31931 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
31932 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
31933 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
31934 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
31935 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
31936 armv8m_main),
31937 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
31938 armv8_1m_main),
31939 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
31940 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
31941 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
31942 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
31943 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
31944 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
31945 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
31946 ARM_ARCH_OPT2 ("armv8.6-a", ARM_ARCH_V8_6A, FPU_ARCH_VFP, armv86a),
31947 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
31948 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
31949 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
31950 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
31951 };
31952 #undef ARM_ARCH_OPT
31953
31954 /* ISA extensions in the co-processor and main instruction set space. */
31955
31956 struct arm_option_extension_value_table
31957 {
31958 const char * name;
31959 size_t name_len;
31960 const arm_feature_set merge_value;
31961 const arm_feature_set clear_value;
31962 /* List of architectures for which an extension is available. ARM_ARCH_NONE
31963 indicates that an extension is available for all architectures while
31964 ARM_ANY marks an empty entry. */
31965 const arm_feature_set allowed_archs[2];
31966 };
31967
31968 /* The following table must be in alphabetical order with a NULL last entry. */
31969
31970 #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
31971 #define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
31972
31973 /* DEPRECATED: Refrain from using this table to add any new extensions, instead
31974 use the context sensitive approach using arm_ext_table's. */
31975 static const struct arm_option_extension_value_table arm_extensions[] =
31976 {
31977 ARM_EXT_OPT ("crc", ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
31978 ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
31979 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31980 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31981 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
31982 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31983 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
31984 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
31985 ARM_ARCH_V8_2A),
31986 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31987 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31988 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
31989 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
31990 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31991 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31992 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31993 ARM_ARCH_V8_2A),
31994 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31995 | ARM_EXT2_FP16_FML),
31996 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31997 | ARM_EXT2_FP16_FML),
31998 ARM_ARCH_V8_2A),
31999 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
32000 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
32001 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
32002 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
32003 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
32004 Thumb divide instruction. Due to this having the same name as the
32005 previous entry, this will be ignored when doing command-line parsing and
32006 only considered by build attribute selection code. */
32007 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32008 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32009 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
32010 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
32011 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
32012 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
32013 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
32014 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
32015 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
32016 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
32017 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
32018 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
32019 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
32020 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32021 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32022 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
32023 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
32024 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
32025 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
32026 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32027 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32028 ARM_ARCH_V8A),
32029 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
32030 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
32031 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
32032 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
32033 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
32034 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
32035 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32036 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32037 ARM_ARCH_V8A),
32038 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
32039 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
32040 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
32041 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
32042 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
32043 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
32044 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
32045 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
32046 | ARM_EXT_DIV),
32047 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
32048 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
32049 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
32050 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
32051 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
32052 };
32053 #undef ARM_EXT_OPT
32054
32055 /* ISA floating-point and Advanced SIMD extensions. */
32056 struct arm_option_fpu_value_table
32057 {
32058 const char * name;
32059 const arm_feature_set value;
32060 };
32061
32062 /* This list should, at a minimum, contain all the fpu names
32063 recognized by GCC. */
32064 static const struct arm_option_fpu_value_table arm_fpus[] =
32065 {
32066 {"softfpa", FPU_NONE},
32067 {"fpe", FPU_ARCH_FPE},
32068 {"fpe2", FPU_ARCH_FPE},
32069 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
32070 {"fpa", FPU_ARCH_FPA},
32071 {"fpa10", FPU_ARCH_FPA},
32072 {"fpa11", FPU_ARCH_FPA},
32073 {"arm7500fe", FPU_ARCH_FPA},
32074 {"softvfp", FPU_ARCH_VFP},
32075 {"softvfp+vfp", FPU_ARCH_VFP_V2},
32076 {"vfp", FPU_ARCH_VFP_V2},
32077 {"vfp9", FPU_ARCH_VFP_V2},
32078 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
32079 {"vfp10", FPU_ARCH_VFP_V2},
32080 {"vfp10-r0", FPU_ARCH_VFP_V1},
32081 {"vfpxd", FPU_ARCH_VFP_V1xD},
32082 {"vfpv2", FPU_ARCH_VFP_V2},
32083 {"vfpv3", FPU_ARCH_VFP_V3},
32084 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
32085 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
32086 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
32087 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
32088 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
32089 {"arm1020t", FPU_ARCH_VFP_V1},
32090 {"arm1020e", FPU_ARCH_VFP_V2},
32091 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
32092 {"arm1136jf-s", FPU_ARCH_VFP_V2},
32093 {"maverick", FPU_ARCH_MAVERICK},
32094 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
32095 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
32096 {"neon-fp16", FPU_ARCH_NEON_FP16},
32097 {"vfpv4", FPU_ARCH_VFP_V4},
32098 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
32099 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
32100 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
32101 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
32102 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
32103 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
32104 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
32105 {"crypto-neon-fp-armv8",
32106 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
32107 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
32108 {"crypto-neon-fp-armv8.1",
32109 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
32110 {NULL, ARM_ARCH_NONE}
32111 };
32112
32113 struct arm_option_value_table
32114 {
32115 const char *name;
32116 long value;
32117 };
32118
32119 static const struct arm_option_value_table arm_float_abis[] =
32120 {
32121 {"hard", ARM_FLOAT_ABI_HARD},
32122 {"softfp", ARM_FLOAT_ABI_SOFTFP},
32123 {"soft", ARM_FLOAT_ABI_SOFT},
32124 {NULL, 0}
32125 };
32126
32127 #ifdef OBJ_ELF
32128 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
32129 static const struct arm_option_value_table arm_eabis[] =
32130 {
32131 {"gnu", EF_ARM_EABI_UNKNOWN},
32132 {"4", EF_ARM_EABI_VER4},
32133 {"5", EF_ARM_EABI_VER5},
32134 {NULL, 0}
32135 };
32136 #endif
32137
32138 struct arm_long_option_table
32139 {
32140 const char * option; /* Substring to match. */
32141 const char * help; /* Help information. */
32142 int (* func) (const char * subopt); /* Function to decode sub-option. */
32143 const char * deprecated; /* If non-null, print this message. */
32144 };
32145
32146 static bfd_boolean
32147 arm_parse_extension (const char *str, const arm_feature_set *opt_set,
32148 arm_feature_set *ext_set,
32149 const struct arm_ext_table *ext_table)
32150 {
32151 /* We insist on extensions being specified in alphabetical order, and with
32152 extensions being added before being removed. We achieve this by having
32153 the global ARM_EXTENSIONS table in alphabetical order, and using the
32154 ADDING_VALUE variable to indicate whether we are adding an extension (1)
32155 or removing it (0) and only allowing it to change in the order
32156 -1 -> 1 -> 0. */
32157 const struct arm_option_extension_value_table * opt = NULL;
32158 const arm_feature_set arm_any = ARM_ANY;
32159 int adding_value = -1;
32160
32161 while (str != NULL && *str != 0)
32162 {
32163 const char *ext;
32164 size_t len;
32165
32166 if (*str != '+')
32167 {
32168 as_bad (_("invalid architectural extension"));
32169 return FALSE;
32170 }
32171
32172 str++;
32173 ext = strchr (str, '+');
32174
32175 if (ext != NULL)
32176 len = ext - str;
32177 else
32178 len = strlen (str);
32179
32180 if (len >= 2 && strncmp (str, "no", 2) == 0)
32181 {
32182 if (adding_value != 0)
32183 {
32184 adding_value = 0;
32185 opt = arm_extensions;
32186 }
32187
32188 len -= 2;
32189 str += 2;
32190 }
32191 else if (len > 0)
32192 {
32193 if (adding_value == -1)
32194 {
32195 adding_value = 1;
32196 opt = arm_extensions;
32197 }
32198 else if (adding_value != 1)
32199 {
32200 as_bad (_("must specify extensions to add before specifying "
32201 "those to remove"));
32202 return FALSE;
32203 }
32204 }
32205
32206 if (len == 0)
32207 {
32208 as_bad (_("missing architectural extension"));
32209 return FALSE;
32210 }
32211
32212 gas_assert (adding_value != -1);
32213 gas_assert (opt != NULL);
32214
32215 if (ext_table != NULL)
32216 {
32217 const struct arm_ext_table * ext_opt = ext_table;
32218 bfd_boolean found = FALSE;
32219 for (; ext_opt->name != NULL; ext_opt++)
32220 if (ext_opt->name_len == len
32221 && strncmp (ext_opt->name, str, len) == 0)
32222 {
32223 if (adding_value)
32224 {
32225 if (ARM_FEATURE_ZERO (ext_opt->merge))
32226 /* TODO: Option not supported. When we remove the
32227 legacy table this case should error out. */
32228 continue;
32229
32230 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
32231 }
32232 else
32233 {
32234 if (ARM_FEATURE_ZERO (ext_opt->clear))
32235 /* TODO: Option not supported. When we remove the
32236 legacy table this case should error out. */
32237 continue;
32238 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
32239 }
32240 found = TRUE;
32241 break;
32242 }
32243 if (found)
32244 {
32245 str = ext;
32246 continue;
32247 }
32248 }
32249
32250 /* Scan over the options table trying to find an exact match. */
32251 for (; opt->name != NULL; opt++)
32252 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
32253 {
32254 int i, nb_allowed_archs =
32255 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
32256 /* Check we can apply the extension to this architecture. */
32257 for (i = 0; i < nb_allowed_archs; i++)
32258 {
32259 /* Empty entry. */
32260 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
32261 continue;
32262 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
32263 break;
32264 }
32265 if (i == nb_allowed_archs)
32266 {
32267 as_bad (_("extension does not apply to the base architecture"));
32268 return FALSE;
32269 }
32270
32271 /* Add or remove the extension. */
32272 if (adding_value)
32273 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
32274 else
32275 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
32276
32277 /* Allowing Thumb division instructions for ARMv7 in autodetection
32278 rely on this break so that duplicate extensions (extensions
32279 with the same name as a previous extension in the list) are not
32280 considered for command-line parsing. */
32281 break;
32282 }
32283
32284 if (opt->name == NULL)
32285 {
32286 /* Did we fail to find an extension because it wasn't specified in
32287 alphabetical order, or because it does not exist? */
32288
32289 for (opt = arm_extensions; opt->name != NULL; opt++)
32290 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
32291 break;
32292
32293 if (opt->name == NULL)
32294 as_bad (_("unknown architectural extension `%s'"), str);
32295 else
32296 as_bad (_("architectural extensions must be specified in "
32297 "alphabetical order"));
32298
32299 return FALSE;
32300 }
32301 else
32302 {
32303 /* We should skip the extension we've just matched the next time
32304 round. */
32305 opt++;
32306 }
32307
32308 str = ext;
32309 };
32310
32311 return TRUE;
32312 }
32313
32314 static bfd_boolean
32315 arm_parse_fp16_opt (const char *str)
32316 {
32317 if (strcasecmp (str, "ieee") == 0)
32318 fp16_format = ARM_FP16_FORMAT_IEEE;
32319 else if (strcasecmp (str, "alternative") == 0)
32320 fp16_format = ARM_FP16_FORMAT_ALTERNATIVE;
32321 else
32322 {
32323 as_bad (_("unrecognised float16 format \"%s\""), str);
32324 return FALSE;
32325 }
32326
32327 return TRUE;
32328 }
32329
32330 static bfd_boolean
32331 arm_parse_cpu (const char *str)
32332 {
32333 const struct arm_cpu_option_table *opt;
32334 const char *ext = strchr (str, '+');
32335 size_t len;
32336
32337 if (ext != NULL)
32338 len = ext - str;
32339 else
32340 len = strlen (str);
32341
32342 if (len == 0)
32343 {
32344 as_bad (_("missing cpu name `%s'"), str);
32345 return FALSE;
32346 }
32347
32348 for (opt = arm_cpus; opt->name != NULL; opt++)
32349 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
32350 {
32351 mcpu_cpu_opt = &opt->value;
32352 if (mcpu_ext_opt == NULL)
32353 mcpu_ext_opt = XNEW (arm_feature_set);
32354 *mcpu_ext_opt = opt->ext;
32355 mcpu_fpu_opt = &opt->default_fpu;
32356 if (opt->canonical_name)
32357 {
32358 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
32359 strcpy (selected_cpu_name, opt->canonical_name);
32360 }
32361 else
32362 {
32363 size_t i;
32364
32365 if (len >= sizeof selected_cpu_name)
32366 len = (sizeof selected_cpu_name) - 1;
32367
32368 for (i = 0; i < len; i++)
32369 selected_cpu_name[i] = TOUPPER (opt->name[i]);
32370 selected_cpu_name[i] = 0;
32371 }
32372
32373 if (ext != NULL)
32374 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
32375
32376 return TRUE;
32377 }
32378
32379 as_bad (_("unknown cpu `%s'"), str);
32380 return FALSE;
32381 }
32382
32383 static bfd_boolean
32384 arm_parse_arch (const char *str)
32385 {
32386 const struct arm_arch_option_table *opt;
32387 const char *ext = strchr (str, '+');
32388 size_t len;
32389
32390 if (ext != NULL)
32391 len = ext - str;
32392 else
32393 len = strlen (str);
32394
32395 if (len == 0)
32396 {
32397 as_bad (_("missing architecture name `%s'"), str);
32398 return FALSE;
32399 }
32400
32401 for (opt = arm_archs; opt->name != NULL; opt++)
32402 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
32403 {
32404 march_cpu_opt = &opt->value;
32405 if (march_ext_opt == NULL)
32406 march_ext_opt = XNEW (arm_feature_set);
32407 *march_ext_opt = arm_arch_none;
32408 march_fpu_opt = &opt->default_fpu;
32409 selected_ctx_ext_table = opt->ext_table;
32410 strcpy (selected_cpu_name, opt->name);
32411
32412 if (ext != NULL)
32413 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
32414 opt->ext_table);
32415
32416 return TRUE;
32417 }
32418
32419 as_bad (_("unknown architecture `%s'\n"), str);
32420 return FALSE;
32421 }
32422
32423 static bfd_boolean
32424 arm_parse_fpu (const char * str)
32425 {
32426 const struct arm_option_fpu_value_table * opt;
32427
32428 for (opt = arm_fpus; opt->name != NULL; opt++)
32429 if (streq (opt->name, str))
32430 {
32431 mfpu_opt = &opt->value;
32432 return TRUE;
32433 }
32434
32435 as_bad (_("unknown floating point format `%s'\n"), str);
32436 return FALSE;
32437 }
32438
32439 static bfd_boolean
32440 arm_parse_float_abi (const char * str)
32441 {
32442 const struct arm_option_value_table * opt;
32443
32444 for (opt = arm_float_abis; opt->name != NULL; opt++)
32445 if (streq (opt->name, str))
32446 {
32447 mfloat_abi_opt = opt->value;
32448 return TRUE;
32449 }
32450
32451 as_bad (_("unknown floating point abi `%s'\n"), str);
32452 return FALSE;
32453 }
32454
32455 #ifdef OBJ_ELF
32456 static bfd_boolean
32457 arm_parse_eabi (const char * str)
32458 {
32459 const struct arm_option_value_table *opt;
32460
32461 for (opt = arm_eabis; opt->name != NULL; opt++)
32462 if (streq (opt->name, str))
32463 {
32464 meabi_flags = opt->value;
32465 return TRUE;
32466 }
32467 as_bad (_("unknown EABI `%s'\n"), str);
32468 return FALSE;
32469 }
32470 #endif
32471
32472 static bfd_boolean
32473 arm_parse_it_mode (const char * str)
32474 {
32475 bfd_boolean ret = TRUE;
32476
32477 if (streq ("arm", str))
32478 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
32479 else if (streq ("thumb", str))
32480 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
32481 else if (streq ("always", str))
32482 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
32483 else if (streq ("never", str))
32484 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
32485 else
32486 {
32487 as_bad (_("unknown implicit IT mode `%s', should be "\
32488 "arm, thumb, always, or never."), str);
32489 ret = FALSE;
32490 }
32491
32492 return ret;
32493 }
32494
32495 static bfd_boolean
32496 arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
32497 {
32498 codecomposer_syntax = TRUE;
32499 arm_comment_chars[0] = ';';
32500 arm_line_separator_chars[0] = 0;
32501 return TRUE;
32502 }
32503
32504 struct arm_long_option_table arm_long_opts[] =
32505 {
32506 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
32507 arm_parse_cpu, NULL},
32508 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
32509 arm_parse_arch, NULL},
32510 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
32511 arm_parse_fpu, NULL},
32512 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
32513 arm_parse_float_abi, NULL},
32514 #ifdef OBJ_ELF
32515 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
32516 arm_parse_eabi, NULL},
32517 #endif
32518 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
32519 arm_parse_it_mode, NULL},
32520 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
32521 arm_ccs_mode, NULL},
32522 {"mfp16-format=",
32523 N_("[ieee|alternative]\n\
32524 set the encoding for half precision floating point "
32525 "numbers to IEEE\n\
32526 or Arm alternative format."),
32527 arm_parse_fp16_opt, NULL },
32528 {NULL, NULL, 0, NULL}
32529 };
32530
32531 int
32532 md_parse_option (int c, const char * arg)
32533 {
32534 struct arm_option_table *opt;
32535 const struct arm_legacy_option_table *fopt;
32536 struct arm_long_option_table *lopt;
32537
32538 switch (c)
32539 {
32540 #ifdef OPTION_EB
32541 case OPTION_EB:
32542 target_big_endian = 1;
32543 break;
32544 #endif
32545
32546 #ifdef OPTION_EL
32547 case OPTION_EL:
32548 target_big_endian = 0;
32549 break;
32550 #endif
32551
32552 case OPTION_FIX_V4BX:
32553 fix_v4bx = TRUE;
32554 break;
32555
32556 #ifdef OBJ_ELF
32557 case OPTION_FDPIC:
32558 arm_fdpic = TRUE;
32559 break;
32560 #endif /* OBJ_ELF */
32561
32562 case 'a':
32563 /* Listing option. Just ignore these, we don't support additional
32564 ones. */
32565 return 0;
32566
32567 default:
32568 for (opt = arm_opts; opt->option != NULL; opt++)
32569 {
32570 if (c == opt->option[0]
32571 && ((arg == NULL && opt->option[1] == 0)
32572 || streq (arg, opt->option + 1)))
32573 {
32574 /* If the option is deprecated, tell the user. */
32575 if (warn_on_deprecated && opt->deprecated != NULL)
32576 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32577 arg ? arg : "", _(opt->deprecated));
32578
32579 if (opt->var != NULL)
32580 *opt->var = opt->value;
32581
32582 return 1;
32583 }
32584 }
32585
32586 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
32587 {
32588 if (c == fopt->option[0]
32589 && ((arg == NULL && fopt->option[1] == 0)
32590 || streq (arg, fopt->option + 1)))
32591 {
32592 /* If the option is deprecated, tell the user. */
32593 if (warn_on_deprecated && fopt->deprecated != NULL)
32594 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32595 arg ? arg : "", _(fopt->deprecated));
32596
32597 if (fopt->var != NULL)
32598 *fopt->var = &fopt->value;
32599
32600 return 1;
32601 }
32602 }
32603
32604 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32605 {
32606 /* These options are expected to have an argument. */
32607 if (c == lopt->option[0]
32608 && arg != NULL
32609 && strncmp (arg, lopt->option + 1,
32610 strlen (lopt->option + 1)) == 0)
32611 {
32612 /* If the option is deprecated, tell the user. */
32613 if (warn_on_deprecated && lopt->deprecated != NULL)
32614 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
32615 _(lopt->deprecated));
32616
32617 /* Call the sup-option parser. */
32618 return lopt->func (arg + strlen (lopt->option) - 1);
32619 }
32620 }
32621
32622 return 0;
32623 }
32624
32625 return 1;
32626 }
32627
32628 void
32629 md_show_usage (FILE * fp)
32630 {
32631 struct arm_option_table *opt;
32632 struct arm_long_option_table *lopt;
32633
32634 fprintf (fp, _(" ARM-specific assembler options:\n"));
32635
32636 for (opt = arm_opts; opt->option != NULL; opt++)
32637 if (opt->help != NULL)
32638 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
32639
32640 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32641 if (lopt->help != NULL)
32642 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
32643
32644 #ifdef OPTION_EB
32645 fprintf (fp, _("\
32646 -EB assemble code for a big-endian cpu\n"));
32647 #endif
32648
32649 #ifdef OPTION_EL
32650 fprintf (fp, _("\
32651 -EL assemble code for a little-endian cpu\n"));
32652 #endif
32653
32654 fprintf (fp, _("\
32655 --fix-v4bx Allow BX in ARMv4 code\n"));
32656
32657 #ifdef OBJ_ELF
32658 fprintf (fp, _("\
32659 --fdpic generate an FDPIC object file\n"));
32660 #endif /* OBJ_ELF */
32661 }
32662
32663 #ifdef OBJ_ELF
32664
32665 typedef struct
32666 {
32667 int val;
32668 arm_feature_set flags;
32669 } cpu_arch_ver_table;
32670
32671 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
32672 chronologically for architectures, with an exception for ARMv6-M and
32673 ARMv6S-M due to legacy reasons. No new architecture should have a
32674 special case. This allows for build attribute selection results to be
32675 stable when new architectures are added. */
32676 static const cpu_arch_ver_table cpu_arch_ver[] =
32677 {
32678 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
32679 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
32680 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
32681 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
32682 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
32683 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
32684 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
32685 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
32686 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
32687 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
32688 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
32689 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
32690 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
32691 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
32692 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
32693 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
32694 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
32695 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
32696 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
32697 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
32698 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
32699 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
32700 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
32701 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
32702
32703 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
32704 always selected build attributes to match those of ARMv6-M
32705 (resp. ARMv6S-M). However, due to these architectures being a strict
32706 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
32707 would be selected when fully respecting chronology of architectures.
32708 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
32709 move them before ARMv7 architectures. */
32710 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
32711 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
32712
32713 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
32714 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
32715 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
32716 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
32717 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
32718 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
32719 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
32720 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
32721 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
32722 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
32723 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
32724 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
32725 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
32726 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
32727 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
32728 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
32729 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_6A},
32730 {-1, ARM_ARCH_NONE}
32731 };
32732
32733 /* Set an attribute if it has not already been set by the user. */
32734
32735 static void
32736 aeabi_set_attribute_int (int tag, int value)
32737 {
32738 if (tag < 1
32739 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32740 || !attributes_set_explicitly[tag])
32741 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
32742 }
32743
32744 static void
32745 aeabi_set_attribute_string (int tag, const char *value)
32746 {
32747 if (tag < 1
32748 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32749 || !attributes_set_explicitly[tag])
32750 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
32751 }
32752
32753 /* Return whether features in the *NEEDED feature set are available via
32754 extensions for the architecture whose feature set is *ARCH_FSET. */
32755
32756 static bfd_boolean
32757 have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
32758 const arm_feature_set *needed)
32759 {
32760 int i, nb_allowed_archs;
32761 arm_feature_set ext_fset;
32762 const struct arm_option_extension_value_table *opt;
32763
32764 ext_fset = arm_arch_none;
32765 for (opt = arm_extensions; opt->name != NULL; opt++)
32766 {
32767 /* Extension does not provide any feature we need. */
32768 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
32769 continue;
32770
32771 nb_allowed_archs =
32772 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
32773 for (i = 0; i < nb_allowed_archs; i++)
32774 {
32775 /* Empty entry. */
32776 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
32777 break;
32778
32779 /* Extension is available, add it. */
32780 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
32781 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
32782 }
32783 }
32784
32785 /* Can we enable all features in *needed? */
32786 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
32787 }
32788
32789 /* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
32790 a given architecture feature set *ARCH_EXT_FSET including extension feature
32791 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
32792 - if true, check for an exact match of the architecture modulo extensions;
32793 - otherwise, select build attribute value of the first superset
32794 architecture released so that results remains stable when new architectures
32795 are added.
32796 For -march/-mcpu=all the build attribute value of the most featureful
32797 architecture is returned. Tag_CPU_arch_profile result is returned in
32798 PROFILE. */
32799
32800 static int
32801 get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
32802 const arm_feature_set *ext_fset,
32803 char *profile, int exact_match)
32804 {
32805 arm_feature_set arch_fset;
32806 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
32807
32808 /* Select most featureful architecture with all its extensions if building
32809 for -march=all as the feature sets used to set build attributes. */
32810 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
32811 {
32812 /* Force revisiting of decision for each new architecture. */
32813 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
32814 *profile = 'A';
32815 return TAG_CPU_ARCH_V8;
32816 }
32817
32818 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
32819
32820 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
32821 {
32822 arm_feature_set known_arch_fset;
32823
32824 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
32825 if (exact_match)
32826 {
32827 /* Base architecture match user-specified architecture and
32828 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
32829 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
32830 {
32831 p_ver_ret = p_ver;
32832 goto found;
32833 }
32834 /* Base architecture match user-specified architecture only
32835 (eg. ARMv6-M in the same case as above). Record it in case we
32836 find a match with above condition. */
32837 else if (p_ver_ret == NULL
32838 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
32839 p_ver_ret = p_ver;
32840 }
32841 else
32842 {
32843
32844 /* Architecture has all features wanted. */
32845 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
32846 {
32847 arm_feature_set added_fset;
32848
32849 /* Compute features added by this architecture over the one
32850 recorded in p_ver_ret. */
32851 if (p_ver_ret != NULL)
32852 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
32853 p_ver_ret->flags);
32854 /* First architecture that match incl. with extensions, or the
32855 only difference in features over the recorded match is
32856 features that were optional and are now mandatory. */
32857 if (p_ver_ret == NULL
32858 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
32859 {
32860 p_ver_ret = p_ver;
32861 goto found;
32862 }
32863 }
32864 else if (p_ver_ret == NULL)
32865 {
32866 arm_feature_set needed_ext_fset;
32867
32868 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
32869
32870 /* Architecture has all features needed when using some
32871 extensions. Record it and continue searching in case there
32872 exist an architecture providing all needed features without
32873 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
32874 OS extension). */
32875 if (have_ext_for_needed_feat_p (&known_arch_fset,
32876 &needed_ext_fset))
32877 p_ver_ret = p_ver;
32878 }
32879 }
32880 }
32881
32882 if (p_ver_ret == NULL)
32883 return -1;
32884
32885 found:
32886 /* Tag_CPU_arch_profile. */
32887 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
32888 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
32889 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
32890 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
32891 *profile = 'A';
32892 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
32893 *profile = 'R';
32894 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
32895 *profile = 'M';
32896 else
32897 *profile = '\0';
32898 return p_ver_ret->val;
32899 }
32900
32901 /* Set the public EABI object attributes. */
32902
32903 static void
32904 aeabi_set_public_attributes (void)
32905 {
32906 char profile = '\0';
32907 int arch = -1;
32908 int virt_sec = 0;
32909 int fp16_optional = 0;
32910 int skip_exact_match = 0;
32911 arm_feature_set flags, flags_arch, flags_ext;
32912
32913 /* Autodetection mode, choose the architecture based the instructions
32914 actually used. */
32915 if (no_cpu_selected ())
32916 {
32917 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
32918
32919 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
32920 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
32921
32922 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
32923 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
32924
32925 /* Code run during relaxation relies on selected_cpu being set. */
32926 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
32927 flags_ext = arm_arch_none;
32928 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
32929 selected_ext = flags_ext;
32930 selected_cpu = flags;
32931 }
32932 /* Otherwise, choose the architecture based on the capabilities of the
32933 requested cpu. */
32934 else
32935 {
32936 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
32937 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
32938 flags_ext = selected_ext;
32939 flags = selected_cpu;
32940 }
32941 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
32942
32943 /* Allow the user to override the reported architecture. */
32944 if (!ARM_FEATURE_ZERO (selected_object_arch))
32945 {
32946 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
32947 flags_ext = arm_arch_none;
32948 }
32949 else
32950 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
32951
32952 /* When this function is run again after relaxation has happened there is no
32953 way to determine whether an architecture or CPU was specified by the user:
32954 - selected_cpu is set above for relaxation to work;
32955 - march_cpu_opt is not set if only -mcpu or .cpu is used;
32956 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
32957 Therefore, if not in -march=all case we first try an exact match and fall
32958 back to autodetection. */
32959 if (!skip_exact_match)
32960 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
32961 if (arch == -1)
32962 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
32963 if (arch == -1)
32964 as_bad (_("no architecture contains all the instructions used\n"));
32965
32966 /* Tag_CPU_name. */
32967 if (selected_cpu_name[0])
32968 {
32969 char *q;
32970
32971 q = selected_cpu_name;
32972 if (strncmp (q, "armv", 4) == 0)
32973 {
32974 int i;
32975
32976 q += 4;
32977 for (i = 0; q[i]; i++)
32978 q[i] = TOUPPER (q[i]);
32979 }
32980 aeabi_set_attribute_string (Tag_CPU_name, q);
32981 }
32982
32983 /* Tag_CPU_arch. */
32984 aeabi_set_attribute_int (Tag_CPU_arch, arch);
32985
32986 /* Tag_CPU_arch_profile. */
32987 if (profile != '\0')
32988 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
32989
32990 /* Tag_DSP_extension. */
32991 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
32992 aeabi_set_attribute_int (Tag_DSP_extension, 1);
32993
32994 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
32995 /* Tag_ARM_ISA_use. */
32996 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
32997 || ARM_FEATURE_ZERO (flags_arch))
32998 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
32999
33000 /* Tag_THUMB_ISA_use. */
33001 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
33002 || ARM_FEATURE_ZERO (flags_arch))
33003 {
33004 int thumb_isa_use;
33005
33006 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
33007 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
33008 thumb_isa_use = 3;
33009 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
33010 thumb_isa_use = 2;
33011 else
33012 thumb_isa_use = 1;
33013 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
33014 }
33015
33016 /* Tag_VFP_arch. */
33017 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
33018 aeabi_set_attribute_int (Tag_VFP_arch,
33019 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33020 ? 7 : 8);
33021 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
33022 aeabi_set_attribute_int (Tag_VFP_arch,
33023 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33024 ? 5 : 6);
33025 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
33026 {
33027 fp16_optional = 1;
33028 aeabi_set_attribute_int (Tag_VFP_arch, 3);
33029 }
33030 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
33031 {
33032 aeabi_set_attribute_int (Tag_VFP_arch, 4);
33033 fp16_optional = 1;
33034 }
33035 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
33036 aeabi_set_attribute_int (Tag_VFP_arch, 2);
33037 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
33038 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
33039 aeabi_set_attribute_int (Tag_VFP_arch, 1);
33040
33041 /* Tag_ABI_HardFP_use. */
33042 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
33043 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
33044 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
33045
33046 /* Tag_WMMX_arch. */
33047 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
33048 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
33049 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
33050 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
33051
33052 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
33053 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
33054 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
33055 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
33056 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
33057 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
33058 {
33059 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
33060 {
33061 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
33062 }
33063 else
33064 {
33065 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
33066 fp16_optional = 1;
33067 }
33068 }
33069
33070 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
33071 aeabi_set_attribute_int (Tag_MVE_arch, 2);
33072 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
33073 aeabi_set_attribute_int (Tag_MVE_arch, 1);
33074
33075 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
33076 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
33077 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
33078
33079 /* Tag_DIV_use.
33080
33081 We set Tag_DIV_use to two when integer divide instructions have been used
33082 in ARM state, or when Thumb integer divide instructions have been used,
33083 but we have no architecture profile set, nor have we any ARM instructions.
33084
33085 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
33086 by the base architecture.
33087
33088 For new architectures we will have to check these tests. */
33089 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
33090 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
33091 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
33092 aeabi_set_attribute_int (Tag_DIV_use, 0);
33093 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
33094 || (profile == '\0'
33095 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
33096 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
33097 aeabi_set_attribute_int (Tag_DIV_use, 2);
33098
33099 /* Tag_MP_extension_use. */
33100 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
33101 aeabi_set_attribute_int (Tag_MPextension_use, 1);
33102
33103 /* Tag Virtualization_use. */
33104 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
33105 virt_sec |= 1;
33106 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
33107 virt_sec |= 2;
33108 if (virt_sec != 0)
33109 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
33110
33111 if (fp16_format != ARM_FP16_FORMAT_DEFAULT)
33112 aeabi_set_attribute_int (Tag_ABI_FP_16bit_format, fp16_format);
33113 }
33114
33115 /* Post relaxation hook. Recompute ARM attributes now that relaxation is
33116 finished and free extension feature bits which will not be used anymore. */
33117
33118 void
33119 arm_md_post_relax (void)
33120 {
33121 aeabi_set_public_attributes ();
33122 XDELETE (mcpu_ext_opt);
33123 mcpu_ext_opt = NULL;
33124 XDELETE (march_ext_opt);
33125 march_ext_opt = NULL;
33126 }
33127
33128 /* Add the default contents for the .ARM.attributes section. */
33129
33130 void
33131 arm_md_end (void)
33132 {
33133 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
33134 return;
33135
33136 aeabi_set_public_attributes ();
33137 }
33138 #endif /* OBJ_ELF */
33139
33140 /* Parse a .cpu directive. */
33141
33142 static void
33143 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
33144 {
33145 const struct arm_cpu_option_table *opt;
33146 char *name;
33147 char saved_char;
33148
33149 name = input_line_pointer;
33150 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33151 input_line_pointer++;
33152 saved_char = *input_line_pointer;
33153 *input_line_pointer = 0;
33154
33155 /* Skip the first "all" entry. */
33156 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
33157 if (streq (opt->name, name))
33158 {
33159 selected_arch = opt->value;
33160 selected_ext = opt->ext;
33161 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33162 if (opt->canonical_name)
33163 strcpy (selected_cpu_name, opt->canonical_name);
33164 else
33165 {
33166 int i;
33167 for (i = 0; opt->name[i]; i++)
33168 selected_cpu_name[i] = TOUPPER (opt->name[i]);
33169
33170 selected_cpu_name[i] = 0;
33171 }
33172 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33173
33174 *input_line_pointer = saved_char;
33175 demand_empty_rest_of_line ();
33176 return;
33177 }
33178 as_bad (_("unknown cpu `%s'"), name);
33179 *input_line_pointer = saved_char;
33180 ignore_rest_of_line ();
33181 }
33182
33183 /* Parse a .arch directive. */
33184
33185 static void
33186 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
33187 {
33188 const struct arm_arch_option_table *opt;
33189 char saved_char;
33190 char *name;
33191
33192 name = input_line_pointer;
33193 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33194 input_line_pointer++;
33195 saved_char = *input_line_pointer;
33196 *input_line_pointer = 0;
33197
33198 /* Skip the first "all" entry. */
33199 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33200 if (streq (opt->name, name))
33201 {
33202 selected_arch = opt->value;
33203 selected_ctx_ext_table = opt->ext_table;
33204 selected_ext = arm_arch_none;
33205 selected_cpu = selected_arch;
33206 strcpy (selected_cpu_name, opt->name);
33207 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33208 *input_line_pointer = saved_char;
33209 demand_empty_rest_of_line ();
33210 return;
33211 }
33212
33213 as_bad (_("unknown architecture `%s'\n"), name);
33214 *input_line_pointer = saved_char;
33215 ignore_rest_of_line ();
33216 }
33217
33218 /* Parse a .object_arch directive. */
33219
33220 static void
33221 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
33222 {
33223 const struct arm_arch_option_table *opt;
33224 char saved_char;
33225 char *name;
33226
33227 name = input_line_pointer;
33228 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33229 input_line_pointer++;
33230 saved_char = *input_line_pointer;
33231 *input_line_pointer = 0;
33232
33233 /* Skip the first "all" entry. */
33234 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33235 if (streq (opt->name, name))
33236 {
33237 selected_object_arch = opt->value;
33238 *input_line_pointer = saved_char;
33239 demand_empty_rest_of_line ();
33240 return;
33241 }
33242
33243 as_bad (_("unknown architecture `%s'\n"), name);
33244 *input_line_pointer = saved_char;
33245 ignore_rest_of_line ();
33246 }
33247
33248 /* Parse a .arch_extension directive. */
33249
33250 static void
33251 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
33252 {
33253 const struct arm_option_extension_value_table *opt;
33254 char saved_char;
33255 char *name;
33256 int adding_value = 1;
33257
33258 name = input_line_pointer;
33259 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33260 input_line_pointer++;
33261 saved_char = *input_line_pointer;
33262 *input_line_pointer = 0;
33263
33264 if (strlen (name) >= 2
33265 && strncmp (name, "no", 2) == 0)
33266 {
33267 adding_value = 0;
33268 name += 2;
33269 }
33270
33271 /* Check the context specific extension table */
33272 if (selected_ctx_ext_table)
33273 {
33274 const struct arm_ext_table * ext_opt;
33275 for (ext_opt = selected_ctx_ext_table; ext_opt->name != NULL; ext_opt++)
33276 {
33277 if (streq (ext_opt->name, name))
33278 {
33279 if (adding_value)
33280 {
33281 if (ARM_FEATURE_ZERO (ext_opt->merge))
33282 /* TODO: Option not supported. When we remove the
33283 legacy table this case should error out. */
33284 continue;
33285 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
33286 ext_opt->merge);
33287 }
33288 else
33289 ARM_CLEAR_FEATURE (selected_ext, selected_ext, ext_opt->clear);
33290
33291 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33292 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33293 *input_line_pointer = saved_char;
33294 demand_empty_rest_of_line ();
33295 return;
33296 }
33297 }
33298 }
33299
33300 for (opt = arm_extensions; opt->name != NULL; opt++)
33301 if (streq (opt->name, name))
33302 {
33303 int i, nb_allowed_archs =
33304 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
33305 for (i = 0; i < nb_allowed_archs; i++)
33306 {
33307 /* Empty entry. */
33308 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
33309 continue;
33310 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
33311 break;
33312 }
33313
33314 if (i == nb_allowed_archs)
33315 {
33316 as_bad (_("architectural extension `%s' is not allowed for the "
33317 "current base architecture"), name);
33318 break;
33319 }
33320
33321 if (adding_value)
33322 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
33323 opt->merge_value);
33324 else
33325 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
33326
33327 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33328 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33329 *input_line_pointer = saved_char;
33330 demand_empty_rest_of_line ();
33331 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
33332 on this return so that duplicate extensions (extensions with the
33333 same name as a previous extension in the list) are not considered
33334 for command-line parsing. */
33335 return;
33336 }
33337
33338 if (opt->name == NULL)
33339 as_bad (_("unknown architecture extension `%s'\n"), name);
33340
33341 *input_line_pointer = saved_char;
33342 ignore_rest_of_line ();
33343 }
33344
33345 /* Parse a .fpu directive. */
33346
33347 static void
33348 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
33349 {
33350 const struct arm_option_fpu_value_table *opt;
33351 char saved_char;
33352 char *name;
33353
33354 name = input_line_pointer;
33355 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33356 input_line_pointer++;
33357 saved_char = *input_line_pointer;
33358 *input_line_pointer = 0;
33359
33360 for (opt = arm_fpus; opt->name != NULL; opt++)
33361 if (streq (opt->name, name))
33362 {
33363 selected_fpu = opt->value;
33364 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, fpu_any);
33365 #ifndef CPU_DEFAULT
33366 if (no_cpu_selected ())
33367 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
33368 else
33369 #endif
33370 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33371 *input_line_pointer = saved_char;
33372 demand_empty_rest_of_line ();
33373 return;
33374 }
33375
33376 as_bad (_("unknown floating point format `%s'\n"), name);
33377 *input_line_pointer = saved_char;
33378 ignore_rest_of_line ();
33379 }
33380
33381 /* Copy symbol information. */
33382
33383 void
33384 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
33385 {
33386 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
33387 }
33388
33389 #ifdef OBJ_ELF
33390 /* Given a symbolic attribute NAME, return the proper integer value.
33391 Returns -1 if the attribute is not known. */
33392
33393 int
33394 arm_convert_symbolic_attribute (const char *name)
33395 {
33396 static const struct
33397 {
33398 const char * name;
33399 const int tag;
33400 }
33401 attribute_table[] =
33402 {
33403 /* When you modify this table you should
33404 also modify the list in doc/c-arm.texi. */
33405 #define T(tag) {#tag, tag}
33406 T (Tag_CPU_raw_name),
33407 T (Tag_CPU_name),
33408 T (Tag_CPU_arch),
33409 T (Tag_CPU_arch_profile),
33410 T (Tag_ARM_ISA_use),
33411 T (Tag_THUMB_ISA_use),
33412 T (Tag_FP_arch),
33413 T (Tag_VFP_arch),
33414 T (Tag_WMMX_arch),
33415 T (Tag_Advanced_SIMD_arch),
33416 T (Tag_PCS_config),
33417 T (Tag_ABI_PCS_R9_use),
33418 T (Tag_ABI_PCS_RW_data),
33419 T (Tag_ABI_PCS_RO_data),
33420 T (Tag_ABI_PCS_GOT_use),
33421 T (Tag_ABI_PCS_wchar_t),
33422 T (Tag_ABI_FP_rounding),
33423 T (Tag_ABI_FP_denormal),
33424 T (Tag_ABI_FP_exceptions),
33425 T (Tag_ABI_FP_user_exceptions),
33426 T (Tag_ABI_FP_number_model),
33427 T (Tag_ABI_align_needed),
33428 T (Tag_ABI_align8_needed),
33429 T (Tag_ABI_align_preserved),
33430 T (Tag_ABI_align8_preserved),
33431 T (Tag_ABI_enum_size),
33432 T (Tag_ABI_HardFP_use),
33433 T (Tag_ABI_VFP_args),
33434 T (Tag_ABI_WMMX_args),
33435 T (Tag_ABI_optimization_goals),
33436 T (Tag_ABI_FP_optimization_goals),
33437 T (Tag_compatibility),
33438 T (Tag_CPU_unaligned_access),
33439 T (Tag_FP_HP_extension),
33440 T (Tag_VFP_HP_extension),
33441 T (Tag_ABI_FP_16bit_format),
33442 T (Tag_MPextension_use),
33443 T (Tag_DIV_use),
33444 T (Tag_nodefaults),
33445 T (Tag_also_compatible_with),
33446 T (Tag_conformance),
33447 T (Tag_T2EE_use),
33448 T (Tag_Virtualization_use),
33449 T (Tag_DSP_extension),
33450 T (Tag_MVE_arch),
33451 /* We deliberately do not include Tag_MPextension_use_legacy. */
33452 #undef T
33453 };
33454 unsigned int i;
33455
33456 if (name == NULL)
33457 return -1;
33458
33459 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
33460 if (streq (name, attribute_table[i].name))
33461 return attribute_table[i].tag;
33462
33463 return -1;
33464 }
33465
33466 /* Apply sym value for relocations only in the case that they are for
33467 local symbols in the same segment as the fixup and you have the
33468 respective architectural feature for blx and simple switches. */
33469
33470 int
33471 arm_apply_sym_value (struct fix * fixP, segT this_seg)
33472 {
33473 if (fixP->fx_addsy
33474 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
33475 /* PR 17444: If the local symbol is in a different section then a reloc
33476 will always be generated for it, so applying the symbol value now
33477 will result in a double offset being stored in the relocation. */
33478 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
33479 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
33480 {
33481 switch (fixP->fx_r_type)
33482 {
33483 case BFD_RELOC_ARM_PCREL_BLX:
33484 case BFD_RELOC_THUMB_PCREL_BRANCH23:
33485 if (ARM_IS_FUNC (fixP->fx_addsy))
33486 return 1;
33487 break;
33488
33489 case BFD_RELOC_ARM_PCREL_CALL:
33490 case BFD_RELOC_THUMB_PCREL_BLX:
33491 if (THUMB_IS_FUNC (fixP->fx_addsy))
33492 return 1;
33493 break;
33494
33495 default:
33496 break;
33497 }
33498
33499 }
33500 return 0;
33501 }
33502 #endif /* OBJ_ELF */
This page took 0.979141 seconds and 4 git commands to generate.